Changeset 1006 for GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
- Timestamp:
- 06/09/06 01:26:46 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1002 r1006 1 #ifndef _Vsp BspTree_H__2 #define _Vsp BspTree_H__1 #ifndef _VspOspTree_H__ 2 #define _VspOspTree_H__ 3 3 4 4 #include "Mesh.h" … … 31 31 32 32 /** 33 This is a view space partitioning specialised BSPtree. 34 There are no polygon splits, but we split the sample rays. 35 The candidates for the next split plane are evaluated only 36 by checking the sampled visibility information. 37 The polygons are employed merely as candidates for the next split planes. 33 This class implements a structure holding two different hierarchies, 34 one for object space partitioning and one for view space partitioning. 35 36 The object space and the view space are subdivided using a cost heuristics. 37 If an object space split or a view space split is chosen is also evaluated 38 based on the heuristics. 39 40 The view space heuristics is evaluated by weighting and adding the pvss of the back and 41 front node of each specific split. unlike for the standalone method vspbsp tree, 42 the pvs of an object would not be the pvs of single object but that of all objects 43 which are contained in the same leaf of the object subdivision. This could be done 44 by storing the pointer to the object space partition parent, which would allow access to all children. 45 Another possibility is to include traced kd-cells in the ray casing process. 46 47 Accordingly, the object space heuristics is evaluated by storing a pvs of view cells with each object. 48 the contribution to an object to the pvs is the number of view cells it can be seen from. 49 50 51 There is a potential efficiency problem involved in a sense that once a certain type 52 of split is chosen for view space / object space, the candidates for the next split of 53 object space / view space must be reevaluated. 54 38 55 */ 39 class Vsp BspTree56 class VspOspTree 40 57 { 41 58 friend class ViewCellsParseHandlers; 42 59 friend class VspBspViewCellsManager; 60 43 61 public: 44 62 63 /** A definition for an axis aligned plane. 64 */ 65 struct AxisAlignedPlane 66 { 67 public: 68 int mAxis; 69 float mPosition; 70 }; 71 45 72 /** Additional data which is passed down the BSP tree during traversal. 46 73 */ 47 class Vsp BspTraversalData74 class VspOspTraversalData 48 75 { 49 76 public: 50 77 /// the current node 51 78 BspNode *mNode; 52 /// polygonal data for splitting53 PolygonContainer *mPolygons;54 79 /// current depth 55 80 int mDepth; … … 58 83 /// the probability that this node contains view point 59 84 float mProbability; 60 /// geometry of node as induced by planes61 BspNodeGeometry *mGeometry;85 /// the bounding box of the node 86 AxisAlignedBox3 mBoundingBox; 62 87 /// pvs size 63 88 int mPvs; 64 89 /// how often this branch has missed the max-cost ratio 65 90 int mMaxCostMisses; 66 /// if this node is a kd-node (i.e., boundaries are axis aligned67 bool mIsKdNode;68 91 // current axis 69 92 int mAxis; … … 80 103 81 104 82 Vsp BspTraversalData():105 VspOspTraversalData(): 83 106 mNode(NULL), 84 mPolygons(NULL),85 107 mDepth(0), 86 108 mRays(NULL), 87 109 mPvs(0), 88 110 mProbability(0.0), 89 mGeometry(NULL),90 111 mMaxCostMisses(0), 91 mIsKdNode(false),92 112 mPriority(0), 93 113 mAxis(0) 94 114 {} 95 115 96 VspBspTraversalData(BspNode *node, 97 PolygonContainer *polys, 116 VspOspTraversalData(BspNode *node, 98 117 const int depth, 99 118 RayInfoContainer *rays, 100 119 const int pvs, 101 120 const float p, 102 BspNodeGeometry *geom):121 const AxisAlignedBox3 &box): 103 122 mNode(node), 104 mPolygons(polys),105 123 mDepth(depth), 106 124 mRays(rays), 107 125 mPvs(pvs), 108 126 mProbability(p), 109 m Geometry(geom),127 mBoundingBox(box), 110 128 mMaxCostMisses(0), 111 mIsKdNode(false),112 129 mPriority(0), 113 130 mAxis(0) 114 131 {} 115 132 116 Vsp BspTraversalData(PolygonContainer *polys,133 VspOspTraversalData(PolygonContainer *polys, 117 134 const int depth, 118 135 RayInfoContainer *rays, 119 BspNodeGeometry *geom):136 const AxisAlignedBox3 &box): 120 137 mNode(NULL), 121 mPolygons(polys),122 138 mDepth(depth), 123 139 mRays(rays), 124 140 mPvs(0), 125 141 mProbability(0), 126 mGeometry(geom),127 142 mMaxCostMisses(0), 128 m IsKdNode(false),129 m Axis(0)143 mAxis(0), 144 mBoundingBox(box) 130 145 {} 131 146 … … 141 156 void Clear() 142 157 { 143 DEL_PTR(mPolygons);144 158 DEL_PTR(mRays); 145 DEL_PTR(mGeometry); 146 } 147 148 friend bool operator<(const VspBspTraversalData &a, const VspBspTraversalData &b) 159 } 160 161 friend bool operator<(const VspOspTraversalData &a, const VspOspTraversalData &b) 149 162 { 150 163 return a.GetCost() < b.GetCost(); … … 153 166 154 167 155 typedef std::priority_queue<Vsp BspTraversalData> VspBspTraversalQueue;156 157 158 struct Vsp BspSplitCandidate168 typedef std::priority_queue<VspOspTraversalData> VspOspTraversalQueue; 169 170 171 struct VspOspSplitCandidate 159 172 { 160 /// the current node 161 Plane3 mSplitPlane; 162 /// split axis of this plane (0, 1, 2, or 3 if non-axis-aligned) 163 int mSplitAxis; 173 /// the current plane 174 AxisAlignedPlane mSplitPlane; 164 175 /// the number of misses of max cost ratio until this split 165 176 int mMaxCostMisses; 166 167 // parent data 168 VspBspTraversalData mParentData; 169 // cost of applying this split 177 /// parent data 178 VspOspTraversalData mParentData; 179 /// cost of applying this split 170 180 float mRenderCost; 171 181 172 Vsp BspSplitCandidate(): mRenderCost(0)182 VspOspSplitCandidate(): mRenderCost(0) 173 183 {}; 174 184 175 Vsp BspSplitCandidate(const Plane3 &plane, const VspBspTraversalData &tData):185 VspOspSplitCandidate(const AxisAlignedPlane &plane, const VspOspTraversalData &tData): 176 186 mSplitPlane(plane), mParentData(tData), mRenderCost(0) 177 187 {} … … 189 199 } 190 200 191 friend bool operator<(const Vsp BspSplitCandidate &a, const VspBspSplitCandidate &b)201 friend bool operator<(const VspOspSplitCandidate &a, const VspOspSplitCandidate &b) 192 202 { 193 203 return a.GetCost() < b.GetCost(); … … 195 205 }; 196 206 197 typedef std::priority_queue<Vsp BspSplitCandidate> VspBspSplitQueue;207 typedef std::priority_queue<VspOspSplitCandidate> VspOspSplitQueue; 198 208 199 209 /** Default constructor creating an empty tree. 200 210 */ 201 VspBspTree(); 202 203 204 /** Constructor creating an empty tree. Loads parameters 205 from an environment file. 206 */ 207 VspBspTree(Environment *env); 211 VspOspTree(); 208 212 209 213 /** Default destructor. 210 214 */ 211 ~Vsp BspTree();215 ~VspOspTree(); 212 216 213 217 /** Returns BSP Tree statistics. … … 252 256 int CastRay(Ray &ray); 253 257 254 /// bsp tree construction types255 enum {FROM_INPUT_VIEW_CELLS, FROM_SCENE_GEOMETRY, FROM_SAMPLES};256 258 257 259 /** finds neighbouring leaves of this tree node. … … 260 262 vector<BspLeaf *> &neighbors, 261 263 const bool onlyUnmailed) const; 262 263 /** Constructs geometry associated with the half space intersections264 leading to this node.265 */266 void ConstructGeometry(BspNode *n, BspNodeGeometry &geom) const;267 268 /** Construct geometry of view cell.269 */270 void ConstructGeometry(ViewCell *vc, BspNodeGeometry &geom) const;271 264 272 265 /** Returns random leaf of BSP tree. … … 400 393 /** faster evaluation of split plane cost for kd axis aligned cells. 401 394 */ 402 float Eval AxisAlignedSplitCost(const VspBspTraversalData &data,403 404 405 406 407 395 float EvalSplitCost(const VspOspTraversalData &data, 396 const AxisAlignedBox3 &box, 397 const int axis, 398 const float &position, 399 float &pFront, 400 float &pBack) const; 408 401 409 402 /** Evaluates candidate for splitting. 410 403 */ 411 void EvalSplitCandidate(Vsp BspTraversalData &tData, VspBspSplitCandidate &splitData);404 void EvalSplitCandidate(VspOspTraversalData &tData, VspOspSplitCandidate &splitData); 412 405 413 406 /** Computes priority of the traversal data and stores it in tData. 414 407 */ 415 void EvalPriority(Vsp BspTraversalData &tData) const;408 void EvalPriority(VspOspTraversalData &tData) const; 416 409 417 410 /** Evaluates render cost decrease of next split. 418 411 */ 419 412 float EvalRenderCostDecrease(const Plane3 &candidatePlane, 420 const Vsp BspTraversalData &data) const;413 const VspOspTraversalData &data) const; 421 414 422 415 /** Constructs tree using the split priority queue. 423 416 */ 424 void Construct WithSplitQueue(const PolygonContainer &polys,RayInfoContainer *rays);417 void Construct(RayInfoContainer *rays); 425 418 426 419 /** Collects view cells in the subtree under root. … … 451 444 /** Evaluates tree stats in the BSP tree leafs. 452 445 */ 453 void EvaluateLeafStats(const Vsp BspTraversalData &data);446 void EvaluateLeafStats(const VspOspTraversalData &data); 454 447 455 448 /** Subdivides node with respect to the traversal data. … … 458 451 @returns new root of the subtree 459 452 */ 460 BspNode *Subdivide(VspBspTraversalQueue &tStack, 461 VspBspTraversalData &tData); 462 463 BspNode *Subdivide(VspBspSplitQueue &tQueue, 464 VspBspSplitCandidate &splitCandidate); 465 466 /** Constructs the tree from the given traversal data. 467 @param polys stores set of polygons on which subdivision may be based 468 @param rays storesset of rays on which subdivision may be based 469 */ 470 void Construct(const PolygonContainer &polys, RayInfoContainer *rays); 471 472 /** Selects the best possible splitting plane. 473 @param plane returns the split plane 474 @param leaf the leaf to be split 475 @param polys the polygon list on which the split decition is based 476 @param rays ray container on which selection may be based 477 @note the polygons can be reordered in the process 478 @returns true if the cost of the split is under maxCostRatio 479 480 */ 481 bool SelectPlane(Plane3 &plane, 482 BspLeaf *leaf, 483 VspBspTraversalData &data, 484 VspBspTraversalData &frontData, 485 VspBspTraversalData &backData, 486 int &splitAxis); 487 488 /** Strategies where the effect of the split plane is tested 489 on all input rays. 490 491 @returns the cost of the candidate split plane 492 */ 493 float EvalSplitPlaneCost(const Plane3 &candidatePlane, 494 const VspBspTraversalData &data, 495 BspNodeGeometry &geomFront, 496 BspNodeGeometry &geomBack, 497 float &pFront, 498 float &pBack) const; 499 453 BspNode *Subdivide(VspOspSplitQueue &tQueue, 454 VspOspSplitCandidate &splitCandidate); 455 456 500 457 /** Subdivides leaf. 501 458 @param leaf the leaf to be subdivided … … 513 470 514 471 BspInterior *SubdivideNode(const Plane3 &splitPlane, 515 VspBspTraversalData &tData, 516 VspBspTraversalData &frontData, 517 VspBspTraversalData &backData, 518 PolygonContainer &coincident); 519 520 /** Extracts the meshes of the objects and adds them to polygons. 521 Adds object aabb to the aabb of the tree. 522 @param maxPolys the maximal number of objects to be stored as polygons 523 @returns the number of polygons 524 */ 525 int AddToPolygonSoup(const ObjectContainer &objects, 526 PolygonContainer &polys, 527 int maxObjects = 0); 528 529 /** Extracts the meshes of the view cells and and adds them to polygons. 530 Adds view cell aabb to the aabb of the tree. 531 @param maxPolys the maximal number of objects to be stored as polygons 532 @returns the number of polygons 533 */ 534 int AddToPolygonSoup(const ViewCellContainer &viewCells, 535 PolygonContainer &polys, 536 int maxObjects = 0); 537 538 /** Extract polygons of this mesh and add to polygon container. 539 @param mesh the mesh that drives the polygon construction 540 @param parent the parent intersectable this polygon is constructed from 541 @returns number of polygons 542 */ 543 int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent); 472 VspOspTraversalData &tData, 473 VspOspTraversalData &frontData, 474 VspOspTraversalData &backData); 544 475 545 476 /** Selects an axis aligned for the next split. 546 477 @returns cost for this split 547 478 */ 548 float SelectAxisAlignedPlane(Plane3 &plane, 549 const VspBspTraversalData &tData, 550 int &axis, 551 BspNodeGeometry **frontGeom, 552 BspNodeGeometry **backGeom, 553 float &pFront, 554 float &pBack, 555 const bool useKdSplit); 479 float SelectPlane(const VspOspTraversalData &tData, 480 AxisAlignedPlane &plane, 481 float &pFront, 482 float &pBack); 556 483 557 484 /** Sorts split candidates for surface area heuristics for axis aligned splits. … … 573 500 float &position); 574 501 575 /** Selects an axis aligned split plane.576 @Returns true if split is valied577 */578 bool SelectAxisAlignedPlane(Plane3 &plane, const PolygonContainer &polys) const;579 580 502 /** Subdivides the rays into front and back rays according to the split plane. 581 503 … … 593 515 RayInfoContainer &backRays) const; 594 516 595 596 /** Extracts the split planes representing the space bounded by node n.597 */598 void ExtractHalfSpaces(BspNode *n, vector<Plane3> &halfSpaces) const;599 600 517 /** Adds the object to the pvs of the front and back leaf with a given classification. 601 518 … … 618 535 /** Returns true if tree can be terminated. 619 536 */ 620 inline bool LocalTerminationCriteriaMet(const Vsp BspTraversalData &data) const;537 inline bool LocalTerminationCriteriaMet(const VspOspTraversalData &data) const; 621 538 622 539 /** Returns true if global tree can be terminated. 623 540 */ 624 inline bool GlobalTerminationCriteriaMet(const VspBspTraversalData &data) const; 625 626 /** Computes accumulated ray lenght of this rays. 627 */ 628 float AccumulatedRayLength(const RayInfoContainer &rays) const; 629 630 /** Splits polygons with respect to the split plane. 631 632 @param plane the split plane 633 @param polys the polygons to be split. the polygons are consumed and 634 distributed to the containers frontPolys, backPolys, coincident. 635 @param frontPolys returns the polygons in the front of the split plane 636 @param backPolys returns the polygons in the back of the split plane 637 @param coincident returns the polygons coincident to the split plane 638 639 @returns the number of splits 640 */ 641 int SplitPolygons(const Plane3 &plane, 642 PolygonContainer &polys, 643 PolygonContainer &frontPolys, 644 PolygonContainer &backPolys, 645 PolygonContainer &coincident) const; 541 inline bool GlobalTerminationCriteriaMet(const VspOspTraversalData &data) const; 646 542 647 543 /** Adds ray sample contributions to the PVS. … … 655 551 int &contributingSamples); 656 552 657 658 659 660 661 662 /** Take 3 ray endpoints, where two are minimum and one a maximum663 point or the other way round.664 */665 Plane3 ChooseCandidatePlane(const RayInfoContainer &rays) const;666 667 /** Take plane normal as plane normal and the midpoint of the ray.668 PROBLEM: does not resemble any point where visibility is669 likely to change670 */671 Plane3 ChooseCandidatePlane2(const RayInfoContainer &rays) const;672 673 /** Fit the plane between the two lines so that the plane674 has equal shortest distance to both lines.675 */676 Plane3 ChooseCandidatePlane3(const RayInfoContainer &rays) const;677 678 /** Collects candidates for merging.679 @param leaves the leaves to be merged680 @returns number of leaves in queue681 */682 int CollectMergeCandidates(const vector<BspLeaf *> leaves, vector<MergeCandidate> &candidates);683 684 /** Collects candidates for the merge in the merge queue.685 @returns number of leaves in queue686 */687 int CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);688 689 /** Preprocesses polygons and throws out all polygons which are coincident to690 the view space box faces (they can be problematic).691 */692 void PreprocessPolygons(PolygonContainer &polys);693 694 553 /** Propagates valid flag up the tree. 695 554 */ … … 707 566 /** Returns estimated memory usage of tree. 708 567 */ 709 //float GetMemUsage(const VspBspTraversalQueue &tstack) const;710 568 float GetMemUsage() const; 711 569 712 570 571 protected: 572 573 ViewCellsManager *mViewCellsManager; 574 vector<SortableEntry> *mSplitCandidates; 713 575 714 576 /// Pointer to the root of the tree … … 716 578 717 579 BspTreeStatistics mBspStats; 718 719 /// Strategies for choosing next split plane. 720 enum {NO_STRATEGY = 0, 721 RANDOM_POLYGON = 1, 722 AXIS_ALIGNED = 2, 723 LEAST_RAY_SPLITS = 256, 724 BALANCED_RAYS = 512, 725 PVS = 1024 726 }; 580 581 /// View cell corresponding to the space outside the valid view space 582 BspViewCell *mOutOfBoundsCell; 727 583 728 584 /// box around the whole view domain 729 585 AxisAlignedBox3 mBox; 730 586 731 bool mUseCostHeuristics; 587 588 589 //-- local termination 732 590 733 591 /// minimal number of rays before subdivision termination … … 741 599 /// maximal contribution per ray 742 600 float mTermMaxRayContribution; 743 /// minimal accumulated ray length744 float mTermMinAccRayLength;745 746 //HACK747 int mTermMinPolygons;748 749 float mTermMinGlobalCostRatio;750 int mTermGlobalCostMissTolerance;751 752 int mGlobalCostMisses;753 754 bool mUseSplitCostQueue;755 //-- termination criteria for axis aligned split756 757 /// minimal number of rays for axis aligned split758 int mTermMinRaysForAxisAligned;759 // max ray contribution760 float mTermMaxRayContriForAxisAligned;761 762 /// strategy to get the best split plane763 int mSplitPlaneStrategy;764 /// number of candidates evaluated for the next split plane765 int mMaxPolyCandidates;766 /// number of candidates for split planes evaluated using the rays767 int mMaxRayCandidates;768 /// balancing factor for PVS criterium769 float mCtDivCi;770 771 bool mUseDrivingAxisForMaxCost;772 //-- axis aligned split criteria773 float mAxisAlignedCtDivCi;774 /// spezifies the split border of the axis aligned split775 float mAxisAlignedSplitBorder;776 777 601 /// maximal acceptable cost ratio 778 602 float mTermMaxCostRatio; … … 780 604 int mTermMissTolerance; 781 605 782 //-- factors guiding the split plane heuristics 783 float mLeastRaySplitsFactor; 784 float mBalancedRaysFactor; 785 float mPvsFactor; 786 787 /// if area or volume should be used for PVS heuristics 788 bool mUseAreaForPvs; 789 /// tolerance for polygon split 790 float mEpsilon; 791 /// maximal number of test rays used to evaluate candidate split plane 792 int mMaxTests; 793 /// normalizes different bsp split plane criteria 794 float mCostNormalizer; 606 607 //-- global criteria 608 float mTermMinGlobalCostRatio; 609 int mTermGlobalCostMissTolerance; 610 int mGlobalCostMisses; 611 795 612 /// maximal number of view cells 796 613 int mMaxViewCells; 797 798 ofstream mSubdivisionStats;799 800 // if rays should be stored in leaves801 bool mStoreRays;802 803 /// if only driving axis should be used for split804 bool mOnlyDrivingAxis;805 806 ViewCellsManager *mViewCellsManager;807 808 vector<SortableEntry> *mSplitCandidates;809 810 811 float mRenderCostWeight;812 /// View cell corresponding to the space outside the valid view space813 BspViewCell *mOutOfBoundsCell;814 815 614 /// maximal tree memory 816 615 float mMaxMemory; 817 616 /// the tree is out of memory 818 617 bool mOutOfMemory; 819 820 float mTotalCost; 821 int mTotalPvsSize; 822 823 float mMinBand;824 float mMaxBand;825 826 //int mSplits;827 /// subdivision stats output file828 ofstream mSubdivsionStats;618 619 620 621 //-- split heuristics based parameters 622 623 bool mUseCostHeuristics; 624 /// balancing factor for PVS criterium 625 float mCtDivCi; 626 /// if only driving axis should be used for split 627 bool mOnlyDrivingAxis; 829 628 /// if random split axis should be used 830 629 bool mUseRandomAxis; 831 /// use polygon split whenever there are polys left 832 bool mUsePolygonSplitIfAvailable; 630 /// if vsp bsp tree should simulate octree 631 bool mCirculatingAxis; 632 /// minimal relative position where the split axis can be placed 633 float mMinBand; 634 /// maximal relative position where the split axis can be placed 635 float mMaxBand; 636 637 833 638 /// current time stamp (used for keeping split history) 834 639 int mTimeStamp; 640 // if rays should be stored in leaves 641 bool mStoreRays; 642 643 /// epsilon for geometric comparisons 644 float mEpsilon; 645 646 /// if we should use breath first priority for the splits 647 int mNodePriorityQueueType; 648 649 // priority queue strategy 650 enum {BREATH_FIRST, DEPTH_FIRST, COST_BASED}; 651 652 653 /// subdivision stats output file 654 ofstream mSubdivisionStats; 655 /// keeps track of cost during subdivision 656 float mTotalCost; 657 /// keeps track of overall pvs size during subdivision 658 int mTotalPvsSize; 835 659 /// number of currenly generated view cells 836 660 int mCreatedViewCells; 837 /// if vsp bsp tree should simulate octree 838 bool mCirculatingAxis; 839 840 /// if we should use breath first priority for the splits 841 int mNodePriorityQueueType; 842 843 bool mEmptyViewCellsMergeAllowed; 844 845 // priority queue strategy 846 enum {BREATH_FIRST, DEPTH_FIRST, COST_BASED}; 661 847 662 private: 848 663
Note: See TracChangeset
for help on using the changeset viewer.