Changeset 1684 for GTP/trunk/Lib/Vis/Preprocessing/src
- Timestamp:
- 10/26/06 19:35:43 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1680 r1684 338 338 //AssociateObjectsWithLeaf(node->GetFront()); 339 339 340 node->mRenderCostDecr += sc.GetRenderCostDecrease(); 341 node->mPvsEntriesIncr += sc.GetPvsEntriesIncr(); 342 340 node->mRenderCostDecr = sc.GetRenderCostDecrease(); 341 node->mPvsEntriesIncr = sc.GetPvsEntriesIncr(); 343 342 } 344 343 … … 370 369 AxisAlignedBox3 bbox = EvalBoundingBox(sc.mBackObjects, &parentBox); 371 370 372 BvhLeaf *back = 373 new BvhLeaf(bbox, node, (int)sc.mBackObjects.size()); 374 BvhLeaf *front = 375 new BvhLeaf(fbox, node, (int)sc.mFrontObjects.size()); 371 BvhLeaf *back = new BvhLeaf(bbox, node, (int)sc.mBackObjects.size()); 372 BvhLeaf *front = new BvhLeaf(fbox, node, (int)sc.mFrontObjects.size()); 376 373 377 374 BvhInterior *parent = leaf->GetParent(); … … 428 425 backData.mMaxCostMisses = sc.GetMaxCostMisses(); 429 426 430 // set the time stamp so the order of traversal can be reconstructed 431 node->mTimeStamp = mHierarchyManager->mTimeStamp ++; 432 //cout << "here4 " << node->mTimeStamp << endl; 433 node->mRenderCostDecr = sc.GetRenderCostDecrease(); 434 node->mPvsEntriesIncr = sc.GetPvsEntriesIncr(); 427 //node->mRenderCostDecr = sc.GetRenderCostDecrease(); 428 //node->mPvsEntriesIncr = sc.GetPvsEntriesIncr(); 435 429 436 430 // assign the objects in sorted order … … 465 459 currentNode = SubdivideNode(*sc, tFrontData, tBackData); 466 460 461 // set the time stamp so the order of traversal can be reconstructed 462 currentNode->mTimeStamp = mHierarchyManager->mTimeStamp ++; 463 //currentNode->mRenderCostDecr = sc.GetRenderCostDecrease(); 464 //currentNode->mPvsEntriesIncr = sc.GetPvsEntriesIncr(); 465 467 466 // decrease the weighted average cost of the subdivisoin 468 467 mTotalCost -= sc->GetRenderCostDecrease(); … … 1293 1292 if (useVisibilityBasedHeuristics) 1294 1293 { 1295 cout << "v";1294 //cout << "v rays: " << tData.mNumRays << " " << endl; 1296 1295 /////////// 1297 1296 //-- heuristics using objects weighted by view cells volume … … 1300 1299 } 1301 1300 else 1302 { cout << "e ";1301 { cout << "e rays: " << tData.mNumRays << " "; 1303 1302 ////////////////// 1304 1303 //-- view cells not constructed yet => use surface area heuristic … … 2124 2123 2125 2124 2126 } 2125 SubdivisionCandidate *BvHierarchy::CreateSubdivisionCandidate(BvhInterior *oldNode) 2126 { 2127 return new BvhSubdivisionCandidate(BvhTraversalData()); 2128 } 2129 2130 2131 BvhNode *BvHierarchy::SubdivideAndCopy(SplitQueue &tQueue, 2132 SubdivisionCandidate *splitCandidate, 2133 const bool globalCriteriaMet, 2134 BvhNode *originalNode) 2135 { 2136 BvhSubdivisionCandidate *sc = dynamic_cast<BvhSubdivisionCandidate *>(splitCandidate); 2137 BvhTraversalData &tData = sc->mParentData; 2138 2139 BvhNode *currentNode = tData.mNode; 2140 BvhNode *oldNode = (BvhNode *)splitCandidate->mEvaluationHack; 2141 2142 if (!oldNode->IsLeaf()) 2143 { 2144 ////////////// 2145 //-- continue subdivision 2146 2147 BvhTraversalData tFrontData; 2148 BvhTraversalData tBackData; 2149 2150 BvhInterior *oldInterior = dynamic_cast<BvhInterior *>(oldNode); 2151 //sc->SetSplitPlane(oldInterior->mSplitPlane); 2152 2153 oldInterior->GetFront()->CollectObjects(sc->mFrontObjects); 2154 oldInterior->GetBack()->CollectObjects(sc->mBackObjects); 2155 EvalSubdivisionCandidate(*sc); 2156 2157 // create new interior node and two leaf node 2158 currentNode = SubdivideNode(*sc, tFrontData, tBackData); 2159 2160 // evaluate the changes in render cost and pvs entries 2161 EvalSubdivisionCandidate(*sc, false); 2162 2163 currentNode->mRenderCostDecr = oldNode->mRenderCostDecr + sc->GetRenderCostDecrease(); 2164 currentNode->mPvsEntriesIncr = oldNode->mPvsEntriesIncr + sc->GetPvsEntriesIncr(); 2165 2166 /////////////////////////// 2167 //-- push the new split candidates on the queue 2168 2169 BvhSubdivisionCandidate *frontCandidate = new BvhSubdivisionCandidate(tFrontData); 2170 BvhSubdivisionCandidate *backCandidate = new BvhSubdivisionCandidate(tBackData); 2171 2172 frontCandidate->SetPriority((float)-oldInterior->GetFront()->mTimeStamp); 2173 backCandidate->SetPriority((float)-oldInterior->GetFront()->mTimeStamp); 2174 2175 frontCandidate->mEvaluationHack = oldInterior->GetFront(); 2176 backCandidate->mEvaluationHack = oldInterior->GetBack(); 2177 2178 // cross reference 2179 tFrontData.mNode->SetSubdivisionCandidate(frontCandidate); 2180 tBackData.mNode->SetSubdivisionCandidate(backCandidate); 2181 2182 //cout << "f: " << frontCandidate->GetPriority() << " b: " << backCandidate->GetPriority() << endl; 2183 tQueue.Push(frontCandidate); 2184 tQueue.Push(backCandidate); 2185 } 2186 2187 ///////////////////////////////// 2188 //-- node is a leaf => terminate traversal 2189 2190 if (currentNode->IsLeaf()) 2191 { 2192 // this leaf is no candidate for splitting anymore 2193 // => detach subdivision candidate 2194 tData.mNode->SetSubdivisionCandidate(NULL); 2195 // detach node so we don't delete it with the traversal data 2196 tData.mNode = NULL; 2197 } 2198 2199 return currentNode; 2200 } 2201 2202 2203 } -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1680 r1684 271 271 272 272 virtual void CollectObjects(ObjectContainer &objects); 273 273 274 protected: 274 275 … … 306 307 mSubdivisionCandidate = candidate; 307 308 } 308 virtual void CollectObjects(ObjectContainer &objects); 309 310 virtual void CollectObjects(ObjectContainer &objects); 311 309 312 public: 310 313 … … 597 600 float GetMemUsage() const; 598 601 599 void UpdateNode(const BvhSubdivisionCandidate &sc); 602 603 /////////////////////////// 604 // hacks in order to provide interleaved heurisitcs 605 606 void UpdateNode(const BvhSubdivisionCandidate &sc); 607 608 SubdivisionCandidate *CreateSubdivisionCandidate(BvhInterior *oldNode); 609 610 BvhNode *SubdivideAndCopy(SplitQueue &tQueue, 611 SubdivisionCandidate *splitCandidate, 612 const bool globalCriteriaMet, 613 BvhNode *originalNode); 614 615 ///////////////////////////////// 600 616 601 617 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1676 r1684 2566 2566 "200"); 2567 2567 2568 RegisterOption("Hierarchy.Construction.maxStepsOfSameType", 2569 optInt, 2570 "hierarchy_construction_max_steps_same_type=", 2571 "700"); 2572 2568 2573 RegisterOption("Hierarchy.Construction.recomputeSplitPlaneOnRepair", 2569 2574 optBool, -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1680 r1684 112 112 "Hierarchy.Construction.minStepsOfSameType", mMinStepsOfSameType); 113 113 114 Environment::GetSingleton()->GetIntValue( 115 "Hierarchy.Construction.maxStepsOfSameType", mMaxStepsOfSameType); 116 114 117 char subdivisionStatsLog[100]; 115 118 Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats", subdivisionStatsLog); … … 128 131 "Hierarchy.Termination.maxMemory", mTermMaxMemory); 129 132 130 Environment::GetSingleton()->GetFloatValue( 131 "Hierarchy.Termination.memoryConst", mMemoryConst); 133 if (1 && mConsiderMemory2) 134 { 135 mMemoryConst = (float)(sizeof(VspLeaf *) + sizeof (VspViewCell *)); 136 } 137 else 138 { 139 Environment::GetSingleton()->GetFloatValue( 140 "Hierarchy.Termination.memoryConst", mMemoryConst); 141 } 132 142 133 143 // compare to bytes … … 147 157 Debug << "consider memory2: " << mConsiderMemory << endl; 148 158 Debug << "mem const: " << mMemoryConst << endl; 159 Debug << "min steps of same kind: " << mMinStepsOfSameType << endl; 160 Debug << "max steps of same kind: " << mMaxStepsOfSameType << endl; 149 161 150 162 switch (mConstructionType) … … 377 389 SplitQueue viewSpaceQueue; 378 390 391 int vspSteps, ospSteps; 392 379 393 // use sah for evaluating osp tree construction 380 394 // in the first iteration of the subdivision … … 385 399 // number of initial splits 386 400 const int minSteps = mMinStepsOfSameType; 387 const int maxSteps = mMinStepsOfSameType + 500; 388 float renderCostDecr = Limits::Infinity; 401 const int maxSteps = mMaxStepsOfSameType; 389 402 390 403 SubdivisionCandidate *osc = PrepareObjectSpaceSubdivision(sampleRays, objects); 391 392 404 objectSpaceQueue.Push(osc); 393 405 … … 396 408 // calulcate initial object space splits 397 409 398 SubdivisionCandidateContainer dirty VspList;410 SubdivisionCandidateContainer dirtyList; 399 411 400 412 // subdivide object space first 401 413 // for first round, use sah splits. Once view space partition 402 414 // has started, use render cost heuristics instead 403 const int ospSteps = 404 RunConstruction(objectSpaceQueue, dirtyVspList, NULL, minSteps, maxSteps); 405 415 ospSteps = RunConstruction(objectSpaceQueue, dirtyList, NULL, minSteps, maxSteps); 406 416 cout << "\n" << ospSteps << " object space partition steps taken" << endl; 407 417 408 418 // create view space 409 419 SubdivisionCandidate *vsc = PrepareViewSpaceSubdivision(sampleRays, objects); 410 411 420 viewSpaceQueue.Push(vsc); 412 421 422 dirtyList.clear(); 423 413 424 // view space subdivision started 414 425 mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 415 426 416 // the priorities were calculated for driving sha. 417 // => recalculate "real" priorities taking visibility into 418 // account so we can compare to view space splits 419 ResetQueue(objectSpaceQueue, false); 427 if (1) 428 { 429 // rather also start with 100 view space splits to avoid initial bias. 430 vspSteps = RunConstruction(viewSpaceQueue, dirtyList, NULL, minSteps, maxSteps); 431 cout << "\n" << vspSteps << " view space partition steps taken" << endl; 432 433 /// Repair split queue 434 cout << "repairing queue ... " << endl; 435 RepairQueue(dirtyList, objectSpaceQueue, true); 436 cout << "repaired " << (int)dirtyList.size() << " candidates" << endl; 437 438 dirtyList.clear(); 439 } 440 else 441 { 442 // the priorities were calculated for driving sah. 443 // => recalculate "real" priorities taking visibility into 444 // account so we can compare to view space splits 445 ResetQueue(objectSpaceQueue, false); 446 } 420 447 421 448 // This method subdivides view space / object space … … 424 451 // then optimizate view space partition for the current osp 425 452 // and vice versa until iteration depth is reached. 426 bool lastSplitWasOsp = true; 453 bool lastSplitWasOsp = true; 454 427 455 while (!(viewSpaceQueue.Empty() && objectSpaceQueue.Empty())) 428 456 { … … 434 462 435 463 // should view or object space be subdivided further? 436 //if (ospPriority >= vspPriority)437 if (!lastSplitWasOsp)464 if (ospPriority >= vspPriority) 465 //if (!lastSplitWasOsp) 438 466 { 439 467 lastSplitWasOsp = true; 440 468 cout << "osp" << endl; 469 441 470 // dirtied view space candidates 442 471 SubdivisionCandidateContainer dirtyVspList; … … 445 474 // for first round, use sah splits. Once view space partition 446 475 // has started, use render cost heuristics instead 447 const int ospSteps = RunConstruction(objectSpaceQueue, 448 dirtyVspList, 449 viewSpaceQueue.Top(), 450 minSteps, 451 maxSteps); 476 const int ospSteps = 477 RunConstruction(objectSpaceQueue, dirtyVspList, viewSpaceQueue.Top(), minSteps, maxSteps); 452 478 453 479 cout << "\n" << ospSteps << " object space partition steps taken" << endl; 454 480 Debug << "\n" << ospSteps << " object space partition steps taken" << endl; 481 455 482 /// Repair split queue, i.e., affected view space candidates 456 483 cout << "repairing queue ... " << endl; … … 466 493 // subdivide view space with respect to the objects 467 494 495 // dirtied object space candidates 468 496 SubdivisionCandidateContainer dirtyOspList; 469 497 … … 473 501 474 502 cout << "\n" << vspSteps << " view space partition steps taken" << endl; 503 Debug << "\n" << vspSteps << " view space partition steps taken" << endl; 475 504 476 505 // view space subdivision constructed … … 717 746 { 718 747 memoryCount += 100000; 719 cout << "\nstorage cost: " << mHierarchyStats.mMemory / float(1024 * 1024) << " MB, steps: " << mHierarchyStats.Leaves() << endl; 748 cout << "\nstorage cost: " << mHierarchyStats.mMemory / float(1024 * 1024) 749 << " MB, steps: " << mHierarchyStats.Leaves() << endl; 720 750 } 721 751 … … 917 947 const float threshold = oldCandidate ? oldCandidate->GetPriority() : 1e20; 918 948 SubdivisionCandidate *sc = NextSubdivisionCandidate(splitQueue); 919 //cout << "here2 " << sc->GetRenderCostDecrease() << " " << threshold << endl;949 920 950 float rc = (float)sc->GetRenderCostDecrease() / (mInitialRenderCost - mHierarchyStats.mTotalCost + 1.0f); 921 951 float mc = (float)sc->GetPvsEntriesIncr() / (float)mHierarchyStats.mPvsEntries; … … 940 970 { 941 971 sc->CollectDirtyCandidates(dirtyCandidates, true); 942 //cout << "collected " << dirtyCandidates.size() << "dirty candidates" << endl;943 972 ++ steps; 944 973 } … … 1281 1310 1282 1311 1283 /////////////////////////// //////1312 /////////////////////////// 1284 1313 //-- reevaluate the dirty list 1285 1314 … … 1611 1640 1612 1641 VspTree *oldVspTree = mVspTree; 1613 //BvHierarchy *oldHierarchy = mBvHierarchy;1614 1615 //mBvHierarchy = new BvHierarchy();1616 //mBvHierarchy->mHierarchyManager = this;1642 BvHierarchy *oldHierarchy = mBvHierarchy; 1643 1644 mBvHierarchy = new BvHierarchy(); 1645 mBvHierarchy->mHierarchyManager = this; 1617 1646 1618 1647 mVspTree = new VspTree(); … … 1636 1665 cout << "Constructing view space / object space tree ... \n"; 1637 1666 1638 ExportStats(filename, objects, oldVspTree );1667 ExportStats(filename, objects, oldVspTree, oldHierarchy); 1639 1668 1640 1669 cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; … … 1649 1678 void HierarchyManager::ExportStats(const string &mergeStats, 1650 1679 const ObjectContainer &objects, 1651 VspTree *oldVspTree) 1680 VspTree *oldVspTree, 1681 BvHierarchy *oldHierarchy) 1652 1682 { 1653 1683 ofstream stats; 1654 1684 stats.open(mergeStats.c_str()); 1685 SplitQueue tQueue; 1686 1687 BvhNode *oldBvhRoot = oldHierarchy->GetRoot(); 1688 VspNode *oldVspRoot = oldVspTree->GetRoot(); 1689 1690 SubdivisionCandidate *firstVsp = mVspTree->CreateSubdivisionCandidate(dynamic_cast<VspInterior *>(oldVspRoot)); 1691 SubdivisionCandidate *firstBvh = mBvHierarchy->CreateSubdivisionCandidate(dynamic_cast<BvhInterior *>(oldBvhRoot)); 1692 1655 1693 /* 1656 1694 BvhQueue bvhQueue; … … 1674 1712 ///////////// 1675 1713 //-- first view cell 1676 // UpdateStats(stats, 2, totalRenderCost, entriesInPvs, memoryCost, true); 1677 1678 1679 /* 1680 1714 UpdateStats(stats, 2, totalRenderCost, entriesInPvs, memoryCost, true); 1681 1715 1682 1716 //-- go through tree in the order of render cost decrease … … 1684 1718 //-- or the reverse order of subdivision for subdivision-only 1685 1719 //-- view cell hierarchies. 1686 int i = 0; 1720 int steps = 0; 1721 while (!tQueue.Empty()) 1722 { 1723 SubdivisionCandidate *nextCandidate = NextSubdivisionCandidate(tQueue); 1724 1725 cout << "next candidate: " << nextCandidate->GetPriority() << endl; 1726 nextCandidate->Apply(tQueue, false); 1727 1728 totalRenderCost -= nextCandidate->GetRenderCostDecrease(); 1729 entriesInPvs += nextCandidate->GetPvsEntriesIncr(); 1730 1731 ++ steps; 1732 1733 const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize(); 1734 UpdateStats(stats, steps, totalRenderCost, entriesInPvs, memoryCost, false); 1735 1736 /*if (nextCandidate->Type() == SubdivisionCandidate::VIEW_SPACE) 1737 { 1738 cout << "v"; 1739 VspNode *vspNode = NULL; 1740 1741 //vspNode->mParent->SetupChildLink(); 1742 if (!vspNode->IsLeaf()) 1743 { 1744 SubdivisionCandidate sc = new VspSubdivisionCandidate(); 1745 1746 mVspTree->EvalPriority(sc, false); 1747 1748 UpdateStats(stats, splits 1749 totalRenderCost -= vspNode->mRenderCostDecr; 1750 entriesInPvs += vspNode->mPvsEntriesIncr; 1751 1752 steps ++; 1753 1754 const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize(); 1755 UpdateStats(stats, steps, totalRenderCost, entriesInPvs, memoryCost, true); 1756 1757 VspNode *front = dynamic_cast<VspInterior *>(vspNode)->GetFront(); 1758 VspNode *back= dynamic_cast<VspInterior *>(vspNode)->GetBack(); 1759 1760 RecreateLeaves(); 1761 if (!front->IsLeaf()) 1762 { 1763 SuddivisionCandidate *candidate = new SubdivisionCandidate; 1764 candidate->mParentData.mNode ? front; 1765 candidate->mParentData.mrays = 0; 1766 1767 SuddivisionCandidate *candidate2 = new SubdivisionCandidate; 1768 candidate->mParentData.mNode = back; 1769 candidate->mParentData.mrays = 0; 1770 1771 1772 vspQueue.push(front); 1773 if (!back->IsLeaf()) 1774 vspQueue.push(back); 1775 1776 } 1777 } 1778 else // object space split 1779 { 1780 cout << "o"; 1781 1782 BvhNode *bvhNode = NULL; 1783 1784 if (!bvhNode->IsLeaf()) 1785 { 1786 totalRenderCost -= bvhNode->mRenderCostDecr; 1787 entriesInPvs += bvhNode->mPvsEntriesIncr; 1788 1789 steps ++; 1790 const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize(); 1791 UpdateStats(stats, steps, totalRenderCost, entriesInPvs, memoryCost, false); 1792 1793 // BvhNode *front = dynamic_cast<BvhInterior *>(bvhNode)->GetFront(); 1794 // BvhNode *back= dynamic_cast<BvhInterior *>(bvhNode)->GetBack(); 1795 1796 // if (!front->IsLeaf()) 1797 // bvhQueue.push(front); 1798 // if (!back->IsLeaf()) 1799 // bvhQueue.push(back); 1800 } 1801 }*/ 1802 } 1803 stats.close(); 1804 } 1805 1806 /* 1687 1807 while (!(bvhQueue.empty() && vspQueue.empty())) 1688 1808 { … … 1775 1895 } 1776 1896 */ 1777 stats.close(); 1778 } 1779 1780 1781 } 1897 1898 1899 } -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1680 r1684 444 444 const string &filename); 445 445 446 void ExportStats(const string &mergeStats, const ObjectContainer &objects, VspTree *oldVspTree );446 void ExportStats(const string &mergeStats, const ObjectContainer &objects, VspTree *oldVspTree, BvHierarchy *oldBvHierarchy); 447 447 protected: 448 448 … … 509 509 /// number of minimal steps of the same type 510 510 int mMinStepsOfSameType; 511 int mMaxStepsOfSameType; 511 512 512 513 /// statistics about the hierarchy -
GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h
r1667 r1684 38 38 */ 39 39 virtual bool GlobalTerminationCriteriaMet() const = 0; 40 /** Collects #ofsubdivision candidates that were affected by the40 /** Collects subdivision candidates that were affected by the 41 41 application of this one. 42 42 */ … … 117 117 static int sReservedMailboxes; 118 118 119 void *mEvaluationHack; 119 120 protected: 120 121 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1680 r1684 3321 3321 3322 3322 3323 } 3323 SubdivisionCandidate *VspTree::CreateSubdivisionCandidate(VspInterior *oldNode) 3324 { 3325 return new VspSubdivisionCandidate(oldNode->GetPlane(), VspTraversalData()); 3326 } 3327 3328 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
r1680 r1684 694 694 695 695 void UpdateNode(const AxisAlignedPlane &splitPlane, 696 VspTraversalData &tData, 697 VspTraversalData &frontData, 698 VspTraversalData &backData); 696 VspTraversalData &tData, 697 VspTraversalData &frontData, 698 VspTraversalData &backData); 699 700 SubdivisionCandidate *CreateSubdivisionCandidate(VspInterior *oldNode); 701 699 702 protected: 700 703
Note: See TracChangeset
for help on using the changeset viewer.