Changeset 286 for trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
- Timestamp:
- 09/16/05 19:24:10 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note: See TracChangeset
for help on using the changeset viewer.