Changeset 1121


Ignore:
Timestamp:
07/12/06 00:52:51 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1112 r1121  
    20542054        RegisterOption("VspBspTree.Construction.renderCostDecreaseWeight", 
    20552055                        optFloat, 
    2056                         "vsp_bsp_post_process_render_cost_decrease_weight=", 
     2056                        "vsp_bsp_construction_render_cost_decrease_weight=", 
    20572057                        "0.99"); 
    20582058 
     
    20982098                                        "vsp_construction_samples=", 
    20992099                                        "10000"); 
     2100 
     2101         
     2102        RegisterOption("VspTree.Construction.renderCostDecreaseWeight", 
     2103                        optFloat, 
     2104                        "vsp_construction_render_cost_decrease_weight=", 
     2105                        "0.99"); 
    21002106 
    21012107        RegisterOption("VspTree.Termination.maxDepth", 
     
    22822288                "false"); 
    22832289 
    2284  
    22852290        RegisterOption("OspTree.subdivisionStats", 
    22862291                                        optString, 
     
    22932298                                        "0.01"); 
    22942299 
     2300        RegisterOption("OspTree.Construction.renderCostDecreaseWeight", 
     2301                        optFloat, 
     2302                        "osp_construction_render_cost_decrease_weight=", 
     2303                        "0.99"); 
     2304 
     2305        RegisterOption("OspTree.Evaluation.countKdPvs", 
     2306                optBool, 
     2307                "osp_evaluation_count_kd_pvs=", 
     2308                "false"); 
    22952309 
    22962310 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp

    r863 r1121  
    1  
    21#include "X3dExporter.h" 
    32#include "VrmlExporter.h" 
     3#include "VspOspTree.h" 
     4#include "KdTree.h" 
     5 
    46 
    57namespace GtpVisibilityPreprocessor { 
     
    2628} 
    2729 
     30 
     31bool Exporter::ExportOspTree(const OspTree &ospTree, const int maxPvs) 
     32{ 
     33        vector<KdLeaf *> leaves; 
     34        ospTree.CollectLeaves(leaves); 
     35 
     36        mUseForcedMaterial = true; 
     37 
     38        vector<KdLeaf *>::const_iterator it, it_end = leaves.end(); 
     39 
     40        Material white;  
     41        white.mDiffuseColor.r = 1; 
     42        white.mDiffuseColor.g = 1; 
     43        white.mDiffuseColor.b = 1; 
     44         
     45        for (it = leaves.begin(); it != it_end; ++ it) 
     46        { 
     47                KdLeaf *leaf = *it; 
     48 
     49                SetWireframe(); 
     50                SetForcedMaterial(white); 
     51                ExportBox(ospTree.GetBBox(leaf)); 
     52 
     53                SetFilled(); 
     54 
     55                if (maxPvs) // color code pvs 
     56                { 
     57                        mForcedMaterial.mDiffuseColor.b = 1.0f; 
     58                        const float importance = (float)ospTree.ComputePvsSize(leaf->mObjects) / (float)maxPvs; 
     59 
     60                        mForcedMaterial.mDiffuseColor.r = importance; 
     61                        mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r; 
     62                } 
     63                else 
     64                { 
     65                        SetForcedMaterial(RandomMaterial()); 
     66                } 
     67 
     68                ExportGeometry(leaf->mObjects);  
     69        } 
     70 
     71        return true; 
    2872} 
     73 
     74} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h

    r1112 r1121  
    7070 
    7171  virtual bool 
    72   ExportOspTree(const OspTree &tree) = 0; 
     72  ExportOspTree(const OspTree &tree, const int maxPvs);// = 0; 
    7373 
    7474//    virtual bool 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r1112 r1121  
    163163}; 
    164164   
     165class SplitCandidate; 
    165166   
    166167/** Implementation of the kd-tree leaf node */ 
     
    209210  /// pvs of view cells seeing this node. 
    210211  // ViewCellPvs mViewCellPvs; 
     212  SplitCandidate *mSplitCandidate; 
    211213 
    212214  /** pointer to view cell. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1027 r1121  
    77#include "Mesh.h" 
    88#include "Intersectable.h" 
    9 #include "MeshKdTree.h" 
     9#include "KdTree.h" 
    1010#include "Triangle3.h" 
    1111#include "common.h" 
     
    2929 
    3030 
    31 typedef priority_queue<ViewCell *, vector<ViewCell *>, myless<vector<ViewCell *>::value_type> > TraversalQueue; 
     31typedef priority_queue<ViewCell *, vector<ViewCell *>,  
     32                                           myless<vector<ViewCell *>::value_type> > TraversalQueue; 
    3233 
    3334int ViewCell::sMailId = 21843194198; 
     
    257258        return result; 
    258259} 
    259  
    260260 
    261261 
     
    16751675 
    16761676 
    1677 int ViewCellsTree::GetPvsSize(ViewCell *vc) const 
     1677int ViewCellsTree::CountKdPvs(const ViewCellLeaf *vc) const 
     1678{ 
     1679        ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end(); 
     1680 
     1681        int pvsSize = 0; 
     1682 
     1683        Intersectable::NewMail(); 
     1684 
     1685        for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     1686        { 
     1687                Intersectable *obj = (*oit).first; 
     1688 
     1689                set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 
     1690 
     1691                for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 
     1692                { 
     1693                        KdLeaf *leaf = *kit; 
     1694 
     1695                        pvsSize += ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size()); 
     1696 
     1697                        //-- handle objects of several kd leaves separately 
     1698                        ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
     1699 
     1700                        for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
     1701                        { 
     1702                                Intersectable *object = *oit; 
     1703 
     1704                                // object not previously in left pvs 
     1705                                if (!object->Mailed()) 
     1706                                { 
     1707                                        object->Mail(); 
     1708                                        ++ pvsSize; 
     1709                                } 
     1710                        }                
     1711                } 
     1712        } 
     1713 
     1714        return pvsSize; 
     1715} 
     1716 
     1717 
     1718int ViewCellsTree::GetPvsSize(ViewCell *vc, const bool countKdPvs) const 
    16781719{ 
    16791720        int pvsSize = 0; 
     
    16911732                        if (vc->IsLeaf()) 
    16921733                        { 
    1693                                 pvsSize = vc->GetPvs().GetSize(); 
     1734                                if (countKdPvs) 
     1735                                        pvsSize = vc->GetPvs().GetSize(); 
     1736                                else 
     1737                                        pvsSize = CountKdPvs(dynamic_cast<ViewCellLeaf *>(vc)); 
    16941738                                break; 
    16951739                        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r1010 r1121  
    350350}; 
    351351 
    352 /** 
    353         Leaf of the view cell hierarchy corresponding to a leaf in a spatial hierarchy. 
     352/** Leaf of the view cell hierarchy corresponding  
     353        to a leaf in a spatial hierarchy. 
    354354*/ 
    355355template<typename T> 
     
    420420        void UpdateViewCellsStats(ViewCell *vc, ViewCellsStatistics &vcStat); 
    421421 
    422  
    423422        /** Get costs resulting from each merge step.  
    424423        */ 
    425424        void GetCostFunction(vector<float> &costFunction); 
    426  
    427425   
    428426        /** Returns optimal set of view cells for a given number of view cells. 
     
    442440        /** Returns pvs size of view cell. 
    443441        */ 
    444         int GetPvsSize(ViewCell *vc) const; 
     442        //int GetPvsSize(ViewCell *vc) const; 
     443        int GetPvsSize(ViewCell *vc, const bool countKdPvs = false) const; 
    445444 
    446445        /** Returns actual number of object in this pvs and the children. 
     
    502501        */ 
    503502        void ResetPvs(); 
     503 
     504        /** Counts pvs of the view cell taking the kd cells into account. 
     505        */ 
     506        int CountKdPvs(const ViewCellLeaf *vc) const; 
    504507 
    505508protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h

    r1084 r1121  
    5151        */ 
    5252        float GetArea() const; 
     53 
    5354        /** Returns volume of this node geometry. 
    5455        */ 
     
    215216        } 
    216217 
    217         int Nodes() const {return nodes;} 
     218        int Nodes() const { return nodes; } 
    218219        int Interior() const { return nodes / 2; } 
    219220        int Leaves() const { return (nodes / 2) + 1; } 
    220221         
    221222        // TODO: computation wrong 
    222         double AvgDepth() const { return accumDepth / (double)Leaves();};  
    223         double AvgRays() const { return accumRays / (double)Leaves();};  
     223        double AvgDepth() const { return accumDepth / (double)Leaves(); } 
     224        double AvgRays() const { return accumRays / (double)Leaves(); } 
    224225 
    225226        void Reset()  
     
    304305        bool IsSibling(BspNode *n) const; 
    305306 
    306         /** returns depth of the node. 
     307        /** Returns depth of the node. 
    307308        */ 
    308309        int GetDepth() const; 
    309310 
    310         /** returns true if the whole subtree is valid 
     311        /** Returns true if the whole subtree is valid 
    311312        */ 
    312313        bool TreeValid() const; 
    313314 
     315        /** Sets the valid flag for the subtree with this node as root. 
     316        */ 
    314317        void SetTreeValid(const bool v); 
    315318 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1112 r1121  
    9999        Environment::GetSingleton()->GetBoolValue("ViewCells.exportBboxesForPvs", mExportBboxesForPvs); 
    100100        Environment::GetSingleton()->GetBoolValue("ViewCells.exportPvs", mExportPvs); 
     101        Environment::GetSingleton()->GetBoolValue("ViewCells.Evaluation.countKdPvs", mCountKdPvs); 
    101102 
    102103        char buf[100]; 
     
    212213        Debug << "export bounding boxes: " << mExportBboxesForPvs << endl; 
    213214        Debug << "export pvs for view cells: " << mExportPvs << endl; 
    214  
     215        Debug << "count kd pvs: " << mCountKdPvs << endl; 
     216         
    215217        Debug << endl; 
    216218} 
     
    783785        sort(viewCells.begin(), viewCells.end(), ViewCell::SmallerPvs); 
    784786 
    785         maxPvs = mViewCellsTree->GetPvsSize(viewCells.back()); 
     787        maxPvs = mViewCellsTree->GetPvsSize(viewCells.back(), mCountKdPvs); 
    786788        minVal = 0; 
    787789 
     
    791793        maxVal = max(histoMaxVal, maxPvs); 
    792794                 
    793         Debug << "histogram minpvssize: " << minVal << " maxpvssize: " << maxVal << " real maxpvs " << maxPvs << endl; 
     795        Debug << "histogram minpvssize: " << minVal << " maxpvssize: " << maxVal  
     796                << " real maxpvs " << maxPvs << endl; 
    794797 
    795798        int histoIntervals; 
     
    826829 
    827830                while ((i < (int)viewCells.size()) &&  
    828                            (mViewCellsTree->GetPvsSize(viewCells[i]) < currentPvs)) 
     831                           (mViewCellsTree->GetPvsSize(viewCells[i], mCountKdPvs) < currentPvs)) 
    829832                { 
    830833                        volDif += viewCells[i]->GetVolume(); 
     
    837840                 
    838841                if (0 && (i < (int)viewCells.size())) 
    839                         Debug << "new pvs size increase: " << mViewCellsTree->GetPvsSize(viewCells[i]) << " " << currentPvs << endl; 
     842                        Debug << "new pvs size increase: " << mViewCellsTree->GetPvsSize(viewCells[i], mCountKdPvs)  
     843                        << " " << currentPvs << endl; 
    840844         
    841845                const float volRatioDif = volDif / totalVol; 
     
    16851689void ViewCellsManager::GetPvsStatistics(PvsStatistics &stat) 
    16861690{ 
    1687   // update pvs of view cells tree if necessary 
    1688   UpdatePvs(); 
    1689    
    1690   ViewCellContainer::const_iterator it = mViewCells.begin(); 
    1691    
    1692   stat.viewcells = 0; 
    1693   stat.minPvs = 100000000; 
    1694   stat.maxPvs = 0; 
    1695   stat.avgPvs = 0.0f; 
    1696    
    1697   for (; it != mViewCells.end(); ++ it)  
    1698         { 
    1699           ViewCell *viewcell = *it; 
    1700            
    1701           const int pvsSize = mViewCellsTree->GetPvsSize(viewcell); 
    1702            
    1703           if (pvsSize < stat.minPvs) 
    1704                 stat.minPvs = pvsSize; 
    1705           if (pvsSize > stat.maxPvs) 
    1706                 stat.maxPvs = pvsSize; 
    1707           stat.avgPvs += pvsSize; 
    1708            
    1709           ++ stat.viewcells; 
    1710         } 
    1711    
    1712   if (stat.viewcells) 
    1713         stat.avgPvs/=stat.viewcells; 
     1691        // update pvs of view cells tree if necessary 
     1692        UpdatePvs(); 
     1693 
     1694        ViewCellContainer::const_iterator it = mViewCells.begin(); 
     1695 
     1696        stat.viewcells = 0; 
     1697        stat.minPvs = 100000000; 
     1698        stat.maxPvs = 0; 
     1699        stat.avgPvs = 0.0f; 
     1700 
     1701        for (; it != mViewCells.end(); ++ it)  
     1702        { 
     1703                ViewCell *viewcell = *it; 
     1704 
     1705                const int pvsSize = mViewCellsTree->GetPvsSize(viewcell, mCountKdPvs); 
     1706 
     1707                if (pvsSize < stat.minPvs) 
     1708                        stat.minPvs = pvsSize; 
     1709                if (pvsSize > stat.maxPvs) 
     1710                        stat.maxPvs = pvsSize; 
     1711 
     1712                stat.avgPvs += pvsSize; 
     1713 
     1714                ++ stat.viewcells; 
     1715        } 
     1716 
     1717        if (stat.viewcells) 
     1718                stat.avgPvs/=stat.viewcells; 
    17141719} 
    17151720 
     
    19491954float ViewCellsManager::GetRendercost(ViewCell *viewCell) const 
    19501955{ 
    1951         return mViewCellsTree->GetPvsSize(viewCell); 
     1956        return mViewCellsTree->GetPvsSize(viewCell, mCountKdPvs); 
    19521957} 
    19531958 
     
    23992404                { 
    24002405                        if (mCurrentViewCellsStats.maxPvs) 
    2401                                 importance = (float)mViewCellsTree->GetPvsSize(vc) / (float)mCurrentViewCellsStats.maxPvs; 
     2406                        { 
     2407                                importance =  
     2408                                        (float)mViewCellsTree->GetPvsSize(vc, mCountKdPvs) /  
     2409                                        (float)mCurrentViewCellsStats.maxPvs; 
     2410                        } 
    24022411                } 
    24032412                break; 
     
    26332642        Debug << "\nView cells after merge:\n" << mCurrentViewCellsStats << endl; 
    26342643 
    2635  
    2636         int savedColorCode = mColorCode; 
     2644        // save color code 
     2645        const int savedColorCode = mColorCode; 
    26372646         
    26382647        //BspLeaf::NewMail(); 
     
    26852694                cout << "finished" << endl; 
    26862695        } 
    2687  
    2688          
    2689         // only for testing 
     2696         
     2697        // only for debugging: test valitidy 
    26902698        TestSubdivision(); 
    26912699 
     
    43794387                Exporter *exporter = Exporter::GetExporter(s); 
    43804388                 
    4381                 Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 
     4389                Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc, mCountKdPvs) << endl; 
    43824390 
    43834391                //-- export the sample rays 
     
    53115319 
    53125320                        exporter->SetWireframe(); 
    5313                         exporter->ExportOspTree(*mOspTree); 
     5321         
     5322                        const int savedColorCode = mColorCode; 
     5323                        const int maxPvs = 200;//mOspTree.GetStatistics().maxPvs; 
     5324 
     5325                        exporter->ExportOspTree(*mOspTree, mColorCode == 0 ? 0 : maxPvs); 
    53145326 
    53155327                        delete exporter; 
     
    53685380                Exporter *exporter = Exporter::GetExporter(s); 
    53695381                 
    5370                 Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 
     5382                Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc, mCountKdPvs) << endl; 
    53715383 
    53725384                //-- export the sample rays 
     
    54405452 
    54415453                //-- export view cell geometry 
     5454 
    54425455                exporter->SetWireframe(); 
    54435456 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1074 r1121  
    559559                                                                           const ViewCellContainer &viewCells); 
    560560   
    561  
    562561        /** Creates clip plane for visualization. 
    563562        */ 
     
    656655        /// if pvs should be exported with view cells 
    657656        bool mExportPvs; 
     657 
     658        bool mCountKdPvs; 
    658659}; 
    659660 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp

    r1108 r1121  
    222222        tStack.push(pair<BspNode *, BspNodeGeometry *>(tree.GetRoot(), geom)); 
    223223 
     224        // color code pvs 
    224225        if (maxPvs) 
     226        { 
    225227                mUseForcedMaterial = true; 
    226          
     228        } 
     229 
    227230        while (!tStack.empty())  
    228231        { 
     
    647650         delete mesh; 
    648651         return true; 
    649 } 
    650  
    651  
    652 bool VrmlExporter::ExportOspTree(const OspTree &ospTree) 
    653 { 
    654         vector<KdLeaf *> leaves; 
    655         ospTree.CollectLeaves(leaves); 
    656  
    657         mUseForcedMaterial = true; 
    658  
    659         vector<KdLeaf *>::const_iterator it, it_end = leaves.end(); 
    660  
    661         Material white;  
    662         white.mDiffuseColor.r = 1; 
    663         white.mDiffuseColor.g = 1; 
    664         white.mDiffuseColor.b = 1; 
    665  
    666         for (it = leaves.begin(); it != it_end; ++ it) 
    667         { 
    668                 SetWireframe(); 
    669                 SetForcedMaterial(white); 
    670                 ExportBox(ospTree.GetBBox(*it)); 
    671  
    672                 SetFilled(); 
    673                 SetForcedMaterial(RandomMaterial()); 
    674                 ExportGeometry((*it)->mObjects);         
    675         } 
    676  
    677         return true; 
    678652} 
    679653 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.h

    r1112 r1121  
    4747  ExportKdTree(const KdTree &tree); 
    4848 
    49   bool 
    50   ExportOspTree(const OspTree &tree); 
     49  //bool ExportOspTree(const OspTree &tree); 
    5150 
    5251  bool 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp

    r1111 r1121  
    2222 
    2323#define USE_FIXEDPOINT_T 0 
    24 #define COUNT_OBJECTS 1 
     24#define COUNT_OBJECTS 0 
    2525 
    2626//-- static members 
     
    5050void VspTreeStatistics::Print(ostream &app) const 
    5151{ 
    52         app << "===== VspTree statistics ===============\n"; 
     52        app << "=========== VspTree statistics ===============\n"; 
    5353 
    5454        app << setprecision(4); 
     
    9999        //app << "#N_PVS: " << pvs << endl; 
    100100 
    101         app << "===== END OF VspTree statistics ==========\n"; 
     101        app << "========== END OF VspTree statistics ==========\n"; 
    102102} 
    103103 
     
    352352        //-- partition criteria 
    353353        Environment::GetSingleton()->GetFloatValue("VspTree.Construction.epsilon", mEpsilon); 
     354        Environment::GetSingleton()->GetFloatValue("VspTree.Construction.renderCostDecreaseWeight", mRenderCostDecreaseWeight); 
    354355 
    355356        // if only the driving axis is used for axis aligned split 
     
    392393        Debug << "use cost heuristics: " << mUseCostHeuristics << endl; 
    393394        Debug << "subdivision stats log: " << subdivisionStatsLog << endl; 
    394          
     395        Debug << "render cost decrease weight: " << mRenderCostDecreaseWeight << endl; 
     396 
    395397        Debug << "circulating axis: " << mCirculatingAxis << endl; 
    396398        Debug << "minband: " << mMinBand << endl; 
     
    598600                tBackData.mMaxCostMisses = maxCostMisses; 
    599601                         
    600                  
     602         
    601603                if (1) 
    602604                { 
     
    620622                } 
    621623 
    622          
     624 
    623625                //-- evaluate new split candidates for global greedy cost heuristics 
    624626                VspSplitCandidate *frontCandidate = new VspSplitCandidate(tFrontData); 
     
    630632                tQueue.Push(frontCandidate); 
    631633                tQueue.Push(backCandidate); 
    632  
     634                 
     635                // delete old view cell 
     636                delete tData.mNode->GetViewCell(); 
    633637                // delete old leaf node 
    634638                DEL_PTR(tData.mNode); 
     
    747751                parent->ReplaceChildLink(leaf, interior); 
    748752                interior->SetParent(parent); 
     753 
     754                // remove "parent" view cell from pvs of all objects (traverse trough rays) 
     755                RemoveParentViewCellReferences(tData.mNode->GetViewCell()); 
    749756        } 
    750757        else // new root 
     
    770777        CreateViewCell(backData); 
    771778 
    772         // TODO:  
     779         
    773780        // create front and back view cell 
    774         // remove "parent" view cell from pvs of all objects (traverse trough rays) 
    775781        // add front and back view cell to "Potentially Visbilie View Cells"  
    776782        // of the objects in front and back pvs 
    777         RemoveParentViewCellReferences(tData.mNode->GetViewCell()); 
    778783        AddViewCellReferences(frontLeaf->GetViewCell()); 
    779784        AddViewCellReferences(backLeaf->GetViewCell()); 
    780  
    781785 
    782786        interior->mTimeStamp = mTimeStamp ++; 
     
    11441148void VspTree::AddContriToPvs(KdLeaf *leaf, int &pvs) const 
    11451149{ 
    1146         if (!leaf->Mailed()) 
    1147         { 
    1148                 leaf->Mail(); 
    1149  
    1150                 // add objects without those which are part of several kd leaves 
    1151                 pvs += ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size()); 
    1152  
    1153                 //-- handle objects of several kd leaves separately 
    1154                 ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
    1155  
    1156                 for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
    1157                 { 
    1158                         Intersectable *object = *oit; 
    1159  
    1160                         // object not previously in left pvs 
    1161                         if (!object->Mailed()) 
    1162                         { 
    1163                                 object->Mail(); 
    1164                                 ++ pvs; 
    1165                         } 
     1150        if (leaf->Mailed()) 
     1151                return; 
     1152         
     1153        leaf->Mail(); 
     1154 
     1155        // add objects without those which are part of several kd leaves 
     1156        pvs += ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size()); 
     1157 
     1158        //-- handle objects of several kd leaves separately 
     1159        ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
     1160 
     1161        for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
     1162        { 
     1163                Intersectable *object = *oit; 
     1164 
     1165                // object not previously in left pvs 
     1166                if (!object->Mailed()) 
     1167                { 
     1168                        object->Mail(); 
     1169                        ++ pvs; 
    11661170                } 
    11671171        }                                        
     
    15131517        // take render cost of node into account  
    15141518        // otherwise danger of being stuck in a local minimum!! 
    1515         const float factor = 0.99f; 
     1519        const float factor = mRenderCostDecreaseWeight; 
    15161520 
    15171521        const float normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); 
     
    25542558 
    25552559 
    2556  
    2557  
    25582560int VspTree::ComputeBoxIntersections(const AxisAlignedBox3 &box, 
    25592561                                                                         ViewCellContainer &viewCells) const 
     
    26062608 
    26072609 
     2610 
     2611void VspTree::CollectDirtyCandidates(VspSplitCandidate *sc,  
     2612                                                                         vector<SplitCandidate *> &dirtyList) 
     2613{ 
     2614        VspLeaf *node = sc->mParentData.mNode; 
     2615         
     2616    ViewCellLeaf *vc = node->GetViewCell(); 
     2617                 
     2618        ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end(); 
     2619 
     2620        KdLeaf::NewMail(); 
     2621 
     2622        for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     2623        { 
     2624                Intersectable *obj = (*oit).first; 
     2625 
     2626                set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 
     2627 
     2628                for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 
     2629                { 
     2630                        KdLeaf *leaf = *kit; 
     2631 
     2632                        if (!leaf->Mailed()) 
     2633                        { 
     2634                                leaf->Mail(); 
     2635                                dirtyList.push_back(leaf->mSplitCandidate); 
     2636                        } 
     2637                } 
     2638        } 
     2639} 
     2640 
     2641 
    26082642/*****************************************************************/ 
    26092643/*                class OspTree implementation                   */ 
     
    26552689 
    26562690        Environment::GetSingleton()->GetFloatValue("OspTree.Construction.splitBorder", mSplitBorder); 
    2657         //mSplitBorder = 0.1f; 
    2658  
    2659  
     2691        Environment::GetSingleton()->GetFloatValue("OspTree.Construction.renderCostDecreaseWeight", mRenderCostDecreaseWeight); 
     2692         
    26602693        //-- debug output 
    26612694 
     
    26792712         
    26802713        Debug << "split borders: " << mSplitBorder << endl; 
     2714        Debug << "render cost decrease weight: " << mRenderCostDecreaseWeight << endl; 
    26812715 
    26822716 
     
    27612795                const AxisAlignedBox3 box = (*mi)->GetBox(); 
    27622796                 
    2763                 if (box.Max(axis) > position)  
     2797                if (box.Max(axis) > position + mEpsilon)  
    27642798                        ++ objectsFront; 
    27652799     
    2766                 if (box.Min(axis) < position) 
     2800                if (box.Min(axis) < position - mEpsilon) 
    27672801                        ++ objectsBack; 
    27682802        } 
     
    28432877                // delete old leaf node 
    28442878                DEL_PTR(tData.mNode); 
    2845                 DEL_PTR(tData.mNode->mViewCell); 
    28462879        } 
    28472880 
     
    28922925{ 
    28932926        // matt: TODO 
    2894         Debug << "here888 " << mTermMaxLeaves << " " << mOspStats.Leaves() << endl; 
    28952927        return ( 
    28962928                (mOspStats.Leaves() >= mTermMaxLeaves) 
     
    29522984                                                                           int &objectsBack) 
    29532985{ 
    2954          
     2986        // sort so we can use a sweep 
    29552987        SortSplitCandidates(node, axis); 
    29562988   
     
    29843016 
    29853017        float sum = (float)pvsSize * sizeBox; 
     3018float dummy1 = 0; 
     3019float dummy2 = 0; 
    29863020 
    29873021        vector<SortableEntry>::const_iterator ci, ci_end = mSplitCandidates->end(); 
    2988  
     3022cout << "***********" << endl; 
    29893023        //-- traverse through visibility events 
    29903024        for (ci = mSplitCandidates->begin(); ci != ci_end; ++ ci) 
    29913025        { 
     3026                int pvslold = pvsl; 
    29923027                EvalPvsIncr(*ci, pvsl, pvsr); 
     3028 
     3029                cout << "incr: " << ci->mObject->mViewCellPvs.GetSize() << " obj id "  
     3030                         << ci->mObject->GetId() << endl; 
    29933031 
    29943032                // Note: sufficient to compare size of bounding boxes of front and back side? 
     
    29973035                        sum = pvsl * ((*ci).value - minBox) + pvsr * (maxBox - (*ci).value); 
    29983036 
    2999                         //Debug  << "pos=" << (*ci).value << "\t pvs=(" <<  pvsl << "," << pvsr << ")" << "\t cost= " << sum << endl; 
     3037                        cout << "pos=" << (*ci).value << "\t pvs=(" <<  pvsl << ","  
     3038                                 << pvsr << ")" << "\t cost= " << sum << endl; 
    30003039 
    30013040                        if (sum < minSum) 
     
    30123051        } 
    30133052         
    3014          
    3015         // -- compute cost 
     3053        //-- compute cost 
    30163054 
    30173055        const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 
     
    30353073         
    30363074        //if (axis != 1) 
    3037         Debug << "axis=" << axis << " costRatio=" << ratio << " pos=" << position << " t=" << (position - minBox) / (maxBox - minBox) 
    3038               <<"\t pb=(" << pvsBack << ")\t pf=(" << pvsFront << ")" << endl; 
     3075        Debug << "axis=" << axis << " costRatio=" << ratio << " pos="  
     3076                  << position << " t=" << (position - minBox) / (maxBox - minBox) 
     3077              << "\t pb=(" << pvsBack << ")\t pf=(" << pvsFront << ")" << endl; 
    30393078 
    30403079        return ratio; 
    30413080} 
    30423081 
     3082 
    30433083void OspTree::SortSplitCandidates(KdLeaf *node, const int axis) 
    30443084{ 
    30453085        mSplitCandidates->clear(); 
    30463086 
    3047         int requestedSize = 2*(int)node->mObjects.size(); 
     3087        int requestedSize = 2 * (int)node->mObjects.size(); 
    30483088         
    30493089        // creates a sorted split candidates array 
     
    30743114        stable_sort(mSplitCandidates->begin(), mSplitCandidates->end()); 
    30753115} 
    3076  
    30773116 
    30783117 
     
    30853124        return object->mViewCellPvs.GetSize(); 
    30863125#endif 
     3126} 
     3127 
     3128 
     3129const OspTreeStatistics &OspTree::GetStatistics() const 
     3130{ 
     3131        return mOspStats; 
    30873132} 
    30883133 
     
    31243169                        break; 
    31253170        } 
     3171 
     3172        cout << "pvs left: " << pvsLeft << " pvs right " << pvsRight << endl; 
    31263173} 
    31273174 
     
    32413288float OspTree::EvalViewCellPvsIncr(Intersectable *object) const 
    32423289{ 
    3243         // TODO          
     3290#if COUNT_OBJECTS        
    32443291        return 1; 
     3292#else 
     3293        return (float)object->mViewCellPvs.GetSize(); 
     3294#endif 
    32453295} 
    32463296 
     
    32763326                const float pvsIncr = EvalViewCellPvsIncr(obj); 
    32773327                totalPvs += pvsIncr; 
     3328                cout << "totalpvs " << totalPvs << " incr " << pvsIncr << endl; 
    32783329 
    32793330                if (box.Max(candidatePlane.mAxis) > candidatePlane.mPosition) 
     
    33103361        const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 
    33113362 
    3312         Debug << "old: " << oldRenderCost << " new: " << newRenderCost << " decrease: " << oldRenderCost - newRenderCost << endl; 
     3363        Debug << "old: " << oldRenderCost << " new: " << newRenderCost << " decrease: "  
     3364                << oldRenderCost - newRenderCost << endl; 
    33133365        const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBoundingBox.GetVolume(); 
    33143366         
    33153367        // take render cost of node into account  
    33163368        // otherwise danger of being stuck in a local minimum!! 
    3317         const float factor = 0.99f; 
     3369        const float factor = mRenderCostDecreaseWeight; 
    33183370 
    33193371        const float normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); 
    3320  
    33213372        return factor * renderCostDecrease + (1.0f - factor) * normalizedOldRenderCost; 
    33223373} 
     
    34293480 
    34303481 
     3482void OspTree::CollectViewCells(KdLeaf *leaf, ViewCellContainer &viewCells) 
     3483{ 
     3484        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     3485 
     3486        ViewCell::NewMail(); 
     3487 
     3488        // loop through all object and collect view cell pvs of this node 
     3489        for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     3490        { 
     3491                Intersectable *obj = *oit; 
     3492 
     3493                ViewCellPvsMap::const_iterator vit, vit_end = obj->mViewCellPvs.mEntries.end(); 
     3494 
     3495                for (vit = obj->mViewCellPvs.mEntries.begin(); vit != vit_end; ++ vit) 
     3496                { 
     3497            ViewCell *vc = (*vit).first; 
     3498 
     3499                        if (!vc->Mailed()) 
     3500                        { 
     3501                                vc->Mail(); 
     3502                                viewCells.push_back(vc); 
     3503                        } 
     3504                } 
     3505        } 
     3506 
     3507} 
     3508 
     3509 
     3510void OspTree::CollectDirtyCandidates(OspSplitCandidate *sc,  
     3511                                                                         vector<SplitCandidate *> &dirtyList) 
     3512{ 
     3513        KdLeaf *node = sc->mParentData.mNode; 
     3514 
     3515        ObjectContainer::const_iterator oit, oit_end = node->mObjects.end(); 
     3516 
     3517        ViewCellContainer viewCells; 
     3518 
     3519        CollectViewCells(node, viewCells); 
     3520 
     3521        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     3522 
     3523        // through split candidates corresponding to view cell pvs of this 
     3524        // node into dirty list 
     3525        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     3526        { 
     3527                VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 
     3528 
     3529                VspLeaf *leaf = vc->mLeaf; 
     3530                dirtyList.push_back(leaf->GetSplitCandidate()); 
     3531        } 
     3532} 
     3533 
     3534 
     3535int OspTree::ComputePvsSize(const ObjectContainer &objects) const 
     3536{ 
     3537        int pvsSize = 0; 
     3538 
     3539        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     3540 
     3541        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     3542        { 
     3543                pvsSize += (*oit)->mViewCellPvs.GetSize(); 
     3544        } 
     3545 
     3546        return pvsSize; 
     3547} 
     3548 
     3549 
    34313550/********************************************************************/ 
    34323551/*               class HierarchyManager implementation              */ 
     
    34453564        SplitCandidate *splitCandidate = mTQueue.Top(); 
    34463565 
    3447         Debug << "next candidate: " << splitCandidate->Type() 
     3566        cout << "next candidate: " << splitCandidate->Type() 
    34483567                << ", priority: " << splitCandidate->GetPriority() << endl; 
    34493568 
     
    34543573 
    34553574 
    3456 void HierarchyManager::PrepareConstruction(const VssRayContainer &sampleRays, 
    3457                                                                                    const ObjectContainer &objects, 
    3458                                                                                    AxisAlignedBox3 *forcedViewSpace, 
    3459                                                                                    RayInfoContainer &rays) 
    3460 { 
    3461         mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 
     3575void HierarchyManager::ProcessRays(const VssRayContainer &sampleRays, 
     3576                                                                   RayInfoContainer &rays, 
     3577                                                                   ObjectContainer &sampledObjects) 
     3578{ 
     3579        VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
    34623580 
    34633581        long startTime = GetTime(); 
     
    34673585        Intersectable::NewMail(); 
    34683586 
    3469         VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
    3470  
    3471         //-- store rays 
     3587        //-- store rays and objects 
    34723588        for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
    34733589        { 
    34743590                VssRay *ray = *rit; 
    3475  
    34763591                float minT, maxT; 
    3477  
    34783592                static Ray hray; 
     3593 
    34793594                hray.Init(*ray); 
    34803595                 
     
    34893604                        rays.push_back(RayInfo(ray, minT / len, maxT / len)); 
    34903605                } 
     3606 
     3607                // store objects 
     3608                if (ray->mTerminationObject && !ray->mTerminationObject->Mailed()) 
     3609                { 
     3610                        ray->mTerminationObject->Mail(); 
     3611                        sampledObjects.push_back(ray->mTerminationObject); 
     3612                } 
     3613 
     3614                if (ray->mOriginObject && !ray->mOriginObject->Mailed()) 
     3615                { 
     3616                        ray->mOriginObject->Mail(); 
     3617                        sampledObjects.push_back(ray->mOriginObject); 
     3618                } 
    34913619        } 
    34923620 
    34933621        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    3494  
    3495  
    3496         int pvsSize = mVspTree.ComputePvsSize(rays); 
    3497  
     3622} 
     3623 
     3624 
     3625void HierarchyManager::PrepareVsp(const VssRayContainer &sampleRays, 
     3626                                                                  AxisAlignedBox3 *forcedViewSpace, 
     3627                                                                  RayInfoContainer &rays) 
     3628{ 
     3629        // prepare bounding box 
     3630        mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 
     3631 
     3632        // get clipped rays 
     3633        ObjectContainer sampledObjects; 
     3634        ProcessRays(sampleRays, rays, sampledObjects); 
     3635 
     3636        //const int pvsSize = mVspTree.ComputePvsSize(rays); 
     3637        const int pvsSize = (int)sampledObjects.size(); 
     3638 
     3639        cout <<  "here450 pvs size: " << pvsSize << endl; 
    34983640        // -- prepare view space partition 
    34993641 
     
    35073649                                                                        0, 
    35083650                                                                        &rays, 
    3509                                                                         //(int)objects.size(), 
    35103651                                                                        pvsSize,         
    35113652                                                                        prop, 
     
    35133654 
    35143655 
     3656        // create first view cell 
     3657        mVspTree.CreateViewCell(vData); 
     3658                 
     3659        // add first view cell to all the objects view cell pvs 
     3660        ObjectPvsMap::const_iterator oit,  
     3661                oit_end = leaf->GetViewCell()->GetPvs().mEntries.end(); 
     3662 
     3663        cout << "here23 " << leaf->GetViewCell()->GetPvs().mEntries.size(); 
     3664 
     3665        for (oit = leaf->GetViewCell()->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     3666        { 
     3667                Intersectable *obj = (*oit).first; 
     3668                cout << "obj: " << obj->GetId() << endl; 
     3669                obj->mViewCellPvs.AddSample(leaf->GetViewCell(), 1); 
     3670        } 
     3671 
    35153672        // compute first split candidate 
    35163673        VspTree::VspSplitCandidate *splitCandidate = new VspTree::VspSplitCandidate(vData); 
     
    35183675 
    35193676        mTQueue.Push(splitCandidate); 
    3520  
    3521  
    3522         //-- object space partition 
    3523  
     3677} 
     3678 
     3679 
     3680void HierarchyManager::PrepareOsp(const ObjectContainer &objects,                                                                                  
     3681                                                                  AxisAlignedBox3 *forcedViewSpace) 
     3682{ 
    35243683        mOspTree.PrepareConstruction(objects, forcedViewSpace); 
    35253684 
     
    35303689        mOspTree.mRoot = kdleaf; 
    35313690         
    3532  
     3691        // TODO matt: this is something different than pvs size. 
     3692        const int pvsSize = mOspTree.ComputePvsSize(objects); 
     3693        const float prop = mOspTree.mBoundingBox.GetVolume(); 
     3694 
     3695        cout <<  "here40 pvs size: " << pvsSize << endl; 
    35333696        // first osp traversal data 
    35343697        OspTree::OspTraversalData oData(kdleaf, 
     
    35423705 
    35433706        // compute first split candidate 
    3544         OspTree::OspSplitCandidate *oSplitCandidate = new OspTree::OspSplitCandidate(oData); 
     3707        OspTree::OspSplitCandidate *oSplitCandidate =  
     3708                new OspTree::OspSplitCandidate(oData); 
    35453709    mOspTree.EvalSplitCandidate(*oSplitCandidate); 
    35463710 
    3547         mTQueue.Push(splitCandidate); 
     3711        mTQueue.Push(oSplitCandidate); 
     3712} 
     3713 
     3714 
     3715void HierarchyManager::PrepareConstruction(const VssRayContainer &sampleRays, 
     3716                                                                                   const ObjectContainer &objects, 
     3717                                                                                   AxisAlignedBox3 *forcedViewSpace, 
     3718                                                                                   RayInfoContainer &rays) 
     3719{ 
     3720        PrepareVsp(sampleRays, forcedViewSpace, rays); 
     3721        PrepareOsp(objects, forcedViewSpace); 
    35483722} 
    35493723 
     
    35613735{ 
    35623736        RayInfoContainer *rays = new RayInfoContainer(); 
    3563  
    3564         mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 
     3737        PrepareVsp(sampleRays, forcedViewSpace, *rays); 
    35653738 
    35663739        long startTime = GetTime(); 
    3567  
    3568         cout << "storing rays ... "; 
    3569  
    3570         Intersectable::NewMail(); 
    3571  
    3572         VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
    3573  
    3574         //-- store rays 
    3575         for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
    3576         { 
    3577                 VssRay *ray = *rit; 
    3578  
    3579                 float minT, maxT; 
    3580  
    3581                 static Ray hray; 
    3582                 hray.Init(*ray); 
    3583                  
    3584                 // TODO: not very efficient to implictly cast between rays types 
    3585                 if (mVspTree.GetBoundingBox().GetRaySegment(hray, minT, maxT)) 
    3586                 { 
    3587                         float len = ray->Length(); 
    3588  
    3589                         if (!len) 
    3590                                 len = Limits::Small; 
    3591  
    3592                         rays->push_back(RayInfo(ray, minT / len, maxT / len)); 
    3593                 } 
    3594         } 
    3595  
    3596         cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    3597  
    3598         const int pvsSize = mVspTree.ComputePvsSize(*rays); 
    3599  
    3600  
    3601         // -- prepare view space partition 
    3602  
    3603         // add first candidate for view space partition 
    3604         VspLeaf *vspleaf = new VspLeaf(); 
    3605  
    3606         mVspTree.mRoot = vspleaf; 
    3607         const float prop = mVspTree.mBoundingBox.GetVolume(); 
    3608  
    3609         // first vsp traversal data 
    3610         VspTree::VspTraversalData vData(vspleaf, 
    3611                                                                         0, 
    3612                                                                         rays, 
    3613                                                                         pvsSize,         
    3614                                                                         prop, 
    3615                                                                         mVspTree.mBoundingBox); 
    3616  
    3617  
    3618         //-- compute first split candidate 
    3619         VspTree::VspSplitCandidate *splitCandidate = new VspTree::VspSplitCandidate(vData); 
    3620     mVspTree.EvalSplitCandidate(*splitCandidate); 
    3621  
    3622         mTQueue.Push(splitCandidate); 
    3623  
     3740        cout << "starting vsp contruction ... " << endl; 
    36243741        int i = 0; 
    36253742 
     
    36313748                        GlobalTerminationCriteriaMet(splitCandidate); 
    36323749 
    3633                 //cout << "vsp nodes: " << i ++ << endl; 
     3750                cout << "vsp nodes: " << i ++ << endl; 
    36343751 
    36353752                // cost ratio of cost decrease / totalCost 
    36363753                const float costRatio = splitCandidate->GetPriority() / mTotalCost; 
    3637                 //Debug << "cost ratio: " << costRatio << endl; 
     3754                //cout << "cost ratio: " << costRatio << endl; 
    36383755 
    36393756                if (costRatio < mTermMinGlobalCostRatio) 
     
    36463763                        dynamic_cast<VspTree::VspSplitCandidate *>(splitCandidate); 
    36473764 
     3765         
    36483766                VspNode *r = mVspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 
    3649          
     3767 
    36503768                DEL_PTR(splitCandidate); 
    36513769        } 
     
    36543772        mVspTree.mVspStats.Stop(); 
    36553773         
    3656         Debug << "object space" << endl; 
     3774        startTime = GetTime(); 
     3775        cout << "starting osp contruction ... " << endl; 
    36573776 
    36583777        //-- object space partition 
    3659  
    3660         mOspTree.PrepareConstruction(objects, forcedViewSpace); 
    3661  
    3662         // add first candidate for view space partition 
    3663         KdLeaf *leaf = new KdLeaf(NULL, 0); 
    3664         leaf->mObjects = objects; 
    3665  
    3666         mOspTree.mRoot = leaf; 
    3667          
    3668  
    3669         //-- first osp traversal data 
    3670         OspTree::OspTraversalData oData(leaf, 
    3671                                                                         0, 
    3672                                                                         pvsSize, 
    3673                                                                         prop, 
    3674                                                                         mOspTree.mBoundingBox); 
    3675  
    3676                  
    3677         mOspTree.ProcessLeafObjects(leaf, NULL); 
    3678  
    3679         // compute first split candidate 
    3680         OspTree::OspSplitCandidate *oSplitCandidate = new OspTree::OspSplitCandidate(oData); 
    3681     mOspTree.EvalSplitCandidate(*oSplitCandidate); 
    3682  
    3683         mTQueue.Push(oSplitCandidate); 
     3778    PrepareOsp(objects, forcedViewSpace); 
    36843779 
    36853780        i = 0; 
     
    37333828        while (!FinishedConstruction()) 
    37343829        { 
    3735                 SplitCandidate *splitCandidate = NextSplitCandidate(); 
    3736              
     3830                mCurrentCandidate = NextSplitCandidate(); 
     3831            
    37373832                const bool globalTerminationCriteriaMet =  
    3738                         GlobalTerminationCriteriaMet(splitCandidate); 
     3833                        GlobalTerminationCriteriaMet(mCurrentCandidate); 
    37393834 
    37403835                cout << "view cells: " << i ++ << endl; 
    37413836 
    37423837                // cost ratio of cost decrease / totalCost 
    3743                 const float costRatio = splitCandidate->GetPriority() / mTotalCost; 
     3838                const float costRatio = mCurrentCandidate->GetPriority() / mTotalCost; 
    37443839                //Debug << "cost ratio: " << costRatio << endl; 
    37453840 
     
    37503845 
    37513846                // we have either a object space or view space split 
    3752                 if (splitCandidate->Type() == SplitCandidate::VIEW_SPACE) 
     3847                if (mCurrentCandidate->Type() == SplitCandidate::VIEW_SPACE) 
    37533848                { 
    37543849                        VspTree::VspSplitCandidate *sc =  
    3755                                 dynamic_cast<VspTree::VspSplitCandidate *>(splitCandidate); 
     3850                                dynamic_cast<VspTree::VspSplitCandidate *>(mCurrentCandidate); 
    37563851 
    37573852                        VspNode *r = mVspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 
     
    37603855                {                        
    37613856                        OspTree::OspSplitCandidate *sc =  
    3762                                 dynamic_cast<OspTree::OspSplitCandidate *>(splitCandidate); 
     3857                                dynamic_cast<OspTree::OspSplitCandidate *>(mCurrentCandidate); 
    37633858 
    37643859                        KdNode *r = mOspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 
    37653860                } 
    37663861 
    3767                 DEL_PTR(splitCandidate); 
     3862                // reevaluate affected candidates 
     3863                RepairQueue(); 
     3864 
     3865                DEL_PTR(mCurrentCandidate); 
    37683866        } 
    37693867 
     
    37803878 
    37813879 
    3782 void HierarchyManager::RepairQueue(const vector<SplitCandidate *> &dirtyList) 
     3880void HierarchyManager::CollectDirtyCandidates(vector<SplitCandidate *> &dirtyList) 
     3881{        
     3882        // we have either a object space or view space split 
     3883        if (mCurrentCandidate->Type() == SplitCandidate::VIEW_SPACE) 
     3884        { 
     3885                VspTree::VspSplitCandidate *sc =  
     3886                        dynamic_cast<VspTree::VspSplitCandidate *>(mCurrentCandidate); 
     3887 
     3888                mVspTree.CollectDirtyCandidates(sc, dirtyList); 
     3889        } 
     3890        else // object space split 
     3891        {                        
     3892                OspTree::OspSplitCandidate *sc =  
     3893                        dynamic_cast<OspTree::OspSplitCandidate *>(mCurrentCandidate); 
     3894 
     3895                mOspTree.CollectDirtyCandidates(sc, dirtyList); 
     3896        } 
     3897} 
     3898 
     3899 
     3900void HierarchyManager::RepairQueue() 
    37833901{ 
    37843902        // TODO 
     
    37993917        // split candidate 
    38003918 
     3919        // collect list of "dirty" candidates 
     3920        vector<SplitCandidate *> dirtyList; 
     3921        CollectDirtyCandidates(dirtyList); 
     3922         
     3923        //-- reevaluate the dirty list 
    38013924        vector<SplitCandidate *>::const_iterator sit, sit_end = dirtyList.end(); 
    38023925 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1110 r1121  
    429429        void SetViewCell(ViewCellLeaf *viewCell); 
    430430 
     431        SplitCandidate *GetSplitCandidate() const  
     432        { return mSplitCandidate; } 
     433 
     434public: 
     435 
    431436        /// Rays piercing this leaf. 
    432437        VssRayContainer mVssRays; 
     
    439444 
    440445protected: 
    441          
     446 
     447        /// pointer to a split plane candidate splitting this leaf 
     448        SplitCandidate *mSplitCandidate; 
     449 
    442450        /// if NULL this does not correspond to feasible viewcell 
    443451        ViewCellLeaf *mViewCell; 
     
    986994        float GetMemUsage() const; 
    987995 
    988         void ProcessViewCellObjects(ViewCell *parent, ViewCell *front, ViewCell *back) const; 
     996        void ProcessViewCellObjects(ViewCell *parent,  
     997                ViewCell *front,  
     998                ViewCell *back) const; 
    989999 
    9901000        void CreateViewCell(VspTraversalData &tData); 
     1001 
     1002        void CollectDirtyCandidates(VspSplitCandidate *sc,  
     1003                vector<SplitCandidate *> &dirtyList); 
    9911004 
    9921005protected: 
     
    10771090        /// number of currenly generated view cells 
    10781091        int mCreatedViewCells; 
     1092 
     1093        /// weight between  render cost decrease and node render cost 
     1094        float mRenderCostDecreaseWeight; 
    10791095}; 
    10801096 
     
    12241240        ~OspTree(); 
    12251241 
    1226         /** Returns BSP Tree statistics. 
    1227         */ 
    1228         const KdTreeStatistics &GetStatistics() const;  
     1242        /** Returns tree statistics. 
     1243        */ 
     1244        const OspTreeStatistics &GetStatistics() const;  
    12291245   
    12301246        /** Returns bounding box of the specified node. 
     
    13101326        int ComputeBoxIntersections(const AxisAlignedBox3 &box,  
    13111327                                                                ViewCellContainer &viewCells) const; 
     1328 
     1329 
     1330        /** Compute "pvs size of this object container 
     1331                @ note bot relly pvs size just weighted sum of object taking their 
     1332                appearances in pvss into account 
     1333        */ 
     1334        int ComputePvsSize(const ObjectContainer &objects) const; 
    13121335 
    13131336 
     
    14701493                                         float &totalPvs) const; 
    14711494         
    1472         /** Computes PVS size induced by the rays. 
    1473         */ 
    1474         int ComputePvsSize(const RayInfoContainer &rays) const; 
    1475  
    14761495        /** Returns true if tree can be terminated. 
    14771496        */ 
     
    15351554                AxisAlignedBox3 *forcedBoundingBox); 
    15361555 
     1556        void CollectDirtyCandidates(OspSplitCandidate *sc, 
     1557                vector<SplitCandidate *> &dirtyList); 
     1558 
     1559        void CollectViewCells(KdLeaf *leaf,  
     1560                ViewCellContainer &viewCells); 
    15371561 
    15381562protected: 
    15391563 
     1564        /// The view cells manager 
    15401565        ViewCellsManager *mViewCellsManager; 
     1566 
     1567        /// candidates for placing split planes during cost heuristics 
    15411568        vector<SortableEntry> *mSplitCandidates; 
    15421569 
     
    15441571        KdNode *mRoot; 
    15451572                 
     1573        /// Statistics for the object space partition 
    15461574        OspTreeStatistics mOspStats; 
    15471575         
     
    15681596 
    15691597        //-- global criteria 
     1598 
    15701599        float mTermMinGlobalCostRatio; 
    15711600        int mTermGlobalCostMissTolerance; 
     
    16091638        /// represents min and max band for sweep 
    16101639        float mSplitBorder; 
     1640 
     1641        /// weight between  render cost decrease and node render cost 
     1642        float mRenderCostDecreaseWeight; 
    16111643}; 
    16121644 
     
    16561688                                        const ObjectContainer &objects, 
    16571689                                        AxisAlignedBox3 *forcedViewSpace); 
     1690 
    16581691public: 
    16591692        VspTree &mVspTree; 
     
    16701703 
    16711704        bool FinishedConstruction(); 
     1705 
    16721706        SplitCandidate *NextSplitCandidate(); 
    16731707 
    1674         void RepairQueue(const vector<SplitCandidate *> &dirtyList); 
     1708        void RepairQueue(); 
     1709 
     1710        void CollectDirtyCandidates(vector<SplitCandidate *> &dirtyList); 
     1711 
     1712        void PrepareVsp(const VssRayContainer &sampleRays, 
     1713                AxisAlignedBox3 *forcedViewSpace, 
     1714                RayInfoContainer &rays); 
     1715 
     1716        void PrepareOsp(const ObjectContainer &objects, AxisAlignedBox3 *forcedViewSpace); 
     1717 
     1718        void ProcessRays(const VssRayContainer &sampleRays, 
     1719                RayInfoContainer &rays, 
     1720                ObjectContainer &sampledObjects); 
     1721 
     1722 
     1723protected: 
    16751724 
    16761725        AxisAlignedBox3 mBoundingBox; 
    16771726 
    16781727        SplitQueue mTQueue; 
     1728 
     1729        SplitCandidate *mCurrentCandidate; 
    16791730 
    16801731        //-- global criteria 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp

    r1112 r1121  
    12921292 
    12931293 
    1294 bool X3dExporter::ExportOspTree(const OspTree &ospTree) 
    1295 { 
    1296         vector<KdLeaf *> leaves; 
    1297         ospTree.CollectLeaves(leaves); 
    1298  
    1299         mUseForcedMaterial = true; 
    1300  
    1301         vector<KdLeaf *>::const_iterator it, it_end = leaves.end(); 
    1302  
    1303         for (it = leaves.begin(); it != it_end; ++ it) 
    1304         { 
    1305                 SetWireframe(); 
    1306                 ExportBox(ospTree.GetBBox(*it)); 
    1307  
    1308                 SetForcedMaterial(RandomMaterial()); 
    1309  
    1310                 ExportGeometry((*it)->mObjects);         
    1311         } 
    1312  
    1313         return true; 
    1314 } 
    1315  
    1316  
    1317 } 
    1318  
     1294} 
     1295 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h

    r1112 r1121  
    6060                                 ); 
    6161 
    62   bool 
    63   ExportOspTree(const OspTree &tree); 
     62  // bool ExportOspTree(const OspTree &tree); 
    6463 
    6564  bool ExportBspTree(const BspTree &tree); 
Note: See TracChangeset for help on using the changeset viewer.