Changeset 1421 for GTP/trunk/Lib/Vis/Preprocessing/src
- Timestamp:
- 09/20/06 18:32:10 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1415 r1421 211 211 212 212 213 ////////////////////////////// //////////////////213 ////////////////////////////// 214 214 //-- max cost ratio for early tree termination 215 215 … … 221 221 222 222 223 ////////////////////////////// ///////////223 ////////////////////////////// 224 224 //-- factors for subdivision heuristics 225 225 … … 239 239 240 240 241 ///////////// ////////////////////241 ///////////// 242 242 //-- debug output 243 243 … … 294 294 AxisAlignedBox3 parentBox = leaf->GetBoundingBox(); 295 295 296 // update stats 297 mBvhStats.nodes += 2; // we have two new leaves296 // update stats: we have two new leaves 297 mBvhStats.nodes += 2; 298 298 299 299 if (tData.mDepth > mBvhStats.maxDepth) … … 306 306 307 307 308 ////////////////// //////////////308 ////////////////// 309 309 //-- create front and back leaf 310 310 … … 336 336 337 337 338 //////////////////////////////////////// ///////////////////////////338 //////////////////////////////////////// 339 339 //-- fill front and back traversal data with the new values 340 340 … … 393 393 if (!LocalTerminationCriteriaMet(tData) && !globalCriteriaMet) 394 394 { 395 ////////////// ////////////////////////////395 ////////////// 396 396 //-- continue subdivision 397 397 … … 412 412 413 413 414 /////////////////////////// //////////////414 /////////////////////////// 415 415 //-- push the new split candidates on the queue 416 416 … … 487 487 const float renderCostDecr = oldRenderCost - newRenderCost; 488 488 489 #ifdef _DEBUG489 //#ifdef _DEBUG 490 490 Debug << "old render cost: " << oldRenderCost << endl; 491 491 Debug << "new render cost: " << newRenderCost << endl; 492 492 Debug << "render cost decrease: " << renderCostDecr << endl; 493 #endif493 //#endif 494 494 splitCandidate.SetRenderCostDecrease(renderCostDecr); 495 495 … … 522 522 inline bool BvHierarchy::GlobalTerminationCriteriaMet(const BvhTraversalData &data) const 523 523 { 524 // matt: TODO525 return(0524 const bool terminationCriteriaMet = 525 (0 526 526 || (mBvhStats.Leaves() >= mTermMaxLeaves) 527 527 || (mGlobalCostMisses >= mTermGlobalCostMissTolerance) 528 528 //|| mOutOfMemory 529 529 ); 530 531 if (0 && terminationCriteriaMet) 532 { 533 Debug << "bvh global termination criteria met:" << endl; 534 Debug << "cost misses: " << mGlobalCostMisses << " " << mTermGlobalCostMissTolerance << endl; 535 Debug << "leaves: " << mBvhStats.Leaves() << " " << mTermMaxLeaves << endl; 536 } 537 538 return terminationCriteriaMet; 530 539 } 531 540 … … 1233 1242 void BvHierarchy::PrintSubdivisionStats(const SubdivisionCandidate &sc) 1234 1243 { 1235 const float costDecr = sc.GetRenderCostDecrease(); 1244 const float costDecr = 1245 sc.GetRenderCostDecrease();// / mHierarchyManager->GetViewSpaceBox().GetVolume(); 1236 1246 1237 1247 mSubdivisionStats 1238 << "#Leaves\n" << mBvhStats.Leaves() 1248 << "#Leaves\n" << mBvhStats.Leaves() << endl 1239 1249 << "#RenderCostDecrease\n" << costDecr << endl 1240 1250 << "#TotalRenderCost\n" << mTotalCost << endl; 1241 //<< "#AvgRenderCost\n" << avgRenderCost << endl;1242 1251 } 1243 1252 … … 1277 1286 return 0.0f; 1278 1287 1279 //////////////////// /////////1288 //////////////////// 1280 1289 //-- surface area heuristics 1281 1290 … … 1283 1292 const float area = box.SurfaceArea(); 1284 1293 1285 return (float)objects.size() * area ;1294 return (float)objects.size() * area / mHierarchyManager->GetViewSpaceBox().SurfaceArea(); 1286 1295 } 1287 1296 else 1288 { //////////////////// /////////1297 { //////////////////// 1289 1298 //-- render cost heuristics 1290 1299 … … 1647 1656 //-- we don't have to sort them here and an binary search 1648 1657 //-- for identifying if a object is in a leaf. 1649 1658 1650 1659 mBvhStats.Reset(); 1651 1660 mBvhStats.Start(); 1661 1652 1662 mBvhStats.nodes = 1; 1653 1663 mGlobalCostMisses = 0; 1664 1654 1665 // store pointer to this tree 1655 1666 BvhSubdivisionCandidate::sBvHierarchy = this; 1656 mBvhStats.nodes = 1; 1657 mGlobalCostMisses = 0; 1658 1667 1659 1668 // compute bounding box from objects 1660 1669 // note: we assume that root was already created -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1418 r1421 2427 2427 optFloat, 2428 2428 "hierarchy_term_min_global_cost_ratio=", 2429 "0. 00001");2429 "0.9"); 2430 2430 2431 2431 RegisterOption("Hierarchy.Termination.globalCostMissTolerance", -
GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp
r1420 r1421 267 267 { 268 268 case Intersectable::TRIANGLE_INTERSECTABLE: 269 { cout << "y";269 { 270 270 TriangleIntersectable *ti = dynamic_cast<TriangleIntersectable *>(obj); 271 271 polys.push_back(new Polygon3(ti->GetItem())); … … 273 273 } 274 274 case Intersectable::MESH_INSTANCE: 275 { cout << "x";275 { 276 276 MeshInstance *mi = dynamic_cast<MeshInstance *>(obj); 277 277 ExportMesh(mi->GetMesh()); 278 //polys.push_back(new Polygon3(ti->GetItem())); 279 break; 278 break; 280 279 } 281 280 default: -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1420 r1421 34 34 35 35 36 HierarchyManager::HierarchyManager(VspTree *vspTree, 37 const int objectSpaceSubdivisionType): 36 HierarchyManager::HierarchyManager(const int objectSpaceSubdivisionType): 38 37 mObjectSpaceSubdivisionType(objectSpaceSubdivisionType), 39 mVspTree(vspTree),40 38 mOspTree(NULL), 41 39 mBvHierarchy(NULL) … … 57 55 58 56 // hierarchy manager links view space partition and object space partition 57 mVspTree = new VspTree(); 59 58 mVspTree->mHierarchyManager = this; 60 59 … … 63 62 64 63 65 HierarchyManager::HierarchyManager( VspTree *vspTree,KdTree *kdTree):64 HierarchyManager::HierarchyManager(KdTree *kdTree): 66 65 mObjectSpaceSubdivisionType(KD_BASED_OBJ_SUBDIV), 67 mVspTree(vspTree),68 66 mBvHierarchy(NULL) 69 67 { … … 71 69 mOspTree->mVspTree = mVspTree; 72 70 71 mVspTree = new VspTree(); 73 72 mVspTree->mHierarchyManager = this; 74 73 … … 120 119 { 121 120 DEL_PTR(mOspTree); 122 //DEL_PTR(mVspTree);121 DEL_PTR(mVspTree); 123 122 DEL_PTR(mBvHierarchy); 124 123 } … … 232 231 bool HierarchyManager::GlobalTerminationCriteriaMet(SubdivisionCandidate *candidate) const 233 232 { 234 return (0 233 const bool terminationCriteriaMet = 234 (0 235 235 || (mHierarchyStats.Leaves() >= mTermMaxLeaves) 236 //|| (mGlobalCostMisses >= mTermGlobalCostMissTolerance)237 || candidate->GlobalTerminationCriteriaMet()236 || (mGlobalCostMisses >= mTermGlobalCostMissTolerance) 237 ||(candidate->GlobalTerminationCriteriaMet()) 238 238 ); 239 240 if (0 && terminationCriteriaMet) 241 { 242 Debug << "hierarchy global termination criteria met:" << endl; 243 Debug << "leaves: " << mHierarchyStats.Leaves() << " " << mTermMaxLeaves << endl; 244 Debug << "cost misses: " << mGlobalCostMisses << " " << mTermGlobalCostMissTolerance << endl; 245 } 246 return terminationCriteriaMet; 239 247 } 240 248 … … 306 314 mVspTree->PrepareConstruction(sampleRays, *viewSpaceRays); 307 315 316 mTotalCost = mVspTree->mTotalCost; 317 Debug << "\nreseting cost, new total cost: " << mTotalCost << endl; 318 308 319 mTQueue.Push(vsc); 309 320 } … … 328 339 329 340 { 330 cout << "starting bv hierarchy construction ... " << endl; 341 const long startTime = GetTime(); 342 343 cout << "preparing bv hierarchy construction ... " << endl; 331 344 mBvHierarchy->CreateRoot(objects); 332 345 … … 339 352 340 353 mTQueue.Push(sc); 354 cout << "finished bv hierarchy preparation in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 341 355 } 342 356 … … 357 371 358 372 mTotalCost = mOspTree->mTotalCost; 359 Debug << " reseting cost, new total cost: " << mTotalCost << endl;373 Debug << "\nreseting cost, new total cost: " << mTotalCost << endl; 360 374 361 375 mTQueue.Push(osc); … … 739 753 740 754 741 void HierarchyManager::PrintHierarchyStatistics(o fstream &stream) const755 void HierarchyManager::PrintHierarchyStatistics(ostream &stream) const 742 756 { 743 757 stream << mHierarchyStats << endl; 744 745 758 stream << "\nview space:" << endl << endl; 746 759 stream << mVspTree->GetStatistics() << endl; -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1419 r1421 139 139 140 140 public: 141 /** Constructor with the object space hierarchy type as argument. 142 */ 143 HierarchyManager(VspTree *vspTree, const int objectSpaceHierarchyType); 141 /** Constructor with the view space partition tree and 142 the object space hierarchy type as argument. 143 */ 144 HierarchyManager(const int objectSpaceHierarchyType); 144 145 /** Hack: OspTree will copy the content from this kd tree. 145 146 Only view space hierarchy will be constructed. 146 147 */ 147 HierarchyManager(VspTree *vspTree, KdTree *kdTree); 148 148 HierarchyManager(KdTree *kdTree); 149 150 /** Deletes space partition and view space partition. 151 */ 149 152 ~HierarchyManager(); 150 153 … … 196 199 float &contribution) const; 197 200 198 void PrintHierarchyStatistics(ofstream &stream) const; 199 201 /** Print out statistics. 202 */ 203 void PrintHierarchyStatistics(ostream &stream) const; 204 205 /** Returns the view space partition tree. 206 */ 200 207 VspTree *GetVspTree(); 201 208 209 /** Returns view space bounding box. 210 */ 202 211 AxisAlignedBox3 GetViewSpaceBox() const; 212 /** Returns object space bounding box. 213 */ 203 214 AxisAlignedBox3 GetObjectSpaceBox() const; 204 215 216 /** Exports object space hierarchy for visualization. 217 */ 205 218 void ExportObjectSpaceHierarchy( 206 219 Exporter *exporter, … … 209 222 const bool exportBounds = true) const; 210 223 211 224 /** Returns intersectable pierced by this ray. 225 */ 212 226 Intersectable *GetIntersectable( 213 227 const VssRay &ray, … … 216 230 friend ostream &operator<<(ostream &s, const HierarchyManager &hm) 217 231 { 218 hm. mHierarchyStats.Print(s);232 hm.PrintHierarchyStatistics(s); 219 233 return s; 220 234 } 235 221 236 222 237 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp
r1379 r1421 211 211 { 212 212 cout << "f"; 213 #if CONNECT_SEQUENTIAL_FACES 214 Face *face = LoadFace(str, vertices, hashTable); 215 if (!face) break; 216 217 faces.push_back(face); 218 219 if (faces.size() >= nMaxFaces) 213 214 if (loadMeshes) 220 215 { 221 ProcessMesh(faces, hashTable, root, parents); 216 Face *face = LoadFace(str, vertices, hashTable); 217 if (!face) break; 218 219 faces.push_back(face); 220 221 if (faces.size() >= nMaxFaces) 222 { 223 ProcessMesh(faces, hashTable, root, parents); 224 } 222 225 } 223 #else 224 Triangle3 triangle = LoadTriangle(str, vertices, hashTable); 226 else 227 { 228 Triangle3 triangle = LoadTriangle(str, vertices, hashTable); 225 229 226 TriangleIntersectable *obj = new TriangleIntersectable(triangle); 227 root->mGeometry.push_back(obj); 228 229 // matt: we don't really need to keep an additional data structure 230 // if working with triangles => remove this 231 if (parents) 232 { 233 FaceParentInfo info(obj, 0); 234 parents->push_back(info); 230 TriangleIntersectable *obj = new TriangleIntersectable(triangle); 231 root->mGeometry.push_back(obj); 232 233 // matt: we don't really need to keep an additional data structure 234 // if working with triangles => remove this 235 if (parents) 236 { 237 FaceParentInfo info(obj, 0); 238 parents->push_back(info); 239 } 235 240 } 236 #endif237 241 break; 238 242 } // end face … … 242 246 } 243 247 244 #if CONNECT_SEQUENTIAL_FACES 245 // there could be faces remaining 246 if (!faces.empty()) 247 { 248 ProcessMesh(faces, hashTable, root, parents); 249 } 250 #endif 248 if (loadMeshes) 249 { 250 // there could be faces remaining 251 if (!faces.empty()) 252 { 253 ProcessMesh(faces, hashTable, root, parents); 254 } 255 } 256 251 257 // reset tables 252 258 hashTable.clear(); -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1418 r1421 131 131 mBspTree(NULL), 132 132 mVspBspTree(NULL), 133 mVspTree(NULL),134 133 mHierarchyManager(NULL), 135 134 mViewCellsManager(NULL), … … 185 184 cout << "Deleting kd tree...\n"; 186 185 DEL_PTR(mKdTree); 187 cout << "done.\n";188 189 cout << "Deleting vsp tree...\n";190 DEL_PTR(mVspTree);191 186 cout << "done.\n"; 192 187 … … 505 500 const bool ishack = false; 506 501 if (ishack) 507 hierarchyManager = new HierarchyManager(m VspTree, mKdTree);502 hierarchyManager = new HierarchyManager(mKdTree); 508 503 else 509 hierarchyManager = new HierarchyManager( mVspTree,HierarchyManager::KD_BASED_OBJ_SUBDIV);504 hierarchyManager = new HierarchyManager(HierarchyManager::KD_BASED_OBJ_SUBDIV); 510 505 } 511 506 else if (strcmp(name, "bvh") == 0) 512 507 { 513 508 Debug << "hierarchy manager: bvh" << endl; 514 hierarchyManager = new HierarchyManager( mVspTree,HierarchyManager::BV_BASED_OBJ_SUBDIV);509 hierarchyManager = new HierarchyManager(HierarchyManager::BV_BASED_OBJ_SUBDIV); 515 510 } 516 511 else // only view space partition 517 512 { 518 513 Debug << "hierarchy manager: obj" << endl; 519 hierarchyManager = new HierarchyManager( mVspTree,HierarchyManager::NO_OBJ_SUBDIV);514 hierarchyManager = new HierarchyManager(HierarchyManager::NO_OBJ_SUBDIV); 520 515 } 521 516 … … 548 543 else if (strcmp(name, "vspOspTree") == 0) 549 544 { 550 mVspTree = new VspTree();545 Debug << "view cell type: VspOsp" << endl; 551 546 char buf[100]; 552 547 Environment::GetSingleton()->GetStringValue("Hierarchy.type", buf); … … 555 550 mViewCellsManager = new VspOspViewCellsManager(vcTree, mHierarchyManager); 556 551 } 557 else if (strcmp(name, "sceneDependent") == 0) 552 else if (strcmp(name, "sceneDependent") == 0) //TODO 558 553 { 559 554 Debug << "view cell type: Bsp" << endl; 560 561 //TODO 555 562 556 mBspTree = new BspTree(); 563 557 mViewCellsManager = new BspViewCellsManager(vcTree, mBspTree); -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1418 r1421 199 199 /// View space partition bsp tree 200 200 VspBspTree *mVspBspTree; 201 // view space partition tree 202 VspTree *mVspTree; 201 /// Hierarchy manager handling view space and object space partition 203 202 HierarchyManager *mHierarchyManager; 204 203 /// BSP tree representing the viewcells -
GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp
r1420 r1421 100 100 101 101 const Vector3 pt = ray.GetLoc() + t * dir; 102 102 #if _DEBUG 103 103 if (!pt.CheckValidity()) 104 104 { … … 106 106 cout << "v: " << pt << " t: " << t << " a: " << a << " b: " << b << " n: " << normal << endl; 107 107 } 108 108 #endif 109 109 const Vector3 w = pt - mVertices[1]; 110 110 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1420 r1421 4781 4781 GetRaySets(rays, mInitialSamples, constructionRays, &savedRays); 4782 4782 4783 Debug << "initial rays : " << (int)constructionRays.size() << endl;4783 Debug << "initial rays used for construction: " << (int)constructionRays.size() << endl; 4784 4784 Debug << "saved rays: " << (int)savedRays.size() << endl; 4785 4785 … … 4794 4794 4795 4795 // print subdivision statistics 4796 Debug << endl << endl << mHierarchyManager << endl;4796 Debug << endl << endl << *mHierarchyManager << endl; 4797 4797 //mHierarchyManager->PrintHierarchyStatistics(Debug); 4798 4798 … … 5583 5583 5584 5584 cout << "reseting pvs ... "; 5585 5586 5585 const bool startFromZero = true; 5587 5588 5586 5589 5587 // reset pvs and start over from zero … … 5632 5630 mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves); 5633 5631 float rc = 0; 5632 5634 5633 ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 5634 5635 5635 for (vit = leaves.begin(); vit != vit_end; ++ vit) 5636 5636 { … … 5639 5639 float vol = vc->GetVolume(); 5640 5640 rc += pvs * vol; 5641 5642 5641 } 5643 5642 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1416 r1421 979 979 }; 980 980 981 #define TEST_EVALUATION 1981 #define TEST_EVALUATION 0 982 982 983 983 /** -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1297 r1421 621 621 622 622 mHierarchyManager = 623 new HierarchyManager(mVspTree, HierarchyManager::KD_BASED_OBJ_SUBDIV); 623 new HierarchyManager(HierarchyManager::KD_BASED_OBJ_SUBDIV); 624 625 DEL_PTR(mHierarchyManager->mVspTree); 626 mHierarchyManager->mVspTree = mVspTree; 624 627 625 628 mObjectSpaceHierarchyType = OSP; … … 642 645 mObjectSpaceHierarchyType = BVH; 643 646 mHierarchyManager = 644 new HierarchyManager(mVspTree, HierarchyManager::BV_BASED_OBJ_SUBDIV); 647 new HierarchyManager(HierarchyManager::BV_BASED_OBJ_SUBDIV); 648 649 DEL_PTR(mHierarchyManager->mVspTree); 650 mHierarchyManager->mVspTree = mVspTree; 645 651 } 646 652 } … … 905 911 } 906 912 } 907 //cout << "\nview space box: " << mViewSpaceBox << endl; 908 } 909 910 911 void ViewCellsParseHandlers::CreateViewCellsManager(/*const char *name*/) 913 } 914 915 916 void ViewCellsParseHandlers::CreateViewCellsManager() 912 917 { 913 918 if (mViewSpaceHierarchyType == BSP) … … 920 925 { 921 926 Debug << "creating view cells manager: VspOsp" << endl; 922 923 927 // hack 924 928 mViewCellsManager = new VspOspViewCellsManager(mViewCellsTree, mHierarchyManager); -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1418 r1421 359 359 360 360 361 361 362 /*************************************************************************/ 362 363 /* class VspTree implementation */ … … 367 368 mRoot(NULL), 368 369 mOutOfBoundsCell(NULL), 369 mStoreRays( true),370 mStoreRays(false), 370 371 mTimeStamp(1), 371 372 mHierarchyManager(NULL) … … 566 567 if (0 && terminationCriteriaMet) 567 568 { 568 Debug << " globlal termination criteria met:" << endl;569 Debug << "vsp global termination criteria met:" << endl; 569 570 Debug << "cost misses: " << mGlobalCostMisses << " " << mTermGlobalCostMissTolerance << endl; 570 571 Debug << "leaves: " << mVspStats.Leaves() << " " << mMaxViewCells << endl; … … 696 697 ///////////// 697 698 //-- store pvs optained from rays 699 698 700 AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 699 701 … … 1295 1297 } 1296 1298 1297 1299 ///////// 1298 1300 //-- compute cost 1299 1301 … … 1479 1481 // the render cost decrase for this split 1480 1482 const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 1481 #ifdef _DEBUG 1482 Debug << "\neval vsp render cost decrease" << endl 1483 1484 //#ifdef _DEBUG 1485 Debug << "\nvsp render cost decrease" << endl 1483 1486 << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl 1484 1487 << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << " p: " << pOverall / viewSpaceVol << endl 1485 1488 << "old rc: " << normalizedOldRenderCost << " new rc: " << newRenderCost / viewSpaceVol << endl 1486 1489 << "render cost decrease: " << renderCostDecrease << endl; 1487 #endif1490 //#endif 1488 1491 return renderCostDecrease; 1489 1492 } … … 2681 2684 2682 2685 const int pvsSize = EvalPvsSize(rays); 2683 //Debug << "pvs size: " << (int)pvsSize << endl;2684 //Debug << "rays size: " << (int)rays.size() << endl; 2685 2686 2687 2688 ////////// 2686 2689 //-- prepare view space partition 2690 2687 2691 const float prop = mBoundingBox.GetVolume(); 2688 2692 … … 2696 2700 // create first view cell 2697 2701 CreateViewCell(vData, false); 2698 2702 2699 2703 #if WORK_WITH_VIEWCELL_PVS 2700 2704 // add first view cell to all the objects view cell pvs … … 2709 2713 #endif 2710 2714 2711 //-- compute first split candidate 2715 ////////////// 2716 //-- create the first split candidate 2712 2717 2713 2718 VspSubdivisionCandidate *splitCandidate = new VspSubdivisionCandidate(vData); -
GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
r1420 r1421 234 234 //-- load data as single triangles instead of whole meshes 235 235 236 //cout << "m";236 cout << "m"; 237 237 Mesh tempMesh(*mCurrentMesh); 238 238 ApplyTransformations(mTransformations, &tempMesh); … … 590 590 591 591 if (element == "Shape") { 592 //cout << "+";592 cout << "+"; 593 593 594 594 // reset current shape values … … 603 603 } 604 604 605 // todo 605 // todo: materials don't work proberly yet 606 606 if (element == "Material") { 607 607 StartMaterial(attributes);
Note: See TracChangeset
for help on using the changeset viewer.