Changeset 448 for trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
- Timestamp:
- 12/05/05 04:42:54 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r445 r448 9 9 #include "VssRay.h" 10 10 #include "RayInfo.h" 11 #include "ViewCellBsp.h" 11 12 12 13 class ViewCell; … … 14 15 class Plane3; 15 16 class VspBspTree; 16 class VspBspInterior;17 class VspBspNode;17 class BspInterior; 18 class BspNode; 18 19 class AxisAlignedBox3; 19 20 class Ray; 20 21 21 class VspBspNodeGeometry 22 { 23 public: 24 VspBspNodeGeometry() 25 {}; 26 27 ~VspBspNodeGeometry(); 28 29 float GetArea() const; 30 31 /** Computes new cell based on the old cell definition and a new split plane 32 @param side indicates which side of the halfspace 33 */ 34 void SplitGeometry(VspBspNodeGeometry &front, 35 VspBspNodeGeometry &back, 36 const VspBspTree &tree, 37 const Plane3 &splitPlane) const; 38 39 Polygon3 *SplitPolygon(Polygon3 *poly, const VspBspTree &tree) const; 40 41 PolygonContainer mPolys; 42 }; 43 44 /** Data structure used for optimized ray casting. 22 /*class BspNodeGeometry; 23 class BspTreeStatistics; 24 class BspViewCellsStatistics; 25 class BspNode; 26 class BspLeaf; 27 class BspInterior; 45 28 */ 46 struct VspBspRayTraversalData47 {48 VspBspNode *mNode;49 Vector3 mExitPoint;50 float mMaxT;51 52 VspBspRayTraversalData() {}53 54 VspBspRayTraversalData(VspBspNode *n, const Vector3 &extp, const float maxt):55 mNode(n), mExitPoint(extp), mMaxT(maxt)56 {}57 };58 59 class VspBspTreeStatistics: public StatisticsBase60 {61 public:62 // total number of nodes63 int nodes;64 // number of splits65 int splits;66 // totals number of rays67 int rays;68 // maximal reached depth69 int maxDepth;70 // minimal depth71 int minDepth;72 73 // max depth nodes74 int maxDepthNodes;75 // minimum depth nodes76 int minDepthNodes;77 // max depth nodes78 int minPvsNodes;79 // nodes with minimum PVS80 int minRaysNodes;81 // max ray contribution nodes82 int maxRayContribNodes;83 // minimum area nodes84 int minAreaNodes;85 86 // max number of rays per node87 int maxObjectRefs;88 // accumulated depth (used to compute average)89 int accumDepth;90 // number of initial polygons91 int polys;92 /// samples contributing to pvs93 int contributingSamples;94 /// sample contributions to pvs95 int sampleContributions;96 /// largest pvs97 int largestPvs;98 99 // Constructor100 VspBspTreeStatistics()101 {102 Reset();103 }104 105 int Nodes() const {return nodes;}106 int Interior() const { return nodes / 2; }107 int Leaves() const { return (nodes / 2) + 1; }108 109 // TODO: computation wrong110 double AvgDepth() const { return accumDepth / (double)Leaves();};111 112 void Reset()113 {114 nodes = 0;115 splits = 0;116 117 maxDepth = 0;118 minDepth = 99999;119 polys = 0;120 accumDepth = 0;121 122 maxDepthNodes = 0;123 minPvsNodes = 0;124 minRaysNodes = 0;125 maxRayContribNodes = 0;126 minAreaNodes = 0;127 128 contributingSamples = 0;129 sampleContributions = 0;130 }131 132 void Print(ostream &app) const;133 134 friend ostream &operator<<(ostream &s, const VspBspTreeStatistics &stat)135 {136 stat.Print(s);137 return s;138 }139 };140 141 class VspBspViewCellsStatistics: public StatisticsBase142 {143 public:144 145 /// number of view cells146 int viewCells;147 148 /// size of the PVS149 int pvs;150 151 /// largest PVS of all view cells152 int maxPvs;153 154 /// smallest PVS of all view cells155 int minPvs;156 157 /// view cells with empty PVS158 int emptyPvs;159 160 /// number of bsp leaves covering the view space161 int bspLeaves;162 163 /// largest number of leaves covered by one view cell164 int maxVspBspLeaves;165 166 // Constructor167 VspBspViewCellsStatistics()168 {169 Reset();170 }171 172 double AvgVspBspLeaves() const {return (double)bspLeaves / (double)viewCells;};173 double AvgPvs() const {return (double)pvs / (double)viewCells;};174 175 void Reset()176 {177 viewCells = 0;178 pvs = 0;179 maxPvs = 0;180 181 minPvs = 999999;182 emptyPvs = 0;183 bspLeaves = 0;184 maxVspBspLeaves = 0;185 }186 187 void Print(ostream &app) const;188 189 friend ostream &operator<<(ostream &s, const VspBspViewCellsStatistics &stat)190 {191 stat.Print(s);192 return s;193 }194 };195 196 /**197 VspBspNode abstract class serving for interior and leaf node implementation198 */199 class VspBspNode200 {201 friend class VspBspTree;202 203 public:204 VspBspNode();205 virtual ~VspBspNode(){};206 VspBspNode(VspBspInterior *parent);207 208 /** Determines whether this node is a leaf or not209 @return true if leaf210 */211 virtual bool IsLeaf() const = 0;212 213 /** Determines whether this node is a root214 @return true if root215 */216 virtual bool IsRoot() const;217 218 /** Returns parent node.219 */220 VspBspInterior *GetParent();221 222 /** Sets parent node.223 */224 void SetParent(VspBspInterior *parent);225 226 227 static int sMailId;228 int mMailbox;229 230 void Mail() { mMailbox = sMailId; }231 static void NewMail() { ++ sMailId; }232 bool Mailed() const { return mMailbox == sMailId; }233 234 protected:235 236 /// parent of this node237 VspBspInterior *mParent;238 };239 240 /** BSP interior node implementation241 */242 class VspBspInterior : public VspBspNode243 {244 friend class VspBspTree;245 public:246 /** Standard contructor taking split plane as argument.247 */248 VspBspInterior(const Plane3 &plane);249 ~VspBspInterior();250 /** @return false since it is an interior node251 */252 bool IsLeaf() const;253 254 VspBspNode *GetBack();255 VspBspNode *GetFront();256 257 Plane3 *GetPlane();258 259 void ReplaceChildLink(VspBspNode *oldChild, VspBspNode *newChild);260 void SetupChildLinks(VspBspNode *b, VspBspNode *f);261 262 /** Splits polygons with respect to the split plane.263 @param polys the polygons to be split. the polygons are consumed and264 distributed to the containers frontPolys, backPolys, coincident.265 @param frontPolys returns the polygons in the front of the split plane266 @param backPolys returns the polygons in the back of the split plane267 @param coincident returns the polygons coincident to the split plane268 269 @returns the number of splits270 */271 int SplitPolygons(PolygonContainer &polys,272 PolygonContainer &frontPolys,273 PolygonContainer &backPolys,274 PolygonContainer &coincident);275 276 friend ostream &operator<<(ostream &s, const VspBspInterior &A)277 {278 return s << A.mPlane;279 }280 281 protected:282 283 /// Splitting plane corresponding to this node284 Plane3 mPlane;285 /// back node286 VspBspNode *mBack;287 /// front node288 VspBspNode *mFront;289 };290 291 /** BSP leaf node implementation.292 */293 class VspBspLeaf : public VspBspNode294 {295 friend class VspBspTree;296 297 public:298 VspBspLeaf();299 VspBspLeaf(BspViewCell *viewCell);300 VspBspLeaf(VspBspInterior *parent);301 VspBspLeaf(VspBspInterior *parent, BspViewCell *viewCell);302 303 /** @return true since it is an interior node304 */305 bool IsLeaf() const;306 307 /** Returns pointer of view cell.308 */309 BspViewCell *GetViewCell() const;310 311 /** Sets pointer to view cell.312 */313 void SetViewCell(BspViewCell *viewCell);314 315 /** Adds ray sample contributions to the PVS.316 @param sampleContributions the number contributions of the samples317 @param contributingSampels the number of contributing rays318 319 */320 void AddToPvs(const RayInfoContainer &rays,321 int &sampleContributions,322 int &contributingSamples,323 bool storeLeavesWithRays = false);324 325 protected:326 327 /// if NULL this does not correspond to feasible viewcell328 BspViewCell *mViewCell;329 };330 29 331 30 /** … … 345 44 { 346 45 /// the current node 347 VspBspNode *mNode;46 BspNode *mNode; 348 47 /// polygonal data for splitting 349 48 PolygonContainer *mPolygons; 350 49 /// current depth 351 50 int mDepth; 352 /// the view cell associated with this subdivsion 353 ViewCell *mViewCell; 51 354 52 /// rays piercing this node 355 53 RayInfoContainer *mRays; 356 54 /// area of current node 357 55 float mArea; 358 /// geometry of current node induced by splitplanes359 VspBspNodeGeometry *mGeometry;360 56 /// geometry of node as induced by planes 57 BspNodeGeometry *mGeometry; 58 361 59 /// pvs size 362 60 int mPvs; … … 374 72 mPolygons(NULL), 375 73 mDepth(0), 376 mViewCell(NULL),377 74 mRays(NULL), 378 75 mPvs(0), … … 381 78 {} 382 79 383 VspBspTraversalData( VspBspNode *node,80 VspBspTraversalData(BspNode *node, 384 81 PolygonContainer *polys, 385 82 const int depth, 386 ViewCell *viewCell,387 83 RayInfoContainer *rays, 388 84 int pvs, 389 85 float area, 390 VspBspNodeGeometry *cell):86 BspNodeGeometry *geom): 391 87 mNode(node), 392 88 mPolygons(polys), 393 89 mDepth(depth), 394 mViewCell(viewCell),395 90 mRays(rays), 396 91 mPvs(pvs), 397 92 mArea(area), 398 mGeometry(cell) 93 mGeometry(geom) 94 {} 95 96 VspBspTraversalData(PolygonContainer *polys, 97 const int depth, 98 RayInfoContainer *rays, 99 BspNodeGeometry *geom): 100 mNode(NULL), 101 mPolygons(polys), 102 mDepth(depth), 103 mRays(rays), 104 mPvs(0), 105 mArea(0), 106 mGeometry(geom) 399 107 {} 400 108 }; … … 406 114 VspBspTree(); 407 115 116 /** Default destructor. 117 */ 408 118 ~VspBspTree(); 409 119 410 const VspBspTreeStatistics &GetStatistics() const; 120 /** Returns BSP Tree statistics. 121 */ 122 const BspTreeStatistics &GetStatistics() const; 411 123 412 124 … … 420 132 /** Returns list of BSP leaves. 421 133 */ 422 void CollectLeaves(vector< VspBspLeaf *> &leaves) const;134 void CollectLeaves(vector<BspLeaf *> &leaves) const; 423 135 424 136 /** Returns box which bounds the whole tree. … … 428 140 /** Returns root of BSP tree. 429 141 */ 430 VspBspNode *GetRoot() const;142 BspNode *GetRoot() const; 431 143 432 144 /** Exports VspBsp tree to file. … … 450 162 /** Returns statistics. 451 163 */ 452 VspBspTreeStatistics &GetStat();164 BspTreeStatistics &GetStat(); 453 165 454 166 /** finds neighbouring leaves of this tree node. 455 167 */ 456 int FindNeighbors(VspBspNode *n, vector<VspBspLeaf *> &neighbors, 168 int FindNeighbors(BspNode *n, 169 vector<BspLeaf *> &neighbors, 457 170 const bool onlyUnmailed) const; 458 171 … … 460 173 leading to this node. 461 174 */ 462 void ConstructGeometry( VspBspNode *n, PolygonContainer &cell) const;175 void ConstructGeometry(BspNode *n, PolygonContainer &cell) const; 463 176 464 177 /** Constructs geometry associated with the half space intersections … … 469 182 /** Construct geometry and stores it in a geometry node container. 470 183 */ 471 void ConstructGeometry( VspBspNode *n, VspBspNodeGeometry &cell) const;184 void ConstructGeometry(BspNode *n, BspNodeGeometry &cell) const; 472 185 473 186 /** Returns random leaf of BSP tree. 474 187 @param halfspace defines the halfspace from which the leaf is taken. 475 188 */ 476 VspBspLeaf *GetRandomLeaf(const Plane3 &halfspace);189 BspLeaf *GetRandomLeaf(const Plane3 &halfspace); 477 190 478 191 /** Returns random leaf of BSP tree. 479 192 @param onlyUnmailed if only unmailed leaves should be returned. 480 193 */ 481 VspBspLeaf *GetRandomLeaf(const bool onlyUnmailed = false);194 BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 482 195 483 196 /** Traverses tree and counts all view cells as well as their PVS size. 484 197 */ 485 void EvaluateViewCellsStats( VspBspViewCellsStatistics &stat) const;198 void EvaluateViewCellsStats(BspViewCellsStatistics &stat) const; 486 199 487 200 … … 489 202 */ 490 203 BspViewCell *GetRootCell() const; 204 205 /** Returns epsilon of this tree. 206 */ 207 float GetEpsilon() const; 491 208 492 209 protected: … … 521 238 @returns new root of the subtree 522 239 */ 523 VspBspNode *Subdivide(VspBspTraversalStack &tStack, VspBspTraversalData &tData); 524 525 /** Constructs the tree from the given list of polygons and rays. 240 BspNode *Subdivide(VspBspTraversalStack &tStack, 241 VspBspTraversalData &tData); 242 243 /** Constructs the tree from the given traversal data. 526 244 @param polys stores set of polygons on which subdivision may be based 527 245 @param rays storesset of rays on which subdivision may be based 528 246 */ 529 void Construct( PolygonContainer *polys, RayInfoContainer *rays);247 void Construct(const PolygonContainer &polys, RayInfoContainer *rays); 530 248 531 249 /** Selects the best possible splitting plane. … … 536 254 @returns the split plane 537 255 */ 538 Plane3 SelectPlane( VspBspLeaf *leaf,256 Plane3 SelectPlane(BspLeaf *leaf, 539 257 VspBspTraversalData &data); 540 258 … … 564 282 */ 565 283 566 VspBspInterior *SubdivideNode(VspBspTraversalData &tData,284 BspInterior *SubdivideNode(VspBspTraversalData &tData, 567 285 VspBspTraversalData &frontData, 568 286 VspBspTraversalData &backData, … … 575 293 @param rays bundle of rays on which the split can be based 576 294 */ 577 Plane3 SelectPlaneHeuristics( VspBspLeaf *leaf,295 Plane3 SelectPlaneHeuristics(BspLeaf *leaf, 578 296 VspBspTraversalData &data); 579 297 … … 639 357 bool SelectAxisAlignedPlane(Plane3 &plane, const PolygonContainer &polys) const; 640 358 641 /** Bounds ray and returns minT and maxT.642 @returns true if ray hits BSP tree bounding box643 */644 bool BoundRay(const Ray &ray, float &minT, float &maxT) const;645 646 359 /** Subdivides the rays into front and back rays according to the split plane. 647 360 … … 662 375 /** Extracts the split planes representing the space bounded by node n. 663 376 */ 664 void ExtractHalfSpaces( VspBspNode *n, vector<Plane3> &halfSpaces) const;377 void ExtractHalfSpaces(BspNode *n, vector<Plane3> &halfSpaces) const; 665 378 666 379 /** Adds the object to the pvs of the front and back leaf with a given classification. … … 686 399 float AccumulatedRayLength(const RayInfoContainer &rays) const; 687 400 688 401 /** Splits polygons with respect to the split plane. 402 403 @param plane the split plane 404 @param polys the polygons to be split. the polygons are consumed and 405 distributed to the containers frontPolys, backPolys, coincident. 406 @param frontPolys returns the polygons in the front of the split plane 407 @param backPolys returns the polygons in the back of the split plane 408 @param coincident returns the polygons coincident to the split plane 409 410 @returns the number of splits 411 */ 412 int SplitPolygons(const Plane3 &plane, 413 PolygonContainer &polys, 414 PolygonContainer &frontPolys, 415 PolygonContainer &backPolys, 416 PolygonContainer &coincident) const; 417 418 /** Adds ray sample contributions to the PVS. 419 @param sampleContributions the number contributions of the samples 420 @param contributingSampels the number of contributing rays 421 422 */ 423 void AddToPvs(BspLeaf *leaf, 424 const RayInfoContainer &rays, 425 int &sampleContributions, 426 int &contributingSamples); 689 427 690 428 /// Pointer to the root of the tree 691 VspBspNode *mRoot;692 693 VspBspTreeStatistics mStat;429 BspNode *mRoot; 430 431 BspTreeStatistics mStat; 694 432 695 433 /// Strategies for choosing next split plane. … … 749 487 bool mPvsUseArea; 750 488 489 float mEpsilon; 490 491 int mMaxTests; 492 751 493 private: 752 494
Note: See TracChangeset
for help on using the changeset viewer.