Changeset 1141 for GTP/trunk/Lib/Vis
- Timestamp:
- 07/18/06 19:03:14 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1139 r1141 2212 2212 "0.99"); 2213 2213 2214 RegisterOption("VspTree.useKdPvs ",2215 optBool, 2216 "vsp_ pvs_use_kd_pvs=",2214 RegisterOption("VspTree.useKdPvsForHeuristics", 2215 optBool, 2216 "vsp_use_kd_pvs_for_heuristics=", 2217 2217 "true"); 2218 2218 2219 RegisterOption("VspTree.storeKdPvs", 2220 optBool, 2221 "vsp_storeKdPvs=", 2222 "true"); 2219 2223 2220 2224 /***************************************************************************/ -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r1112 r1141 1705 1705 ViewCellContainer &viewcells = mViewCellsManager->GetViewCells(); 1706 1706 int maxPvs = -1; 1707 for (i=0; i < viewcells.size(); i++) { 1707 for (i=0; i < viewcells.size(); i++) 1708 { 1708 1709 ViewCell *vc = viewcells[i]; 1709 int p = vc->GetPvs().GetSize();1710 const int p = vc->GetPvs().CountPvs(); 1710 1711 if (p > maxPvs) 1711 1712 maxPvs = p; … … 1723 1724 c = vc->GetColor(); 1724 1725 else { 1725 float importance = (float)vc->GetPvs().GetSize() / (float)maxPvs;1726 const float importance = (float)vc->GetPvs().CountPvs() / (float)maxPvs; 1726 1727 c = RgbColor(importance, 1.0f - importance, 0.0f); 1727 1728 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp
r863 r1141 1 1 #include <iostream> 2 #include <stack> 2 3 #include "Pvs.h" 4 #include "Intersectable.h" 5 #include "KdIntersectable.h" 6 #include "KdTree.h" 7 #include "common.h" 8 3 9 4 10 namespace GtpVisibilityPreprocessor { 5 11 6 int 7 KdPvs::Compress()12 13 int KdPvs::Compress() 8 14 { 9 15 return 0; // TODO 10 16 } 11 17 18 19 int ObjectPvs::CountPvs() const 20 { 21 int pvs = 0; 22 23 Intersectable::NewMail(); 24 KdNode::NewMail(); 25 26 ObjectPvsMap::const_iterator it, it_end = mEntries.end(); 27 28 for (it = mEntries.begin(); it != it_end; ++ it) 29 { 30 Intersectable *obj = (*it).first; 31 32 if (obj->Type() == Intersectable::KD_INTERSECTABLE) 33 { 34 KdIntersectable *kdObj = dynamic_cast<KdIntersectable *>(obj); 35 36 stack<KdNode *> tStack; 37 38 tStack.push(kdObj->GetNode()); 39 40 while (!tStack.empty()) 41 { 42 KdNode *node = tStack.top(); 43 tStack.pop(); 44 45 // already processed node (objects in pvs) 46 if (node->Mailed()) 47 continue; 48 49 node->Mail(); 50 51 if (node->IsLeaf()) 52 { 53 54 KdLeaf *leaf = dynamic_cast<KdLeaf *>(node); 55 56 pvs += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 57 58 ObjectContainer::const_iterator it, it_end = leaf->mMultipleObjects.end(); 59 { 60 Intersectable *object = *it; 61 62 if (!object->Mailed()) 63 { 64 object->Mail(); 65 ++ pvs; 66 } 67 } 68 } 69 else 70 { 71 KdInterior *interior = dynamic_cast<KdInterior *>(node); 72 73 tStack.push(interior->mFront); 74 tStack.push(interior->mBack); 75 } 76 } 77 } 78 else 79 { 80 ++ pvs; 81 } 82 } 83 84 return pvs; 12 85 } 86 87 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r1112 r1141 58 58 59 59 /** Normalize the visibility of entries in order to get comparable 60 results */61 60 results 61 */ 62 62 void NormalizeMaximum(); 63 63 … … 413 413 class KdPvs: public Pvs<KdNode *> 414 414 { 415 public: 415 416 int Compress(); 416 417 }; 417 418 419 420 class ObjectPvs: public Pvs<Intersectable *> 421 { 422 public: 423 /** Counts pvs. Different to GetSize(), not 424 only the raw container size is returned, 425 but the individual contributions of the entries are summed up. 426 */ 427 int CountPvs() const; 428 }; 418 429 419 430 //-- typedefs … … 426 437 typedef PvsData<KdNode *> KdPvsData; 427 438 428 typedef Pvs<Intersectable *> ObjectPvs;439 //typedef Pvs<Intersectable *> ObjectPvs; 429 440 typedef Pvs<ViewCell *> ViewCellPvs; 430 441 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ResourceManager.h
r1004 r1141 49 49 T *CreateResource() 50 50 { 51 const int id = CreateUniqueId();51 const unsigned int id = CreateUniqueId(); 52 52 53 53 T *resource = new T(id); … … 61 61 @returns mesh or NULL if mesh was not found. 62 62 */ 63 T *FindEntry(const int id) const63 T *FindEntry(const unsigned int id) const 64 64 { 65 std::map< int, T *>::const_iterator mit = mEntries.find(id);65 std::map<unsigned int, T *>::const_iterator mit = mEntries.find(id); 66 66 67 67 if (mit != mEntries.end()) … … 76 76 @returns true if the mesh was found, false if not 77 77 */ 78 bool DestroyEntry(const int id)78 bool DestroyEntry(const unsigned int id) 79 79 { 80 80 if (!FindEntry(id)) … … 112 112 ~ResourceManager<T>() 113 113 { 114 std::map< int, T *>::iterator mit, mit_end = mEntries.end();114 std::map<unsigned int, T *>::iterator mit, mit_end = mEntries.end(); 115 115 116 116 for (mit = mEntries.begin(); mit != mEntries.end(); ++ mit) … … 129 129 /** Helper function returning unique id for resource. 130 130 */ 131 static int CreateUniqueId()131 static unsigned int CreateUniqueId() 132 132 { 133 133 return sCurrentId ++; … … 137 137 138 138 /// the resource container 139 std::map< int, T *> mEntries;139 std::map<unsigned int, T *> mEntries; 140 140 141 141 private: 142 142 143 143 static ResourceManager<T> *sResourceManager; 144 static int sCurrentId;144 static unsigned int sCurrentId; 145 145 }; 146 146 147 147 // only instance of the resource manager 148 148 template <typename T> ResourceManager<T> *ResourceManager<T>::sResourceManager = NULL; 149 template <typename T> int ResourceManager<T>::sCurrentId = 0;149 template <typename T> unsigned int ResourceManager<T>::sCurrentId = 0; 150 150 151 151 /// This type is responsible for creation and disposal the meshes -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1139 r1141 823 823 824 824 Debug << "updating active vc: " << (int)viewCells.size() << endl; 825 // find all already merged view cells and remove them from view cells 825 826 // find all already merged view cells and remove them from the 827 // container view cells 826 828 827 829 // sort out all view cells which are not active anymore, i.e., they … … 883 885 const int upper = mViewCellsManager->GetMaxPvsSize(); 884 886 885 const float penalty = EvalPvsPenalty((*vit)->GetPvs(). GetSize(), lower, upper);887 const float penalty = EvalPvsPenalty((*vit)->GetPvs().CountPvs(), lower, upper); 886 888 887 889 mDeviation += fabs(mAvgRenderCost - penalty); … … 943 945 944 946 // TODO: should be done in view cells manager 945 ViewCellInterior *ViewCellsTree::MergeViewCells(ViewCell *l ,946 ViewCell *r ,947 ViewCellInterior *ViewCellsTree::MergeViewCells(ViewCell *left, 948 ViewCell *right, 947 949 int &pvsDiff) //const 948 950 { 949 ViewCellInterior *vc = mViewCellsManager->MergeViewCells(l, r); 951 // create merged view cell 952 ViewCellInterior *vc = 953 mViewCellsManager->MergeViewCells(left, right); 950 954 951 955 // if merge was unsuccessful … … 953 957 954 958 // set to the new parent view cell 955 l ->SetParent(vc);956 r ->SetParent(vc);957 958 // set new size of view cell959 left->SetParent(vc); 960 right->SetParent(vc); 961 962 959 963 if (mUseAreaForPvs) 960 964 { 961 vc->SetArea(l->GetArea() + l->GetArea()); 965 // set new area of view cell 966 // not not correct, but costly to compute real area!! 967 vc->SetArea(left->GetArea() + right->GetArea()); 962 968 } 963 969 else 964 { 965 vc->SetVolume( r->GetVolume() + l->GetVolume());970 { // set new volume of view cell 971 vc->SetVolume(left->GetVolume() + right->GetVolume()); 966 972 } 967 973 … … 971 977 vc->Mail(); 972 978 973 const int pvs1 = l ->GetPvs().GetSize();974 const int pvs2 = r ->GetPvs().GetSize();975 976 977 // new view cells are stored in this vector979 const int pvs1 = left->GetPvs().CountPvs(); 980 const int pvs2 = right->GetPvs().CountPvs(); 981 982 983 // the new view cells are stored in this container 978 984 mMergedViewCells.push_back(vc); 979 985 980 pvsDiff = vc->GetPvs().GetSize() - pvs1 - pvs2; 981 982 983 984 //Ždon't store intermediate pvs 986 pvsDiff = vc->GetPvs().CountPvs() - pvs1 - pvs2; 987 988 989 // don't store pvs in interior cells, just a scalar 985 990 if (mViewCellsStorage == PVS_IN_LEAVES) 986 991 { 987 l ->mPvsSize = l->GetPvs().GetSize();988 l ->mPvsSizeValid = true;992 left->mPvsSize = left->GetPvs().GetSize(); 993 left->mPvsSizeValid = true; 989 994 990 if (!l->IsLeaf()) 991 l->GetPvs().Clear(); 995 // remove pvs, we don't store interior pvss 996 if (!left->IsLeaf()) 997 { 998 left->GetPvs().Clear(); 999 } 1000 1001 right->mPvsSize = right->GetPvs().CountPvs(); 1002 right->mPvsSizeValid = true; 992 1003 993 r->mPvsSize = r->GetPvs().GetSize(); 994 r->mPvsSizeValid = true; 995 996 if (!r->IsLeaf()) 997 r->GetPvs().Clear(); 998 999 } 1000 1004 // remove pvs, we don't store interior pvss 1005 if (!right->IsLeaf()) 1006 { 1007 right->GetPvs().Clear(); 1008 } 1009 } 1001 1010 1002 1011 return vc; … … 1258 1267 const float penalty = 1259 1268 EvalPvsPenalty(vc->GetPvs().GetSize(), lower, upper); 1269 1260 1270 return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) / 1261 1271 (float)mNumActiveViewCells; … … 1274 1284 if (1) 1275 1285 { 1276 const float penalty = EvalPvsPenalty(vc->GetPvs(). GetSize(), lower, upper);1286 const float penalty = EvalPvsPenalty(vc->GetPvs().CountPvs(), lower, upper); 1277 1287 return fabs(mAvgRenderCost - penalty) / (float)mNumActiveViewCells; 1278 1288 } … … 1283 1293 1284 1294 1285 1286 1295 float ViewCellsTree::GetRenderCost(ViewCell *vc) const 1287 1296 { 1288 1297 if (mUseAreaForPvs) 1289 return vc->GetPvs().GetSize() * vc->GetArea(); 1290 1291 return vc->GetPvs().GetSize() * vc->GetVolume(); 1298 { 1299 return vc->GetPvs().CountPvs() * vc->GetArea(); 1300 } 1301 1302 return vc->GetPvs().CountPvs() * vc->GetVolume(); 1292 1303 } 1293 1304 … … 1328 1339 newPvs = (int)ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 1329 1340 1330 const float newPenalty = EvalPvsPenalty(newPvs, 1341 const float newPenalty = EvalPvsPenalty(newPvs, 1331 1342 mViewCellsManager->GetMinPvsSize(), 1332 1343 mViewCellsManager->GetMaxPvsSize()); … … 1477 1488 for (it = interior->mChildren.begin(); it != it_end; ++ it) 1478 1489 { 1479 int pvsSize = GetPvsSize(*it);1490 const int pvsSize = GetPvsSize(*it); 1480 1491 childCost += (float) pvsSize * (*it)->GetVolume(); 1481 1492 childPvs += pvsSize; … … 1603 1614 1604 1615 1605 1606 1616 // delete all the objects from the leaf sets which were moved to parent pvs 1607 1617 ObjectPvsMap::const_iterator oit_end = interior->GetPvs().mEntries.end(); … … 1615 1625 } 1616 1626 } 1617 1618 /*int dummy = interior->GetPvs().GetSize();1619 1620 for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit)1621 {1622 dummy += (*cit)->GetPvs().GetSize();1623 }*/1624 1625 1627 } 1626 1628 … … 1729 1731 { 1730 1732 if (countKdPvs) 1731 pvsSize = vc->GetPvs(). GetSize();1733 pvsSize = vc->GetPvs().CountPvs(); 1732 1734 else 1733 1735 pvsSize = CountKdPvs(dynamic_cast<ViewCellLeaf *>(vc)); … … 1817 1819 case PVS_IN_INTERIORS: 1818 1820 default: 1819 Debug << "in interiors: " << vc->mPvsSize << " $$ " << vc->GetPvs(). GetSize() << endl;1820 pvsSize = vc->GetPvs(). GetSize();1821 Debug << "in interiors: " << vc->mPvsSize << " $$ " << vc->GetPvs().CountPvs() << endl; 1822 pvsSize = vc->GetPvs().CountPvs(); 1821 1823 } 1822 1824 … … 1840 1842 if ((mViewCellsStorage == PVS_IN_INTERIORS) || vc->IsLeaf()) 1841 1843 { 1842 pvsSize = vc->GetPvs(). GetSize();1844 pvsSize = vc->GetPvs().CountPvs(); 1843 1845 } 1844 1846 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r1139 r1141 206 206 return a->mPvsSize < b->mPvsSize; 207 207 #else 208 return a->GetPvs(). GetSize() < b->GetPvs().GetSize();208 return a->GetPvs().CountPvs() < b->GetPvs().CountPvs(); 209 209 #endif 210 210 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
r1106 r1141 1948 1948 << "#polygons: " << (int)data.mPolygons->size() << " (max: " << mTermMinPolys << "), " 1949 1949 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 1950 << "#pvs: " << leaf->GetViewCell()->GetPvs(). GetSize() << "=, "1950 << "#pvs: " << leaf->GetViewCell()->GetPvs().CountPvs() << "=, " 1951 1951 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 1952 1952 #endif -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1139 r1141 226 226 // question: rather create view cells resource manager? 227 227 if (!ViewCellsTreeConstructed()) 228 { 228 229 CLEAR_CONTAINER(mViewCells); 229 230 } 231 230 232 DEL_PTR(mViewCellsTree); 231 233 } … … 301 303 Ray *pray = (*it)->mPiercingRays[0]; 302 304 Debug << "view cell " << (*it)->GetId() << " not empty, pvs: " 303 << (*it)->GetPvs(). GetSize() << " " << (int)pray->intersections.size() << endl;305 << (*it)->GetPvs().CountPvs() << " " << (int)pray->intersections.size() << endl; 304 306 305 307 exporter->ExportRays((*it)->mPiercingRays); … … 1195 1197 { 1196 1198 1197 if ((vc->GetPvs(). GetSize() > maxPvsSize) ||1198 (vc->GetPvs(). GetSize() < minPvsSize))1199 if ((vc->GetPvs().CountPvs() > maxPvsSize) || 1200 (vc->GetPvs().CountPvs() < minPvsSize)) 1199 1201 { 1200 1202 return false; … … 1412 1414 { 1413 1415 ViewCell *vc = *it; 1414 totalRenderCost += vc->GetPvs(). GetSize() * vc->GetVolume();1415 totalPvs += (int)vc->GetPvs(). GetSize();1416 totalRenderCost += vc->GetPvs().CountPvs() * vc->GetVolume(); 1417 totalPvs += (int)vc->GetPvs().CountPvs(); 1416 1418 } 1417 1419 … … 1430 1432 ViewCell *vc = *it; 1431 1433 1432 float renderCost = vc->GetPvs(). GetSize() * vc->GetVolume();1434 float renderCost = vc->GetPvs().CountPvs() * vc->GetVolume(); 1433 1435 float dev; 1434 1436 1435 1437 if (1) 1436 dev = fabs(avgRenderCost - (float)vc->GetPvs(). GetSize());1438 dev = fabs(avgRenderCost - (float)vc->GetPvs().CountPvs()); 1437 1439 else 1438 1440 dev = fabs(expectedRenderCost - renderCost); … … 1591 1593 1592 1594 // update pvs size 1593 vc->mPvsSize = vc->GetPvs(). GetSize();1595 vc->mPvsSize = vc->GetPvs().CountPvs(); 1594 1596 vc->mPvsSizeValid = true; 1595 1597 … … 4065 4067 { 4066 4068 pvs = root->GetPvs(); 4067 SetScalarPvsSize(root, root->GetPvs(). GetSize());4069 SetScalarPvsSize(root, root->GetPvs().CountPvs()); 4068 4070 4069 4071 return; … … 5464 5466 exporter->SetFilled(); 5465 5467 5466 5467 5468 if (1) 5468 5469 { … … 5479 5480 exporter->SetForcedMaterial(m); 5480 5481 5481 // find kd nodes5482 // export pvs entries 5482 5483 for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 5483 5484 { … … 5488 5489 exporter->ExportIntersectable(obj); 5489 5490 obj->Mail(); 5490 }5491 5492 // export "original" pvs5493 m.mDiffuseColor = RgbColor(0, 0, 1);5494 exporter->SetForcedMaterial(m);5495 5496 if ((*oit).first->Type() == Intersectable::KD_INTERSECTABLE)5497 {5498 KdIntersectable *kdObj = dynamic_cast<KdIntersectable *>(obj);5499 Intersectable *hitObj = kdObj->mHitObject;5500 5501 if (!hitObj->Mailed())5502 {5503 exporter->ExportIntersectable(hitObj);5504 hitObj->Mail();5505 }5506 5491 } 5507 5492 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1121 r1141 655 655 /// if pvs should be exported with view cells 656 656 bool mExportPvs; 657 657 // matt§§: need this? 658 658 bool mCountKdPvs; 659 659 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp
r1139 r1141 261 261 262 262 mForcedMaterial.mDiffuseColor.b = 1.0f; 263 const float importance = (float)leaf->GetViewCell()->GetPvs(). GetSize() / (float)maxPvs;263 const float importance = (float)leaf->GetViewCell()->GetPvs().CountPvs() / (float)maxPvs; 264 264 265 265 mForcedMaterial.mDiffuseColor.r = importance; -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1137 r1141 854 854 855 855 // update scalar pvs size lookup 856 mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs(). GetSize());856 mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().CountPvs()); 857 857 858 858 … … 991 991 992 992 // update scalar pvs size value 993 mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs(). GetSize());993 mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().CountPvs()); 994 994 995 995 mBspStats.contributingSamples += conSamp; … … 2343 2343 if (leaf->TreeValid() && 2344 2344 (!onlyUnmailed || !leaf->Mailed()) && 2345 ((maxPvsSize < 0) || (leaf->GetViewCell()->GetPvs(). GetSize() <= maxPvsSize)))2345 ((maxPvsSize < 0) || (leaf->GetViewCell()->GetPvs().CountPvs() <= maxPvsSize))) 2346 2346 { 2347 2347 leaves.push_back(leaf); … … 2420 2420 << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 2421 2421 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 2422 << "#pvs: " << leaf->GetViewCell()->GetPvs(). GetSize() << "), "2422 << "#pvs: " << leaf->GetViewCell()->GetPvs().CountPvs() << "), " 2423 2423 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 2424 2424 #endif -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1139 r1141 364 364 Environment::GetSingleton()->GetBoolValue("VspTree.simulateOctree", mCirculatingAxis); 365 365 366 Environment::GetSingleton()->GetBoolValue("VspTree.useKdPvs ", mUseKdPvs);366 Environment::GetSingleton()->GetBoolValue("VspTree.useKdPvsForHeuristics", mUseKdPvsForHeuristics); 367 367 368 368 char subdivisionStatsLog[100]; … … 400 400 Debug << "maxband: " << mMaxBand << endl; 401 401 402 if (!mUseKdPvs )402 if (!mUseKdPvsForHeuristics) 403 403 Debug << "pvs count method: per object" << endl; 404 404 else … … 534 534 int conSamp = 0; 535 535 float sampCon = 0.0f; 536 Add ToPvs(leaf, *tData.mRays, sampCon, conSamp);536 AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 537 537 538 538 // update scalar pvs size value 539 mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs(). GetSize());539 mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().CountPvs()); 540 540 541 541 mVspStats.contributingSamples += conSamp; … … 847 847 848 848 849 void VspTree::AddToPvs(VspLeaf *leaf, 850 const RayInfoContainer &rays, 851 float &sampleContributions, 852 int &contributingSamples) 849 bool VspTree::AddKdLeafToPvs(KdLeaf *leaf, 850 ViewCell *vc, 851 float &pdf, 852 float &contribution) 853 { 854 bool contri = false; 855 856 #if 1 // add kd intersecable to pvs 857 KdIntersectable *kdObj = mOspTree->GetOrCreateKdIntersectable(leaf); 858 859 if (vc->AddPvsSample(kdObj, pdf, contribution)) 860 { 861 return true; 862 } 863 864 #else // add all objects of kd node 865 866 pdf = 0; 867 contribution = 0; 868 869 ObjectContainer::const_iterator it, it_end = leaf->mObjects.end(); 870 871 for (it = leaf->mObjects.begin(); it != it_end; ++ it) 872 { 873 Intersectable *object = *it; 874 875 float newpdf; 876 float newcontri; 877 878 if (vc->AddPvsSample(object, newpdf, newcontri)) 879 { 880 contri = true; 881 } 882 883 pdf += newPdf; 884 newContri += contribution; 885 } 886 887 #endif 888 889 return contri; 890 } 891 892 void VspTree::AddSamplesToPvs(VspLeaf *leaf, 893 const RayInfoContainer &rays, 894 float &sampleContributions, 895 int &contributingSamples) 853 896 { 854 897 sampleContributions = 0; … … 859 902 ViewCellLeaf *vc = leaf->GetViewCell(); 860 903 904 861 905 // add contributions from samples to the PVS 862 906 for (it = rays.begin(); it != it_end; ++ it) … … 875 919 876 920 // potentially visible kd cells 877 if (m UseKdPvs)921 if (mStoreKdPvs) 878 922 { 879 923 KdLeaf *leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 880 KdIntersectable *kdObj = new KdIntersectable(leaf); 881 882 entry = kdObj; 924 AddKdLeafToPvs(leaf, vc, ray->mPdf, contribution); 883 925 } 884 926 else 885 entry = obj;886 887 if (vc->AddPvsSample(obj, ray->mPdf, contribution))888 {889 madeContrib = true;927 { 928 if (vc->AddPvsSample(obj, ray->mPdf, contribution)) 929 { 930 madeContrib = true; 931 } 890 932 } 891 933 … … 900 942 901 943 // potentially visible kd cells 902 if (mUseKdPvs) 903 { 904 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 905 KdIntersectable *kdObj = new KdIntersectable(leaf); 906 907 entry = kdObj; 944 if (mUseKdPvsForHeuristics) 945 { 946 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 947 AddKdLeafToPvs(leaf, vc, ray->mPdf, contribution); 908 948 } 909 949 else 910 entry = obj;911 912 if (vc->AddPvsSample(obj, ray->mPdf, contribution))913 {914 madeContrib = true;950 { 951 if (vc->AddPvsSample(obj, ray->mPdf, contribution)) 952 { 953 madeContrib = true; 954 } 915 955 } 916 956 … … 919 959 920 960 if (madeContrib) 961 { 921 962 ++ contributingSamples; 922 963 } 964 923 965 // store rays for visualization 924 966 if (0) leaf->mVssRays.push_back(new VssRay(*ray)); … … 1056 1098 if (oObject) 1057 1099 { 1058 if (!mUseKdPvs )1100 if (!mUseKdPvsForHeuristics) 1059 1101 { 1060 1102 if (!oObject->Mailed()) … … 1080 1122 if (tObject) 1081 1123 { 1082 if (!mUseKdPvs )1124 if (!mUseKdPvsForHeuristics) 1083 1125 { 1084 1126 if (!tObject->Mailed()) … … 1166 1208 if (oObject) 1167 1209 { 1168 if (!mUseKdPvs )1210 if (!mUseKdPvsForHeuristics) 1169 1211 { 1170 1212 if (ci.type == SortableEntry::ERayMin) … … 1202 1244 if (tObject) 1203 1245 { 1204 if (!mUseKdPvs )1246 if (!mUseKdPvsForHeuristics) 1205 1247 { 1206 1248 if (ci.type == SortableEntry::ERayMin) … … 1615 1657 if (leaf->TreeValid() && 1616 1658 (!onlyUnmailed || !leaf->Mailed()) && 1617 ((maxPvsSize < 0) || (leaf->GetViewCell()->GetPvs(). GetSize() <= maxPvsSize)))1659 ((maxPvsSize < 0) || (leaf->GetViewCell()->GetPvs().CountPvs() <= maxPvsSize))) 1618 1660 { 1619 1661 leaves.push_back(leaf); … … 1692 1734 << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 1693 1735 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 1694 << "#pvs: " << leaf->GetViewCell()->GetPvs(). GetSize() << "), "1736 << "#pvs: " << leaf->GetViewCell()->GetPvs().CountPvs() << "), " 1695 1737 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 1696 1738 #endif … … 2707 2749 } 2708 2750 2751 2752 OspTree::~OspTree() 2753 { 2754 KdIntersectableMap::iterator it, it_end = mKdIntersectables.end(); 2755 2756 for (it = mKdIntersectables.begin(); it != mKdIntersectables.end(); ++ it) 2757 { 2758 DEL_PTR((*it).second); 2759 } 2760 } 2709 2761 2710 2762 … … 3895 3947 3896 3948 3949 KdIntersectable *OspTree::GetOrCreateKdIntersectable(KdNode *node) 3950 { 3951 // search nodes 3952 std::map<KdNode *, KdIntersectable *>::const_iterator it = mKdIntersectables.find(node); 3953 3954 if (it != mKdIntersectables.end()) 3955 { 3956 return (*it).second; 3957 } 3958 3959 // not in map => create new entry 3960 KdIntersectable *kdObj= new KdIntersectable(node); 3961 3962 mKdIntersectables[node] = kdObj; 3963 3964 return kdObj; 3965 } 3897 3966 3898 3967 … … 3900 3969 /* class HierarchyManager implementation */ 3901 3970 /********************************************************************/ 3902 3903 3971 3904 3972 … … 4068 4136 // makes no sense otherwise because only one kd cell available 4069 4137 // during view space partition 4070 const bool savedCountMethod = mVspTree.mUseKdPvs; 4071 mVspTree.mUseKdPvs = false; 4138 const bool savedCountMethod = mVspTree.mUseKdPvsForHeuristics; 4139 const bool savedStoreMethod = mVspTree.mStoreKdPvs; 4140 4141 mVspTree.mUseKdPvsForHeuristics = false; 4142 mVspTree.mStoreKdPvs = false; 4072 4143 4073 4144 mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, *viewSpaceRays)); … … 4148 4219 cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 4149 4220 4150 mVspTree.mUseKdPvs = savedCountMethod; 4221 mVspTree.mUseKdPvsForHeuristics = savedCountMethod; 4222 mVspTree.mStoreKdPvs = savedStoreMethod; 4151 4223 } 4152 4224 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1139 r1141 33 33 class KdLeaf; 34 34 class OspTree; 35 class KdIntersectable; 36 35 37 36 38 … … 461 463 #endif 462 464 465 typedef map<KdNode *, KdIntersectable *> KdIntersectableMap; 466 463 467 typedef FlexibleHeap<SplitCandidate *> SplitQueue; 464 468 … … 980 984 981 985 */ 982 void Add ToPvs(VspLeaf *leaf,986 void AddSamplesToPvs(VspLeaf *leaf, 983 987 const RayInfoContainer &rays, 984 988 float &sampleContributions, 985 989 int &contributingSamples); 990 991 bool AddKdLeafToPvs(KdLeaf *leaf, ViewCell *vc, float &pvs, float &contribution); 986 992 987 993 /** Propagates valid flag up the tree. … … 1018 1024 protected: 1019 1025 1020 bool mUseKdPvs; 1021 1022 enum {PER_OBJECT, PER_KDLEAF}; 1026 bool mUseKdPvsForHeuristics; 1027 bool mStoreKdPvs; 1023 1028 1024 1029 ViewCellsManager *mViewCellsManager; … … 1036 1041 /// box around the whole view domain 1037 1042 AxisAlignedBox3 mBoundingBox; 1038 1039 1043 1040 1044 … … 1339 1343 #endif 1340 1344 1345 /** Returns or creates a new intersectable for use in a kd based pvs. 1346 The OspTree is responsible for destruction of the intersectable. 1347 */ 1348 KdIntersectable *GetOrCreateKdIntersectable(KdNode *node); 1349 1341 1350 /** Collects rays stored in the leaves. 1342 1351 */ … … 1549 1558 float &pFront, 1550 1559 float &pBack); 1551 /** Adds ray sample contributions to the PVS. 1552 @param sampleContributions the number contributions of the samples 1553 @param contributingSampels the number of contributing rays 1554 1555 */ 1556 void AddToPvs(VspLeaf *leaf, 1557 const RayInfoContainer &rays, 1558 float &sampleContributions, 1559 int &contributingSamples); 1560 1560 1561 1561 /** Propagates valid flag up the tree. 1562 1562 */ … … 1667 1667 1668 1668 1669 1670 1669 //-- split heuristics based parameters 1671 1670 … … 1698 1697 /// weight between render cost decrease and node render cost 1699 1698 float mRenderCostDecreaseWeight; 1699 1700 /// stores the kd node intersectables used for pvs 1701 KdIntersectableMap mKdIntersectables; 1700 1702 }; 1701 1703 -
GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp
r1121 r1141 297 297 298 298 mForcedMaterial.mDiffuseColor.b = 1.0f; 299 const float importance = (float)leaf->GetViewCell()->GetPvs().GetSize() / (float)maxPvs; 299 const float importance = 300 (float)leaf->GetViewCell()->GetPvs().CountPvs() / (float)maxPvs; 300 301 301 302 mForcedMaterial.mDiffuseColor.r = importance;
Note: See TracChangeset
for help on using the changeset viewer.