- Timestamp:
- 09/20/05 02:39:50 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r292 r294 65 65 66 66 BspTree { 67 # splitPlaneStrategy leastSplits 68 splitPlaneStrategy balancedTree 69 # splitPlaneStrategy nextPolygon 70 # splitPlaneStrategy combined 67 splitPlaneStrategy 14 71 68 # constructionMethod rays 72 69 constructionMethod viewCells -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r293 r294 61 61 //-- plane - line intersection 62 62 Vector3 splitPt = partition->FindIntersection(ptA, ptB); 63 Debug << "fpg " << splitPt << " side " << partition->Side(splitPt, SIDE_TOLERANCE) << 64 "\nptA " << ptA << " side " << sideA << "\nptB " << ptB << " side " << sideB << " " << Distance(ptB, splitPt) << endl; 63 65 64 if (!foundSplit || (SqrDistance(splitPt, prevSplitPt) > SIDE_TOLERANCE_SQRD)) 66 65 { … … 81 80 //-- plane - line intersection 82 81 Vector3 splitPt = partition->FindIntersection(ptA, ptB); 83 // if (foundSplit) Debug << "back split pt " << splitPt << " prev " << prevSplitPt << endl;82 84 83 if (!foundSplit || (SqrDistance(splitPt, prevSplitPt) > SIDE_TOLERANCE_SQRD)) 85 84 { 86 //Debug << "add back split vertex " << splitPt << endl;87 85 // add vertex to both polygons 88 86 front->mVertices.push_back(splitPt); … … 91 89 foundSplit = true; 92 90 prevSplitPt = splitPt; 93 } //else Debug << "reject back split vertex " << splitPt << endl;91 } 94 92 } 95 93 back->mVertices.push_back(ptB); … … 125 123 bool onFrontSide = false; 126 124 bool onBackSide = false; 125 // threshold for coincident classification 126 const float dot_thres = 0.99f; 127 127 128 128 int count = 0; … … 131 131 { 132 132 int side = plane.Side(*it, SIDE_TOLERANCE); 133 //Debug << "side: " << side << " " << plane.Distance(*it) << endl; 134 133 135 134 if (side > 0) 136 135 onFrontSide = true; … … 147 146 { 148 147 // Decide if plane and surface normal are same 149 if (DotProd(plane.mNormal, GetSupportingPlane().mNormal) > 0.99)148 if (DotProd(plane.mNormal, GetSupportingPlane().mNormal) > dot_thres) 150 149 return COINCIDENT; // plane and polygon are coincident 151 150 else … … 164 163 165 164 // Decide if plane and surface normal are same 166 if (DotProd(plane.mNormal, GetSupportingPlane().mNormal) > float(1.0 - 1.0e-5))165 if (DotProd(plane.mNormal, GetSupportingPlane().mNormal) > dot_thres) 167 166 return COINCIDENT; // plane and polygon are coincident 168 167 else -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r293 r294 13 13 #include "Exporter.h" 14 14 15 #define INITIAL_COST 999999// unreachable high initial cost for heuristic evaluation16 17 15 int BspTree::sTermMaxPolygons = 10; 18 16 int BspTree::sTermMaxDepth = 20; … … 24 22 contribution for a balanced tree. 25 23 */ 26 int BspTree::sLeastSplitsTable[4] = {0, 0, 1, 0};24 float BspTree::sLeastSplitsTable[] = {0, 0, 1, 0}; 27 25 /** Evaluates split plane classification with respect to the plane's 28 26 contribution for a minimum number splits in the tree. 29 27 */ 30 int BspTree::sBalancedTreeTable[4] = {-1, 1, 0, 0}; 31 32 const int FACTOR_BALANCE = 1; 33 const int FACTOR_LEAST_SPLITS = 1; 28 float BspTree::sBalancedTreeTable[] = {-1, 1, 0, 0}; 34 29 35 30 //int counter = 0; 36 //bool BspTree::displayDebug = false; 31 37 32 /****************************************************************/ 38 33 /* class BspNode implementation */ … … 151 146 Polygon3 *splitPoly = NULL; 152 147 #ifdef _Debug 153 Debug << " Splitting polygons of node " << this << " with plane " << mPlane << endl;148 Debug << "splitting polygons of node " << this << " with plane " << mPlane << endl; 154 149 #endif 155 150 while (!polys->empty()) … … 183 178 front_piece = new Polygon3(poly->mParent); 184 179 back_piece = new Polygon3(poly->mParent); 185 Debug << "*************\n"; 186 Debug << "initial poly\n" << *poly << endl; 180 187 181 //-- split polygon into front and back part 188 182 poly->Split(&mPlane, front_piece, back_piece); 189 183 190 184 ++ splits; // increase number of splits 191 192 if (front_piece->mVertices.size() >= 3) // check if polygon still valid185 // check if polygon still valid 186 if (front_piece->mVertices.size() >= 3) 193 187 frontPolys->push_back(front_piece); 194 else{ 195 Debug << "poly\n" << *poly << "split front piece not valid\n" << *front_piece << endl; 196 DEL_PTR(front_piece);} 188 else 189 DEL_PTR(front_piece); 190 // check if polygon still valid 191 if (back_piece->mVertices.size() >= 3) 192 backPolys->push_back(back_piece); 193 else 194 DEL_PTR(back_piece); 197 195 198 if (back_piece->mVertices.size() >= 3) // check if polygon still valid199 backPolys->push_back(back_piece);200 else{201 Debug << "poly\n" << *poly << "split back piece not valid\n" << *back_piece << endl;202 DEL_PTR(back_piece);}203 204 Debug << "*************\n";205 196 #ifdef _DEBUG 206 197 Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; … … 214 205 } 215 206 } 216 //Debug << "inside: " << inside << endl;217 207 } 218 208 … … 258 248 mTermMaxDepth(0), 259 249 mRoot(NULL), 250 mVerticalAxis(Vector3(0, 0, 1)), 260 251 //mStorePolys(true) 261 252 mStorePolys(false) … … 570 561 571 562 Debug << "**** Finished tree construction ****\n"; 572 Debug << "BSP tree contruction time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;563 Debug << "BSP tree contruction time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 573 564 } 574 565 … … 594 585 leaf->SetViewCell(viewCell); 595 586 viewCells->push_back(viewCell); 596 Debug << "creating new viewcell" << endl;587 // Debug << "creating new viewcell" << endl; 597 588 } 598 589 //-- add viewcell stored in split polygon … … 602 593 Debug << "ERROR: leaf already has view cell " << endl;//leaf->mViewCellIdx << endl; 603 594 604 //leaf->mViewCellIdx = counter; 605 Debug << "insert view cell " << tData.mViewCell << endl; 606 595 //leaf->mViewCellIdx = counter; Debug << "insert view cell " << tData.mViewCell << endl; 607 596 leaf->SetViewCell(dynamic_cast<ViewCell *>(tData.mViewCell)); 608 597 } … … 627 616 &coincident); 628 617 629 if ((backPolys->size() == 0) && (coincident.size() > 1)) 630 { 631 Debug << "WARNING: size " << (int)coincident.size() << " at depth " << tData.mDepth << ", #back polys: " << (int)backPolys->size() << ", #front polys: " << (int)frontPolys->size() << endl; 632 for (int i=0; i<coincident.size(); ++i) 633 Debug << "coincident poly " << i << ", vc: " << coincident[i]->mParent << "\n" << *coincident[i] << 634 "dotprod: " << DotProd(coincident[i]->GetSupportingPlane().mNormal, interior->GetPlane()->mNormal) << endl; 635 } 636 //Debug << "coincident size: " << coincident.size() << endl; 637 638 // get view cell associated with the first split polygon 618 // view cell associated with the first split polygon 639 619 ViewCell *viewCell = (coincident.size() > 0) ? 640 620 dynamic_cast<ViewCell *>(coincident.front()->mParent) : NULL; … … 700 680 701 681 // simple strategy: just take next polygon 702 if (sSplitPlaneStrategy ==NEXT_POLYGON)682 if (sSplitPlaneStrategy & NEXT_POLYGON) 703 683 { 704 684 return polys->front()->GetSupportingPlane(); 705 685 } 706 686 687 if (sSplitPlaneStrategy & VERTICAL_AXIS) 688 { 689 const float dot_thres = 0.999; 690 PolygonContainer::const_iterator it, it_end = polys->end(); 691 692 for (it = polys->begin(); it != it_end; ++ it) 693 { 694 if (DotProd((*it)->GetSupportingPlane().mNormal, mVerticalAxis) > dot_thres) 695 return (*it)->GetSupportingPlane(); 696 } 697 } 707 698 // use heuristics to find appropriate plane 708 699 return SelectPlaneHeuristics(polys, sMaxCandidates); … … 711 702 Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer *polygons, int maxTests) const 712 703 { 713 int lowestCost = INITIAL_COST;704 float lowestCost = MAX_FLOAT; 714 705 int bestPlaneIdx = 0; 715 706 … … 718 709 for (int i = 0; i < limit; ++ i) 719 710 { 720 int candidateIdx = Random((int)polygons->size()); // TODO: 711 int candidateIdx = Random((int)polygons->size()); // TODO: avoid testing same plane 2 times 721 712 Plane3 candidatePlane = (*polygons)[candidateIdx]->GetSupportingPlane(); 722 713 723 714 // evaluate current candidate 724 int candidateCost = EvalSplitPlane(polygons, candidatePlane);715 float candidateCost = EvalSplitPlane(polygons, candidatePlane); 725 716 726 717 if (candidateCost < lowestCost) … … 728 719 bestPlaneIdx = candidateIdx; 729 720 lowestCost = candidateCost; 730 //Debug << "new plane cost " << lowestCost << endl;731 721 } 732 722 } … … 736 726 } 737 727 738 int BspTree::EvalSplitPlane(PolygonContainer *polygons, const Plane3 &candidatePlane) const728 float BspTree::EvalSplitPlane(PolygonContainer *polygons, const Plane3 &candidatePlane) const 739 729 { 740 730 PolygonContainer::const_iterator it; 741 731 742 int sumBalanced = 0, sumLeastSplits = 0;732 float sumBalanced = 0, sumLeastSplits = 0; 743 733 744 734 for (it = polygons->begin(); it != polygons->end(); ++ it) … … 746 736 int classification = (*it)->ClassifyPlane(candidatePlane); 747 737 748 if ( (sSplitPlaneStrategy == COMBINED) || (sSplitPlaneStrategy == BALANCED_TREE))738 if (sSplitPlaneStrategy & BALANCED_TREE) 749 739 { 750 740 sumBalanced += sBalancedTreeTable[classification]; 751 741 } 752 742 753 if ( (sSplitPlaneStrategy == COMBINED) || (sSplitPlaneStrategy == LEAST_SPLITS))743 if (sSplitPlaneStrategy & LEAST_SPLITS) 754 744 { 755 745 sumLeastSplits += sLeastSplitsTable[classification]; … … 758 748 759 749 // return linear combination of both sums 760 return FACTOR_BALANCE * abs(sumBalanced) + FACTOR_LEAST_SPLITS *abs(sumLeastSplits);750 return fabs(sumBalanced) + fabs(sumLeastSplits); 761 751 } 762 752 … … 766 756 environment->GetIntValue("BspTree.Termination.maxPolygons", sTermMaxPolygons); 767 757 environment->GetIntValue("BspTree.maxCandidates", sMaxCandidates); 758 environment->GetIntValue("BspTree.splitPlaneStrategy", sSplitPlaneStrategy); 768 759 769 760 Debug << "BSP max depth: " << sTermMaxDepth << endl; 770 761 Debug << "BSP max polys: " << sTermMaxPolygons << endl; 771 762 Debug << "BSP max candidates: " << sMaxCandidates << endl; 772 773 //-- extract strategy to choose the next split plane774 char splitPlaneStrategyStr[60];775 776 environment->GetStringValue("BspTree.splitPlaneStrategy", splitPlaneStrategyStr);777 778 sSplitPlaneStrategy = BspTree::NEXT_POLYGON;779 780 if (strcmp(splitPlaneStrategyStr, "nextPolygon") == 0)781 sSplitPlaneStrategy = BspTree::NEXT_POLYGON;782 else if (strcmp(splitPlaneStrategyStr, "leastSplits") == 0)783 sSplitPlaneStrategy = BspTree::LEAST_SPLITS;784 else if (strcmp(splitPlaneStrategyStr, "balancedTree") == 0)785 sSplitPlaneStrategy = BspTree::BALANCED_TREE;786 else if (strcmp(splitPlaneStrategyStr, "combined") == 0)787 sSplitPlaneStrategy = BspTree::COMBINED;788 else789 {790 cerr << "Wrong BSP split plane strategy " << splitPlaneStrategyStr << endl;791 exit(1);792 }793 794 Debug << "Split plane heuristic: " << splitPlaneStrategyStr << endl;795 763 796 764 //-- parse BSP tree construction method -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r289 r294 344 344 345 345 /** Evaluates the contribution of the candidate split plane. 346 */ 347 int EvalSplitPlane(PolygonContainer *polygons, const Plane3 &candidatePlane) const; 346 @returns the cost of the candidate split plane 347 */ 348 float EvalSplitPlane(PolygonContainer *polygons, const Plane3 &candidatePlane) const; 348 349 349 350 /** Evaluates tree stats in the BSP tree leafs. … … 442 443 443 444 /// Strategies for choosing next split plane. 444 enum {NEXT_POLYGON, LEAST_SPLITS, BALANCED_TREE, COMBINED}; 445 enum {NEXT_POLYGON = 0, 446 LEAST_SPLITS = 2, 447 BALANCED_TREE = 4, 448 VERTICAL_AXIS = 8, 449 AXIS_ALIGNED = 16}; 445 450 446 451 /// box around the whole view domain 447 452 AxisAlignedBox3 mBox; 448 453 449 /// if view cell calculation is incremential450 bool mIsIncremential;451 452 454 /// if polygons should be stored in the tree 453 455 bool mStorePolys; 454 456 457 /// vertical axis of scene 458 Vector3 mVerticalAxis; 455 459 public: 456 460 /// Parses the environment and stores the global BSP tree parameters … … 472 476 contribution for a balanced tree. 473 477 */ 474 static int sLeastSplitsTable[4];478 static float sLeastSplitsTable[4]; 475 479 /** Evaluates split plane classification with respect to the plane's 476 480 contribution for a minimum number splits in the tree. 477 481 */ 478 static int sBalancedTreeTable[4];482 static float sBalancedTreeTable[4]; 479 483 }; 480 484 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp
r262 r294 517 517 Mesh *mesh = mViewCells->back()->GetMesh(); 518 518 #ifdef _DEBUG 519 Debug << "Viewcell :"519 Debug << "Viewcell: " 520 520 << mesh->mVertices[0] << " " << mesh->mVertices[1] << " " << mesh->mVertices[2] << " " 521 521 << mesh->mVertices[3] << " " << mesh->mVertices[4] << " " << mesh->mVertices[5] << "\n"; -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r292 r294 54 54 p->Export("vc_bsptree.x3d", false, false, true); 55 55 56 57 // export the complementary view cells, i.e., the view cells not in the tree. 56 //-- export the complementary view cells, i.e., the view cells not associated with leafs in the tree. 58 57 Exporter *exporter = Exporter::GetExporter("viewcells_compl.x3d"); 59 58 60 59 ViewCellContainer::iterator vc_compl_it; 61 60 ViewCellContainer vc_compl(p->mViewCells.size() + X3dExporter::foundViewCells.size()); 62 63 Debug << "here1" << endl; 61 64 62 sort(p->mViewCells.begin(), p->mViewCells.end()); 65 Debug << "here2.5 " << X3dExporter::foundViewCells.size() << endl;66 67 63 vc_compl_it = set_difference(p->mViewCells.begin(), p->mViewCells.end(), 68 64 X3dExporter::foundViewCells.begin(), X3dExporter::foundViewCells.end(), 69 65 vc_compl.begin()); 70 71 Debug << "here2" << endl;72 73 66 vc_compl.erase(vc_compl_it, vc_compl.end()); 74 67 75 Debug << "Complementary view cells: " << vc_compl.size() << endl;76 68 77 69 if (exporter) … … 79 71 exporter->ExportViewCells(&vc_compl); // export view cells 80 72 delete exporter; 81 } Debug << "here4" << endl;73 } 82 74 83 75 #endif
Note: See TracChangeset
for help on using the changeset viewer.