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

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

added bsp tree stuff

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