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

added kd pvs support, changed way of counting pvs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.