Changeset 479


Ignore:
Timestamp:
12/23/05 11:05:33 (18 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r478 r479  
    177177Simulation { 
    178178        objRenderCost 1.0 
    179         vcOverhead 7.0 
    180         moveSpeed 3.0 
     179        vcOverhead 2.0 
     180        # always between 0 and 1 
     181        moveSpeed 0.00002 
    181182} 
    182183 
     
    208209        # maximal cost for merging a view cell 
    209210        PostProcess { 
    210                 maxCostRatio 5000000 
     211                maxCostRatio 1.4 
    211212                minViewCells 100 
    212213                maxPvsSize   50000 
     
    240241         
    241242        # maximal tested rays for split cost heuristics 
    242         maxTests 10000 
     243        maxTests 500 
    243244         
    244245        # factors for evaluating split plane costs 
     
    261262                #maxAccRayLength        100 
    262263                 
    263                 maxViewCells            1500 
     264                maxViewCells            1000 
    264265                 
    265266                # used for pvs criterium 
     
    288289         
    289290        PostProcess { 
    290                 maxCostRatio 5000000 
    291                 minViewCells 1000 
    292                 maxPvsSize   50000 
     291                maxCostRatio 0.05 
     292                minViewCells 700 
     293                maxPvsSize   500 
    293294        } 
    294295} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp

    r477 r479  
    7777                // probability of view cell 
    7878                const float pInVc = mViewCellsManager->GetProbability(vc); 
    79                 Debug << "prop: " << pInVc << endl; 
    8079                // compute render time of PVS times probability that view point is in view cell 
    8180                const float vcCost = pInVc * mViewCellsManager->GetRendercost(vc, mObjRenderCost); 
    82                 Debug << "cost: " << vcCost << " rcost: " 
    83                           << mViewCellsManager->GetRendercost(vc, mObjRenderCost) << endl; 
    84  
     81         
    8582                // crossing the border of a view cell is depending on the move speed 
    8683                // and the probability that a view cell border is crossed 
    8784                loadPvsOverhead += GetCrossVcProbability() * mVcOverhead; 
    8885 
    89                 Debug << "crossvc: " << GetCrossVcProbability() * mVcOverhead << endl; 
    9086                //-- update statistics 
    9187                renderTime += vcCost; 
     
    105101} 
    106102 
     103 
    107104float RenderSimulator::GetCrossVcProbability() const 
    108105{ 
    109106        // assume the view cells are uniformly distributed 
     107        //NOTE: should I take move speed relative to view space or absolute? 
    110108        const float vcNum =  
    111109                (float)mViewCellsManager->GetViewCells().size(); 
    112110 
    113         return 1.0f - (1 / mMoveSpeed * vcNum); 
     111        const float prop = mMoveSpeed * vcNum; 
     112 
     113        // clamp probability between 0 and 1 
     114        return min(1.0f, prop); 
    114115} 
    115116 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r478 r479  
    5555} 
    5656 
     57void ViewCell::UpdateViewCellsStats(ViewCellsStatistics &vcStat) 
     58{ 
     59        ++ vcStat.viewCells; 
     60                 
     61        const int pvsSize = mPvs.GetSize(); 
     62 
     63        vcStat.pvs += pvsSize; 
     64 
     65        if (pvsSize == 0) 
     66                ++ vcStat.emptyPvs; 
     67 
     68        if (pvsSize > vcStat.maxPvs) 
     69                vcStat.maxPvs = pvsSize; 
     70 
     71        if (pvsSize < vcStat.minPvs) 
     72                vcStat.minPvs = pvsSize; 
     73} 
    5774 
    5875float ViewCell::GetArea() const 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h

    r478 r479  
    1616class VspKdLeaf; 
    1717class KdLeaf; 
    18  
    19 /** 
    20         View cell with an optional mesh representation 
    21 */ 
    22 class ViewCell: public MeshInstance 
    23 { 
    24 public: 
    25         ViewCell(); 
    26  
    27         /** Constructor taking a mesh representing the shape of the viewcell. 
    28         */ 
    29         ViewCell(Mesh *mesh); 
    30  
    31         /** Default destructor. 
    32         */ 
    33         virtual ~ViewCell() {} 
    34         /** Returns Pvs. 
    35         */ 
    36         const ObjectPvs &GetPvs() const; 
    37         ObjectPvs &GetPvs(); 
    38  
    39         int Type() const; 
    40  
    41         /** Adds a passing ray to the passing ray container. 
    42         */ 
    43         void AddPassingRay(const Ray &ray, const int contributions); 
    44  
    45         /** Returns volume of the view cell. 
    46         */ 
    47         float GetVolume() const; 
    48  
    49         /** Returns area of the view cell. 
    50         */ 
    51         float GetArea() const; 
    52  
    53         /** Sets the volume of the view cell. 
    54         */ 
    55         void SetVolume(float volume); 
    56          
    57         /** Sets the area of the view cell. 
    58         */ 
    59         void SetArea(float area); 
    60  
    61         /// Ray set description of the rays passing through this node. 
    62         PassingRaySet mPassingRays; 
    63  
    64         /// Rays piercing this view cell. 
    65         RayContainer mPiercingRays; 
    66  
    67 protected: 
    68  
    69         /// the potentially visible objects 
    70         ObjectPvs mPvs; 
    71  
    72         float mVolume; 
    73         float mArea; 
    74 }; 
    75  
    76 /** 
    77         View cell belonging to a hierarchy. 
    78 */ 
    79 template<typename T> 
    80 class HierarchyViewCell: public ViewCell 
    81 { 
    82 public: 
    83         HierarchyViewCell<T>(): mLeaves(0) {} 
    84         HierarchyViewCell<T>(Mesh *mesh): 
    85                 ViewCell(mesh), mLeaves(0) {} 
    86  
    87         /// Leaves of the hierarchy which are part of this view cell. 
    88         std::vector<T> mLeaves; 
    89 }; 
    90  
    91 typedef HierarchyViewCell<BspLeaf *> BspViewCell; 
    92 typedef HierarchyViewCell<KdLeaf *> KdViewCell; 
    93 typedef HierarchyViewCell<VspKdLeaf *> VspKdViewCell; 
    94  
    9518 
    9619/** Statistics for a view cell partition. 
     
    15275}; 
    15376 
     77/** 
     78        View cell with an optional mesh representation 
     79*/ 
     80class ViewCell: public MeshInstance 
     81{ 
     82public: 
     83        ViewCell(); 
     84 
     85        /** Constructor taking a mesh representing the shape of the viewcell. 
     86        */ 
     87        ViewCell(Mesh *mesh); 
     88 
     89        /** Default destructor. 
     90        */ 
     91        virtual ~ViewCell() {} 
     92        /** Returns Pvs. 
     93        */ 
     94        const ObjectPvs &GetPvs() const; 
     95        ObjectPvs &GetPvs(); 
     96 
     97        int Type() const; 
     98 
     99        /** Adds a passing ray to the passing ray container. 
     100        */ 
     101        void AddPassingRay(const Ray &ray, const int contributions); 
     102 
     103        /** Returns volume of the view cell. 
     104        */ 
     105        float GetVolume() const; 
     106 
     107        /** Returns area of the view cell. 
     108        */ 
     109        float GetArea() const; 
     110 
     111        /** Sets the volume of the view cell. 
     112        */ 
     113        void SetVolume(float volume); 
     114         
     115        /** Sets the area of the view cell. 
     116        */ 
     117        void SetArea(float area); 
     118        virtual void UpdateViewCellsStats(ViewCellsStatistics &vcStat); 
     119 
     120        /// Ray set description of the rays passing through this node. 
     121        PassingRaySet mPassingRays; 
     122 
     123        /// Rays piercing this view cell. 
     124        RayContainer mPiercingRays; 
     125 
     126protected: 
     127 
     128        /// the potentially visible objects 
     129        ObjectPvs mPvs; 
     130 
     131        float mVolume; 
     132        float mArea; 
     133}; 
     134 
     135/** 
     136        View cell belonging to a hierarchy. 
     137*/ 
     138template<typename T> 
     139class HierarchyViewCell: public ViewCell 
     140{ 
     141public: 
     142        HierarchyViewCell<T>(): mLeaves(0) {} 
     143        HierarchyViewCell<T>(Mesh *mesh): 
     144                ViewCell(mesh), mLeaves(0) {} 
     145 
     146        void UpdateViewCellsStats(ViewCellsStatistics &vcStat) 
     147        { 
     148                ViewCell::UpdateViewCellsStats(vcStat); 
     149 
     150                if ((int)mLeaves.size() > vcStat.maxLeaves) 
     151                        vcStat.maxLeaves = (int)mLeaves.size(); 
     152        } 
     153 
     154        /// Leaves of the hierarchy which are part of this view cell. 
     155        std::vector<T> mLeaves; 
     156}; 
     157 
     158 
     159typedef HierarchyViewCell<BspLeaf *> BspViewCell; 
     160typedef HierarchyViewCell<KdLeaf *> KdViewCell; 
     161typedef HierarchyViewCell<VspKdLeaf *> VspKdViewCell; 
     162 
     163 
    154164#endif 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r478 r479  
    11781178 
    11791179Plane3 BspTree::ChooseCandidatePlane(const BoundedRayContainer &rays) const 
    1180 {       return Plane3(); 
    1181         /*const int candidateIdx = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 
    1182          
    1183         const Vector3 minPt = rays[candidateIdx].ExtrapOrigin(); 
    1184         const Vector3 maxPt = rays[candidateIdx].ExtrapTermination(); 
     1180{        
     1181        const int candidateIdx = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 
     1182        BoundedRay *bRay = rays[candidateIdx]; 
     1183        Ray *ray = bRay->mRay; 
     1184 
     1185        const Vector3 minPt = ray->Extrap(bRay->mMinT); 
     1186        const Vector3 maxPt = ray->Extrap(bRay->mMaxT); 
    11851187 
    11861188        const Vector3 pt = (maxPt + minPt) * 0.5; 
    1187         const Vector3 normal = Normalize(rays[candidateIdx].mRay->GetDir()); 
    1188  
    1189         return Plane3(normal, pt);*/ 
     1189 
     1190        const Vector3 normal = ray->GetDir(); 
     1191                         
     1192        return Plane3(normal, pt); 
    11901193} 
    11911194 
    11921195Plane3 BspTree::ChooseCandidatePlane2(const BoundedRayContainer &rays) const 
    1193 {       return Plane3(); 
    1194         /*Vector3 pt[3]; 
    1195          
     1196{        
     1197        Vector3 pt[3]; 
    11961198        int idx[3]; 
    11971199        int cmaxT = 0; 
     
    11991201        bool chooseMin = false; 
    12001202 
    1201         for (int j = 0; j < 3; ++ j) 
    1202         { 
    1203                 idx[j] = (int)RandomValue(0, (Real)((int)rays.size() * 2 - 1)); 
    1204                          
     1203        for (int j = 0; j < 3; j ++) 
     1204        { 
     1205                idx[j] = (int)RandomValue(0, Real((int)rays.size() * 2 - 1)); 
     1206                                 
    12051207                if (idx[j] >= (int)rays.size()) 
    12061208                { 
    1207                         idx[j] -= (int)rays.size(); 
    1208                                  
     1209                        idx[j] -= (int)rays.size();              
    12091210                        chooseMin = (cminT < 2); 
    12101211                } 
     
    12121213                        chooseMin = (cmaxT < 2); 
    12131214 
    1214                 RayInfo rayInf = rays[idx[j]]; 
    1215                 pt[j] = chooseMin ? rayInf.ExtrapOrigin() : rayInf.ExtrapTermination(); 
     1215                BoundedRay *bRay = rays[idx[j]]; 
     1216                pt[j] = chooseMin ? bRay->mRay->Extrap(bRay->mMinT) :  
     1217                                                        bRay->mRay->Extrap(bRay->mMaxT); 
    12161218        }        
    1217  
    1218         return Plane3(pt[0], pt[1], pt[2]);*/ 
     1219                         
     1220        return Plane3(pt[0], pt[1], pt[2]); 
    12191221} 
    12201222 
    12211223Plane3 BspTree::ChooseCandidatePlane3(const BoundedRayContainer &rays) const 
    1222 {       return Plane3();/* 
     1224{        
    12231225        Vector3 pt[3]; 
    12241226         
     
    12301232                idx2 = (idx2 + 1) % (int)rays.size(); 
    12311233 
    1232         const RayInfo ray1 = rays[idx1]; 
    1233         const RayInfo ray2 = rays[idx2]; 
     1234        const BoundedRay *ray1 = rays[idx1]; 
     1235        const BoundedRay *ray2 = rays[idx2]; 
    12341236 
    12351237        // normal vector of the plane parallel to both lines 
    1236         const Vector3 norm = Normalize(CrossProd(ray1.mRay->GetDir(), ray2.mRay->GetDir())); 
     1238        const Vector3 norm =  
     1239                Normalize(CrossProd(ray1->mRay->GetDir(), ray2->mRay->GetDir())); 
     1240 
     1241        const Vector3 orig1 = ray1->mRay->Extrap(ray1->mMinT); 
     1242        const Vector3 orig2 = ray2->mRay->Extrap(ray2->mMinT); 
    12371243 
    12381244        // vector from line 1 to line 2 
    1239         const Vector3 vd = (ray2.ExtrapOrigin() - ray1.ExtrapOrigin()); 
     1245        const Vector3 vd = orig1 - orig2; 
    12401246         
    12411247        // project vector on normal to get distance 
     
    12431249 
    12441250        // point on plane lies halfway between the two planes 
    1245         const Vector3 planePt = ray1.ExtrapOrigin() + norm * dist * 0.5; 
    1246  
    1247         return Plane3(norm, planePt);*/ 
     1251        const Vector3 planePt = orig1 + norm * dist * 0.5; 
     1252 
     1253        return Plane3(norm, planePt); 
    12481254} 
    12491255 
     
    20112017} 
    20122018 
    2013 void BspTree::EvaluateViewCellsStats(ViewCellsStatistics &vcStat) const 
    2014 { 
    2015         vcStat.Reset(); 
    2016  
    2017         stack<BspNode *> nodeStack; 
    2018         nodeStack.push(mRoot); 
    2019  
    2020         ViewCell::NewMail(); 
    2021  
    2022         // exclude root cell 
    2023         mRootCell->Mail(); 
    2024  
    2025         while (!nodeStack.empty())  
    2026         { 
    2027                 BspNode *node = nodeStack.top(); 
    2028                 nodeStack.pop(); 
    2029  
    2030                 if (node->IsLeaf())  
    2031                 { 
    2032                         ++ vcStat.leaves; 
    2033  
    2034                         BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->mViewCell; 
    2035  
    2036                         if (!viewCell->Mailed())  
    2037                         { 
    2038                                 viewCell->Mail(); 
    2039                                  
    2040                                 ++ vcStat.viewCells; 
    2041                                 const int pvsSize = viewCell->GetPvs().GetSize(); 
    2042  
    2043                 vcStat.pvs += pvsSize; 
    2044  
    2045                                 if (pvsSize < 1) 
    2046                                         ++ vcStat.emptyPvs; 
    2047  
    2048                                 if (pvsSize > vcStat.maxPvs) 
    2049                                         vcStat.maxPvs = pvsSize; 
    2050  
    2051                                 if (pvsSize < vcStat.minPvs) 
    2052                                         vcStat.minPvs = pvsSize; 
    2053  
    2054                                 if ((int)viewCell->mLeaves.size() > vcStat.maxLeaves) 
    2055                                         vcStat.maxLeaves = (int)viewCell->mLeaves.size();                
    2056                         } 
    2057                 } 
    2058                 else  
    2059                 { 
    2060                         BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    2061  
    2062                         nodeStack.push(interior->GetFront()); 
    2063                         nodeStack.push(interior->GetBack()); 
    2064                 } 
    2065         } 
    2066 } 
    20672019 
    20682020BspTreeStatistics &BspTree::GetStat() 
     
    20702022        return mStat; 
    20712023} 
     2024 
    20722025 
    20732026float BspTree::AccumulatedRayLength(BoundedRayContainer &rays) const 
     
    20852038        return len; 
    20862039} 
     2040 
    20872041 
    20882042int BspTree::SplitRays(const Plane3 &plane, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r478 r479  
    457457        BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 
    458458 
    459         /** Traverses tree and counts all view cells as well as their PVS size. 
    460         */ 
    461         void EvaluateViewCellsStats(ViewCellsStatistics &stat) const; 
    462  
    463459        /** Returns view cell corresponding to unbounded space. 
    464460        */ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r478 r479  
    7272} 
    7373 
     74void ViewCellsManager::EvaluateViewCellsStats() 
     75{ 
     76        mViewCellsStats.Reset(); 
     77 
     78        ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 
     79 
     80        for (it = mViewCells.begin(); it != it_end; ++ it) 
     81                (*it)->UpdateViewCellsStats(mViewCellsStats); 
     82} 
     83 
    7484void ViewCellsManager::AddViewCell(ViewCell *viewCell) 
    7585{ 
     
    378388        } 
    379389 
    380         mBspTree->EvaluateViewCellsStats(mViewCellsStats); 
     390        EvaluateViewCellsStats(); 
    381391 
    382392        // destroy rays created only for construction 
     
    396406        // compute view cell area as subsititute for probability 
    397407#if 0 
    398         return GetArea(viewCell) / mBspTree->GetBoundingBox().SurfaceArea(); 
     408        return GetArea(viewCell) / GetSceneBbox().SurfaceArea(); 
    399409#else 
    400410        return GetArea(viewCell) / GetAccVcArea(); 
     
    520530        // reset view cells and stats 
    521531        mViewCells.clear(); 
     532        mTotalAreaValid = false; 
    522533        mBspTree->CollectViewCells(mViewCells); 
    523534        mViewCellsStats.Reset(); 
    524         mBspTree->EvaluateViewCellsStats(mViewCellsStats); 
     535        EvaluateViewCellsStats(); 
    525536 
    526537        return merged; 
     
    699710                        CLEAR_CONTAINER(vcGeom); 
    700711                } 
     712                         
    701713                         
    702714                Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
     
    840852float KdViewCellsManager::GetProbability(ViewCell *viewCell) 
    841853{ 
    842         // compute view cell area as subsititute for probability 
    843         AxisAlignedBox3 box = mKdTree->GetBox(mKdTree->GetRoot()); 
     854        // compute view cell area / volume as subsititute for probability 
    844855#if 0 
    845         return GetArea(viewCell) / box.SurfaceArea(); 
    846 #else 
     856        return GetArea(viewCell) / GetSceneBbox().SurfaceArea(); 
     857#endif 
     858#if 1 
    847859        return GetArea(viewCell) / GetAccVcArea(); 
    848860#endif 
     861#if 0 
     862        return GetVolume(viewCell) / GetSceneBbox().GetVolume(); 
     863#endif 
    849864} 
    850865 
     
    855870} 
    856871 
     872 
    857873AxisAlignedBox3 KdViewCellsManager::GetSceneBbox() const 
    858874{ 
    859875        return mKdTree->GetBox(); 
    860876} 
     877 
    861878 
    862879int KdViewCellsManager::Construct(const ObjectContainer &objects,  
     
    872889        // create the view cells 
    873890        mKdTree->CreateAndCollectViewCells(mViewCells); 
    874         //mKdTree->EvaluateViewCellsStats(mViewCellsStats); 
     891        EvaluateViewCellsStats(); 
    875892 
    876893        return 0; 
     
    901918        const int pvsOut = min((int)objects.size(), 10); 
    902919        VssRayContainer *rays = new VssRayContainer[pvsOut]; 
    903  
    904   //$$ JB 
    905 //#if 0 
    906920 
    907921        if (useViewCells) 
     
    927941                         
    928942                        cout << "creating output for view cell " << i << " ... "; 
    929                          
     943#if 0                    
    930944                        // check whether we can add the current ray to the output rays 
    931                         /*for (int k = 0; k < raysOut; ++ k)  
     945                        for (int k = 0; k < raysOut; ++ k)  
    932946                        { 
    933947                                Ray *ray = sampleRays[k]; 
     
    942956                                        } 
    943957                                } 
    944                         }*/ 
    945                          
     958                        } 
     959#endif                   
    946960                        Intersectable::NewMail(); 
    947961                         
     
    11361150        mVspKdTree->Construct(constructionRays, sceneBbox); 
    11371151        mVspKdTree->CollectViewCells(mViewCells); 
    1138         //mVspBspTree->EvaluateViewCellsStats(mViewCellsStats); 
     1152        EvaluateViewCellsStats(); 
    11391153 
    11401154        Debug << mVspKdTree->GetStatistics() << endl; 
     
    13311345{ 
    13321346#if 0 
    1333         return GetArea(viewCell) / mVspBspTree->GetBbox().SurfaceArea(); 
     1347        return GetArea(viewCell) / GetSceneBbox().SurfaceArea(); 
    13341348#else 
    13351349        return GetArea(viewCell) / GetAccVcArea(); 
     
    13381352 
    13391353 
    1340 float VspBspViewCellsManager::GetArea(ViewCell *viewCell) const 
    1341 { 
    1342         PolygonContainer geom; 
    1343  
    1344         // compute view cell area 
    1345         mVspBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(viewCell), geom); 
    1346          
    1347         const float area = Polygon3::GetArea(geom); 
    1348         CLEAR_CONTAINER(geom); 
    1349  
    1350         return area; 
    1351 } 
    1352  
    13531354float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell,  
    13541355                                                                                        float objRendercost) const 
     
    13921393        mVspBspTree->Construct(constructionRays); 
    13931394        mVspBspTree->CollectViewCells(mViewCells); 
    1394         mVspBspTree->EvaluateViewCellsStats(mViewCellsStats); 
     1395        EvaluateViewCellsStats(); 
    13951396 
    13961397        Debug << mVspBspTree->GetStatistics() << endl; 
     
    15321533        // reset view cells and stats 
    15331534        mViewCells.clear(); 
     1535        mTotalAreaValid = false; 
    15341536        mVspBspTree->CollectViewCells(mViewCells); 
    15351537        mViewCellsStats.Reset(); 
    1536         mVspBspTree->EvaluateViewCellsStats(mViewCellsStats); 
     1538        EvaluateViewCellsStats(); 
    15371539 
    15381540        return merged; 
     
    16961698                        CLEAR_CONTAINER(vcGeom); 
    16971699                } 
     1700                         
    16981701                         
    16991702                Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r478 r479  
    207207 
    208208protected: 
     209        /** Evaluates view cells statistics and stores it in 
     210                mViewCellsStatistics. 
     211        */ 
     212        void EvaluateViewCellsStats(); 
    209213                 
    210214        /// the view cell corresponding to unbounded space 
     
    438442        float GetProbability(ViewCell *viewCell); 
    439443        float GetRendercost(ViewCell *viewCell, float objRendercost) const; 
    440         float GetArea(ViewCell *viewCell) const; 
    441  
     444         
    442445        AxisAlignedBox3 GetSceneBbox() const; 
    443446 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r478 r479  
    800800 
    801801        // vector from line 1 to line 2 
    802         const Vector3 vd = (ray2.ExtrapOrigin() - ray1.ExtrapOrigin()); 
     802        const Vector3 vd = ray2.ExtrapOrigin() - ray1.ExtrapOrigin(); 
    803803         
    804804        // project vector on normal to get distance 
     
    13061306} 
    13071307 
    1308 void VspBspTree::EvaluateViewCellsStats(ViewCellsStatistics &stat) const 
    1309 { 
    1310         stat.Reset(); 
    1311  
    1312         stack<BspNode *> nodeStack; 
    1313         nodeStack.push(mRoot); 
    1314  
    1315         ViewCell::NewMail(); 
    1316  
    1317         // exclude root cell 
    1318         mRootCell->Mail(); 
    1319  
    1320         while (!nodeStack.empty())  
    1321         { 
    1322                 BspNode *node = nodeStack.top(); 
    1323                 nodeStack.pop(); 
    1324  
    1325                 if (node->IsLeaf())  
    1326                 { 
    1327                         ++ stat.leaves; 
    1328  
    1329                         BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
    1330  
    1331                         if (!viewCell->Mailed())  
    1332                         { 
    1333                                 viewCell->Mail(); 
    1334                                  
    1335                                 ++ stat.viewCells; 
    1336                                 const int pvsSize = viewCell->GetPvs().GetSize(); 
    1337  
    1338                 stat.pvs += pvsSize; 
    1339  
    1340                                 if (pvsSize < 1) 
    1341                                         ++ stat.emptyPvs; 
    1342  
    1343                                 if (pvsSize > stat.maxPvs) 
    1344                                         stat.maxPvs = pvsSize; 
    1345  
    1346                                 if (pvsSize < stat.minPvs) 
    1347                                         stat.minPvs = pvsSize; 
    1348  
    1349                                 if ((int)viewCell->mLeaves.size() > stat.maxLeaves) 
    1350                                         stat.maxLeaves = (int)viewCell->mLeaves.size();          
    1351                         } 
    1352                 } 
    1353                 else  
    1354                 { 
    1355                         BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    1356  
    1357                         nodeStack.push(interior->GetFront()); 
    1358                         nodeStack.push(interior->GetBack()); 
    1359                 } 
    1360         } 
    1361 } 
    13621308 
    13631309BspTreeStatistics &VspBspTree::GetStat() 
     
    13651311        return mStat; 
    13661312} 
     1313 
    13671314 
    13681315float VspBspTree::AccumulatedRayLength(const RayInfoContainer &rays) const 
     
    13771324        return len; 
    13781325} 
     1326 
    13791327 
    13801328int VspBspTree::SplitRays(const Plane3 &plane, 
     
    14261374        return splits; 
    14271375} 
     1376 
    14281377 
    14291378void VspBspTree::ExtractHalfSpaces(BspNode *n, vector<Plane3> &halfSpaces) const 
     
    18891838} 
    18901839 
     1840 
     1841BspNode *VspBspTree::CollapseTree(BspNode *node) 
     1842{ 
     1843    if (node->IsLeaf()) 
     1844                return node; 
     1845 
     1846        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     1847 
     1848        BspNode *front = CollapseTree(interior->GetFront()); 
     1849        BspNode *back = CollapseTree(interior->GetBack()); 
     1850 
     1851        if (front->IsLeaf() && back->IsLeaf()) 
     1852        { 
     1853                BspLeaf *frontLeaf = dynamic_cast<BspLeaf *>(front); 
     1854                BspLeaf *backLeaf = dynamic_cast<BspLeaf *>(back); 
     1855 
     1856                //-- collapse tree 
     1857                if (frontLeaf->GetViewCell() == backLeaf->GetViewCell()) 
     1858                { 
     1859                        BspViewCell *vc = frontLeaf->GetViewCell(); 
     1860 
     1861                        BspLeaf *leaf = new BspLeaf(interior->GetParent(), vc); 
     1862                         
     1863                        // replace a link from node's parent 
     1864                        if (leaf->GetParent()) 
     1865                                leaf->GetParent()->ReplaceChildLink(node, leaf); 
     1866 
     1867                        delete interior; 
     1868 
     1869                        return leaf; 
     1870                } 
     1871        } 
     1872 
     1873        return node; 
     1874} 
     1875 
     1876 
     1877void VspBspTree::RepairVcLeafLists() 
     1878{ 
     1879        // list not valid anymore => clear 
     1880        stack<BspNode *> nodeStack; 
     1881        nodeStack.push(mRoot); 
     1882 
     1883        ViewCell::NewMail(); 
     1884 
     1885        while (!nodeStack.empty()) 
     1886        { 
     1887                BspNode *node = nodeStack.top(); 
     1888                nodeStack.pop(); 
     1889 
     1890                if (node->IsLeaf()) 
     1891                { 
     1892                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     1893 
     1894                        BspViewCell *viewCell = leaf->GetViewCell(); 
     1895 
     1896                        if (!viewCell->Mailed()) 
     1897                        { 
     1898                                viewCell->mLeaves.clear(); 
     1899                                viewCell->Mail(); 
     1900                        } 
     1901 
     1902                        viewCell->mLeaves.push_back(leaf); 
     1903                } 
     1904                else 
     1905                { 
     1906                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     1907 
     1908                        nodeStack.push(interior->GetFront()); 
     1909                        nodeStack.push(interior->GetBack()); 
     1910                } 
     1911        } 
     1912} 
     1913 
     1914 
    18911915int VspBspTree::MergeLeaves() 
    18921916{ 
     
    19331957        int merged = 0; 
    19341958 
    1935         Debug << "here234: " << mMergeMaxCostRatio << endl; 
     1959        Debug << "mergecost: " << mergeQueue.top().GetMergeCost() / BspMergeCandidate::sOverallCost << " " << mMergeMaxCostRatio << endl; 
     1960        Debug << "overall cost: " << BspMergeCandidate::sOverallCost << endl; 
    19361961 
    19371962        // use priority queue to merge leaves 
    1938         while (!mergeQueue.empty() && (vcSize > mMergeMinViewCells) )//&& 
    1939                    //(mergeQueue.top().GetMergeCost() <  
    1940                     //mMergeMaxCostRatio / BspMergeCandidate::sOverallCost)) 
    1941         { 
    1942                 Debug << "mergecost: " << mergeQueue.top().GetMergeCost() << " " << mMergeMaxCostRatio << endl; 
     1963        while (!mergeQueue.empty() && (vcSize > mMergeMinViewCells) && 
     1964                   (mergeQueue.top().GetMergeCost() <  
     1965                    mMergeMaxCostRatio * BspMergeCandidate::sOverallCost)) 
     1966        { 
     1967                Debug << "mergecost: " << mergeQueue.top().GetMergeCost() / BspMergeCandidate::sOverallCost << " " << mMergeMaxCostRatio << endl; 
    19431968                BspMergeCandidate mc = mergeQueue.top(); 
    19441969                mergeQueue.pop(); 
     
    19701995 
    19711996        // collapse tree according to view cell partition 
    1972         //CollapseTree(mRoot); 
    1973  
     1997        CollapseTree(mRoot); 
    19741998        // revalidate leaves 
    1975         //ValidateViewCellLeaves(); 
     1999        RepairVcLeafLists(); 
    19762000 
    19772001        //Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl; 
     
    19962020 
    19972021        // set new size of view cell 
    1998         vc->SetArea(fVc->GetVolume() + bVc->GetVolume()); 
     2022        vc->SetArea(fVc->GetArea() + bVc->GetArea()); 
    19992023 
    20002024        vector<BspLeaf *> fLeaves = fVc->mLeaves; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r478 r479  
    225225        BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 
    226226 
    227         /** Traverses tree and counts all view cells as well as their PVS size. 
    228         */ 
    229         void EvaluateViewCellsStats(ViewCellsStatistics &stat) const; 
    230  
    231  
    232227        /** Returns view cell corresponding to unbounded space. 
    233228        */ 
     
    246241        */ 
    247242        int MergeLeaves(); 
    248  
    249  
    250243                 
    251244        /** Sets pointer to view cells manager. 
    252245        */ 
    253246        void SetViewCellsManager(ViewCellsManager *vcm); 
     247 
     248        /** Helper function revalidating the view cell leaf list after merge. 
     249        */ 
     250        void RepairVcLeafLists(); 
     251 
     252        /** Collapses the tree with respect to the view cell partition. 
     253                @returns node of type leaf if the node could be collapsed, this node otherwise 
     254        */ 
     255        BspNode *CollapseTree(BspNode *node); 
     256         
    254257 
    255258protected: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp

    r478 r479  
    20222022        leaf->SetViewCell(vc); 
    20232023 
    2024         vc->SetArea(GetBBox(leaf).GetVolume()); 
     2024        vc->SetVolume(GetBBox(leaf).GetVolume()); 
     2025        vc->SetArea(GetBBox(leaf).SurfaceArea()); 
     2026 
    20252027        vc->mLeaves.push_back(leaf); 
    20262028 
     
    20362038        } 
    20372039} 
    2038  
    2039  
    2040 void VspKdTree::EvaluateViewCellsStats(ViewCellsStatistics &vcStat) const 
    2041 { 
    2042         vcStat.Reset(); 
    2043  
    2044         stack<VspKdNode *> nodeStack; 
    2045         nodeStack.push(mRoot); 
    2046  
    2047         ViewCell::NewMail(); 
    2048  
    2049         while (!nodeStack.empty()) 
    2050         { 
    2051                 VspKdNode *node = nodeStack.top(); 
    2052                 nodeStack.pop(); 
    2053  
    2054                 if (node->IsLeaf()) 
    2055                 { 
    2056                         ++ vcStat.leaves; 
    2057  
    2058                         VspKdViewCell *viewCell = dynamic_cast<VspKdLeaf *>(node)->mViewCell; 
    2059  
    2060                         if (!viewCell->Mailed()) 
    2061                         { 
    2062                                 viewCell->Mail(); 
    2063  
    2064                                 ++ vcStat.viewCells; 
    2065                                 const int pvsSize = viewCell->GetPvs().GetSize(); 
    2066  
    2067                 vcStat.pvs += pvsSize; 
    2068  
    2069                                 if (pvsSize < 1) 
    2070                                         ++ vcStat.emptyPvs; 
    2071  
    2072                                 if (pvsSize > vcStat.maxPvs) 
    2073                                         vcStat.maxPvs = pvsSize; 
    2074  
    2075                                 if (pvsSize < vcStat.minPvs) 
    2076                                         vcStat.minPvs = pvsSize; 
    2077  
    2078                                 if ((int)viewCell->mLeaves.size() > vcStat.maxLeaves) 
    2079                                         vcStat.maxLeaves = (int)viewCell->mLeaves.size(); 
    2080                         } 
    2081                 } 
    2082                 else 
    2083                 { 
    2084                         VspKdInterior *interior = dynamic_cast<VspKdInterior *>(node); 
    2085  
    2086                         nodeStack.push(interior->GetFront()); 
    2087                         nodeStack.push(interior->GetBack()); 
    2088                 } 
    2089         } 
    2090 } 
    2091  
    20922040 
    20932041 
     
    21062054 
    21072055        // set new size of view cell 
    2108         vc->SetArea(fVc->GetVolume() + bVc->GetVolume()); 
     2056        vc->SetVolume(fVc->GetVolume() + bVc->GetVolume()); 
    21092057 
    21102058        vector<VspKdLeaf *> fLeaves = fVc->mLeaves; 
     
    22222170        } 
    22232171 
    2224         // collapse tree according to view cell partition 
     2172        // collapse siblings belonging to the same view cell 
    22252173        CollapseTree(mRoot); 
    2226  
    22272174        // revalidate leaves 
    2228         ValidateViewCellLeaves(); 
     2175        RepairVcLeafLists(); 
    22292176 
    22302177        //Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl; 
     
    22352182 
    22362183 
    2237 void VspKdTree::ValidateViewCellLeaves() 
     2184void VspKdTree::RepairVcLeafLists() 
    22382185{ 
    22392186        // list not valid anymore => clear 
     
    22712218        } 
    22722219} 
     2220 
    22732221 
    22742222VspKdNode *VspKdTree::CollapseTree(VspKdNode *node) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h

    r474 r479  
    597597        void CollectViewCells(ViewCellContainer &viewCells) const; 
    598598 
    599         /** Traverses tree and counts all view cells as well as their PVS size. 
    600         */ 
    601         void EvaluateViewCellsStats(ViewCellsStatistics &stat) const; 
    602  
    603599        /** Refines view cells in a post processing step. 
    604600        */ 
     
    715711        /** Helper function revalidating the view cell leaf list after merge. 
    716712        */ 
    717         void ValidateViewCellLeaves(); 
     713        void RepairVcLeafLists(); 
    718714 
    719715protected: 
Note: See TracChangeset for help on using the changeset viewer.