Changeset 319 for trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
- Timestamp:
- 10/12/05 01:15:22 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r318 r319 16 16 int BspTree::sTermMaxDepth = 20; 17 17 int BspTree::sMaxCandidates = 10; 18 int BspTree::sSplitPlaneStrategy = NEXT_POLYGON;18 int BspTree::sSplitPlaneStrategy = BALANCED_POLYS; 19 19 int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS; 20 20 int BspTree::sTermMaxPolysForAxisAligned = 50; … … 30 30 float BspTree::sVerticalSplitsFactor = 1.0f; // very important criterium for 2.5d scenes 31 31 float BspTree::sLargestPolyAreaFactor = 1.0f; 32 float BspTree::sBlockedRaysFactor = 1.0f; 32 33 33 34 /** Evaluates split plane classification with respect to the plane's … … 552 553 } 553 554 554 void BspTree::Construct(const RayContainer &rays, ViewCellContainer *viewCells) 555 { 556 // TODO 555 void BspTree::Construct(const ObjectContainer &objects, 556 const RayContainer &rays, 557 ViewCellContainer *viewCells) 558 { 559 PolygonContainer *polys = new PolygonContainer(); 560 561 // copy mesh instance polygons into one big polygon soup 562 mStat.polys = AddToPolygonSoup(objects, *polys); 563 564 RayContainer::const_iterator rit, rit_end = rays.end(); 565 566 long startTime = GetTime(); 567 Debug << "**** Casting rays into polygons ****\n"; 568 569 //-- cast rays into all polygons 570 for (rit = rays.begin(); rit != rays.end(); ++ rit) 571 { 572 Ray *ray = *rit; 573 574 PolygonContainer::const_iterator pit, pit_end = polys->end(); 575 576 for (pit = polys->begin(); pit != pit_end; ++ pit) 577 { 578 Polygon3 *poly = *pit; 579 580 float t = 0; 581 float nearestT = 0; 582 583 if (poly->CastRay(*ray, t, nearestT) > 0) 584 poly->AddPiercingRay(ray); 585 } 586 } 587 588 Debug << "**** Finished ray casting ****\n"; 589 Debug << "ray casting time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 590 591 Construct(polys, viewCells); 557 592 } 558 593 … … 565 600 566 601 long startTime = GetTime(); 567 Debug << "**** Contructing tree using objects****\n";602 Debug << "**** Contructing tree using scene geometry ****\n"; 568 603 while (!tStack.empty()) 569 604 { … … 607 642 leaf->SetViewCell(tData.mViewCell); 608 643 609 //-- clean up 610 644 // clean up 611 645 // remaining polygons are discarded or added to node 612 646 leaf->ProcessPolygons(tData.mPolygons, mStoreSplitPolys); 613 647 DEL_PTR(tData.mPolygons); 614 615 CLEAR_CONTAINER(*tData.mRays);616 DEL_PTR(tData.mRays);617 648 618 649 return leaf; … … 629 660 *frontPolys, 630 661 *backPolys, 631 coincident, 632 *tData.mRays); 662 coincident); 633 663 634 664 ViewCell *frontViewCell = mRootCell; … … 644 674 // extract view cells from coincident polygons according to plane normal 645 675 // only if front or back polygons are empty 646 ExtractViewCells(&backViewCell, 647 &frontViewCell, 648 coincident, 649 interior->mPlane, 676 ExtractViewCells(&backViewCell, 677 &frontViewCell, 678 coincident, 679 interior->mPlane, 650 680 backPolys->empty(), 651 681 frontPolys->empty()); … … 653 683 // don't need coincident polygons anymore 654 684 interior->ProcessPolygons(&coincident, mStoreSplitPolys); 655 656 // split rays657 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 685 669 686 // push the children on the stack … … 671 688 backPolys, 672 689 tData.mDepth + 1, 673 backViewCell, 674 backRays)); 690 backViewCell)); 675 691 676 692 tStack.push(BspTraversalData(interior->GetFront(), 677 693 frontPolys, 678 694 tData.mDepth + 1, 679 frontViewCell, 680 frontRays)); 695 frontViewCell)); 681 696 682 697 // cleanup 683 698 DEL_PTR(tData.mNode); 684 699 DEL_PTR(tData.mPolygons); 685 DEL_PTR(tData.mRays);686 700 687 701 return interior; … … 720 734 PolygonContainer &frontPolys, 721 735 PolygonContainer &backPolys, 722 PolygonContainer &coincident, 723 const RayContainer &rays) 736 PolygonContainer &coincident) 724 737 { 725 738 mStat.nodes += 2; 726 739 727 740 // add the new nodes to the tree + select subdivision plane 728 BspInterior *interior = new BspInterior(SelectPlane(leaf, polys , rays));741 BspInterior *interior = new BspInterior(SelectPlane(leaf, polys)); 729 742 730 743 #ifdef _DEBUG … … 863 876 864 877 Plane3 BspTree::SelectPlane(BspLeaf *leaf, 865 PolygonContainer &polys, 866 const RayContainer &rays) 878 PolygonContainer &polys) 867 879 { 868 880 if (polys.size() == 0) … … 917 929 918 930 // use heuristics to find appropriate plane 919 return SelectPlaneHeuristics(polys, rays,sMaxCandidates);931 return SelectPlaneHeuristics(polys, sMaxCandidates); 920 932 } 921 933 922 934 Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer &polys, 923 const RayContainer &rays,924 935 const int maxTests) 925 936 { … … 938 949 939 950 // evaluate current candidate 940 float candidateCost = EvalSplitPlane(polys, candidatePlane , rays);951 float candidateCost = EvalSplitPlane(polys, candidatePlane); 941 952 942 953 if (candidateCost < lowestCost) … … 966 977 967 978 float BspTree::EvalSplitPlane(PolygonContainer &polys, 968 const Plane3 &candidatePlane, 969 const RayContainer &rays) 979 const Plane3 &candidatePlane) 970 980 { 971 981 float val = 0; … … 980 990 } 981 991 982 //-- strategies where the effect of the split plane on the polygons is tested 983 if (!((sSplitPlaneStrategy & BALANCED_POLYS) || 984 (sSplitPlaneStrategy & LEAST_SPLITS) || 985 (sSplitPlaneStrategy & LARGEST_POLY_AREA) || 986 (sSplitPlaneStrategy & BALANCED_VIEW_CELLS))) 992 // strategies where the effect of the split plane is tested 993 // on all input polygons 994 if (!((sSplitPlaneStrategy & BALANCED_POLYS) || 995 (sSplitPlaneStrategy & LEAST_SPLITS) || 996 (sSplitPlaneStrategy & LARGEST_POLY_AREA) || 997 (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) || 998 (sSplitPlaneStrategy & BLOCKED_RAYS))) 999 { 987 1000 return val; 988 989 PolygonContainer::const_iterator it, it_end = polys.end(); 1001 } 1002 990 1003 float sumBalancedPolys = 0; 991 1004 float sumSplits = 0; 992 1005 float sumPolyArea = 0; 993 1006 float sumBalancedViewCells = 0; 1007 float sumBlockedRays = 0; 1008 1009 float totalBlockedRays = 0; 994 1010 //float totalArea = 0; 995 1011 996 // container for view cells1012 // container for balanced view cells criterium 997 1013 ObjectContainer frontViewCells; 998 1014 ObjectContainer backViewCells; 1015 1016 PolygonContainer::const_iterator it, it_end = polys.end(); 999 1017 1000 1018 for (it = polys.begin(); it != it_end; ++ it) … … 1019 1037 } 1020 1038 1039 1040 if (sSplitPlaneStrategy & BLOCKED_RAYS) 1041 { 1042 float blockedRays = (float)(*it)->GetPiercingRays()->size(); 1043 if (classification == Polygon3::COINCIDENT) 1044 { 1045 sumBlockedRays += blockedRays; 1046 } 1047 1048 totalBlockedRays += blockedRays; 1049 } 1050 1021 1051 // assign view cells to back or front according to classificaion 1022 1052 if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) … … 1031 1061 } 1032 1062 1063 // all values should be approx. between 0 and 1 so they can be combined 1064 // and scaled with the factors according to their importance 1033 1065 if (sSplitPlaneStrategy & BALANCED_POLYS) 1034 1066 val += sBalancedPolysFactor * fabs(sumBalancedPolys) / (float)polys.size(); … … 1038 1070 1039 1071 if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 1040 val += sLargestPolyAreaFactor * (float)polys.size() / sumPolyArea; // HACK 1072 // HACK (polys.size should be totalArea) 1073 val += sLargestPolyAreaFactor * (float)polys.size() / sumPolyArea; 1074 1075 if (sSplitPlaneStrategy & BLOCKED_RAYS) 1076 if (totalBlockedRays > 0) 1077 val += sBlockedRaysFactor * sumBlockedRays / totalBlockedRays; 1041 1078 1042 1079 if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) … … 1133 1170 if (sSplitPlaneStrategy & VERTICAL_AXIS) 1134 1171 Debug << "vertical axis "; 1172 if (sSplitPlaneStrategy & BLOCKED_RAYS) 1173 Debug << "blocked rays "; 1135 1174 1136 1175 Debug << endl; … … 1357 1396 } 1358 1397 } 1359 1360 void BspTree::SplitRays(const Plane3 plane,1361 RayContainer &rays,1362 RayContainer &frontRays,1363 RayContainer &backRays)1364 {1365 while (!rays.empty())1366 {1367 //TODO1368 }1369 }1370 1398 //} // GtpVisibilityPreprocessor
Note: See TracChangeset
for help on using the changeset viewer.