- Timestamp:
- 12/23/05 11:05:33 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r478 r479 177 177 Simulation { 178 178 objRenderCost 1.0 179 vcOverhead 7.0 180 moveSpeed 3.0 179 vcOverhead 2.0 180 # always between 0 and 1 181 moveSpeed 0.00002 181 182 } 182 183 … … 208 209 # maximal cost for merging a view cell 209 210 PostProcess { 210 maxCostRatio 5000000211 maxCostRatio 1.4 211 212 minViewCells 100 212 213 maxPvsSize 50000 … … 240 241 241 242 # maximal tested rays for split cost heuristics 242 maxTests 10000243 maxTests 500 243 244 244 245 # factors for evaluating split plane costs … … 261 262 #maxAccRayLength 100 262 263 263 maxViewCells 1 500264 maxViewCells 1000 264 265 265 266 # used for pvs criterium … … 288 289 289 290 PostProcess { 290 maxCostRatio 5000000291 minViewCells 1000292 maxPvsSize 500 00291 maxCostRatio 0.05 292 minViewCells 700 293 maxPvsSize 500 293 294 } 294 295 } -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
r477 r479 77 77 // probability of view cell 78 78 const float pInVc = mViewCellsManager->GetProbability(vc); 79 Debug << "prop: " << pInVc << endl;80 79 // compute render time of PVS times probability that view point is in view cell 81 80 const float vcCost = pInVc * mViewCellsManager->GetRendercost(vc, mObjRenderCost); 82 Debug << "cost: " << vcCost << " rcost: " 83 << mViewCellsManager->GetRendercost(vc, mObjRenderCost) << endl; 84 81 85 82 // crossing the border of a view cell is depending on the move speed 86 83 // and the probability that a view cell border is crossed 87 84 loadPvsOverhead += GetCrossVcProbability() * mVcOverhead; 88 85 89 Debug << "crossvc: " << GetCrossVcProbability() * mVcOverhead << endl;90 86 //-- update statistics 91 87 renderTime += vcCost; … … 105 101 } 106 102 103 107 104 float RenderSimulator::GetCrossVcProbability() const 108 105 { 109 106 // assume the view cells are uniformly distributed 107 //NOTE: should I take move speed relative to view space or absolute? 110 108 const float vcNum = 111 109 (float)mViewCellsManager->GetViewCells().size(); 112 110 113 return 1.0f - (1 / mMoveSpeed * vcNum); 111 const float prop = mMoveSpeed * vcNum; 112 113 // clamp probability between 0 and 1 114 return min(1.0f, prop); 114 115 } 115 116 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r478 r479 55 55 } 56 56 57 void ViewCell::UpdateViewCellsStats(ViewCellsStatistics &vcStat) 58 { 59 ++ vcStat.viewCells; 60 61 const int pvsSize = mPvs.GetSize(); 62 63 vcStat.pvs += pvsSize; 64 65 if (pvsSize == 0) 66 ++ vcStat.emptyPvs; 67 68 if (pvsSize > vcStat.maxPvs) 69 vcStat.maxPvs = pvsSize; 70 71 if (pvsSize < vcStat.minPvs) 72 vcStat.minPvs = pvsSize; 73 } 57 74 58 75 float ViewCell::GetArea() const -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r478 r479 16 16 class VspKdLeaf; 17 17 class KdLeaf; 18 19 /**20 View cell with an optional mesh representation21 */22 class ViewCell: public MeshInstance23 {24 public:25 ViewCell();26 27 /** Constructor taking a mesh representing the shape of the viewcell.28 */29 ViewCell(Mesh *mesh);30 31 /** Default destructor.32 */33 virtual ~ViewCell() {}34 /** Returns Pvs.35 */36 const ObjectPvs &GetPvs() const;37 ObjectPvs &GetPvs();38 39 int Type() const;40 41 /** Adds a passing ray to the passing ray container.42 */43 void AddPassingRay(const Ray &ray, const int contributions);44 45 /** Returns volume of the view cell.46 */47 float GetVolume() const;48 49 /** Returns area of the view cell.50 */51 float GetArea() const;52 53 /** Sets the volume of the view cell.54 */55 void SetVolume(float volume);56 57 /** Sets the area of the view cell.58 */59 void SetArea(float area);60 61 /// Ray set description of the rays passing through this node.62 PassingRaySet mPassingRays;63 64 /// Rays piercing this view cell.65 RayContainer mPiercingRays;66 67 protected:68 69 /// the potentially visible objects70 ObjectPvs mPvs;71 72 float mVolume;73 float mArea;74 };75 76 /**77 View cell belonging to a hierarchy.78 */79 template<typename T>80 class HierarchyViewCell: public ViewCell81 {82 public:83 HierarchyViewCell<T>(): mLeaves(0) {}84 HierarchyViewCell<T>(Mesh *mesh):85 ViewCell(mesh), mLeaves(0) {}86 87 /// Leaves of the hierarchy which are part of this view cell.88 std::vector<T> mLeaves;89 };90 91 typedef HierarchyViewCell<BspLeaf *> BspViewCell;92 typedef HierarchyViewCell<KdLeaf *> KdViewCell;93 typedef HierarchyViewCell<VspKdLeaf *> VspKdViewCell;94 95 18 96 19 /** Statistics for a view cell partition. … … 152 75 }; 153 76 77 /** 78 View cell with an optional mesh representation 79 */ 80 class ViewCell: public MeshInstance 81 { 82 public: 83 ViewCell(); 84 85 /** Constructor taking a mesh representing the shape of the viewcell. 86 */ 87 ViewCell(Mesh *mesh); 88 89 /** Default destructor. 90 */ 91 virtual ~ViewCell() {} 92 /** Returns Pvs. 93 */ 94 const ObjectPvs &GetPvs() const; 95 ObjectPvs &GetPvs(); 96 97 int Type() const; 98 99 /** Adds a passing ray to the passing ray container. 100 */ 101 void AddPassingRay(const Ray &ray, const int contributions); 102 103 /** Returns volume of the view cell. 104 */ 105 float GetVolume() const; 106 107 /** Returns area of the view cell. 108 */ 109 float GetArea() const; 110 111 /** Sets the volume of the view cell. 112 */ 113 void SetVolume(float volume); 114 115 /** Sets the area of the view cell. 116 */ 117 void SetArea(float area); 118 virtual void UpdateViewCellsStats(ViewCellsStatistics &vcStat); 119 120 /// Ray set description of the rays passing through this node. 121 PassingRaySet mPassingRays; 122 123 /// Rays piercing this view cell. 124 RayContainer mPiercingRays; 125 126 protected: 127 128 /// the potentially visible objects 129 ObjectPvs mPvs; 130 131 float mVolume; 132 float mArea; 133 }; 134 135 /** 136 View cell belonging to a hierarchy. 137 */ 138 template<typename T> 139 class HierarchyViewCell: public ViewCell 140 { 141 public: 142 HierarchyViewCell<T>(): mLeaves(0) {} 143 HierarchyViewCell<T>(Mesh *mesh): 144 ViewCell(mesh), mLeaves(0) {} 145 146 void UpdateViewCellsStats(ViewCellsStatistics &vcStat) 147 { 148 ViewCell::UpdateViewCellsStats(vcStat); 149 150 if ((int)mLeaves.size() > vcStat.maxLeaves) 151 vcStat.maxLeaves = (int)mLeaves.size(); 152 } 153 154 /// Leaves of the hierarchy which are part of this view cell. 155 std::vector<T> mLeaves; 156 }; 157 158 159 typedef HierarchyViewCell<BspLeaf *> BspViewCell; 160 typedef HierarchyViewCell<KdLeaf *> KdViewCell; 161 typedef HierarchyViewCell<VspKdLeaf *> VspKdViewCell; 162 163 154 164 #endif -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r478 r479 1178 1178 1179 1179 Plane3 BspTree::ChooseCandidatePlane(const BoundedRayContainer &rays) const 1180 { return Plane3(); 1181 /*const int candidateIdx = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 1182 1183 const Vector3 minPt = rays[candidateIdx].ExtrapOrigin(); 1184 const Vector3 maxPt = rays[candidateIdx].ExtrapTermination(); 1180 { 1181 const int candidateIdx = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 1182 BoundedRay *bRay = rays[candidateIdx]; 1183 Ray *ray = bRay->mRay; 1184 1185 const Vector3 minPt = ray->Extrap(bRay->mMinT); 1186 const Vector3 maxPt = ray->Extrap(bRay->mMaxT); 1185 1187 1186 1188 const Vector3 pt = (maxPt + minPt) * 0.5; 1187 const Vector3 normal = Normalize(rays[candidateIdx].mRay->GetDir()); 1188 1189 return Plane3(normal, pt);*/ 1189 1190 const Vector3 normal = ray->GetDir(); 1191 1192 return Plane3(normal, pt); 1190 1193 } 1191 1194 1192 1195 Plane3 BspTree::ChooseCandidatePlane2(const BoundedRayContainer &rays) const 1193 { return Plane3(); 1194 /*Vector3 pt[3]; 1195 1196 { 1197 Vector3 pt[3]; 1196 1198 int idx[3]; 1197 1199 int cmaxT = 0; … … 1199 1201 bool chooseMin = false; 1200 1202 1201 for (int j = 0; j < 3; ++ j)1202 { 1203 idx[j] = (int)RandomValue(0, (Real)((int)rays.size() * 2 - 1));1204 1203 for (int j = 0; j < 3; j ++) 1204 { 1205 idx[j] = (int)RandomValue(0, Real((int)rays.size() * 2 - 1)); 1206 1205 1207 if (idx[j] >= (int)rays.size()) 1206 1208 { 1207 idx[j] -= (int)rays.size(); 1208 1209 idx[j] -= (int)rays.size(); 1209 1210 chooseMin = (cminT < 2); 1210 1211 } … … 1212 1213 chooseMin = (cmaxT < 2); 1213 1214 1214 RayInfo rayInf = rays[idx[j]]; 1215 pt[j] = chooseMin ? rayInf.ExtrapOrigin() : rayInf.ExtrapTermination(); 1215 BoundedRay *bRay = rays[idx[j]]; 1216 pt[j] = chooseMin ? bRay->mRay->Extrap(bRay->mMinT) : 1217 bRay->mRay->Extrap(bRay->mMaxT); 1216 1218 } 1217 1218 return Plane3(pt[0], pt[1], pt[2]); */1219 1220 return Plane3(pt[0], pt[1], pt[2]); 1219 1221 } 1220 1222 1221 1223 Plane3 BspTree::ChooseCandidatePlane3(const BoundedRayContainer &rays) const 1222 { return Plane3();/*1224 { 1223 1225 Vector3 pt[3]; 1224 1226 … … 1230 1232 idx2 = (idx2 + 1) % (int)rays.size(); 1231 1233 1232 const RayInforay1 = rays[idx1];1233 const RayInforay2 = rays[idx2];1234 const BoundedRay *ray1 = rays[idx1]; 1235 const BoundedRay *ray2 = rays[idx2]; 1234 1236 1235 1237 // normal vector of the plane parallel to both lines 1236 const Vector3 norm = Normalize(CrossProd(ray1.mRay->GetDir(), ray2.mRay->GetDir())); 1238 const Vector3 norm = 1239 Normalize(CrossProd(ray1->mRay->GetDir(), ray2->mRay->GetDir())); 1240 1241 const Vector3 orig1 = ray1->mRay->Extrap(ray1->mMinT); 1242 const Vector3 orig2 = ray2->mRay->Extrap(ray2->mMinT); 1237 1243 1238 1244 // vector from line 1 to line 2 1239 const Vector3 vd = (ray2.ExtrapOrigin() - ray1.ExtrapOrigin());1245 const Vector3 vd = orig1 - orig2; 1240 1246 1241 1247 // project vector on normal to get distance … … 1243 1249 1244 1250 // point on plane lies halfway between the two planes 1245 const Vector3 planePt = ray1.ExtrapOrigin()+ norm * dist * 0.5;1246 1247 return Plane3(norm, planePt); */1251 const Vector3 planePt = orig1 + norm * dist * 0.5; 1252 1253 return Plane3(norm, planePt); 1248 1254 } 1249 1255 … … 2011 2017 } 2012 2018 2013 void BspTree::EvaluateViewCellsStats(ViewCellsStatistics &vcStat) const2014 {2015 vcStat.Reset();2016 2017 stack<BspNode *> nodeStack;2018 nodeStack.push(mRoot);2019 2020 ViewCell::NewMail();2021 2022 // exclude root cell2023 mRootCell->Mail();2024 2025 while (!nodeStack.empty())2026 {2027 BspNode *node = nodeStack.top();2028 nodeStack.pop();2029 2030 if (node->IsLeaf())2031 {2032 ++ vcStat.leaves;2033 2034 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->mViewCell;2035 2036 if (!viewCell->Mailed())2037 {2038 viewCell->Mail();2039 2040 ++ vcStat.viewCells;2041 const int pvsSize = viewCell->GetPvs().GetSize();2042 2043 vcStat.pvs += pvsSize;2044 2045 if (pvsSize < 1)2046 ++ vcStat.emptyPvs;2047 2048 if (pvsSize > vcStat.maxPvs)2049 vcStat.maxPvs = pvsSize;2050 2051 if (pvsSize < vcStat.minPvs)2052 vcStat.minPvs = pvsSize;2053 2054 if ((int)viewCell->mLeaves.size() > vcStat.maxLeaves)2055 vcStat.maxLeaves = (int)viewCell->mLeaves.size();2056 }2057 }2058 else2059 {2060 BspInterior *interior = dynamic_cast<BspInterior *>(node);2061 2062 nodeStack.push(interior->GetFront());2063 nodeStack.push(interior->GetBack());2064 }2065 }2066 }2067 2019 2068 2020 BspTreeStatistics &BspTree::GetStat() … … 2070 2022 return mStat; 2071 2023 } 2024 2072 2025 2073 2026 float BspTree::AccumulatedRayLength(BoundedRayContainer &rays) const … … 2085 2038 return len; 2086 2039 } 2040 2087 2041 2088 2042 int BspTree::SplitRays(const Plane3 &plane, -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r478 r479 457 457 BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 458 458 459 /** Traverses tree and counts all view cells as well as their PVS size.460 */461 void EvaluateViewCellsStats(ViewCellsStatistics &stat) const;462 463 459 /** Returns view cell corresponding to unbounded space. 464 460 */ -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r478 r479 72 72 } 73 73 74 void ViewCellsManager::EvaluateViewCellsStats() 75 { 76 mViewCellsStats.Reset(); 77 78 ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 79 80 for (it = mViewCells.begin(); it != it_end; ++ it) 81 (*it)->UpdateViewCellsStats(mViewCellsStats); 82 } 83 74 84 void ViewCellsManager::AddViewCell(ViewCell *viewCell) 75 85 { … … 378 388 } 379 389 380 mBspTree->EvaluateViewCellsStats(mViewCellsStats);390 EvaluateViewCellsStats(); 381 391 382 392 // destroy rays created only for construction … … 396 406 // compute view cell area as subsititute for probability 397 407 #if 0 398 return GetArea(viewCell) / mBspTree->GetBoundingBox().SurfaceArea();408 return GetArea(viewCell) / GetSceneBbox().SurfaceArea(); 399 409 #else 400 410 return GetArea(viewCell) / GetAccVcArea(); … … 520 530 // reset view cells and stats 521 531 mViewCells.clear(); 532 mTotalAreaValid = false; 522 533 mBspTree->CollectViewCells(mViewCells); 523 534 mViewCellsStats.Reset(); 524 mBspTree->EvaluateViewCellsStats(mViewCellsStats);535 EvaluateViewCellsStats(); 525 536 526 537 return merged; … … 699 710 CLEAR_CONTAINER(vcGeom); 700 711 } 712 701 713 702 714 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() … … 840 852 float KdViewCellsManager::GetProbability(ViewCell *viewCell) 841 853 { 842 // compute view cell area as subsititute for probability 843 AxisAlignedBox3 box = mKdTree->GetBox(mKdTree->GetRoot()); 854 // compute view cell area / volume as subsititute for probability 844 855 #if 0 845 return GetArea(viewCell) / box.SurfaceArea(); 846 #else 856 return GetArea(viewCell) / GetSceneBbox().SurfaceArea(); 857 #endif 858 #if 1 847 859 return GetArea(viewCell) / GetAccVcArea(); 848 860 #endif 861 #if 0 862 return GetVolume(viewCell) / GetSceneBbox().GetVolume(); 863 #endif 849 864 } 850 865 … … 855 870 } 856 871 872 857 873 AxisAlignedBox3 KdViewCellsManager::GetSceneBbox() const 858 874 { 859 875 return mKdTree->GetBox(); 860 876 } 877 861 878 862 879 int KdViewCellsManager::Construct(const ObjectContainer &objects, … … 872 889 // create the view cells 873 890 mKdTree->CreateAndCollectViewCells(mViewCells); 874 //mKdTree->EvaluateViewCellsStats(mViewCellsStats);891 EvaluateViewCellsStats(); 875 892 876 893 return 0; … … 901 918 const int pvsOut = min((int)objects.size(), 10); 902 919 VssRayContainer *rays = new VssRayContainer[pvsOut]; 903 904 //$$ JB905 //#if 0906 920 907 921 if (useViewCells) … … 927 941 928 942 cout << "creating output for view cell " << i << " ... "; 929 943 #if 0 930 944 // check whether we can add the current ray to the output rays 931 /*for (int k = 0; k < raysOut; ++ k)945 for (int k = 0; k < raysOut; ++ k) 932 946 { 933 947 Ray *ray = sampleRays[k]; … … 942 956 } 943 957 } 944 } */945 958 } 959 #endif 946 960 Intersectable::NewMail(); 947 961 … … 1136 1150 mVspKdTree->Construct(constructionRays, sceneBbox); 1137 1151 mVspKdTree->CollectViewCells(mViewCells); 1138 //mVspBspTree->EvaluateViewCellsStats(mViewCellsStats);1152 EvaluateViewCellsStats(); 1139 1153 1140 1154 Debug << mVspKdTree->GetStatistics() << endl; … … 1331 1345 { 1332 1346 #if 0 1333 return GetArea(viewCell) / mVspBspTree->GetBbox().SurfaceArea();1347 return GetArea(viewCell) / GetSceneBbox().SurfaceArea(); 1334 1348 #else 1335 1349 return GetArea(viewCell) / GetAccVcArea(); … … 1338 1352 1339 1353 1340 float VspBspViewCellsManager::GetArea(ViewCell *viewCell) const1341 {1342 PolygonContainer geom;1343 1344 // compute view cell area1345 mVspBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(viewCell), geom);1346 1347 const float area = Polygon3::GetArea(geom);1348 CLEAR_CONTAINER(geom);1349 1350 return area;1351 }1352 1353 1354 float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell, 1354 1355 float objRendercost) const … … 1392 1393 mVspBspTree->Construct(constructionRays); 1393 1394 mVspBspTree->CollectViewCells(mViewCells); 1394 mVspBspTree->EvaluateViewCellsStats(mViewCellsStats);1395 EvaluateViewCellsStats(); 1395 1396 1396 1397 Debug << mVspBspTree->GetStatistics() << endl; … … 1532 1533 // reset view cells and stats 1533 1534 mViewCells.clear(); 1535 mTotalAreaValid = false; 1534 1536 mVspBspTree->CollectViewCells(mViewCells); 1535 1537 mViewCellsStats.Reset(); 1536 mVspBspTree->EvaluateViewCellsStats(mViewCellsStats);1538 EvaluateViewCellsStats(); 1537 1539 1538 1540 return merged; … … 1696 1698 CLEAR_CONTAINER(vcGeom); 1697 1699 } 1700 1698 1701 1699 1702 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r478 r479 207 207 208 208 protected: 209 /** Evaluates view cells statistics and stores it in 210 mViewCellsStatistics. 211 */ 212 void EvaluateViewCellsStats(); 209 213 210 214 /// the view cell corresponding to unbounded space … … 438 442 float GetProbability(ViewCell *viewCell); 439 443 float GetRendercost(ViewCell *viewCell, float objRendercost) const; 440 float GetArea(ViewCell *viewCell) const; 441 444 442 445 AxisAlignedBox3 GetSceneBbox() const; 443 446 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r478 r479 800 800 801 801 // vector from line 1 to line 2 802 const Vector3 vd = (ray2.ExtrapOrigin() - ray1.ExtrapOrigin());802 const Vector3 vd = ray2.ExtrapOrigin() - ray1.ExtrapOrigin(); 803 803 804 804 // project vector on normal to get distance … … 1306 1306 } 1307 1307 1308 void VspBspTree::EvaluateViewCellsStats(ViewCellsStatistics &stat) const1309 {1310 stat.Reset();1311 1312 stack<BspNode *> nodeStack;1313 nodeStack.push(mRoot);1314 1315 ViewCell::NewMail();1316 1317 // exclude root cell1318 mRootCell->Mail();1319 1320 while (!nodeStack.empty())1321 {1322 BspNode *node = nodeStack.top();1323 nodeStack.pop();1324 1325 if (node->IsLeaf())1326 {1327 ++ stat.leaves;1328 1329 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell();1330 1331 if (!viewCell->Mailed())1332 {1333 viewCell->Mail();1334 1335 ++ stat.viewCells;1336 const int pvsSize = viewCell->GetPvs().GetSize();1337 1338 stat.pvs += pvsSize;1339 1340 if (pvsSize < 1)1341 ++ stat.emptyPvs;1342 1343 if (pvsSize > stat.maxPvs)1344 stat.maxPvs = pvsSize;1345 1346 if (pvsSize < stat.minPvs)1347 stat.minPvs = pvsSize;1348 1349 if ((int)viewCell->mLeaves.size() > stat.maxLeaves)1350 stat.maxLeaves = (int)viewCell->mLeaves.size();1351 }1352 }1353 else1354 {1355 BspInterior *interior = dynamic_cast<BspInterior *>(node);1356 1357 nodeStack.push(interior->GetFront());1358 nodeStack.push(interior->GetBack());1359 }1360 }1361 }1362 1308 1363 1309 BspTreeStatistics &VspBspTree::GetStat() … … 1365 1311 return mStat; 1366 1312 } 1313 1367 1314 1368 1315 float VspBspTree::AccumulatedRayLength(const RayInfoContainer &rays) const … … 1377 1324 return len; 1378 1325 } 1326 1379 1327 1380 1328 int VspBspTree::SplitRays(const Plane3 &plane, … … 1426 1374 return splits; 1427 1375 } 1376 1428 1377 1429 1378 void VspBspTree::ExtractHalfSpaces(BspNode *n, vector<Plane3> &halfSpaces) const … … 1889 1838 } 1890 1839 1840 1841 BspNode *VspBspTree::CollapseTree(BspNode *node) 1842 { 1843 if (node->IsLeaf()) 1844 return node; 1845 1846 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1847 1848 BspNode *front = CollapseTree(interior->GetFront()); 1849 BspNode *back = CollapseTree(interior->GetBack()); 1850 1851 if (front->IsLeaf() && back->IsLeaf()) 1852 { 1853 BspLeaf *frontLeaf = dynamic_cast<BspLeaf *>(front); 1854 BspLeaf *backLeaf = dynamic_cast<BspLeaf *>(back); 1855 1856 //-- collapse tree 1857 if (frontLeaf->GetViewCell() == backLeaf->GetViewCell()) 1858 { 1859 BspViewCell *vc = frontLeaf->GetViewCell(); 1860 1861 BspLeaf *leaf = new BspLeaf(interior->GetParent(), vc); 1862 1863 // replace a link from node's parent 1864 if (leaf->GetParent()) 1865 leaf->GetParent()->ReplaceChildLink(node, leaf); 1866 1867 delete interior; 1868 1869 return leaf; 1870 } 1871 } 1872 1873 return node; 1874 } 1875 1876 1877 void VspBspTree::RepairVcLeafLists() 1878 { 1879 // list not valid anymore => clear 1880 stack<BspNode *> nodeStack; 1881 nodeStack.push(mRoot); 1882 1883 ViewCell::NewMail(); 1884 1885 while (!nodeStack.empty()) 1886 { 1887 BspNode *node = nodeStack.top(); 1888 nodeStack.pop(); 1889 1890 if (node->IsLeaf()) 1891 { 1892 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 1893 1894 BspViewCell *viewCell = leaf->GetViewCell(); 1895 1896 if (!viewCell->Mailed()) 1897 { 1898 viewCell->mLeaves.clear(); 1899 viewCell->Mail(); 1900 } 1901 1902 viewCell->mLeaves.push_back(leaf); 1903 } 1904 else 1905 { 1906 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1907 1908 nodeStack.push(interior->GetFront()); 1909 nodeStack.push(interior->GetBack()); 1910 } 1911 } 1912 } 1913 1914 1891 1915 int VspBspTree::MergeLeaves() 1892 1916 { … … 1933 1957 int merged = 0; 1934 1958 1935 Debug << "here234: " << mMergeMaxCostRatio << endl; 1959 Debug << "mergecost: " << mergeQueue.top().GetMergeCost() / BspMergeCandidate::sOverallCost << " " << mMergeMaxCostRatio << endl; 1960 Debug << "overall cost: " << BspMergeCandidate::sOverallCost << endl; 1936 1961 1937 1962 // use priority queue to merge leaves 1938 while (!mergeQueue.empty() && (vcSize > mMergeMinViewCells) )//&&1939 //(mergeQueue.top().GetMergeCost() <1940 //mMergeMaxCostRatio /BspMergeCandidate::sOverallCost))1941 { 1942 Debug << "mergecost: " << mergeQueue.top().GetMergeCost() << " " << mMergeMaxCostRatio << endl;1963 while (!mergeQueue.empty() && (vcSize > mMergeMinViewCells) && 1964 (mergeQueue.top().GetMergeCost() < 1965 mMergeMaxCostRatio * BspMergeCandidate::sOverallCost)) 1966 { 1967 Debug << "mergecost: " << mergeQueue.top().GetMergeCost() / BspMergeCandidate::sOverallCost << " " << mMergeMaxCostRatio << endl; 1943 1968 BspMergeCandidate mc = mergeQueue.top(); 1944 1969 mergeQueue.pop(); … … 1970 1995 1971 1996 // collapse tree according to view cell partition 1972 //CollapseTree(mRoot); 1973 1997 CollapseTree(mRoot); 1974 1998 // revalidate leaves 1975 //ValidateViewCellLeaves();1999 RepairVcLeafLists(); 1976 2000 1977 2001 //Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl; … … 1996 2020 1997 2021 // set new size of view cell 1998 vc->SetArea(fVc->Get Volume() + bVc->GetVolume());2022 vc->SetArea(fVc->GetArea() + bVc->GetArea()); 1999 2023 2000 2024 vector<BspLeaf *> fLeaves = fVc->mLeaves; -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r478 r479 225 225 BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 226 226 227 /** Traverses tree and counts all view cells as well as their PVS size.228 */229 void EvaluateViewCellsStats(ViewCellsStatistics &stat) const;230 231 232 227 /** Returns view cell corresponding to unbounded space. 233 228 */ … … 246 241 */ 247 242 int MergeLeaves(); 248 249 250 243 251 244 /** Sets pointer to view cells manager. 252 245 */ 253 246 void SetViewCellsManager(ViewCellsManager *vcm); 247 248 /** Helper function revalidating the view cell leaf list after merge. 249 */ 250 void RepairVcLeafLists(); 251 252 /** Collapses the tree with respect to the view cell partition. 253 @returns node of type leaf if the node could be collapsed, this node otherwise 254 */ 255 BspNode *CollapseTree(BspNode *node); 256 254 257 255 258 protected: -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r478 r479 2022 2022 leaf->SetViewCell(vc); 2023 2023 2024 vc->SetArea(GetBBox(leaf).GetVolume()); 2024 vc->SetVolume(GetBBox(leaf).GetVolume()); 2025 vc->SetArea(GetBBox(leaf).SurfaceArea()); 2026 2025 2027 vc->mLeaves.push_back(leaf); 2026 2028 … … 2036 2038 } 2037 2039 } 2038 2039 2040 void VspKdTree::EvaluateViewCellsStats(ViewCellsStatistics &vcStat) const2041 {2042 vcStat.Reset();2043 2044 stack<VspKdNode *> nodeStack;2045 nodeStack.push(mRoot);2046 2047 ViewCell::NewMail();2048 2049 while (!nodeStack.empty())2050 {2051 VspKdNode *node = nodeStack.top();2052 nodeStack.pop();2053 2054 if (node->IsLeaf())2055 {2056 ++ vcStat.leaves;2057 2058 VspKdViewCell *viewCell = dynamic_cast<VspKdLeaf *>(node)->mViewCell;2059 2060 if (!viewCell->Mailed())2061 {2062 viewCell->Mail();2063 2064 ++ vcStat.viewCells;2065 const int pvsSize = viewCell->GetPvs().GetSize();2066 2067 vcStat.pvs += pvsSize;2068 2069 if (pvsSize < 1)2070 ++ vcStat.emptyPvs;2071 2072 if (pvsSize > vcStat.maxPvs)2073 vcStat.maxPvs = pvsSize;2074 2075 if (pvsSize < vcStat.minPvs)2076 vcStat.minPvs = pvsSize;2077 2078 if ((int)viewCell->mLeaves.size() > vcStat.maxLeaves)2079 vcStat.maxLeaves = (int)viewCell->mLeaves.size();2080 }2081 }2082 else2083 {2084 VspKdInterior *interior = dynamic_cast<VspKdInterior *>(node);2085 2086 nodeStack.push(interior->GetFront());2087 nodeStack.push(interior->GetBack());2088 }2089 }2090 }2091 2092 2040 2093 2041 … … 2106 2054 2107 2055 // set new size of view cell 2108 vc->Set Area(fVc->GetVolume() + bVc->GetVolume());2056 vc->SetVolume(fVc->GetVolume() + bVc->GetVolume()); 2109 2057 2110 2058 vector<VspKdLeaf *> fLeaves = fVc->mLeaves; … … 2222 2170 } 2223 2171 2224 // collapse tree according to view cell partition2172 // collapse siblings belonging to the same view cell 2225 2173 CollapseTree(mRoot); 2226 2227 2174 // revalidate leaves 2228 ValidateViewCellLeaves();2175 RepairVcLeafLists(); 2229 2176 2230 2177 //Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl; … … 2235 2182 2236 2183 2237 void VspKdTree:: ValidateViewCellLeaves()2184 void VspKdTree::RepairVcLeafLists() 2238 2185 { 2239 2186 // list not valid anymore => clear … … 2271 2218 } 2272 2219 } 2220 2273 2221 2274 2222 VspKdNode *VspKdTree::CollapseTree(VspKdNode *node) -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
r474 r479 597 597 void CollectViewCells(ViewCellContainer &viewCells) const; 598 598 599 /** Traverses tree and counts all view cells as well as their PVS size.600 */601 void EvaluateViewCellsStats(ViewCellsStatistics &stat) const;602 603 599 /** Refines view cells in a post processing step. 604 600 */ … … 715 711 /** Helper function revalidating the view cell leaf list after merge. 716 712 */ 717 void ValidateViewCellLeaves();713 void RepairVcLeafLists(); 718 714 719 715 protected:
Note: See TracChangeset
for help on using the changeset viewer.