Changeset 1174 for GTP/trunk/Lib/Vis
- Timestamp:
- 07/31/06 18:27:06 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1161 r1174 2320 2320 2321 2321 2322 RegisterOption("Hierarchy.subdivisionStats", 2323 optString, 2324 "hierarchy_subdivision_stats=", 2325 "hierarchySubdivisionStats.log"); 2326 2322 2327 ////////////////////////////////////////////////////////////////////////////////// 2323 2328 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r1166 r1174 28 28 KdPvs mKdPvs; 29 29 30 /// view cell based pvs per object 30 31 ViewCellPvs mViewCellPvs; 31 32 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1145 r1174 444 444 mVspTree = new VspTree(); 445 445 mOspTree = new OspTree(); 446 // HACK 447 //mOspTree = new OspTree(*mKdTree); 446 447 // HACK for testing if per kd evaluation works!! 448 mOspTree = new OspTree(*mKdTree); 448 449 449 450 mViewCellsManager = new VspOspViewCellsManager(mVspTree, mOspTree); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1168 r1174 1130 1130 struct SortableViewCellEntry { 1131 1131 1132 1133 1134 1135 1136 1137 1138 1139 return a.mValue < b.mValue;1140 1132 SortableViewCellEntry() {} 1133 SortableViewCellEntry(const float v, ViewCell *cell):mValue(v), mViewCell(cell) {} 1134 1135 float mValue; 1136 ViewCell *mViewCell; 1137 1138 friend bool operator<(const SortableViewCellEntry &a, const SortableViewCellEntry &b) { 1139 return a.mValue < b.mValue; 1140 } 1141 1141 }; 1142 1142 1143 ViewCell * 1144 ViewCell sManager::ConstructLocalMergeTree2(ViewCell *currentViewCell,1145 1143 1144 ViewCell * ViewCellsManager::ConstructLocalMergeTree2(ViewCell *currentViewCell, 1145 const ViewCellContainer &viewCells) 1146 1146 { 1147 1147 … … 2542 2542 } 2543 2543 2544 2545 2546 2544 2547 /*******************************************************************/ 2545 2548 /* BspViewCellsManager implementation */ … … 4885 4888 if (!mOspTree->GetRoot()) 4886 4889 { 4887 cout<< "constructing vsp and osp tree" << endl;4890 Debug << "constructing vsp and osp tree" << endl; 4888 4891 //mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox); 4889 4892 mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox); … … 4891 4894 else // just build view space partition tree 4892 4895 { 4893 cout<< "constructing only vsp tree" << endl;4896 Debug << "constructing only vsp tree" << endl; 4894 4897 mHierarchyManager->Construct3(constructionRays, objects, &mViewSpaceBox); 4895 4898 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1168 r1174 637 637 638 638 639 void VspTree::EvalSubdivisionStats(const VspTraversalData &tData, 640 const VspTraversalData &tFrontData, 641 const VspTraversalData &tBackData 642 ) 643 { 644 const float cFront = (float)tFrontData.mPvs * tFrontData.mProbability; 645 const float cBack = (float)tBackData.mPvs * tBackData.mProbability; 646 const float cData = (float)tData.mPvs * tData.mProbability; 647 648 const float costDecr = 649 (cFront + cBack - cData) / mBoundingBox.GetVolume(); 650 651 mTotalCost += costDecr; 652 mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 653 639 void VspTree::EvalSubdivisionStats(const SplitCandidate &sc) 640 { 641 const float costDecr = sc.GetRenderCostDecrease(); 642 654 643 AddSubdivisionStats(mVspStats.Leaves(), 655 644 -costDecr, … … 663 652 const bool globalCriteriaMet) 664 653 { 665 // doto remove dynamic cast654 // todo remove dynamic cast 666 655 VspSplitCandidate *sc = dynamic_cast<VspSplitCandidate *>(splitCandidate); 667 656 VspTraversalData &tData = sc->mParentData; 668 657 669 658 VspNode *newNode = tData.mNode; 659 670 660 671 661 if (!LocalTerminationCriteriaMet(tData) && !globalCriteriaMet) … … 687 677 tBackData.mMaxCostMisses = maxCostMisses; 688 678 689 690 if (1) //-- subdivision statistics 691 EvalSubdivisionStats(tData, tFrontData, tBackData); 679 mTotalCost -= sc->GetRenderCostDecrease(); 680 mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 681 682 // subdivision statistics 683 if (1) EvalSubdivisionStats(*sc); 692 684 693 685 //-- evaluate new split candidates for global greedy cost heuristics … … 882 874 CreateViewCell(backData, false); 883 875 884 876 877 #if WORK_WITH_VIEWCELL_PVS 885 878 // create front and back view cell 886 879 // add front and back view cell to "Potentially Visbilie View Cells" 887 880 // of the objects in front and back pvs 888 881 889 //AddViewCellReferences(frontLeaf->GetViewCell()); 890 //AddViewCellReferences(backLeaf->GetViewCell()); 882 AddViewCellReferences(frontLeaf->GetViewCell()); 883 AddViewCellReferences(backLeaf->GetViewCell()); 884 #endif 891 885 892 886 interior->mTimeStamp = mTimeStamp ++; … … 2823 2817 { 2824 2818 ReadEnvironment(); 2825 2826 2819 mSplitCandidates = new vector<SortableEntry>; 2827 2820 } … … 2994 2987 2995 2988 // TODO matt: compute pvs 2996 frontData.mPvs = 999 ; // ComputePvsSize(*frontData.mRays);2997 backData.mPvs = 999 ; //ComputePvsSize(*backData.mRays);2989 frontData.mPvs = 999999; // ComputePvsSize(*frontData.mRays); 2990 backData.mPvs = 9999999; //ComputePvsSize(*backData.mRays); 2998 2991 2999 2992 frontData.mProbability = frontData.mBoundingBox.GetVolume(); … … 3089 3082 const int maxCostMisses = sc->mMaxCostMisses; 3090 3083 3091 3084 // how often was max cost ratio missed in this branch? 3092 3085 tFrontData.mMaxCostMisses = maxCostMisses; 3093 3086 tBackData.mMaxCostMisses = maxCostMisses; 3094 3087 3088 mTotalCost -= sc->GetRenderCostDecrease(); 3089 3090 // subdivision statistics 3091 if (1) EvalSubdivisionStats(*sc); 3092 3095 3093 //-- push the new split candidates on the queue 3094 3096 3095 OspSplitCandidate *frontCandidate = new OspSplitCandidate(tFrontData); 3097 3096 OspSplitCandidate *backCandidate = new OspSplitCandidate(tBackData); … … 3231 3230 { 3232 3231 RayInfoContainer usedRays; 3233 int mMaxTests = 5000; 3232 int mMaxTests = 5000; // HACK 3234 3233 if (mMaxTests < (int)tData.mRays->size()) 3235 3234 { … … 3384 3383 << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 3385 3384 << "render cost decrease: " << oldRenderCost / viewSpaceVol - newRenderCost / viewSpaceVol << endl; 3385 3386 if (oldRenderCost < newRenderCost) 3387 Debug << "\nwarning!!:\n" << "old rc: " << oldRenderCost * viewSpaceVol << " new rc: " << newRenderCost * viewSpaceVol << endl; 3388 3386 3389 3387 3390 return ratio; … … 3747 3750 3748 3751 3749 #if TODO 3750 void OspTree::EvalSubdivisionStats(const VspTraversalData &tData, 3751 const VspTraversalData &tFrontData, 3752 const VspTraversalData &tBackData 3753 ) 3754 { 3755 const float cFront = (float)tFrontData.mPvs * tFrontData.mProbability; 3756 const float cBack = (float)tBackData.mPvs * tBackData.mProbability; 3757 const float cData = (float)tData.mPvs * tData.mProbability; 3758 3759 const float costDecr = 3760 (cFront + cBack - cData) / mBoundingBox.GetVolume(); 3761 3762 mTotalCost += costDecr; 3763 mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 3764 3765 AddSubdivisionStats(mVspStats.Leaves(), 3766 -costDecr, 3767 sc->GetPriority(), 3768 mTotalCost, 3769 (float)mTotalPvsSize / (float)mVspStats.Leaves()); 3770 } 3771 #endif 3752 void OspTree::EvalSubdivisionStats(const SplitCandidate &sc) 3753 { 3754 const float costDecr = sc.GetRenderCostDecrease(); 3755 Debug << "**********************$$$$$$$$$$$$$$"<< endl; 3756 Debug << "here78 " << mOspStats.Leaves() << " " << mTotalCost << endl; 3757 AddSubdivisionStats(mOspStats.Leaves(), 3758 costDecr, 3759 mTotalCost 3760 ); 3761 } 3762 3763 3764 3765 void OspTree::AddSubdivisionStats(const int leaves, 3766 const float renderCostDecr, 3767 const float totalRenderCost) 3768 //const float avgRenderCost) 3769 {Debug << "here64 " << totalRenderCost << " " << renderCostDecr << endl; 3770 mSubdivisionStats 3771 << "#Leaves\n" << leaves << endl 3772 << "#RenderCostDecrease\n" << renderCostDecr << endl 3773 << "#TotalRenderCost\n" << totalRenderCost << endl; 3774 //<< "#AvgRenderCost\n" << avgRenderCost << endl; 3775 } 3772 3776 3773 3777 … … 3809 3813 float pvsFront = 0; 3810 3814 float pvsBack = 0; 3811 float totalPvs = 0;3812 3815 3813 3816 // probability that view point lies in back / front node … … 3823 3826 3824 3827 KdLeaf *leaf = tData.mNode; 3828 int totalPvs = (int)leaf->mObjects.size(); 3829 3825 3830 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 3826 3831 … … 3829 3834 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 3830 3835 { 3836 int pvsContri = 0; 3837 3831 3838 Intersectable *obj = *oit; 3832 3839 const AxisAlignedBox3 box = obj->GetBox(); 3833 3834 ++ totalPvs;3835 3840 3836 3841 //cout << "totalpvs " << totalPvs << endl; 3837 3842 3838 3843 // test if box falls in left / right child node 3839 if (box.Max(candidatePlane.mAxis) > candidatePlane.mPosition)3844 if (box.Max(candidatePlane.mAxis) >= candidatePlane.mPosition) 3840 3845 { 3841 3846 ++ pvsFront; 3842 3847 } 3848 3843 3849 if (box.Min(candidatePlane.mAxis) < candidatePlane.mPosition) 3844 3850 { … … 3846 3852 } 3847 3853 } 3848 3849 3854 3850 3855 // sum up volume seen from the objects of left and right children … … 3889 3894 const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 3890 3895 3891 Debug << "\n==== eval render cost decrease === " << endl3896 Debug << "\n==== eval render cost decrease ====" << endl 3892 3897 << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl 3893 3898 << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << " p: " << pOverall / viewSpaceVol << endl … … 3896 3901 3897 3902 normalizedOldRenderCost = oldRenderCost / viewSpaceVol; 3903 3904 if (oldRenderCost < newRenderCost) 3905 Debug << "\nwarning2!!:\n" << "old rc: " << oldRenderCost * viewSpaceVol << " new rc: " << newRenderCost * viewSpaceVol << endl; 3906 else 3907 Debug << "here4" << endl; 3908 3909 if (pBack + pFront < pOverall * 0.9) 3910 Debug << "\nwarning3!!:\n" << "p new: " << pBack + pFront << " p old: " << pOverall << endl; 3911 else 3912 Debug << "here55" << endl; 3913 3914 if (pvsBack + pvsFront < totalPvs) 3915 Debug << "\nwarning4!!:\n" << "pvs new: " << pvsBack + pvsFront << " pvs old: " << totalPvs << endl; 3916 else 3917 Debug << "here25" << endl; 3898 3918 3899 3919 return renderCostDecrease; … … 4290 4310 mVspTree.mOspTree = &ospTree; 4291 4311 mOspTree.mVspTree = &vspTree; 4312 4313 char subdivisionStatsLog[100]; 4314 Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats", subdivisionStatsLog); 4315 mSubdivisionStats.open(subdivisionStatsLog); 4292 4316 } 4293 4317 … … 4345 4369 mVspTree.mBoundingBox); 4346 4370 4347 4371 #if WORK_WITH_VIEWCELL_PVS 4372 4348 4373 // create first view cell 4349 4374 mVspTree.CreateViewCell(vData, false); … … 4359 4384 obj->mViewCellPvs.AddSample(leaf->GetViewCell(), 1); 4360 4385 } 4386 #endif 4361 4387 4362 4388 // compute first split candidate … … 4365 4391 mVspTree.EvalSplitCandidate(*splitCandidate); 4366 4392 4393 mVspTree.mTotalCost = (float)pvsSize; 4394 mVspTree.EvalSubdivisionStats(*splitCandidate); 4395 4367 4396 return splitCandidate; 4368 4397 } … … 4370 4399 4371 4400 OspTree::OspSplitCandidate * HierarchyManager::PrepareOsp(const VssRayContainer &sampleRays, 4372 const ObjectContainer &objects,4373 AxisAlignedBox3 *forcedObjectSpace,4374 RayInfoContainer &rays)4401 const ObjectContainer &objects, 4402 AxisAlignedBox3 *forcedObjectSpace, 4403 RayInfoContainer &rays) 4375 4404 { 4376 4405 // store pointer to this tree … … 4410 4439 new OspTree::OspSplitCandidate(oData); 4411 4440 4412 mOspTree.EvalSplitCandidate(*oSplitCandidate); 4441 mOspTree.EvalSplitCandidate(*oSplitCandidate); 4442 4443 mOspTree.mTotalCost = (float)objects.size(); 4444 Debug << "total cost here553: " << mOspTree.mTotalCost << endl; 4445 mOspTree.EvalSubdivisionStats(*oSplitCandidate); 4413 4446 4414 4447 return oSplitCandidate; … … 4433 4466 4434 4467 4468 void HierarchyManager::EvalSubdivisionStats(const SplitCandidate &tData) 4469 { 4470 const float costDecr = tData.GetRenderCostDecrease(); 4471 4472 //mTotalCost -= costDecr; 4473 // mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 4474 4475 AddSubdivisionStats(mOspTree.mOspStats.Leaves() + mVspTree.mVspStats.Leaves(), 4476 costDecr, 4477 mTotalCost 4478 ); 4479 } 4480 4481 4482 void HierarchyManager::AddSubdivisionStats(const int splits, 4483 const float renderCostDecr, 4484 const float totalRenderCost) 4485 { 4486 mSubdivisionStats 4487 << "#Splits\n" << splits << endl 4488 << "#RenderCostDecrease\n" << renderCostDecr << endl 4489 << "#TotalRenderCost\n" << totalRenderCost << endl; 4490 //<< "#AvgRenderCost\n" << avgRenderCost << endl; 4491 } 4492 4493 4435 4494 bool HierarchyManager::GlobalTerminationCriteriaMet(SplitCandidate *candidate) const 4436 4495 { … … 4473 4532 if (vspSplit) 4474 4533 { 4475 mVspTree.Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 4476 return true; 4534 VspNode *n = mVspTree.Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 4477 4535 } 4478 4536 else 4479 4537 { 4480 mOspTree.Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 4481 return false; 4482 } 4538 KdNode *n = mOspTree.Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 4539 } 4540 4541 return !globalTerminationCriteriaMet; 4483 4542 } 4484 4543 … … 4492 4551 SplitCandidate *splitCandidate = NextSplitCandidate(); 4493 4552 4494 cout << "nodes: " << ++ numNodes << endl;4495 4496 4553 mTotalCost -= splitCandidate->GetRenderCostDecrease(); 4497 4498 4554 // cost ratio of cost decrease / totalCost 4499 4555 const float costRatio = splitCandidate->GetRenderCostDecrease() / mTotalCost; 4500 4556 4557 if (costRatio < mTermMinGlobalCostRatio) 4558 ++ mGlobalCostMisses; 4559 4560 /* cout << "nodes: " << ++ numNodes << endl; 4501 4561 Debug << "\n**********" << endl 4502 4562 << "total cost: " << mTotalCost << " render cost decr: " 4503 4563 << splitCandidate->GetRenderCostDecrease() 4504 4564 << " cost ratio: " << costRatio << endl << endl; 4505 4565 */ 4506 4566 //-- subdivide leaf node 4507 SubdivideSplitCandidate(splitCandidate);4508 4509 if (costRatio < mTermMinGlobalCostRatio)4510 ++ mGlobalCostMisses;4511 4512 // reevaluate candidates affected by the split4513 // for view space splits, this would be object space splits4514 // and other way round4515 if (repair)4516 RepairQueue();4567 if (SubdivideSplitCandidate(splitCandidate)) 4568 { 4569 EvalSubdivisionStats(*splitCandidate); 4570 4571 // reevaluate candidates affected by the split 4572 // for view space splits, this would be object space splits 4573 // and other way round 4574 if (repair) 4575 RepairQueue(); 4576 } 4517 4577 4518 4578 DEL_PTR(splitCandidate); … … 4544 4604 VspTree::VspSplitCandidate *vsc = 4545 4605 PrepareVsp(sampleRays, forcedViewSpace, *viewSpaceRays); 4606 4546 4607 // add to queue 4547 4608 mTQueue.Push(vsc); … … 4590 4651 // note: only true for view space = object space 4591 4652 mTotalCost = (float)osc->mParentData.mNode->mObjects.size();//(float)sc->mParentData.mPvs; 4592 4653 4593 4654 Debug << "reseting cost, new total cost: " << mTotalCost << endl; 4594 4655 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1159 r1174 66 66 int mMaxCostMisses; 67 67 68 SplitCandidate() 68 SplitCandidate(): mRenderCostDecrease(0) 69 69 {}; 70 70 71 SplitCandidate(const AxisAlignedPlane &plane): mSplitPlane(plane) 71 SplitCandidate(const AxisAlignedPlane &plane): mSplitPlane(plane), mRenderCostDecrease(0) 72 72 {} 73 73 … … 1039 1039 RayInfoContainer &rays); 1040 1040 1041 void EvalSubdivisionStats(const VspTraversalData &tData, 1042 const VspTraversalData &tFrontData, 1043 const VspTraversalData &tBackData); 1041 void EvalSubdivisionStats(const SplitCandidate &tData); 1044 1042 protected: 1045 1043 … … 1668 1666 int ClassifyRay(VssRay *ray, KdLeaf *leaf, const AxisAlignedPlane &plane) const; 1669 1667 1668 void EvalSubdivisionStats(const SplitCandidate &tData); 1669 1670 void AddSubdivisionStats(const int viewCells, 1671 const float renderCostDecr, 1672 const float totalRenderCost); 1673 1670 1674 protected: 1671 1675 … … 1844 1848 RayInfoContainer &rays); 1845 1849 1850 void EvalSubdivisionStats(const SplitCandidate &tData); 1851 1852 void AddSubdivisionStats(const int splits, 1853 const float renderCostDecr, 1854 const float totalRenderCost); 1855 1846 1856 1847 1857 protected: … … 1860 1870 /// keeps track of cost during subdivision 1861 1871 float mTotalCost; 1872 1873 ofstream mSubdivisionStats; 1862 1874 }; 1863 1875
Note: See TracChangeset
for help on using the changeset viewer.