Changeset 235
- Timestamp:
- 08/12/05 01:17:56 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 5 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/include/ViewCellBsp.h
r225 r235 69 69 { 70 70 public: 71 /** Constructor takes a pointer to the cell corresponding to the whole72 viewspace*/73 BspTree( ViewCell *cell);71 /** Default constructor. 72 */ 73 BspTree(); 74 74 75 75 protected: 76 76 77 /// Pointer to the root of the tree 77 78 BspNode *mRoot; -
trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj
r234 r235 63 63 Name="VCCLCompilerTool" 64 64 AdditionalIncludeDirectories="..\support;..\support\devil\include;..\support\zlib\include;"$(QTDIR)\include";"$(QTDIR)\include\Qt";..\include" 65 PreprocessorDefinitions="WIN32;NDEBUG;_LIB; DEST_BSP_VIEWCELLS"65 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;TEST_BSP_VIEWCELLS" 66 66 RuntimeLibrary="2" 67 67 RuntimeTypeInfo="TRUE" … … 199 199 </File> 200 200 <File 201 RelativePath="..\src\Polygon3.cpp"> 202 </File> 203 <File 204 RelativePath="..\src\Polygon3.h"> 205 </File> 206 <File 201 207 RelativePath="..\src\Preprocessor.cpp"> 202 208 </File> … … 251 257 <File 252 258 RelativePath="..\src\Vector3.h"> 259 </File> 260 <File 261 RelativePath="..\src\ViewCell.cpp"> 253 262 </File> 254 263 <File … … 303 312 </File> 304 313 <File 314 RelativePath="..\include\Polygon3.h"> 315 </File> 316 <File 305 317 RelativePath="..\include\Preprocessor.h"> 306 318 </File> -
trunk/VUT/GtpVisibilityPreprocessor/src/Containers.h
r176 r235 3 3 4 4 #include <vector> 5 #include <queue> 6 5 7 using namespace std; 6 8 … … 9 11 class SceneGraphNode; 10 12 class Intersectable; 13 class Polygon3; 14 11 15 12 16 /** Container for Mesh pointers primarily for the use within the kDTree and … … 18 22 19 23 typedef vector<ViewCell *> ViewCellContainer; 24 25 /** Container for ViewCell pointers primarily for the use within the kDTree and 26 BSP hierarchies */ 27 //typedef vector<MeshInstance *> MeshInstanceContainer; 28 20 29 /** Container for HierarchyNodes pointers primarily for the use within the kDTree and 21 30 BSP hierarchies */ 22 31 23 32 typedef vector<HierarchyNode *> NodeContainer; 33 34 /** Queue storing a soup of polygons used during BSP tree construction 35 */ 36 typedef queue<Polygon3 *> PolygonQueue; 37 38 24 39 25 40 typedef vector<SceneGraphNode *> SceneGraphNodeContainer; -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r177 r235 1151 1151 "10"); 1152 1152 1153 1153 RegisterOption("BspTree.Termination.maxPolygons", 1154 optInt, 1155 "-bsp_term_max_polygons=", 1156 "5"); 1157 1158 RegisterOption("BspTree.Termination.maxDepth", 1159 optInt, 1160 "-bsp_term_max_depth=", 1161 "100"); 1162 1163 RegisterOption("BspTree.splitPlaneStrategy", 1164 optString, 1165 "-bsp_split_method=", 1166 "leastSplits"); 1167 1168 RegisterOption("BspTree.constructionMethod", 1169 optString, 1170 "-bsp_construction_method=", 1171 "viewCells"); 1154 1172 } 1155 1173 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r234 r235 4 4 #include "X3dParser.h" 5 5 #include "Preprocessor.h" 6 7 6 #include "ViewCell.h" 7 #include "Environment.h" 8 8 9 9 … … 18 18 Preprocessor::GenerateViewcells() 19 19 { 20 ObjectContainer objects; 21 mSceneGraph->CollectObjects(&objects); 22 //mBspTree = new BspTree(objects); 23 24 return true; 20 return BuildBspTree(); 25 21 } 26 22 … … 66 62 Preprocessor::BuildBspTree() 67 63 { 68 69 return true; 64 ObjectContainer objects; 65 mSceneGraph->CollectObjects(&objects); 66 67 mBspTree = new BspTree(); 68 69 char constructionMethodStr[64]; 70 71 environment->GetStringValue("BspTree.constructionMethod", 72 constructionMethodStr); 73 74 int constructionMethod = BspTree::VIEWCELLS; 75 76 if (strcmp(constructionMethodStr, "viewCells") == 0) 77 constructionMethod = BspTree::VIEWCELLS; 78 else if (strcmp(constructionMethodStr, "sceneGeometry") == 0) 79 constructionMethod = BspTree::SCENE_GEOMETRY; 80 else 81 { 82 cerr << "Wrong bsp construction method " << constructionMethodStr << endl; 83 exit(1); 84 } 85 86 Debug << constructionMethodStr << endl; 87 88 switch (constructionMethod) 89 { 90 case BspTree::VIEWCELLS: 91 mViewcells.clear(); 92 // derive viewcells from the scene objects 93 ViewCell::DeriveViewCells(objects, mViewcells, 1000); 94 mBspTree->Construct(mViewcells); 95 break; 96 case BspTree::SCENE_GEOMETRY: 97 mBspTree->Construct(objects); 98 break; 99 default: 100 break; 101 } 102 return true; 70 103 } 71 104 … … 81 114 Preprocessor::BspTreeStatistics(ostream &s) 82 115 { 83 // s<<mBspTree->GetStatistics();116 s << mBspTree->GetStatistics(); 84 117 } 85 118 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
r234 r235 98 98 99 99 BspTree * mBspTree; 100 101 100 }; 102 101 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r224 r235 3 3 4 4 #include "Intersectable.h" 5 #include "Containers.h" 5 6 6 7 class Mesh; … … 19 20 the viewcell. 20 21 */ 21 ViewCell(Mesh *mesh) : mMesh(mesh), mPvs(NULL) {}22 ViewCell(Mesh *mesh); 22 23 23 24 /** Returns pointer to the mesh which represents the shape of the viewcell. 24 25 */ 25 Mesh *GetMesh() {return mMesh;}26 Mesh *GetMesh(); 26 27 27 28 /** Returns pointer to PVS. 28 29 @returns PVS, i.e., the visible BSP tree nodes. 29 30 */ 30 BspPvs *GetPVS() {return mPvs;}31 BspPvs *GetPVS(); 31 32 32 AxisAlignedBox3 GetBox() {return mMesh->mBox;}33 AxisAlignedBox3 GetBox(); 33 34 34 int CastRay(Ray &ray) {return 0;}35 int CastRay(Ray &ray); 35 36 36 bool IsConvex() {return mMesh->mIsConvex;}37 bool IsWatertight() {return mMesh->mIsWatertight;}38 float IntersectionComplexity() {return mMesh->mFaces.size();}37 bool IsConvex(); 38 bool IsWatertight(); 39 float IntersectionComplexity(); 39 40 40 int Type() const { return VIEWCELL; }41 int Type() const; 41 42 42 void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) {point = Vector3(0,0,0);};43 void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 43 44 45 /** Derives viewcells from object container. 46 @param objects the intersectables the viewcells are derived from 47 @param viewCells the viewcells are returned in this container 48 @param if >0, indicates the maximim number of viewcells that will be created 49 */ 50 static void DeriveViewCells(const ObjectContainer &objects, 51 ViewCellContainer &viewCells, 52 const int max); 44 53 protected: 45 54 55 /// the mesh defining the geometry of this viewcell 46 56 Mesh *mMesh; 47 57 /// the PVS (i.e., the visible bsp tree nodes) -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r234 r235 2 2 #include "ViewCellBsp.h" 3 3 #include "Mesh.h" 4 4 #include "common.h" 5 5 #include "ViewCell.h" 6 6 #include <stack> 7 8 #define DEL_PTR(ptr) while (0) {if (ptr) {delete (ptr); (ptr) = NULL;}} 7 #include "Environment.h" 8 #include "Polygon3.h" 9 10 int BspTree::sTermMaxPolygons = 10; 11 int BspTree::sTermMaxDepth = 20; 9 12 10 13 //namespace GtpVisibilityPreprocessor { 14 15 11 16 /****************************************************************/ 12 17 /* class BspNode implementation */ 13 18 /****************************************************************/ 19 20 BspNode::BspNode(): mParent(NULL) 21 {} 22 23 BspNode::BspNode(BspInterior *parent): mParent(parent) 24 {} 25 26 14 27 bool BspNode::IsRoot() const 15 28 { … … 21 34 return mParent; 22 35 } 36 37 void BspNode::SetParent(BspInterior *parent) 38 { 39 mParent = parent; 40 } 41 23 42 /****************************************************************/ 24 43 /* class BspInterior implementation */ … … 67 86 } 68 87 69 void BspInterior::SplitPolygons(PolygonQueue *polys, PolygonQueue *frontPolys, PolygonQueue *backPolys) 88 void BspInterior::SplitPolygons(PolygonQueue *polys, 89 PolygonQueue *frontPolys, 90 PolygonQueue *backPolys, 91 int &splits) 70 92 { 71 93 while (!polys->empty()) 72 94 { 73 Polygon *poly = polys->front();95 Polygon3 *poly = polys->front(); 74 96 75 97 polys->pop(); … … 77 99 int result = poly->Side(&mPlane); 78 100 79 Polygon *front_piece = NULL;80 Polygon *back_piece = NULL;101 Polygon3 *front_piece = NULL; 102 Polygon3 *back_piece = NULL; 81 103 82 104 switch (result) 83 105 { 84 case Polygon ::COINCIDENT:106 case Polygon3::COINCIDENT: 85 107 break; 86 case Polygon ::FRONT_SIDE:108 case Polygon3::FRONT_SIDE: 87 109 frontPolys->push(poly); 88 110 break; 89 case Polygon ::BACK_SIDE:111 case Polygon3::BACK_SIDE: 90 112 backPolys->push(poly); 91 113 break; 92 case Polygon ::SPLIT:93 front_piece = new Polygon ();94 back_piece = new Polygon ();114 case Polygon3::SPLIT: 115 front_piece = new Polygon3(); 116 back_piece = new Polygon3(); 95 117 96 118 //-- split polygon 97 poly->Split(&mPlane, front_piece, back_piece);98 119 poly->Split(&mPlane, front_piece, back_piece, splits); 120 99 121 backPolys->push(back_piece); 100 122 frontPolys->push(front_piece); … … 108 130 } 109 131 // delete old polygons 110 Polygon::DeletePolygons(polys);132 // Polygon3::DeletePolygons(polys); 111 133 } 112 134 … … 129 151 } 130 152 131 /****************************************************************/132 /* class Polygon implementation */133 /****************************************************************/134 135 Polygon::Polygon()136 {}137 138 Polygon::Polygon(const VertexContainer &vertices): mVertices(vertices)139 {}140 141 Polygon::Polygon(Face *face, Mesh *parent)142 {143 VertexIndexContainer::const_iterator it;144 145 for (it = face->mVertexIndices.begin(); it != face->mVertexIndices.end(); ++ it)146 {147 mVertices.push_back(parent->mVertices[*it]);148 }149 }150 151 Plane3 Polygon::GetSupportingPlane()152 {153 return Plane3(mVertices[0], mVertices[1], mVertices[2]);154 }155 156 void Polygon::DeletePolygons(PolygonQueue *polys)157 {158 // don't need to store polygon information = delete polygons159 while(!polys->empty())160 {161 Polygon *poly = polys->front();162 polys->pop();163 DEL_PTR(poly);164 }165 }166 167 void Polygon::Split(Plane3 *partition, Polygon *front, Polygon *back)168 {169 Vector3 ptA = mVertices[mVertices.size() - 1];;170 171 int sideA = partition->Side(ptA);172 173 VertexContainer::const_iterator it;174 175 // find line - plane intersections176 for (it = mVertices.begin(); it != mVertices.end(); ++ it)177 {178 Vector3 ptB = (*it);179 int sideB = partition->Side(ptB);180 181 // vertices on different sides => split182 if ((sideA != 0) && (sideB != 0) && (sideA != sideB))183 {184 Vector3 v = ptB - ptA; // line from A to B185 float dv = DotProd(partition->mNormal, v);186 float t = 0;187 188 if (dv)189 {190 t = - partition->Distance(ptA) / dv;191 }192 }193 if (sideB >= 0)194 {195 back->mVertices.push_back(ptB);196 }197 else if (sideB <= 0)198 {199 front->mVertices.push_back(ptB);200 }201 202 ptA = ptB;203 sideA = sideB;204 }205 }206 207 int Polygon::Side(Plane3 *plane)208 {209 VertexContainer::const_iterator it;210 211 bool onFrontSide = false;212 bool onBackSide = false;213 214 // find line - plane intersections215 for (it = mVertices.begin(); it != mVertices.end(); ++ it)216 {217 int side = plane->Side(*it);218 219 if (side > 0)220 {221 onFrontSide = true;222 }223 else if (side < 0)224 {225 onBackSide = true;226 }227 228 if (onFrontSide && onBackSide) // splits229 return SPLIT;230 }231 232 if (onBackSide)233 {234 return BACK_SIDE;235 }236 else if (onFrontSide)237 {238 return FRONT_SIDE;239 }240 241 return COINCIDENT;242 }243 153 244 154 /****************************************************************/ … … 246 156 /****************************************************************/ 247 157 248 BspTree::BspTree(const ViewCellContainer &viewCells): 249 mMaxPolys(0), mMaxDepth(999999), mRoot(NULL) // null => until we stripped all polygons 250 { 251 //mRootCell = cell; 252 Subdivide(viewCells); 253 } 254 255 BspTree::BspTree(const ObjectContainer &objects, int maxPolys, int maxDepth): 256 mMaxPolys(maxPolys), mMaxDepth(maxDepth) 158 BspTree::BspTree(): mTermMaxPolygons(0), mTermMaxDepth(0) 257 159 { 258 160 mRoot = new BspLeaf(); 259 260 Subdivide(objects);261 161 } 262 162 163 const BspTreeStatistics &BspTree::GetStatistics() const 164 { 165 return mStat; 166 } 167 168 void BspTreeStatistics::Print(ostream &app) const 169 { 170 app << "===== BspTree statistics ===============\n"; 171 172 app << "#N_RAYS Number of rays )\n" 173 << rays <<endl; 174 app << "#N_DOMAINS ( Number of query domains )\n" 175 << queryDomains <<endl; 176 177 app << "#N_NODES ( Number of nodes )\n" << nodes << "\n"; 178 179 app << "#N_LEAVES ( Number of leaves )\n" << Leaves() << "\n"; 180 181 app << "#N_SPLITS ( Number of splits)\n" << splits << "\n"; 182 183 app << "#N_RAYREFS ( Number of rayRefs )\n" << 184 rayRefs << "\n"; 185 186 app << "#N_RAYRAYREFS ( Number of rayRefs / ray )\n" << 187 rayRefs/(double)rays << "\n"; 188 189 app << "#N_LEAFRAYREFS ( Number of rayRefs / leaf )\n" << 190 rayRefs/(double)Leaves() << "\n"; 191 192 app << "#N_MAXOBJECTREFS ( Max number of rayRefs / leaf )\n" << 193 maxObjectRefs << "\n"; 194 195 app << "#N_NONEMPTYRAYREFS ( Number of rayRefs in nonEmpty leaves / non empty leaf )\n" << 196 rayRefsNonZeroQuery/(double)(Leaves() - zeroQueryNodes) << "\n"; 197 198 app << "#N_LEAFDOMAINREFS ( Number of query domain Refs / leaf )\n" << 199 objectRefs/(double)Leaves() << "\n"; 200 201 // app << setprecision(4); 202 203 app << "#N_PEMPTYLEAVES ( Percentage of leaves with zero query domains )\n"<< 204 zeroQueryNodes*100/(double)Leaves()<<endl; 205 206 app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maxdepth )\n"<< 207 maxDepthNodes*100/(double)Leaves()<<endl; 208 209 app << "#N_PMAXDEPTH ( Maximal reached depth )\n"<< 210 maxDepth*100/(double)Leaves()<<endl; 211 212 app << "#N_ADDED_RAYREFS (Number of dynamically added ray references )\n"<< 213 addedRayRefs<<endl; 214 215 app << "#N_REMOVED_RAYREFS (Number of dynamically removed ray references )\n"<< 216 removedRayRefs<<endl; 217 218 // app << setprecision(4); 219 220 // app << "#N_CTIME ( Construction time [s] )\n" 221 // << Time() << " \n"; 222 223 app << "===== END OF BspTree statistics ==========\n"; 224 } 225 263 226 BspTree::~BspTree() 264 227 { … … 296 259 PolygonQueue polys; 297 260 // copy polygon information to guide the split process 298 CopyMesh2Polygon (viewCell->GetMesh(), polys);261 CopyMesh2Polygons(viewCell->GetMesh(), polys); 299 262 300 263 tStack.push(BspTraversalData(mRoot, NULL, &polys, 0)); … … 315 278 PolygonQueue *backPolys = new PolygonQueue(); 316 279 317 interior->SplitPolygons(tData.mPolys, frontPolys, backPolys); 280 int splits = 0; 281 interior->SplitPolygons(tData.mPolygons, frontPolys, backPolys, splits); 282 mStat.splits += splits; 318 283 319 284 // push the children on the stack 320 285 if (frontPolys->size() > 0) // if polygons on this side of bsp tree 321 tStack.push(BspTraversalData(interior->GetFront(), interior->GetParent(), frontPolys, tData.mDepth + 1)); 286 tStack.push(BspTraversalData(interior->GetFront(), interior->GetParent(), 287 frontPolys, tData.mDepth + 1)); 322 288 else 323 289 delete frontPolys; 324 290 325 291 if (backPolys > 0) // if polygons on this side of bsp tree 326 tStack.push(BspTraversalData(interior->GetBack(), interior->GetParent(), backPolys, tData.mDepth + 1)); 292 tStack.push(BspTraversalData(interior->GetBack(), interior->GetParent(), 293 backPolys, tData.mDepth + 1)); 327 294 else 328 295 delete backPolys; 329 296 } 330 else // reached leaf and must split297 else // reached leaf => subdivide 331 298 { 332 BuildTree(tStack, tData, NULL);299 Subdivide(tStack, tData, NULL); 333 300 } 334 301 } 335 302 } 336 303 337 void BspTree::Subdivide(const ViewCellContainer &viewCells) 338 { 339 } 340 341 void BspTree::CopyMesh2Polygon(Mesh *mesh, PolygonQueue &polys) 304 void BspTree::Construct(const ViewCellContainer &viewCells) 305 { 306 // for this type of construction we split until no polygons is left 307 mTermMaxPolygons = 0; 308 mTermMaxDepth = sTermMaxDepth; 309 310 mStat.nodes = 1; 311 312 // insert all viewcells 313 ViewCellContainer::const_iterator it; 314 315 for (it = viewCells.begin(); it != viewCells.end(); ++ it) 316 { 317 InsertViewCell(*it); 318 } 319 } 320 321 void BspTree::CopyMesh2Polygons(Mesh *mesh, PolygonQueue &polys) 342 322 { 343 323 FaceContainer::const_iterator fi; 324 344 325 // copy the face data to polygons 345 326 for (fi = mesh->mFaces.begin(); fi != mesh->mFaces.end(); ++ fi) 346 327 { 347 Polygon *poly = new Polygon((*fi), mesh);328 Polygon3 *poly = new Polygon3((*fi), mesh); 348 329 polys.push(poly); 349 330 } … … 357 338 { 358 339 Intersectable *object = *it; 359 360 // extract the mesh instances 361 if (object->Type() == Intersectable::MESH_INSTANCE) 340 Mesh *mesh = NULL; 341 342 // extract the meshes 343 switch (object->Type()) 362 344 { 363 MeshInstance *inst = dynamic_cast<MeshInstance *>(object); 364 365 Mesh *mesh = inst->GetMesh(); 366 345 case Intersectable::MESH_INSTANCE: 346 347 mesh = dynamic_cast<MeshInstance *>(object)->GetMesh(); 348 349 case Intersectable::VIEWCELL: 350 mesh = dynamic_cast<ViewCell *>(object)->GetMesh(); 367 351 // copy the mesh data to polygons 368 CopyMesh2Polygon(mesh, polys); 352 CopyMesh2Polygons(mesh, polys); 353 break; 354 default: 355 break; 369 356 } 370 357 } 371 } 372 373 void BspTree::Subdivide(const ObjectContainer &objects) 374 { 358 Debug << "number of polygons: " << polys.size() << endl; 359 } 360 361 void BspTree::Construct(const ObjectContainer &objects) 362 { 363 mTermMaxPolygons = sTermMaxPolygons; 364 mTermMaxDepth = sTermMaxDepth; 365 366 mStat.nodes = 1; 367 375 368 std::stack<BspTraversalData> tStack; 376 369 PolygonQueue *polys = new PolygonQueue(); … … 385 378 { 386 379 tData = tStack.top(); 387 388 380 tStack.pop(); 389 381 390 BuildTree(tStack, tData);391 } 392 } 393 394 void BspTree:: BuildTree(BspTraversalStack &tStack, BspTraversalData ¤tData, ViewCell *viewCell)382 Subdivide(tStack, tData); 383 } 384 } 385 386 void BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell) 395 387 { 396 388 PolygonQueue *backPolys = new PolygonQueue(); 397 389 PolygonQueue *frontPolys = new PolygonQueue(); 398 390 399 BspNode *node = SubdivideNode(dynamic_cast<BspLeaf *>( currentData.mNode),400 currentData.mParent,401 currentData.mPolys,402 currentData.mDepth,391 BspNode *node = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 392 tData.mParent, 393 tData.mPolygons, 394 tData.mDepth, 403 395 viewCell, 404 396 backPolys, … … 410 402 411 403 // push the children on the stack (there are always two children) 412 tStack.push(BspTraversalData(interior->GetBack(), interior, backPolys, currentData.mDepth + 1)); 413 tStack.push(BspTraversalData(interior->GetFront(), interior, frontPolys, currentData.mDepth + 1)); 414 } 404 tStack.push(BspTraversalData(interior->GetBack(), interior, backPolys, tData.mDepth + 1)); 405 tStack.push(BspTraversalData(interior->GetFront(), interior, frontPolys, tData.mDepth + 1)); 406 } 407 else 408 EvaluateLeafStats(tData); 415 409 } 416 410 … … 429 423 PolygonQueue *backPolys) 430 424 { 431 // terminate traversal if no more faces in mesh432 if ((polys->size() <= m MaxPolys) || (depth >=mMaxDepth))433 { 434 // don't need to store polygon information = delete polygons435 Polygon ::DeletePolygons(polys);436 425 // terminate traversal 426 if ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth)) 427 { 428 // don't need to store polygon information => delete polygons 429 Polygon3::DeletePolygons(polys); 430 // Debug << polys->size() << ", " << depth << endl; 437 431 return leaf; 438 432 } 433 434 mStat.nodes += 2; 439 435 440 436 // add the new nodes to the tree + select subdivision plane … … 442 438 443 439 // split polygon according to current plane 444 node->SplitPolygons(polys, frontPolys, backPolys); 445 440 int splits = 0; 441 node->SplitPolygons(polys, frontPolys, backPolys, splits); 442 mStat.splits += splits; 443 446 444 // two new leaves 447 445 BspLeaf *back = new BspLeaf(); … … 461 459 return node; 462 460 } 461 462 void BspTree::ParseEnvironment() 463 { 464 environment->GetIntValue("BspTree.Termination.maxDepth", sTermMaxDepth); 465 environment->GetIntValue("BspTree.Termination.maxPolygons", sTermMaxPolygons); 466 } 467 468 void BspTree::EvaluateLeafStats(const BspTraversalData &data) 469 { 470 471 // the node became a leaf -> evaluate stats for leafs 472 BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode); 473 474 if (data.mDepth > mTermMaxDepth) 475 ++ mStat.maxDepthNodes; 476 477 // record maximal depth 478 if (data.mDepth > mStat.maxDepth) 479 mStat.maxDepth = data.mDepth; 480 } 463 481 //} // GtpVisibilityPreprocessor -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r234 r235 14 14 class BspTree; 15 15 class BspInterior; 16 class Polygon; 17 18 typedef std::queue<Polygon *> PolygonQueue; 16 class Polygon3; 17 18 /** Queue storing a soup of polygons used during BSP tree construction 19 */ 20 typedef std::queue<Polygon3 *> PolygonQueue; 19 21 20 22 class BspTreeStatistics // TODO: should have common superclass with KdTreeStatistics … … 23 25 // total number of nodes 24 26 int nodes; 27 // number of splits 28 int splits; 25 29 // totals number of rays 26 30 int rays; 31 // maximal reached depth 32 int maxDepth; 27 33 // total number of query domains 28 34 int queryDomains; … … 47 53 BspTreeStatistics() 48 54 { 49 55 Reset(); 50 56 } 51 57 … … 57 63 { 58 64 nodes = 0; 59 65 splits = 0; 60 66 rays = queryDomains = 0; 61 67 rayRefs = rayRefsNonZeroQuery = objectRefs = 0; … … 85 91 86 92 public: 93 BspNode(); 94 BspNode(BspInterior *parent); 95 87 96 /** Determines whether this node is a leaf or not 88 97 @return true if leaf … … 98 107 */ 99 108 BspInterior *GetParent(); 100 109 /** Sets parent node. 110 */ 111 void SetParent(BspInterior *parent); 112 101 113 protected: 102 114 … … 129 141 @param frontPolys returns the polygons in the front of the split plane 130 142 @param backPolys returns the polygons in the back of the split plane 131 */ 132 void SplitPolygons(PolygonQueue *polys, PolygonQueue *frontPolys, PolygonQueue *backPolys); 143 @param splits number of splits 144 */ 145 void SplitPolygons(PolygonQueue *polys, PolygonQueue *frontPolys, PolygonQueue *backPolys, int &splits); 133 146 134 147 protected: … … 161 174 162 175 163 /** Class representing a polygon.164 */165 class Polygon166 {167 public:168 Polygon();169 Polygon(const VertexContainer &vertices);170 171 /** Copies all the vertices of the face.172 */173 Polygon(Face *face, Mesh *parent);174 175 /** Returns supporting plane of this polygon.176 */177 Plane3 GetSupportingPlane();178 179 /** Splits polygon.180 @param partition the split plane181 @param front the front polygon182 @param back the back polygon183 */184 void Split(Plane3 *partition, Polygon *front, Polygon *back);185 186 enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT};187 188 /** Side of the plane where the polygon is located.189 @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT190 */191 int Side(Plane3 *plane);192 193 static void DeletePolygons(PolygonQueue *polys);194 195 /// vertices are connected in counterclockwise order.196 VertexContainer mVertices;197 };198 199 176 /** Implementation of the ViewCell BSP tree. */ 200 177 class BspTree … … 211 188 BspInterior *mParent; 212 189 /// polygonal data for splitting 213 PolygonQueue *mPoly s;190 PolygonQueue *mPolygons; 214 191 /// current depth 215 192 int mDepth; … … 218 195 219 196 BspTraversalData(BspNode *node, BspInterior *parent, PolygonQueue *polys, const int depth): 220 mNode(node), mParent(parent), mPoly s(polys), mDepth(depth) {}197 mNode(node), mParent(parent), mPolygons(polys), mDepth(depth) {} 221 198 }; 222 199 223 200 typedef std::stack<BspTraversalData> BspTraversalStack; 224 201 225 /** Constructs BSP tree from list of view cells. 202 /// BSP tree construction type 203 enum {VIEWCELLS, SCENE_GEOMETRY}; 204 205 /** Default constructor creating an empty tree. 226 206 */ 227 BspTree(const ViewCellContainer &viewCells); 228 /** Constructs BSP tree from list of objects. 229 @param object list of intersectables 230 @param maxPolys maximal allowed number of polygons 231 @param maxDepth maximal allowed BSP tree depth 232 */ 233 BspTree(const ObjectContainer &objects, int maxPolys, int maxDepth); 207 BspTree(); 234 208 235 209 ~BspTree(); 236 210 211 const BspTreeStatistics &GetStatistics() const; 212 213 /** Constructs tree using the given list of viewcells. 214 A pointer to the appropriate viewcell is stored within each leaf. 215 Many leafs can point to the same viewcell. 216 */ 217 void Construct(const ViewCellContainer &viewCells); 218 /** Constructs tree using the given list of objects. Each leaf is taken as viewcell. 219 No objects are treated as viewcells explicitly. 220 221 @param objects list of objects 222 */ 223 void Construct(const ObjectContainer &objects); 224 225 237 226 protected: 238 /** Builds a new extension of the tree. 239 */ 240 void BuildTree(BspTraversalStack &tStack, BspTraversalData ¤tData, ViewCell *viewCell = NULL); 241 242 /** Selects a splitting plane from the given polygons. 227 void EvaluateLeafStats(const BspTraversalData &data); 228 229 /** Subdivides node with respect to the traversal data. 230 @param tStack current traversal stack 231 @param tData traversal data also holding node to be subdivided 232 @param viewCell the view cell that will be represented with this part of the Bsp tree. 233 */ 234 void Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell = NULL); 235 236 /** Selects a splitting plane. 237 @param polyQueue the polygon data on which the split decition is based 243 238 */ 244 239 Plane3 SelectPlane(PolygonQueue *polyQueue); … … 248 243 */ 249 244 void InsertViewCell(ViewCell *viewCell); 250 251 /** Subdivides tree according to the given list of viewcells.252 */253 void Subdivide(const ViewCellContainer &viewCells);254 /** Subdivides tree according to the given list of objects.255 */256 void Subdivide(const ObjectContainer &objects);257 245 258 /** Subdivide sleaf.246 /** Subdivide leaf. 259 247 @param leaf the leaf to be subdivided 260 248 @param parent the parent node of this leaf … … 275 263 @param backPolys returns the polygons in the back of the split plane 276 264 */ 277 void FilterPolygons(BspInterior *node, PolygonQueue *polys, PolygonQueue *frontPolys, PolygonQueue *backPolys); 278 279 /** Extracts the mesh instances of the objects and copies them into the mesh. 265 void FilterPolygons(BspInterior *node, PolygonQueue *polys, 266 PolygonQueue *frontPolys, PolygonQueue *backPolys); 267 268 /** Extracts the meshes of the objects and copies them into the mesh. 280 269 */ 281 270 static void Copy2PolygonSoup(const ObjectContainer &objects, PolygonQueue &polys); 282 271 283 static void CopyMesh2Polygon(Mesh *mesh, PolygonQueue &polys); 272 /** copy this mesh into polygons. 273 */ 274 static void CopyMesh2Polygons(Mesh *mesh, PolygonQueue &polys); 284 275 285 276 /// Pointer to the root of the tree … … 287 278 /// Pointer to the root cell of the viewspace 288 279 // ViewCell *mRootCell; 289 /// maximal number of polygons allowed in leaf 290 int mMaxPolys; 291 /// maximal depth 292 int mMaxDepth; 293 280 281 294 282 BspTreeStatistics mStat; 283 284 /// local maximal polygons (changes depending on method) 285 int mTermMaxPolygons; 286 int mTermMaxDepth; 287 288 public: 289 /// Parses the environment and stores the global BSP tree parameters 290 static void ParseEnvironment(); 291 292 /// maximal number of polygons where tree construction is terminated 293 static int sTermMaxPolygons; 294 /// maximal possible depth 295 static int sTermMaxDepth; 295 296 }; 296 297 -
trunk/VUT/GtpVisibilityPreprocessor/src/common.h
r162 r235 127 127 #define MAX_FLOAT 1e30f 128 128 129 #ifndef DEL_PTR 130 #define DEL_PTR(ptr) while (0) {if (ptr) {delete (ptr); (ptr) = NULL;}} 131 #endif 132 129 133 inline 130 134 int signum(const Real a, const Real thresh = TRASH) -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r234 r235 18 18 environment->Parse(argc, argv, USE_EXE_PATH); 19 19 MeshKdTree::ParseEnvironment(); 20 20 BspTree::ParseEnvironment(); 21 21 22 Preprocessor *p = 22 23 new SamplingPreprocessor(); … … 27 28 28 29 p->LoadScene(filename); 30 29 31 p->BuildKdTree(); 30 32 p->KdTreeStatistics(cout); 31 32 #ifdef DEST_BSP_VIEWCELLS 33 #ifdef TEST_BSP_VIEWCELLS 33 34 p->GenerateViewcells(); 34 p->BspTreeStatistics( cout);35 p->BspTreeStatistics(Debug); 35 36 #endif 36 37 … … 46 47 p->ExportPreprocessedData("scene.vis"); 47 48 } 48 49 49 50 if (0) { 50 51 Camera camera;
Note: See TracChangeset
for help on using the changeset viewer.