source: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBSP.h @ 195

Revision 195, 2.4 KB checked in by mattausch, 19 years ago (diff)

added bsp tree stuff

RevLine 
[190]1#ifndef _ViewCellBsp_H__
2#define _ViewCellBsp_H__
3
[195]4#include "Mesh.h"
[190]5class ViewCell;
6class Plane3;
[195]7//class Mesh;
[190]8
9//namespace GtpVisibilityPreprocessor {
10 
[194]11class BSPInterior;
[190]12
[195]13
14  /**
15     BSPNode abstract class serving for interior and leaf node implementation
16  */
17  class BSPNode
18  {
19  public:
20          /** Determines whether this node is a leaf or not
21          @return true if leaf
22          */
23          virtual bool IsLeaf() const = 0;
[190]24   
[195]25          /** Determines whether this node is a root
26          @return true if root
27          */
28          virtual bool IsRoot() const;
[190]29
[195]30  protected:
[194]31
[195]32          /// parent of this node
33          BSPInterior *mParent;
[190]34  };
35
36  /** BSP interior node implementation */
37  class BSPInterior : public BSPNode
[195]38  {   
39  public:
40          /** @return false since it is an interior node */
41          bool IsLeaf() const;
[190]42
[195]43          BSPNode *GetBack() {return mBack;}
44          BSPNode *GetFront() {return mFront;}
45
46          void ReplaceChildLink(BSPNode *oldChild, BSPNode *newChild);
47          void SetupChildLinks(BSPNode *b, BSPNode *f);
48
[190]49  protected:
[195]50               
51          /// Splitting plane corresponding to this node
52          Plane3 mPlane;
53          /// back node
54          BSPNode *mBack;
55          /// front node
56          BSPNode *mFront;
[190]57  };
58 
59 
60  /** BSP leaf node implementation */
61  class BSPLeaf : public BSPNode
62  {
63  public:
[195]64          BSPLeaf(ViewCell *viewCell = NULL);
[190]65   
[195]66          /** @return true since it is an interior node */
67          bool IsLeaf() const;
[190]68
69  protected:
[195]70   
71          /// polygonal representation of this viewcell
72          /// if NULL this note does not correspond to feasible viewcell
73          ViewCell *mViewCell;
[190]74  };
75 
76  /** Implementation of the ViewCell BSP tree */
77  class BSPTree
78  {
79  public:
[195]80          struct BSPTraversalData
81          { 
82                  BSPNode *mNode;
83                  BSPInterior *mParent;
84
85                  Mesh mViewCell;
86                  int mDepth;
87                     
88                  BSPTraversalData() {}
89                  BSPTraversalData(BSPNode *n, BSPInterior *p, const Mesh &m, const int d):
90                  mNode(n), mParent(p), mViewCell(m), mDepth(d) {}
91      };
92         
93          /** Constructor takes a pointer to the cell corresponding to the whole
94          viewspace */
95          BSPTree(ViewCell *cell);
[190]96       
97  protected:
[195]98           
99          Plane3 *SelectPlane(Mesh *viewcell);
100           void Subdivide();
101           
102           BSPNode *SubdivideNode(BSPLeaf *leaf, BSPInterior *parent,
103                                                         Mesh *viewCell, const int depth,
104                                                         Mesh &frontPolys, Mesh &backPolys);
105
106          /// Pointer to the root of the tree
107          BSPNode *mRoot;
108          /// Pointer to the root cell of the viewspace
109          ViewCell *mRootCell;
[190]110  };
111 
112//}; // GtpVisibilityPreprocessor
113
114#endif
Note: See TracBrowser for help on using the repository browser.