- Timestamp:
- 01/16/06 03:23:29 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r540 r542 13 13 #;../data/vienna/vienna-plane.x3d 14 14 # filename ../data/vienna/viewcells-25-sel.x3d 15 #filename ../data/atlanta/atlanta2.x3d15 filename ../data/atlanta/atlanta2.x3d 16 16 # filename ../data/soda/soda.dat 17 filename ../data/soda/soda5.dat17 # filename ../data/soda/soda5.dat 18 18 } 19 19 … … 21 21 # stored sample rays 22 22 samplesFilename rays.out 23 useGlRenderer true23 useGlRenderer false 24 24 # type sampling 25 25 type vss … … 29 29 VssPreprocessor { 30 30 samplesPerPass 100000 31 initialSamples 20000032 vssSamples 20000031 initialSamples 300000 32 vssSamples 1000000 33 33 vssSamplesPerPass 100000 34 34 useImportanceSampling true … … 52 52 maxDepth 40 53 53 minPvs 30 54 minRays 50054 minRays 800 55 55 minSize 0.001 56 56 maxCostRatio 1.5 57 57 maxRayContribution 0.5 58 58 59 maxTotalMemory 20060 maxStaticMemory 10059 maxTotalMemory 50 60 maxStaticMemory 20 61 61 62 62 splitType regular … … 66 66 67 67 interleaveDirSplits true 68 dirSplitDepth 1068 dirSplitDepth 0 69 69 70 70 numberOfEndPointDomains 10000 … … 174 174 #type kdTree 175 175 #type vspKdTree 176 #type bspTree176 type bspTree 177 177 type vspBspTree 178 178 … … 182 182 maxViewCells 100000 183 183 #percentage of total visible objects where pvs is considered invalid 184 maxPvsRatio 0. 5185 186 delayedConstruction false184 maxPvsRatio 0.3 185 186 delayedConstruction true 187 187 188 188 189 189 PostProcess { 190 190 # how much samples are used for post processing 191 samples 20000 191 samples 200000 192 192 } 193 193 … … 224 224 225 225 Construction { 226 samples 300000226 samples 500000 227 227 } 228 228 … … 230 230 maxDepth 40 231 231 minPvs 50 232 minRays 700232 minRays 800 233 233 minSize 0.001 234 234 maxCostRatio 0.9 235 235 missTolerance 4 236 maxRayContribution 0. 05236 maxRayContribution 0.5 237 237 } 238 238 239 239 maxTotalMemory 100 240 maxStaticMemory 50240 maxStaticMemory 40 241 241 242 242 splitType regular 243 243 #splitType heuristics 244 splitUseOnlyDrivingAxis true244 splitUseOnlyDrivingAxis false 245 245 ct_div_ci 0.0 246 246 … … 248 248 PostProcess { 249 249 maxCostRatio 0.005 250 minViewCells 200250 minViewCells 1000 251 251 maxPvsSize 50000 252 252 } … … 259 259 VspBspTree { 260 260 Construction { 261 samples 100000261 samples 300000 262 262 epsilon 0.005 263 263 randomize false … … 280 280 maxTests 10000 281 281 282 maxTotalMemory 50 283 maxStaticMemory 50 284 282 285 # factors for evaluating split plane costs 283 286 Factor { … … 289 292 Termination { 290 293 # parameters used for autopartition 291 minRays 1000294 minRays 500 292 295 minPolygons -1 293 296 maxDepth 30 294 297 minPvs 10 295 minArea 0.00008296 #minArea 0.000297 maxRayContribution 0. 3298 maxCostRatio 0.93298 #minArea 0.0001 299 minArea -1 300 maxRayContribution 0.9 301 maxCostRatio 99999.93 299 302 missTolerance 3 300 303 #maxAccRayLength 100 301 304 302 maxViewCells 200 305 maxViewCells 2001 303 306 304 307 # used for pvs criterium … … 306 309 307 310 AxisAligned { 308 minRays 5000311 minRays 4000 309 312 maxRayContribution 0.5 310 313 } … … 315 318 Visualization { 316 319 # x3d visualization of the split planes 317 exportSplits false320 exportSplits true 318 321 } 319 322 320 323 PostProcess { 321 maxCostRatio 0. 1324 maxCostRatio 0.001 322 325 minViewCells 1000 323 maxPvsSize 10000324 326 useRaysForMerge true 325 327 } -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp
r540 r542 2030 2030 mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) ); 2031 2031 mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) ); 2032 2033 } 2032 } 2033 2034 2035 void AxisAlignedBox3::ExtractPolys(PolygonContainer &polys) const 2036 { 2037 Polygon3 *face1 = new Polygon3(); 2038 polys.push_back(face1); 2039 2040 face1->mVertices.push_back(Vector3(mMin.x,mMin.y,mMax.z)); 2041 face1->mVertices.push_back(Vector3(mMin.x,mMax.y,mMax.z)); 2042 face1->mVertices.push_back(Vector3(mMin.x,mMax.y,mMin.z)); 2043 face1->mVertices.push_back(Vector3(mMin.x,mMin.y,mMin.z)); 2044 2045 Polygon3 *face2 = new Polygon3(); 2046 polys.push_back(face2); 2047 2048 face2->mVertices.push_back(Vector3(mMax.x,mMin.y,mMin.z)); 2049 face2->mVertices.push_back(Vector3(mMax.x,mMax.y,mMin.z)); 2050 face2->mVertices.push_back(Vector3(mMax.x,mMax.y,mMax.z)); 2051 face2->mVertices.push_back(Vector3(mMax.x,mMin.y,mMax.z)); 2052 2053 Polygon3 *face3 = new Polygon3(); 2054 polys.push_back(face3); 2055 2056 face3->mVertices.push_back(Vector3(mMax.x,mMin.y,mMin.z)); 2057 face3->mVertices.push_back(Vector3(mMax.x,mMin.y,mMax.z)); 2058 face3->mVertices.push_back(Vector3(mMin.x,mMin.y,mMax.z)); 2059 face3->mVertices.push_back(Vector3(mMin.x,mMin.y,mMin.z)); 2060 2061 Polygon3 *face4 = new Polygon3(); 2062 polys.push_back(face4); 2063 2064 face4->mVertices.push_back(Vector3(mMin.x,mMax.y,mMin.z)); 2065 face4->mVertices.push_back(Vector3(mMin.x,mMax.y,mMax.z)); 2066 face4->mVertices.push_back(Vector3(mMax.x,mMax.y,mMax.z)); 2067 face4->mVertices.push_back(Vector3(mMax.x,mMax.y,mMin.z)); 2068 2069 Polygon3 *face5 = new Polygon3(); 2070 polys.push_back(face5); 2071 2072 face5->mVertices.push_back(Vector3(mMin.x,mMax.y,mMin.z)); 2073 face5->mVertices.push_back(Vector3(mMax.x,mMax.y,mMin.z)); 2074 face5->mVertices.push_back(Vector3(mMax.x,mMin.y,mMin.z)); 2075 face5->mVertices.push_back(Vector3(mMin.x,mMin.y,mMin.z)); 2076 2077 Polygon3 *face6 = new Polygon3(); 2078 polys.push_back(face6); 2079 2080 face6->mVertices.push_back(Vector3(mMin.x,mMin.y,mMax.z)); 2081 face6->mVertices.push_back(Vector3(mMax.x,mMin.y,mMax.z)); 2082 face6->mVertices.push_back(Vector3(mMax.x,mMax.y,mMax.z)); 2083 face6->mVertices.push_back(Vector3(mMin.x,mMax.y,mMax.z)); 2084 } -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h
r538 r542 6 6 #include "Vector3.h" 7 7 #include "Plane3.h" 8 #include "Containers.h" 8 9 9 10 class Ray; 10 11 class Polygon3; 11 12 class Mesh; 13 12 14 // -------------------------------------------------------- 13 15 // CAABox class. … … 356 358 void AddBoxToMesh(Mesh *mesh) const; 357 359 360 void ExtractPolys(PolygonContainer &polys) const; 361 358 362 #define __EXTENT_HACK 359 363 // get the extent of face -
trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp
r540 r542 71 71 } 72 72 return result; 73 } 74 75 76 Beam::~Beam() 77 { 78 DEL_PTR(mMesh); 73 79 } 74 80 -
trunk/VUT/GtpVisibilityPreprocessor/src/Beam.h
r540 r542 89 89 const AxisAlignedBox3 &sceneBBox) const; 90 90 91 /* Computes parameters for glOrtho.91 /** Computes parameters for glOrtho. 92 92 */ 93 93 void ComputeOrthoFrustum(float &left, float &right, … … 107 107 } 108 108 109 ~Beam(); 110 111 /** Creates beam mesh bounded at zfar. 112 */ 109 113 void CreateMesh(const float zfar); 110 114 }; -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r539 r542 1820 1820 "1000"); 1821 1821 1822 RegisterOption("VspBspTree.PostProcess.maxPvsSize",1823 optInt,1824 "vsp_bsp_term_post_process_max_pvs_size=",1825 "100");1826 1827 1822 RegisterOption("VspBspTree.PostProcess.useRaysForMerge", 1828 1823 optBool, -
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
r541 r542 977 977 } 978 978 979 979 980 void GlRendererBuffer::ComputeRays(Intersectable *sourceObj, VssRayContainer &rays) 980 981 { … … 1017 1018 ObjectContainer::iterator oit = 1018 1019 lower_bound(objects.begin(), objects.end(), &dummy, ilt); 1019 obj = *oit; 1020 if (!obj->Mailed()) 1020 1021 1022 if (//(oit != oit.end()) && 1023 ((*oit)->GetId() == id) && 1024 !obj->Mailed()) 1021 1025 { 1026 obj = *oit; 1022 1027 obj->Mail(); 1023 1028 ++ pvsSize; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r540 r542 27 27 mViewCellsFinished(false) 28 28 { 29 m SceneBox.Initialize();29 mViewSpaceBox.Initialize(); 30 30 ParseEnvironment(); 31 31 } … … 39 39 mViewCellsFinished(false) 40 40 { 41 m SceneBox.Initialize();41 mViewSpaceBox.Initialize(); 42 42 ParseEnvironment(); 43 43 } … … 77 77 int ViewCellsManager::Construct(VssRayContainer &rays) 78 78 { 79 VssPreprocessor preprocessor; 80 81 82 83 return 0; 79 /* VssPreprocessor preprocessor; 80 81 VssRayContainer vssRays; 82 preprocessor->GenerateVssRays(mConstructionSamples, vssRays); 83 Construct(preprocessor->mObjects, vssRays); 84 85 // add rays to output rays 86 while (!vssRays.empty) 87 { 88 rays.push_back(vssRays.back()); 89 vssRays.pop_back(); 90 } 91 92 const int importanceRays = 1000000; 93 preprocessor->GenerateVssRays(max(importanceRays, mPostProcessSamples); 94 95 PostProcess(preprocesor->mObjects, importanceRays); 96 Visualize(preprocessor->mObjects, importanceRays); 97 98 // add rays to output rays 99 while (!importanceRays.empty) 100 { 101 rays.push_back(importanceRays.back()); 102 importanceRays.pop_back(); 103 } 104 */ 105 return (int)rays.size(); 84 106 } 85 107 … … 99 121 bool ViewCellsManager::GetViewPoint(Vector3 &viewPoint) const 100 122 { 101 viewPoint = m SceneBox.GetRandomPoint();123 viewPoint = mViewSpaceBox.GetRandomPoint(); 102 124 103 125 return true; … … 107 129 bool ViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 108 130 { 109 return m SceneBox.IsInside(viewPoint);131 return mViewSpaceBox.IsInside(viewPoint); 110 132 } 111 133 … … 333 355 void ViewCellsManager::SetViewSpaceBox(const AxisAlignedBox3 &box) 334 356 { 335 m SceneBox = box;357 mViewSpaceBox = box; 336 358 } 337 359 … … 339 361 AxisAlignedBox3 ViewCellsManager::GetViewSpaceBox() const 340 362 { 341 return m SceneBox;363 return mViewSpaceBox; 342 364 } 343 365 … … 358 380 void ViewCellsManager::ComputeSampleContributions(VssRay &ray) 359 381 { 360 361 362 363 364 365 366 367 368 369 370 382 ViewCellContainer viewcells; 383 384 ray.mPvsContribution = 0; 385 ray.mRelativePvsContribution = 0.0f; 386 387 // matt TODO: remove this!! 388 Ray hray(ray); 389 float tmin = 0, tmax = 1.0; 390 391 //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 392 if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 371 393 return; 372 394 373 Vector3 origin = hray.Extrap(tmin); 374 Vector3 termination = hray.Extrap(tmax); 375 376 CastLineSegment(origin, 377 termination, 378 viewcells); 379 //Debug << "constribution: " << (int)viewcells.size() << endl; 380 // copy viewcells memory efficiently 381 const bool storeViewcells = false; 382 if (storeViewcells) { 383 ray.mViewCells.reserve(viewcells.size()); 384 ray.mViewCells = viewcells; 385 } 386 387 ViewCellContainer::const_iterator it = viewcells.begin(); 388 389 bool addInPlace = false; 390 391 if (addInPlace) { 392 for (; it != viewcells.end(); ++it) { 393 ViewCell *viewcell = *it; 394 395 // if ray not outside of view space 396 float contribution; 397 bool added = 398 viewcell->GetPvs().AddSample(ray.mTerminationObject, 399 contribution 400 ); 401 if (added) 402 ray.mPvsContribution++; 403 404 ray.mRelativePvsContribution += contribution; 405 } 406 } else { 407 for (; it != viewcells.end(); ++it) { 408 ViewCell *viewcell = *it; 409 // if ray not outside of view space 410 float contribution; 411 if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject, 412 contribution 413 )) 414 ray.mPvsContribution++; 415 416 ray.mRelativePvsContribution += contribution; 417 } 418 419 for (it = viewcells.begin(); it != viewcells.end(); ++it) { 420 ViewCell *viewcell = *it; 421 // if ray not outside of view space 422 viewcell->GetPvs().AddSample(ray.mTerminationObject); 423 } 424 } 395 Vector3 origin = hray.Extrap(tmin); 396 Vector3 termination = hray.Extrap(tmax); 397 398 CastLineSegment(origin, 399 termination, 400 viewcells); 401 //Debug << "constribution: " << (int)viewcells.size() << endl; 402 // copy viewcells memory efficiently 403 const bool storeViewcells = false; 404 if (storeViewcells) 405 { 406 ray.mViewCells.reserve(viewcells.size()); 407 ray.mViewCells = viewcells; 408 } 409 410 ViewCellContainer::const_iterator it = viewcells.begin(); 411 412 bool addInPlace = false; 413 414 if (addInPlace) 415 { 416 for (; it != viewcells.end(); ++it) { 417 ViewCell *viewcell = *it; 418 419 // if ray not outside of view space 420 float contribution; 421 bool added = 422 viewcell->GetPvs().AddSample(ray.mTerminationObject, 423 contribution 424 ); 425 if (added) 426 ray.mPvsContribution++; 427 428 ray.mRelativePvsContribution += contribution; 429 } 430 } 431 else 432 { 433 for (; it != viewcells.end(); ++it) { 434 ViewCell *viewcell = *it; 435 // if ray not outside of view space 436 float contribution; 437 if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject, 438 contribution 439 )) 440 ray.mPvsContribution++; 441 ray.mRelativePvsContribution += contribution; 442 } 443 444 for (it = viewcells.begin(); it != viewcells.end(); ++it) { 445 ViewCell *viewcell = *it; 446 // if ray not outside of view space 447 viewcell->GetPvs().AddSample(ray.mTerminationObject); 448 } 449 } 425 450 } 426 451 … … 1456 1481 << (int)constructionRays.size() << " samples" << endl; 1457 1482 1458 mVspKdTree->Construct(constructionRays, &m SceneBox);1483 mVspKdTree->Construct(constructionRays, &mViewSpaceBox); 1459 1484 Debug << mVspKdTree->GetStatistics() << endl; 1460 1485 … … 1468 1493 mVspKdTree->RefineViewCells(rays); 1469 1494 1470 1495 // collapse siblings belonging to the same view cell 1471 1496 mVspKdTree->CollapseTree(); 1472 1497 … … 1827 1852 Debug << "saved rays: " << (int)savedRays.size() << endl; 1828 1853 1829 mVspBspTree->Construct(constructionRays, &m SceneBox);1854 mVspBspTree->Construct(constructionRays, &mViewSpaceBox); 1830 1855 1831 1856 Debug << mVspBspTree->GetStatistics() << endl; … … 1982 2007 } 1983 2008 1984 EvaluateViewCellsStats(); 1985 1986 // view cells already finished post processing step 2009 2010 // view cells already finished before post processing step (i.e. because they were loaded) 1987 2011 if (mViewCellsFinished) 2012 { 2013 EvaluateViewCellsStats(); 1988 2014 return 0; 2015 } 2016 2017 2018 // check if new view cells turned invalid 2019 mVspBspTree->CheckValidy(); 2020 ResetViewCells(); 2021 1989 2022 1990 2023 VssRayContainer postProcessRays; … … 2038 2071 for (int i = 0; i < limit; ++ i) 2039 2072 { 2040 viewPoint = m SceneBox.GetRandomPoint();2073 viewPoint = mViewSpaceBox.GetRandomPoint(); 2041 2074 if (mVspBspTree->ViewPointValid(viewPoint)) 2042 2075 { … … 2051 2084 bool VspBspViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 2052 2085 { 2053 return m SceneBox.IsInside(viewPoint) &&2086 return mViewSpaceBox.IsInside(viewPoint) && 2054 2087 mVspBspTree->ViewPointValid(viewPoint); 2055 2088 } … … 2072 2105 if (exporter) 2073 2106 { 2107 if (1) 2108 { 2109 exporter->SetWireframe(); 2110 exporter->ExportBox(mViewSpaceBox); 2111 exporter->SetFilled(); 2112 } 2113 2074 2114 if (mExportGeometry) 2115 { 2075 2116 exporter->ExportGeometry(objects); 2117 } 2076 2118 2077 2119 // export rays … … 2099 2141 } 2100 2142 2101 // export single view cells2143 //-- export single view cells 2102 2144 ExportBspPvs(objects, visRays); 2103 2145 } … … 2167 2209 VssRayContainer vcRays; 2168 2210 Intersectable::NewMail(); 2169 #if 0 2211 #if 0 // largest view cell pvs first 2170 2212 BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[i]); 2171 2213 #else … … 2301 2343 ViewCell *vc) const 2302 2344 { 2303 #if 1 2304 if (vc->GetMesh()) 2345 if (vc->GetMesh()) 2305 2346 { 2306 2347 exporter->ExportMesh(vc->GetMesh()); … … 2312 2353 ConstructGeometry(dynamic_cast<BspViewCell *>(vc), geom); 2313 2354 exporter->ExportPolygons(geom.mPolys); 2314 #else2315 2316 Material m2;2317 m2.mDiffuseColor.b = 0.3f + Random(0.7f);2318 m2.mDiffuseColor.r = 0.0f;//0.3f + Random(0.7f);2319 m2.mDiffuseColor.g = 0.3f + Random(0.7f);2320 Material m;2321 m.mDiffuseColor.b = 0.0f;2322 m.mDiffuseColor.r = 1.0f;2323 m.mDiffuseColor.g = 0.0f;2324 2325 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc);2326 vector<BspLeaf *>::const_iterator it, it_end = bspVc->mLeaves.end();2327 2328 for (it = bspVc->mLeaves.begin(); it != it_end; ++ it)2329 {2330 if ((*it)->Mailed())2331 exporter->SetForcedMaterial(m);2332 else2333 exporter->SetForcedMaterial(m2);2334 //exporter->ResetForcedMaterial();2335 BspNodeGeometry geom;2336 mVspBspTree->ConstructGeometry(*it, geom);2337 exporter->ExportPolygons(geom.mPolys);2338 }2339 #endif2340 2355 } 2341 2356 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r532 r542 319 319 ViewCellsStatistics mViewCellsStats; 320 320 /// the scene bounding box 321 AxisAlignedBox3 m SceneBox;321 AxisAlignedBox3 mViewSpaceBox; 322 322 /// holds the view cell meshes 323 323 MeshContainer mMeshContainer; -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r538 r542 278 278 279 279 int numObj = 0; 280 280 281 //-- extract polygons intersected by the rays 281 282 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) … … 313 314 mMaxPvs = (int)(mMaxPvsRatio * (float)numObj); 314 315 315 Debug << "maximal pvs (i.e., view cell considered as valid: " << mMaxPvs << endl;316 Debug << "maximal pvs (i.e., pvs still considered as valid) : " << mMaxPvs << endl; 316 317 //-- store rays 317 318 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) … … 382 383 383 384 mStat.Start(); 384 cout << "Contructing vsp bsp tree ... "; 385 386 long startTime = GetTime(); 387 388 bool mOutOfMemory = false; 385 cout << "Contructing vsp bsp tree ... \n"; 386 387 long startTime = GetTime(); 388 long interTime = GetTime(); 389 mOutOfMemory = false; 390 391 int nleaves = 500; 389 392 390 393 while (!tStack.empty()) … … 404 407 } 405 408 406 // subdivide leaf node409 // subdivide leaf node 407 410 BspNode *r = Subdivide(tStack, tData); 408 411 409 412 if (r == mRoot) 410 413 Debug << "VSP BSP tree construction time spent at root: " 411 << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl << endl; 412 } 413 414 Debug << "Used Memory: " << GetMemUsage() << " MB" << endl; 414 << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 415 416 if (mStat.Leaves() >= nleaves) 417 { 418 nleaves += 500; 419 420 cout << "leaves=" << mStat.Leaves() << endl; 421 Debug << "needed " 422 << TimeDiff(interTime, GetTime())*1e-3 << " secs to create 500 leaves" << endl; 423 interTime = GetTime(); 424 } 425 } 426 427 Debug << "Used Memory: " << GetMemUsage() << " MB" << endl << endl; 415 428 cout << "finished\n"; 416 429 … … 436 449 BspNode *newNode = tData.mNode; 437 450 438 if (!mOutOfMemory ||!TerminationCriteriaMet(tData))451 if (!mOutOfMemory && !TerminationCriteriaMet(tData)) 439 452 { 440 453 PolygonContainer coincident; … … 508 521 509 522 523 524 510 525 BspNode *VspBspTree::SubdivideNode(VspBspTraversalData &tData, 511 526 VspBspTraversalData &frontData, … … 517 532 // select subdivision plane 518 533 Plane3 splitPlane; 534 519 535 int maxCostMisses = tData.mMaxCostMisses; 520 bool success = SelectPlane(splitPlane, 521 leaf, 522 tData, 523 frontData, 524 backData); 536 537 const bool success = 538 SelectPlane(splitPlane, leaf, tData, frontData, backData); 539 525 540 if (!success) 526 541 { … … 578 593 if (mPvsUseArea) 579 594 { 580 // if not already computed595 // if geometry was not already computed 581 596 if (!frontData.mGeometry && !backData.mGeometry) 582 597 { … … 820 835 BspNodeGeometry **backGeom, 821 836 float &frontArea, 822 float &backArea) 837 float &backArea, 838 bool useKdSplit) 823 839 { 824 840 const bool useCostHeuristics = false; … … 838 854 AxisAlignedBox3 box; 839 855 box.Initialize(); 840 856 //TODO: for kd split geometry already is box 841 857 if (1 && mPvsUseArea) 842 858 { … … 868 884 Vector3 normal(0,0,0); normal[axis] = 1; 869 885 870 nCostRatio[axis] = SplitPlaneCost(Plane3(normal, nPosition[axis]), 871 tData, *nFrontGeom[axis], *nBackGeom[axis], 872 nFrontArea[axis], nBackArea[axis]); 886 if (useKdSplit) 887 { 888 nCostRatio[axis] = EvalAxisAlignedSplitCost(tData, 889 box, 890 axis, 891 nPosition[axis]); 892 893 Vector3 pos = box.Max(); pos[axis] = nPosition[axis]; 894 AxisAlignedBox3 frontBox(box.Min(), pos); 895 frontBox.ExtractPolys(nFrontGeom[axis]->mPolys); 896 897 pos = box.Min(); pos[axis] = nPosition[axis]; 898 AxisAlignedBox3 backBox(pos, box.Max()); 899 backBox.ExtractPolys(nBackGeom[axis]->mPolys); 900 901 } 902 else 903 { 904 nCostRatio[axis] = SplitPlaneCost(Plane3(normal, nPosition[axis]), 905 tData, *nFrontGeom[axis], *nBackGeom[axis], 906 nFrontArea[axis], nBackArea[axis]); 907 } 873 908 } 874 909 else … … 903 938 *frontGeom = nFrontGeom[bestAxis]; 904 939 *backGeom = nBackGeom[bestAxis]; 940 905 941 // and delete other geometry 906 942 delete nFrontGeom[(bestAxis + 1) % 3]; … … 913 949 return nCostRatio[bestAxis]; 914 950 } 951 952 953 float VspBspTree::EvalAxisAlignedSplitCost(const VspBspTraversalData &data, 954 const AxisAlignedBox3 &box, 955 const int axis, 956 const float &position) const 957 { 958 int pvsFront = 0; 959 int pvsBack = 0; 960 int pvsTotal = 0; 961 962 // create unique ids for pvs heuristics 963 GenerateUniqueIdsForPvs(); 964 965 const int pvsSize = data.mPvs; 966 967 // this is the main ray classification loop! 968 for(RayInfoContainer::iterator ri = data.mRays->begin(); 969 ri != data.mRays->end(); ++ ri) 970 { 971 if (!(*ri).mRay->IsActive()) 972 continue; 973 974 // determine the side of this ray with respect to the plane 975 float t; 976 int side = (*ri).ComputeRayIntersection(axis, position, t); 977 978 AddObjToPvs((*ri).mRay->mTerminationObject, side, pvsFront, pvsBack, pvsTotal); 979 AddObjToPvs((*ri).mRay->mOriginObject, side, pvsFront, pvsBack, pvsTotal); 980 } 981 982 //-- only one of these options should be one 983 //-- pvs + probability heuristics 984 float pBack, pFront, pOverall; 985 986 if (1) 987 { 988 // box length substitute for probability 989 const float minBox = box.Min(axis); 990 const float maxBox = box.Max(axis); 991 992 pBack = position - minBox; 993 pFront = maxBox - position; 994 pOverall = maxBox - minBox; 995 } 996 else //-- area substitute for probability 997 { 998 pOverall = box.SurfaceArea(); 999 1000 const bool useMidSplit = true; 1001 //const bool useMidSplit = false; 1002 1003 //-- simplified computation for mid split 1004 const int axis2 = (axis + 1) % 3; 1005 const int axis3 = (axis + 2) % 3; 1006 1007 const float faceArea = 1008 (box.Max(axis2) - box.Min(axis2)) * 1009 (box.Max(axis3) - box.Min(axis3)); 1010 1011 pBack = pFront = pOverall * 0.5f + faceArea; 1012 } 1013 1014 //Debug << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl; 1015 //Debug << pFront << " " << pBack << " " << pOverall << endl; 1016 1017 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 1018 const float newCost = pvsBack * pBack + pvsFront * pFront; 1019 // float oldCost = leaf->mRays.size(); 1020 const float oldCost = (float)pvsSize * pOverall; 1021 1022 return (mCtDivCi + newCost) / oldCost; 1023 } 1024 915 1025 916 1026 … … 984 1094 candidateCost = SelectAxisAlignedPlane(plane, data, axis, 985 1095 &fGeom, &bGeom, 986 fArea, bArea); 1096 fArea, bArea, 1097 onlyAxisAligned); 987 1098 988 1099 if (candidateCost < lowestCost) … … 991 1102 lowestCost = candidateCost; 992 1103 993 //-- assign already computed values 1104 // assign already computed values 1105 // we can do this because we always save the 1106 // computed values from the axis aligned splits 994 1107 frontData.mGeometry = fGeom; 995 1108 backData.mGeometry = bGeom; … … 1123 1236 int totalPvs = 0; 1124 1237 1238 int limit; 1239 bool useRand; 1240 1241 // choose test rays randomly if too much 1242 if ((int)data.mRays->size() > mMaxTests) 1243 { 1244 useRand = true; 1245 limit = mMaxTests; 1246 } 1247 else 1248 { 1249 useRand = false; 1250 limit = (int)data.mRays->size(); 1251 } 1252 1253 for (int i = 0; i < limit; ++ i) 1254 { 1255 const int testIdx = useRand ? 1256 (int)RandomValue(0, (Real)((int)data.mRays->size() - 1)) : i; 1257 RayInfo rayInf = (*data.mRays)[testIdx]; 1258 1259 float t; 1260 VssRay *ray = rayInf.mRay; 1261 const int cf = rayInf.ComputeRayIntersection(candidatePlane, t); 1262 1263 if (cf >= 0) 1264 ++ raysFront; 1265 if (cf <= 0) 1266 ++ raysBack; 1267 1268 if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 1269 { 1270 sumBalancedRays += cf; 1271 } 1272 1273 if (mSplitPlaneStrategy & BALANCED_RAYS) 1274 { 1275 if (cf == 0) 1276 ++ sumRaySplits; 1277 } 1278 1279 if (mSplitPlaneStrategy & PVS) 1280 { 1281 // find front and back pvs for origing and termination object 1282 AddObjToPvs(ray->mTerminationObject, cf, pvsFront, pvsBack, totalPvs); 1283 AddObjToPvs(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs); 1284 } 1285 } 1286 1287 const float raysSize = (float)data.mRays->size() + Limits::Small; 1125 1288 if (mSplitPlaneStrategy & PVS) 1126 1289 { … … 1136 1299 mBox, 1137 1300 mEpsilon); 1138 1301 #if 0 1302 AxisAlignedBox3 fbox; 1303 AxisAlignedBox3 bbox; 1304 AxisAlignedBox3 box; 1305 fbox.Initialize(); 1306 bbox.Initialize(); 1307 box.Initialize(); 1308 1309 geomFront.IncludeInBox(fbox); 1310 geomBack.IncludeInBox(bbox); 1311 data.mGeometry->IncludeInBox(box); 1312 1313 areaFront = fbox.GetVolume(); 1314 areaBack = bbox.GetVolume(); 1315 1316 pOverall = box.GetVolume(); 1317 #else 1139 1318 areaFront = geomFront.GetArea(); 1140 1319 areaBack = geomBack.GetArea(); 1141 1320 1321 pOverall = data.mArea; 1322 #endif 1142 1323 pBack = areaBack; 1143 1324 pFront = areaFront; 1144 pOverall = data.mArea;1145 1325 } 1146 1326 else // use number of rays to approximate volume … … 1152 1332 } 1153 1333 1154 int limit;1155 bool useRand;1156 1157 // choose test rays randomly if too much1158 if ((int)data.mRays->size() > mMaxTests)1159 {1160 useRand = true;1161 limit = mMaxTests;1162 }1163 else1164 {1165 useRand = false;1166 limit = (int)data.mRays->size();1167 }1168 1169 for (int i = 0; i < limit; ++ i)1170 {1171 const int testIdx = useRand ?1172 (int)RandomValue(0, (Real)((int)data.mRays->size() - 1)) : i;1173 RayInfo rayInf = (*data.mRays)[testIdx];1174 1175 float t;1176 VssRay *ray = rayInf.mRay;1177 const int cf = rayInf.ComputeRayIntersection(candidatePlane, t);1178 1179 if (cf >= 0)1180 ++ raysFront;1181 if (cf <= 0)1182 ++ raysBack;1183 1184 if (mSplitPlaneStrategy & LEAST_RAY_SPLITS)1185 {1186 sumBalancedRays += cf;1187 }1188 1189 if (mSplitPlaneStrategy & BALANCED_RAYS)1190 {1191 if (cf == 0)1192 ++ sumRaySplits;1193 }1194 1195 if (mSplitPlaneStrategy & PVS)1196 {1197 // find front and back pvs for origing and termination object1198 AddObjToPvs(ray->mTerminationObject, cf, pvsFront, pvsBack, totalPvs);1199 AddObjToPvs(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs);1200 }1201 }1202 1203 const float raysSize = (float)data.mRays->size() + Limits::Small;1204 1334 1205 1335 if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) … … 1473 1603 } 1474 1604 1605 1606 1607 void VspBspTree::CheckValidy() 1608 { 1609 stack<BspNode *> nodeStack; 1610 1611 if (!mRoot) 1612 return; 1613 1614 nodeStack.push(mRoot); 1615 1616 while (!nodeStack.empty()) 1617 { 1618 BspNode *node = nodeStack.top(); 1619 nodeStack.pop(); 1620 1621 if (node->IsLeaf()) 1622 { 1623 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 1624 1625 if (node->TreeValid()) 1626 { 1627 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 1628 1629 if (viewCell->GetPvs().GetSize() > mMaxPvs) 1630 { 1631 while (!viewCell->mLeaves.empty()) 1632 { 1633 BspLeaf *l = viewCell->mLeaves.back(); 1634 l->SetTreeValid(false); 1635 PropagateUpValidity(l); 1636 1637 l->SetViewCell(GetOrCreateOutOfBoundsCell()); 1638 viewCell->mLeaves.pop_back(); 1639 } 1640 1641 mOutOfBoundsCell->GetPvs().AddPvs(viewCell->GetPvs()); 1642 1643 DEL_PTR(viewCell); 1644 } 1645 } 1646 } 1647 else 1648 { 1649 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1650 1651 nodeStack.push(interior->GetFront()); 1652 nodeStack.push(interior->GetBack()); 1653 } 1654 } 1655 } 1475 1656 1476 1657 void VspBspTree::CollectViewCells(BspNode *root, … … 2438 2619 2439 2620 //-- collect the leaves which haven't been found by ray casting 2440 vector<BspLeaf *> leaves; 2441 CollectLeaves(leaves, true, mMaxPvs); 2442 Debug << "found " << (int)leaves.size() << " new leaves" << endl << endl; 2443 // TODO 2444 CollectMergeCandidates(leaves); 2621 if (0) 2622 { 2623 vector<BspLeaf *> leaves; 2624 CollectLeaves(leaves, true, mMaxPvs); 2625 Debug << "found " << (int)leaves.size() << " new leaves" << endl << endl; 2626 CollectMergeCandidates(leaves); 2627 } 2445 2628 2446 2629 return numLeaves; … … 2519 2702 mMergeMaxCostRatio * BspMergeCandidate::sOverallCost)) 2520 2703 { 2521 / /Debug << "abs mergecost: " << mMergeQueue.top().GetMergeCost() << " rel mergecost: "2522 //<< mMergeQueue.top().GetMergeCost() / BspMergeCandidate::sOverallCost2523 // << " max ratio: " << mMergeMaxCostRatio << endl;2704 /*Debug << "abs mergecost: " << mMergeQueue.top().GetMergeCost() << " rel mergecost: " 2705 << mMergeQueue.top().GetMergeCost() / BspMergeCandidate::sOverallCost 2706 << " max ratio: " << mMergeMaxCostRatio << endl;*/ 2524 2707 BspMergeCandidate mc = mMergeQueue.top(); 2525 2708 mMergeQueue.pop(); … … 2532 2715 { 2533 2716 ViewCell::NewMail(); 2717 2534 2718 MergeViewCells(mc.GetLeaf1(), mc.GetLeaf2()); 2535 2719 -- nViewCells; … … 2709 2893 2710 2894 leaf->SetViewCell(vc2); // finally change view cell 2711 2712 //Debug << "new pvs: " << vc1->GetPvs().GetSize() + vc2->GetPvs().GetSize()2713 // << " (" << vc1->GetPvs().GetSize() << ", " << vc2->GetPvs().GetSize() << ")" << endl;2714 2715 2895 } 2716 2896 … … 2741 2921 if (shuffledCost1 < shuffledCost2) 2742 2922 { 2743 //Debug << "old cost: " << oldCost << ", new cost: " << shuffledCost1 << endl;2744 2923 ShuffleLeaf(leaf1, vc1, vc2); 2745 2924 leaf1->Mail(); … … 2747 2926 else 2748 2927 { 2749 //Debug << "old cost: " << oldCost << ", new cost: " << shuffledCost2 << endl;2750 2928 ShuffleLeaf(leaf2, vc2, vc1); 2751 2929 leaf2->Mail(); … … 2879 3057 2880 3058 //-- compute ratio of old cost 2881 // -- (added size of left and right view cell times pvs size)2882 // -- to new rendering cost (size of merged view cell times pvs size)3059 // (i.e., added size of left and right view cell times pvs size) 3060 // to new rendering cost (i.e, size of merged view cell times pvs size) 2883 3061 const float oldCost = GetLeaf1Cost() + GetLeaf2Cost(); 2884 3062 … … 2886 3064 (float)newPvs * (vc1->GetArea() + vc2->GetArea()); 2887 3065 2888 mMergeCost = newCost - oldCost;2889 3066 if (newPvs > sMaxPvsSize) // strong penalty if pvs size too large 2890 mMergeCost += 1.0; 2891 } 3067 { 3068 mMergeCost = 1e15f; 3069 } 3070 else 3071 { 3072 mMergeCost = newCost - oldCost; 3073 } 3074 } 3075 2892 3076 2893 3077 void BspMergeCandidate::SetLeaf1(BspLeaf *l) … … 2896 3080 } 2897 3081 3082 2898 3083 void BspMergeCandidate::SetLeaf2(BspLeaf *l) 2899 3084 { … … 2901 3086 } 2902 3087 3088 2903 3089 BspLeaf *BspMergeCandidate::GetLeaf1() 2904 3090 { … … 2906 3092 } 2907 3093 3094 2908 3095 BspLeaf *BspMergeCandidate::GetLeaf2() 2909 3096 { 2910 3097 return mLeaf2; 2911 3098 } 3099 2912 3100 2913 3101 bool BspMergeCandidate::Valid() const … … 2918 3106 } 2919 3107 3108 2920 3109 float BspMergeCandidate::GetMergeCost() const 2921 3110 { 2922 3111 return mMergeCost; 2923 3112 } 3113 2924 3114 2925 3115 void BspMergeCandidate::SetValid() -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r532 r542 60 60 /// how often this branch has missed the max-cost ratio 61 61 int mMaxCostMisses; 62 62 /// bounding box of current view space. 63 ///AxisAlignedBox3 mBbox; 64 63 65 /** Returns average ray contribution. 64 66 */ … … 78 80 mGeometry(NULL), 79 81 mMaxCostMisses(0) 82 //,mIsAxisAligned(false) 80 83 {} 81 84 … … 297 300 ViewCellContainer &viewCells, 298 301 bool onlyUnmailed = false) const; 302 303 /** returns maximal valid pvs. 304 */ 305 int GetMaxPvs() { return mMaxPvs;} 306 307 /** Checks validy of view cells. 308 if not valid, sets regions invalid and deletes view cell. 309 */ 310 void CheckValidy(); 311 299 312 protected: 300 313 … … 326 339 }; 327 340 341 float EvalAxisAlignedSplitCost(const VspBspTraversalData &data, 342 const AxisAlignedBox3 &box, 343 const int axis, 344 const float &position) const; 345 328 346 /** Returns view cell corresponding to 329 347 the invalid view space. If it does not exist, it is created. … … 447 465 BspNodeGeometry **backGeom, 448 466 float &frontArea, 449 float &backArea); 467 float &backArea, 468 bool useKdSplit); 450 469 451 470 /** Sorts split candidates for surface area heuristics for axis aligned splits. … … 779 798 static float sOverallCost; 780 799 800 /** Evaluates the merge costs of the leaves. 801 */ 802 void EvalMergeCost(); 803 781 804 protected: 782 805 … … 784 807 */ 785 808 float GetCost(ViewCell *vc) const; 786 /** Evaluates the merge costs of the leaves. 787 */ 788 void EvalMergeCost(); 789 809 790 810 int mLeaf1Id; 791 811 int mLeaf2Id; -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r517 r542 832 832 float pBack, pFront, pOverall; 833 833 834 if ( 0)834 if (1) 835 835 { 836 836 // box length substitute for probability … … 843 843 } 844 844 845 if ( 1) //-- area substitute for probability845 if (0) //-- area substitute for probability 846 846 { 847 847 pOverall = box.SurfaceArea(); -
trunk/VUT/GtpVisibilityPreprocessor/src/common.cpp
r372 r542 46 46 Real Limits::Threshold = 1e-6f; 47 47 Real Limits::Small = 0.01f; 48 Real Limits::Infinity = 1e20 f;48 Real Limits::Infinity = 1e20; 49 49 50 50
Note: See TracChangeset
for help on using the changeset viewer.