#ifndef _ViewCellBsp_H__ #define _ViewCellBsp_H__ #include "Mesh.h" class ViewCell; class Plane3; //class Mesh; //namespace GtpVisibilityPreprocessor { class BSPInterior; /** BSPNode abstract class serving for interior and leaf node implementation */ class BSPNode { public: /** Determines whether this node is a leaf or not @return true if leaf */ virtual bool IsLeaf() const = 0; /** Determines whether this node is a root @return true if root */ virtual bool IsRoot() const; protected: /// parent of this node BSPInterior *mParent; }; /** BSP interior node implementation */ class BSPInterior : public BSPNode { public: /** @return false since it is an interior node */ bool IsLeaf() const; BSPNode *GetBack() {return mBack;} BSPNode *GetFront() {return mFront;} void ReplaceChildLink(BSPNode *oldChild, BSPNode *newChild); void SetupChildLinks(BSPNode *b, BSPNode *f); protected: /// Splitting plane corresponding to this node Plane3 mPlane; /// back node BSPNode *mBack; /// front node BSPNode *mFront; }; /** BSP leaf node implementation */ class BSPLeaf : public BSPNode { public: BSPLeaf(ViewCell *viewCell = NULL); /** @return true since it is an interior node */ bool IsLeaf() const; protected: /// polygonal representation of this viewcell /// if NULL this note does not correspond to feasible viewcell ViewCell *mViewCell; }; /** Implementation of the ViewCell BSP tree */ class BSPTree { public: struct BSPTraversalData { BSPNode *mNode; BSPInterior *mParent; Mesh mViewCell; int mDepth; BSPTraversalData() {} BSPTraversalData(BSPNode *n, BSPInterior *p, const Mesh &m, const int d): mNode(n), mParent(p), mViewCell(m), mDepth(d) {} }; /** Constructor takes a pointer to the cell corresponding to the whole viewspace */ BSPTree(ViewCell *cell); protected: Plane3 *SelectPlane(Mesh *viewcell); void Subdivide(); BSPNode *SubdivideNode(BSPLeaf *leaf, BSPInterior *parent, Mesh *viewCell, const int depth, Mesh &frontPolys, Mesh &backPolys); /// Pointer to the root of the tree BSPNode *mRoot; /// Pointer to the root cell of the viewspace ViewCell *mRootCell; }; //}; // GtpVisibilityPreprocessor #endif