Changeset 318 for trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
- Timestamp:
- 10/11/05 19:25:27 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r313 r318 149 149 } 150 150 151 void BspInterior::SplitPolygons(PolygonContainer *polys,152 PolygonContainer *frontPolys,153 PolygonContainer *backPolys,154 PolygonContainer *coincident,151 void BspInterior::SplitPolygons(PolygonContainer &polys, 152 PolygonContainer &frontPolys, 153 PolygonContainer &backPolys, 154 PolygonContainer &coincident, 155 155 int &splits, 156 156 bool storePolys) … … 160 160 Debug << "splitting polygons of node " << this << " with plane " << mPlane << endl; 161 161 #endif 162 while (!polys ->empty())163 { 164 Polygon3 *poly = polys ->back();165 polys ->pop_back();162 while (!polys.empty()) 163 { 164 Polygon3 *poly = polys.back(); 165 polys.pop_back(); 166 166 167 167 //Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n"; … … 179 179 case Polygon3::COINCIDENT: 180 180 //Debug << "coincident" << endl; 181 coincident ->push_back(poly);181 coincident.push_back(poly); 182 182 break; 183 183 case Polygon3::FRONT_SIDE: 184 184 //Debug << "front" << endl; 185 frontPolys ->push_back(poly);185 frontPolys.push_back(poly); 186 186 break; 187 187 case Polygon3::BACK_SIDE: 188 188 //Debug << "back" << endl; 189 backPolys ->push_back(poly);189 backPolys.push_back(poly); 190 190 break; 191 191 case Polygon3::SPLIT: … … 200 200 // check if polygons still valid 201 201 if (front_piece->Valid()) 202 frontPolys ->push_back(front_piece);202 frontPolys.push_back(front_piece); 203 203 else 204 204 DEL_PTR(front_piece); 205 205 206 206 if (back_piece->Valid()) 207 backPolys ->push_back(back_piece);207 backPolys.push_back(back_piece); 208 208 else 209 209 DEL_PTR(back_piece); … … 402 402 403 403 // split viewcell polygons with respect to split plane 404 interior->SplitPolygons( tData.mPolygons,405 frontPolys,406 backPolys,407 &coincident,404 interior->SplitPolygons(*tData.mPolygons, 405 *frontPolys, 406 *backPolys, 407 coincident, 408 408 splits, 409 409 mStoreSplitPolys); … … 475 475 } 476 476 477 int BspTree:: Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects)477 int BspTree::AddToPolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects) 478 478 { 479 479 int limit = (maxObjects > 0) ? Min((int)viewCells.size(), maxObjects) : (int)viewCells.size(); … … 491 491 } 492 492 493 int BspTree:: Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects)493 int BspTree::AddToPolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects) 494 494 { 495 495 int limit = (maxObjects > 0) ? Min((int)objects.size(), maxObjects) : (int)objects.size(); … … 531 531 // copy view cell meshes into one big polygon soup 532 532 PolygonContainer *polys = new PolygonContainer(); 533 mStat.polys = Copy2PolygonSoup(viewCells, *polys);533 mStat.polys = AddToPolygonSoup(viewCells, *polys); 534 534 535 535 // construct tree from viewcell polygons … … 546 546 547 547 // copy mesh instance polygons into one big polygon soup 548 mStat.polys = Copy2PolygonSoup(objects, *polys);548 mStat.polys = AddToPolygonSoup(objects, *polys); 549 549 550 550 // construct tree from polygon soup … … 607 607 leaf->SetViewCell(tData.mViewCell); 608 608 609 //-- clean up 610 609 611 // remaining polygons are discarded or added to node 610 612 leaf->ProcessPolygons(tData.mPolygons, mStoreSplitPolys); 611 613 DEL_PTR(tData.mPolygons); 614 615 CLEAR_CONTAINER(*tData.mRays); 616 DEL_PTR(tData.mRays); 612 617 613 618 return leaf; … … 621 626 // create new interior node and two leaf nodes 622 627 BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 623 tData.mPolygons, 624 frontPolys, 625 backPolys, 626 &coincident); 628 *tData.mPolygons, 629 *frontPolys, 630 *backPolys, 631 coincident, 632 *tData.mRays); 627 633 628 634 ViewCell *frontViewCell = mRootCell; … … 648 654 interior->ProcessPolygons(&coincident, mStoreSplitPolys); 649 655 656 // split rays 657 RayContainer *frontRays = NULL; 658 RayContainer *backRays = NULL; 659 660 if (tData.mRays->size() > 0) 661 { 662 RayContainer *frontRays = new RayContainer(); 663 RayContainer *backRays = new RayContainer(); 664 665 Plane3 plane; 666 SplitRays(plane, *tData.mRays, *frontRays, *backRays); 667 } 668 650 669 // push the children on the stack 651 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, backViewCell)); 652 tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, frontViewCell)); 670 tStack.push(BspTraversalData(interior->GetBack(), 671 backPolys, 672 tData.mDepth + 1, 673 backViewCell, 674 backRays)); 675 676 tStack.push(BspTraversalData(interior->GetFront(), 677 frontPolys, 678 tData.mDepth + 1, 679 frontViewCell, 680 frontRays)); 653 681 654 682 // cleanup 655 683 DEL_PTR(tData.mNode); 656 684 DEL_PTR(tData.mPolygons); 685 DEL_PTR(tData.mRays); 657 686 658 687 return interior; … … 684 713 foundFront = true; 685 714 } 686 //if (foundFront) Debug << "front viewCell: " << *frontViewCell << endl;687 //if (foundBack) Debug << "back viewCell: " << *backViewCell << endl;688 715 } 689 716 } 690 717 691 718 BspInterior *BspTree::SubdivideNode(BspLeaf *leaf, 692 PolygonContainer *polys, 693 PolygonContainer *frontPolys, 694 PolygonContainer *backPolys, 695 PolygonContainer *coincident) 719 PolygonContainer &polys, 720 PolygonContainer &frontPolys, 721 PolygonContainer &backPolys, 722 PolygonContainer &coincident, 723 const RayContainer &rays) 696 724 { 697 725 mStat.nodes += 2; 698 726 699 727 // add the new nodes to the tree + select subdivision plane 700 BspInterior *interior = new BspInterior(SelectPlane(leaf, *polys));728 BspInterior *interior = new BspInterior(SelectPlane(leaf, polys, rays)); 701 729 702 730 #ifdef _DEBUG … … 707 735 int splits = 0; 708 736 709 interior->SplitPolygons(polys, frontPolys, backPolys, coincident, splits, mStoreSplitPolys); 737 interior->SplitPolygons(polys, 738 frontPolys, 739 backPolys, 740 coincident, 741 splits, 742 mStoreSplitPolys); 710 743 711 744 mStat.splits += splits; … … 829 862 } 830 863 831 Plane3 BspTree::SelectPlane(BspLeaf *leaf, PolygonContainer &polys) 864 Plane3 BspTree::SelectPlane(BspLeaf *leaf, 865 PolygonContainer &polys, 866 const RayContainer &rays) 832 867 { 833 868 if (polys.size() == 0) … … 882 917 883 918 // use heuristics to find appropriate plane 884 return SelectPlaneHeuristics(polys, sMaxCandidates); 885 } 886 887 Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer &polys, int maxTests) 919 return SelectPlaneHeuristics(polys, rays, sMaxCandidates); 920 } 921 922 Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer &polys, 923 const RayContainer &rays, 924 const int maxTests) 888 925 { 889 926 float lowestCost = MAX_FLOAT; … … 901 938 902 939 // evaluate current candidate 903 float candidateCost = EvalSplitPlane(polys, candidatePlane );940 float candidateCost = EvalSplitPlane(polys, candidatePlane, rays); 904 941 905 942 if (candidateCost < lowestCost) … … 928 965 } 929 966 930 float BspTree::EvalSplitPlane(PolygonContainer &polys, const Plane3 &candidatePlane) 967 float BspTree::EvalSplitPlane(PolygonContainer &polys, 968 const Plane3 &candidatePlane, 969 const RayContainer &rays) 931 970 { 932 971 float val = 0; … … 1318 1357 } 1319 1358 } 1359 1360 void BspTree::SplitRays(const Plane3 plane, 1361 RayContainer &rays, 1362 RayContainer &frontRays, 1363 RayContainer &backRays) 1364 { 1365 while (!rays.empty()) 1366 { 1367 //TODO 1368 } 1369 } 1320 1370 //} // GtpVisibilityPreprocessor
Note: See TracChangeset
for help on using the changeset viewer.