Changeset 308
- Timestamp:
- 10/05/05 02:19:15 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r306 r308 8 8 # filename glasgow1.x3d 9 9 # filename vienna.x3d 10 filename ../data/vienna/vienna-simple.x3d 10 # filename ../data/vienna/vienna-simple.x3d 11 filename ../data/vienna/vienna-buildings.x3d 11 12 # filename ../data/vienna/viewcells-25-sel.x3d 12 13 # filename ../data/atlanta/atlanta2.x3d … … 15 16 # viewcells ../data/atlanta/atlanta_viewcells_large.x3d 16 17 # viewcells ../data/atlanta/atlanta_viewcells_large2.x3d 17 #viewcells ../data/vienna/viewcells-25-sel.x3d18 viewcells ../data/vienna/viewcells-25.x3d18 viewcells ../data/vienna/viewcells-25-sel.x3d 19 # viewcells ../data/vienna/viewcells-25.x3d 19 20 # viewcells ../data/vienna/viewcells-large-sel.x3d 20 21 } … … 60 61 61 62 Sampling { 62 totalSamples 10000 63 totalSamples 1000000 63 64 samplesPerPass 5 64 65 } 66 65 67 66 68 BspTree { … … 73 75 # vertical axis = 64 74 76 75 splitPlaneStrategy 3277 splitPlaneStrategy 66 76 78 # least splits + balanced polygons 77 79 #splitPlaneStrategy 12 -
trunk/VUT/GtpVisibilityPreprocessor/src/Camera.h
r162 r308 24 24 mWidth = 640; 25 25 mHeight = 480; 26 mFovy = 60*M_PI/180 ;26 mFovy = 60*M_PI/180.0f; 27 27 } 28 28 -
trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h
r245 r308 13 13 KdPvs mKdPvs; 14 14 15 enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE, VIEW CELL };15 enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE, VIEW_CELL }; 16 16 17 17 Intersectable():mailbox(0) {} -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp
r258 r308 54 54 float &nearestT, 55 55 int &nearestFace, 56 MeshInstance *instance56 Intersectable *instance 57 57 ) 58 58 { … … 121 121 Ray &ray, 122 122 const vector<int> &faces, 123 MeshInstance *instance123 Intersectable *instance 124 124 ) 125 125 { -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h
r271 r308 107 107 CastRay( 108 108 Ray &ray, 109 MeshInstance *instance109 MeshInstance *instance 110 110 ); 111 111 … … 114 114 Ray &ray, 115 115 const vector<int> &faces, 116 MeshInstance *instance116 Intersectable *instance 117 117 ); 118 118 … … 123 123 float &nearestT, 124 124 int &nearestFace, 125 MeshInstance *instance125 Intersectable *instance 126 126 ); 127 127 -
trunk/VUT/GtpVisibilityPreprocessor/src/MeshKdTree.cpp
r245 r308 277 277 } 278 278 279 float oldCost = node->mFaces.size();279 float oldCost = (float)node->mFaces.size(); 280 280 float newCost = mCt_div_ci + minSum/boxArea; 281 281 float ratio = newCost/oldCost; -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r306 r308 2 2 #include "Mesh.h" 3 3 #include "ViewCellBsp.h" // TODO: erase this 4 #include " Intersectable.h"4 #include "Mesh.h" 5 5 #include "AxisAlignedBox3.h" 6 6 … … 16 16 {} 17 17 18 Polygon3::Polygon3( Intersectable *parent): mMaterial(NULL), mParent(parent)18 Polygon3::Polygon3(MeshInstance *parent): mMaterial(NULL), mParent(parent) 19 19 { 20 20 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r306 r308 24 24 Polygon3(); 25 25 Polygon3(const VertexContainer &vertices); 26 Polygon3( Intersectable *parent);26 Polygon3(MeshInstance *parent); 27 27 28 28 /** Copies all the vertices of the face. … … 81 81 Material *mMaterial; 82 82 83 /// pointer to the intersectable this polygon is derived from84 Intersectable *mParent;83 /// pointer to the mesh instance this polygon is derived from 84 MeshInstance *mParent; 85 85 }; 86 86 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r304 r308 16 16 Preprocessor::~Preprocessor() 17 17 { 18 CLEAR_CONTAINER(mViewCells); 19 DEL_PTR(mBspTree); 20 DEL_PTR(mKdTree); 21 DEL_PTR(mRootViewCell); 18 DeleteViewCells(); 19 20 DEL_PTR(mBspTree); 21 DEL_PTR(mKdTree); 22 DEL_PTR(mRootViewCell); 22 23 } 23 24 … … 26 27 { 27 28 return X3dParser().ParseFile(filename, mViewCells); 29 } 30 31 void Preprocessor::DeleteViewCells() 32 { 33 for (int i = 0; i < mViewCells.size(); ++ i) 34 delete mViewCells[i]->GetMesh(); 35 36 CLEAR_CONTAINER(mViewCells); 28 37 } 29 38 … … 90 99 DEL_PTR(mBspTree); 91 100 DEL_PTR(mRootViewCell); 92 mRootViewCell = new ViewCell( );101 mRootViewCell = new ViewCell(NULL); 93 102 mBspTree = new BspTree(mRootViewCell); 94 103 95 104 ObjectContainer objects; 96 105 RayContainer rays; 97 ViewCellContainer dummy; 106 98 107 switch (BspTree::sConstructionMethod) 99 108 { … … 102 111 break; 103 112 case BspTree::SCENE_GEOMETRY: 104 CLEAR_CONTAINER(mViewCells); // we generate new view cells113 DeleteViewCells(); // we generate new view cells 105 114 mSceneGraph->CollectObjects(&objects); 106 115 mBspTree->Construct(objects, &mViewCells); 107 116 break; 108 117 case BspTree::RAYS: 109 CLEAR_CONTAINER(mViewCells); // we generate new view cells118 DeleteViewCells(); // we generate new view cells 110 119 mBspTree->Construct(rays, &mViewCells); 111 120 break; -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
r297 r308 90 90 virtual void BspTreeStatistics(ostream &s); 91 91 92 void DeleteViewCells(); 93 92 94 /// scene graph loaded from file 93 95 SceneGraph *mSceneGraph; -
trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.cpp
r240 r308 2 2 using namespace std; 3 3 #include "Pvs.h" 4 #include "Intersectable.h" 4 5 5 6 KdPvsData * … … 87 88 data = (*i).second; 88 89 } 90 91 ViewCellPvsData *ViewCellPvs::Find(Intersectable *obj) 92 { 93 ViewCellPvsMap::iterator i = mEntries.find(obj); 94 95 if (i != mEntries.end()) 96 { 97 // cout<<node<<" "<<(*i).first<<" "<<(*i).second.mVisibleSamples<<endl; 98 return &(*i).second; 99 } 100 else 101 return NULL; 102 } 103 104 int ViewCellPvs::AddObject(Intersectable *obj) 105 { 106 int result; 107 108 ViewCellPvsData *data = Find(obj); 109 110 if (data) 111 { 112 data->mVisibleSamples ++; 113 result = 0; 114 } 115 else 116 { 117 mEntries[obj] = ViewCellPvsData(1); 118 result = 1; 119 } 120 121 return result; 122 } 123 124 void ViewCellPvs::GetData(const int index, Intersectable *&obj, ViewCellPvsData &data) 125 { 126 ViewCellPvsMap::iterator i = mEntries.begin(); 127 128 for (int k = 0; k!=index && i != mEntries.end(); i++, k++); 129 130 obj = (*i).first; 131 data = (*i).second; 132 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h
r265 r308 7 7 class BspNode; 8 8 class Ray; 9 class Intersectable; 9 10 10 11 struct LtKdNode … … 92 93 }; 93 94 95 96 struct LtIntersectable 97 { 98 bool operator()(const Intersectable *a, 99 const Intersectable *b) const 100 { 101 return a < b; 102 } 103 }; 104 105 struct ViewCellPvsData { 106 int mVisibleSamples; 107 ViewCellPvsData() {} 108 ViewCellPvsData(const int samples): mVisibleSamples(samples) {} 109 }; 110 111 typedef std::map<Intersectable *, ViewCellPvsData, LtIntersectable> ViewCellPvsMap; 112 113 class ViewCellPvs 114 { 115 public: 116 ViewCellPvs(): mEntries() {} 117 118 ViewCellPvsMap mEntries; 119 120 int Compress() {return 0;} 121 int GetSize() {return (int)mEntries.size();} 122 123 ViewCellPvsData *Find(Intersectable *obj); 124 int AddObject(Intersectable *obj); 125 126 void GetData(const int index, 127 Intersectable *&obj, 128 ViewCellPvsData &data); 129 130 }; 131 94 132 #endif 95 133 -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
r245 r308 11 11 class KdLeaf; 12 12 class MeshInstance; 13 13 class ViewCell; 14 14 15 15 // ------------------------------------------------------------------- … … 59 59 vector<KdLeaf *> leaves; 60 60 vector<MeshInstance *> meshes; 61 vector<ViewCell *> viewCells; 61 62 62 63 // constructors -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r257 r308 6 6 #include "MutualVisibility.h" 7 7 #include "Polygon3.h" 8 9 SamplingPreprocessor::SamplingPreprocessor() 8 #include "ViewCell.h" 9 10 SamplingPreprocessor::SamplingPreprocessor(): mPass(0) 10 11 { 11 12 // this should increase coherence of the samples … … 23 24 ray.leaves.clear(); 24 25 ray.meshes.clear(); 26 ray.viewCells.clear(); 27 25 28 // cout<<point<<" "<<direction<<endl; 26 29 ray.Init(point, direction, Ray::LOCAL_RAY); … … 57 60 58 61 62 int SamplingPreprocessor::AddObjectSamples(Intersectable *obj, const Ray &ray) 63 { 64 int contributingSamples = 0; 65 int j; 66 67 if (mPass > 10) 68 for (j=1; j < ray.viewCells.size() - 1; j++) 69 { 70 ray.viewCells[j]->AddPassingRay(ray, contributingSamples ? 1 : 0); 71 } 72 73 // add object to view cell 74 for (j=0; j < ray.viewCells.size(); j++) 75 { 76 ViewCell *vc = ray.viewCells[j]; 77 contributingSamples += vc->GetPvs().AddObject(obj); 78 } 79 80 return contributingSamples; 81 } 82 83 59 84 void 60 85 SamplingPreprocessor::HoleSamplingPass() … … 74 99 SamplingPreprocessor::CastRay(Intersectable *object, Ray &ray) 75 100 { 101 int sampleContributions = 0; 102 103 #ifndef TEST_BSP_VIEWCELLS 76 104 mKdTree->CastRay(ray); 77 int sampleContributions = 0;105 78 106 if (ray.leaves.size()) { 79 107 sampleContributions += AddNodeSamples(object, ray); … … 83 111 } 84 112 } 113 #else 114 mBspTree->CastRay(ray); 115 116 if (ray.viewCells.size() > 0) // view cell found 117 { 118 ++ sampleContributions; 119 120 // cast ray to KD tree to find intersections with other objects 121 mKdTree->CastRay(ray); 122 123 if (ray.intersections.size()) 124 { 125 sampleContributions += AddObjectSamples(ray.intersections[0].mObject, ray); 126 } 127 } 128 #endif 85 129 return sampleContributions; 86 130 } … … 190 234 int passSamples = 0; 191 235 int index = 0; 192 193 for (i =0; i < objects.size(); i++) { 236 Debug << "************************************" << endl; 237 Debug << "totalSamples: " << totalSamples << " (" << mTotalSamples << ")" << endl; 238 for (i = 0; i < objects.size(); i++) { 194 239 KdNode *nodeToSample = NULL; 195 240 Intersectable *object = objects[i]; 196 241 197 242 int pvsSize = object->mKdPvs.GetSize(); 198 199 200 243 201 244 if (0 && pvsSize) { … … 210 253 211 254 int maxTries = 2*pvsSize; 212 255 Debug << "Finding random neighbour" << endl; 213 256 for (int tries = 0; tries < 10; tries++) { 214 257 index = RandomValue(0, pvsSize - 1); … … 230 273 node->Mail(); 231 274 } 232 275 Debug << "Get all neighbours from PVS" << endl; 233 276 vector<KdNode *> invisibleNeighbors; 234 277 // get all neighbors of all PVS nodes … … 251 294 } 252 295 253 296 254 297 object->GetRandomSurfacePoint(point, normal); 255 298 bool viewcellSample = true; … … 278 321 279 322 // construct a ray 323 280 324 SetupRay(ray, point, direction); 281 325 sampleContributions = CastRay(object, ray); … … 310 354 } 311 355 312 313 314 356 totalSamples += passSamples; 315 357 … … 319 361 320 362 mPass++; 321 363 322 364 int pvsSize = 0; 365 #ifdef TEST_BSP_VIEWCELLS 366 for (i=0; i < mViewCells.size(); i++) { 367 ViewCell *vc = mViewCells[i]; 368 pvsSize += vc->GetPvs().GetSize(); 369 } 370 Debug << "pvs size: " << pvsSize << endl; 371 #else 323 372 for (i=0; i < objects.size(); i++) { 324 373 Intersectable *object = objects[i]; 325 374 pvsSize += object->mKdPvs.GetSize(); 326 375 } 327 376 #endif 328 377 cout << "#Pass " << mPass<<" : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 329 378 cout << "#TotalSamples=" << totalSamples/1000 … … 343 392 "#AvgRayContrib\n" << passSampleContributions/(float)passContributingSamples << endl; 344 393 } 345 394 Debug << "Collecting leaf pvs" << endl; 346 395 int totalPvsSize = mKdTree->CollectLeafPvs(); 347 396 cout << "#totalPvsSize=" << totalPvsSize << endl; -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
r256 r308 51 51 ); 52 52 53 /** Adds objects samples to view cells. 54 */ 55 int AddObjectSamples(Intersectable *obj, const Ray &ray); 53 56 }; 54 57 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r265 r308 1 1 #include "ViewCell.h" 2 2 #include "Mesh.h" 3 #include "Intersectable.h" 3 4 #include "MeshKdTree.h" 4 5 #include "Triangle3.h" 5 6 6 ViewCell::ViewCell(): mMesh(NULL)7 ViewCell::ViewCell(): MeshInstance(NULL) 7 8 { 8 9 } 9 10 10 ViewCell::ViewCell(Mesh *mesh): mMesh(mesh), mPvs(NULL)11 ViewCell::ViewCell(Mesh *mesh): MeshInstance(mesh) 11 12 { 12 13 } 13 14 14 ViewCell::~ViewCell() 15 { 16 // NOTE: should I really do this here? (I know that there is only one mesh per view cell) 17 DEL_PTR(mMesh); 18 } 19 20 Mesh *ViewCell::GetMesh() 21 { 22 return mMesh; 23 } 24 25 BspPvs *ViewCell::GetPVS() 15 ViewCellPvs &ViewCell::GetPvs() 26 16 { 27 17 return mPvs; 28 18 } 29 19 30 AxisAlignedBox3 ViewCell::GetBox()31 {32 return mMesh->mBox;33 }34 35 int ViewCell::CastRay(Ray &ray)36 {37 return 0;38 }39 40 bool ViewCell::IsConvex()41 {42 return mMesh->mIsConvex;43 }44 45 bool ViewCell::IsWatertight()46 {47 return mMesh->mIsWatertight;48 }49 50 float ViewCell::IntersectionComplexity()51 {52 return (float)mMesh->mFaces.size();53 }54 55 20 int ViewCell::Type() const 56 21 { 57 return VIEWCELL; 58 } 59 60 void ViewCell::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) 61 { 62 point = Vector3(0,0,0); 22 return VIEW_CELL; 63 23 } 64 24 … … 122 82 return new ViewCell(mesh); 123 83 } 84 85 void ViewCell::AddPassingRay(const Ray &ray, const int contributions) 86 { 87 mPassingRays.AddRay(ray, contributions); 88 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r268 r308 2 2 #define _ViewCell_H__ 3 3 4 #include " Intersectable.h"4 #include "Mesh.h" 5 5 #include "Containers.h" 6 7 class Mesh; 6 #include "Ray.h" 8 7 9 8 //namespace GtpVisibilityPreprocessor { … … 12 11 class BspPvs; 13 12 struct Triangle3; 13 14 14 /** 15 View cell represented as a mesh15 View cell with an optional mesh representation 16 16 */ 17 class ViewCell: public Intersectable17 class ViewCell: public MeshInstance 18 18 { 19 19 public: 20 20 ViewCell(); 21 /** Default constructor taking a mesh which represents the shape of 22 the viewcell. 21 /** Constructor taking a mesh representing the shape of the viewcell. 23 22 */ 24 23 ViewCell(Mesh *mesh); 25 26 /** Returns pointer to the mesh which represents the shape of the viewcell. 24 /** Returns PvS. 27 25 */ 28 Mesh *GetMesh(); 29 30 /** Returns pointer to PVS. 31 @returns PVS, i.e., the visible BSP tree nodes. 32 */ 33 BspPvs *GetPVS(); 34 35 AxisAlignedBox3 GetBox(); 36 37 int CastRay(Ray &ray); 38 39 bool IsConvex(); 40 bool IsWatertight(); 41 float IntersectionComplexity(); 26 ViewCellPvs &GetPvs(); 42 27 43 28 int Type() const; 44 45 void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);46 29 47 30 /** Derives viewcells from object container. … … 60 43 static ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height); 61 44 45 void AddPassingRay(const Ray &ray, const int contributions); 46 62 47 protected: 63 48 64 /// the mesh defining the geometry of this viewcell 65 Mesh *mMesh; 66 /// the PVS (i.e., the visible bsp tree nodes) 67 BspPvs *mPvs; 49 /// the potentially visible objects 50 ViewCellPvs mPvs; 68 51 52 /** Ray set description of the rays passing through this node */ 53 PassingRaySet mPassingRays; 69 54 }; 70 55 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r307 r308 424 424 interior->ProcessPolygons(&coincident, mStoreSplitPolys); 425 425 426 //Debug << "split node on level " << tData.mDepth << " bk: " << backPolys->size() << " frnt: " << frontPolys->size() << endl;427 426 mStat.splits += splits; 428 427 … … 437 436 else // reached leaf => subdivide current viewcell 438 437 { 439 //if (tData.mPolygons->size() > 0) 440 // Debug << "Subdividing further: polygon size: " << (int)tData.mPolygons->size() << ", view cell: " << tData.mViewCell << endl; 441 442 BspNode *root = Subdivide(tStack, tData, viewCells); 443 438 //if (tData.mPolygons->size() > 0) Debug << "Subdividing further: polygon size: " << (int)tData.mPolygons->size() << ", view cell: " << tData.mViewCell << endl; 439 BspNode *root = Subdivide(tStack, tData); 440 441 if (viewCells && root->IsLeaf()) 442 { // generate new view cell for each leaf 443 ViewCell *viewCell = new ViewCell(); 444 viewCells->push_back(viewCell); 445 446 dynamic_cast<BspLeaf *>(root)->SetViewCell(viewCell); 447 } 444 448 if (!mRoot) // tree empty => new root 445 449 mRoot = root; … … 448 452 } 449 453 450 int BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent)454 int BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent) 451 455 { 452 456 FaceContainer::const_iterator fi; … … 498 502 mesh = dynamic_cast<MeshInstance *>(object)->GetMesh(); 499 503 break; 500 case Intersectable::VIEW CELL:504 case Intersectable::VIEW_CELL: 501 505 mesh = dynamic_cast<ViewCell *>(object)->GetMesh(); 502 506 break; … … 586 590 587 591 // subdivide leaf node 588 BspNode *root = Subdivide(tStack, tData, viewCells); 592 BspNode *root = Subdivide(tStack, tData); 593 594 if (viewCells && root->IsLeaf()) 595 { // generate new view cell for each leaf 596 ViewCell *viewCell = new ViewCell(); 597 viewCells->push_back(viewCell); 598 599 dynamic_cast<BspLeaf *>(root)->SetViewCell(viewCell); 600 } 589 601 590 602 // empty tree => new root corresponding to unbounded space … … 598 610 599 611 600 BspNode *BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, 601 ViewCellContainer *viewCells) 612 BspNode *BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData) 602 613 { 603 614 //-- terminate traversal … … 605 616 { 606 617 #ifdef _DEBUG 607 Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: " << (int)tData.mPolygons->size() << endl; 618 Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: " 619 << (int)tData.mPolygons->size() << endl; 608 620 #endif 609 621 … … 611 623 612 624 BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 613 614 //-- new viewcells are generated and added to each leaf 615 if (viewCells) 616 { 617 ViewCell *viewCell = new ViewCell(); 618 leaf->SetViewCell(viewCell); 619 viewCells->push_back(viewCell); 620 // Debug << "creating new viewcell" << endl; 621 } 622 //-- add viewcell stored in split polygon 623 else if (!leaf->GetViewCell()) 625 626 // add view cell to leaf 627 if (!leaf->GetViewCell()) 624 628 leaf->SetViewCell(tData.mViewCell); 625 //else Debug << "Leaf already has view cell " << endl;626 629 627 630 // remaining polygons are discarded or added to node 628 tData.mNode->ProcessPolygons(tData.mPolygons, mStoreSplitPolys);631 leaf->ProcessPolygons(tData.mPolygons, mStoreSplitPolys); 629 632 DEL_PTR(tData.mPolygons); 630 633 631 return tData.mNode;634 return leaf; 632 635 } 633 636 … … 644 647 &coincident); 645 648 646 //-- extract view cells from coincident polygons according to plane normal647 649 ViewCell *frontViewCell = mViewCell; 648 650 ViewCell *backViewCell = mViewCell; 649 650 if (!viewCells) 651 { // extract the pointer to the view cells 652 ExtractViewCells(&backViewCell, 653 &frontViewCell, 654 coincident, 655 interior->mPlane, 656 frontPolys->empty(), 657 backPolys->empty()); 658 } 651 652 #ifdef _DEBUG 653 if (frontPolys->empty() && backPolys->empty() && (coincident.size() > 2)) 654 { for (PolygonContainer::iterator it = coincident.begin(); it != coincident.end(); ++it) 655 Debug << (*it) << " " << (*it)->GetArea() << " " << (*it)->mParent << endl ; 656 Debug << endl;} 657 #endif 658 659 //-- extract view cells from coincident polygons according to plane normal 660 ExtractViewCells(&backViewCell, &frontViewCell, coincident, interior->mPlane, 661 frontPolys->empty(), backPolys->empty()); 659 662 660 663 // don't need coincident polygons anymore … … 684 687 PolygonContainer::const_iterator it, it_end = coincident.end(); 685 688 689 //-- find first view cells in front and back leafs 686 690 for (it = coincident.begin(); !(foundFront && foundBack) && 687 (it < coincident.end()); ++it)691 (it != it_end); ++ it) 688 692 { 689 693 if (DotProd((*it)->GetSupportingPlane().mNormal, splitPlane.mNormal > 0)) … … 996 1000 if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 997 1001 { 998 Intersectable *viewCell = (*it)->mParent;1002 MeshInstance *viewCell = (*it)->mParent; 999 1003 1000 1004 if (classification == Polygon3::FRONT_SIDE) … … 1011 1015 val += sLeastSplitsFactor * sumSplits / (float)polys.size(); 1012 1016 1013 if ( (sSplitPlaneStrategy & LARGEST_POLY_AREA) && sumPolyArea)1017 if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 1014 1018 val += sLargestPolyAreaFactor * (float)polys.size() / sumPolyArea; // HACK 1015 1019 … … 1022 1026 ObjectContainer::const_iterator frontIt, frontIt_end = frontViewCells.end(); 1023 1027 1024 Intersectable * intersect= NULL;1028 Intersectable *vc = NULL; 1025 1029 // increase counter for view cells in front of plane 1026 1030 for (frontIt = frontViewCells.begin(); frontIt != frontIt_end; ++frontIt) 1027 1031 { 1028 if (*frontIt != intersect)1032 if (*frontIt != vc) 1029 1033 { 1030 intersect= *frontIt;1034 vc = *frontIt; 1031 1035 sumBalancedViewCells += 1.0f; 1032 1036 } … … 1034 1038 1035 1039 ObjectContainer::const_iterator backIt, backIt_end = backViewCells.end(); 1036 intersect= NULL;1040 vc = NULL; 1037 1041 // decrease counter for view cells on back side of plane 1038 1042 for (backIt = backViewCells.begin(); backIt != backIt_end; ++backIt) 1039 1043 { 1040 if (*backIt != intersect)1044 if (*backIt != vc) 1041 1045 { 1042 intersect= *backIt;1046 vc = *backIt; 1043 1047 sumBalancedViewCells -= 1.0f; 1044 1048 } … … 1136 1140 } 1137 1141 1138 int BspTree::CollectLeafPvs()1139 {1140 int totalPvsSize = 0;1141 1142 stack<BspNode *> nodeStack;1143 1144 nodeStack.push(mRoot);1145 1146 while (!nodeStack.empty())1147 {1148 BspNode *node = nodeStack.top();1149 1150 nodeStack.pop();1151 1152 if (node->IsLeaf())1153 {1154 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);1155 1156 ViewCell *viewcell = leaf->GetViewCell();1157 1158 if (!viewcell->Mailed())1159 {1160 viewcell->Mail(); // what does mail mean?1161 1162 // add this node to pvs of all nodes it can see1163 BspPvsMap::iterator ni;1164 1165 /* for (ni = object->mBspPvs.mEntries.begin(); ni != object->mKdPvs.mEntries.end(); ni++)1166 {1167 BspNode *node = (*ni).first;1168 1169 // $$ JB TEMPORARY solution -> should add object PVS or explictly computed1170 // BSP tree PVS1171 if (leaf->mBspPvs.AddNodeSample(node))1172 totalPvsSize++;1173 }*/1174 }1175 } else1176 {1177 // traverse tree1178 BspInterior *interior = (BspInterior *)node;1179 1180 nodeStack.push(interior->GetFront());1181 nodeStack.push(interior->GetBack());1182 }1183 }1184 1185 return totalPvsSize;1186 }1187 1188 1142 AxisAlignedBox3 BspTree::GetBoundingBox() const 1189 1143 { … … 1303 1257 extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 1304 1258 1305 } else // compute intersections with objects in leaf1259 } else // reached leaf => intersection with view cell 1306 1260 { 1307 1261 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 1308 //ray.leaves.push_back(leaf);1309 // TODO 1310 /*ObjectContainer::const_iterator mi; 1311 for (mi = leaf->mObjects.begin(); mi != leaf->mObjects.end(); ++mi)1262 1263 //ray.mBspLeaves.push_back(leaf); 1264 1265 if (!leaf->mViewCell->Mailed()) 1312 1266 { 1313 Intersectable *object = *mi; 1314 if (!object->Mailed()) 1315 { 1316 object->Mail(); 1317 //ray.meshes.push_back(mesh); 1318 hits += object->CastRay(ray); 1319 } 1320 }*/ 1321 1322 if (hits && ray.GetType() == Ray::LOCAL_RAY) 1267 ray.viewCells.push_back(leaf->mViewCell); 1268 mViewCell->Mail(); 1269 ++ hits; 1270 } 1271 1272 if (hits && ray.GetType() == Ray::LOCAL_RAY) 1323 1273 if (ray.intersections[0].mT <= maxt) 1324 1274 break; … … 1355 1305 return false; 1356 1306 } 1307 1308 void BspTree::CollectViewCells(BspNode *n, ViewCellContainer &viewCells) 1309 { 1310 stack<BspNode *> nodeStack; 1311 1312 nodeStack.push(n); 1313 1314 while (!nodeStack.empty()) 1315 { 1316 BspNode *node = nodeStack.top(); 1317 nodeStack.pop(); 1318 1319 if (node->IsLeaf()) 1320 { 1321 ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->mViewCell; 1322 1323 if (!viewCell->Mailed()) 1324 { 1325 viewCell->Mail(); 1326 viewCells.push_back(viewCell); 1327 } 1328 } 1329 else 1330 { 1331 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1332 nodeStack.push(interior->mFront); 1333 nodeStack.push(interior->mBack); 1334 } 1335 } 1336 } 1357 1337 //} // GtpVisibilityPreprocessor -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r306 r308 327 327 bool Export(const string filename); 328 328 329 void CollectViewCells(BspNode *n, ViewCellContainer &viewCells); 330 331 /** A ray is cast possible intersecting the tree. 332 @param the ray that is cast. 333 @returns the number of intersections with objects stored in the tree. 334 */ 335 int CastRay(Ray &ray); 336 329 337 //static bool displayDebug; 330 338 protected: … … 368 376 @param tStack current traversal stack 369 377 @param tData traversal data also holding node to be subdivided 370 @param viewCellContainer if not null, a new viewcell is created and stored in the container371 378 @returns new root of the subtree 372 379 */ 373 BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData , ViewCellContainer *viewCells = NULL);380 BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData); 374 381 375 382 /** Selects a splitting plane. … … 436 443 @returns number of polygons 437 444 */ 438 int AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent); 439 440 /** A ray is cast possible intersecting the tree. 441 @param the ray that is cast. 442 @returns the number of intersections with objects stored in the tree. 443 */ 444 int CastRay(Ray &ray); 445 int AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent); 445 446 446 447 /** returns next candidate index and reorders polygons so no candidate is chosen two times -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r292 r308 102 102 ExportMeshInstance((MeshInstance *)object); 103 103 break; 104 case Intersectable::VIEW CELL:104 case Intersectable::VIEW_CELL: 105 105 ExportViewCell((ViewCell *)object); 106 106 break;
Note: See TracChangeset
for help on using the changeset viewer.