Changeset 409 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 11/14/05 15:59:20 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r406 r409 132 132 133 133 Termination { 134 # autopartition134 # parameters used for autopartition 135 135 maxRays 200 136 136 maxPolygons -1 137 137 maxDepth 40 138 138 minPvs 35 139 minArea 0.005 139 minArea 0.01 140 maxRayContribution 0.05 141 #maxAccRayLength 100 140 142 141 143 # axis aligned splits … … 166 168 vcOverhead 0.05 167 169 } 170 171 VssTree { 172 epsilon 1e-6 173 174 maxDepth 40 175 minPvs 1 176 minRays 50 177 minSize 0.00001 178 maxCostRatio 0.95 179 maxRayContribution 0.05 180 181 maxTotalMemory 400 182 maxStaticMemory 20 183 184 splitType regular 185 # splitType heuristics 186 187 numberOfEndPointDomains 10000 188 ct_div_ci 0.0 189 randomize false 190 191 refDirBoxMaxSize 0.1 192 } 193 194 VspKdTree { 195 epsilon 1e-6 196 197 maxDepth 40 198 minPvs 1 199 minRays 50 200 minSize 0.00001 201 maxCostRatio 0.95 202 maxRayContribution 0.05 203 204 maxTotalMemory 400 205 maxStaticMemory 20 206 207 splitType regular 208 # splitType heuristics 209 210 numberOfEndPointDomains 10000 211 ct_div_ci 0.0 212 randomize false 213 214 refDirBoxMaxSize 0.1 215 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r408 r409 1210 1210 "0.05"); 1211 1211 1212 RegisterOption("Simulation.moveSpeed", 1213 optFloat, 1214 "-simulation_moveSpeed", 1215 "1.0"); 1216 1212 1217 RegisterOption("BspTree.Construction.input", 1213 1218 optString, … … 1244 1249 "-bsp_term_min_area=", 1245 1250 "0.001"); 1251 1252 RegisterOption("BspTree.Termination.maxRayContribution", 1253 optFloat, 1254 "-bsp_term_ray_contribution=", 1255 "0.005"); 1256 1257 RegisterOption("BspTree.Termination.maxAccRayLenght", 1258 optFloat, 1259 "-bsp_term_max_acc_ray_length=", 1260 "50"); 1246 1261 1247 1262 RegisterOption("BspTree.Termination.maxRays", … … 1304 1319 "-view_cells_max_viewcells=", 1305 1320 "0"); 1306 1307 1321 1308 1322 RegisterOption("BspTree.Visualization.samples", … … 1347 1361 RegisterOption("VspKdTree.accessTimeThreshold", optInt, "accesstime=", "1000"); 1348 1362 RegisterOption("VspKdTree.minCollapseDepth", optInt, "colldepth=", "4"); 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1363 1359 1364 RegisterOption("VssTree.maxDepth", optInt, "kd_depth=", "12"); -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r387 r409 6 6 #include "ViewCell.h" 7 7 #include "Environment.h" 8 #include "RenderSimulator.h" 8 9 9 10 Preprocessor::Preprocessor(): 10 11 mKdTree(NULL), 11 mBspTree(NULL) 12 mBspTree(NULL), 13 mRenderSimulator(NULL) 12 14 { 13 15 } … … 20 22 DEL_PTR(mBspTree); 21 23 DEL_PTR(mKdTree); 24 25 DEL_PTR(mRenderSimulator); 22 26 } 23 27 … … 52 56 53 57 if (strcmp(viewCellsStr, "bspTree") == 0) 58 { 54 59 ViewCell::sHierarchy = ViewCell::BSP; 60 } 55 61 else if (strcmp(viewCellsStr, "kdTree") == 0) 62 { 56 63 ViewCell::sHierarchy = ViewCell::KD; 64 } 57 65 else if (strcmp(viewCellsStr, "sceneDependent") == 0) 58 66 { … … 68 76 } 69 77 78 RenderSimulator *Preprocessor::GetRenderSimulator() 79 { 80 if (mRenderSimulator) 81 return mRenderSimulator; 82 83 float objRenderCost = 0, vcOverhead = 0, moveSpeed = 0; 84 85 environment->GetFloatValue("Simulation.objRenderCost",objRenderCost); 86 environment->GetFloatValue("Simulation.vcOverhead", vcOverhead); 87 environment->GetFloatValue("Simulation.moveSpeed", moveSpeed); 88 89 if (ViewCell::sHierarchy = ViewCell::BSP) 90 mRenderSimulator = new BspViewCellRenderSimulator(objRenderCost, vcOverhead, moveSpeed, mBspTree); 91 else // KD view cells 92 mRenderSimulator = new KdViewCellRenderSimulator(objRenderCost, vcOverhead, moveSpeed, mKdTree); 93 94 return mRenderSimulator; 95 } 96 70 97 void Preprocessor::DeleteViewCells() 71 98 { 72 for (int i = 0; i < mViewCells.size(); ++ i) 73 delete mViewCells[i]->GetMesh(); 74 99 for (int i = 0; i < (int)mViewCells.size(); ++ i) 100 { 101 Mesh *mesh = mViewCells[i]->GetMesh(); 102 DEL_PTR(mesh); 103 } 75 104 CLEAR_CONTAINER(mViewCells); 76 105 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
r392 r409 9 9 #include "ViewCellBsp.h" 10 10 #include "ViewCell.h" 11 //#include "SceneGraph.h"12 11 12 class RenderSimulator; 13 13 class SceneGraph; 14 14 … … 93 93 void DeleteViewCells(); 94 94 95 RenderSimulator *GetRenderSimulator(); 96 95 97 /** Parses the view cell options 96 98 */ … … 115 117 /// the view cell corresponding to unbounded space 116 118 BspViewCell mUnbounded; 119 120 RenderSimulator *mRenderSimulator; 117 121 }; 118 122 -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
r407 r409 7 7 {} 8 8 9 RenderSimulator::RenderSimulator(float objRenderCost, float vcOverhead ):10 mObjRenderCost(objRenderCost), mVcOverhead(vcOverhead) 9 RenderSimulator::RenderSimulator(float objRenderCost, float vcOverhead, float moveSpeed): 10 mObjRenderCost(objRenderCost), mVcOverhead(vcOverhead), mMoveSpeed(moveSpeed) 11 11 { 12 12 } … … 16 16 *****************************************************/ 17 17 18 Bsp TreeRenderSimulator::BspTreeRenderSimulator(float objRenderCost,18 BspViewCellRenderSimulator::BspViewCellRenderSimulator(float objRenderCost, 19 19 float vcOverhead, 20 float moveSpeed, 20 21 BspTree *bspTree): 21 RenderSimulator(objRenderCost, vcOverhead ), mBspTree(bspTree)22 RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree) 22 23 { 23 24 } 24 25 25 Real Bsp TreeRenderSimulator::SimulateRendering()26 Real BspViewCellRenderSimulator::SimulateRendering() 26 27 { 27 28 Real renderTime = 0; 28 29 29 // total area ofview cells30 float totalArea = 0;//= mKdTree->GetBox().SurfaceArea();30 // overhead for loading the PVS of the view cells 31 float loadPvsOverhead = 0; 31 32 33 // probability that view point lies in a view cell 34 float pInVcTotal = 0; 35 36 // total probability that a view cell border is crossed 37 float pCrossVcTotal = 0; 38 39 // collect all view cells 32 40 ViewCellContainer viewCells; 33 34 41 mBspTree->CollectViewCells(viewCells); 35 42 … … 37 44 38 45 // surface area substitute for probability 39 PolygonContainer cell;46 PolygonContainer geom; 40 47 41 48 for (it = viewCells.begin(); it != it_end; ++ it) 42 49 { 43 mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), cell); 44 CLEAR_CONTAINER(cell); 45 float area = Polygon3::GetArea(cell); 50 mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom); 51 CLEAR_CONTAINER(geom); 52 53 const float area = Polygon3::GetArea(geom); 54 // area substitute for view point probability 55 float pInVc = area; 56 57 // compute render time of PVS times probability that view point is in view cell 58 renderTime += pInVc * RenderPvs(*(*it), mObjRenderCost); 46 59 47 renderTime += area * (RenderPvs(*(*it), mObjRenderCost) + mVcOverhead); 48 totalArea += area; 60 // probability that a view cell border is crossed 61 float pCrossVc = area; 62 63 loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed; 64 65 pInVcTotal += pInVc; 66 pCrossVcTotal += pCrossVc; 49 67 } 50 68 51 renderTime /= totalArea; 69 70 renderTime /= pInVcTotal; 71 loadPvsOverhead /= pCrossVcTotal; 52 72 53 73 //Debug << "render time without overhead: " << renderTime * 1e-3 << endl; 54 //renderTime += (float)viewCells.size() * vcOverhead; 55 56 return renderTime; 74 75 return renderTime + loadPvsOverhead; 57 76 } 58 77 59 Real Bsp TreeRenderSimulator::RenderPvs(ViewCell &viewCell,78 Real BspViewCellRenderSimulator::RenderPvs(ViewCell &viewCell, 60 79 float objRenderTime) const 61 80 { … … 67 86 *******************************************************/ 68 87 69 KdTreeRenderSimulator::KdTreeRenderSimulator(float objRenderCost, 70 float vcOverhead, 88 KdViewCellRenderSimulator::KdViewCellRenderSimulator(float objRenderCost, 89 float vcOverhead, 90 float moveSpeed, 71 91 KdTree *kdTree): 72 RenderSimulator(objRenderCost, vcOverhead ), mKdTree(kdTree)92 RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree) 73 93 { 74 94 } 75 95 76 Real Kd TreeRenderSimulator::SimulateRendering()96 Real KdViewCellRenderSimulator::SimulateRendering() 77 97 { 78 98 //mKdTree->CollectLeavesPvs(); … … 81 101 Real renderTime = 0; 82 102 // overhead for loading a view cell 83 float load Overhead = 0;103 float loadPvsOverhead = 0; 84 104 85 105 // probability that view point lies in a view cell … … 112 132 113 133 renderTime += pInVc * RenderPvs(*it, mObjRenderCost); 114 load Overhead += pCrossVc * mVcOverhead;134 loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed; 115 135 116 136 pInVcTotal += pInVc; … … 119 139 120 140 renderTime /= pInVcTotal; 121 load Overhead /= pCrossVcTotal;141 loadPvsOverhead /= pCrossVcTotal; 122 142 123 return renderTime + load Overhead;143 return renderTime + loadPvsOverhead; 124 144 } 125 145 126 Real Kd TreeRenderSimulator::RenderPvs(KdLeaf *leaf,146 Real KdViewCellRenderSimulator::RenderPvs(KdLeaf *leaf, 127 147 float objRenderTime) const 128 148 { -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h
r407 r409 16 16 public: 17 17 RenderSimulator(); 18 RenderSimulator(float objRendercost, float vcOverhead );18 RenderSimulator(float objRendercost, float vcOverhead, float moveSpeed); 19 19 virtual Real SimulateRendering() = 0; 20 20 21 protected: 22 // render time for single object of the PVS 21 /// render time for single object of the PVS 23 22 float mObjRenderCost; 24 // const overhead for crossing a view cell border23 /// const overhead for crossing a view cell border 25 24 float mVcOverhead; 25 /// move speed of player 26 float mMoveSpeed; 26 27 }; 27 28 28 class Bsp TreeRenderSimulator: public RenderSimulator29 class BspViewCellRenderSimulator: public RenderSimulator 29 30 { 30 31 public: 31 Bsp TreeRenderSimulator(float objRenderCost, float vcOverhead, BspTree *bspTree);32 BspViewCellRenderSimulator(float objRenderCost, float vcOverhead, float moveSpeed, BspTree *bspTree); 32 33 33 34 Real SimulateRendering(); … … 43 44 }; 44 45 45 class Kd TreeRenderSimulator: public RenderSimulator46 class KdViewCellRenderSimulator: public RenderSimulator 46 47 { 47 48 public: 48 Kd TreeRenderSimulator(float objRenderCost, float vcOverhead, KdTree *kdTree);49 KdViewCellRenderSimulator(float objRenderCost, float vcOverhead, float moveSpeed, KdTree *kdTree); 49 50 Real SimulateRendering(); 50 51 -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r407 r409 17 17 environment->GetIntValue("ViewCells.PostProcessing.samples", mPostProcessSamples); 18 18 environment->GetIntValue("BspTree.Visualization.samples", mVisualizationSamples); 19 environment->GetFloatValue("Simulation.objRenderCost", mObjRenderCost); 20 environment->GetFloatValue("Simulation.vcOverhead", mVcOverhead); 21 19 22 20 mKdPvsDepth = 100; 23 21 mStats.open("stats.log"); 24 25 22 } 26 23 … … 543 540 //-- render simulation 544 541 cout << "\nevaluating bsp view cells render time before merge ... "; 545 Real rt = BspTreeRenderSimulator(mObjRenderCost, mVcOverhead, mBspTree).SimulateRendering();542 Real rt = GetRenderSimulator()->SimulateRendering(); 546 543 547 544 cout << "avg render time: " << rt * 1e-3 << endl; … … 589 586 cout << "\nevaluating render time after merge ... "; 590 587 591 rt = BspTreeRenderSimulator(mObjRenderCost, mVcOverhead, mBspTree).SimulateRendering();588 rt = GetRenderSimulator()->SimulateRendering(); 592 589 593 590 cout << "render time: " << rt * 1e-3 << endl; … … 655 652 { 656 653 cout << "\nevaluating kd view cells render time ... "; 657 Real rt = KdTreeRenderSimulator(mObjRenderCost, mVcOverhead, mKdTree).SimulateRendering();654 Real rt = GetRenderSimulator()->SimulateRendering(); 658 655 659 656 cout << "avg render time: " << rt * 1e-3 << endl; -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
r406 r409 98 98 */ 99 99 int PostprocessViewCells(const RayContainer &rays); 100 101 // rendering costs for a single object102 float mObjRenderCost;103 // rendering overhead when crossing a view cell border104 float mVcOverhead;105 100 }; 106 101 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r407 r409 14 14 #include "Plane3.h" 15 15 16 int BspTree::sMaxPolyCandidates = 10; 17 int BspTree::sMaxRayCandidates = 10; 18 int BspTree::sSplitPlaneStrategy = BALANCED_POLYS; 19 int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS; 20 21 16 22 int BspTree::sTermMaxPolygons = 10; 17 23 int BspTree::sTermMinPvs = 20; 18 24 int BspTree::sTermMaxDepth = 20; 19 25 float BspTree::sTermMinArea = 0.001f; 20 int BspTree::sMaxPolyCandidates = 10;21 int BspTree::sMaxRayCandidates = 10;22 int BspTree::sSplitPlaneStrategy = BALANCED_POLYS;23 int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS;24 26 int BspTree::sTermMaxPolysForAxisAligned = 50; 25 27 int BspTree::sTermMaxObjectsForAxisAligned = 50; 26 28 int BspTree::sTermMaxRaysForAxisAligned = -1; 27 29 int BspTree::sTermMaxRays = -1; 30 float BspTree::sTermMaxRayContribution = 0.05f; 31 float BspTree::sTermMaxAccRayLength = 50; 32 33 28 34 int BspTree::sMinPvsDif = 10; 29 35 int BspTree::sMinPvs = 10; … … 704 710 (data.mPvs <= sTermMinPvs) || 705 711 (data.mArea <= sTermMinArea) || 706 (data.mDepth >= sTermMaxDepth)); 712 (data.mDepth >= sTermMaxDepth) || 713 (((float)data.mPvs / (float)data.mRays->size()) < sTermMaxRayContribution)); 707 714 } 708 715 … … 863 870 coincident); 864 871 865 // split geometry 866 tData.mGeometry->SplitGeometry(*frontData.mGeometry, *backData.mGeometry, 867 *this, interior->mPlane); 868 869 // compute area 870 frontData.mArea = frontData.mGeometry->GetArea(); 871 backData.mArea = backData.mGeometry->GetArea(); 872 873 // compute pvs 872 // compute pvs 874 873 frontData.mPvs = ComputePvsSize(*frontData.mRays); 875 874 backData.mPvs = ComputePvsSize(*backData.mRays); 876 875 876 // split geometry and compute area 877 if (1) 878 { 879 tData.mGeometry->SplitGeometry(*frontData.mGeometry, 880 *backData.mGeometry, 881 *this, 882 interior->mPlane); 883 884 885 frontData.mArea = frontData.mGeometry->GetArea(); 886 backData.mArea = backData.mGeometry->GetArea(); 887 } 888 889 // compute accumulated ray length 890 //frontData.mAccRayLength = AccumulatedRayLength(*frontData.mRays); 891 //backData.mAccRayLength = AccumulatedRayLength(*backData.mRays); 877 892 878 893 //-- create front and back leaf … … 1502 1517 (pOverall * (float)pvs * 2); 1503 1518 1504 // give penalty for unbalanced cell1505 if (((pFront * 0.2 + 0.00001) > pBack) || (pFront < (pBack * 0.2 + 0.00001)))1519 // give penalty to unbalanced split 1520 if (((pFront * 0.2 + Limits::Small) > pBack) || (pFront < (pBack * 0.2 + Limits::Small))) 1506 1521 val += 0.5; 1507 1522 } … … 1633 1648 environment->GetIntValue("BspTree.Termination.maxPolygons", sTermMaxPolygons); 1634 1649 environment->GetIntValue("BspTree.Termination.maxRays", sTermMaxRays); 1635 environment->GetFloatValue("BspTree.Termination.minArea", sTermMinArea); 1650 environment->GetFloatValue("BspTree.Termination.minArea", sTermMinArea); 1651 environment->GetFloatValue("BspTree.Termination.maxRayContribution", sTermMaxRayContribution); 1652 environment->GetFloatValue("BspTree.Termination.maxAccRayLenght", sTermMaxAccRayLength); 1636 1653 1637 1654 //-- termination criteria for axis aligned split … … 1743 1760 mStat.minDepth = data.mDepth; 1744 1761 1745 // store minimal and maximal pvs 1746 /*if (data.mPvs > mStat.pvs)mStat.pvs = data.mPvs; 1747 if (data.mPvs < mStat.pvs) mStat.pvs = data.mPvs;*/ 1748 1749 // accumulate depth to compute average 1762 // accumulate depth to compute average depth 1750 1763 mStat.accumDepth += data.mDepth; 1751 1764 … … 1757 1770 << "#polygons: " << (int)data.mPolygons->size() << " (max: " << sTermMaxPolygons << "), " 1758 1771 << "#rays: " << (int)data.mRays->size() << " (max: " << sTermMaxRays << "), " 1759 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << endl; 1772 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "=, " 1773 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 1760 1774 //#endif 1761 1775 } … … 2028 2042 { 2029 2043 return mStat; 2044 } 2045 2046 float BspTree::AccumulatedRayLength(BoundedRayContainer &rays) const 2047 { 2048 float len = 0; 2049 2050 BoundedRayContainer::const_iterator it, it_end = rays.end(); 2051 2052 for (it = rays.begin(); it != it_end; ++ it) 2053 { 2054 len += SqrDistance((*it)->mRay->Extrap((*it)->mMinT), 2055 (*it)->mRay->Extrap((*it)->mMaxT)); 2056 } 2057 2058 return len; 2030 2059 } 2031 2060 … … 2077 2106 2078 2107 DEL_PTR(bRay); 2079 2080 ++ splits;2081 2108 } 2082 2109 break; … … 2089 2116 backRays.push_back(new BoundedRay(ray, bRay->mMinT, newT)); 2090 2117 frontRays.push_back(new BoundedRay(ray, newT, bRay->mMaxT)); 2091 2092 2118 DEL_PTR(bRay); 2093 2119 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r407 r409 734 734 bool TerminationCriteriaMet(const BspTraversalData &data) const; 735 735 736 float AccumulatedRayLength(BoundedRayContainer &rays) const; 737 736 738 /// Pointer to the root of the tree 737 739 BspNode *mRoot; … … 794 796 static int sTermMaxObjectsForAxisAligned; 795 797 798 static float sTermMaxRayContribution; 799 static float sTermMaxAccRayLength; 800 796 801 static bool sStoreLeavesWithRays; 797 802 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r408 r409 34 34 VspKdTreeLeaf::mailID = 0; 35 35 36 inline void 37 AddObject2Pvs(Intersectable *object, 38 const int side, 39 int &pvsBack, 40 int &pvsFront) 41 { 42 36 inline void AddObject2Pvs(Intersectable *object, 37 const int side, 38 int &pvsBack, 39 int &pvsFront) 40 { 43 41 if (!object) 44 42 return; 45 43 46 if (side <= 0) { 47 if (!object->Mailed() && !object->Mailed(2)) { 48 pvsBack++; 44 if (side <= 0) 45 { 46 if (!object->Mailed() && !object->Mailed(2)) 47 { 48 ++ pvsBack; 49 49 50 if (object->Mailed(1)) 50 51 object->Mail(2); … … 54 55 } 55 56 56 if (side >= 0) { 57 if (!object->Mailed(1) && !object->Mailed(2)) { 58 pvsFront++; 57 if (side >= 0) 58 { 59 if (!object->Mailed(1) && !object->Mailed(2)) 60 { 61 ++ pvsFront; 59 62 if (object->Mailed()) 60 63 object->Mail(2); … … 69 72 VspKdTree::VspKdTree() 70 73 { 71 74 environment->GetIntValue("VspKdTree.maxDepth", termMaxDepth); 72 75 environment->GetIntValue("VspKdTree.minPvs", termMinPvs); 73 76 environment->GetIntValue("VspKdTree.minRays", termMinRays); 74 77 environment->GetFloatValue("VspKdTree.maxRayContribution", termMaxRayContribution); 75 environment->GetFloatValue("VspKdTree.maxCostRatio", termMaxCostRatio); 76 77 environment->GetFloatValue("VspKdTree.minSize", termMinSize); 78 termMinSize = sqr(termMinSize); 79 80 environment->GetFloatValue("VspKdTree.refDirBoxMaxSize", refDirBoxMaxSize); 81 refDirBoxMaxSize = sqr(refDirBoxMaxSize); 82 83 environment->GetFloatValue("VspKdTree.epsilon", epsilon); 84 environment->GetFloatValue("VspKdTree.ct_div_ci", ct_div_ci); 85 86 environment->GetFloatValue("VspKdTree.maxTotalMemory", maxTotalMemory); 87 environment->GetFloatValue("VspKdTree.maxStaticMemory", maxStaticMemory); 88 89 90 91 92 float refDirAngle; 93 environment->GetFloatValue("VspKdTree.refDirAngle", refDirAngle); 94 95 environment->GetIntValue("VspKdTree.accessTimeThreshold", accessTimeThreshold); 96 //= 1000; 97 environment->GetIntValue("VspKdTree.minCollapseDepth", minCollapseDepth); 98 // int minCollapseDepth = 4; 99 100 // pRefDirThresh = cos(0.5*M_PI - M_PI*refDirAngle/180.0); 101 // cosRefDir = cos(M_PI*refDirAngle/180.0); 102 // sinRefDir = sin(M_PI*refDirAngle/180.0); 103 104 105 // split type 78 environment->GetFloatValue("VspKdTree.maxCostRatio", termMaxCostRatio); 79 80 environment->GetFloatValue("VspKdTree.minSize", termMinSize); 81 termMinSize = sqr(termMinSize); 82 83 environment->GetFloatValue("VspKdTree.refDirBoxMaxSize", refDirBoxMaxSize); 84 refDirBoxMaxSize = sqr(refDirBoxMaxSize); 85 86 environment->GetFloatValue("VspKdTree.epsilon", epsilon); 87 environment->GetFloatValue("VspKdTree.ct_div_ci", ct_div_ci); 88 89 environment->GetFloatValue("VspKdTree.maxTotalMemory", maxTotalMemory); 90 environment->GetFloatValue("VspKdTree.maxStaticMemory", maxStaticMemory); 91 92 93 float refDirAngle; 94 environment->GetFloatValue("VspKdTree.refDirAngle", refDirAngle); 95 96 environment->GetIntValue("VspKdTree.accessTimeThreshold", accessTimeThreshold); 97 //= 1000; 98 environment->GetIntValue("VspKdTree.minCollapseDepth", minCollapseDepth); 99 100 101 // split type 106 102 char sname[128]; 107 103 environment->GetStringValue("VspKdTree.splitType", sname); 108 string name(sname); 109 110 if (name.compare("regular") == 0) 111 splitType = ESplitRegular; 112 else 113 if (name.compare("heuristic") == 0) 114 splitType = ESplitHeuristic; 115 else { 116 cerr<<"Invalid VspKdTree split type "<<name<<endl; 104 string name(sname); 105 106 if (name.compare("regular") == 0) 107 splitType = ESplitRegular; 108 else 109 { 110 if (name.compare("heuristic") == 0) 111 splitType = ESplitHeuristic; 112 else 113 { 114 cerr << "Invalid VspKdTree split type " << name << endl; 117 115 exit(1); 118 116 } 119 120 environment->GetBoolValue("VspKdTree.randomize", randomize); 121 122 root = NULL; 123 124 splitCandidates = new vector<SortableEntry>; 117 } 118 119 environment->GetBoolValue("VspKdTree.randomize", randomize); 120 121 root = NULL; 122 123 splitCandidates = new vector<SortableEntry>; 125 124 } 126 125 … … 128 127 VspKdTree::~VspKdTree() 129 128 { 130 131 129 if (root) 130 delete root; 132 131 } 133 132 … … 204 203 VspKdTreeLeaf::UpdatePvsSize() 205 204 { 206 if (!mValidPvs) { 205 if (!mValidPvs) 206 { 207 207 Intersectable::NewMail(); 208 208 int pvsSize = 0; 209 for(VspKdTreeNode::RayInfoContainer::iterator ri = rays.begin(); 210 ri != rays.end(); 211 ri++) 212 if ((*ri).mRay->IsActive()) { 209 for(VspKdTreeNode::RayInfoContainer::iterator ri = rays.begin(); 210 ri != rays.end(); ++ ri) 211 { 212 if ((*ri).mRay->IsActive()) 213 { 213 214 Intersectable *object; 214 215 #if BIDIRECTIONAL_RAY 215 216 object = (*ri).mRay->mOriginObject; 216 if (object && !object->Mailed()) { 217 pvsSize++; 217 218 if (object && !object->Mailed()) 219 { 220 ++ pvsSize; 218 221 object->Mail(); 219 222 } 220 223 #endif 221 224 object = (*ri).mRay->mTerminationObject; 222 if (object && !object->Mailed()) { 223 pvsSize++; 225 if (object && !object->Mailed()) 226 { 227 ++ pvsSize; 224 228 object->Mail(); 225 229 } 226 230 } 231 } 232 227 233 mPvsSize = pvsSize; 228 234 mValidPvs = true; … … 232 238 233 239 void 234 VspKdTree::Construct( 235 VssRayContainer &rays, 236 AxisAlignedBox3 *forcedBoundingBox 237 ) 238 { 239 stat.Start(); 240 VspKdTree::Construct(VssRayContainer &rays, 241 AxisAlignedBox3 *forcedBoundingBox) 242 { 243 stat.Start(); 240 244 241 245 maxMemory = maxStaticMemory; 242 246 243 if (root) 244 delete root; 245 246 root = new VspKdTreeLeaf(NULL, rays.size()); 247 // first construct a leaf that will get subdivide 248 VspKdTreeLeaf *leaf = (VspKdTreeLeaf *) root; 249 250 stat.nodes = 1; 251 252 bbox.Initialize(); 253 dirBBox.Initialize(); 254 255 for(VssRayContainer::const_iterator ri = rays.begin(); 256 ri != rays.end(); 257 ri++) { 258 leaf->AddRay(VspKdTreeNode::RayInfo(*ri)); 259 260 bbox.Include((*ri)->GetOrigin()); 261 bbox.Include((*ri)->GetTermination()); 262 263 264 dirBBox.Include(Vector3( 265 (*ri)->GetDirParametrization(0), 266 (*ri)->GetDirParametrization(1), 267 0 268 ) 269 ); 270 } 271 272 273 if ( forcedBoundingBox ) 247 if (root) 248 delete root; 249 250 root = new VspKdTreeLeaf(NULL, rays.size()); 251 252 // first construct a leaf that will get subdivide 253 VspKdTreeLeaf *leaf = (VspKdTreeLeaf *) root; 254 255 256 stat.nodes = 1; 257 258 bbox.Initialize(); 259 dirBBox.Initialize(); 260 261 262 for (VssRayContainer::const_iterator ri = rays.begin(); ri != rays.end(); ++ ri) 263 { 264 leaf->AddRay(VspKdTreeNode::RayInfo(*ri)); 265 266 bbox.Include((*ri)->GetOrigin()); 267 bbox.Include((*ri)->GetTermination()); 268 269 dirBBox.Include(Vector3((*ri)->GetDirParametrization(0), (*ri)->GetDirParametrization(1), 0)); 270 } 271 272 if (forcedBoundingBox) 274 273 bbox = *forcedBoundingBox; 275 274 … … 277 276 cout<<"Dirr Bbox = "<<dirBBox<<endl; 278 277 279 278 stat.rays = leaf->rays.size(); 280 279 leaf->UpdatePvsSize(); 281 stat.initialPvsSize = leaf->GetPvsSize(); 282 // Subdivide(); 283 root = Subdivide(TraversalData(leaf, bbox, 0)); 284 285 if (splitCandidates) { 286 // force realease of this vector 287 delete splitCandidates; 288 splitCandidates = new vector<SortableEntry>; 289 } 290 291 stat.Stop(); 280 281 stat.initialPvsSize = leaf->GetPvsSize(); 282 283 // Subdivide(); 284 root = Subdivide(TraversalData(leaf, bbox, 0)); 285 286 if (splitCandidates) 287 { 288 // force realease of this vector 289 delete splitCandidates; 290 splitCandidates = new vector<SortableEntry>; 291 } 292 293 stat.Stop(); 292 294 293 295 stat.Print(cout); 294 cout<<"#Total memory="<<GetMemUsage()<<endl; 295 296 } 297 298 299 300 VspKdTreeNode * 301 VspKdTree::Subdivide(const TraversalData &tdata) 302 { 303 VspKdTreeNode *result = NULL; 304 305 priority_queue<TraversalData> tStack; 306 // stack<TraversalData> tStack; 307 308 tStack.push(tdata); 309 310 AxisAlignedBox3 backBox; 311 AxisAlignedBox3 frontBox; 312 296 cout<<"#Total memory=" << GetMemUsage() << endl; 297 } 298 299 300 301 VspKdTreeNode *VspKdTree::Subdivide(const TraversalData &tdata) 302 { 303 VspKdTreeNode *result = NULL; 304 305 priority_queue<TraversalData> tStack; 306 // stack<TraversalData> tStack; 307 308 tStack.push(tdata); 309 310 AxisAlignedBox3 backBox; 311 AxisAlignedBox3 frontBox; 313 312 314 313 int lastMem = 0; 315 while (!tStack.empty()) { 316 314 while (!tStack.empty()) 315 { 317 316 float mem = GetMemUsage(); 318 317 319 if ( lastMem/10 != ((int)mem)/10) { 320 cout<<mem<<" MB"<<endl; 318 if ( lastMem/10 != ((int)mem)/10) 319 { 320 cout << mem << " MB" << endl; 321 321 } 322 322 lastMem = (int)mem; 323 323 324 if ( mem > maxMemory ) { 325 // count statistics on unprocessed leafs 326 while (!tStack.empty()) { 324 if ( mem > maxMemory ) 325 { 326 // count statistics on unprocessed leafs 327 while (!tStack.empty()) 328 { 327 329 EvaluateLeafStats(tStack.top()); 328 330 tStack.pop(); 329 330 331 331 } 332 break; 333 } 332 334 333 334 335 TraversalData data = tStack.top(); 336 tStack.pop(); 335 337 336 VspKdTreeNode *node = SubdivideNode((VspKdTreeLeaf *) data.node, 337 data.bbox, 338 backBox, 339 frontBox 340 ); 341 if (result == NULL) 342 result = node; 338 339 VspKdTreeNode *node = SubdivideNode((VspKdTreeLeaf *) data.node, 340 data.bbox, backBox, frontBox); 341 if (result == NULL) 342 result = node; 343 343 344 if (!node->IsLeaf()) { 345 346 VspKdTreeInterior *interior = (VspKdTreeInterior *) node; 347 // push the children on the stack 348 tStack.push(TraversalData(interior->back, backBox, data.depth+1)); 349 tStack.push(TraversalData(interior->front, frontBox, data.depth+1)); 350 351 } else { 352 EvaluateLeafStats(data); 353 } 354 } 355 356 return result; 344 if (!node->IsLeaf()) 345 { 346 VspKdTreeInterior *interior = (VspKdTreeInterior *) node; 347 348 // push the children on the stack 349 tStack.push(TraversalData(interior->back, backBox, data.depth+1)); 350 tStack.push(TraversalData(interior->front, frontBox, data.depth+1)); 351 } 352 else 353 { 354 EvaluateLeafStats(data); 355 } 356 } 357 358 return result; 357 359 } 358 360 … … 360 362 // returns selected plane for subdivision 361 363 int 362 VspKdTree::SelectPlane( 363 VspKdTreeLeaf *leaf, 364 const AxisAlignedBox3 &box, 365 float &position, 366 int &raysBack, 367 int &raysFront, 368 int &pvsBack, 369 int &pvsFront 370 ) 364 VspKdTree::SelectPlane(VspKdTreeLeaf *leaf, 365 const AxisAlignedBox3 &box, 366 float &position, 367 int &raysBack, 368 int &raysFront, 369 int &pvsBack, 370 int &pvsFront) 371 371 { 372 372 … … 776 776 { 777 777 778 if ( (leaf->GetPvsSize() < termMinPvs) || 779 (leaf->rays.size() < termMinRays) || 780 // (leaf->GetAvgRayContribution() > termMaxRayContribution ) || 781 (leaf->depth >= termMaxDepth) || 782 SqrMagnitude(box.Size()) <= termMinSize ) { 778 if ( (leaf->GetPvsSize() < termMinPvs) || (leaf->rays.size() < termMinRays) || 779 // (leaf->GetAvgRayContribution() > termMaxRayContribution ) || 780 (leaf->depth >= termMaxDepth) || SqrMagnitude(box.Size()) <= termMinSize ) 781 { 783 782 784 783 #if 0 -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r387 r409 25 25 BspTree::ParseEnvironment(); 26 26 27 char buff[128]; 28 29 environment->GetStringValue("Preprocessor.type", buff); 30 31 string preprocessorType(buff); 27 char buff[128]; 28 29 environment->GetStringValue("Preprocessor.type", buff); 30 string preprocessorType(buff); 32 31 33 32 Preprocessor *p; … … 83 82 p->Export("vc_bsptree.x3d", false, false, true); 84 83 p->BspTreeStatistics(Debug); 85 86 #if 087 //-- export the complementary view cells88 // i.e., the view cells not associated with leafs in the tree.89 Exporter *exporter = Exporter::GetExporter("viewcells_compl.x3d");90 91 ViewCellContainer::iterator vc_compl_it;92 ViewCellContainer vc_compl(p->mViewCells.size() + X3dExporter::foundViewCells.size());93 94 sort(p->mViewCells.begin(), p->mViewCells.end());95 96 vc_compl_it = set_difference(p->mViewCells.begin(), p->mViewCells.end(),97 X3dExporter::foundViewCells.begin(), X3dExporter::foundViewCells.end(), vc_compl.begin());98 99 vc_compl.erase(vc_compl_it, vc_compl.end());100 101 102 if (exporter)103 {104 Debug << "Exporting complementary view cells" << endl;105 exporter->ExportViewCells(vc_compl); // export view cells106 delete exporter;107 }108 #endif109 84 } 110 85
Note: See TracChangeset
for help on using the changeset viewer.