Changeset 1141 for GTP/trunk/Lib/Vis


Ignore:
Timestamp:
07/18/06 19:03:14 (18 years ago)
Author:
mattausch
Message:

added kd pvs support, changed way of counting pvs

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
15 edited

Legend:

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

    r1139 r1141  
    22122212                                        "0.99"); 
    22132213 
    2214         RegisterOption("VspTree.useKdPvs", 
    2215                                         optBool, 
    2216                                         "vsp_pvs_use_kd_pvs=", 
     2214        RegisterOption("VspTree.useKdPvsForHeuristics", 
     2215                                        optBool, 
     2216                                        "vsp_use_kd_pvs_for_heuristics=", 
    22172217                                        "true"); 
    22182218 
     2219        RegisterOption("VspTree.storeKdPvs", 
     2220                                        optBool, 
     2221                                        "vsp_storeKdPvs=", 
     2222                                        "true"); 
    22192223         
    22202224/***************************************************************************/ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r1112 r1141  
    17051705  ViewCellContainer &viewcells = mViewCellsManager->GetViewCells(); 
    17061706  int maxPvs = -1; 
    1707   for (i=0; i < viewcells.size(); i++) { 
     1707  for (i=0; i < viewcells.size(); i++)  
     1708  { 
    17081709        ViewCell *vc = viewcells[i]; 
    1709         int p = vc->GetPvs().GetSize(); 
     1710        const int p = vc->GetPvs().CountPvs(); 
    17101711        if (p > maxPvs) 
    17111712          maxPvs = p; 
     
    17231724          c = vc->GetColor(); 
    17241725        else { 
    1725           float importance = (float)vc->GetPvs().GetSize() / (float)maxPvs; 
     1726          const float importance = (float)vc->GetPvs().CountPvs() / (float)maxPvs; 
    17261727          c = RgbColor(importance, 1.0f - importance, 0.0f); 
    17271728        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp

    r863 r1141  
    11#include <iostream> 
     2#include <stack> 
    23#include "Pvs.h" 
     4#include "Intersectable.h" 
     5#include "KdIntersectable.h" 
     6#include "KdTree.h" 
     7#include "common.h" 
     8 
    39 
    410namespace GtpVisibilityPreprocessor { 
    511 
    6 int 
    7 KdPvs::Compress() 
     12 
     13int KdPvs::Compress() 
    814{ 
    915        return 0; // TODO 
    1016} 
    1117 
     18 
     19int ObjectPvs::CountPvs() const 
     20{ 
     21        int pvs = 0; 
     22 
     23        Intersectable::NewMail(); 
     24        KdNode::NewMail(); 
     25 
     26        ObjectPvsMap::const_iterator it, it_end = mEntries.end(); 
     27 
     28        for (it = mEntries.begin(); it != it_end; ++ it) 
     29        { 
     30                Intersectable *obj = (*it).first; 
     31 
     32                if (obj->Type() == Intersectable::KD_INTERSECTABLE) 
     33                { 
     34                        KdIntersectable *kdObj = dynamic_cast<KdIntersectable *>(obj); 
     35 
     36                        stack<KdNode *> tStack; 
     37 
     38                        tStack.push(kdObj->GetNode()); 
     39 
     40                        while (!tStack.empty()) 
     41                        { 
     42                                KdNode *node = tStack.top(); 
     43                                tStack.pop(); 
     44 
     45                                // already processed node (objects in pvs) 
     46                                if (node->Mailed()) 
     47                                        continue; 
     48 
     49                                node->Mail(); 
     50 
     51                                if (node->IsLeaf()) 
     52                                { 
     53                                         
     54                                        KdLeaf *leaf = dynamic_cast<KdLeaf *>(node); 
     55 
     56                                        pvs += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 
     57 
     58                                        ObjectContainer::const_iterator it, it_end = leaf->mMultipleObjects.end(); 
     59                                        { 
     60                                                Intersectable *object = *it;                                             
     61                                                 
     62                                                if (!object->Mailed()) 
     63                                                { 
     64                                                        object->Mail(); 
     65                                                        ++ pvs; 
     66                                                } 
     67                                        } 
     68                                } 
     69                                else 
     70                                { 
     71                                        KdInterior *interior = dynamic_cast<KdInterior *>(node); 
     72 
     73                                        tStack.push(interior->mFront); 
     74                                        tStack.push(interior->mBack); 
     75                                } 
     76                        } 
     77                } 
     78                else 
     79                { 
     80                        ++ pvs; 
     81                } 
     82        } 
     83 
     84        return pvs; 
    1285} 
     86 
     87} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r1112 r1141  
    5858 
    5959  /** Normalize the visibility of entries in order to get comparable 
    60           results */ 
    61    
     60          results  
     61  */ 
    6262  void NormalizeMaximum(); 
    6363   
     
    413413class KdPvs: public Pvs<KdNode *> 
    414414{ 
     415public: 
    415416        int Compress(); 
    416417}; 
    417418 
     419 
     420class ObjectPvs: public Pvs<Intersectable *> 
     421{ 
     422public: 
     423        /** Counts pvs. Different to GetSize(), not 
     424                only the raw container size is returned, 
     425                but the individual contributions of the entries are summed up. 
     426        */ 
     427        int CountPvs() const; 
     428}; 
    418429 
    419430//-- typedefs 
     
    426437typedef PvsData<KdNode *> KdPvsData; 
    427438 
    428 typedef Pvs<Intersectable *> ObjectPvs; 
     439//typedef Pvs<Intersectable *> ObjectPvs; 
    429440typedef Pvs<ViewCell *> ViewCellPvs; 
    430441} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ResourceManager.h

    r1004 r1141  
    4949        T *CreateResource() 
    5050        { 
    51                 const int id = CreateUniqueId(); 
     51                const unsigned int id = CreateUniqueId(); 
    5252 
    5353                T *resource = new T(id); 
     
    6161                @returns mesh or NULL if mesh was not found. 
    6262        */ 
    63         T *FindEntry(const int id) const 
     63        T *FindEntry(const unsigned int id) const 
    6464        { 
    65                 std::map<int, T *>::const_iterator mit = mEntries.find(id); 
     65                std::map<unsigned int, T *>::const_iterator mit = mEntries.find(id); 
    6666 
    6767                if (mit != mEntries.end())  
     
    7676                @returns true if the mesh was found, false if not 
    7777        */ 
    78         bool DestroyEntry(const int id) 
     78        bool DestroyEntry(const unsigned int id) 
    7979        {        
    8080                if (!FindEntry(id)) 
     
    112112        ~ResourceManager<T>() 
    113113        { 
    114                 std::map<int, T *>::iterator mit, mit_end = mEntries.end(); 
     114                std::map<unsigned int, T *>::iterator mit, mit_end = mEntries.end(); 
    115115 
    116116                for (mit = mEntries.begin(); mit != mEntries.end(); ++ mit) 
     
    129129         /** Helper function returning unique id for resource. 
    130130         */ 
    131         static int CreateUniqueId() 
     131        static unsigned int CreateUniqueId() 
    132132        { 
    133133                return sCurrentId ++; 
     
    137137 
    138138        /// the resource container 
    139         std::map<int, T *> mEntries; 
     139        std::map<unsigned int, T *> mEntries; 
    140140 
    141141private: 
    142142 
    143143        static ResourceManager<T> *sResourceManager; 
    144         static int sCurrentId; 
     144        static unsigned int sCurrentId; 
    145145}; 
    146146 
    147147// only instance of the resource manager 
    148148template <typename T> ResourceManager<T> *ResourceManager<T>::sResourceManager = NULL; 
    149 template <typename T> int ResourceManager<T>::sCurrentId = 0; 
     149template <typename T> unsigned int ResourceManager<T>::sCurrentId = 0; 
    150150 
    151151/// This type is responsible for creation and disposal the meshes 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1139 r1141  
    823823 
    824824        Debug << "updating active vc: " << (int)viewCells.size() << endl; 
    825         // find all already merged view cells and remove them from view cells 
     825         
     826        // find all already merged view cells and remove them from the 
     827        // container view cells 
    826828                 
    827829        // sort out all view cells which are not active anymore, i.e., they 
     
    883885                const int upper = mViewCellsManager->GetMaxPvsSize(); 
    884886 
    885                 const float penalty = EvalPvsPenalty((*vit)->GetPvs().GetSize(), lower, upper); 
     887                const float penalty = EvalPvsPenalty((*vit)->GetPvs().CountPvs(), lower, upper); 
    886888                 
    887889                mDeviation += fabs(mAvgRenderCost - penalty); 
     
    943945 
    944946// TODO: should be done in view cells manager 
    945 ViewCellInterior *ViewCellsTree::MergeViewCells(ViewCell *l,  
    946                                                                                                 ViewCell *r,  
     947ViewCellInterior *ViewCellsTree::MergeViewCells(ViewCell *left,  
     948                                                                                                ViewCell *right,  
    947949                                                                                                int &pvsDiff) //const 
    948950{ 
    949         ViewCellInterior *vc = mViewCellsManager->MergeViewCells(l, r); 
     951        // create merged view cell 
     952        ViewCellInterior *vc =  
     953                mViewCellsManager->MergeViewCells(left, right); 
    950954 
    951955        // if merge was unsuccessful 
     
    953957 
    954958        // set to the new parent view cell 
    955         l->SetParent(vc); 
    956         r->SetParent(vc); 
    957  
    958         // set new size of view cell 
     959        left->SetParent(vc); 
     960        right->SetParent(vc); 
     961 
     962         
    959963        if (mUseAreaForPvs) 
    960964        { 
    961                 vc->SetArea(l->GetArea() + l->GetArea()); 
     965                // set new area of view cell 
     966                // not not correct, but costly to compute real area!! 
     967                vc->SetArea(left->GetArea() + right->GetArea()); 
    962968        } 
    963969        else 
    964         { 
    965                 vc->SetVolume(r->GetVolume() + l->GetVolume()); 
     970        {       // set new volume of view cell 
     971                vc->SetVolume(left->GetVolume() + right->GetVolume()); 
    966972        } 
    967973 
     
    971977        vc->Mail(); 
    972978 
    973         const int pvs1 = l->GetPvs().GetSize(); 
    974         const int pvs2 = r->GetPvs().GetSize(); 
    975  
    976  
    977         // new view cells are stored in this vector 
     979        const int pvs1 = left->GetPvs().CountPvs(); 
     980        const int pvs2 = right->GetPvs().CountPvs(); 
     981 
     982 
     983        // the new view cells are stored in this container 
    978984        mMergedViewCells.push_back(vc); 
    979985 
    980         pvsDiff = vc->GetPvs().GetSize() - pvs1 - pvs2; 
    981  
    982  
    983  
    984         //Ždon't store intermediate pvs 
     986        pvsDiff = vc->GetPvs().CountPvs() - pvs1 - pvs2; 
     987 
     988 
     989        // don't store pvs in interior cells, just a scalar 
    985990        if (mViewCellsStorage == PVS_IN_LEAVES) 
    986991        { 
    987                 l->mPvsSize = l->GetPvs().GetSize();  
    988                 l->mPvsSizeValid = true; 
     992                left->mPvsSize = left->GetPvs().GetSize();  
     993                left->mPvsSizeValid = true; 
    989994                 
    990                 if (!l->IsLeaf()) 
    991                         l->GetPvs().Clear(); 
     995                // remove pvs, we don't store interior pvss 
     996                if (!left->IsLeaf()) 
     997                { 
     998                        left->GetPvs().Clear(); 
     999                } 
     1000 
     1001                right->mPvsSize = right->GetPvs().CountPvs();  
     1002                right->mPvsSizeValid = true; 
    9921003                 
    993                 r->mPvsSize = r->GetPvs().GetSize();  
    994                 r->mPvsSizeValid = true; 
    995                  
    996                 if (!r->IsLeaf()) 
    997                         r->GetPvs().Clear(); 
    998          
    999 } 
    1000  
     1004                // remove pvs, we don't store interior pvss 
     1005                if (!right->IsLeaf()) 
     1006                { 
     1007                        right->GetPvs().Clear(); 
     1008                } 
     1009        } 
    10011010 
    10021011        return vc; 
     
    12581267                const float penalty =  
    12591268                        EvalPvsPenalty(vc->GetPvs().GetSize(), lower, upper); 
     1269 
    12601270                return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) /  
    12611271                        (float)mNumActiveViewCells; 
     
    12741284        if (1) 
    12751285        { 
    1276                 const float penalty = EvalPvsPenalty(vc->GetPvs().GetSize(), lower, upper); 
     1286                const float penalty = EvalPvsPenalty(vc->GetPvs().CountPvs(), lower, upper); 
    12771287                return fabs(mAvgRenderCost - penalty) / (float)mNumActiveViewCells; 
    12781288        } 
     
    12831293 
    12841294 
    1285  
    12861295float ViewCellsTree::GetRenderCost(ViewCell *vc) const 
    12871296{ 
    12881297        if (mUseAreaForPvs) 
    1289                 return vc->GetPvs().GetSize() * vc->GetArea(); 
    1290  
    1291         return vc->GetPvs().GetSize() * vc->GetVolume(); 
     1298        { 
     1299                return vc->GetPvs().CountPvs() * vc->GetArea(); 
     1300        } 
     1301 
     1302        return vc->GetPvs().CountPvs() * vc->GetVolume(); 
    12921303} 
    12931304 
     
    13281339                newPvs = (int)ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 
    13291340 
    1330         const float newPenalty = EvalPvsPenalty(newPvs, 
     1341        const float newPenalty = EvalPvsPenalty(newPvs,  
    13311342                                                                                        mViewCellsManager->GetMinPvsSize(), 
    13321343                                                                                        mViewCellsManager->GetMaxPvsSize()); 
     
    14771488                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
    14781489                        { 
    1479                                 int pvsSize = GetPvsSize(*it); 
     1490                                const int pvsSize = GetPvsSize(*it); 
    14801491                                childCost += (float) pvsSize * (*it)->GetVolume(); 
    14811492                                childPvs += pvsSize; 
     
    16031614 
    16041615 
    1605  
    16061616        // delete all the objects from the leaf sets which were moved to parent pvs 
    16071617        ObjectPvsMap::const_iterator oit_end = interior->GetPvs().mEntries.end(); 
     
    16151625                } 
    16161626        } 
    1617  
    1618         /*int dummy = interior->GetPvs().GetSize(); 
    1619  
    1620         for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit) 
    1621         { 
    1622                 dummy += (*cit)->GetPvs().GetSize(); 
    1623         }*/ 
    1624  
    16251627} 
    16261628 
     
    17291731                        { 
    17301732                                if (countKdPvs) 
    1731                                         pvsSize = vc->GetPvs().GetSize(); 
     1733                                        pvsSize = vc->GetPvs().CountPvs(); 
    17321734                                else 
    17331735                                        pvsSize = CountKdPvs(dynamic_cast<ViewCellLeaf *>(vc)); 
     
    18171819        case PVS_IN_INTERIORS: 
    18181820        default: 
    1819                 Debug << "in interiors: " << vc->mPvsSize << " $$ " << vc->GetPvs().GetSize() << endl; 
    1820                 pvsSize = vc->GetPvs().GetSize();                
     1821                Debug << "in interiors: " << vc->mPvsSize << " $$ " << vc->GetPvs().CountPvs() << endl; 
     1822                pvsSize = vc->GetPvs().CountPvs();               
    18211823        } 
    18221824 
     
    18401842        if ((mViewCellsStorage == PVS_IN_INTERIORS) || vc->IsLeaf()) 
    18411843        { 
    1842                 pvsSize = vc->GetPvs().GetSize(); 
     1844                pvsSize = vc->GetPvs().CountPvs(); 
    18431845        } 
    18441846 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r1139 r1141  
    206206                return a->mPvsSize < b->mPvsSize; 
    207207#else 
    208                 return a->GetPvs().GetSize() < b->GetPvs().GetSize(); 
     208                return a->GetPvs().CountPvs() < b->GetPvs().CountPvs(); 
    209209#endif 
    210210        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp

    r1106 r1141  
    19481948                  << "#polygons: " << (int)data.mPolygons->size() << " (max: " << mTermMinPolys << "), " 
    19491949                  << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), "  
    1950                   << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "=, " 
     1950                  << "#pvs: " << leaf->GetViewCell()->GetPvs().CountPvs() << "=, " 
    19511951                  << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 
    19521952#endif 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1139 r1141  
    226226        // question: rather create view cells resource manager? 
    227227        if (!ViewCellsTreeConstructed()) 
     228        { 
    228229                CLEAR_CONTAINER(mViewCells); 
    229          
     230        } 
     231 
    230232        DEL_PTR(mViewCellsTree); 
    231233} 
     
    301303                                Ray *pray = (*it)->mPiercingRays[0]; 
    302304                                Debug << "view cell " << (*it)->GetId() << " not empty, pvs: "  
    303                                           << (*it)->GetPvs().GetSize() << " " << (int)pray->intersections.size() << endl; 
     305                                          << (*it)->GetPvs().CountPvs() << " " << (int)pray->intersections.size() << endl; 
    304306 
    305307                                exporter->ExportRays((*it)->mPiercingRays); 
     
    11951197{ 
    11961198 
    1197         if ((vc->GetPvs().GetSize() > maxPvsSize) || 
    1198                 (vc->GetPvs().GetSize() < minPvsSize)) 
     1199        if ((vc->GetPvs().CountPvs() > maxPvsSize) || 
     1200                (vc->GetPvs().CountPvs() < minPvsSize)) 
    11991201        { 
    12001202                return false; 
     
    14121414        { 
    14131415                ViewCell *vc = *it; 
    1414                 totalRenderCost += vc->GetPvs().GetSize() * vc->GetVolume(); 
    1415                 totalPvs += (int)vc->GetPvs().GetSize(); 
     1416                totalRenderCost += vc->GetPvs().CountPvs() * vc->GetVolume(); 
     1417                totalPvs += (int)vc->GetPvs().CountPvs(); 
    14161418        } 
    14171419 
     
    14301432                ViewCell *vc = *it; 
    14311433 
    1432                 float renderCost = vc->GetPvs().GetSize() * vc->GetVolume(); 
     1434                float renderCost = vc->GetPvs().CountPvs() * vc->GetVolume(); 
    14331435                float dev; 
    14341436 
    14351437                if (1) 
    1436                         dev = fabs(avgRenderCost - (float)vc->GetPvs().GetSize()); 
     1438                        dev = fabs(avgRenderCost - (float)vc->GetPvs().CountPvs()); 
    14371439                else 
    14381440                        dev = fabs(expectedRenderCost - renderCost); 
     
    15911593 
    15921594        // update pvs size 
    1593         vc->mPvsSize = vc->GetPvs().GetSize(); 
     1595        vc->mPvsSize = vc->GetPvs().CountPvs(); 
    15941596        vc->mPvsSizeValid = true; 
    15951597 
     
    40654067        { 
    40664068                pvs = root->GetPvs(); 
    4067                 SetScalarPvsSize(root, root->GetPvs().GetSize()); 
     4069                SetScalarPvsSize(root, root->GetPvs().CountPvs()); 
    40684070                 
    40694071                return; 
     
    54645466                exporter->SetFilled(); 
    54655467 
    5466  
    54675468                if (1) 
    54685469                {        
     
    54795480                        exporter->SetForcedMaterial(m); 
    54805481 
    5481                         // find kd nodes 
     5482                        // export pvs entries 
    54825483                        for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
    54835484                        {        
     
    54885489                                        exporter->ExportIntersectable(obj); 
    54895490                                        obj->Mail(); 
    5490                                 }                                        
    5491                                  
    5492                                 // export "original" pvs 
    5493                                 m.mDiffuseColor = RgbColor(0, 0, 1); 
    5494                                 exporter->SetForcedMaterial(m); 
    5495  
    5496                                 if ((*oit).first->Type() == Intersectable::KD_INTERSECTABLE) 
    5497                                 { 
    5498                                         KdIntersectable *kdObj = dynamic_cast<KdIntersectable *>(obj); 
    5499                                         Intersectable *hitObj = kdObj->mHitObject; 
    5500                                  
    5501                                         if (!hitObj->Mailed()) 
    5502                                         { 
    5503                                                 exporter->ExportIntersectable(hitObj); 
    5504                                                 hitObj->Mail(); 
    5505                                         }        
    55065491                                } 
    55075492                        }                
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1121 r1141  
    655655        /// if pvs should be exported with view cells 
    656656        bool mExportPvs; 
    657  
     657// matt§§: need this? 
    658658        bool mCountKdPvs; 
    659659}; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp

    r1139 r1141  
    261261 
    262262                                mForcedMaterial.mDiffuseColor.b = 1.0f; 
    263                                 const float importance = (float)leaf->GetViewCell()->GetPvs().GetSize() / (float)maxPvs; 
     263                                const float importance = (float)leaf->GetViewCell()->GetPvs().CountPvs() / (float)maxPvs; 
    264264 
    265265                                mForcedMaterial.mDiffuseColor.r = importance; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r1137 r1141  
    854854 
    855855                // update scalar pvs size lookup 
    856                 mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().GetSize()); 
     856                mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().CountPvs()); 
    857857         
    858858 
     
    991991 
    992992                // update scalar pvs size value 
    993                 mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().GetSize()); 
     993                mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().CountPvs()); 
    994994 
    995995                mBspStats.contributingSamples += conSamp; 
     
    23432343                        if (leaf->TreeValid() &&  
    23442344                                (!onlyUnmailed || !leaf->Mailed()) && 
    2345                                 ((maxPvsSize < 0) || (leaf->GetViewCell()->GetPvs().GetSize() <= maxPvsSize))) 
     2345                                ((maxPvsSize < 0) || (leaf->GetViewCell()->GetPvs().CountPvs() <= maxPvsSize))) 
    23462346                        { 
    23472347                                leaves.push_back(leaf); 
     
    24202420                  << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 
    24212421                  << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 
    2422                   << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "), " 
     2422                  << "#pvs: " << leaf->GetViewCell()->GetPvs().CountPvs() << "), " 
    24232423                  << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 
    24242424#endif 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp

    r1139 r1141  
    364364        Environment::GetSingleton()->GetBoolValue("VspTree.simulateOctree", mCirculatingAxis); 
    365365         
    366         Environment::GetSingleton()->GetBoolValue("VspTree.useKdPvs", mUseKdPvs); 
     366        Environment::GetSingleton()->GetBoolValue("VspTree.useKdPvsForHeuristics", mUseKdPvsForHeuristics); 
    367367 
    368368        char subdivisionStatsLog[100]; 
     
    400400        Debug << "maxband: " << mMaxBand << endl; 
    401401 
    402         if (!mUseKdPvs) 
     402        if (!mUseKdPvsForHeuristics) 
    403403                Debug << "pvs count method: per object" << endl; 
    404404        else 
     
    534534        int conSamp = 0; 
    535535        float sampCon = 0.0f; 
    536         AddToPvs(leaf, *tData.mRays, sampCon, conSamp); 
     536        AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 
    537537 
    538538        // update scalar pvs size value 
    539         mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().GetSize()); 
     539        mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().CountPvs()); 
    540540 
    541541        mVspStats.contributingSamples += conSamp; 
     
    847847 
    848848 
    849 void VspTree::AddToPvs(VspLeaf *leaf, 
    850                                            const RayInfoContainer &rays, 
    851                                            float &sampleContributions, 
    852                                            int &contributingSamples) 
     849bool VspTree::AddKdLeafToPvs(KdLeaf *leaf,  
     850                                                         ViewCell *vc,  
     851                                                         float &pdf,  
     852                                                         float &contribution) 
     853{ 
     854        bool contri = false; 
     855 
     856#if 1 // add kd intersecable to pvs 
     857        KdIntersectable *kdObj = mOspTree->GetOrCreateKdIntersectable(leaf); 
     858         
     859        if (vc->AddPvsSample(kdObj, pdf, contribution)) 
     860        { 
     861                return true; 
     862        } 
     863 
     864#else // add all objects of kd node 
     865 
     866        pdf = 0; 
     867        contribution = 0; 
     868 
     869        ObjectContainer::const_iterator it, it_end = leaf->mObjects.end(); 
     870 
     871        for (it = leaf->mObjects.begin(); it != it_end; ++ it) 
     872        { 
     873                Intersectable *object = *it;                                             
     874 
     875                float newpdf; 
     876                float newcontri; 
     877                                                 
     878                if (vc->AddPvsSample(object, newpdf, newcontri)) 
     879                { 
     880                        contri = true; 
     881                } 
     882 
     883                pdf += newPdf; 
     884                newContri += contribution; 
     885        } 
     886 
     887#endif 
     888 
     889        return contri; 
     890} 
     891 
     892void VspTree::AddSamplesToPvs(VspLeaf *leaf, 
     893                                                         const RayInfoContainer &rays, 
     894                                                         float &sampleContributions, 
     895                                                         int &contributingSamples) 
    853896{ 
    854897        sampleContributions = 0; 
     
    859902        ViewCellLeaf *vc = leaf->GetViewCell(); 
    860903   
     904         
    861905        // add contributions from samples to the PVS 
    862906        for (it = rays.begin(); it != it_end; ++ it) 
     
    875919 
    876920                        // potentially visible kd cells 
    877                         if (mUseKdPvs) 
     921                        if (mStoreKdPvs) 
    878922                        { 
    879923                                KdLeaf *leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
    880                                 KdIntersectable *kdObj = new KdIntersectable(leaf); 
    881  
    882                                 entry = kdObj; 
     924                                AddKdLeafToPvs(leaf, vc, ray->mPdf, contribution); 
    883925                        } 
    884926                        else 
    885                                 entry = obj; 
    886  
    887                         if (vc->AddPvsSample(obj, ray->mPdf, contribution)) 
    888                         { 
    889                                 madeContrib = true; 
     927                        { 
     928                                if (vc->AddPvsSample(obj, ray->mPdf, contribution)) 
     929                                { 
     930                                        madeContrib = true; 
     931                                } 
    890932                        } 
    891933 
     
    900942 
    901943                        // potentially visible kd cells 
    902                         if (mUseKdPvs) 
    903                         { 
    904                                 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
    905                                 KdIntersectable *kdObj = new KdIntersectable(leaf); 
    906  
    907                                 entry = kdObj;                           
     944                        if (mUseKdPvsForHeuristics) 
     945                        { 
     946                                KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode);        
     947                                AddKdLeafToPvs(leaf, vc, ray->mPdf, contribution); 
    908948                        } 
    909949                        else 
    910                                 entry = obj; 
    911  
    912                         if (vc->AddPvsSample(obj, ray->mPdf, contribution)) 
    913                         { 
    914                                 madeContrib = true; 
     950                        { 
     951                                if (vc->AddPvsSample(obj, ray->mPdf, contribution)) 
     952                                { 
     953                                        madeContrib = true; 
     954                                } 
    915955                        } 
    916956 
     
    919959 
    920960                if (madeContrib) 
     961                { 
    921962                        ++ contributingSamples; 
    922                  
     963                } 
     964 
    923965                // store rays for visualization 
    924966                if (0) leaf->mVssRays.push_back(new VssRay(*ray)); 
     
    10561098                if (oObject) 
    10571099                { 
    1058                         if (!mUseKdPvs) 
     1100                        if (!mUseKdPvsForHeuristics) 
    10591101                        { 
    10601102                                if (!oObject->Mailed()) 
     
    10801122                if (tObject) 
    10811123                { 
    1082                         if (!mUseKdPvs) 
     1124                        if (!mUseKdPvsForHeuristics) 
    10831125                        { 
    10841126                                if (!tObject->Mailed()) 
     
    11661208        if (oObject) 
    11671209        {        
    1168                 if (!mUseKdPvs) 
     1210                if (!mUseKdPvsForHeuristics) 
    11691211                { 
    11701212                        if (ci.type == SortableEntry::ERayMin) 
     
    12021244        if (tObject) 
    12031245        {        
    1204                 if (!mUseKdPvs) 
     1246                if (!mUseKdPvsForHeuristics) 
    12051247                { 
    12061248                        if (ci.type == SortableEntry::ERayMin) 
     
    16151657                        if (leaf->TreeValid() &&  
    16161658                                (!onlyUnmailed || !leaf->Mailed()) && 
    1617                                 ((maxPvsSize < 0) || (leaf->GetViewCell()->GetPvs().GetSize() <= maxPvsSize))) 
     1659                                ((maxPvsSize < 0) || (leaf->GetViewCell()->GetPvs().CountPvs() <= maxPvsSize))) 
    16181660                        { 
    16191661                                leaves.push_back(leaf); 
     
    16921734                  << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 
    16931735                  << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 
    1694                   << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "), " 
     1736                  << "#pvs: " << leaf->GetViewCell()->GetPvs().CountPvs() << "), " 
    16951737                  << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 
    16961738#endif 
     
    27072749} 
    27082750 
     2751 
     2752OspTree::~OspTree() 
     2753{ 
     2754        KdIntersectableMap::iterator it, it_end = mKdIntersectables.end(); 
     2755 
     2756        for (it = mKdIntersectables.begin(); it != mKdIntersectables.end(); ++ it) 
     2757        { 
     2758                DEL_PTR((*it).second); 
     2759        } 
     2760} 
    27092761 
    27102762 
     
    38953947 
    38963948 
     3949KdIntersectable *OspTree::GetOrCreateKdIntersectable(KdNode *node) 
     3950{ 
     3951        // search nodes 
     3952        std::map<KdNode *, KdIntersectable *>::const_iterator it = mKdIntersectables.find(node); 
     3953 
     3954        if (it != mKdIntersectables.end())  
     3955        { 
     3956                return (*it).second; 
     3957        } 
     3958 
     3959        // not in map => create new entry 
     3960        KdIntersectable *kdObj= new KdIntersectable(node); 
     3961 
     3962        mKdIntersectables[node] = kdObj; 
     3963 
     3964        return kdObj; 
     3965} 
    38973966 
    38983967 
     
    39003969/*               class HierarchyManager implementation              */ 
    39013970/********************************************************************/ 
    3902  
    39033971 
    39043972 
     
    40684136        // makes no sense otherwise because only one kd cell available 
    40694137        // during view space partition 
    4070         const bool savedCountMethod = mVspTree.mUseKdPvs; 
    4071         mVspTree.mUseKdPvs = false; 
     4138        const bool savedCountMethod = mVspTree.mUseKdPvsForHeuristics; 
     4139        const bool savedStoreMethod = mVspTree.mStoreKdPvs; 
     4140         
     4141        mVspTree.mUseKdPvsForHeuristics = false; 
     4142        mVspTree.mStoreKdPvs = false; 
    40724143 
    40734144        mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, *viewSpaceRays)); 
     
    41484219        cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 
    41494220 
    4150         mVspTree.mUseKdPvs = savedCountMethod; 
     4221        mVspTree.mUseKdPvsForHeuristics = savedCountMethod; 
     4222        mVspTree.mStoreKdPvs = savedStoreMethod; 
    41514223} 
    41524224 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1139 r1141  
    3333class KdLeaf; 
    3434class OspTree; 
     35class KdIntersectable; 
     36 
    3537 
    3638 
     
    461463#endif 
    462464 
     465typedef map<KdNode *, KdIntersectable *> KdIntersectableMap; 
     466 
    463467typedef FlexibleHeap<SplitCandidate *> SplitQueue; 
    464468 
     
    980984                 
    981985        */ 
    982         void AddToPvs(VspLeaf *leaf, 
     986        void AddSamplesToPvs(VspLeaf *leaf, 
    983987                                  const RayInfoContainer &rays,  
    984988                                  float &sampleContributions, 
    985989                                  int &contributingSamples); 
     990 
     991        bool AddKdLeafToPvs(KdLeaf *leaf, ViewCell *vc, float &pvs, float &contribution); 
    986992 
    987993        /** Propagates valid flag up the tree. 
     
    10181024protected: 
    10191025 
    1020         bool mUseKdPvs; 
    1021  
    1022         enum {PER_OBJECT, PER_KDLEAF}; 
     1026        bool mUseKdPvsForHeuristics; 
     1027        bool mStoreKdPvs; 
    10231028 
    10241029        ViewCellsManager *mViewCellsManager; 
     
    10361041        /// box around the whole view domain 
    10371042        AxisAlignedBox3 mBoundingBox; 
    1038  
    10391043 
    10401044 
     
    13391343#endif 
    13401344 
     1345        /** Returns or creates a new intersectable for use in a kd based pvs. 
     1346                The OspTree is responsible for destruction of the intersectable. 
     1347        */ 
     1348        KdIntersectable *GetOrCreateKdIntersectable(KdNode *node); 
     1349 
    13411350        /** Collects rays stored in the leaves. 
    13421351        */ 
     
    15491558                float &pFront, 
    15501559                float &pBack); 
    1551         /** Adds ray sample contributions to the PVS. 
    1552                 @param sampleContributions the number contributions of the samples 
    1553                 @param contributingSampels the number of contributing rays 
    1554                  
    1555         */ 
    1556         void AddToPvs(VspLeaf *leaf, 
    1557                                   const RayInfoContainer &rays,  
    1558                                   float &sampleContributions, 
    1559                                   int &contributingSamples); 
    1560  
     1560         
    15611561        /** Propagates valid flag up the tree. 
    15621562        */ 
     
    16671667 
    16681668 
    1669  
    16701669        //-- split heuristics based parameters 
    16711670         
     
    16981697        /// weight between  render cost decrease and node render cost 
    16991698        float mRenderCostDecreaseWeight; 
     1699 
     1700        /// stores the kd node intersectables used for pvs 
     1701        KdIntersectableMap mKdIntersectables; 
    17001702}; 
    17011703 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp

    r1121 r1141  
    297297 
    298298                                mForcedMaterial.mDiffuseColor.b = 1.0f; 
    299                                 const float importance = (float)leaf->GetViewCell()->GetPvs().GetSize() / (float)maxPvs; 
     299                                const float importance =  
     300                                        (float)leaf->GetViewCell()->GetPvs().CountPvs() / (float)maxPvs; 
    300301 
    301302                                mForcedMaterial.mDiffuseColor.r = importance; 
Note: See TracChangeset for help on using the changeset viewer.