Changeset 1640 for GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
- Timestamp:
- 10/18/06 18:17:27 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1636 r1640 109 109 "Hierarchy.Construction.levels", mNumMultiLevels); 110 110 111 Environment::GetSingleton()->GetIntValue( 112 "Hierarchy.Construction.minStepsOfSameType", mMinStepsOfSameType); 113 114 111 115 char subdivisionStatsLog[100]; 112 116 Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats", subdivisionStatsLog); … … 116 120 "Hierarchy.Construction.recomputeSplitPlaneOnRepair", mRecomputeSplitPlaneOnRepair); 117 121 118 Debug << "******** Hierachy Manager Parameters ***********" << endl;122 Debug << "******** Hierachy Manager Options ***********" << endl; 119 123 Debug << "max leaves: " << mTermMaxLeaves << endl; 120 124 Debug << "min global cost ratio: " << mTermMinGlobalCostRatio << endl; … … 124 128 Debug << "number of multilevels: " << mNumMultiLevels << endl; 125 129 Debug << "recompute split plane on repair: " << mRecomputeSplitPlaneOnRepair << endl; 130 Debug << "minimal number of steps from same type: " << mMinStepsOfSameType << endl; 126 131 127 132 switch (mConstructionType) … … 228 233 void HierarchyManager::EvalSubdivisionStats() 229 234 { 235 // TODO 236 const float objectSpaceMem = GetObjectSpaceMemUsage(); 237 const float viewSpaceMem = mVspTree->GetMemUsage(); 238 239 // calculate cost in MB 240 const float memoryCost = mHierarchyStats.mMemory / (1024.0f * 1024.0f) 241 + objectSpaceMem + viewSpaceMem; 242 230 243 //cout << "pvs entries " << mHierarchyStats.pvsEntries << endl; 231 244 AddSubdivisionStats(mHierarchyStats.Leaves(), … … 233 246 mHierarchyStats.mTotalCost, 234 247 mHierarchyStats.mPvsEntries, 235 m HierarchyStats.mMemory,236 1.0f / (mHierarchyStats.mTotalCost * m HierarchyStats.mMemory)248 memoryCost, 249 1.0f / (mHierarchyStats.mTotalCost * memoryCost) 237 250 ); 238 251 } … … 243 256 const float totalRenderCost, 244 257 const int pvsEntries, 245 const int memory,258 const float memory, 246 259 const float renderCostPerStorage) 247 260 { … … 309 322 310 323 mHierarchyStats.mNodes = 2; 311 324 325 // create first nodes 326 mVspTree->Initialise(sampleRays, forcedViewSpace); 327 InitialiseObjectSpaceSubdivision(objects); 328 329 // hack: assume that object space can be seen from view space 312 330 mHierarchyStats.mTotalCost = (float)objects.size(); 331 mHierarchyStats.mPvsEntries = 1; 332 mHierarchyStats.mMemory = sizeof(PvsData) + sizeof(Intersectable *) / (1024.0f * 1024.0f); 333 334 EvalSubdivisionStats(); 313 335 Debug << "setting total cost to " << mHierarchyStats.mTotalCost << endl; 314 336 … … 316 338 cout << "Constructing view space / object space tree ... \n"; 317 339 318 // compute view space bounding box319 mVspTree->ComputeBoundingBox(sampleRays, forcedViewSpace);320 321 340 SplitQueue objectSpaceQueue; 322 341 SplitQueue viewSpaceQueue; … … 326 345 mSavedViewSpaceSubdivisionType = mViewSpaceSubdivisionType; 327 346 mViewSpaceSubdivisionType = NO_VIEWSPACE_SUBDIV; 328 329 mSavedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType; 347 //mSavedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType; 330 348 331 349 // number of initial splits 332 int minSteps = 200;350 const int minSteps = mMinStepsOfSameType; 333 351 float renderCostDecr = Limits::Infinity; 334 352 … … 337 355 338 356 objectSpaceQueue.Push(osc); 357 339 358 340 359 ///////////////////////// … … 349 368 RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, minSteps); 350 369 351 cout << ospSteps << " object space partition steps taken" << endl; 352 370 cout << "\n" << ospSteps << " object space partition steps taken" << endl; 371 372 // create view space 353 373 SubdivisionCandidate *vsc = 354 374 PrepareViewSpaceSubdivision(sampleRays, objects); 355 375 356 376 viewSpaceQueue.Push(vsc); 357 377 358 378 // view space subdivision was constructed 359 379 mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 360 380 361 // don't terminate on max steps 362 //maxSteps = mTermMaxLeaves; 381 // the priorities were calculated for driving sha. 382 // => recalculate "real" priorities taking visibility into 383 // account so we can compare to view space splits 384 ResetQueue(objectSpaceQueue, false); 385 386 387 // lower number of minsteps: the decicion of which domain to subdivide 388 // should be decided using the render cost decrease from now 389 //minSteps = 1; 363 390 364 391 // This method subdivides view space / object space … … 370 397 while (!(viewSpaceQueue.Empty() && objectSpaceQueue.Empty())) 371 398 { 399 const float vspPriority = viewSpaceQueue.Empty() ? 0 : viewSpaceQueue.Top()->GetPriority(); 400 const float ospPriority = objectSpaceQueue.Empty() ? 0 : objectSpaceQueue.Top()->GetPriority(); 401 402 cout << "new decicion, vsp: " << vspPriority << ", osp: " << ospPriority << endl; 403 372 404 // should view or object space be subdivided further? 373 if (viewSpaceQueue.Empty() || 374 (!objectSpaceQueue.Empty() && 375 (objectSpaceQueue.Top()->GetPriority() > viewSpaceQueue.Top()->GetPriority()))) 376 { 377 // use splits of one kind until rendercost slope is reached 378 //renderCostDecr = mHierarchyStats.mRenderCostDecrease; 379 380 // lower number of minsteps: this should be solved 381 // with render cost decrease from now 382 //minSteps = 5; 383 405 if (ospPriority >= vspPriority) 406 { 407 // use splits of one kind until rendercost decrease of other domain is reached 408 renderCostDecr = vspPriority; 409 cout << "comparing with this render cost: " << renderCostDecr << endl; 384 410 // dirtied view space candidates 385 411 SubdivisionCandidateContainer dirtyVspList; … … 391 417 RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, minSteps); 392 418 393 cout << ospSteps << " object space partition steps taken" << endl;419 cout << "\n" << ospSteps << " object space partition steps taken" << endl; 394 420 395 // object space subdivision constructed 396 mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 397 398 /// Repair split queue 421 /// Repair split queue, i.e., affected view space candidates 399 422 cout << "repairing queue ... " << endl; 400 423 RepairQueue(dirtyVspList, viewSpaceQueue, true); 401 cout << " repaired " <<dirtyVspList.size() << " candidates" << endl;424 cout << "\nrepaired " << (int)dirtyVspList.size() << " candidates" << endl; 402 425 } 403 426 else 404 427 { 405 428 // use splits of one kind until rendercost slope is reached 406 // renderCostDecr = mHierarchyStats.mRenderCostDecrease; 429 renderCostDecr = ospPriority; 430 cout << "comparing with this render cost: " << renderCostDecr << endl; 407 431 408 432 ///////////////// … … 415 439 RunConstruction(viewSpaceQueue, dirtyOspList, renderCostDecr, minSteps); 416 440 417 cout << vspSteps << " view space partition steps taken" << endl;441 cout << "\n" << vspSteps << " view space partition steps taken" << endl; 418 442 419 443 // view space subdivision constructed … … 423 447 cout << "repairing queue ... " << endl; 424 448 RepairQueue(dirtyOspList, objectSpaceQueue, true); 425 cout << "repaired " << dirtyOspList.size() << " candidates" << endl;449 cout << "repaired " << (int)dirtyOspList.size() << " candidates" << endl; 426 450 } 427 451 } … … 443 467 mHierarchyStats.Start(); 444 468 mHierarchyStats.mNodes = 2; // two nodes for view space and object space 445 469 mHierarchyStats.mPvsEntries = 1; 470 mHierarchyStats.mMemory = sizeof(PvsData) + sizeof(Intersectable *) / (1024.0f * 1024.0f); 446 471 mHierarchyStats.mTotalCost = (float)objects.size(); 472 447 473 mHierarchyStats.mRenderCostDecrease = 0; 448 474 … … 453 479 cout << "Constructing view space / object space tree ... \n"; 454 480 455 // compute view space bounding box 456 mVspTree->ComputeBoundingBox(sampleRays, forcedViewSpace); 481 // create only roots 482 mVspTree->Initialise(sampleRays, forcedViewSpace); 483 InitialiseObjectSpaceSubdivision(objects); 457 484 458 485 // use objects for evaluating vsp tree construction in the … … 464 491 mViewSpaceSubdivisionType = NO_VIEWSPACE_SUBDIV; 465 492 466 // create just one view cell467 SubdivisionCandidate *vspSc =468 PrepareViewSpaceSubdivision(sampleRays, objects);469 470 493 // start view space subdivison immediately? 471 494 if (StartViewSpaceSubdivision()) 472 495 { 473 496 // prepare vsp tree for traversal 474 mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 497 mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 498 SubdivisionCandidate *vspSc = 499 PrepareViewSpaceSubdivision(sampleRays, objects); 500 475 501 mTQueue.Push(vspSc); 476 502 } … … 489 515 sampleRays, 490 516 objects, 491 forcedViewSpace,// 492 vspSc); 517 forcedViewSpace); 493 518 494 519 cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; … … 519 544 520 545 return vsc; 546 } 547 548 549 float HierarchyManager::GetObjectSpaceMemUsage() const 550 { 551 if (mObjectSpaceSubdivisionType == KD_BASED_OBJ_SUBDIV) 552 { 553 // TODO; 554 } 555 else if (mObjectSpaceSubdivisionType == BV_BASED_OBJ_SUBDIV) 556 { 557 return mBvHierarchy->GetMemUsage(); 558 } 559 560 return -1; 561 } 562 563 void HierarchyManager::InitialiseObjectSpaceSubdivision(const ObjectContainer &objects) 564 { 565 if (mObjectSpaceSubdivisionType == KD_BASED_OBJ_SUBDIV) 566 { 567 // TODO; 568 } 569 else if (mObjectSpaceSubdivisionType == BV_BASED_OBJ_SUBDIV) 570 { 571 mBvHierarchy->Initialise(objects); 572 } 521 573 } 522 574 … … 608 660 } 609 661 610 mHierarchyStats.mTotalCost -= sc->GetRenderCostDecrease();611 612 662 cout << sc->Type() << " "; 613 663 664 ///////////// 614 665 // update stats 666 615 667 mHierarchyStats.mNodes += 2; 616 617 const int pvsEntries = sc->GetPvsEntriesIncr(); 618 mHierarchyStats.mPvsEntries += pvsEntries; 619 620 //cout << "pvs entries: " << pvsEntries << " " << mHierarchyStats.pvsEntries << endl; 621 mHierarchyStats.mMemory += 0; // TODO 668 mHierarchyStats.mTotalCost -= sc->GetRenderCostDecrease(); 669 670 const int pvsEntriesIncr = sc->GetPvsEntriesIncr(); 671 mHierarchyStats.mPvsEntries += pvsEntriesIncr; 672 //cout << "pvs entries: " << pvsEntriesIncr << " " << mHierarchyStats.pvsEntries << endl; 673 674 const int sizeOfEntry = sizeof(PvsData) + sizeof(Intersectable *); 675 // memory size in byte 676 mHierarchyStats.mMemory += float(pvsEntriesIncr * sizeOfEntry); 622 677 mHierarchyStats.mRenderCostDecrease = sc->GetRenderCostDecrease(); 623 678 624 // subdivision successful679 // output stats 625 680 EvalSubdivisionStats(); 626 681 … … 656 711 657 712 713 int HierarchyManager::GetObjectSpaceSubdivisionLeaves() const 714 { 715 int maxLeaves= 0; 716 717 if (mObjectSpaceSubdivisionType == KD_BASED_OBJ_SUBDIV) 718 { 719 maxLeaves = mOspTree->mOspStats.Leaves(); 720 } 721 else if (mObjectSpaceSubdivisionType == BV_BASED_OBJ_SUBDIV) 722 { 723 maxLeaves = mBvHierarchy->mBvhStats.Leaves(); 724 } 725 726 return maxLeaves; 727 } 728 729 658 730 bool HierarchyManager::StartObjectSpaceSubdivision() const 659 731 { … … 673 745 return 674 746 ((mConstructionType == INTERLEAVED) && 675 (mMin DepthForObjectSpaceSubdivion <= mVspTree->mVspStats.maxDepth));747 (mMinStepsOfSameType <= mVspTree->mVspStats.nodes)); 676 748 } 677 749 … … 694 766 return 695 767 ((mConstructionType == INTERLEAVED) && 696 (mMin DepthForViewSpaceSubdivion <= GetObjectSpaceSubdivisionDepth()));768 (mMinStepsOfSameType <= GetObjectSpaceSubdivisionLeaves())); 697 769 } 698 770 … … 701 773 const VssRayContainer &sampleRays, 702 774 const ObjectContainer &objects, 703 AxisAlignedBox3 *forcedViewSpace, 704 SubdivisionCandidate *firstVsp) 775 AxisAlignedBox3 *forcedViewSpace) 705 776 { 706 777 while (!FinishedConstruction()) … … 719 790 mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 720 791 721 cout << "\nstarting object space subdivision a t depth"722 << mVspTree->mVspStats. maxDepth<< " ("723 << mMin DepthForObjectSpaceSubdivion<< ") " << endl;792 cout << "\nstarting object space subdivision after " 793 << mVspTree->mVspStats.nodes << " (" 794 << mMinStepsOfSameType << ") " << endl; 724 795 725 796 SubdivisionCandidate *ospSc = PrepareObjectSpaceSubdivision(sampleRays, objects); 797 798 cout << "reseting queue ... "; 799 ResetQueue(mTQueue, mRecomputeSplitPlaneOnRepair); 800 cout << "finished" << endl; 801 726 802 mTQueue.Push(ospSc); 803 } 804 805 if (StartViewSpaceSubdivision()) 806 { 807 mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 808 809 cout << "\nstarting view space subdivision at depth " 810 << GetObjectSpaceSubdivisionLeaves() << " (" 811 << mMinStepsOfSameType << ") " << endl; 812 813 SubdivisionCandidate *vspSc = PrepareViewSpaceSubdivision(sampleRays, objects); 727 814 728 815 cout << "reseting queue ... "; 729 ResetQueue( );816 ResetQueue(mTQueue, mRecomputeSplitPlaneOnRepair); 730 817 cout << "finished" << endl; 731 } 732 733 if (StartViewSpaceSubdivision()) 734 { 735 mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 736 737 cout << "\nstarting view space subdivision at depth " 738 << GetObjectSpaceSubdivisionDepth() << " (" 739 << mMinDepthForViewSpaceSubdivion << ") " << endl; 740 741 //SubdivisionCandidate *vspSc = PrepareViewSpaceSubdivision(sampleRays, objects); 742 mTQueue.Push(firstVsp); 743 744 cout << "reseting queue ... "; 745 ResetQueue(); 746 cout << "finished" << endl; 818 819 // push view space candidate 820 mTQueue.Push(vspSc); 747 821 } 748 822 … … 784 858 if ((sc->GetRenderCostDecrease() < minRenderCostDecr) && 785 859 !(steps < minSteps)) 860 { 861 cout << "breaking on " << sc->GetRenderCostDecrease() << " smaller than " << minRenderCostDecr << endl; 786 862 break; 787 863 } 788 864 //////// 789 865 //-- subdivide leaf node of either type … … 826 902 827 903 mHierarchyStats.mTotalCost = mBvHierarchy->mTotalCost; 828 904 905 // bug!! pvs entries could be much higher at this stage 829 906 mHierarchyStats.mNodes = 2; 830 mHierarchyStats.mPvsEntries = 0;907 mHierarchyStats.mPvsEntries = 1; 831 908 mHierarchyStats.mRenderCostDecrease = 0; 832 909 … … 861 938 862 939 mHierarchyStats.mNodes = 2; 863 mHierarchyStats.mPvsEntries = 0; 940 // bug!! pvs entries could be much higher at this stage 941 mHierarchyStats.mPvsEntries = 1; 864 942 mHierarchyStats.mRenderCostDecrease = 0; 865 943 944 // evaluate new stats before first subdivsiion 866 945 EvalSubdivisionStats(); 867 946 … … 884 963 cout << "Constructing view space / object space tree ... \n"; 885 964 886 // compute view space bounding box 887 mVspTree->ComputeBoundingBox(sampleRays, forcedViewSpace); 965 // initialise view / object space 966 mVspTree->Initialise(sampleRays, forcedViewSpace); 967 InitialiseObjectSpaceSubdivision(objects); 888 968 889 969 // use sah for evaluating osp tree construction … … 892 972 mSavedViewSpaceSubdivisionType = mViewSpaceSubdivisionType; 893 973 mViewSpaceSubdivisionType = NO_VIEWSPACE_SUBDIV; 894 895 // first view cell896 SubdivisionCandidate *vspVc = PrepareViewSpaceSubdivision(sampleRays, objects);897 974 898 975 mSavedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType; 899 //mObjectSpaceSubdivisionType = NO_OBJ_SUBDIV;976 mObjectSpaceSubdivisionType = NO_OBJ_SUBDIV; 900 977 901 978 const int limit = mNumMultiLevels; … … 935 1012 // subdivide view space with respect to the objects 936 1013 937 if (!ViewSpaceSubdivisionConstructed()) 938 { 939 mTQueue.Push(vspVc); 940 941 // view space subdivision constructed 942 mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 943 } 944 else 945 { 946 ResetViewSpaceSubdivision(sampleRays, objects); 947 } 1014 SubdivisionCandidate *vspVc = ResetViewSpaceSubdivision(sampleRays, objects); 1015 mTQueue.Push(vspVc); 1016 1017 // view space subdivision constructed 1018 mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 1019 948 1020 949 1021 // process view space candidates … … 969 1041 FinishObjectSpaceSubdivision(objects); 970 1042 } 1043 1044 1045 void HierarchyManager::OptimizeMultiLevel(const VssRayContainer &sampleRays, 1046 const ObjectContainer &objects, 1047 AxisAlignedBox3 *forcedViewSpace) 1048 { 1049 mHierarchyStats.Reset(); 1050 mHierarchyStats.Start(); 1051 mHierarchyStats.mNodes = 2; 1052 1053 mHierarchyStats.mTotalCost = (float)objects.size(); 1054 Debug << "setting total cost to " << mHierarchyStats.mTotalCost << endl; 1055 1056 const long startTime = GetTime(); 1057 cout << "Constructing view space / object space tree ... \n"; 1058 1059 // initialise view / object space 1060 mVspTree->Initialise(sampleRays, forcedViewSpace); 1061 InitialiseObjectSpaceSubdivision(objects); 1062 1063 // use sah for evaluating osp tree construction 1064 // in the first iteration of the subdivision 1065 1066 mSavedViewSpaceSubdivisionType = mViewSpaceSubdivisionType; 1067 mViewSpaceSubdivisionType = NO_VIEWSPACE_SUBDIV; 1068 1069 mSavedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType; 1070 mObjectSpaceSubdivisionType = NO_OBJ_SUBDIV; 1071 1072 const int limit = mNumMultiLevels; 1073 int i = 0; 1074 1075 // This method subdivides view space / object space 1076 // in order to converge to some optimal cost for this partition 1077 // start with object space partiton 1078 // then optimizate view space partition for the current osp 1079 // and vice versa until iteration depth is reached. 1080 while (1) 1081 { 1082 char subdivisionStatsLog[100]; 1083 sprintf(subdivisionStatsLog, "tests/i3d/subdivision-%04d.log", i); 1084 mSubdivisionStats.open(subdivisionStatsLog); 1085 1086 // subdivide object space first 1087 ResetObjectSpaceSubdivision(sampleRays, objects); 1088 1089 // process object space candidates 1090 RunConstruction(false); 1091 1092 // object space subdivision constructed 1093 mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 1094 1095 cout << "iteration " << i << " of " << limit << " finished" << endl; 1096 1097 mSubdivisionStats.close(); 1098 1099 if ((i ++) >= limit) 1100 break; 1101 1102 sprintf(subdivisionStatsLog, "tests/i3d/subdivision-%04d.log", i); 1103 mSubdivisionStats.open(subdivisionStatsLog); 1104 1105 ///////////////// 1106 // subdivide view space with respect to the objects 1107 1108 SubdivisionCandidate *vspVc = ResetViewSpaceSubdivision(sampleRays, objects); 1109 mTQueue.Push(vspVc); 1110 1111 // view space subdivision constructed 1112 mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 1113 1114 1115 // process view space candidates 1116 RunConstruction(false); 1117 1118 cout << "iteration " << i << " of " << limit << " finished" << endl; 1119 1120 mSubdivisionStats.close(); 1121 1122 if ((i ++) >= limit) 1123 break; 1124 } 1125 1126 cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 1127 1128 /*#if _DEBUG 1129 cout << "view space: " << GetViewSpaceBox() << endl; 1130 cout << "object space: " << GetObjectSpaceBox() << endl; 1131 #endif*/ 1132 1133 mHierarchyStats.Stop(); 1134 mVspTree->mVspStats.Stop(); 1135 FinishObjectSpaceSubdivision(objects); 1136 } 1137 971 1138 972 1139 … … 1067 1234 1068 1235 1069 void HierarchyManager::ResetQueue( )1236 void HierarchyManager::ResetQueue(SplitQueue &splitQueue, const bool recomputeSplitPlane) 1070 1237 { 1071 1238 SubdivisionCandidateContainer mCandidateBuffer; 1072 1239 1073 1240 // remove from queue 1074 while (! mTQueue.Empty())1075 { 1076 SubdivisionCandidate *candidate = NextSubdivisionCandidate( mTQueue);1241 while (!splitQueue.Empty()) 1242 { 1243 SubdivisionCandidate *candidate = NextSubdivisionCandidate(splitQueue); 1077 1244 // reevaluate local split plane and priority 1078 candidate->EvalPriority( );1245 candidate->EvalPriority(recomputeSplitPlane); 1079 1246 cout << "."; 1080 1247 mCandidateBuffer.push_back(candidate); … … 1085 1252 for (sit = mCandidateBuffer.begin(); sit != sit_end; ++ sit) 1086 1253 { 1087 mTQueue.Push(*sit);1254 splitQueue.Push(*sit); 1088 1255 } 1089 1256 }
Note: See TracChangeset
for help on using the changeset viewer.