Changeset 439 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 11/29/05 00:01:43 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/include/Preprocessor.h
r261 r439 27 27 */ 28 28 virtual bool LoadScene(const string filename); 29 30 /** Load the input viewcells. The input viewcells should be given as a collection31 of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of32 the viewcell. The method then builds a BSP tree of these view cells.33 @param filename file to load34 @return true on success35 */36 virtual bool LoadViewCells(const string filename);37 29 38 30 /** Generate the viewCells automatically. The particular algorithm to be used depends -
trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj
r437 r439 300 300 </File> 301 301 <File 302 RelativePath="..\src\ViewCellsManager.cpp"> 303 </File> 304 <File 305 RelativePath="..\src\ViewCellsManager.h"> 306 </File> 307 <File 302 308 RelativePath="..\src\VspBspTree.cpp"> 303 309 </File> -
trunk/VUT/GtpVisibilityPreprocessor/src/ExactPreprocessor.h
r374 r439 10 10 virtual bool ComputeVisibility(); 11 11 12 virtual bool BuildBspTree() { return false; }13 14 12 }; 15 13 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r429 r439 6 6 #include "ViewCell.h" 7 7 #include "Environment.h" 8 #include " RenderSimulator.h"8 #include "ViewCellsManager.h" 9 9 10 10 Preprocessor::Preprocessor(): … … 12 12 mBspTree(NULL), 13 13 mVspKdTree(NULL), 14 m RenderSimulator(NULL)14 mViewCellsManager(NULL) 15 15 { 16 16 } … … 21 21 DEL_PTR(mBspTree); 22 22 DEL_PTR(mKdTree); 23 24 DEL_PTR(mRenderSimulator); 25 26 DeleteViewCells(); 27 } 28 29 bool 30 Preprocessor::LoadViewCells(const string filename) 31 { 32 X3dParser parser; 33 34 environment->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 35 36 return parser.ParseFile(filename, mViewCells); 37 } 38 39 bool 40 Preprocessor::ParseViewCellsOptions() 41 { 42 // parse type of view cells 43 char viewCellsStr[64]; 44 environment->GetStringValue("ViewCells.hierarchy", viewCellsStr); 45 46 if (strcmp(viewCellsStr, "bspTree") == 0) 47 { 48 ViewCell::sHierarchy = ViewCell::BSP; 49 } 50 else if (strcmp(viewCellsStr, "kdTree") == 0) 51 { 52 ViewCell::sHierarchy = ViewCell::KD; 53 } 54 else if (strcmp(viewCellsStr, "vspTree") == 0) 55 { 56 ViewCell::sHierarchy = ViewCell::VSP; 57 } 58 else if (strcmp(viewCellsStr, "sceneDependent") == 0) 59 { 60 //TODO 61 } 62 else 63 { 64 cerr<<"Wrong view cells type" << viewCellsStr << endl; 65 exit(1); 66 } 67 68 return true; 69 } 70 71 RenderSimulator *Preprocessor::GetRenderSimulator() 72 { 73 if (mRenderSimulator) 74 return mRenderSimulator; 75 76 float objRenderCost = 0, vcOverhead = 0, moveSpeed = 0; 77 78 environment->GetFloatValue("Simulation.objRenderCost",objRenderCost); 79 environment->GetFloatValue("Simulation.vcOverhead", vcOverhead); 80 environment->GetFloatValue("Simulation.moveSpeed", moveSpeed); 81 82 Debug << "render simulator using render cost=" << objRenderCost << ", vc overhead=" << vcOverhead << ", move speed=" << moveSpeed << endl; 83 if (ViewCell::sHierarchy == ViewCell::BSP) 84 { 85 mRenderSimulator = new BspViewCellRenderSimulator(objRenderCost, vcOverhead, moveSpeed, mBspTree); 86 Debug << "creating bsp render simulator" << endl; 87 } 88 else if (ViewCell::sHierarchy == ViewCell::KD)// KD view cells 89 { 90 mRenderSimulator = new KdViewCellRenderSimulator(objRenderCost, vcOverhead, moveSpeed, mKdTree); 91 Debug << "creating kd render simulator" << endl; 92 } 93 else 94 { 95 Debug << "not implemented yet" << endl; 96 return NULL; 97 } 98 99 return mRenderSimulator; 100 } 101 102 void Preprocessor::DeleteViewCells() 103 { 104 for (int i = 0; i < (int)mViewCells.size(); ++ i) 105 { 106 Mesh *mesh = mViewCells[i]->GetMesh(); 107 DEL_PTR(mesh); 108 } 109 CLEAR_CONTAINER(mViewCells); 23 DEL_PTR(mVspKdTree); 24 DEL_PTR(mViewCellsManager); 110 25 } 111 26 … … 512 427 exporter->ExportIntersectable(objects[j]); 513 428 } 429 430 bool Preprocessor::PrepareViewCells() 431 { 432 //-- parse type of view cell container 433 char viewCellsStr[64]; 434 environment->GetStringValue("ViewCells.type", viewCellsStr); 435 436 if (strcmp(viewCellsStr, "kdTree") == 0) 437 { 438 //mViewCellsManager = new KdViewCellsManager(mKdTree); 439 } 440 if (strcmp(viewCellsStr, "bspTree") == 0) 441 { 442 //mViewCellsManager = new BspViewCellsManager(mBspTree, mBspConstructionSamples); 443 } 444 else if (strcmp(viewCellsStr, "vspTree") == 0) 445 { 446 //mViewCellsManager = new VspKdViewCellContaienr(mVspKdTree, mVspKdConstructionSamples); 447 } 448 else if (strcmp(viewCellsStr, "sceneDependent") == 0) 449 { 450 //TODO 451 //mViewCellsManager = new BspViewCellContainer(mBspTree); 452 } 453 else 454 { 455 cerr<<"Wrong view cells type" << viewCellsStr << endl; 456 exit(1); 457 } 458 459 //-- parse view cells construction method 460 bool loadViewCells = false; 461 environment->GetBoolValue("ViewCell.Construction.loadFromFile", loadViewCells); 462 463 //-- load view cells from file if requested 464 if (loadViewCells) 465 { 466 char buff[100]; 467 environment->GetStringValue("ViewCells.filename", buff); 468 string vcFilename(buff); 469 mViewCellsManager->LoadViewCells(vcFilename); 470 } 471 472 return true; 473 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
r429 r439 14 14 class SceneGraph; 15 15 class Exporter; 16 class ViewCellsManager; 17 16 18 17 19 /** Namespace for the external visibility preprocessor … … 40 42 virtual bool LoadScene(const string filename); 41 43 42 /** Load the input viewcells. The input viewcells should be given as a collection43 of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of44 the viewcell. The method then builds a BSP tree of these view cells.45 @param filename file to load46 @return true on success47 */48 virtual bool LoadViewCells(const string filename);49 50 44 /** Export all preprocessed data in a XML format understandable by the 51 45 PreprocessingInterface of the GtpVisibilityPreprocessor Module. The file can be compressed depending … … 60 54 */ 61 55 virtual bool BuildKdTree(); 62 63 /** Build the BSP tree of currently loaded occluders/occludees/viewcells. The construction64 is driven by the environment settings, which also says which of the three types of65 entities should be used to drive the heuristical construction (only occluders by default)66 */67 virtual bool BuildBspTree() = 0;68 56 69 57 /** Compute visibility method. This method has to be reimplemented by the actual … … 73 61 virtual bool ComputeVisibility() = 0; 74 62 63 /** View cells are either loaded or prepared for generation, according to the chosen environment 64 object. Important evironment options are, e.g, the view cell type. 65 Should be done after scene loading (i.e., some options are based on scene type). 66 */ 67 bool PrepareViewCells(); 75 68 76 69 bool … … 85 78 virtual void BspTreeStatistics(ostream &s); 86 79 87 void DeleteViewCells();88 89 RenderSimulator *GetRenderSimulator();90 91 /** Parses the view cell options92 */93 bool ParseViewCellsOptions();94 95 96 80 /// scene graph loaded from file 97 81 SceneGraph *mSceneGraph; … … 104 88 /// list of all loaded occludees 105 89 ObjectContainer mOccludees; 106 /// list of all loaded/generated viewcells 107 ViewCellContainer mViewCells; 108 90 109 91 /// BSP tree representing the viewcells 110 92 BspTree *mBspTree; 111 93 112 /// the view cell corresponding to unbounded space 113 BspViewCell mUnbounded; 114 115 RenderSimulator *mRenderSimulator; 94 ViewCellsManager *mViewCellsManager; 116 95 117 96 /** Kd tree inducing a coarse partition of view space that are the building -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
r420 r439 26 26 {} 27 27 28 RenderSimulator::RenderSimulator(float objRenderCost, float vcOverhead, float moveSpeed): 29 mObjRenderCost(objRenderCost), mVcOverhead(vcOverhead), mMoveSpeed(moveSpeed) 30 { 31 } 32 33 /***************************************************** 34 * class ViewCellRenderSimulator implementation * 35 *****************************************************/ 36 37 BspViewCellRenderSimulator::BspViewCellRenderSimulator(float objRenderCost, 28 RenderSimulator::RenderSimulator(float objRenderCost, 29 float vcOverhead, 30 float moveSpeed): 31 mObjRenderCost(objRenderCost), 32 mVcOverhead(vcOverhead), 33 mMoveSpeed(moveSpeed) 34 { 35 } 36 37 void RenderSimulator::SetObjectRenderCost(const float objRenderCost) 38 { 39 mObjRenderCost = objRenderCost; 40 } 41 42 void RenderSimulator::SetVcOverhead(const float vcOverhead) 43 { 44 mVcOverhead = vcOverhead; 45 } 46 47 void RenderSimulator::SetMoveSpeed(const float moveSpeed) 48 { 49 mMoveSpeed = moveSpeed; 50 } 51 52 /********************************************************/ 53 /* class BspRenderSimulator implementation */ 54 /********************************************************/ 55 56 BspRenderSimulator::BspRenderSimulator(float objRenderCost, 38 57 float vcOverhead, 39 58 float moveSpeed, … … 43 62 } 44 63 45 Real BspViewCellRenderSimulator::SimulateRendering() 46 { 47 mStat.Reset(); 48 mStat.Start(); 64 SimulationStatistics BspRenderSimulator::SimulateRendering() 65 { 66 SimulationStatistics simStat; 67 68 simStat.Reset(); 69 simStat.Start(); 49 70 50 71 Real renderTime = 0; … … 84 105 renderTime += vcCost; 85 106 86 if (vcCost > mStat.maxCost)87 mStat.maxCost = vcCost;88 else if (vcCost < mStat.minCost)89 mStat.minCost = vcCost;107 if (vcCost > simStat.maxCost) 108 simStat.maxCost = vcCost; 109 else if (vcCost < simStat.minCost) 110 simStat.minCost = vcCost; 90 111 91 112 // probability that a view cell border is crossed … … 94 115 // crossing the border of a view cell is also depending on the move speed 95 116 loadPvsOverhead += pCrossVc * mVcOverhead; 96 overallarea +=area;117 overallarea += area; 97 118 pInVcTotal += pInVc; 98 119 } … … 102 123 loadPvsOverhead /= pCrossVcTotal; 103 124 104 mStat.avgRtWithoutOverhead = renderTime;105 mStat.avgRenderTime = renderTime + loadPvsOverhead;106 107 mStat.maxCost /= pInVcTotal;108 mStat.minCost /= pInVcTotal;109 110 mStat.Stop();111 112 return renderTime + loadPvsOverhead;113 } 114 115 Real Bsp ViewCellRenderSimulator::RenderPvs(ViewCell &viewCell,125 simStat.avgRtWithoutOverhead = renderTime; 126 simStat.avgRenderTime = renderTime + loadPvsOverhead; 127 128 simStat.maxCost /= pInVcTotal; 129 simStat.minCost /= pInVcTotal; 130 131 simStat.Stop(); 132 133 return simStat; 134 } 135 136 Real BspRenderSimulator::RenderPvs(ViewCell &viewCell, 116 137 float objRenderTime) const 117 138 { … … 123 144 *******************************************************/ 124 145 125 Kd ViewCellRenderSimulator::KdViewCellRenderSimulator(float objRenderCost,146 KdRenderSimulator::KdRenderSimulator(float objRenderCost, 126 147 float vcOverhead, 127 148 float moveSpeed, … … 131 152 } 132 153 133 Real KdViewCellRenderSimulator::SimulateRendering() 134 { 154 SimulationStatistics KdRenderSimulator::SimulateRendering() 155 { 156 SimulationStatistics simStat; 157 135 158 //mKdTree->CollectLeavesPvs(); 136 mStat.Reset();137 mStat.Start();159 simStat.Reset(); 160 simStat.Start(); 138 161 139 162 // total render time … … 170 193 renderTime += vcCost; 171 194 172 if (vcCost > mStat.maxCost)173 mStat.maxCost = vcCost;174 else if (vcCost < mStat.minCost)175 mStat.minCost = vcCost;195 if (vcCost > simStat.maxCost) 196 simStat.maxCost = vcCost; 197 else if (vcCost < simStat.minCost) 198 simStat.minCost = vcCost; 176 199 177 200 // probability that a view cell border is crossed … … 186 209 loadPvsOverhead /= pCrossVcTotal; 187 210 188 mStat.avgRtWithoutOverhead = renderTime;189 mStat.avgRenderTime = renderTime + loadPvsOverhead;190 191 mStat.maxCost /= pInVcTotal;192 mStat.minCost /= pInVcTotal;193 194 mStat.Stop();195 196 return renderTime + loadPvsOverhead;197 } 198 199 Real Kd ViewCellRenderSimulator::RenderPvs(KdLeaf *leaf,200 211 simStat.avgRtWithoutOverhead = renderTime; 212 simStat.avgRenderTime = renderTime + loadPvsOverhead; 213 214 simStat.maxCost /= pInVcTotal; 215 simStat.minCost /= pInVcTotal; 216 217 simStat.Stop(); 218 219 return simStat; 220 } 221 222 Real KdRenderSimulator::RenderPvs(KdLeaf *leaf, 223 float objRenderTime) const 201 224 { 202 225 return leaf->mKdPvs.GetSize() * objRenderTime; -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h
r414 r439 47 47 public: 48 48 RenderSimulator(); 49 /** Constructor taking the estimated render cost, 50 the view cell overhead, 51 and the average move speed of the player into account. 52 */ 49 53 RenderSimulator(float objRendercost, float vcOverhead, float moveSpeed); 50 virtual Real SimulateRendering() = 0; 54 55 /** Simulates rendering of the view cells. 56 @returns the statistics of the simulation. 57 */ 58 virtual SimulationStatistics SimulateRendering() = 0; 59 60 /** Sets estimated render time for a single object in the PVS. 61 */ 62 void SetObjectRenderCost(const float objRenderCost); 63 64 /** Contant overhead for crossing a view cell border. 65 */ 66 void SetVcOverhead(const float vcOverhead); 67 68 /** Average move speed of the player during rendering. 69 */ 70 void SetMoveSpeed(const float moveSpeed); 71 72 73 protected: 51 74 52 75 /// render time for single object of the PVS … … 56 79 /// move speed of player 57 80 float mMoveSpeed; 58 59 SimulationStatistics mStat;60 81 }; 61 82 62 class Bsp ViewCellRenderSimulator: public RenderSimulator83 class BspRenderSimulator: public RenderSimulator 63 84 { 64 85 public: 65 Bsp ViewCellRenderSimulator(float objRenderCost,86 BspRenderSimulator(float objRenderCost, 66 87 float vcOverhead, 67 88 float moveSpeed, 68 89 BspTree *bspTree); 69 90 70 RealSimulateRendering();91 SimulationStatistics SimulateRendering(); 71 92 72 93 protected: … … 80 101 }; 81 102 82 class Kd ViewCellRenderSimulator: public RenderSimulator103 class KdRenderSimulator: public RenderSimulator 83 104 { 84 105 public: 85 Kd ViewCellRenderSimulator(float objRenderCost,106 KdRenderSimulator(float objRenderCost, 86 107 float vcOverhead, 87 108 float moveSpeed, 88 109 KdTree *kdTree); 89 RealSimulateRendering();110 SimulationStatistics SimulateRendering(); 90 111 91 112 protected: -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r437 r439 7 7 #include "Polygon3.h" 8 8 #include "ViewCell.h" 9 #include "ViewCellsManager.h" 9 10 #include "RenderSimulator.h" 10 11 … … 53 54 } 54 55 55 bool56 SamplingPreprocessor::BuildBspTree()57 {58 // delete old tree59 DEL_PTR(mBspTree);60 mBspTree = new BspTree(&mUnbounded);61 ObjectContainer objects;62 63 switch (BspTree::sConstructionMethod)64 {65 case BspTree::FROM_INPUT_VIEW_CELLS:66 mBspTree->Construct(mViewCells);67 break;68 case BspTree::FROM_SCENE_GEOMETRY:69 DeleteViewCells(); // we generate new view cells70 mSceneGraph->CollectObjects(&objects);71 mBspTree->Construct(objects);72 break;73 case BspTree::FROM_SAMPLES:74 DeleteViewCells(); // we generate new view cells75 mBspTree->Construct(mSampleRays);76 break;77 default:78 Debug << "Error: Method not available\n";79 break;80 }81 82 83 return true;84 }85 86 56 int 87 57 SamplingPreprocessor::AddNodeSamples(const Ray &ray, 88 89 90 58 Intersectable *sObject, 59 Intersectable *tObject 60 ) 91 61 { 92 62 int contributingSamples = 0; … … 110 80 for (j=1; j < ((int)ray.kdLeaves.size() - 1); j++) { 111 81 ray.kdLeaves[j]->AddPassingRay2(ray, 112 113 114 82 objects, 83 ray.kdLeaves.size() 84 ); 115 85 } 116 86 … … 138 108 139 109 // object can be seen from the view cell => add to view cell pvs 140 for (j=0; j < ray.bspIntersections.size(); ++ j)110 /*for (j=0; j < ray.bspIntersections.size(); ++ j) 141 111 { 142 112 BspLeaf *leaf = ray.bspIntersections[j].mLeaf; … … 145 115 contributingSamples += 146 116 leaf->GetViewCell()->GetPvs().AddSample(obj); 147 } 117 }*/ 148 118 149 119 // rays passing through this viewcell 150 if (mPass > 1)120 /*if (mPass > 1) 151 121 for (j=1; j < ((int)ray.bspIntersections.size() - 1); ++ j) 152 122 { … … 157 127 AddPassingRay(ray, contributingSamples ? 1 : 0); 158 128 } 159 129 */ 160 130 return contributingSamples; 161 131 } … … 167 137 int sampleContributions = 0; 168 138 169 long t1 = GetRealTime();139 /* long t1 = GetRealTime(); 170 140 // cast ray to KD tree to find intersection with other objects 171 141 mKdTree->CastRay(ray); … … 214 184 break; 215 185 } 216 186 */ 217 187 return sampleContributions; 218 188 } … … 413 383 414 384 int pvsSize = 0; 415 if (ViewCell::sHierarchy == ViewCell::KD)416 pvsSize = object->mKdPvs.GetSize();385 //if (ViewCell::sHierarchy == ViewCell::KD) 386 // pvsSize = object->mKdPvs.GetSize(); 417 387 418 388 … … 479 449 } 480 450 //------------------- 481 if (ViewCell::sHierarchy == ViewCell::BSP) 482 { 483 ProcessBspViewCells(ray, 484 reverseSample ? NULL : object, 485 faceIndex, 486 passContributingSamples, 487 passSampleContributions); 488 489 } 490 else if (ViewCell::sHierarchy == ViewCell::VSP) 491 { 492 ProcessVspViewCells(ray, 493 reverseSample ? NULL : object, 494 faceIndex, 495 passContributingSamples, 496 passSampleContributions); 497 } 451 ProcessViewCells(ray, 452 reverseSample ? NULL : object, 453 faceIndex, 454 passContributingSamples, 455 passSampleContributions); 498 456 } 499 457 } else { … … 514 472 mPass++; 515 473 516 if (ViewCell::sHierarchy == ViewCell::KD) 474 // TODO: move into view cell container 475 /*if (ViewCell::sHierarchy == ViewCell::KD) 517 476 { 518 477 pvsSize = 0; … … 525 484 else 526 485 pvsSize += passSampleContributions; 527 486 */ 528 487 float avgRayContrib = (passContributingSamples > 0) ? 529 488 passSampleContributions/(float)passContributingSamples : 0; … … 547 506 } 548 507 549 if (ViewCell::sHierarchy == ViewCell::KD)508 // if (ViewCell::sHierarchy == ViewCell::KD) 550 509 cout << "#totalKdPvsSize=" << mKdTree->CollectLeafPvs() << endl; 551 510 552 511 //-- render simulation 553 RenderSimulator *rs = GetRenderSimulator(); 554 555 if (rs) 556 { 557 cout << "\nevaluating bsp view cells render time before merge ... "; 558 559 rs->SimulateRendering(); 560 561 cout << " finished" << endl; 562 563 cout << GetRenderSimulator()->mStat << endl; 564 Debug << GetRenderSimulator()->mStat << endl; 565 } 512 cout << "\nevaluating bsp view cells render time before merge ... "; 513 514 SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 515 516 cout << " finished" << endl; 517 cout << ss << endl; 518 Debug << ss << endl; 566 519 567 520 if (mBspTree) … … 610 563 611 564 //-- render simulation 612 613 RenderSimulator *rs = GetRenderSimulator(); 614 615 if (rs) 616 { 617 cout << "\nevaluating render time after merge ... "; 565 cout << "\nevaluating render time after merge ... "; 618 566 619 rs->SimulateRendering(); 620 621 cout << " finished" << endl; 622 623 cout << GetRenderSimulator()->mStat << endl; 624 Debug << GetRenderSimulator()->mStat << endl; 625 } 567 SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 568 569 cout << " finished" << endl; 570 571 cout << ss << endl; 572 Debug << ss << endl; 626 573 627 574 if (1) // export view cells … … 806 753 } 807 754 808 755 void SamplingPreprocessor::ProcessViewCells(const Ray &ray, 756 Intersectable *object, 757 const int faceIndex, 758 int &contributingSamples, 759 int &sampleContributions) 760 { 761 } 762 /* 809 763 void SamplingPreprocessor::ProcessVspViewCells(Ray &ray, 810 764 Intersectable *object, … … 843 797 } 844 798 } 845 // save rays for post processing846 /*else if (((int)mVspSampleRays.size() < mPostProcessSamples) ||847 ((int)mVspSampleRays.size() < mVisualizationSamples))848 {849 mVspSampleRays.push_back(new Ray(ray));850 }*/851 799 } 852 800 … … 897 845 } 898 846 } 899 847 */ 900 848 // merge or subdivide view cells 901 849 int SamplingPreprocessor::PostprocessViewCells(const RayContainer &rays) -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
r429 r439 65 65 @param sampleContributions contribution of the samples 66 66 */ 67 void ProcessBspViewCells(const Ray &ray,67 /*void ProcessBspViewCells(const Ray &ray, 68 68 Intersectable *object, 69 69 const int faceIndex, … … 76 76 int &contributingSamples, 77 77 int &sampleContributions); 78 */ 79 void ProcessViewCells(const Ray &ray, 80 Intersectable *object, 81 const int faceIndex, 82 int &contributingSamples, 83 int &sampleContributions); 78 84 79 /** Adds objects samples to bsp view cells.85 /** Adds objects samples to kd and bsp view cells. 80 86 */ 81 87 int AddObjectSamples(Intersectable *obj, const Ray &ray); 82 83 bool BuildBspTree();84 88 85 89 /** Post processes view cells (i.e., merges or subdivides view cells based -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r430 r439 4 4 #include "MeshKdTree.h" 5 5 #include "Triangle3.h" 6 7 ViewCell::HierarchyType ViewCell::sHierarchy = BSP;8 6 9 7 ViewCell::ViewCell(): MeshInstance(NULL), mPiercingRays(0) … … 13 11 ViewCell::ViewCell(Mesh *mesh): MeshInstance(mesh), mPiercingRays(0) 14 12 { 15 }16 17 ViewCell *ViewCell::Generate(Mesh *mesh)18 {19 switch(sHierarchy)20 {21 case KD:22 return new ViewCell(mesh);23 case BSP:24 return new BspViewCell(mesh);25 default:26 Debug << "should not come here 3" << endl;27 return NULL;28 }29 13 } 30 14 … … 44 28 } 45 29 46 void ViewCell::DeriveViewCells(const ObjectContainer &objects,47 ViewCellContainer &viewCells,48 const int maxViewCells)49 {50 // maximal max viewcells51 int limit = maxViewCells > 0 ?52 Min((int)objects.size(), maxViewCells) : (int)objects.size();53 54 for (int i = 0; i < limit; ++ i)55 {56 Intersectable *object = objects[i];57 58 // extract the mesh instances59 if (object->Type() == Intersectable::MESH_INSTANCE)60 {61 MeshInstance *inst = dynamic_cast<MeshInstance *>(object);62 63 ViewCell *viewCell = Generate(inst->GetMesh());64 viewCells.push_back(viewCell);65 }66 //TODO: transformed meshes67 }68 }69 70 ViewCell *ViewCell::ExtrudeViewCell(const Triangle3 &baseTri, const float height)71 {72 // one mesh per view cell73 Mesh *mesh = new Mesh();74 75 //-- construct prism76 77 // bottom78 mesh->mFaces.push_back(new Face(2,1,0));79 // top80 mesh->mFaces.push_back(new Face(3,4,5));81 // sides82 mesh->mFaces.push_back(new Face(1, 4, 3, 0));83 mesh->mFaces.push_back(new Face(2, 5, 4, 1));84 mesh->mFaces.push_back(new Face(3, 5, 2, 0));85 86 //--- extrude new vertices for top of prism87 Vector3 triNorm = baseTri.GetNormal();88 89 Triangle3 topTri;90 91 // add base vertices and calculate top vertices92 for (int i = 0; i < 3; ++ i)93 mesh->mVertices.push_back(baseTri.mVertices[i]);94 95 // add top vertices96 for (int i = 0; i < 3; ++ i)97 mesh->mVertices.push_back(baseTri.mVertices[i] + height * triNorm);98 99 mesh->Preprocess();100 101 return Generate(mesh);102 }103 104 ViewCell *ViewCell::Merge(ViewCell &front, ViewCell &back)105 {106 ViewCell *vc = Generate();107 // merge pvs108 vc->mPvs.Merge(front.mPvs, back.mPvs);109 110 // merge ray sets111 stable_sort(front.mPiercingRays.begin(), front.mPiercingRays.end());112 stable_sort(back.mPiercingRays.begin(), back.mPiercingRays.end());113 114 std::merge(front.mPiercingRays.begin(), front.mPiercingRays.end(),115 back.mPiercingRays.begin(), back.mPiercingRays.end(),116 vc->mPiercingRays.begin());117 118 return vc;119 }120 121 30 void ViewCell::AddPassingRay(const Ray &ray, const int contributions) 122 31 { -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r419 r439 29 29 30 30 int Type() const; 31 32 /** Derives viewcells from object container.33 @param objects the intersectables the viewcells are derived from34 @param viewCells the viewcells are returned in this container35 @param maxViewCells the maximum number of viewcells created. if 0 => unbounded36 */37 static void DeriveViewCells(const ObjectContainer &objects,38 ViewCellContainer &viewCells,39 const int maxViewCells);40 41 31 42 32 /** Adds a passing ray to the passing ray container. … … 44 34 void AddPassingRay(const Ray &ray, const int contributions); 45 35 46 /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.47 @param the base triangle48 @param the height of the newly created view cell49 */50 static ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height);51 52 /** Merges two view cells.53 @note the piercing rays of the front and back will be ordered54 @returns new view cell based on the merging.55 */56 static ViewCell *Merge(ViewCell &front, ViewCell &back);57 36 58 37 /// Ray set description of the rays passing through this node. … … 61 40 /// Rays piercing this view cell. 62 41 RayContainer mPiercingRays; 63 64 /// view cells types65 enum HierarchyType {BSP, KD, VSP};66 67 /** Generates view cells of type specified by view cells type.68 */69 static ViewCell *Generate(Mesh *mesh = NULL);70 71 /// type of view cells hierarchy (KD, BSP)72 static HierarchyType sHierarchy;73 42 74 43 protected: -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r437 r439 353 353 } 354 354 355 void BspTree::ParseEnvironment()356 {357 //-- parse bsp cell tree construction method358 char constructionMethodStr[60];359 360 environment->GetStringValue("BspTree.Construction.input", constructionMethodStr);361 362 sConstructionMethod = FROM_INPUT_VIEW_CELLS;363 364 if (strcmp(constructionMethodStr, "fromViewCells") == 0)365 sConstructionMethod = FROM_INPUT_VIEW_CELLS;366 else if (strcmp(constructionMethodStr, "fromSceneGeometry") == 0)367 sConstructionMethod = FROM_SCENE_GEOMETRY;368 else if (strcmp(constructionMethodStr, "fromSamples") == 0)369 sConstructionMethod = FROM_SAMPLES;370 else371 {372 cerr << "Wrong construction method " << constructionMethodStr << endl;373 exit(1);374 }375 376 Debug << "Construction method: " << constructionMethodStr << endl;377 }378 379 355 const BspTreeStatistics &BspTree::GetStatistics() const 380 356 { … … 809 785 if (mGenerateViewCells) 810 786 { 811 viewCell = dynamic_cast<BspViewCell *>(ViewCell::Generate());787 viewCell = new BspViewCell(); 812 788 } 813 789 else … … 1980 1956 { 1981 1957 BspViewCell *viewCell = 1982 dynamic_cast<BspViewCell *>(ViewCell::Merge(*front->mViewCell, *back->mViewCell));1958 NULL;//todo dynamic_cast<BspViewCell *>(ViewCell::Merge(*front->mViewCell, *back->mViewCell)); 1983 1959 1984 1960 if (!viewCell) -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r437 r439 527 527 VspBspLeaf *leaf = dynamic_cast<VspBspLeaf *>(tData.mNode); 528 528 529 BspViewCell *viewCell = 530 dynamic_cast<BspViewCell *>(ViewCell::Generate()); 529 BspViewCell *viewCell = new BspViewCell(); 531 530 532 531 leaf->SetViewCell(viewCell); … … 1437 1436 { 1438 1437 BspViewCell *viewCell = 1439 dynamic_cast<BspViewCell *>(ViewCell::Merge(*front->mViewCell, *back->mViewCell));1438 NULL;//TODO dynamic_cast<BspViewCell *>(ViewCell::Merge(*front->mViewCell, *back->mViewCell)); 1440 1439 1441 1440 if (!viewCell) -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r438 r439 9 9 #include "VssRay.h" 10 10 #include "VssTree.h" 11 11 #include "ViewCellsManager.h" 12 12 13 13 bool useViewSpaceBox = true;//true; … … 451 451 } 452 452 453 //-- construct BSP view cells 454 if (ViewCell::sHierarchy == ViewCell::BSP) 455 { 456 const int bspSamples = min((int)mVssRays.size(), mBspConstructionSamples); 457 458 Debug << "bpssamples: " << bspSamples << endl; 459 for (int i = 0; i < bspSamples; ++ i) 460 bspRays.push_back(new Ray(*mVssRays[i])); 461 462 //-- construct BSP tree using the samples 463 mBspTree = new BspTree(&mUnbounded); 464 465 ObjectContainer objects; 466 mSceneGraph->CollectObjects(&objects); 467 mBspTree->Construct(objects, bspRays); 468 } 453 ObjectContainer objects; 454 mSceneGraph->CollectObjects(&objects); 455 456 //mViewCellsManager->Construct(mVssRays, objects); 469 457 470 458 vssTree = new VssTree; … … 541 529 542 530 // cast rays into BSP tree 543 if (ViewCell::sHierarchy == ViewCell::BSP)531 /*if (ViewCell::sHierarchy == ViewCell::BSP) 544 532 { 545 533 for (int i = 0; i < (int)vssRays.size(); ++ i) … … 548 536 } 549 537 } 550 538 */ 551 539 samples+=num; 552 540 float pvs = vssTree->GetAvgPvsSize(); … … 562 550 delete vssTree; 563 551 564 if (ViewCell::sHierarchy == ViewCell::BSP)565 {566 Debug << mBspTree->GetStatistics();567 568 ObjectContainer objects;569 ExportSplits(objects, bspRays, 10000);570 ExportBspPvs(objects, bspRays, 10000);571 572 BspViewCellsStatistics stat;573 mBspTree->EvaluateViewCellsStats(stat);574 Debug << "original view cell partition:\n" << stat << endl;575 576 // clear BSP samples577 CLEAR_CONTAINER(bspRays);578 }579 580 552 return true; 581 553 } 582 583 void VssPreprocessor::CastRay(const BspTree &tree, const VssRay & vssRay)584 {585 //-- cast ray to BSP tree to get intersection with view cells586 Ray ray(vssRay);587 mBspTree->CastRay(ray);588 589 //if (0 && ray.sourceObject.mObject)590 //sampleContributions +=591 //AddObjectSamples(ray.sourceObject.mObject, ray);592 593 if (!ray.intersections.empty()) // second intersection found594 {595 //sampleContributions +=596 AddObjectSamples(ray.intersections[0].mObject, ray);597 }598 }599 600 int VssPreprocessor::AddObjectSamples(Intersectable *obj, const Ray &ray)601 {602 int contributingSamples = 0;603 int j;604 605 // object can be seen from the view cell => add to view cell pvs606 for (j=0; j < ray.bspIntersections.size(); ++ j)607 {608 BspLeaf *leaf = ray.bspIntersections[j].mLeaf;609 // if ray not in unbounded space610 if (leaf->GetViewCell() != &mUnbounded)611 contributingSamples +=612 leaf->GetViewCell()->GetPvs().AddSample(obj);613 }614 615 // rays passing through this viewcell616 if (mPass > 1)617 for (j=1; j < ((int)ray.bspIntersections.size() - 1); ++ j)618 {619 BspLeaf *leaf = ray.bspIntersections[j].mLeaf;620 621 if (leaf->GetViewCell() != &mUnbounded)622 leaf->GetViewCell()->623 AddPassingRay(ray, contributingSamples ? 1 : 0);624 }625 626 return contributingSamples;627 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
r438 r439 58 58 59 59 ); 60 61 62 63 virtual bool BuildBspTree() { return false; }64 60 65 61 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp
r376 r439 28 28 #include "SceneGraph.h" 29 29 #include "Triangle3.h" 30 #include "ViewCell .h"30 #include "ViewCellsManager.h" 31 31 32 32 // --------------------------------------------------------------------------- … … 103 103 void 104 104 X3dParseHandlers::StartIndexedFaceSet( 105 105 AttributeList& attributes) 106 106 { 107 107 int len = attributes.getLength(); … … 195 195 void 196 196 X3dParseHandlers::startElement(const XMLCh* const name, 197 197 AttributeList& attributes) 198 198 { 199 199 StrX lname(name); … … 385 385 // StdInParseHandlers: Constructors and Destructor 386 386 // --------------------------------------------------------------------------- 387 X3dViewCellsParseHandlers::X3dViewCellsParseHandlers(ViewCell Container *viewCells,387 X3dViewCellsParseHandlers::X3dViewCellsParseHandlers(ViewCellsManager *viewCellsManager, 388 388 float viewCellHeight) : 389 389 mElementCount(0) … … 391 391 , mCharacterCount(0) 392 392 , mSpaceCount(0) 393 , mViewCells (viewCells)393 , mViewCellsManager(viewCellsManager) 394 394 , mViewCellHeight(viewCellHeight) 395 395 { … … 457 457 458 458 void 459 X3dViewCellsParseHandlers::StartCoordinate( 460 AttributeList& attributes) 459 X3dViewCellsParseHandlers::StartCoordinate(AttributeList& attributes) 461 460 { 462 461 int len = attributes.getLength(); … … 507 506 508 507 for (i = 0; i < mCurrentVertexIndices.size(); i += 3) 509 508 { 510 509 Triangle3 baseTri(vertices[mCurrentVertexIndices[i + 0]], 511 510 vertices[mCurrentVertexIndices[i + 1]], … … 513 512 514 513 // create view cell from base triangle 515 mViewCells->push_back(ViewCell::ExtrudeViewCell(baseTri, mViewCellHeight)); 516 517 Mesh *mesh = mViewCells->back()->GetMesh(); 518 #ifdef _DEBUG 519 Debug << "Viewcell: " 520 << mesh->mVertices[0] << " " << mesh->mVertices[1] << " " << mesh->mVertices[2] << " " 521 << mesh->mVertices[3] << " " << mesh->mVertices[4] << " " << mesh->mVertices[5] << "\n"; 522 #endif 523 } 514 mViewCellsManager->AddViewCell(mViewCellsManager->ExtrudeViewCell(baseTri, mViewCellHeight)); 515 } 524 516 } 525 517 … … 527 519 void 528 520 X3dViewCellsParseHandlers::startElement(const XMLCh* const name, 529 521 AttributeList& attributes) 530 522 { 531 523 StrX lname(name); … … 608 600 609 601 bool 610 X3dParser::ParseFile(const string filename, ViewCell Container &viewCells)602 X3dParser::ParseFile(const string filename, ViewCellsManager &viewCells) 611 603 { 612 604 // Initialize the XML4C system -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.h
r312 r439 5 5 #include "Containers.h" 6 6 7 class ViewCell ;7 class ViewCellsManager; 8 8 9 9 class X3dParser : public Parser … … 13 13 14 14 bool ParseFile(const string filename, SceneGraphNode **root); 15 bool ParseFile(const string filename, ViewCell Container &viewCells);15 bool ParseFile(const string filename, ViewCellsManager &viewCells); 16 16 17 17 float mViewCellHeight; -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParserXerces.h
r313 r439 16 16 class Mesh; 17 17 class Material; 18 class ViewCellsManager; 18 19 19 20 class X3dParseHandlers : public HandlerBase … … 114 115 // Constructors and Destructor 115 116 // ----------------------------------------------------------------------- 116 X3dViewCellsParseHandlers(ViewCell Container *mViewCells,117 X3dViewCellsParseHandlers(ViewCellsManager *viewCellsManager, 117 118 float viewCellHeight); 118 119 ~X3dViewCellsParseHandlers(); … … 152 153 void resetDocument(); 153 154 154 ViewCell Container *mViewCells;155 ViewCellsManager *mViewCellsManager; 155 156 float mViewCellHeight; 156 157 -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r422 r439 54 54 p->KdTreeStatistics(cout); 55 55 56 // parse view cell hierarchyoptions57 p->P arseViewCellsOptions();56 // parse view cells related options 57 p->PrepareViewCells(); 58 58 59 if (ViewCell::sHierarchy == ViewCell::BSP)60 {61 BspTree::ParseEnvironment();62 63 // We construct BSP tree immediately for "from view cells" or "from scene geometry"64 // construction method.65 // For the "from samples" option, construction is delayed until enough samples were collected66 if (BspTree::sConstructionMethod != BspTree::FROM_SAMPLES)67 {68 if (BspTree::sConstructionMethod == BspTree::FROM_INPUT_VIEW_CELLS)69 {70 //-- load view cells from file71 environment->GetStringValue("ViewCells.filename", buff);72 string vcFilename(buff);73 p->LoadViewCells(vcFilename);74 Debug << (int)p->mViewCells.size() << " view cells loaded" << endl;75 }76 77 p->BuildBspTree();78 79 p->Export("vc_bsptree.x3d", false, false, true);80 p->BspTreeStatistics(Debug);81 }82 }83 59 84 60 // p->mSceneGraph->Export("soda.x3d");
Note: See TracChangeset
for help on using the changeset viewer.