Changeset 500


Ignore:
Timestamp:
01/05/06 00:47:59 (18 years ago)
Author:
mattausch
Message:

added new node primitive ro vspkd tree

Location:
trunk/VUT
Files:
6 edited

Legend:

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

    r498 r500  
    44#include <QtOpenGL> 
    55#include <QWaitCondition> 
     6//#include <QGLPixelBuffer> 
    67 
    78#include "Vector3.h" 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.cpp

    r492 r500  
    19221922        positions--; 
    19231923  } 
     1924  return true; // corr. matt 
    19241925} 
    19251926 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r498 r500  
    17511751        nodeStack.push(mRoot); 
    17521752 
    1753         // planes needed to verify that we found neighbor leaf. 
     1753        // split planes from the root to this node 
     1754        // needed to verify that we found neighbor leaf 
    17541755        vector<Plane3> halfSpaces; 
    17551756        ExtractHalfSpaces(n, halfSpaces); 
     
    17831784                                                isAdjacent = false; 
    17841785                                } 
    1785  
     1786                                // neighbor was found 
    17861787                                if (isAdjacent) 
    17871788                                        neighbors.push_back(dynamic_cast<BspLeaf *>(node)); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp

    r495 r500  
    7575 
    7676// Inline constructor 
    77 VspKdNode::VspKdNode(VspKdInterior *p): 
     77VspKdNode::VspKdNode(VspKdNode *p): 
    7878mParent(p), mAxis(-1), mDepth(p ? p->mDepth + 1 : 0) 
    7979{} 
     
    8383}; 
    8484 
    85 inline VspKdInterior *VspKdNode::GetParent() const 
     85inline VspKdNode *VspKdNode::GetParent() const 
    8686{ 
    8787        return mParent; 
    8888} 
    8989 
    90 inline void VspKdNode::SetParent(VspKdInterior *p) 
     90inline void VspKdNode::SetParent(VspKdNode *p) 
    9191{ 
    9292        mParent = p; 
     
    126126 
    127127void VspKdInterior::ReplaceChildLink(VspKdNode *oldChild, 
    128                                                                                 VspKdNode *newChild) 
     128                                                                        VspKdNode *newChild) 
    129129{ 
    130130        if (mBack == oldChild) 
     
    184184 
    185185 
    186 VspKdLeaf::VspKdLeaf(VspKdInterior *p,  
     186VspKdLeaf::VspKdLeaf(VspKdNode *p,  
    187187                                         const int nRays,  
    188188                                         const int maxCostMisses): 
     
    339339} 
    340340 
    341 /*********************************************************/ 
    342 /*            class VspKdTree implementation             */ 
    343 /*********************************************************/ 
     341 
     342/***************************************************************/ 
     343/*          class VspKdIntermediate implementation             */ 
     344/***************************************************************/ 
     345 
     346 
     347VspKdIntermediate::VspKdIntermediate(VspKdInterior *p): 
     348VspKdNode(p), mBack(NULL), mFront(NULL), mAccesses(0), mLastAccessTime(-1) 
     349{ 
     350} 
     351 
     352 
     353VspKdIntermediate::~VspKdIntermediate() 
     354{ 
     355        DEL_PTR(mFront); 
     356        DEL_PTR(mBack); 
     357} 
     358     
     359         
     360int VspKdIntermediate::Type() const 
     361{ 
     362        return EIntermediate; 
     363} 
     364 
     365 
     366VspKdLeaf *VspKdIntermediate::GetBack() const 
     367{ 
     368        return mBack; 
     369} 
     370 
     371 
     372VspKdLeaf *VspKdIntermediate::GetFront() const 
     373{ 
     374        return mFront; 
     375} 
     376 
     377 
     378void VspKdIntermediate::Print(ostream &s) const 
     379{ 
     380        s << endl << mSplitPlane << endl; 
     381} 
     382 
     383 
     384void VspKdIntermediate::SetupChildLinks(VspKdLeaf *b, VspKdLeaf *f) 
     385{ 
     386        mBack = b; 
     387        mFront = f; 
     388 
     389        b->SetParent(this); 
     390        f->SetParent(this); 
     391} 
     392 
     393 
     394int VspKdIntermediate::ComputeRayIntersection(const RayInfo &rayData, float &t) 
     395{ 
     396        return rayData.ComputeRayIntersection(mSplitPlane, t); 
     397} 
     398 
     399 
     400/*************************************************************/ 
     401/*              class VspKdTree implementation               */ 
     402/*************************************************************/ 
    344403 
    345404 
     
    11311190 
    11321191        // add the new nodes to the tree 
    1133         VspKdInterior *node = new VspKdInterior(leaf->mParent); 
     1192        VspKdInterior *node =  
     1193                new VspKdInterior(dynamic_cast<VspKdInterior *>(leaf->mParent)); 
    11341194 
    11351195        node->mAxis = axis; 
     
    11471207        // replace a link from node's parent 
    11481208        if (leaf->mParent) 
    1149                 leaf->mParent->ReplaceChildLink(leaf, node); 
     1209        { 
     1210                VspKdInterior *parent = dynamic_cast<VspKdInterior *>(leaf->mParent); 
     1211                parent->ReplaceChildLink(leaf, node); 
     1212        } 
    11501213        // and setup child links 
    11511214        node->SetupChildLinks(back, front); 
     
    15701633        VspKdLeaf *newLeaf = new VspKdLeaf(sroot->mParent, rayCount); 
    15711634 
    1572         if (newLeaf->mParent) 
    1573         { 
    1574                 newLeaf->mParent->ReplaceChildLink(sroot, newLeaf); 
     1635        VspKdInterior *parent =  
     1636                dynamic_cast<VspKdInterior *>(newLeaf->mParent); 
     1637 
     1638        if (parent) 
     1639        { 
     1640                parent->ReplaceChildLink(sroot, newLeaf); 
    15751641        } 
    15761642        tstack.push(sroot); 
     
    18341900 
    18351901        if (!node->IsLeaf()) 
    1836                 return (dynamic_cast<VspKdInterior *>(node))->mBox; 
    1837  
    1838         if (node->mParent->mAxis >= 3) 
    1839                 return node->mParent->mBox; 
    1840  
    1841         AxisAlignedBox3 box(node->mParent->mBox); 
    1842         if (node->mParent->GetFront() == node) 
    1843                 box.SetMin(node->mParent->mAxis, node->mParent->mPosition); 
     1902        { 
     1903                if (node->Type() == VspKdNode::EIntermediate) 
     1904            return (dynamic_cast<VspKdInterior *>(node))->mBox; 
     1905                else 
     1906                        return (dynamic_cast<VspKdIntermediate *>(node))->mBox; 
     1907        } 
     1908 
     1909        VspKdInterior *parent = dynamic_cast<VspKdInterior *>(node->mParent); 
     1910 
     1911        if (parent->mAxis >= 3) 
     1912                return parent->mBox; 
     1913 
     1914        AxisAlignedBox3 box(parent->mBox); 
     1915        if (parent->GetFront() == node) 
     1916                box.SetMin(parent->mAxis, parent->mPosition); 
    18441917        else 
    1845                 box.SetMax(node->mParent->mAxis, node->mParent->mPosition); 
     1918                box.SetMax(parent->mAxis, parent->mPosition); 
    18461919 
    18471920        return box; 
     
    23482421                        leaf->SetViewCell(vc); 
    23492422 
     2423                        VspKdInterior *parent =  
     2424                                dynamic_cast<VspKdInterior *>(leaf->mParent); 
    23502425                        // replace a link from node's parent 
    2351                         if (leaf->mParent) 
    2352                                 leaf->mParent->ReplaceChildLink(node, leaf); 
     2426                        if (parent) 
     2427                                parent->ReplaceChildLink(node, leaf); 
    23532428 
    23542429                        delete interior; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h

    r495 r500  
    203203        friend class VspKdTree; 
    204204 
    205         enum {EInterior, ELeaf}; 
     205        enum {EInterior, EIntermediate, ELeaf}; 
    206206 
    207207        /** Constructs new interior node from the parent node. 
    208208        */ 
    209         inline VspKdNode(VspKdInterior *p); 
     209        inline VspKdNode(VspKdNode *p); 
    210210 
    211211        /** Destroys this node and the subtree. 
     
    226226 
    227227        /** Returns time needed to access this node. 
    228         */ 
    229         virtual int GetAccessTime(); // NOTE: don't really know how it is used! 
     228                @NOTE: don't really know how it is used! 
     229        */ 
     230        virtual int GetAccessTime();  
    230231 
    231232        /** Returns parent node. 
    232233        */ 
    233         VspKdInterior *GetParent() const; 
     234        VspKdNode *GetParent() const; 
    234235 
    235236        /** Sets parent node. 
    236237        */ 
    237         void SetParent(VspKdInterior *p); 
     238        void SetParent(VspKdNode *p); 
    238239 
    239240protected: 
     
    242243   
    243244        /// link to the parent 
    244         VspKdInterior *mParent; 
     245        VspKdNode *mParent; 
    245246 
    246247        enum {SPLIT_X = 0, SPLIT_Y, SPLIT_Z}; 
     
    308309 
    309310 
     311/** 
     312        Node type just before leaf holding abitrary split plane 
     313*/ 
     314class VspKdIntermediate: public VspKdNode 
     315{ 
     316public: 
     317        friend class VspKdTree; 
     318 
     319        /** Constructs new interior node from parent node. 
     320        */ 
     321        VspKdIntermediate(VspKdInterior *p); 
     322                         
     323        //virtual int GetAccessTime(); 
     324         
     325        virtual int Type() const; 
     326   
     327        virtual ~VspKdIntermediate(); 
     328     
     329        virtual void Print(ostream &s) const; 
     330 
     331        /** Returns back child. 
     332        */ 
     333        inline VspKdLeaf *GetBack() const; 
     334        /** Returns front child. 
     335        */ 
     336        inline VspKdLeaf *GetFront() const; 
     337 
     338protected: 
     339 
     340        /** Sets pointers to back child and front child. 
     341        */ 
     342        void SetupChildLinks(VspKdLeaf *b, VspKdLeaf *f); 
     343        /** Computes intersection of the ray with the node boundaries. 
     344        */ 
     345        int ComputeRayIntersection(const RayInfo &rayData, float &t); 
     346 
     347        // plane in local modelling coordinates 
     348        Plane3 mSplitPlane; 
     349 
     350        // pointers to children 
     351        VspKdLeaf *mBack; 
     352        VspKdLeaf *mFront; 
     353 
     354        // the bbox of the node 
     355        AxisAlignedBox3 mBox; 
     356 
     357        // data for caching 
     358        long mAccesses; 
     359        long mLastAccessTime; 
     360}; 
     361 
    310362// -------------------------------------------------------------- 
    311363// KD-tree node - leaf node 
     
    322374                @parma maxMisses how many times the max cost ratio was missed on the path to the leaf 
    323375        */ 
    324         VspKdLeaf(VspKdInterior *p,     const int nRays, const int maxCostMisses = 0); 
     376        VspKdLeaf(VspKdNode *p, const int nRays, const int maxCostMisses = 0); 
    325377         
    326378        virtual ~VspKdLeaf(); 
     
    385437        */ 
    386438        int GetMaxCostMisses(); 
    387  
    388439 
    389440        //////////////////////////////////////////// 
     
    413464        int mMaxCostMisses; 
    414465 
    415 private: 
     466//private: 
    416467        /// stores PVS size so we have to evaluate PVS size only once 
    417468        int mPvsSize; 
    418469}; 
    419  
    420470 
    421471 
     
    456506                VspKdNode *mNode; 
    457507                AxisAlignedBox3 mBox; 
     508                //TODO PolygonContainer *mPolys; 
     509 
    458510                int mDepth; 
    459511                //float mPriority; 
     
    480532                { 
    481533                        // return a.node->queries.size() < b.node->queries.size(); 
    482                         VspKdLeaf *leafa = (VspKdLeaf *) a.mNode; 
    483                         VspKdLeaf *leafb = (VspKdLeaf *) b.mNode; 
     534                        VspKdLeaf *leafa = dynamic_cast<VspKdLeaf *>(a.mNode); 
     535                        VspKdLeaf *leafb = dynamic_cast<VspKdLeaf *>(b.mNode); 
    484536#if 0 
    485537                        return 
Note: See TracChangeset for help on using the changeset viewer.