Ignore:
Timestamp:
11/16/05 18:33:18 (19 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r414 r418  
    272272{ 
    273273public: 
    274   // plane in local modelling coordinates 
    275   float position; 
    276  
    277   // pointers to children 
    278   VspKdTreeNode *back, *front; 
    279  
    280   // the bbox of the node 
    281   AxisAlignedBox3 bbox; 
    282  
    283   // the bbox of the node 
    284   AxisAlignedBox3 dirBBox; 
    285    
    286   // data for caching 
    287   long accesses; 
    288   long lastAccessTime; 
    289    
    290   VspKdTreeInterior(VspKdTreeInterior *p):VspKdTreeNode(p), 
    291                                         back(NULL), 
    292                                         front(NULL), 
    293                                         accesses(0), 
    294                                         lastAccessTime(-1) 
    295   { } 
    296  
    297   virtual int GetAccessTime() { 
    298     return lastAccessTime; 
    299   } 
    300  
    301   void SetupChildLinks(VspKdTreeNode *b, VspKdTreeNode *f) { 
    302     back = b; 
    303     front = f; 
    304     b->parent = f->parent = this; 
    305   } 
    306  
    307   void ReplaceChildLink(VspKdTreeNode *oldChild, VspKdTreeNode *newChild) { 
    308     if (back == oldChild) 
    309       back = newChild; 
    310     else 
    311       front = newChild; 
    312   } 
    313  
    314   virtual int Type() const  { return EInterior; } 
    315    
    316   virtual ~VspKdTreeInterior() 
    317   { 
    318           DEL_PTR(back); 
    319           DEL_PTR(front); 
    320   } 
    321    
    322   virtual void Print(ostream &s) const  
    323   { 
    324           if (axis == 0) 
    325                   s << "x "; 
    326           else 
    327                   if (axis == 1) 
    328                           s << "y "; 
    329                   else 
    330                           s << "z "; 
    331           s << position << " "; 
    332           back->Print(s); 
    333           front->Print(s); 
    334   } 
    335          
    336   int ComputeRayIntersection(const RayInfo &rayData, float &t)  
    337   { 
    338           return rayData.ComputeRayIntersection(axis, position, t); 
    339   } 
    340  
     274         
     275        VspKdTreeInterior(VspKdTreeInterior *p); 
     276                         
     277        virtual int GetAccessTime(); 
     278         
     279        virtual int Type(); 
     280   
     281        virtual ~VspKdTreeInterior(); 
     282     
     283        virtual void Print(ostream &s) const; 
     284 
     285protected: 
     286 
     287        void SetupChildLinks(VspKdTreeNode *b, VspKdTreeNode *f); 
     288  
     289        void ReplaceChildLink(VspKdTreeNode *oldChild, VspKdTreeNode *newChild); 
     290  
     291        int ComputeRayIntersection(const RayInfo &rayData, float &t); 
     292 
     293        // plane in local modelling coordinates 
     294        float mPosition; 
     295 
     296        // pointers to children 
     297        VspKdTreeNode *mBack; 
     298        VspKdTreeNode *mFront; 
     299 
     300        // the bbox of the node 
     301        AxisAlignedBox3 mBbox; 
     302 
     303        // data for caching 
     304        long mAccesses; 
     305        long mLastAccessTime; 
    341306}; 
    342307 
     
    543508         
    544509public: 
    545          
    546         ///////////////////////////// 
    547         // The core pointer 
    548         VspKdTreeNode *root; 
    549    
    550         ///////////////////////////// 
    551         // Basic properties 
    552  
    553         // total number of nodes of the tree 
    554         int nodes; 
    555          
    556         // axis aligned bounding box of the scene 
    557         AxisAlignedBox3 bbox; 
    558  
    559         // axis aligned bounding box of directions 
    560         AxisAlignedBox3 dirBBox; 
    561  
    562         const VspKdStatistics &GetStatistics() const { 
    563                 return mStat; 
    564         } 
    565         ///////////////////////////// 
    566         // Construction parameters 
    567  
    568         // epsilon used for the construction 
    569         float epsilon; 
    570  
    571         // ratio between traversal and intersection costs 
    572         float ct_div_ci; 
    573          
    574         // max depth of the tree 
    575         int termMaxDepth; 
    576         // minimal ratio of the volume of the cell and the query volume 
    577         float termMinSize; 
    578  
    579         // minimal pvs per node to still get subdivided 
    580         int termMinPvs; 
    581  
    582         // minimal ray number per node to still get subdivided 
    583         int termMinRays; 
    584          
    585         // maximal cost ration to subdivide a node 
    586         float termMaxCostRatio; 
    587          
    588         // maximal contribution per ray to subdivide the node 
    589         float termMaxRayContribution; 
    590  
    591         // randomized construction 
    592         bool randomize; 
    593  
    594         // type of the splitting to use for the tree construction 
    595         enum {ESplitRegular, ESplitHeuristic }; 
    596         int splitType; 
    597          
    598         // maximal size of the box on which the refdir splitting can be performed 
    599         // (relative to the scene bbox 
    600         float refDirBoxMaxSize; 
    601    
    602         // maximum alovable memory in MB 
    603         float maxTotalMemory; 
    604  
    605         // maximum alovable memory for static kd tree in MB 
    606         float maxStaticMemory; 
    607  
    608         // this is used during the construction depending 
    609         // on the type of the tree and queries... 
    610         float maxMemory; 
    611  
    612         // minimal acess time for collapse 
    613         int accessTimeThreshold; 
    614  
    615         // minimal depth at which to perform collapse 
    616         int minCollapseDepth; 
    617          
    618         // reusable array of split candidates 
    619         vector<SortableEntry> *splitCandidates; 
    620          
    621         ///////////////////////////// 
    622         VspKdStatistics mStat; 
    623          
     510 
    624511        VspKdTree(); 
    625512        virtual ~VspKdTree(); 
     
    697584                                                int &pvsFront); 
    698585 
    699         AxisAlignedBox3 GetBBox(const VspKdTreeNode *node)  
    700         { 
    701                 if (node->parent == NULL) 
    702                         return bbox; 
    703  
    704                 if (!node->IsLeaf()) 
    705                         return ((VspKdTreeInterior *)node)->bbox; 
    706  
    707                 if (node->parent->axis >= 3) 
    708                         return node->parent->bbox; 
    709        
    710                 AxisAlignedBox3 box(node->parent->bbox); 
    711                 if (node->parent->front == node) 
    712                         box.SetMin(node->parent->axis, node->parent->position); 
    713                 else 
    714                         box.SetMax(node->parent->axis, node->parent->position); 
    715                 return box; 
    716         } 
    717  
    718         AxisAlignedBox3 GetDirBBox(const VspKdTreeNode *node)  
    719         { 
    720                 if (node->parent == NULL) 
    721                         return dirBBox; 
    722                 if (!node->IsLeaf()) 
    723                         return ((VspKdTreeInterior *)node)->dirBBox; 
    724                 if (node->parent->axis < 3) 
    725                         return node->parent->dirBBox; 
    726      
    727                 AxisAlignedBox3 dBBox(node->parent->dirBBox); 
    728  
    729                 if (node->parent->front == node) 
    730                         dBBox.SetMin(node->parent->axis - 3, node->parent->position); 
    731                 else 
    732                         dBBox.SetMax(node->parent->axis - 3, node->parent->position); 
    733                 return dBBox; 
    734         } 
    735    
    736         int     ReleaseMemory(const int time); 
    737  
    738         int     CollapseSubtree(VspKdTreeNode *node, const int time); 
    739          
    740         void CountAccess(VspKdTreeInterior *node, const long time)  
    741         { 
    742                 ++ node->accesses; 
    743                 node->lastAccessTime = time; 
    744         } 
     586        AxisAlignedBox3 GetBBox(const VspKdTreeNode *node);      
    745587 
    746588        VspKdTreeNode * SubdivideLeaf(VspKdTreeLeaf *leaf, 
     
    759601 
    760602 
    761         int     GetRootPvsSize() const  
    762         { 
    763                 return GetPvsSize(root, bbox); 
    764         } 
     603        int     GetRootPvsSize() const; 
    765604         
    766605        int     GetPvsSize(VspKdTreeNode *node, const AxisAlignedBox3 &box) const; 
     
    774613 
    775614        float GetAvgPvsSize(); 
     615 
     616        /** Get the root of the tree. 
     617        */ 
     618        VspKdTreeNode *GetRoot() const; 
     619 
     620        int CollapseSubtree(VspKdTreeNode *sroot, const int time); 
     621 
     622        const VspKdStatistics &GetStatistics() const { 
     623                return mStat; 
     624        } 
     625         
     626         
     627        ///////////////////////////// 
     628        // Construction parameters 
     629 
     630        // max depth of the tree 
     631        int sTermMaxDepth; 
     632 
     633        // minimal ratio of the volume of the cell and the query volume 
     634        float sTermMinSize; 
     635 
     636        // minimal pvs per node to still get subdivided 
     637        int sTermMinPvs; 
     638 
     639        // minimal ray number per node to still get subdivided 
     640        int sTermMinRays; 
     641         
     642        // maximal cost ration to subdivide a node 
     643        float sTermMaxCostRatio; 
     644         
     645        // maximal contribution per ray to subdivide the node 
     646        float sTermMaxRayContribution; 
     647 
     648protected: 
     649        ///////////////////////////// 
     650        // The core pointer 
     651        VspKdTreeNode *mRoot; 
     652   
     653        ///////////////////////////// 
     654        // Basic properties 
     655 
     656        // total number of nodes of the tree 
     657        int nodes; 
     658         
     659        // axis aligned bounding box of the scene 
     660        AxisAlignedBox3 mBox; 
     661 
     662        // epsilon used for the construction 
     663        float epsilon; 
     664 
     665        // ratio between traversal and intersection costs 
     666        float ct_div_ci; 
     667         
     668        // type of the splitting to use for the tree construction 
     669        enum {ESplitRegular, ESplitHeuristic }; 
     670        int splitType; 
     671         
     672        // maximum alovable memory in MB 
     673        float maxTotalMemory; 
     674 
     675        // maximum alovable memory for static kd tree in MB 
     676        float maxStaticMemory; 
     677 
     678        // this is used during the construction depending 
     679        // on the type of the tree and queries... 
     680        float maxMemory; 
     681 
     682        // minimal acess time for collapse 
     683        int accessTimeThreshold; 
     684 
     685        // minimal depth at which to perform collapse 
     686        int minCollapseDepth; 
     687         
     688        // reusable array of split candidates 
     689        vector<SortableEntry> *splitCandidates; 
     690         
     691        ///////////////////////////// 
     692        VspKdStatistics mStat;   
    776693}; 
    777694 
Note: See TracChangeset for help on using the changeset viewer.