- Timestamp:
- 08/25/06 18:25:09 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1279 r1286 1454 1454 1455 1455 1456 void BvHierarchy::ExportObjects(BvhLeaf *leaf, OUT_STREAM &stream) 1457 { 1458 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 1459 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 1460 { 1461 stream << (*oit)->GetId() << " "; 1462 } 1463 } 1464 1465 1456 1466 void BvHierarchy::ExportNode(BvhNode *node, OUT_STREAM &stream) 1457 1467 { … … 1460 1470 BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node); 1461 1471 1462 stream << "<Leaf "; 1463 stream << "objects=\""; 1472 stream << "<Leaf" 1473 << " min=\"" << leaf->GetBoundingBox().Min() 1474 << " max=\"" << leaf->GetBoundingBox().Max() 1475 << " objects=\""; 1464 1476 1465 //-- export objects in kd leaves1466 //if (mExportObjects)ExportObjects(leaf, stream);1477 //-- export objects 1478 ExportObjects(leaf, stream); 1467 1479 1468 1480 stream << "\" />" << endl; 1469 //stream << " </Leaf>" << endl;1470 1481 } 1471 1482 else … … 1473 1484 BvhInterior *interior = dynamic_cast<BvhInterior *>(node); 1474 1485 1475 stream << "<Interior box=\"" << interior->GetBoundingBox() << "\">" << endl; 1486 stream << "<Interior" 1487 << " min=\"" << interior->GetBoundingBox().Min() 1488 << " max=\"" << interior->GetBoundingBox().Max() 1489 << "\">" << endl; 1476 1490 1477 1491 ExportNode(interior->GetBack(), stream); -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1259 r1286 640 640 void ExportNode(BvhNode *node, OUT_STREAM &stream); 641 641 642 void ExportObjects(BvhLeaf *leaf, OUT_STREAM &stream); 643 642 644 /** Returns estimated memory usage of tree. 643 645 */ -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1284 r1286 260 260 261 261 262 void HierarchyManager::Construct2(const VssRayContainer &sampleRays,263 const ObjectContainer &objects,264 AxisAlignedBox3 *forcedViewSpace)265 {266 // rays clipped in view space and in object space267 RayInfoContainer *viewSpaceRays = new RayInfoContainer();268 RayInfoContainer *objectSpaceRays = new RayInfoContainer();269 270 271 /////////////////////////////////////////////////////////////272 // view space space partition273 /////////////////////////////////////////////////////////////274 275 #if 0276 // makes no sense otherwise because only one kd cell available277 // during view space partition278 const bool savedCountMethod = mVspTree.mUseKdPvsForHeuristics;279 const bool savedStoreMethod = mVspTree.mStoreObjectPvs;280 281 mVspTree.mUseKdPvsForHeuristics = false;282 mVspTree.mStoreObjectPvs = false;283 #endif284 SubdivisionCandidate *vsc =285 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays);286 287 // add to queue288 mTQueue.Push(vsc);289 290 long startTime = GetTime();291 cout << "starting vsp contruction ... " << endl;292 293 mVspTree->mVspStats.Reset();294 mVspTree->mVspStats.Start();295 296 int i = 0;297 298 // all objects can be seen from everywhere299 mTotalCost = (float)dynamic_cast<VspTree::VspSubdivisionCandidate *>(vsc)->mParentData.mPvs;300 301 const bool repairQueue = false;302 303 // process view space candidates304 RunConstruction(repairQueue);305 306 cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl;307 mVspTree->mVspStats.Stop();308 309 310 /////////////////////////////////////////////////////////////311 // object space partition312 /////////////////////////////////////////////////////////////313 314 315 Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl;316 cout << "starting osp contruction ... " << endl;317 318 // start with one big kd cell - all objects can be seen from everywhere319 // note: only true for view space = object space320 321 // compute first candidate322 SubdivisionCandidate *osc =323 mOspTree->PrepareConstruction(sampleRays, objects, forcedViewSpace, *objectSpaceRays);324 325 Debug << "reseting cost, new total cost: " << mTotalCost << endl;326 mTotalCost = mOspTree->mTotalCost;327 328 mTQueue.Push(osc);329 330 mOspTree->mOspStats.Reset();331 mOspTree->mOspStats.Start();332 333 startTime = GetTime();334 335 // process object space candidates336 RunConstruction(repairQueue);337 338 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;339 340 mOspTree->mOspStats.Stop();341 342 //////////////////////////343 // matt: only for debugging purpose344 345 const float rc = mOspTree->EvalRenderCost(sampleRays);346 347 Debug << "My render cost evalulation: " << rc << endl;348 349 #if 0350 // reset parameters351 mVspTree->mUseKdPvsForHeuristics = savedCountMethod;352 mVspTree->mStoreObjectPvs = savedStoreMethod;353 #endif354 }355 356 357 262 void HierarchyManager::Construct3(const VssRayContainer &sampleRays, 358 263 const ObjectContainer &objects, … … 372 277 mTQueue.Push(sc); 373 278 374 cout << "starting vsp con truction ... " << endl;279 cout << "starting vsp construction ... " << endl; 375 280 376 281 long startTime = GetTime(); … … 552 457 void HierarchyManager::ExportObjectSpaceHierarchyForViz(const ObjectContainer &objects) const 553 458 { 554 if (mOspTree && mOspTree->GetRoot()) 555 { 556 //-- export final object partition 557 Exporter *exporter = Exporter::GetExporter("final_object_partition.wrl"); 459 switch (mObjectSpaceSubdivisonType) 460 { 461 case KD_BASED_OBJ_SUBDIV: 462 { 463 ExportOspTreeForViz(objects); 464 break; 465 } 466 case BV_BASED_OBJ_SUBDIV: 467 { 468 ExportBvhForViz(objects); 469 break; 470 } 471 default: 472 break; 473 } 474 } 475 476 477 void HierarchyManager::ExportBvhForViz(const ObjectContainer &objects) const 478 { 479 } 480 481 482 void HierarchyManager::ExportOspTreeForViz(const ObjectContainer &objects) const 483 { 484 //-- export final object partition 485 Exporter *exporter = Exporter::GetExporter("final_object_partition.wrl"); 558 486 559 if (exporter) 560 { 561 cout << "exporting object space partition ... "; 562 563 if (1) 564 { 565 exporter->ExportGeometry(objects); 566 } 487 if (exporter) 488 { 489 cout << "exporting object space partition ... "; 490 491 if (1) exporter->ExportGeometry(objects); 567 492 568 493 #if 0 569 570 494 // export rays 495 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 571 496 #endif 572 573 exporter->SetWireframe(); 574 575 const int colorCode = 0; 576 const int maxPvs = 0;//mOspTree.GetStatistics().maxPvs; 577 578 exporter->ExportOspTree(*mOspTree, 0); 579 580 delete exporter; 581 582 cout << "finished" << endl; 583 } 584 } 585 } 586 587 } 497 exporter->SetWireframe(); 498 499 const int colorCode = 0; 500 const int maxPvs = 0;//mOspTree.GetStatistics().maxPvs; 501 502 exporter->ExportOspTree(*mOspTree, 0); 503 delete exporter; 504 505 cout << "finished" << endl; 506 } 507 } 508 509 510 void HierarchyManager::Construct2(const VssRayContainer &sampleRays, 511 const ObjectContainer &objects, 512 AxisAlignedBox3 *forcedViewSpace) 513 { 514 // rays clipped in view space and in object space 515 RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 516 517 ///////////////////////////////////////////////////////////// 518 // view space space partition 519 ///////////////////////////////////////////////////////////// 520 521 // use objects for evaluating vsp tree construction 522 const int savedobjectSpaceSubdivisionType = mObjectSpaceSubdivisonType; 523 mObjectSpaceSubdivisonType = NO_OBJ_SUBDIV; 524 525 SubdivisionCandidate *vsc = 526 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays); 527 528 // add to queue 529 mTQueue.Push(vsc); 530 531 long startTime = GetTime(); 532 cout << "starting vsp construction ... " << endl; 533 534 mVspTree->mVspStats.Reset(); 535 mVspTree->mVspStats.Start(); 536 537 int i = 0; 538 539 // all objects can be seen from everywhere 540 mTotalCost = (float)dynamic_cast<VspTree::VspSubdivisionCandidate *>(vsc)->mParentData.mPvs; 541 542 const bool repairQueue = false; 543 544 // process view space candidates 545 RunConstruction(repairQueue); 546 547 cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 548 mVspTree->mVspStats.Stop(); 549 550 // reset subdivision type 551 mObjectSpaceSubdivisonType = savedobjectSpaceSubdivisionType; 552 553 554 ///////////////////////////////////////////////////////////// 555 // object space partition 556 ///////////////////////////////////////////////////////////// 557 558 559 switch (mObjectSpaceSubdivisonType) 560 { 561 case KD_BASED_OBJ_SUBDIV: 562 { 563 ConstructOspTree(sampleRays, objects, forcedViewSpace); 564 break; 565 } 566 case BV_BASED_OBJ_SUBDIV: 567 { 568 ConstructBvHierarchy(sampleRays, objects, forcedViewSpace); 569 break; 570 } 571 default: 572 break; 573 } 574 } 575 576 577 void HierarchyManager::ConstructBvHierarchy(const VssRayContainer &sampleRays, 578 const ObjectContainer &objects, 579 AxisAlignedBox3 *forcedViewSpace) 580 581 { 582 Debug << "\n$$$$$$$$$ bv hierarchy construction $$$$$$$$$$\n" << endl; 583 cout << "starting bv hierarchy construction ... " << endl; 584 585 // start with one big kd cell - all objects can be seen from everywhere 586 // note: only true for view space = object space 587 588 ObjectContainer obj = objects; 589 590 // compute first candidate 591 SubdivisionCandidate *sc = 592 mBvHierarchy->PrepareConstruction(sampleRays, obj, forcedViewSpace); 593 594 Debug << "reseting cost, new total cost: " << mTotalCost << endl; 595 mTotalCost = mOspTree->mTotalCost; 596 597 mTQueue.Push(sc); 598 599 mOspTree->mOspStats.Reset(); 600 mOspTree->mOspStats.Start(); 601 602 const long startTime = GetTime(); 603 const bool repairQueue = false; 604 605 // process object space candidates 606 RunConstruction(repairQueue); 607 608 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 609 610 mOspTree->mOspStats.Stop(); 611 612 ////////////////////////// 613 // matt: only for debugging purpose 614 615 const float rc = mOspTree->EvalRenderCost(sampleRays); 616 617 Debug << "My render cost evalulation: " << rc << endl; 618 } 619 620 621 void HierarchyManager::ConstructOspTree(const VssRayContainer &sampleRays, 622 const ObjectContainer &objects, 623 AxisAlignedBox3 *forcedViewSpace) 624 625 { 626 RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 627 628 Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl; 629 cout << "starting osp tree construction ... " << endl; 630 631 // start with one big kd cell - all objects can be seen from everywhere 632 // note: only true for view space = object space 633 634 // compute first candidate 635 SubdivisionCandidate *osc = 636 mOspTree->PrepareConstruction(sampleRays, objects, forcedViewSpace, *objectSpaceRays); 637 638 Debug << "reseting cost, new total cost: " << mTotalCost << endl; 639 mTotalCost = mOspTree->mTotalCost; 640 641 mTQueue.Push(osc); 642 643 mOspTree->mOspStats.Reset(); 644 mOspTree->mOspStats.Start(); 645 646 const long startTime = GetTime(); 647 const bool repairQueue = false; 648 649 // process object space candidates 650 RunConstruction(repairQueue); 651 652 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 653 654 mOspTree->mOspStats.Stop(); 655 656 ////////////////////////// 657 // matt: only for debugging purpose 658 659 const float rc = mOspTree->EvalRenderCost(sampleRays); 660 661 Debug << "My render cost evalulation: " << rc << endl; 662 } 663 664 } -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1283 r1286 100 100 HierarchyManager(VspTree *vspTree, KdTree *kdTree); 101 101 102 ~HierarchyManager(); 103 102 104 /** Constructs the view space and object space subdivision from a given set of rays 103 105 and a set of objects. … … 153 155 154 156 void ExportObjectSpaceHierarchyForViz(const ObjectContainer &objects) const; 155 ~HierarchyManager(); 157 156 158 157 159 protected: … … 197 199 void CollectObjectSpaceDirtyList(SubdivisionCandidateContainer &dirtyList); 198 200 201 void ExportOspTreeForViz(const ObjectContainer &objects) const; 202 void ExportBvhForViz(const ObjectContainer &objects) const; 203 204 void ConstructBvHierarchy( 205 const VssRayContainer &sampleRays, 206 const ObjectContainer &objects, 207 AxisAlignedBox3 *forcedViewSpace); 208 209 void ConstructOspTree( 210 const VssRayContainer &sampleRays, 211 const ObjectContainer &objects, 212 AxisAlignedBox3 *forcedViewSpace); 199 213 200 214 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r1233 r1286 331 331 ProcessMultipleRefs(front); 332 332 333 334 333 delete leaf; 334 return node; 335 335 } 336 336 … … 852 852 KdNode * 853 853 KdTree::FindRandomNeighbor(KdNode *n, 854 855 854 bool onlyUnmailed 855 ) 856 856 { 857 857 stack<KdNode *> nodeStack; … … 1288 1288 IN_STREAM stream(filename.c_str(), IN_BIN_MODE); 1289 1289 1290 //if (!stream.is_open()) return false;1290 if (!stream.is_open()) return false; 1291 1291 1292 1292 std::stable_sort(objects.begin(), objects.end(), ilt); … … 1299 1299 { 1300 1300 Intersectable *obj = *oit; 1301 1302 1301 // compute bounding box of view space 1303 1302 mBox.Include(obj->GetBox()); … … 1334 1333 1335 1334 ++ mStat.splits[interior->mAxis]; 1336 1337 //Debug << "plane: " << interior->mAxis << " " << interior->mPosition << endl;1338 //Debug << "box: " << tData.mBox << endl;1339 1335 1340 1336 // compute new bounding box … … 1355 1351 } 1356 1352 } 1357 1358 1353 Debug << mStat << endl; 1359 1354 -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r1233 r1286 576 576 577 577 }; 578 579 580 578 581 579 -
GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp
r1281 r1286 158 158 159 159 SceneGraphNode *root = new SceneGraphNode; 160 cout<<"HERE2!\n"; 160 161 161 int meshGrouping; 162 162 Environment::GetSingleton()->GetIntValue("ObjParser.meshGrouping", meshGrouping); -
GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp
r1264 r1286 643 643 644 644 float sum = (float)totalVol * sizeBox; 645 646 645 647 646 Debug << "here82 render cost: " << renderCost / viewSpaceVol << endl; … … 2570 2569 stream << "objects=\""; 2571 2570 2572 // --export objects in kd leaves2571 // export objects in kd leaves 2573 2572 //if (mExportObjects) ExportObjects(leaf, stream); 2574 2573 2575 2574 stream << "\" />" << endl; 2576 //stream << " </Leaf>" << endl;2577 2575 } 2578 2576 else … … 2658 2656 2659 2657 SubdivisionCandidate * OspTree::PrepareConstruction(const VssRayContainer &sampleRays, 2660 2661 2662 2658 const ObjectContainer &objects, 2659 AxisAlignedBox3 *forcedObjectSpace, 2660 RayInfoContainer &rays) 2663 2661 { 2664 2662 // store pointer to this tree -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1283 r1286 425 425 // default view space is the extent of the scene 426 426 mViewCellsManager->SetViewSpaceBox(mSceneGraph->GetBox()); 427 428 429 427 } 430 428 … … 1231 1229 } 1232 1230 1231 1233 1232 int Preprocessor::CastRay( 1234 1233 const Vector3 &viewPoint, -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
r1283 r1286 61 61 <Tool 62 62 Name="VCCLCompilerTool" 63 Optimization="0" 64 InlineFunctionExpansion="0" 65 FavorSizeOrSpeed="0" 63 Optimization="3" 64 GlobalOptimizations="TRUE" 65 InlineFunctionExpansion="2" 66 EnableIntrinsicFunctions="TRUE" 67 FavorSizeOrSpeed="1" 68 OmitFramePointers="TRUE" 69 EnableFiberSafeOptimizations="TRUE" 70 OptimizeForProcessor="3" 66 71 OptimizeForWindowsApplication="TRUE" 67 72 AdditionalIncludeDirectories="..\include;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost" … … 73 78 RuntimeTypeInfo="TRUE" 74 79 UsePrecompiledHeader="0" 80 BrowseInformation="1" 75 81 WarningLevel="2" 76 82 Detect64BitPortabilityProblems="TRUE" -
GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
r1283 r1286 70 70 <Tool 71 71 Name="VCCLCompilerTool" 72 Optimization="0" 72 Optimization="3" 73 GlobalOptimizations="TRUE" 74 InlineFunctionExpansion="2" 75 EnableIntrinsicFunctions="TRUE" 76 FavorSizeOrSpeed="1" 77 OptimizeForProcessor="3" 78 OptimizeForWindowsApplication="TRUE" 73 79 AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\MultiLevelRayTracing" 74 80 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" … … 76 82 RuntimeTypeInfo="TRUE" 77 83 UsePrecompiledHeader="0" 84 BrowseInformation="1" 78 85 WarningLevel="3" 79 86 Detect64BitPortabilityProblems="TRUE" -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1284 r1286 304 304 else 305 305 mChildren.erase(it); 306 } 307 308 309 void ViewCellInterior::ReplaceChildLink(ViewCell *prev, ViewCell *cur) 310 { 311 // erase leaf from old view cell 312 ViewCellContainer::iterator it = mChildren.begin(); 313 314 for (; (*it) != prev; ++ it); 315 if (it == mChildren.end()) 316 { 317 Debug << "error: child link not found" << endl; 318 } 319 else 320 { 321 (*it) = cur; 322 } 306 323 } 307 324 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r1284 r1286 302 302 */ 303 303 void SetupChildLink(ViewCell *l); 304 void ReplaceChildLink(ViewCell *prev, ViewCell *cur); 305 304 306 void RemoveChildLink(ViewCell *l); 305 307 bool IsLeaf() const; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1284 r1286 362 362 startTime = GetTime(); 363 363 364 // -- stats after con truction364 // -- stats after construction 365 365 ResetViewCells(); 366 366 Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl; … … 480 480 } 481 481 482 483 //-- visualization484 485 482 if (mShowVisualization) 486 483 { 484 //-- visualization 487 485 VssRayContainer visualizationSamples; 488 486 … … 690 688 691 689 mVspBspTree->Export(stream); 692 stream << endl <<"</ViewSpaceHierarchy>" << endl;690 stream << "</ViewSpaceHierarchy>" << endl; 693 691 694 692 stream << "</VisibilitySolution>" << endl; … … 4800 4798 Debug << "saved rays: " << (int)savedRays.size() << endl; 4801 4799 4802 long startTime;4803 4804 4800 //mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox); 4805 4801 mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox); … … 4827 4823 4828 4824 4829 startTime = GetTime();4825 const long startTime = GetTime(); 4830 4826 4831 4827 cout << "Computing remaining ray contributions ... "; … … 5389 5385 stream << "<ViewSpaceHierarchy type=\"vsp\"" 5390 5386 << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\"" 5391 << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl;5387 << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\">" << endl; 5392 5388 5393 5389 mHierarchyManager->GetVspTree()->Export(stream); 5394 stream << endl <<"</ViewSpaceHierarchy>" << endl;5390 stream << "</ViewSpaceHierarchy>" << endl; 5395 5391 5396 5392 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1284 r1286 89 89 , mCurrentBspNode(NULL) 90 90 , mCurrentVspNode(NULL) 91 , mCurrentKdNode(NULL) 91 , mCurrentOspNode(NULL) 92 , mCurrentBvhNode(NULL) 92 93 , mObjects(objects) 93 94 , mBoundingBoxConverter(bconverter) … … 114 115 115 116 if (element == "BoundingBoxes") 117 { 116 118 EndBoundingBoxes(); 119 } 117 120 118 121 if (element == "ViewCells") 122 { 119 123 EndViewCells(); 120 121 // inside the view cell description 122 if (mCurrentState == PARSE_VIEWCELLS) 123 { 124 if (element == "Interior") 125 EndViewCellInterior(); 126 } 127 else 128 { 129 if (element == "Interior") 130 EndBspInterior(); 124 } 125 126 if (element == "ObjectSpaceHierarchy") 127 { 128 EndObjectSpaceHierarchy(); 131 129 } 132 130 133 131 // finished, create view cells manager 134 132 if (element == "VisibilitySolution") 133 { 135 134 CreateViewCellsManager(); 135 } 136 137 if (element == "Interior") 138 { 139 switch (mCurrentState) 140 { 141 case PARSE_VIEWCELLS: 142 EndViewCellInterior(); 143 break; 144 case PARSE_OBJECTSPACE_HIERARCHY: 145 EndObjectSpaceHierarchyInterior(); 146 break; 147 case PARSE_VIEWSPACE_HIERARCHY: 148 EndViewSpaceHierarchyInterior(); 149 break; 150 default: 151 break; 152 } 153 } 154 } 155 156 157 void ViewCellsParseHandlers::EndObjectSpaceHierarchy() 158 { 159 if (mObjectSpaceHierarchyType == OSP) 160 { 161 mHierarchyManager->mOspTree->InsertObjects( 162 mHierarchyManager->mOspTree->mRoot, *mObjects); 163 } 164 } 165 166 167 void ViewCellsParseHandlers::EndViewSpaceHierarchyInterior() 168 { 169 switch (mViewSpaceHierarchyType) 170 { 171 case BSP: 172 EndBspInterior(); 173 break; 174 case VSP: 175 EndVspInterior(); 176 break; 177 default: 178 Debug << "not implemented view space hierarchy type " << mViewSpaceHierarchyType << endl; 179 break; 180 } 181 } 182 183 184 void ViewCellsParseHandlers::EndObjectSpaceHierarchyInterior() 185 { 186 switch (mObjectSpaceHierarchyType) 187 { 188 case OSP: 189 EndOspInterior(); 190 break; 191 case BVH: 192 EndBvhInterior(); 193 break; 194 default: 195 Debug << "not implemented object space hierarchy type " << mViewSpaceHierarchyType << endl; 196 break; 197 } 136 198 } 137 199 … … 143 205 { cout << "]"; 144 206 mCurrentBspNode = mCurrentBspNode->GetParent(); 207 } 208 } 209 210 211 void ViewCellsParseHandlers::EndBvhInterior() 212 { 213 // go one up in the tree 214 if (mCurrentBvhNode->GetParent()) 215 { cout << "]"; 216 mCurrentBvhNode = mCurrentBvhNode->GetParent(); 217 } 218 } 219 220 221 void ViewCellsParseHandlers::EndOspInterior() 222 { 223 // go one up in the tree 224 if (mCurrentOspNode->mParent) 225 { cout << "]"; 226 mCurrentOspNode = mCurrentOspNode->mParent; 145 227 } 146 228 } … … 243 325 StartVspInterior(attributes); 244 326 } 245 246 327 if (element == "Leaf") 247 328 { … … 289 370 AttributeList& attributes) 290 371 { 291 //if (!mViewCellsManager)return;292 293 372 //-- use cell type according to the chosen method 294 295 373 switch (mViewSpaceHierarchyType) 296 374 { 297 298 299 300 301 302 303 304 305 375 case BSP: 376 StartBspElement(element, attributes); 377 break; 378 case VSP: 379 StartVspElement(element, attributes); 380 break; 381 default: 382 Debug << "not implemented" << endl; 383 break; 306 384 } 307 385 } … … 412 490 413 491 414 void ViewCellsParseHandlers:: ParseViewCellPvs(ViewCell *viewCell,492 void ViewCellsParseHandlers::StartViewCellPvs(ViewCell *viewCell, 415 493 AttributeList& attributes) 416 494 { … … 433 511 while (1) 434 512 { 435 int index = strtol(ptr, &endptr, 10); 436 437 if (ptr == endptr) 438 break; 513 const int index = strtol(ptr, &endptr, 10); 514 515 if (ptr == endptr) break; 439 516 440 517 objIndices.push_back(index); … … 454 531 455 532 ObjectContainer::iterator oit = 456 lower_bound(mObjects->begin(), mObjects->end(), (Intersectable *)&dummyInst, ilt); 533 lower_bound(mObjects->begin(), 534 mObjects->end(), 535 (Intersectable *)&dummyInst, ilt); 457 536 458 537 if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) … … 551 630 void ViewCellsParseHandlers::StartObjectSpaceHierarchy(AttributeList& attributes) 552 631 { 553 int len = attributes.getLength(); 554 632 const int len = attributes.getLength(); 555 633 Vector3 bmin, bmax; 556 cout << "here3" << endl; 634 557 635 for (int i = 0; i < len; ++ i) 558 636 { … … 567 645 { 568 646 cout << "\nobject space hierarchy: Osp" << endl; 647 569 648 mHierarchyManager = 570 649 new HierarchyManager(mVspTree, HierarchyManager::KD_BASED_OBJ_SUBDIV); 650 651 mObjectSpaceHierarchyType = OSP; 652 653 //std::stable_sort(objects.begin(), objects.end(), ilt); 654 mHierarchyManager->mOspTree->mBoundingBox.Initialize(); 655 ObjectContainer::const_iterator oit, oit_end = mObjects->end(); 656 657 //-- compute bounding box 658 for (oit = mObjects->begin(); oit != oit_end; ++ oit) 659 { 660 Intersectable *obj = *oit; 661 // compute bounding box of view space 662 mHierarchyManager->mOspTree->mBoundingBox.Include(obj->GetBox()); 663 } 571 664 } 572 665 else if (strcmp(ptr, "bvh") == 0) 573 666 { 574 667 cout << "\nobject space hierarchy: Bvh" << endl; 668 mObjectSpaceHierarchyType = BVH; 575 669 mHierarchyManager = 576 670 new HierarchyManager(mVspTree, HierarchyManager::BV_BASED_OBJ_SUBDIV); … … 579 673 } 580 674 } 581 582 675 583 676 … … 675 768 { 676 769 // add to invalid view space 677 if (mViewSpaceHierarchyType== ViewCellsManager::VSP_BSP) 678 { 679 leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell()); 680 leaf->SetTreeValid(false); 681 mVspBspTree->PropagateUpValidity(leaf); 682 } 770 leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell()); 771 leaf->SetTreeValid(false); 772 mVspBspTree->PropagateUpValidity(leaf); 683 773 } 684 774 } … … 736 826 } 737 827 738 ParseViewCellPvs(viewCell, attributes);828 StartViewCellPvs(viewCell, attributes); 739 829 740 830 // collect leaves … … 746 836 { 747 837 ViewCellInterior* interior = new ViewCellInterior(); 748 cout << "here7"<<endl;838 749 839 if (mCurrentViewCell) // replace NULL child of parent with current node 750 840 { … … 760 850 mCurrentViewCell = interior; 761 851 762 ParseViewCellPvs(interior, attributes);852 StartViewCellPvs(interior, attributes); 763 853 } 764 854 … … 767 857 { 768 858 ViewCellContainer::iterator it, it_end = mViewCells.end(); 769 Debug<< endl;859 cout << "\n====================" << endl << endl; 770 860 for (it = mViewCells.begin(); it != it_end; ++ it) 771 861 { 772 Debug<< (*it)->GetId() << " ";773 } 774 Debug<< endl;862 cout << (*it)->GetId() << " "; 863 } 864 cout << endl; 775 865 if (mViewSpaceHierarchyType == BSP) 776 866 { … … 799 889 else 800 890 { 801 vc->GetParent()->SetupChildLink(bspVc); 802 vc->GetParent()->RemoveChildLink(vc); 891 vc->GetParent()->ReplaceChildLink(vc, bspVc); 803 892 } 804 893 … … 806 895 (*vit) = bspVc; 807 896 } 808 809 897 } 810 898 else if (mViewSpaceHierarchyType == VSP) … … 834 922 else 835 923 { 836 vc->GetParent()->SetupChildLink(vspVc); 837 vc->GetParent()->RemoveChildLink(vc); 924 vc->GetParent()->ReplaceChildLink(vc, vspVc); 838 925 } 839 926 … … 849 936 } 850 937 } 851 Debug<< "************************" << endl;938 cout << "************************" << endl; 852 939 it_end = mViewCells.end(); 853 940 for (it = mViewCells.begin(); it != it_end; ++ it) 854 941 { 855 Debug<< (*it)->GetId() << " ";856 } 857 Debug<< endl;942 cout << (*it)->GetId() << " "; 943 } 944 cout << endl; 858 945 cout << "\nview space box: " << mViewSpaceBox << endl; 859 946 } … … 862 949 void ViewCellsParseHandlers::CreateViewCellsManager(/*const char *name*/) 863 950 { 864 if (mViewSpaceHierarchyType == BSP) //951 if (mViewSpaceHierarchyType == BSP) 865 952 { 866 953 Debug << "creating view cells manager: VspBsp" << endl; 867 954 868 //mVspBspTree = new VspBspTree();869 955 mViewCellsManager = new VspBspViewCellsManager(mViewCellsTree, mVspBspTree); 870 956 } … … 950 1036 if (vit == mViewCells.end()) 951 1037 cout << "error: view cell " << viewCellId << " not found" << endl; 952 1038 953 1039 VspViewCell *viewCell = dynamic_cast<VspViewCell *>(*vit); 954 1040 955 1041 if (viewCell->GetId() == viewCellId) 956 1042 { … … 964 1050 } 965 1051 else 966 { 1052 { 967 1053 // add to invalid view space 968 1054 leaf->SetViewCell(mVspTree->GetOrCreateOutOfBoundsCell()); … … 986 1072 if (attrName == "plane") 987 1073 { 988 sscanf(ptr, "% d %f", &plane.mAxis, &plane.mPosition);1074 sscanf(ptr, "%f %d", &plane.mPosition, &plane.mAxis); 989 1075 } 990 1076 } … … 994 1080 if (mCurrentVspNode) // replace NULL child of parent with current node 995 1081 { 996 VspInterior *current = dynamic_cast<VspInterior *>(mCurrentVspNode); 997 998 current->ReplaceChildLink(NULL, interior); 999 interior->SetParent(current); 1082 VspInterior *parent = dynamic_cast<VspInterior *>(mCurrentVspNode); 1083 1084 parent->ReplaceChildLink(NULL, interior); 1085 interior->SetParent(parent); 1086 1087 AxisAlignedBox3 frontBox, backBox; 1088 1089 parent->GetBoundingBox().Split(parent->GetPlane().mAxis, parent->GetPlane().mPosition, frontBox, backBox); 1090 if (parent->GetFront() == interior) 1091 interior->SetBoundingBox(frontBox); 1092 else 1093 interior->SetBoundingBox(backBox); 1000 1094 } 1001 1095 else 1002 1096 { 1003 1097 mVspTree->mRoot = interior; 1098 interior->SetBoundingBox(mVspTree->GetBoundingBox()); 1004 1099 } 1005 1100 … … 1021 1116 if (attrName == "plane") 1022 1117 { 1023 sscanf(ptr, "%d %f", 1024 &plane.mAxis, &plane.mPosition); 1118 sscanf(ptr, "%f %d", &plane.mPosition, &plane.mAxis); 1025 1119 } 1026 1120 } … … 1031 1125 interior->mPosition = plane.mPosition; 1032 1126 1033 if (mCurrent KdNode) // replace NULL child of parent with current node1034 { 1035 KdInterior *parent = dynamic_cast<KdInterior *>(mCurrent KdNode);1127 if (mCurrentOspNode) // replace NULL child of parent with current node 1128 { 1129 KdInterior *parent = dynamic_cast<KdInterior *>(mCurrentOspNode); 1036 1130 parent->ReplaceChildLink(NULL, interior); 1037 1131 interior->mParent = parent; 1132 1133 AxisAlignedBox3 frontBox, backBox; 1134 1135 parent->mBox.Split(parent->mAxis, parent->mPosition, frontBox, backBox); 1136 if (parent->mFront == interior) 1137 interior->mBox = frontBox; 1138 else 1139 interior->mBox = backBox; 1038 1140 } 1039 1141 else 1040 1142 { 1041 1143 mHierarchyManager->mOspTree->mRoot = interior; 1042 } 1043 1044 mCurrentKdNode = interior; 1144 interior->mBox = mHierarchyManager->mOspTree->mBoundingBox; 1145 } 1146 1147 mCurrentOspNode = interior; 1045 1148 } 1046 1149 … … 1049 1152 { 1050 1153 KdLeaf * leaf = 1051 new KdLeaf(dynamic_cast<KdInterior *>(mCurrent KdNode), NULL);1052 1053 if (mCurrent KdNode) // replace front or (if not NULL) back child1054 { 1055 dynamic_cast<KdInterior *>(mCurrent KdNode)->ReplaceChildLink(NULL, leaf);1154 new KdLeaf(dynamic_cast<KdInterior *>(mCurrentOspNode), NULL); 1155 1156 if (mCurrentOspNode) // replace front or (if not NULL) back child 1157 { 1158 dynamic_cast<KdInterior *>(mCurrentOspNode)->ReplaceChildLink(NULL, leaf); 1056 1159 } 1057 1160 else … … 1063 1166 1064 1167 void ViewCellsParseHandlers::StartBvhLeaf(AttributeList& attributes) 1065 {/* 1066 KdLeaf * leaf = 1067 new KdLeaf(dynamic_cast<KdInterior *>(mCurrentKdNode), NULL); 1068 1069 if (mCurrentKdNode) // replace front or (if not NULL) back child 1070 { 1071 dynamic_cast<KdInterior *>(mCurrentKdNode)->ReplaceChildLink(NULL, leaf); 1072 } 1073 else 1074 { 1075 mHierarchyManager->mBvHierarchy->mRoot = leaf; 1076 }*/ 1077 } 1078 1079 1080 void ViewCellsParseHandlers::StartBvhInterior(AttributeList& attributes) 1081 {/* 1082 AxisAlignedPlane plane; 1083 int len = attributes.getLength(); 1168 { 1169 const int len = attributes.getLength(); 1170 Vector3 minBox, maxBox; 1171 1172 ObjectContainer objects; 1084 1173 1085 1174 for (int i = 0; i < len; ++ i) … … 1089 1178 const char *ptr = attrValue.LocalForm(); 1090 1179 1091 if (attrName == "plane") 1092 { 1093 sscanf(ptr, "%d %f", 1094 &plane.mAxis, &plane.mPosition); 1095 } 1096 } 1097 1098 KdInterior* interior = new KdInterior(NULL); 1099 1100 interior->mAxis = plane.mAxis; 1101 interior->mPosition = plane.mPosition; 1102 1103 if (mCurrentKdNode) // replace NULL child of parent with current node 1104 { 1105 KdInterior *parent = dynamic_cast<KdInterior *>(mCurrentKdNode); 1180 if (attrName == "min") 1181 { 1182 sscanf(ptr, "%f %f %f", &minBox); 1183 } 1184 if (attrName == "max") 1185 { 1186 sscanf(ptr, "%f %f %f", &maxBox); 1187 } 1188 if (attrName == "objects") 1189 { 1190 StartBvhLeafObjects(objects, ptr); 1191 } 1192 } 1193 1194 BvhLeaf * leaf = 1195 new BvhLeaf(AxisAlignedBox3(minBox, maxBox), 1196 dynamic_cast<BvhInterior *>(mCurrentBvhNode), (int)objects.size()); 1197 1198 leaf->mObjects = objects; 1199 1200 if (mCurrentBvhNode) // replace front or (if not NULL) back child 1201 { 1202 dynamic_cast<BvhInterior *>(mCurrentBvhNode)->ReplaceChildLink(NULL, leaf); 1203 } 1204 else 1205 { 1206 mHierarchyManager->mBvHierarchy->mRoot = leaf; 1207 } 1208 } 1209 1210 1211 void ViewCellsParseHandlers::StartBvhLeafObjects(ObjectContainer &objects, 1212 const char *ptr) 1213 { 1214 vector<int> objIndices; 1215 1216 char *endptr; 1217 1218 while (1) 1219 { 1220 const int index = strtol(ptr, &endptr, 10); 1221 1222 if (ptr == endptr) break; 1223 1224 objIndices.push_back(index); 1225 1226 ptr = endptr; 1227 } 1228 1229 //TODO: find objects and add them to pvs 1230 // TODO: get view cell with specified id 1231 MeshInstance dummyInst(NULL); 1232 1233 vector<int>::const_iterator it, it_end = objIndices.end(); 1234 1235 for (it = objIndices.begin(); it != it_end; ++ it) 1236 { 1237 const int objId = *it; 1238 dummyInst.SetId(objId); 1239 1240 ObjectContainer::iterator oit = 1241 lower_bound(mObjects->begin(), mObjects->end(), (Intersectable *)&dummyInst, ilt); 1242 1243 if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) 1244 { 1245 objects.push_back(*oit); 1246 } 1247 else 1248 { 1249 cout << "error: object with id " << objId << " does not exist" << endl; 1250 } 1251 } 1252 } 1253 1254 1255 void ViewCellsParseHandlers::StartBvhInterior(AttributeList& attributes) 1256 { 1257 const int len = attributes.getLength(); 1258 Vector3 minBox, maxBox; 1259 1260 for (int i = 0; i < len; ++ i) 1261 { 1262 string attrName(StrX(attributes.getName(i)).LocalForm()); 1263 StrX attrValue(attributes.getValue(i)); 1264 const char *ptr = attrValue.LocalForm(); 1265 1266 if (attrName == "min") 1267 { 1268 sscanf(ptr, "%f %f %f", &minBox); 1269 } 1270 if (attrName == "max") 1271 { 1272 sscanf(ptr, "%f %f %f", &maxBox); 1273 } 1274 } 1275 1276 BvhInterior* interior = new BvhInterior(AxisAlignedBox3(minBox, maxBox)); 1277 1278 if (mCurrentBvhNode) // replace NULL child of parent with current node 1279 { 1280 BvhInterior *parent = dynamic_cast<BvhInterior *>(mCurrentBvhNode); 1106 1281 parent->ReplaceChildLink(NULL, interior); 1107 interior-> mParent = parent;1282 interior->SetParent(parent); 1108 1283 } 1109 1284 else 1110 1285 { 1111 mOspTree->mRoot = interior; 1112 } 1113 1114 mCurrentKdNode = interior;*/ 1115 } 1116 1286 mBvHierarchy->mRoot = interior; 1287 } 1288 1289 mCurrentBvhNode = interior; 1290 } 1117 1291 1118 1292 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
r1284 r1286 24 24 class OspTree; 25 25 class VspNode; 26 class BvhNode; 26 27 class BvHierarchy; 27 28 class HierarchyManager; … … 83 84 84 85 BspNode *mCurrentBspNode; 86 BvhNode *mCurrentBvhNode; 87 KdNode *mCurrentOspNode; 85 88 VspNode *mCurrentVspNode; 89 //KdNode *mCurrentKdNode; 90 86 91 ViewCell *mCurrentViewCell; 87 KdNode *mCurrentKdNode; 88 92 89 93 BspNode *mBspRoot; 90 94 VspNode *mVspRoot; … … 101 105 int mCurrentState; 102 106 103 enum {PARSE_OPTIONS, PARSE_VIEWCELLS, PARSE_VIEWSPACE_HIERARCHY, PARSE_OBJECTSPACE_HIERARCHY}; 107 enum { 108 PARSE_OPTIONS, 109 PARSE_VIEWCELLS, 110 PARSE_VIEWSPACE_HIERARCHY, 111 PARSE_OBJECTSPACE_HIERARCHY}; 104 112 105 113 /// view space / object space hierarchy types … … 118 126 void EndVspInterior(); 119 127 120 void ParseViewCellPvs(ViewCell *viewCell, AttributeList& attributes);128 void StartViewCellPvs(ViewCell *viewCell, AttributeList& attributes); 121 129 void EndViewCells(); 122 130 void EndBoundingBoxes(); … … 150 158 void StartBvhElement(string element, AttributeList& attributes); 151 159 160 void EndViewSpaceHierarchyInterior(); 161 void EndObjectSpaceHierarchyInterior(); 162 163 void EndBvhInterior(); 164 void EndOspInterior(); 165 166 void EndObjectSpaceHierarchy(); 167 168 void StartBvhLeafObjects(ObjectContainer &objects, const char *ptr); 152 169 153 170 // ----------------------------------------------------------------------- -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1278 r1286 2759 2759 2760 2760 if (parent->GetFront() == node) 2761 2761 box.SetMin(parent->GetAxis(), parent->GetPosition()); 2762 2762 else 2763 2763 box.SetMax(parent->GetAxis(), parent->GetPosition()); 2764 2764 2765 2765 return box;
Note: See TracChangeset
for help on using the changeset viewer.