Changeset 286
- Timestamp:
- 09/16/05 19:24:10 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r275 r286 8 8 # filename glasgow1.x3d 9 9 # filename vienna.x3d 10 filename ../data/atlanta/atlanta2.x3d 10 filename ../data/vienna/vienna-simple.x3d 11 # filename ../data/vienna/viewcells-25-sel.x3d 12 # filename ../data/atlanta/atlanta2.x3d 11 13 # filename ../data/soda/soda.dat 12 14 # filename ../data/soda/soda5.dat 13 15 # viewcells ../data/atlanta/atlanta_viewcells_large.x3d 14 16 #viewcells ../data/atlanta/atlanta_viewcells_large2.x3d 15 #viewcells ../data/vienna/viewcells-25-sel.x3d16 viewcells ../data/vienna/viewcells-25.x3d17 viewcells ../data/vienna/viewcells-25-sel.x3d 18 # viewcells ../data/vienna/viewcells-25.x3d 17 19 # viewcells ../data/vienna/viewcells-large-sel.x3d 18 20 } … … 68 70 splitPlaneStrategy combined 69 71 # constructionMethod rays 70 constructionMethod viewCells71 #constructionMethod sceneGeometry72 # constructionMethod viewCells 73 constructionMethod sceneGeometry 72 74 maxCandidates 25 73 75 maxViewCells 999999 74 76 Termination { 75 maxPolygons 076 maxDepth 30 0077 maxPolygons 3 78 maxDepth 30 77 79 } 78 80 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r268 r286 2 2 #include "Mesh.h" 3 3 #include "ViewCellBsp.h" // TODO: erase this 4 #include "Intersectable.h" 5 4 6 // tolerance value for side relation 5 7 #define SIDE_TOLERANCE 0.002f // TODO: Test different values 6 8 7 Polygon3::Polygon3(): mMaterial(NULL) 9 Polygon3::Polygon3(): mMaterial(NULL), mParent(NULL) 8 10 {} 9 11 10 Polygon3::Polygon3(const VertexContainer &vertices): mVertices(vertices), mMaterial(NULL) 12 Polygon3::Polygon3(const VertexContainer &vertices): mVertices(vertices), mMaterial(NULL), mParent(NULL) 11 13 {} 12 14 13 Polygon3::Polygon3(Face *face, Mesh *parent) 15 Polygon3::Polygon3(Intersectable *parent): mMaterial(NULL), mParent(parent) 16 { 17 } 18 Polygon3::Polygon3(Face *face, Mesh *parentMesh) 14 19 { 15 20 VertexIndexContainer::iterator it = face->mVertexIndices.begin(); 16 21 for (; it != face->mVertexIndices.end(); ++it) 17 22 { 18 mVertices.push_back(parent ->mVertices[*it]);19 mMaterial = parent ->mMaterial;23 mVertices.push_back(parentMesh->mVertices[*it]); 24 mMaterial = parentMesh->mMaterial; 20 25 21 //Debug << parent ->mVertices[*it] << endl;26 //Debug << parentMesh->mVertices[*it] << endl; 22 27 } 23 28 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r270 r286 13 13 class Plane3; 14 14 class Face; 15 15 class Intersectable; 16 16 17 17 /** Class representing a general planar polygon in 3d. … … 22 22 Polygon3(); 23 23 Polygon3(const VertexContainer &vertices); 24 Polygon3(Intersectable *parent); 24 25 25 26 /** Copies all the vertices of the face. 26 27 */ 27 Polygon3(Face *face, Mesh *parent );28 Polygon3(Face *face, Mesh *parentMesh); 28 29 29 30 /** Returns supporting plane of this polygon. … … 65 66 /// we can also store materials with polygons 66 67 Material *mMaterial; 67 68 static int mLeastSplitTable[4];69 static int mBalancedTreeTable[4];68 69 /// pointer to the intersectable this polygon is derived from 70 Intersectable *mParent; 70 71 }; 71 72 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r276 r286 39 39 /****************************************************************/ 40 40 41 BspNode::BspNode(): mParent(NULL), mPolygons(NULL) ,mViewCellIdx(0)41 BspNode::BspNode(): mParent(NULL), mPolygons(NULL)//,mViewCellIdx(0) 42 42 {} 43 43 44 BspNode::BspNode(BspInterior *parent): mParent(parent), mPolygons(NULL) ,mViewCellIdx(0)44 BspNode::BspNode(BspInterior *parent): mParent(parent), mPolygons(NULL)//,mViewCellIdx(0) 45 45 {} 46 46 … … 144 144 } 145 145 146 boolBspInterior::SplitPolygons(PolygonContainer *polys,147 PolygonContainer *frontPolys,148 PolygonContainer *backPolys,149 PolygonContainer *coincident,150 int &splits, bool storePolys) 151 { 146 Polygon3 *BspInterior::SplitPolygons(PolygonContainer *polys, 147 PolygonContainer *frontPolys, 148 PolygonContainer *backPolys, 149 int &splits, bool storePolys) 150 { 151 Polygon3 *splitPoly = NULL; 152 152 #ifdef _Debug 153 153 if (BspTree::displayDebug)Debug << "Splitting polygons of node " << this << " with plane " << mPlane << endl; … … 169 169 { 170 170 case Polygon3::COINCIDENT: 171 //Debug << "coincident" << endl; 171 172 // same surface normal 172 173 if (DotProd(mPlane.mNormal, poly->GetSupportingPlane().mNormal) > 0) 173 174 { 174 coincident->push_back(poly); 175 if (!splitPoly) // store the split polygon if there is none 176 splitPoly = poly; 177 else // discard it otherwise 178 ProcessPolygon(poly, storePolys); 179 175 180 break; 176 } 177 //if (BspTree::displayDebug) Debug << "coincident" << endl; 181 } 178 182 179 183 case Polygon3::FRONT_SIDE: 180 // if (BspTree::displayDebug)Debug << "front" << endl;184 //Debug << "front" << endl; 181 185 frontPolys->push_back(poly); 182 186 break; 183 187 case Polygon3::BACK_SIDE: 184 // if (BspTree::displayDebug)Debug << "back" << endl;188 //Debug << "back" << endl; 185 189 backPolys->push_back(poly); 186 190 break; 187 191 case Polygon3::SPLIT: 188 front_piece = new Polygon3(poly-> GetParent());189 back_piece = new Polygon3(poly-> GetParent());192 front_piece = new Polygon3(poly->mParent); 193 back_piece = new Polygon3(poly->mParent); 190 194 191 195 //-- split polygon … … 196 200 197 201 #ifdef _DEBUG 198 if (BspTree::displayDebug)Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl;202 Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 199 203 #endif 200 204 ProcessPolygon(poly, storePolys); … … 207 211 } 208 212 //if (BspTree::displayDebug) Debug << "inside: " << inside << endl; 209 // contains nothing 210 delete polys; 213 214 delete polys; // contains nothing 215 return splitPoly; 211 216 } 212 217 … … 252 257 mTermMaxDepth(0), 253 258 mRoot(NULL), 254 mIsIncremential(false),255 259 //mStorePolys(true) 256 260 mStorePolys(false) … … 354 358 355 359 356 void BspTree::InsertViewCell(ViewCell *viewCell)360 /*void BspTree::InsertViewCell(ViewCell *viewCell) 357 361 { 358 362 std::stack<BspTraversalData> tStack; … … 384 388 PolygonContainer *frontPolys = new PolygonContainer(); 385 389 PolygonContainer *backPolys = new PolygonContainer(); 386 Polygon Container *coincident = new PolygonContainer();390 Polygon3 *coincident = NULL; 387 391 388 392 int splits = 0; … … 400 404 401 405 // push the children on the stack 402 tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1 ));403 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1 ));406 tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, NULL)); 407 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, coincident)); 404 408 405 409 } … … 420 424 } 421 425 } 422 } 426 }*/ 423 427 424 428 void BspTree::InitTree(int maxPolygons, int maxDepth) … … 433 437 434 438 435 int BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys )439 int BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent) 436 440 { 437 441 FaceContainer::const_iterator fi; … … 442 446 { 443 447 Polygon3 *poly = new Polygon3((*fi), mesh); 448 poly->mParent = parent; // set parent intersectable 444 449 polys.push_back(poly); 445 450 //if (displayDebug)Debug << *poly << endl; 446 polysNum ++;451 ++ polysNum; 447 452 } 448 453 return polysNum; … … 458 463 { 459 464 mBox.Include(viewCells[i]->GetBox()); // add to BSP tree aabb 460 AddMesh2Polygons(viewCells[i]->GetMesh(), polys );465 AddMesh2Polygons(viewCells[i]->GetMesh(), polys, viewCells[i]); 461 466 } 462 467 } … … 507 512 InitTree(sTermMaxPolygons, sTermMaxDepth); 508 513 509 bool savedStorePolys = mStorePolys; 510 511 // tree is completely constructed once before 512 // view cells are inserted one after another => 513 // global tree optimization possible 514 if (!mIsIncremential) // todo: not incremential does not work 515 { 516 // copy view cell meshes into one big polygon soup 517 PolygonContainer *polys = new PolygonContainer(); 518 Copy2PolygonSoup(viewCells, *polys); 519 520 // polygons are stored only during view cell insertion 521 mStorePolys = false; 522 523 // construct tree from viewcell polygons 524 Construct(polys); 525 //Export("bsp.x3d"); 526 } 527 528 //-- insert all viewcells one after another 529 ViewCellContainer::const_iterator it; 530 531 mStorePolys = savedStorePolys; 532 mStat.polys = 0; 533 mStat.splits = 0; 534 mStat.accumDepth = 0; 535 536 long startTime = GetTime(); 537 //displayDebug = true; 538 counter = 0; 539 Debug << "**** Starting view cell insertion ****" << endl; 540 for (it = viewCells.begin(); it != viewCells.end(); ++ it) 541 { 542 //if ((counter == 12) || (counter == 14)){ 543 //Debug << "** inserting view cell " << counter << " **" << endl; 544 InsertViewCell(*it); 545 //} counter ++; 546 } 547 548 Debug << "**** Finished view cell insertion ****" << endl; 549 Debug << "insertion time: "<< TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 514 // copy view cell meshes into one big polygon soup 515 PolygonContainer *polys = new PolygonContainer(); 516 Copy2PolygonSoup(viewCells, *polys); 517 518 // construct tree from viewcell polygons 519 Construct(polys); 520 //Export("bsp.x3d"); 550 521 } 551 522 … … 574 545 std::stack<BspTraversalData> tStack; 575 546 576 BspTraversalData tData(new BspLeaf(), polys, 0, true, viewCells);547 BspTraversalData tData(new BspLeaf(), polys, 0, NULL); 577 548 578 549 tStack.push(tData); … … 585 556 tStack.pop(); 586 557 587 //TODO588 ViewCell *viewCell = NULL;589 590 /*if (viewCells) // generate new view cell in leaf591 {592 viewCell = new ViewCell();593 viewCells->push_back(viewCell);594 }*/595 596 558 // subdivide leaf node 597 BspNode *root = Subdivide(tStack, tData, viewCell );559 BspNode *root = Subdivide(tStack, tData, viewCells); 598 560 599 561 // empty tree => new root corresponding to unbounded space … … 608 570 609 571 BspNode *BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, 610 ViewCell *viewCell)572 ViewCellContainer *viewCells) 611 573 { 612 574 //-- terminate traversal 613 575 if ((tData.mPolygons->size() <= mTermMaxPolygons) || (tData.mDepth >= mTermMaxDepth)) 614 // if there is another view cell associated with this leaf => subdivide further615 //&& !(viewCell && tData.mIsInside && dynamic_cast<BspLeaf *>(tData.mNode)->GetViewCell()))616 576 { 617 577 #ifdef _DEBUG 618 if (displayDebug)Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: " << (int)tData.mPolygons->size() << endl;578 Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: " << (int)tData.mPolygons->size() << endl; 619 579 #endif 620 580 621 581 EvaluateLeafStats(tData); 622 582 623 // add view cell if inside object) 624 if (viewCell && tData.mCoincident && (tData.mCoincident->size() > 0))) // || (tData.mGeometry->size() > 0) // or if there is still geometry left 625 { 626 BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 627 583 BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 584 585 //-- new viewcells are generated and added to each leaf 586 if (viewCells) 587 { 588 ViewCell *viewCell = new ViewCell(); 589 leaf->SetViewCell(viewCell); 590 viewCells->push_back(viewCell); 591 Debug << "creating new viewcell" << endl; 592 } 593 //-- add viewcell stored in split polygon 594 else if (tData.mSplitPoly && tData.mSplitPoly->mParent) 595 { 628 596 if (leaf->GetViewCell()) 629 597 Debug << "ERROR: leaf already has view cell " << endl;//leaf->mViewCellIdx << endl; 630 598 631 //leaf->mViewCellIdx = counter; 632 //Debug << "insert view cell" << endl; 633 634 leaf->SetViewCell(coincident[0]->GetParent()); 635 } 636 599 //leaf->mViewCellIdx = counter;Debug << "insert view cell" << endl; 600 601 leaf->SetViewCell(dynamic_cast<ViewCell *>(tData.mSplitPoly->mParent)); 602 603 // discard split polygon 604 tData.mNode->GetParent()->ProcessPolygon(tData.mSplitPoly, mStorePolys); 605 } 606 637 607 // add or delete remaining polygons 638 608 tData.mNode->ProcessPolygons(tData.mPolygons, mStorePolys); 639 tData.mNode->ProcessPolygons(tData.coincident, mStorePolys); 640 609 641 610 return tData.mNode; 642 611 } 643 612 644 tData.mNode->ProcessPolygons(tData.coincident, mStorePolys); 613 // discard the split polygon (not needed if traversal continues) 614 if (tData.mSplitPoly) 615 tData.mNode->GetParent()->ProcessPolygon(tData.mSplitPoly, mStorePolys); 645 616 646 617 //-- create new subdivided node 647 618 PolygonContainer *backPolys = new PolygonContainer(); 648 619 PolygonContainer *frontPolys = new PolygonContainer(); 649 Polygon Container *coincident = new PolygonContainer();620 Polygon3 *splitPoly = NULL; 650 621 651 622 BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), … … 653 624 frontPolys, 654 625 backPolys, 655 coincident);626 &splitPoly); 656 627 657 628 // push the children on the stack 658 629 // inside information is only propagated with the back leaf 659 tStack.push(BspTraversalData(interior->Get Back(), backPolys, tData.mDepth + 1, coincident));660 tStack.push(BspTraversalData(interior->Get Front(), frontPolys, tData.mDepth + 1));630 tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, NULL)); 631 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, splitPoly)); 661 632 662 633 return interior; … … 667 638 PolygonContainer *polys, 668 639 PolygonContainer *frontPolys, 669 PolygonContainer *coincident, 670 PolygonContainer *backPolys, bool &inside) 640 PolygonContainer *backPolys, Polygon3 **splitPoly) 671 641 { 672 642 mStat.nodes += 2; … … 682 652 int splits = 0; 683 653 684 inside = interior->SplitPolygons(polys, frontPolys, backPolys, coincident, splits, mStorePolys);654 *splitPoly = interior->SplitPolygons(polys, frontPolys, backPolys, splits, mStorePolys); 685 655 686 656 mStat.splits += splits; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r271 r286 144 144 */ 145 145 PolygonContainer *GetPolygons(); 146 int mViewCellIdx; 146 /** Stores polygons in node or discards them according to storePolys. 147 */ 148 void ProcessPolygons(PolygonContainer *polys, const bool storePolys); 149 150 //int mViewCellIdx; 147 151 protected: 148 149 /** Adds or discards polygons according to storePolys.150 */151 void ProcessPolygons(PolygonContainer *polys, const bool storePolys);152 153 152 154 153 /// parent of this node … … 184 183 @param backPolys returns the polygons in the back of the split plane 185 184 @param splits number of splits 186 @returns true if one or more polygons are inside of the split plane 187 */ 188 bool SplitPolygons(PolygonContainer *polys, PolygonContainer *frontPolys, 189 PolygonContainer *backPolys, int &splits, bool storePolys = false); 185 @returns split polygon if there is a polygon coincident to the split plane, NULL otherwise 186 */ 187 Polygon3 *SplitPolygons(PolygonContainer *polys, 188 PolygonContainer *frontPolys, 189 PolygonContainer *backPolys, 190 int &splits, 191 bool storePolys = false); 192 193 /** Stores polygon in node or discards them according to storePolys. 194 @param polys the polygons 195 @param storePolys if the polygons should be stored or discarded 196 */ 197 void ProcessPolygon(Polygon3 *poly, const bool storePolys); 190 198 191 199 friend ostream &operator<<(ostream &s, const BspInterior &A) … … 194 202 } 195 203 196 protected: 204 protected: 197 205 198 /** Discards or stores polygon in node.199 @param polys the polygons200 @param storePolys if the polygons should be stored or discarded201 */202 void ProcessPolygon(Polygon3 *poly, const bool storePolys);203 206 204 207 /// Splitting plane corresponding to this node … … 255 258 /// current depth 256 259 int mDepth; 260 /// the polygon that drove the split plane computation 261 Polygon3 *mSplitPoly; 257 262 /// if the node is an inside or outside node with respect to the parent plane 258 bool mIsInside;263 //bool mIsInside; 259 264 BspTraversalData() {} 260 265 261 BspTraversalData(BspNode *node, PolygonContainer *polys, const int depth, const bool inside):262 mNode(node), mPolygons(polys), mDepth(depth), m IsInside(inside) {}266 BspTraversalData(BspNode *node, PolygonContainer *polys, const int depth, Polygon3 *splitPoly): 267 mNode(node), mPolygons(polys), mDepth(depth), mSplitPoly(splitPoly) {} 263 268 }; 264 269 … … 345 350 @param tStack current traversal stack 346 351 @param tData traversal data also holding node to be subdivided 347 @param viewCell the view cell that will be represented with this part of the Bsp tree.352 @param viewCellContainer if not null, a new viewcell is created and stored in the container 348 353 @returns new root of the subtree 349 354 */ 350 BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell= NULL);355 BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCellContainer *viewCells = NULL); 351 356 352 357 /** Selects a splitting plane. … … 358 363 (i.e., possibly more than one leaf). 359 364 */ 360 void InsertViewCell(ViewCell *viewCell);365 //void InsertViewCell(ViewCell *viewCell); 361 366 362 367 /** Subdivide leaf. … … 365 370 @param frontPolys the polygons of the front child node as a result from splitting 366 371 @param backPolys the polygons of the back child node as a result from splitting 367 @param if the polygons are outside or inside with respect to the interior node plane372 @param splitPoly polygon that is coincident to the split plane, NULL if no such polygon 368 373 @returns the root of the subdivision 369 374 */ … … 371 376 PolygonContainer *polys, 372 377 PolygonContainer *frontPolys, 373 PolygonContainer *backPolys, bool &inside);378 PolygonContainer *backPolys, Polygon3 **splitPoly); 374 379 375 380 /** Filters polygons down the tree. … … 402 407 403 408 /** Extract polygons of this mesh and add to polygon container. 409 @param mesh the mesh that drives the polygon construction 410 @param parent the parent intersectable this polygon is constructed from 404 411 @returns number of polygons 405 412 */ 406 int AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys );413 int AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent = NULL); 407 414 408 415 /** A ray is cast possible intersecting the tree. -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r275 r286 53 53 else 54 54 p->GenerateViewCells(); 55 56 Debug << "Number of view cells: " << p->mViewCells.size() << endl;57 55 } 58 56 59 57 p->BuildBspTree(); 60 58 p->BspTreeStatistics(Debug); 59 Debug << "Number of view cells: " << p->mViewCells.size() << endl; 61 60 p->Export(filename + "-bsptree.x3d", false, false, true); 62 61
Note: See TracChangeset
for help on using the changeset viewer.