Ignore:
Timestamp:
06/09/06 09:07:40 (18 years ago)
Author:
mattausch
Message:

worked on vsp osp tree. warning: does not compile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1006 r1008  
    99#include "VssRay.h" 
    1010#include "RayInfo.h" 
    11 #include "ViewCellBsp.h" 
    12  
     11#include "gzstream.h" 
    1312 
    1413 
     
    1615 
    1716class ViewCellLeaf; 
    18 //class BspViewCell; 
     17class VspViewCell; 
    1918class Plane3; 
    20 class VspBspTree;   
    21 class BspInterior; 
    22 class BspNode; 
    2319class AxisAlignedBox3; 
    2420class Ray; 
     
    2925class ViewCellsTree; 
    3026class Environment; 
     27class VspInterior; 
     28class VspLeaf; 
     29class VspNode; 
     30 
     31 
     32/** A definition for an axis aligned plane. 
     33*/ 
     34struct AxisAlignedPlane 
     35{ 
     36public: 
     37        int mAxis; 
     38        float mPosition; 
     39}; 
     40 
     41 
     42class VspTreeStatistics: public StatisticsBase 
     43{ 
     44public: 
     45        // total number of nodes 
     46        int nodes; 
     47        // number of splits 
     48        int splits[3]; 
     49         
     50        // totals number of rays 
     51        int rays; 
     52        // maximal reached depth 
     53        int maxDepth; 
     54        // minimal depth 
     55        int minDepth; 
     56         
     57        // max depth nodes 
     58        int maxDepthNodes; 
     59        // minimum depth nodes 
     60        int minDepthNodes; 
     61        // max depth nodes 
     62        int minPvsNodes; 
     63        // nodes with minimum PVS 
     64        int minRaysNodes; 
     65        // max ray contribution nodes 
     66        int maxRayContribNodes; 
     67        // minimum area nodes 
     68        int minProbabilityNodes; 
     69        /// nodes termination because of max cost ratio; 
     70        int maxCostNodes; 
     71        // max number of rays per node 
     72        int maxObjectRefs; 
     73        /// samples contributing to pvs 
     74        int contributingSamples; 
     75        /// sample contributions to pvs 
     76        int sampleContributions; 
     77        /// largest pvs 
     78        int maxPvs; 
     79        /// number of invalid leaves 
     80        int invalidLeaves; 
     81        /// accumulated number of rays refs 
     82        int accumRays; 
     83        int pvs; 
     84        // accumulated depth (used to compute average) 
     85        int accumDepth; 
     86 
     87        // Constructor 
     88        VspTreeStatistics()  
     89        { 
     90                Reset(); 
     91        } 
     92 
     93        int Nodes() const {return nodes;} 
     94        int Interior() const { return nodes / 2; } 
     95        int Leaves() const { return (nodes / 2) + 1; } 
     96         
     97        // TODO: computation wrong 
     98        double AvgDepth() const { return accumDepth / (double)Leaves();};  
     99        double AvgRays() const { return accumRays / (double)Leaves();};  
     100 
     101        void Reset()  
     102        { 
     103                nodes = 0; 
     104                for (int i = 0; i < 3; ++ i) 
     105                        splits[i] = 0; 
     106                 
     107                maxDepth = 0; 
     108                minDepth = 99999; 
     109                accumDepth = 0; 
     110        pvs = 0; 
     111                maxDepthNodes = 0; 
     112                minPvsNodes = 0; 
     113                minRaysNodes = 0; 
     114                maxRayContribNodes = 0; 
     115                minProbabilityNodes = 0; 
     116                maxCostNodes = 0; 
     117 
     118                contributingSamples = 0; 
     119                sampleContributions = 0; 
     120 
     121                maxPvs = 0; 
     122                invalidLeaves = 0; 
     123                accumRays = 0; 
     124        } 
     125 
     126        void Print(ostream &app) const; 
     127 
     128        friend ostream &operator<<(ostream &s, const VspTreeStatistics &stat)  
     129        { 
     130                stat.Print(s); 
     131                return s; 
     132        }  
     133}; 
     134 
     135/** 
     136    VspNode abstract class serving for interior and leaf node implementation 
     137*/ 
     138class VspNode  
     139{ 
     140 
     141public: 
     142        VspNode(); 
     143        virtual ~VspNode(){}; 
     144        VspNode(VspInterior *parent); 
     145 
     146        /** Determines whether this node is a leaf or not 
     147        @return true if leaf 
     148        */ 
     149        virtual bool IsLeaf() const = 0; 
     150 
     151        /** Determines whether this node is a root 
     152        @return true if root 
     153        */ 
     154        virtual bool IsRoot() const; 
     155 
     156        /** Returns parent node. 
     157        */ 
     158        VspInterior *GetParent(); 
     159 
     160        /** Sets parent node. 
     161        */ 
     162        void SetParent(VspInterior *parent); 
     163 
     164        /** Returns true if this node is a sibling of node n. 
     165        */ 
     166        bool IsSibling(VspNode *n) const; 
     167 
     168        /** returns depth of the node. 
     169        */ 
     170        int GetDepth() const; 
     171 
     172        /** returns true if the whole subtree is valid 
     173        */ 
     174        bool TreeValid() const; 
     175 
     176        void SetTreeValid(const bool v); 
     177 
     178        //-- mailing options 
     179 
     180        void Mail() { mMailbox = sMailId; } 
     181        static void NewMail() { ++ sMailId; } 
     182        bool Mailed() const { return mMailbox == sMailId; } 
     183 
     184        static int sMailId; 
     185        int mMailbox; 
     186 
     187        int mTimeStamp; 
     188 
     189protected: 
     190 
     191        /// if this sub tree is a completely valid view space region 
     192        bool mTreeValid; 
     193        /// parent of this node 
     194        VspInterior *mParent; 
     195}; 
     196 
     197 
     198/** BSP interior node implementation  
     199*/ 
     200class VspInterior: public VspNode  
     201{ 
     202public: 
     203        /** Standard contructor taking split plane as argument. 
     204        */ 
     205        VspInterior(const AxisAlignedPlane &plane); 
     206        ~VspInterior(); 
     207        /** @return false since it is an interior node  
     208        */ 
     209        bool IsLeaf() const; 
     210 
     211        VspNode *GetBack(); 
     212        VspNode *GetFront(); 
     213 
     214        /** Returns split plane. 
     215        */ 
     216        AxisAlignedPlane GetPlane() const; 
     217 
     218        /** Replace front or back child with new child. 
     219        */ 
     220        void ReplaceChildLink(VspNode *oldChild, VspNode *newChild); 
     221        /** Replace front and back child. 
     222        */ 
     223        void SetupChildLinks(VspNode *b, VspNode *f); 
     224 
     225        friend ostream &operator<<(ostream &s, const VspInterior &A) 
     226        { 
     227                return s << A.mPlane.mAxis << " " << A.mPlane.mPosition; 
     228        } 
     229 
     230protected: 
     231 
     232        /// Splitting plane corresponding to this node 
     233        AxisAlignedPlane mPlane; 
     234 
     235        /// back node 
     236        VspNode *mBack; 
     237        /// front node 
     238        VspNode *mFront; 
     239}; 
     240 
     241 
     242/** BSP leaf node implementation. 
     243*/ 
     244class VspLeaf: public VspNode  
     245{ 
     246 
     247public: 
     248        VspLeaf(); 
     249        VspLeaf(ViewCellLeaf *viewCell); 
     250        VspLeaf(VspInterior *parent); 
     251        VspLeaf(VspInterior *parent, ViewCellLeaf *viewCell); 
     252 
     253        ~VspLeaf(); 
     254 
     255        /** @return true since it is an interior node  
     256        */ 
     257        bool IsLeaf() const; 
     258         
     259        /** Returns pointer of view cell. 
     260        */ 
     261        ViewCellLeaf *GetViewCell() const; 
     262 
     263        /** Sets pointer to view cell. 
     264        */ 
     265        void SetViewCell(ViewCellLeaf *viewCell); 
     266 
     267        /// Rays piercing this leaf. 
     268        VssRayContainer mVssRays; 
     269         
     270        /// leaf pvs 
     271        ObjectPvs *mPvs; 
     272 
     273        /// Probability that the view point lies in this leaf 
     274        float mProbability; 
     275 
     276protected: 
     277         
     278        /// if NULL this does not correspond to feasible viewcell 
     279        ViewCellLeaf *mViewCell; 
     280}; 
     281 
    31282 
    32283/** 
     
    57308{ 
    58309        friend class ViewCellsParseHandlers; 
    59         friend class VspBspViewCellsManager; 
     310        friend class VspVspViewCellsManager; 
    60311 
    61312public: 
    62313         
    63         /** A definition for an axis aligned plane. 
    64         */ 
    65         struct AxisAlignedPlane 
    66         { 
    67         public: 
    68                 int mAxis; 
    69                 float mPosition; 
    70         }; 
    71  
    72314        /** Additional data which is passed down the BSP tree during traversal. 
    73315        */ 
     
    76318        public: 
    77319                /// the current node 
    78                 BspNode *mNode; 
     320                VspNode *mNode; 
    79321                /// current depth 
    80322                int mDepth; 
     
    114356                {} 
    115357                 
    116                 VspOspTraversalData(BspNode *node,  
     358                VspOspTraversalData(VspNode *node,  
    117359                                                        const int depth,  
    118360                                                        RayInfoContainer *rays, 
     
    193435#if 1 
    194436                        return mRenderCost; 
    195 #endif 
    196 #if 0 
     437#else 
    197438                        return (float) (-mDepth); // for kd tree 
    198439#endif 
     
    217458        /** Returns BSP Tree statistics. 
    218459        */ 
    219         const BspTreeStatistics &GetStatistics() const;  
     460        const VspTreeStatistics &GetStatistics() const;  
    220461   
    221462 
     
    233474                @param maxPvs the maximal pvs (-1 means unlimited) 
    234475        */ 
    235         void CollectLeaves(vector<BspLeaf *> &leaves,  
     476        void CollectLeaves(vector<VspLeaf *> &leaves,  
    236477                                           const bool onlyUnmailed = false, 
    237478                                           const int maxPvs = -1) const; 
     
    241482        AxisAlignedBox3 GetBoundingBox()const; 
    242483 
    243         /** Returns root of BSP tree. 
    244         */ 
    245         BspNode *GetRoot() const; 
     484        /** Returns root of the view space partitioning tree. 
     485        */ 
     486        VspNode *GetRoot() const; 
    246487 
    247488        /** Collects the leaf view cells of the tree 
     
    259500        /** finds neighbouring leaves of this tree node. 
    260501        */ 
    261         int FindNeighbors(BspNode *n,  
    262                                           vector<BspLeaf *> &neighbors,  
     502        int FindNeighbors(VspNode *n,  
     503                                          vector<VspLeaf *> &neighbors,  
    263504                                          const bool onlyUnmailed) const; 
    264505 
     
    266507                @param halfspace defines the halfspace from which the leaf is taken. 
    267508        */ 
    268         BspLeaf *GetRandomLeaf(const Plane3 &halfspace); 
     509        VspLeaf *GetRandomLeaf(const Plane3 &halfspace); 
    269510 
    270511        /** Returns random leaf of BSP tree. 
    271512                @param onlyUnmailed if only unmailed leaves should be returned. 
    272513        */ 
    273         BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 
     514        VspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 
    274515 
    275516        /** Returns epsilon of this tree. 
     
    291532        void SetViewCellsManager(ViewCellsManager *vcm); 
    292533 
    293         /** Returns distance from node 1 to node 2. 
    294         */ 
    295         int TreeDistance(BspNode *n1, BspNode *n2) const; 
    296534 
    297535        /** Collapses the tree with respect to the view cell partition. 
     
    316554                the invalid view space. 
    317555        */ 
    318         BspViewCell *GetOutOfBoundsCell(); 
     556        VspViewCell *GetOutOfBoundsCell(); 
    319557 
    320558        /** Writes tree to output stream 
     
    332570        int CastBeam(Beam &beam); 
    333571 
    334         /** Finds approximate neighbours, i.e., finds correct neighbors 
    335                 in most cases but sometimes more. 
    336         */ 
    337         int FindApproximateNeighbors(BspNode *n,  
    338                                                              vector<BspLeaf *> &neighbors, 
    339                                                                  const bool onlyUnmailed) const; 
    340572 
    341573        /** Checks if tree validity-flags are right  
     
    410642        /** Evaluates render cost decrease of next split. 
    411643        */ 
    412         float EvalRenderCostDecrease(const Plane3 &candidatePlane, 
     644        float EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, 
    413645                                                                 const VspOspTraversalData &data) const; 
    414646 
     
    419651        /** Collects view cells in the subtree under root. 
    420652        */ 
    421         void CollectViewCells(BspNode *root,  
     653        void CollectViewCells(VspNode *root,  
    422654                                                  bool onlyValid,  
    423655                                                  ViewCellContainer &viewCells, 
     
    427659                the invalid view space. If it does not exist, it is created. 
    428660        */ 
    429         BspViewCell *GetOrCreateOutOfBoundsCell(); 
     661        VspViewCell *GetOrCreateOutOfBoundsCell(); 
    430662 
    431663        /** Collapses the tree with respect to the view cell partition, 
     
    436668                this node otherwise 
    437669        */ 
    438         BspNode *CollapseTree(BspNode *node, int &collapsed); 
     670        VspNode *CollapseTree(VspNode *node, int &collapsed); 
    439671 
    440672        /** Helper function revalidating the view cell leaf list after merge. 
     
    451683                @returns new root of the subtree 
    452684        */ 
    453         BspNode *Subdivide(VspOspSplitQueue &tQueue, 
     685        VspNode *Subdivide(VspOspSplitQueue &tQueue, 
    454686                                           VspOspSplitCandidate &splitCandidate); 
    455687 
     
    469701        */ 
    470702 
    471         BspInterior *SubdivideNode(const Plane3 &splitPlane, 
     703        VspInterior *SubdivideNode(const AxisAlignedPlane &splitPlane, 
    472704                                                           VspOspTraversalData &tData, 
    473705                                                           VspOspTraversalData &frontData, 
     
    546778                 
    547779        */ 
    548         void AddToPvs(BspLeaf *leaf, 
     780        void AddToPvs(VspLeaf *leaf, 
    549781                                  const RayInfoContainer &rays,  
    550782                                  float &sampleContributions, 
     
    553785        /** Propagates valid flag up the tree. 
    554786        */ 
    555         void PropagateUpValidity(BspNode *node); 
     787        void PropagateUpValidity(VspNode *node); 
    556788 
    557789        /** Writes the node to disk 
     
    559791        */ 
    560792#if ZIPPED_VIEWCELLS 
    561         void ExportNode(BspNode *node, ogzstream &stream); 
     793        void ExportNode(VspNode *node, ogzstream &stream); 
    562794#else 
    563         void ExportNode(BspNode *node, ofstream &stream); 
     795        void ExportNode(VspNode *node, ofstream &stream); 
    564796#endif 
    565797 
     
    575807 
    576808        /// Pointer to the root of the tree 
    577         BspNode *mRoot; 
    578                  
    579         BspTreeStatistics mBspStats; 
     809        VspNode *mRoot; 
     810                 
     811        VspTreeStatistics mVspStats; 
    580812         
    581813        /// View cell corresponding to the space outside the valid view space 
    582         BspViewCell *mOutOfBoundsCell; 
     814        VspViewCell *mOutOfBoundsCell; 
    583815 
    584816        /// box around the whole view domain 
Note: See TracChangeset for help on using the changeset viewer.