Ignore:
Timestamp:
11/11/05 21:28:02 (19 years ago)
Author:
mattausch
Message:

started kd based bottom-up view cells

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellKd.h

    r405 r406  
    1 #ifndef _KdTree_H__ 
    2 #define _KdTree_H__ 
     1#ifndef _ViewCellKdTree_H__ 
     2#define _ViewCellKdTree_H__ 
    33 
    44#include <functional> 
     
    1111 
    1212   
    13 class KdNode; 
    14 class KdLeaf; 
    15 class KdInterior; 
     13class ViewCellKdNode; 
     14class ViewCellKdLeaf; 
     15class ViewCellKdInterior; 
    1616class Intersectable; 
    1717 
     
    2020// Static statistics for kd-tree search 
    2121// -------------------------------------------------------------- 
    22 class KdTreeStatistics  
     22class ViewCellKdTreeStatistics  
    2323{ 
    2424public:   
     
    5151   
    5252  // Constructor 
    53   KdTreeStatistics() { 
     53  ViewCellKdTreeStatistics() { 
    5454    Reset(); 
    5555  } 
     
    7575  Print(ostream &app) const; 
    7676 
    77   friend ostream &operator<<(ostream &s, const KdTreeStatistics &stat) { 
     77  friend ostream &operator<<(ostream &s, const ViewCellKdTreeStatistics &stat) { 
    7878    stat.Print(s); 
    7979    return s; 
     
    8383 
    8484   
    85 class KdInterior; 
     85class ViewCellKdInterior; 
    8686/** Abstract class for kd-tree node */ 
    87 class KdNode { 
     87class ViewCellKdNode { 
    8888public: 
    8989  static int mailID; 
     
    9595 
    9696 
    97   KdNode(KdInterior *parent); 
     97  ViewCellKdNode(ViewCellKdInterior *parent); 
    9898 
    9999  /** Determines whether this node is a leaf or interior node 
     
    111111  /** Parent of the node - the parent is a little overhead for maintanance of the tree, 
    112112      but allows various optimizations of tree traversal algorithms */ 
    113   KdInterior *mParent; 
     113  ViewCellKdInterior *mParent; 
    114114  int mDepth; 
    115115}; 
    116116 
    117117/** Implementation of the kd-tree interior node */ 
    118 class KdInterior : public KdNode { 
     118class ViewCellKdInterior : public ViewCellKdNode { 
    119119 
    120120public: 
    121121     
    122   KdInterior(KdInterior *parent):KdNode(parent), mBack(NULL), mFront(NULL) {} 
    123  
    124   /** \sa KdNode::IsLeaf() */ 
     122  ViewCellKdInterior(ViewCellKdInterior *parent):ViewCellKdNode(parent), mBack(NULL), mFront(NULL) {} 
     123 
     124  /** \sa ViewCellKdNode::IsLeaf() */ 
    125125  virtual bool IsLeaf() const { return false; } 
    126126 
     
    133133 
    134134  /** back node */ 
    135   KdNode *mBack; 
     135  ViewCellKdNode *mBack; 
    136136  /** front node */ 
    137   KdNode *mFront; 
    138  
    139   void SetupChildLinks(KdNode *b, KdNode *f) { 
     137  ViewCellKdNode *mFront; 
     138 
     139  void SetupChildLinks(ViewCellKdNode *b, ViewCellKdNode *f) { 
    140140    mBack = b; 
    141141    mFront = f; 
     
    143143  } 
    144144   
    145   void ReplaceChildLink(KdNode *oldChild, KdNode *newChild) { 
     145  void ReplaceChildLink(ViewCellKdNode *oldChild, ViewCellKdNode *newChild) { 
    146146    if (mBack == oldChild) 
    147147      mBack = newChild; 
     
    155155   
    156156/** Implementation of the kd-tree leaf node */ 
    157 class KdLeaf : public KdNode { 
     157class ViewCellKdLeaf : public ViewCellKdNode { 
    158158public: 
    159   KdLeaf(KdInterior *parent, const int objects):KdNode(parent) { 
     159  ViewCellKdLeaf(ViewCellKdInterior *parent, const int objects):ViewCellKdNode(parent) { 
    160160    mObjects.reserve(objects); 
    161161  } 
     
    176176  } 
    177177 
    178   /** \sa KdNode::IsLeaf() */ 
     178  /** \sa ViewCellKdNode::IsLeaf() */ 
    179179  virtual bool IsLeaf() const { return true; } 
    180180   
     
    191191  PassingRaySet mPassingRays; 
    192192         
    193   /** PVS consisting of visible KdTree nodes */ 
    194   KdPvs mKdPvs; 
     193  /** PVS consisting of visible ViewCellKd nodes */ 
     194  ViewCellKdPvs mKdPvs; 
    195195         
    196196        /** PVS consisting of visible objects */ 
     
    200200   
    201201 
    202 /** KdTree for indexing scene entities - occluders/occludees/viewcells */ 
    203 class KdTree { 
     202/** ViewCellKd for indexing scene entities - occluders/occludees/viewcells */ 
     203class ViewCellKd { 
    204204 
    205205protected: 
    206206  struct TraversalData 
    207207  {   
    208     KdNode *mNode; 
     208    ViewCellKdNode *mNode; 
    209209    AxisAlignedBox3 mBox; 
    210210    int mDepth; 
     
    213213    TraversalData() {} 
    214214 
    215     TraversalData(KdNode *n, const float p): 
     215    TraversalData(ViewCellKdNode *n, const float p): 
    216216      mNode(n), mPriority(p) 
    217217    {} 
    218218     
    219     TraversalData(KdNode *n, 
     219    TraversalData(ViewCellKdNode *n, 
    220220                   const AxisAlignedBox3 &b, 
    221221                   const int d): 
     
    225225    bool operator<( 
    226226                   const TraversalData &b) const { 
    227       KdLeaf *leafa = (KdLeaf *) mNode; 
    228       KdLeaf *leafb = (KdLeaf *) b.mNode; 
     227      ViewCellKdLeaf *leafa = (ViewCellKdLeaf *) mNode; 
     228      ViewCellKdLeaf *leafb = (ViewCellKdLeaf *) b.mNode; 
    229229      return  
    230230        leafa->mObjects.size()*mBox.SurfaceArea() 
     
    254254        SPLIT_SAH}; 
    255255   
    256   KdTree(); 
     256  ViewCellKd(); 
    257257   
    258258     
     
    274274      were already met 
    275275  */ 
    276   virtual KdNode *Subdivide(const TraversalData &tdata); 
     276  virtual ViewCellKdNode *Subdivide(const TraversalData &tdata); 
    277277 
    278278  /** Get the root of the tree */ 
    279   KdNode *GetRoot() const { 
     279  ViewCellKdNode *GetRoot() const { 
    280280    return mRoot; 
    281281  } 
     
    289289          ); 
    290290 
    291   const KdTreeStatistics &GetStatistics() const { 
     291  const ViewCellKdTreeStatistics &GetStatistics() const { 
    292292    return mStat; 
    293293  } 
    294294 
    295295  void 
    296   CollectObjects(KdNode *n, ObjectContainer &objects); 
     296  CollectObjects(ViewCellKdNode *n, ObjectContainer &objects); 
    297297         
    298298  void 
    299   CollectLeaves(vector<KdLeaf *> &leaves); 
    300          
    301   AxisAlignedBox3 GetBox(const KdNode *node) const { 
    302     KdInterior *parent = node->mParent; 
     299  CollectLeaves(vector<ViewCellKdLeaf *> &leaves); 
     300         
     301  AxisAlignedBox3 GetBox(const ViewCellKdNode *node) const { 
     302    ViewCellKdInterior *parent = node->mParent; 
    303303    if (parent == NULL) 
    304304      return mBox; 
    305305     
    306306    if (!node->IsLeaf()) 
    307       return ((KdInterior *)node)->mBox; 
     307      return ((ViewCellKdInterior *)node)->mBox; 
    308308     
    309309    AxisAlignedBox3 box(parent->mBox); 
     
    315315  } 
    316316         
    317   KdNode * 
    318   FindRandomNeighbor(KdNode *n, 
     317  ViewCellKdNode * 
     318  FindRandomNeighbor(ViewCellKdNode *n, 
    319319                                                                                 bool onlyUnmailed 
    320320                                                                                 ); 
    321321   
    322   KdNode * 
    323   KdTree::GetRandomLeaf(const Plane3 &halfspace); 
    324  
    325         KdNode * 
     322  ViewCellKdNode * 
     323  ViewCellKd::GetRandomLeaf(const Plane3 &halfspace); 
     324 
     325        ViewCellKdNode * 
    326326        GetRandomLeaf(const bool onlyUnmailed = false); 
    327327 
    328328  int 
    329   FindNeighbors(KdNode *n, 
    330                 vector<KdNode *> &neighbors, 
     329  FindNeighbors(ViewCellKdNode *n, 
     330                vector<ViewCellKdNode *> &neighbors, 
    331331                bool onlyUnmailed 
    332332                ); 
     
    419419 
    420420  struct RayTraversalData { 
    421     KdNode *mNode; 
     421    ViewCellKdNode *mNode; 
    422422    Vector3 mExitPoint; 
    423423    float mMaxT; 
    424424     
    425425    RayTraversalData() {} 
    426     RayTraversalData(KdNode *n, 
     426    RayTraversalData(ViewCellKdNode *n, 
    427427                     const Vector3 &p, 
    428428                     const float maxt): 
     
    460460  float 
    461461  BestCostRatio( 
    462                 KdLeaf *node, 
     462                ViewCellKdLeaf *node, 
    463463                const AxisAlignedBox3 &box, 
    464464                const int axis, 
     
    470470  void 
    471471  SortSplitCandidates( 
    472                       KdLeaf *node, 
     472                      ViewCellKdLeaf *node, 
    473473                      const int axis 
    474474                      ); 
     
    477477  EvaluateLeafStats(const TraversalData &data); 
    478478 
    479   KdNode * 
     479  ViewCellKdNode * 
    480480  SubdivideNode( 
    481                 KdLeaf *leaf, 
     481                ViewCellKdLeaf *leaf, 
    482482                const AxisAlignedBox3 &box, 
    483483                AxisAlignedBox3 &backBBox, 
     
    486486 
    487487  bool 
    488   TerminationCriteriaMet(const KdLeaf *leaf); 
     488  TerminationCriteriaMet(const ViewCellKdLeaf *leaf); 
    489489   
    490490  int 
    491   SelectPlane(KdLeaf *leaf, 
     491  SelectPlane(ViewCellKdLeaf *leaf, 
    492492              const AxisAlignedBox3 &box, 
    493493              float &position 
     
    504504  bool mSahUseFaces; 
    505505  /// root of the tree 
    506   KdNode *mRoot; 
     506  ViewCellKdNode *mRoot; 
    507507  /// bounding box of the tree root 
    508508  AxisAlignedBox3 mBox; 
    509   KdTreeStatistics mStat; 
     509  ViewCellKdTreeStatistics mStat; 
    510510   
    511511}; 
    512    
    513  
    514  
    515  
    516  
    517512 
    518513#endif 
Note: See TracChangeset for help on using the changeset viewer.