Changeset 468
- Timestamp:
- 12/15/05 18:45:12 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj
r448 r468 249 249 </File> 250 250 <File 251 RelativePath="..\src\Renderer.cpp"> 252 </File> 253 <File 254 RelativePath="..\src\Renderer.h"> 255 </File> 256 <File 251 257 RelativePath="..\src\RenderSimulator.cpp"> 252 258 </File> -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
r463 r468 15 15 class VspKdTree; 16 16 class VspBspTree; 17 class RenderSimulator; 17 18 18 19 /** Namespace for the external visibility preprocessor … … 100 101 VspKdTree *mVspKdTree; 101 102 103 /** Simulates rendering of the scene. 104 */ 105 RenderSimulator *mRenderSimulator; 106 102 107 protected: 103 108 -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
r465 r468 5 5 #include "VspBspTree.h" 6 6 #include "VspKdTree.h" 7 #include "ViewCellsManager.h" 7 8 8 9 void SimulationStatistics::Print(ostream &app) const … … 52 53 } 53 54 54 /********************************************************/ 55 /* class BspRenderSimulator implementation */ 56 /********************************************************/ 57 58 59 BspRenderSimulator::BspRenderSimulator(BspTree *bspTree): 60 mBspTree(bspTree) 55 bool RenderSimulator::RenderScene() 61 56 { 62 } 63 64 BspRenderSimulator::BspRenderSimulator(float objRenderCost, 65 float vcOverhead, 66 float moveSpeed, 67 BspTree *bspTree): 68 RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree) 69 { 70 } 71 72 SimulationStatistics BspRenderSimulator::SimulateRendering() 73 { 74 SimulationStatistics simStat; 75 76 simStat.Reset(); 77 simStat.Start(); 57 mSimulationStatistics.Reset(); 58 mSimulationStatistics.Start(); 78 59 79 60 Real renderTime = 0; … … 81 62 // overhead for loading the PVS of the view cells 82 63 float loadPvsOverhead = 0; 83 // probability that view point lies in a view cell 84 float pInVcTotal = 0; 64 65 ViewCellContainer::const_iterator it, 66 it_end = mViewCellsManager->GetViewCells().end(); 85 67 86 // total probability that a view cell border is crossed 87 const float pCrossVcTotal = mBspTree->GetBoundingBox().SurfaceArea(); 68 for (it = mViewCellsManager->GetViewCells().begin(); it != it_end; ++ it) 69 { 70 ViewCell *vc = *it; 88 71 89 // collect all view cells 90 ViewCellContainer viewCells; 91 mBspTree->CollectViewCells(viewCells); 92 93 ViewCellContainer::const_iterator it, it_end = viewCells.end(); 94 95 // surface area substitute for probability 96 PolygonContainer geom; 97 float overallarea = 0; 98 for (it = viewCells.begin(); it != it_end; ++ it) 99 { 100 // compute view cell area 101 mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom); 102 const float area = Polygon3::GetArea(geom); 103 if (area < 0.0001) 104 Debug << "warning, area: " << area << endl; 105 CLEAR_CONTAINER(geom); 106 107 // area substitute for view point probability 108 float pInVc = area; 72 // probability of view cell 73 const float pInVc = mViewCellsManager->GetProbability(vc); 109 74 110 75 // compute render time of PVS times probability that view point is in view cell 111 float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost); 112 //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl; 76 const float vcCost = pInVc * mViewCellsManager->GetRendercost(vc, mObjRenderCost); 77 78 // crossing the border of a view cell is depending on the move speed 79 // and the probability that a view cell border is crossed 80 loadPvsOverhead += GetCrossVcProbability() * mVcOverhead; 81 82 //-- update statistics 113 83 renderTime += vcCost; 114 84 115 if (vcCost > simStat.maxCost) 116 simStat.maxCost = vcCost; 117 else if (vcCost < simStat.minCost) 118 simStat.minCost = vcCost; 85 if (vcCost > mSimulationStatistics.maxCost) 86 mSimulationStatistics.maxCost = vcCost; 87 else if (vcCost < mSimulationStatistics.minCost) 88 mSimulationStatistics.minCost = vcCost; 89 } 90 91 mSimulationStatistics.avgRtWithoutOverhead = renderTime; 92 mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead; 93 94 mSimulationStatistics.Stop(); 119 95 120 // probability that a view cell border is crossed 121 float pCrossVc = area * mMoveSpeed; 122 123 // crossing the border of a view cell is also depending on the move speed 124 loadPvsOverhead += pCrossVc * mVcOverhead; 125 overallarea += area; 126 pInVcTotal += pInVc; 127 } 128 Debug << "overall area: " << overallarea << endl; 129 130 renderTime /= pInVcTotal; 131 loadPvsOverhead /= pCrossVcTotal; 132 133 simStat.avgRtWithoutOverhead = renderTime; 134 simStat.avgRenderTime = renderTime + loadPvsOverhead; 135 136 simStat.maxCost /= pInVcTotal; 137 simStat.minCost /= pInVcTotal; 138 139 simStat.Stop(); 140 141 return simStat; 96 return true; 142 97 } 143 98 144 Real BspRenderSimulator::RenderPvs(ViewCell &viewCell, 145 float objRenderTime) const 99 float RenderSimulator::GetCrossVcProbability() 146 100 { 147 return viewCell.GetPvs().GetSize() * objRenderTime;101 return 0; 148 102 } 149 103 150 /*******************************************************/ 151 /* class KdenderSimulator implementation */ 152 /*******************************************************/ 153 154 KdRenderSimulator::KdRenderSimulator(float objRenderCost, 155 float vcOverhead, 156 float moveSpeed, 157 KdTree *kdTree): 158 RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree) 104 void RenderSimulator::GetStatistics(SimulationStatistics &simStats) const 159 105 { 106 simStats = mSimulationStatistics; 160 107 } 161 162 KdRenderSimulator::KdRenderSimulator(KdTree *kdTree):163 mKdTree(kdTree)164 {165 }166 167 SimulationStatistics KdRenderSimulator::SimulateRendering()168 {169 SimulationStatistics simStat;170 171 //mKdTree->CollectLeavesPvs();172 simStat.Reset();173 simStat.Start();174 175 // total render time176 Real renderTime = 0;177 // overhead for loading a view cell178 float loadPvsOverhead = 0;179 180 // probability that view point lies in a view cell181 float pInVcTotal = 0;//mKdTree->GetBox().GetVolume();182 183 // total probability that a view cell border is crossed184 const float pCrossVcTotal = mKdTree->GetBox().SurfaceArea();185 186 vector<KdLeaf *> leaves;187 mKdTree->CollectLeaves(leaves);188 189 AxisAlignedBox3 box;190 191 vector<KdLeaf *>::const_iterator it, it_end = leaves.end();192 193 for (it = leaves.begin(); it != it_end; ++ it)194 {195 box = mKdTree->GetBox(*it);196 197 // volume substitute for view point probability198 float pInVc = 0;199 200 if (0)201 pInVc = box.GetVolume();202 else203 pInVc = box.SurfaceArea();204 205 float vcCost = pInVc * RenderPvs(*it, mObjRenderCost);206 renderTime += vcCost;207 208 if (vcCost > simStat.maxCost)209 simStat.maxCost = vcCost;210 else if (vcCost < simStat.minCost)211 simStat.minCost = vcCost;212 213 // probability that a view cell border is crossed214 const float pCrossVc = box.SurfaceArea() * mMoveSpeed;215 216 loadPvsOverhead += pCrossVc * mVcOverhead;217 218 pInVcTotal += pInVc;219 }220 221 renderTime /= pInVcTotal;222 loadPvsOverhead /= pCrossVcTotal;223 224 simStat.avgRtWithoutOverhead = renderTime;225 simStat.avgRenderTime = renderTime + loadPvsOverhead;226 227 simStat.maxCost /= pInVcTotal;228 simStat.minCost /= pInVcTotal;229 230 simStat.Stop();231 232 return simStat;233 }234 235 Real KdRenderSimulator::RenderPvs(KdLeaf *leaf,236 float objRenderTime) const237 {238 return leaf->mKdPvs.GetSize() * objRenderTime;239 }240 241 /**********************************************************/242 /* class BspRenderSimulator implementation */243 /**********************************************************/244 245 VspBspRenderSimulator::VspBspRenderSimulator(VspBspTree *vspBspTree):246 mVspBspTree(vspBspTree)247 {248 }249 250 VspBspRenderSimulator::VspBspRenderSimulator(float objRenderCost,251 float vcOverhead,252 float moveSpeed,253 VspBspTree *vspBspTree):254 RenderSimulator(objRenderCost, vcOverhead, moveSpeed),255 mVspBspTree(vspBspTree)256 {257 }258 259 SimulationStatistics VspBspRenderSimulator::SimulateRendering()260 {261 SimulationStatistics simStat;262 263 simStat.Reset();264 simStat.Start();265 266 Real renderTime = 0;267 268 // overhead for loading the PVS of the view cells269 float loadPvsOverhead = 0;270 // probability that view point lies in a view cell271 float pInVcTotal = 0;272 273 // total probability that a view cell border is crossed274 const float pCrossVcTotal = mVspBspTree->GetBoundingBox().SurfaceArea();275 276 // collect all view cells277 ViewCellContainer viewCells;278 mVspBspTree->CollectViewCells(viewCells);279 280 ViewCellContainer::const_iterator it, it_end = viewCells.end();281 282 // surface area substitute for probability283 PolygonContainer geom;284 float overallarea = 0;285 for (it = viewCells.begin(); it != it_end; ++ it)286 {287 // compute view cell area288 mVspBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);289 290 const float area = Polygon3::GetArea(geom);291 if (area < 0.0001)292 Debug << "warning, area: " << area << endl;293 CLEAR_CONTAINER(geom);294 295 // area substitute for view point probability296 float pInVc = area;297 298 // compute render time of PVS times probability that view point is in view cell299 float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);300 //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;301 renderTime += vcCost;302 303 if (vcCost > simStat.maxCost)304 simStat.maxCost = vcCost;305 else if (vcCost < simStat.minCost)306 simStat.minCost = vcCost;307 308 // probability that a view cell border is crossed309 float pCrossVc = area * mMoveSpeed;310 311 // crossing the border of a view cell is also depending on the move speed312 loadPvsOverhead += pCrossVc * mVcOverhead;313 overallarea += area;314 pInVcTotal += pInVc;315 }316 Debug << "overall area: " << overallarea << endl;317 318 renderTime /= pInVcTotal;319 loadPvsOverhead /= pCrossVcTotal;320 321 simStat.avgRtWithoutOverhead = renderTime;322 simStat.avgRenderTime = renderTime + loadPvsOverhead;323 324 simStat.maxCost /= pInVcTotal;325 simStat.minCost /= pInVcTotal;326 327 simStat.Stop();328 329 return simStat;330 }331 332 Real VspBspRenderSimulator::RenderPvs(ViewCell &viewCell,333 float objRenderTime) const334 {335 return viewCell.GetPvs().GetSize() * objRenderTime;336 }337 338 339 340 /*************************************************************/341 /* class VspKdRenderSimulator implementation */342 /*************************************************************/343 344 345 VspKdRenderSimulator::VspKdRenderSimulator(VspKdTree *vspKdTree):346 mVspKdTree(vspKdTree)347 {348 }349 350 VspKdRenderSimulator::VspKdRenderSimulator(float objRenderCost,351 float vcOverhead,352 float moveSpeed,353 VspKdTree *vspKdTree):354 RenderSimulator(objRenderCost, vcOverhead, moveSpeed),355 mVspKdTree(vspKdTree)356 {357 }358 359 SimulationStatistics VspKdRenderSimulator::SimulateRendering()360 {SimulationStatistics simStat;361 362 simStat.Reset();363 simStat.Start();364 365 Real renderTime = 0;366 367 // overhead for loading the PVS of the view cells368 float loadPvsOverhead = 0;369 // probability that view point lies in a view cell370 float pInVcTotal = 0;371 372 // total probability that a view cell border is crossed373 /* const float pCrossVcTotal = mVspBspTree->GetBoundingBox().SurfaceArea();374 375 // collect all view cells376 ViewCellContainer viewCells;377 mVspBspTree->CollectViewCells(viewCells);378 379 ViewCellContainer::const_iterator it, it_end = viewCells.end();380 381 // surface area substitute for probability382 PolygonContainer geom;383 float overallarea = 0;384 for (it = viewCells.begin(); it != it_end; ++ it)385 {386 // compute view cell area387 mVspBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);388 389 const float area = Polygon3::GetArea(geom);390 if (area < 0.0001)391 Debug << "warning, area: " << area << endl;392 CLEAR_CONTAINER(geom);393 394 // area substitute for view point probability395 float pInVc = area;396 397 // compute render time of PVS times probability that view point is in view cell398 float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);399 //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;400 renderTime += vcCost;401 402 if (vcCost > simStat.maxCost)403 simStat.maxCost = vcCost;404 else if (vcCost < simStat.minCost)405 simStat.minCost = vcCost;406 407 // probability that a view cell border is crossed408 float pCrossVc = area * mMoveSpeed;409 410 // crossing the border of a view cell is also depending on the move speed411 loadPvsOverhead += pCrossVc * mVcOverhead;412 overallarea += area;413 pInVcTotal += pInVc;414 }415 Debug << "overall area: " << overallarea << endl;416 417 renderTime /= pInVcTotal;418 loadPvsOverhead /= pCrossVcTotal;419 420 simStat.avgRtWithoutOverhead = renderTime;421 simStat.avgRenderTime = renderTime + loadPvsOverhead;422 423 simStat.maxCost /= pInVcTotal;424 simStat.minCost /= pInVcTotal;425 426 simStat.Stop();427 */428 return simStat;429 }430 431 Real VspKdRenderSimulator::RenderPvs(ViewCell &viewCell,432 float objRenderTime) const433 {434 return 0; // TODO435 } -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h
r463 r468 4 4 #include "common.h" 5 5 #include "Statistics.h" 6 #include "Renderer.h" 6 7 7 class BspTree;8 class KdTree;9 class ViewCell;10 class KdLeaf;11 class VspKdTree;12 class VspBspTree;13 8 14 9 class SimulationStatistics: public StatisticsBase … … 47 42 48 43 /** Simulated rendering using a simple render heuristics. Used to evaluate the 49 quality of the view cell partition. 44 quality of the view cell partition. Evaluates some statistics of the simulation. 50 45 */ 51 class RenderSimulator 46 class RenderSimulator: public Renderer 52 47 { 53 48 … … 59 54 */ 60 55 RenderSimulator(float objRendercost, float vcOverhead, float moveSpeed); 61 62 /** Simulates rendering of the view cells.63 @returns the statistics of the simulation.64 */65 virtual SimulationStatistics SimulateRendering() = 0;66 56 67 57 /** Sets estimated render time for a single object in the PVS. … … 77 67 void SetMoveSpeed(const float moveSpeed); 78 68 69 /** Returns simulation statistics. 70 */ 71 void GetStatistics(SimulationStatistics &simStats) const; 72 73 /** Simulates rendering of the scene. 74 */ 75 bool RenderScene(); 79 76 80 77 protected: 81 78 79 /** Probability for crossing one view cell. 80 */ 81 float GetCrossVcProbability(); 82 82 83 /// render time for single object of the PVS 83 84 float mObjRenderCost; 85 84 86 /// const overhead for crossing a view cell border 85 87 float mVcOverhead; 88 86 89 /// move speed of player 87 90 float mMoveSpeed; 88 };89 91 90 class BspRenderSimulator: public RenderSimulator 91 { 92 public: 93 BspRenderSimulator(BspTree *bspTree); 94 95 BspRenderSimulator(float objRenderCost, 96 float vcOverhead, 97 float moveSpeed, 98 BspTree *bspTree); 99 100 SimulationStatistics SimulateRendering(); 101 102 protected: 103 /** Simulates rendering of the pvs of one view cell, with given rendering time for an object. 104 @param viewCell the view cell holding the Pvs 105 @param objRenderTime estimated render time for one object of the Pvs 106 */ 107 Real RenderPvs(ViewCell &viewCell, const float objRenderTime) const; 108 109 private: 110 BspTree *mBspTree; 111 }; 112 113 class VspBspRenderSimulator: public RenderSimulator 114 { 115 public: 116 VspBspRenderSimulator(VspBspTree *vspBspTree); 117 118 VspBspRenderSimulator(float objRenderCost, 119 float vcOverhead, 120 float moveSpeed, 121 VspBspTree *vspBspTree); 122 123 SimulationStatistics SimulateRendering(); 124 125 protected: 126 /** Simulates rendering of the pvs of one view cell, with given rendering time for an object. 127 @param viewCell the view cell holding the Pvs 128 @param objRenderTime estimated render time for one object of the Pvs 129 */ 130 Real RenderPvs(ViewCell &viewCell, const float objRenderTime) const; 131 132 private: 133 VspBspTree *mVspBspTree; 134 }; 135 136 class KdRenderSimulator: public RenderSimulator 137 { 138 public: 139 KdRenderSimulator(KdTree *kdTree); 140 141 KdRenderSimulator(float objRenderCost, 142 float vcOverhead, 143 float moveSpeed, 144 KdTree *kdTree); 145 SimulationStatistics SimulateRendering(); 146 147 protected: 148 149 Real RenderPvs(KdLeaf *leaf, float objRenderTime) const; 150 151 KdTree *mKdTree; 152 }; 153 154 class VspKdRenderSimulator: public RenderSimulator 155 { 156 public: 157 VspKdRenderSimulator(VspKdTree *vspKdTree); 158 159 VspKdRenderSimulator(float objRenderCost, 160 float vcOverhead, 161 float moveSpeed, 162 VspKdTree *vspKdTree); 163 164 SimulationStatistics SimulateRendering(); 165 166 protected: 167 /** Simulates rendering of the pvs of one view cell, with given rendering time for an object. 168 @param viewCell the view cell holding the Pvs 169 @param objRenderTime estimated render time for one object of the Pvs 170 */ 171 Real RenderPvs(ViewCell &viewCell, const float objRenderTime) const; 172 173 private: 174 VspKdTree *mVspKdTree; 92 /// Simulation statistics 93 SimulationStatistics mSimulationStatistics; 175 94 }; 176 95 -
trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
r467 r468 642 642 cout << "\nevaluating bsp view cells render time after merge ... "; 643 643 644 const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 645 644 mRenderSimulator->RenderScene(); 645 SimulationStatistics ss; 646 mRenderSimulator->GetStatistics(ss); 647 646 648 cout << " finished" << endl; 647 649 cout << ss << endl; -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r466 r468 394 394 cout << "\nevaluating bsp view cells render time after merge ... "; 395 395 396 const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 397 398 cout << " finished" << endl; 399 cout << ss << endl; 400 Debug << ss << endl; 396 //-- render simulation after merge 397 cout << "\nevaluating bsp view cells render time after merge ... "; 398 399 mRenderSimulator->RenderScene(); 400 SimulationStatistics ss; 401 mRenderSimulator->GetStatistics(ss); 402 403 cout << " finished" << endl; 404 cout << ss << endl; 405 Debug << ss << endl; 401 406 402 407 // $$JB temporary removed -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r466 r468 1863 1863 1864 1864 1865 int 1866 BspTree::CastLineSegment(const Vector3 &origin, 1867 const Vector3 &termination, 1868 vector<ViewCell *> &viewcells 1869 ) 1865 int BspTree::CastLineSegment(const Vector3 &origin, 1866 const Vector3 &termination, 1867 vector<ViewCell *> &viewcells) 1870 1868 { 1871 1869 int hits = 0; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r467 r468 164 164 } 165 165 166 SimulationStatistics ViewCellsManager::SimulateRendering() const167 {168 if (!ViewCellsConstructed() || !mRenderSimulator)169 return SimulationStatistics();170 171 return mRenderSimulator->SimulateRendering();172 }173 166 174 167 ViewCell *ViewCellsManager::GenerateViewCell(Mesh *mesh) const … … 242 235 } 243 236 237 ViewCellContainer &ViewCellsManager::GetViewCells() 238 { 239 return mViewCells; 240 } 241 242 void ViewCellsManager::ComputeSampleContributions(VssRay &ray) 243 { 244 ViewCellContainer viewcells; 245 246 CastLineSegment(ray.mOrigin, 247 ray.mTermination, 248 viewcells); 249 250 ray.mPvsContribution = 0; 251 ray.mRelativePvsContribution = 0.0f; 252 253 ViewCellContainer::const_iterator it = viewcells.begin(); 254 255 for (; it != viewcells.end(); ++it) 256 { 257 ViewCell *viewcell = *it; 258 259 // if ray not outside of view space 260 float contribution; 261 bool added = 262 viewcell->GetPvs().AddSample(ray.mTerminationObject, 263 contribution); 264 265 if (added) 266 ray.mPvsContribution++; 267 268 ray.mRelativePvsContribution += contribution; 269 } 270 } 271 272 244 273 /**********************************************************************/ 245 274 /* BspViewCellsManager implementation */ … … 250 279 mBspTree(bspTree) 251 280 { 252 mRenderSimulator = new BspRenderSimulator(bspTree);253 InitRenderSimulator();254 281 } 255 282 … … 306 333 } 307 334 308 void 309 ViewCellsManager::ComputeSampleContributions(VssRay &ray) 310 { 311 312 ViewCellContainer viewcells; 313 314 CastLineSegment(ray.mOrigin, 315 ray.mTermination, 316 viewcells 317 ); 318 319 ray.mPvsContribution = 0; 320 ray.mRelativePvsContribution = 0.0f; 321 322 ViewCellContainer::const_iterator it = viewcells.begin(); 323 for (; it != viewcells.end(); ++it) { 324 ViewCell *viewcell = *it; 325 326 // if ray not outside of view space 327 float contribution; 328 bool added = 329 viewcell->GetPvs().AddSample(ray.mTerminationObject, 330 contribution 331 ); 332 if (added) 333 ray.mPvsContribution++; 334 335 ray.mRelativePvsContribution += contribution; 336 } 337 338 } 339 340 int 341 BspViewCellsManager::CastLineSegment(const Vector3 &origin, 342 const Vector3 &termination, 343 ViewCellContainer &viewcells 344 ) 345 { 346 return mBspTree->CastLineSegment(origin, termination, viewcells); 347 } 348 349 int 350 BspViewCellsManager::PostProcess(const ObjectContainer &objects, 351 const VssRayContainer &rays) 335 336 float BspViewCellsManager::GetProbability(ViewCell *viewCell) 337 { 338 PolygonContainer geom; 339 340 // compute view cell area 341 mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(viewCell), geom); 342 343 const float area = Polygon3::GetArea(geom); 344 const float accArea = mBspTree->GetBoundingBox().SurfaceArea(); 345 346 CLEAR_CONTAINER(geom); 347 348 return area / accArea; 349 } 350 351 352 float BspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) 353 { 354 return viewCell->GetPvs().GetSize() * objRendercost; 355 } 356 357 358 int BspViewCellsManager::CastLineSegment(const Vector3 &origin, 359 const Vector3 &termination, 360 ViewCellContainer &viewcells) 361 { 362 return mBspTree->CastLineSegment(origin, termination, viewcells); 363 } 364 365 366 int BspViewCellsManager::PostProcess(const ObjectContainer &objects, 367 const VssRayContainer &rays) 352 368 { 353 369 if (!ViewCellsConstructed()) … … 392 408 //-- render simulation 393 409 cout << "\nevaluating bsp view cells render time before merge ... "; 394 395 const SimulationStatistics ss = SimulateRendering(); 396 397 cout << " finished" << endl; 398 cout << ss << endl; 399 Debug << ss << endl; 410 //-- render simulation after merge 411 cout << "\nevaluating bsp view cells render time after merge ... "; 412 413 mRenderSimulator->RenderScene(); 414 SimulationStatistics ss; 415 mRenderSimulator->GetStatistics(ss); 416 417 cout << " finished" << endl; 418 cout << ss << endl; 419 Debug << ss << endl; 420 400 421 } 401 422 … … 819 840 mKdPvsDepth(100) 820 841 { 821 mRenderSimulator = new KdRenderSimulator(mKdTree); 822 InitRenderSimulator(); 842 } 843 844 float KdViewCellsManager::GetProbability(ViewCell *viewCell) 845 { 846 return 0; 847 } 848 849 850 float KdViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) 851 { 852 return 0; 823 853 } 824 854 … … 970 1000 mVspKdTree(vspKdTree) 971 1001 { 972 mRenderSimulator = new VspKdRenderSimulator(vspKdTree); 973 mVspKdTree->SetViewCellsManager(this); 974 975 InitRenderSimulator(); 976 } 977 1002 mVspKdTree->SetViewCellsManager(this); 1003 } 1004 1005 float VspKdViewCellsManager::GetProbability(ViewCell *viewCell) 1006 { 1007 /*AxisAlignedBox3 box = mKdTree->GetBox(*it); 1008 1009 // volume or area substitutes for view point probability 1010 if (0) 1011 return box.GetVolume(); 1012 else 1013 return box.SurfaceArea();*/ 1014 1015 return dynamic_cast<VspKdViewCell *>(viewCell)->GetSize(); 1016 } 1017 1018 1019 float VspKdViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) 1020 { 1021 return 0;//leaf->mKdPvs.GetSize() * objRendercost; 1022 } 978 1023 979 1024 VspKdViewCellsManager::~VspKdViewCellsManager() … … 1181 1226 mVspBspTree(vspBspTree) 1182 1227 { 1183 mRenderSimulator = new VspBspRenderSimulator(vspBspTree); 1184 InitRenderSimulator(); 1185 } 1186 1187 1228 } 1229 1230 float VspBspViewCellsManager::GetProbability(ViewCell *viewCell) 1231 { 1232 PolygonContainer geom; 1233 1234 // compute view cell area 1235 mVspBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(viewCell), geom); 1236 1237 const float area = Polygon3::GetArea(geom); 1238 const float accArea = mVspBspTree->GetBoundingBox().SurfaceArea(); 1239 1240 CLEAR_CONTAINER(geom); 1241 1242 return area / accArea; 1243 } 1244 1245 1246 float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) 1247 { 1248 return viewCell->GetPvs().GetSize() * objRendercost; 1249 } 1188 1250 1189 1251 VspBspViewCellsManager::~VspBspViewCellsManager() -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r467 r468 62 62 @param contributingSamples returns the number of contributingSamples 63 63 */ 64 void ComputeSampleContributions(const VssRayContainer &rays 65 ); 64 void ComputeSampleContributions(const VssRayContainer &rays); 66 65 67 66 … … 94 93 virtual int GetType() const = 0; 95 94 96 /** Simulates rendering with the given view cell partition.97 @returns render time statistics98 */99 SimulationStatistics SimulateRendering() const;100 101 95 /** Load the input viewcells. The input viewcells should be given as a collection 102 96 of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of … … 176 170 PrintPvsStatistics(ostream &s); 177 171 172 /** Returns probability that view point lies in one view cell. 173 */ 174 virtual float GetProbability(ViewCell *viewCell) = 0; 175 176 /** Returns render cost of a single view cell given the render cost of an object. 177 */ 178 virtual float GetRendercost(ViewCell *viewCell, float objRendercost) = 0; 179 180 /** Returns vector of loaded / generated view cells. 181 */ 182 ViewCellContainer &GetViewCells(); 183 178 184 protected: 179 180 185 181 186 … … 239 244 ~BspViewCellsManager(); 240 245 241 int CastLineSegment(const Vector3 &origin, 242 const Vector3 &termination, 243 ViewCellContainer &viewcells 244 ); 245 246 246 int CastLineSegment(const Vector3 &origin, 247 const Vector3 &termination, 248 ViewCellContainer &viewcells); 249 250 float GetProbability(ViewCell *viewCell); 251 float GetRendercost(ViewCell *viewCell, float objRendercost); 252 247 253 protected: 248 254 … … 305 311 */ 306 312 virtual void PrintStatistics(ostream &s) const; 313 314 float GetProbability(ViewCell *viewCell); 315 float GetRendercost(ViewCell *viewCell, float objRendercost); 307 316 308 317 protected: … … 353 362 int CastLineSegment(const Vector3 &origin, 354 363 const Vector3 &termination, 355 ViewCellContainer &viewcells 356 ) ; 364 ViewCellContainer &viewcells); 365 366 float GetProbability(ViewCell *viewCell); 367 float GetRendercost(ViewCell *viewCell, float objRendercost); 357 368 358 369 protected: … … 394 405 395 406 void PrintStatistics(ostream &s) const; 396 397 int CastLineSegment(const Vector3 &origin, 398 const Vector3 &termination, 399 ViewCellContainer &viewcells 400 ) ; 407 408 int CastLineSegment(const Vector3 &origin, 409 const Vector3 &termination, 410 ViewCellContainer &viewcells); 411 412 float GetProbability(ViewCell *viewCell); 413 float GetRendercost(ViewCell *viewCell, float objRendercost); 414 401 415 402 416 protected: -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r466 r468 1901 1901 1902 1902 1903 int VspKdTree::CastRay(Ray &ray) 1903 int VspKdTree::CastLineSegment(const Vector3 &origin, 1904 const Vector3 &termination, 1905 vector<ViewCell *> &viewcells) 1904 1906 { 1905 1907 int hits = 0; 1906 1908 1907 stack<RayTraversalData> tStack;1908 1909 float maxt = 1e6; 1910 float mint = 0;1909 float mint = 0.0f, maxt = 1.0f; 1910 const Vector3 dir = termination - origin; 1911 1912 stack<LineSegmentTraversalData > tStack; 1911 1913 1912 1914 Intersectable::NewMail(); 1913 1915 1914 if (!mBox.GetMinMaxT(ray, &mint, &maxt)) 1915 return 0; 1916 //if (!mBox.GetMinMaxT(ray, &mint, &maxt)) return 0; 1916 1917 1917 1918 if (mint < 0) … … 1920 1921 maxt += Limits::Threshold; 1921 1922 1922 Vector3 entp = ray.Extrap(mint);1923 Vector3 extp = ray.Extrap(maxt);1923 Vector3 entp = origin; 1924 Vector3 extp = termination; 1924 1925 1925 1926 VspKdNode *node = mRoot; … … 1969 1970 // $$ modification 3.5.2004 - hints from Kamil Ghais 1970 1971 // case N4 or P4 1971 float tdist = (position - ray.GetLoc(axis)) / ray.GetDir(axis);1972 float tdist = (position - origin[axis]) / dir[axis]; 1972 1973 //tStack.push(RayTraversalData(farChild, extp, maxt)); //TODO 1973 extp = ray.GetLoc() + ray.GetDir()*tdist;1974 extp = origin + dir * tdist; 1974 1975 maxt = tdist; 1975 1976 } … … 1977 1978 { 1978 1979 // compute intersection with all objects in this leaf 1979 /*KdLeaf *leaf = (KdLeaf *) node; 1980 if (ray.mFlags & Ray::STORE_KDLEAVES) 1981 ray.kdLeaves.push_back(leaf); 1982 1983 ObjectContainer::const_iterator mi; 1984 for ( mi = leaf->mObjects.begin(); mi != leaf->mObjects.end(); mi++) 1985 { 1986 Intersectable *object = *mi; 1987 if (!object->Mailed() ) 1988 { 1989 object->Mail(); 1990 if (ray.mFlags & Ray::STORE_TESTED_OBJECTS) 1991 ray.testedObjects.push_back(object); 1992 hits += object->CastRay(ray); 1993 } 1994 } 1995 1996 if (hits && ray.GetType() == Ray::LOCAL_RAY) 1997 if (ray.intersections[0].mT <= maxt) 1998 break; 1980 VspKdLeaf *leaf = dynamic_cast<VspKdLeaf *>(node); 1981 ViewCell *vc = leaf->GetViewCell(); 1982 1983 if (!vc->Mailed()) 1984 { 1985 vc->Mail(); 1986 viewcells.push_back(vc); 1987 } 1999 1988 2000 1989 // get the next node from the stack … … 2004 1993 entp = extp; 2005 1994 mint = maxt; 2006 if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 2007 break; 2008 2009 RayTraversalData &s = tStack.top(); 1995 1996 LineSegmentTraversalData &s = tStack.top(); 2010 1997 node = s.mNode; 2011 1998 extp = s.mExitPoint; 2012 1999 maxt = s.mMaxT; 2013 2000 tStack.pop(); 2014 */2015 2001 } 2016 2002 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
r465 r468 488 488 leafb->GetPvsSize() * (float)leafb->rays.size(); 489 489 #endif 490 491 492 493 494 495 496 497 498 499 500 490 } 491 }; 492 493 /** Simplified data for ray traversal only. 494 */ 495 struct RayTraversalData 496 { 497 RayInfo mRayData; 498 VspKdNode *mNode; 499 500 RayTraversalData() {} 501 501 502 RayTraversalData(VspKdNode *n, const RayInfo &data): 503 mRayData(data), mNode(n) {} 504 }; 505 502 RayTraversalData(VspKdNode *n, const RayInfo &data): 503 mRayData(data), mNode(n) {} 504 }; 505 506 struct LineSegmentTraversalData 507 { 508 VspKdNode *mNode; 509 Vector3 mExitPoint; 510 511 float mMaxT; 512 513 LineSegmentTraversalData () {} 514 LineSegmentTraversalData (VspKdNode *n, 515 const Vector3 &p, 516 const float maxt): 517 mNode(n), mExitPoint(p), mMaxT(maxt) {} 518 }; 519 506 520 public: 507 521 … … 558 572 @returns the number of intersections with objects stored in the tree. 559 573 */ 560 int CastRay(Ray &ray); 574 int CastLineSegment(const Vector3 &origin, 575 const Vector3 &termination, 576 vector<ViewCell *> &viewcells); 561 577 562 578 /** Collects view cells generated by this tree. -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r466 r468 27 27 environment->GetBoolValue("VssPreprocessor.useImportanceSampling", mUseImportanceSampling); 28 28 environment->GetIntValue("BspTree.Construction.samples", mBspConstructionSamples); 29 29 30 30 mStats.open("stats.log"); 31 31 } … … 37 37 38 38 void 39 VssPreprocessor::SetupRay(Ray &ray, 40 const Vector3 &point, 39 VssPreprocessor::SetupRay(Ray &ray, 40 const Vector3 &point, 41 41 const Vector3 &direction 42 42 ) … … 62 62 if (!sbox.IsInside(viewPoint)) 63 63 return 0; 64 64 65 65 SetupRay(ray, viewPoint, direction); 66 66 // cast ray to KD tree to find intersection with other objects … … 81 81 } 82 82 pointA = ray.Extrap(tmax); 83 83 84 84 } 85 85 86 86 bool detectEmptyViewSpace = true; 87 87 88 88 if (detectEmptyViewSpace) { 89 89 SetupRay(ray, pointA, -direction); 90 90 } else 91 91 SetupRay(ray, viewPoint, -direction); 92 93 92 93 94 94 if (mKdTree->CastRay(ray)) { 95 95 96 96 objectB = ray.intersections[0].mObject; 97 97 pointB = ray.Extrap(ray.intersections[0].mT); … … 105 105 // cerr<<"ray"<<ray<<endl; 106 106 } 107 107 108 108 pointB = ray.Extrap(tmax); 109 109 } … … 118 118 } 119 119 } 120 120 121 121 if (validSample) { 122 122 if (objectA) { … … 128 128 hits ++; 129 129 } 130 130 131 131 if (objectB) { 132 132 vssRay = new VssRay(pointA, … … 138 138 } 139 139 } 140 140 141 141 return hits; 142 142 } … … 147 147 { 148 148 AxisAlignedBox3 box; 149 149 150 150 if (viewSpaceBox) 151 151 box =*viewSpaceBox; 152 else 152 else 153 153 box = mKdTree->GetBox(); 154 154 155 155 // shrink the box in the y direction 156 156 return box.GetRandomPoint(); … … 170 170 } else { 171 171 AxisAlignedBox3 box; 172 172 173 173 if (viewSpaceBox) 174 174 box =*viewSpaceBox; 175 else 175 else 176 176 box = mKdTree->GetBox(); 177 177 178 178 point = box.GetRandomPoint(); 179 179 point.y = viewpoint.y; 180 180 } 181 181 182 182 return point - viewpoint; 183 183 } … … 194 194 float maxRayContribution; 195 195 float avgRayContribution; 196 196 197 197 vssTree->GetRayContributionStatistics(minRayContribution, 198 198 maxRayContribution, 199 199 avgRayContribution); 200 200 201 201 cout<< 202 202 "#MIN_RAY_CONTRIB\n"<<minRayContribution<<endl<< 203 203 "#MAX_RAY_CONTRIB\n"<<maxRayContribution<<endl<< 204 204 "#AVG_RAY_CONTRIB\n"<<avgRayContribution<<endl; 205 205 206 206 float p = desiredSamples/(float)(avgRayContribution*vssTree->stat.Leaves()); 207 207 num = vssTree->GenerateRays(p, rays); … … 210 210 num = vssTree->GenerateRays(desiredSamples, leaves, rays); 211 211 } 212 212 213 213 cout<<"Generated "<<num<<" rays."<<endl; 214 214 215 215 return num; 216 216 } … … 224 224 { 225 225 cout<<"Exporting vss rays..."<<endl<<flush; 226 226 227 227 float prob = number/(float)vssRays.size(); 228 228 … … 241 241 exporter->ResetForcedMaterial(); 242 242 } 243 243 244 244 VssRayContainer rays; for (int i=0; i < vssRays.size(); i++) 245 245 if (RandomValue(0,1) < prob) … … 247 247 248 248 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 249 249 250 250 delete exporter; 251 251 … … 280 280 exporter->SetWireframe(); 281 281 exporter->ExportKdTree(*mKdTree); 282 282 283 283 if (mViewSpaceBox) { 284 284 exporter->SetForcedMaterial(RgbColor(1,0,0)); … … 286 286 exporter->ResetForcedMaterial(); 287 287 } 288 288 289 289 exporter->SetForcedMaterial(RgbColor(0,0,1)); 290 290 exporter->ExportBox(tree->GetBBox(leaf)); 291 291 exporter->ResetForcedMaterial(); 292 292 293 293 VssRayContainer rays[4]; 294 294 for (int i=0; i < leaf->rays.size(); i++) { … … 296 296 rays[k].push_back(leaf->rays[i].mRay); 297 297 } 298 298 299 299 // SOURCE RAY 300 300 exporter->ExportRays(rays[0], RgbColor(1, 0, 0)); … … 342 342 for (it = viewcells.begin(); it != it_end; ++ it) 343 343 sum += tree->GetPvsSize(*it); 344 344 345 345 return sum/(float)viewcells.size(); 346 346 } … … 349 349 VssPreprocessor::ComputeVisibility() 350 350 { 351 351 352 352 mSceneGraph->CollectObjects(&mObjects); 353 353 354 354 long startTime = GetTime(); 355 355 356 356 int totalSamples = 0; 357 357 … … 368 368 box->SetMax(box->Max() + translation); 369 369 } else { 370 370 371 371 // sample city like heights 372 372 box->SetMin(1, box->Min(1) + box->Size(1)*0.2); … … 376 376 if (use2dSampling) 377 377 box->SetMax(1, box->Min(1)); 378 378 379 379 if (useViewSpaceBox) 380 380 mViewSpaceBox = box; 381 381 else 382 382 mViewSpaceBox = NULL; 383 383 384 384 385 385 VssTree *vssTree = NULL; … … 390 390 int passSamples = 0; 391 391 int index = 0; 392 392 393 393 int sampleContributions; 394 394 395 395 int s = Min(mSamplesPerPass, mInitialSamples); 396 396 for (int k=0; k < s; k++) { 397 397 398 398 Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 399 399 Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 400 400 401 401 sampleContributions = CastRay(viewpoint, direction, mVssRays); 402 403 402 403 404 404 //-- CORR matt: put block inside loop 405 405 if (sampleContributions) { … … 410 410 totalSamples++; 411 411 } 412 412 413 413 mPass++; 414 414 415 415 int pvsSize = 0; 416 float avgRayContrib = (passContributingSamples > 0) ? 416 float avgRayContrib = (passContributingSamples > 0) ? 417 417 passSampleContributions/(float)passContributingSamples : 0; 418 418 419 419 cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 420 cout << "#TotalSamples=" << totalSamples/1000 421 << "k #SampleContributions=" << passSampleContributions << " (" 420 cout << "#TotalSamples=" << totalSamples/1000 421 << "k #SampleContributions=" << passSampleContributions << " (" 422 422 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 423 << pvsSize/(float)mObjects.size() << endl 423 << pvsSize/(float)mObjects.size() << endl 424 424 << "avg ray contrib=" << avgRayContrib << endl; 425 425 426 426 mStats << 427 427 "#Pass\n" <<mPass<<endl<< 428 428 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 429 429 "#TotalSamples\n" << totalSamples<< endl<< 430 "#SampleContributions\n" << passSampleContributions << endl << 430 "#SampleContributions\n" << passSampleContributions << endl << 431 431 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 432 432 "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << … … 435 435 436 436 437 438 } 439 437 438 } 439 440 440 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 441 441 cout << "#totalRayStackSize=" << mVssRays.size() << endl <<flush; 442 442 443 443 //int numExportRays = 10000; 444 444 int numExportRays = 0; … … 449 449 ExportRays(filename, mVssRays, numExportRays); 450 450 } 451 451 452 452 mSceneGraph->CollectObjects(&mObjects); 453 453 … … 457 457 vssTree = new VssTree; 458 458 // viewcells = Construct(mVssRays); 459 459 460 460 vssTree->Construct(mVssRays, mViewSpaceBox); 461 461 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 462 462 463 463 if (0) 464 464 { … … 482 482 if (RandomValue(0.0f,1.0f) < prob) 483 483 kdViewcells.push_back(mKdTree->GetBox(*it)); 484 484 485 485 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 486 486 cout<<"Initial average PVS size = "<<avgPvs<<endl; 487 487 } 488 488 489 489 490 490 int samples = 0; 491 491 int pass = 0; … … 498 498 SimpleRayContainer rays; 499 499 VssRayContainer vssRays; 500 500 501 501 if (!mUseImportanceSampling) { 502 502 for (int j=0; j < num; j++) { … … 508 508 num = GenerateImportanceRays(vssTree, num, rays); 509 509 } 510 510 511 511 for (int i=0; i < rays.size(); i++) 512 512 CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); 513 513 514 514 vssTree->AddRays(vssRays); 515 515 516 516 if (0) { 517 517 int subdivided = vssTree->UpdateSubdivision(); … … 528 528 else 529 529 sprintf(filename, "vss-rays-%04d.x3d", pass); 530 530 531 531 ExportRays(filename, vssRays, numExportRays); 532 532 } … … 547 547 } 548 548 549 549 550 { 550 551 VssRayContainer storedRays; … … 552 553 mViewCellsManager->GetPostProcessSamples(), 553 554 mViewCellsManager->GetVisualizationSamples())); 554 555 555 556 //-- post process view cells 556 557 mViewCellsManager->PostProcess(mObjects, storedRays); 557 558 558 559 //-- several visualizations and statistics 559 560 mViewCellsManager->PrintStatistics(Debug); … … 563 564 CLEAR_CONTAINER(storedRays); 564 565 } 566 567 //-- render simulation after merge 568 cout << "\nevaluating bsp view cells render time after merge ... "; 565 569 566 570 //-- render simulation after merge 567 571 cout << "\nevaluating bsp view cells render time after merge ... "; 568 572 569 const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 570 573 mRenderSimulator->RenderScene(); 574 SimulationStatistics ss; 575 mRenderSimulator->GetStatistics(ss); 576 571 577 cout << " finished" << endl; 572 578 cout << ss << endl; 573 579 Debug << ss << endl; 574 575 580 581 576 582 delete vssTree; 577 583 578 584 return true; 579 585 }
Note: See TracChangeset
for help on using the changeset viewer.