Changeset 295 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 09/21/05 10:29:41 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp
r209 r295 6 6 #include "AxisAlignedBox3.h" 7 7 #include "Ray.h" 8 #include "Polygon3.h" 8 9 9 10 #define FATAL Debug … … 43 44 Minimize(mMin, newpt); 44 45 Maximize(mMax, newpt); 46 } 47 48 void 49 AxisAlignedBox3::Include(const Polygon3 &newpoly) 50 { 51 VertexContainer::const_iterator it, it_end = newpoly.mVertices.end(); 52 53 for (it = newpoly.mVertices.begin(); it != it_end; ++ it) 54 Include(*it); 45 55 } 46 56 -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h
r265 r295 9 9 class Plane3; 10 10 class Ray; 11 11 class Polygon3; 12 12 13 13 // -------------------------------------------------------- … … 91 91 92 92 // the size of the box along all the axes 93 Vector3 Size() const { return mMax - mMin; }93 Vector3 Size() const { return mMax - mMin; } 94 94 95 95 // Return whether the box is unbounded. Unbounded boxes appear … … 99 99 // Expand the axis-aligned box to include the given object. 100 100 void Include(const Vector3 &newpt); 101 void Include(const Polygon3 &newpoly); 101 102 void Include(const AxisAlignedBox3 &bbox); 102 103 // Expand the axis-aligned box to include given values in particular axis -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r294 r295 3 3 #include "ViewCellBsp.h" // TODO: erase this 4 4 #include "Intersectable.h" 5 #include "AxisAlignedBox3.h" 5 6 6 7 // tolerance value for side relation … … 212 213 return true; 213 214 } 215 216 void Polygon3::IncludeInBox(const PolygonContainer &polys, AxisAlignedBox3 &box) 217 { 218 PolygonContainer::const_iterator it, it_end = polys.end(); 219 220 for (it = polys.begin(); it != it_end; ++ it) 221 box.Include(*(*it)); 222 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r289 r295 14 14 class Face; 15 15 class Intersectable; 16 16 class AxisAlignedBox3; 17 17 //typedef Vertex3 Vector3; 18 18 … … 65 65 bool CheckValid() const; 66 66 67 /** Includes polygons to axis aligned box. 68 */ 69 static void IncludeInBox(const PolygonContainer &polys, AxisAlignedBox3 &box); 70 67 71 /// vertices are connected in counterclockwise order. 68 72 VertexContainer mVertices; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r294 r295 245 245 246 246 BspTree::BspTree(): 247 mTermMaxPolygons(0),248 mTermMaxDepth(0),249 247 mRoot(NULL), 250 248 mVerticalAxis(Vector3(0, 0, 1)), … … 425 423 } 426 424 427 void BspTree::InitTree(int maxPolygons, int maxDepth)428 {429 mTermMaxPolygons = maxPolygons;430 mTermMaxDepth = maxDepth;431 mStat.nodes = 1;432 433 mBox.Initialize(); // initialise bsp tree bounding box434 }435 436 437 438 425 int BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent) 439 426 { … … 506 493 void BspTree::Construct(const ViewCellContainer &viewCells) 507 494 { 508 InitTree(sTermMaxPolygons, sTermMaxDepth); 495 mStat.nodes = 1; 496 mBox.Initialize(); // initialise bsp tree bounding box 509 497 510 498 // copy view cell meshes into one big polygon soup … … 520 508 void BspTree::Construct(const ObjectContainer &objects, ViewCellContainer *viewCells) 521 509 { 522 // take termination criteria from globals523 InitTree(sTermMaxPolygons, sTermMaxDepth);510 mStat.nodes = 1; 511 mBox.Initialize(); // initialise bsp tree bounding box 524 512 525 513 PolygonContainer *polys = new PolygonContainer(); … … 569 557 { 570 558 //-- terminate traversal 571 if ((tData.mPolygons->size() <= mTermMaxPolygons) || (tData.mDepth >= mTermMaxDepth))559 if ((tData.mPolygons->size() <= sTermMaxPolygons) || (tData.mDepth >= sTermMaxDepth)) 572 560 { 573 561 #ifdef _DEBUG … … 643 631 644 632 // add the new nodes to the tree + select subdivision plane 645 BspInterior *interior = new BspInterior(SelectPlane( polys));633 BspInterior *interior = new BspInterior(SelectPlane(*polys)); 646 634 647 635 #ifdef _DEBUG … … 671 659 } 672 660 673 Plane3 BspTree::SelectPlane( PolygonContainer *polys) const674 { 675 if (polys ->size() == 0)661 Plane3 BspTree::SelectPlane(const PolygonContainer &polys) const 662 { 663 if (polys.size() == 0) 676 664 { 677 665 Debug << "Warning: No split candidate available\n"; … … 682 670 if (sSplitPlaneStrategy & NEXT_POLYGON) 683 671 { 684 return polys->front()->GetSupportingPlane(); 685 } 686 687 if (sSplitPlaneStrategy & VERTICAL_AXIS) 672 return polys.front()->GetSupportingPlane(); 673 } 674 675 if (sSplitPlaneStrategy & AXIS_ALIGNED) 676 { 677 AxisAlignedBox3 box; 678 box.Initialize(); 679 680 Polygon3::IncludeInBox(polys, box); 681 682 int axis = box.Size().DrivingAxis(); 683 Vector3 norm(0,0,0); norm[axis] = 1; 684 685 Vector3 pt = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 686 687 return Plane3(norm, pt); 688 } 689 690 /*if (sSplitPlaneStrategy & DRIVING_AXIS) 688 691 { 689 692 const float dot_thres = 0.999; … … 695 698 return (*it)->GetSupportingPlane(); 696 699 } 697 } 700 }*/ 701 698 702 // use heuristics to find appropriate plane 699 703 return SelectPlaneHeuristics(polys, sMaxCandidates); 700 704 } 701 705 702 Plane3 BspTree::SelectPlaneHeuristics( PolygonContainer *polygons, int maxTests) const706 Plane3 BspTree::SelectPlaneHeuristics(const PolygonContainer &polys, int maxTests) const 703 707 { 704 708 float lowestCost = MAX_FLOAT; 705 709 int bestPlaneIdx = 0; 706 710 707 int limit = Min((int)poly gons->size(), maxTests);711 int limit = Min((int)polys.size(), maxTests); 708 712 709 713 for (int i = 0; i < limit; ++ i) 710 714 { 711 int candidateIdx = Random((int)polygons->size()); // TODO: avoid testing same plane 2 times712 Plane3 candidatePlane = (*polygons)[candidateIdx]->GetSupportingPlane();715 int candidateIdx = GetNextCandidateIdx((int)polys.size()); 716 Plane3 candidatePlane = polys[candidateIdx]->GetSupportingPlane(); 713 717 714 718 // evaluate current candidate 715 float candidateCost = EvalSplitPlane(poly gons, candidatePlane);719 float candidateCost = EvalSplitPlane(polys, candidatePlane); 716 720 717 721 if (candidateCost < lowestCost) … … 723 727 //Debug << "Plane lowest cost: " << lowestCost << endl; 724 728 725 return (*polygons)[bestPlaneIdx]->GetSupportingPlane(); 726 } 727 728 float BspTree::EvalSplitPlane(PolygonContainer *polygons, const Plane3 &candidatePlane) const 729 { 730 PolygonContainer::const_iterator it; 731 732 float sumBalanced = 0, sumLeastSplits = 0; 733 734 for (it = polygons->begin(); it != polygons->end(); ++ it) 735 { 736 int classification = (*it)->ClassifyPlane(candidatePlane); 729 return polys[bestPlaneIdx]->GetSupportingPlane(); 730 } 731 732 int BspTree::GetNextCandidateIdx(const int max) const 733 { 734 return Random(max); // TODO: avoid testing same plane 2 times 735 } 736 737 float BspTree::EvalSplitPlane(const PolygonContainer &polys, const Plane3 &candidatePlane) const 738 { 739 float sumBalanced = 0, sumLeastSplits, drivingAxis = 0; 740 741 if (sSplitPlaneStrategy & DRIVING_AXIS) 742 { 743 drivingAxis = (candidatePlane.mNormal.DrivingAxis() == mBox.Size().DrivingAxis()) ? 744 99.0f : 0.0f; // always prefer driving axis => very high value 745 } 746 if ((sSplitPlaneStrategy & BALANCED_TREE) || (sSplitPlaneStrategy & LEAST_SPLITS)) 747 { 748 PolygonContainer::const_iterator it, it_end = polys.end(); 737 749 738 if (sSplitPlaneStrategy & BALANCED_TREE) 739 { 740 sumBalanced += sBalancedTreeTable[classification]; 741 } 742 743 if (sSplitPlaneStrategy & LEAST_SPLITS) 744 { 745 sumLeastSplits += sLeastSplitsTable[classification]; 746 } 747 } 748 749 // return linear combination of both sums 750 return fabs(sumBalanced) + fabs(sumLeastSplits); 750 for (it = polys.begin(); it != it_end; ++ it) 751 { 752 int classification = (*it)->ClassifyPlane(candidatePlane); 753 754 if (sSplitPlaneStrategy & BALANCED_TREE) 755 sumBalanced += sBalancedTreeTable[classification]; 756 757 if (sSplitPlaneStrategy & LEAST_SPLITS) 758 sumLeastSplits += sLeastSplitsTable[classification]; 759 } 760 } 761 762 // return linear combination of the sums 763 return fabs(sumBalanced) + sumLeastSplits + drivingAxis; 751 764 } 752 765 … … 879 892 BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode); 880 893 881 if (data.mDepth >= mTermMaxDepth)894 if (data.mDepth >= sTermMaxDepth) 882 895 { 883 896 ++ mStat.maxDepthNodes; … … 898 911 #ifdef _DEBUG 899 912 Debug << "BSP Traversal data. Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), #polygons: " << 900 data.mPolygons->size() << " (max: " << mTermMaxPolygons << ")" << endl;913 data.mPolygons->size() << " (max: " << sTermMaxPolygons << ")" << endl; 901 914 #endif 902 915 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r294 r295 329 329 protected: 330 330 331 /** Initialises BSP tree.332 @param maxPolygons the maximal polygon count before termination of333 subdivision334 @param maxDepth the maximal depth before termination of335 subdivision336 */337 void InitTree(int maxPolygons, int maxDepth);338 339 331 /** Constructs the tree from the given list of polygons. 340 332 @param viewCells if not NULL, new view cells are … … 346 338 @returns the cost of the candidate split plane 347 339 */ 348 float EvalSplitPlane( PolygonContainer *polygons, const Plane3 &candidatePlane) const;340 float EvalSplitPlane(const PolygonContainer &polys, const Plane3 &candidatePlane) const; 349 341 350 342 /** Evaluates tree stats in the BSP tree leafs. … … 363 355 @param polys the polygon list on which the split decition is based 364 356 */ 365 Plane3 SelectPlane( PolygonContainer *polys) const;357 Plane3 SelectPlane(const PolygonContainer &polys) const; 366 358 367 359 /** Filters next view cell down the tree and inserts it into the appropriate leaves … … 402 394 @param maxTests the maximal number of candidate tests 403 395 */ 404 Plane3 SelectPlaneHeuristics( PolygonContainer *polygons,int maxTests) const;396 Plane3 SelectPlaneHeuristics(const PolygonContainer &polys, const int maxTests) const; 405 397 406 398 /** Extracts the meshes of the objects and copies them into the mesh. … … 430 422 int CastRay(Ray &ray); 431 423 424 /** returns next candidate index 425 @param max the range of candidates 426 */ 427 inline int GetNextCandidateIdx(const int max) const; 428 432 429 /// Pointer to the root of the tree 433 430 BspNode *mRoot; … … 438 435 BspTreeStatistics mStat; 439 436 440 /// local maximal polygons (changes depending on method)441 int mTermMaxPolygons;442 int mTermMaxDepth;443 444 437 /// Strategies for choosing next split plane. 445 438 enum {NEXT_POLYGON = 0, 446 439 LEAST_SPLITS = 2, 447 440 BALANCED_TREE = 4, 448 VERTICAL_AXIS = 8,441 DRIVING_AXIS = 8, 449 442 AXIS_ALIGNED = 16}; 450 443 … … 457 450 /// vertical axis of scene 458 451 Vector3 mVerticalAxis; 452 459 453 public: 460 454 /// Parses the environment and stores the global BSP tree parameters
Note: See TracChangeset
for help on using the changeset viewer.