Changeset 313 for trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
- Timestamp:
- 10/10/05 04:19:59 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r312 r313 120 120 } 121 121 122 void X3dExporter::ExportViewCells(ViewCellContainer *viewCells) 123 { 124 ViewCellContainer::iterator it, it_end = viewCells->end(); 125 126 for (it = viewCells->begin(); it != it_end; ++it) 122 void 123 X3dExporter::ExportViewCells(const ViewCellContainer &viewCells) 124 { 125 ViewCellContainer::const_iterator it, it_end = viewCells.end(); 126 127 for (it = viewCells.begin(); it != it_end; ++ it) 127 128 ExportViewCell(*it); 128 129 } 130 129 131 void 130 132 X3dExporter::ExportViewCell(ViewCell *viewCell) … … 274 276 } 275 277 276 void X3dExporter::ExportPolygons( PolygonContainer *polys)278 void X3dExporter::ExportPolygons(const PolygonContainer &polys) 277 279 { 278 280 stream << "<Shape>" << endl; … … 314 316 VertexContainer::const_iterator vi; 315 317 316 for (pit = polys ->begin(); pit != polys->end(); ++pit)318 for (pit = polys.begin(); pit != polys.end(); ++pit) 317 319 { 318 320 Polygon3 *poly = *pit; … … 327 329 328 330 stream << "<Coordinate point=\"" << endl; 329 for (pit = polys ->begin(); pit != polys->end(); ++pit)331 for (pit = polys.begin(); pit != polys.end(); ++pit) 330 332 { 331 333 Polygon3 *poly = *pit; … … 453 455 ViewCellContainer::iterator new_end = unique(foundViewCells.begin(), foundViewCells.end()); 454 456 foundViewCells.erase(new_end, foundViewCells.end()); 455 ExportViewCells( &foundViewCells);457 ExportViewCells(foundViewCells); 456 458 457 459 Debug << "Number of view cells after erasing dublicates: " << (int)foundViewCells.size() << endl; … … 533 535 if (vc->mPassingRays.mRays) 534 536 { 535 float importance = vc->mPassingRays.mContributions/(float)vc->mPassingRays.mRays; 537 float importance = 538 vc->mPassingRays.mContributions / (float)vc->mPassingRays.mRays; 536 539 537 540 mForcedMaterial.mDiffuseColor.r = importance; … … 616 619 BspNode *mNode; 617 620 618 PolygonContainer *mPolygons;619 621 vector<Plane3 *> mPlanes; 620 622 vector<bool> mSides; 621 623 bool mIsFront; 622 624 623 BspSplitData(BspNode *node , PolygonContainer *polys):624 mNode(node), m Polygons(polys), mIsFront(false)625 BspSplitData(BspNode *node): 626 mNode(node), mIsFront(false) 625 627 {}; 626 628 BspSplitData(BspNode *node, 627 PolygonContainer *polys,628 629 vector<Plane3 *> planes, 629 630 vector<bool> sides, 630 631 bool isFront): 631 mNode(node), mP olygons(polys), mPlanes(planes),632 mNode(node), mPlanes(planes), 632 633 mSides(sides), mIsFront(isFront) 633 634 {}; … … 636 637 void X3dExporter::ExportBspSplits(const BspTree &tree) 637 638 { 638 int mask = Random(50000);639 640 639 std::stack<BspSplitData> tStack; 641 640 642 BspSplitData tData(tree.GetRoot() , new PolygonContainer());641 BspSplitData tData(tree.GetRoot()); 643 642 tStack.push(tData); 644 643 644 PolygonContainer polys; 645 645 646 while (!tStack.empty()) 646 647 { … … 652 653 { 653 654 BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 654 655 tData.mPlanes.push_back(interior->GetPlane()); 656 tData.mSides.push_back(tData.mIsFront); 655 if (tData.mNode != tree.GetRoot()) 656 tData.mSides.push_back(tData.mIsFront); // add current side 657 657 658 658 // bounded plane is added to the polygons 659 Polygon3 *planePoly = tree.GetBoundingBox().BoundPlane(* tData.mPlanes.back());659 Polygon3 *planePoly = tree.GetBoundingBox().BoundPlane(*interior->GetPlane()); 660 660 661 PolygonContainer *frontPolys = new PolygonContainer();662 PolygonContainer *backPolys = new PolygonContainer();663 PolygonContainer coincident;664 665 int splits = 0;666 667 // split polygons with respect to split plane668 interior->SplitPolygons(tData.mPolygons,669 frontPolys,670 backPolys,671 &coincident,672 splits,673 false);674 675 661 // do all the splits with the previous planes 676 662 for (int i = 0; i < (int)tData.mPlanes.size(); ++i) … … 692 678 else 693 679 { 694 Debug << "take backpoly" << endl;695 680 planePoly = backPoly; 696 681 DEL_PTR(frontPoly); … … 699 684 } 700 685 701 PolygonContainer *polys; 702 BspNode *next; 703 bool side = false; 704 705 // random decision 706 if (mask & 1) 707 { 708 next = interior->GetBack(); 709 polys = backPolys; 710 CLEAR_CONTAINER(*frontPolys); 711 DEL_PTR(frontPolys); 712 side = false; 713 } 686 tData.mPlanes.push_back(interior->GetPlane()); // add plane to split planes 687 if (planePoly->Valid()) 688 polys.push_back(planePoly); 714 689 else 715 690 { 716 next = interior->GetFront(); 717 polys = frontPolys; 718 719 CLEAR_CONTAINER(*backPolys); 720 DEL_PTR(backPolys); 721 side = true; 691 Debug << "polygon not valid: " << *planePoly << " size: " << planePoly->mVertices.size() << endl; 692 DEL_PTR(planePoly); 722 693 } 723 724 mask = mask >> 1;725 polys->push_back(planePoly);726 727 694 // push the children on the stack 728 tStack.push(BspSplitData(next, polys, tData.mPlanes, 729 tData.mSides, side)); 730 //tStack.push(BspSplitData(interior->GetBack(), backPolys, 731 // tData.mPlanes, tData.mSides, false)); 732 733 // clean up 734 CLEAR_CONTAINER(coincident); // NOTE: should contain nothing 735 CLEAR_CONTAINER(*tData.mPolygons); 736 DEL_PTR(tData.mPolygons); 695 tStack.push(BspSplitData(interior->GetFront(), tData.mPlanes, tData.mSides, true)); 696 tStack.push(BspSplitData(interior->GetBack(), tData.mPlanes, tData.mSides, false)); 737 697 } 738 else // reached leaf 698 } 699 ExportPolygons(polys); 700 CLEAR_CONTAINER(polys); 701 } 702 703 void X3dExporter::ExportBspSplitPlanes(const BspTree &tree) 704 { 705 std::stack<BspNode *> tStack; 706 707 tStack.push(tree.GetRoot()); 708 709 PolygonContainer polys; 710 711 while (!tStack.empty()) 712 { 713 // filter polygons donw the tree 714 BspNode *node = tStack.top(); 715 tStack.pop(); 716 717 if (!node->IsLeaf()) 739 718 { 740 //Debug << "\nsplits: " << endl; 741 //for (int i = 0; i < (int)tData.mSides.size(); ++ i)Debug << " " << tData.mSides[i]; 742 ExportPolygons(tData.mPolygons); 743 744 // clean up 745 CLEAR_CONTAINER(*tData.mPolygons); 746 DEL_PTR(tData.mPolygons); 719 BspInterior *interior = dynamic_cast<BspInterior *>(node); 720 721 // bounded plane is added to the polygons 722 polys.push_back(tree.GetBoundingBox().BoundPlane(*interior->GetPlane())); 723 724 // push the children on the stack 725 tStack.push(interior->GetBack()); 726 tStack.push(interior->GetFront()); 747 727 } 748 728 } 749 } 729 730 ExportPolygons(polys); 731 CLEAR_CONTAINER(polys); 732 }
Note: See TracChangeset
for help on using the changeset viewer.