Changeset 573


Ignore:
Timestamp:
01/24/06 10:06:58 (18 years ago)
Author:
mattausch
Message:

implemented functtion for view cell construction

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
8 edited

Legend:

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

    r568 r573  
    3030VssPreprocessor { 
    3131        samplesPerPass  100000 
    32         initialSamples 2000000 
     32        initialSamples 6000000 
    3333        vssSamples 0 
    3434        vssSamplesPerPass 500000 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h

    r563 r573  
    118118                           ); 
    119119   
     120  virtual void CastRays(SimpleRayContainer &rays, 
     121          VssRayContainer &vssRays) {}; 
     122 
    120123  /// scene graph loaded from file 
    121124  SceneGraph *mSceneGraph; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h

    r556 r573  
    133133        std::map<T, PvsData<T>, LtSample<T> >::const_iterator it; 
    134134 
     135        mEntries = a.mEntries; 
    135136        // todo: copy all elements instead of inserting 
    136         for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it) 
    137                 mEntries.insert(*it); 
     137        //for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it) 
     138        //      mEntries.insert(*it); 
    138139         
    139140        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r556 r573  
    201201} 
    202202 
     203 
    203204bool BspLeaf::IsLeaf() const  
    204205{  
     
    206207} 
    207208 
    208 /****************************************************************/ 
    209 /*                  class BspTree implementation                */ 
    210 /****************************************************************/ 
     209 
     210/******************************************************************/ 
     211/*                    class BspTree implementation                */ 
     212/******************************************************************/ 
    211213 
    212214BspTree::BspTree():   
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r572 r573  
    8888 
    8989 
     90int ViewCellsManager::CastPassSamples(int samplesPerPass,  
     91                                                                          int sampleType,  
     92                                                                          VssRayContainer *outRays) const 
     93{ 
     94        VssRayContainer passSamples; 
     95        SimpleRayContainer simpleRays; 
     96 
     97        preprocessor->GenerateRays(samplesPerPass, 
     98                                                           sampleType, 
     99                                                           simpleRays); 
     100 
     101        // shoot simple ray and add it to importance samples 
     102        preprocessor->CastRays(simpleRays, passSamples); 
     103 
     104        const int numSamples = (int)passSamples.size(); 
     105 
     106        if (outRays) 
     107        { 
     108                while (!passSamples.empty()) 
     109                        outRays->push_back(passSamples.back()); 
     110        } 
     111        else 
     112        { 
     113                CLEAR_CONTAINER(passSamples); 
     114        } 
     115 
     116        return numSamples; 
     117} 
     118 
     119 
    90120int ViewCellsManager::Construct(Preprocessor *preprocessor, VssRayContainer *outRays) 
    91121{ 
     122        int numSamples = 0; 
    92123        SimpleRayContainer simpleRays; 
    93         VssRayContainer constructionRays; 
    94  
    95         preprocessor->GenerateRays(mConstructionSamples, 
    96                                                            Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION, 
    97                                                            simpleRays); 
    98  
    99         Construct(preprocessor->mObjects, constructionRays); 
    100  
    101         int numRays = (int)simpleRays.size(); 
    102  
    103         static Ray traversalRay; 
    104  
    105         // shoot simple ray and add it to construction rays 
    106         while (!simpleRays.empty()) 
    107         { 
    108                 SimpleRay sray = simpleRays.back(); 
    109  
    110                 // TODO: shoot into kdtree 
    111                 constructionRays.push_back(new VssRay(traversalRay)); 
    112  
    113                 if (outRays) 
    114                         outRays->push_back(constructionRays.back()); 
    115  
    116                 simpleRays.pop_back(); 
    117         } 
    118  
    119         if (!outRays) 
    120                 CLEAR_CONTAINER(constructionRays); 
    121  
    122         // guided rays 
    123         VssRayContainer importanceRays; 
    124         const int desiredImportanceRays = max(1000000, mPostProcessSamples); 
    125         preprocessor->GenerateRays(desiredImportanceRays, 
    126                                                            Preprocessor::RSS_BASED_DISTRIBUTION, 
    127                                                            simpleRays); 
    128  
    129         numRays += (int)simpleRays.size(); 
    130  
    131         // shoot simple ray and add it to construction rays 
    132         while (!simpleRays.empty()) 
    133         { 
    134                 SimpleRay sray = simpleRays.back(); 
    135  
    136                 // TODO: shoot into kdtree 
    137                 importanceRays.push_back(new VssRay(traversalRay)); 
    138  
    139                 if (outRays) 
    140                         outRays->push_back(importanceRays.back()); 
    141  
    142                 simpleRays.pop_back(); 
    143         } 
    144  
    145         if (!outRays) 
    146                 CLEAR_CONTAINER(importanceRays); 
    147  
     124         
     125        VssRayContainer constructionSamples; 
     126 
     127        //-- construction rays => we use uniform samples for this 
     128        CastPassSamples(mConstructionSamples,  
     129                                        Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION,  
     130                                        &constructionSamples); 
     131         
     132        // construct view cells 
     133        const int initialSamples = Construct(preprocessor->mObjects, constructionSamples); 
     134 
     135        numSamples += initialSamples; 
     136 
     137        if (outRays) 
     138        { 
     139                while (!constructionSamples.empty()) 
     140                        outRays->push_back(constructionSamples.back()); 
     141        } 
     142        else 
     143        { 
     144                CLEAR_CONTAINER(constructionSamples); 
     145        } 
     146 
     147 
     148        //-- guided rays are used for further sampling 
     149        const int desiredImportanceSamples = 5000000; 
     150        const int importanceRayPerPass = 1000000; 
     151 
     152        const int n = desiredImportanceSamples; //+initialSamples; 
     153 
     154        while (numSamples < n) 
     155        { 
     156                numSamples += CastPassSamples(importanceRayPerPass,  
     157                                                                          Preprocessor::RSS_BASED_DISTRIBUTION,  
     158                                                                          //Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION, 
     159                                                                          outRays); 
     160        } 
     161         
     162 
     163        //-- post processing 
     164        VssRayContainer postProcessSamples; 
     165 
     166        //-- construction rays => we use uniform samples for this 
     167        CastPassSamples(max(mPostProcessSamples, mVisualizationSamples), 
     168                                    Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION,  
     169                                        &postProcessSamples); 
     170         
    148171        // merge the view cells 
    149         PostProcess(preprocessor->mObjects, importanceRays); 
    150  
    151         Visualize(preprocessor->mObjects, importanceRays); 
    152  
    153  
    154         return numRays; 
     172        PostProcess(preprocessor->mObjects, postProcessSamples); 
     173        // several visualizations 
     174        Visualize(preprocessor->mObjects, postProcessSamples); 
     175 
     176        if (outRays) 
     177        { 
     178                while (!postProcessSamples.empty()) 
     179                        outRays->push_back(postProcessSamples.back()); 
     180        } 
     181        else 
     182        { 
     183                CLEAR_CONTAINER(postProcessSamples); 
     184        } 
     185 
     186        return numSamples; 
    155187} 
    156188 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r570 r573  
    306306protected: 
    307307 
     308        int CastPassSamples(int samplesPerPass,  
     309                                                int sampleType,  
     310                                                VssRayContainer *outRays) const; 
     311 
    308312        void ParseEnvironment(); 
    309313 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r570 r573  
    942942                                else 
    943943                                { 
    944                                         nCostRatio[axis] = SplitPlaneCost(Plane3(normal, nPosition[axis]),  
    945                                                                                                           tData, *nFrontGeom[axis], *nBackGeom[axis], 
    946                                                                                                           nProbFront[axis], nProbBack[axis]); 
     944                                        nCostRatio[axis] =  
     945                                                EvalSplitPlaneCost(Plane3(normal, nPosition[axis]),  
     946                                                                                   tData, *nFrontGeom[axis], *nBackGeom[axis], 
     947                                                                                   nProbFront[axis], nProbBack[axis]); 
    947948                                } 
    948949                        } 
     
    11231124                float fArea, bArea; 
    11241125                plane = poly->GetSupportingPlane(); 
    1125                 candidateCost = SplitPlaneCost(plane, data, fGeom, bGeom, fArea, bArea); 
     1126                candidateCost = EvalSplitPlaneCost(plane, data, fGeom, bGeom, fArea, bArea); 
    11261127                 
    11271128                if (candidateCost < lowestCost) 
     
    12631264 
    12641265 
    1265 float VspBspTree::SplitPlaneCost(const Plane3 &candidatePlane, 
    1266                                                                 const VspBspTraversalData &data, 
    1267                                                                 BspNodeGeometry &geomFront, 
    1268                                                                 BspNodeGeometry &geomBack, 
    1269                                                                 float &pFront, 
    1270                                                                 float &pBack) const 
     1266float VspBspTree::EvalSplitPlaneCost(const Plane3 &candidatePlane, 
     1267                                                                        const VspBspTraversalData &data, 
     1268                                                                        BspNodeGeometry &geomFront, 
     1269                                                                        BspNodeGeometry &geomBack, 
     1270                                                                        float &pFront, 
     1271                                                                        float &pBack) const 
    12711272{ 
    12721273        float cost = 0; 
     
    13771378        if (mSplitPlaneStrategy & PVS) 
    13781379        { 
    1379                 const float oldCost = pOverall * (float)totalPvs + Limits::Small; 
    1380                 cost += mPvsFactor * (pvsFront * pFront + pvsBack * pBack) / oldCost; 
     1380                if (1) 
     1381                { 
     1382                        const float oldCost = pOverall * (float)totalPvs + Limits::Small; 
     1383                        cost += mPvsFactor * (pvsFront * pFront + pvsBack * pBack) / oldCost; 
     1384                } 
     1385                else 
     1386                { 
     1387                        // try to equalize render differences 
     1388                        const float oldCost = pOverall * (float)totalPvs + Limits::Small; 
     1389                        float newCost = fabs(pvsFront * pFront - pvsBack * pBack); 
     1390 
     1391                        cost += mPvsFactor * newCost / oldCost; 
     1392                } 
    13811393        } 
    13821394 
     
    25732585        } 
    25742586 
     2587        // important so other merge candidates sharing this view cell 
     2588        // are notified that the merge cost must be updated!! 
    25752589        vc->Mail(); 
    25762590 
    2577         // clean up old view cells 
     2591        //-- clean up old view cells 
    25782592        if (mExportMergedViewCells) 
    25792593        { 
     
    25812595                DEL_PTR(bVc); 
    25822596        } 
    2583         else // throw them into old view cells container 
    2584         { 
     2597        else  
     2598        { 
     2599                // old view cells container needed for visualization 
    25852600                //fVc->mMailbox = -1; 
    25862601                //bVc->mMailbox = -1; 
     
    32043219                return 1e15f; 
    32053220 
     3221#if 1 
    32063222        float p1, p2; 
    32073223 
     
    32173233        } 
    32183234 
    3219         const float cost1 = (float)pvs1;// * p1; 
    3220         const float cost2 = (float)pvs2;// * p2; 
     3235        const float cost1 = pvs1 * p1; 
     3236        const float cost2 = pvs2 * p2; 
     3237#else 
     3238        const float cost1 = pvs1; 
     3239        const float cost2 = pvs2; 
     3240#endif 
    32213241 
    32223242        return cost1 + cost2; 
     
    32703290        BspViewCell *vc2 = leaf2->GetViewCell(); 
    32713291 
    3272         float cost1 = vc1->GetPvs().GetSize();  
    3273         float cost2 = vc2->GetPvs().GetSize();  
    3274  
    3275         /*if (mUseAreaForPvs) 
     3292        float cost1, cost2; 
     3293 
     3294#if 1 
     3295        if (mUseAreaForPvs) 
    32763296        { 
    32773297                cost1 = vc1->GetPvs().GetSize() * vc1->GetArea(); 
     
    32823302                cost1 = vc1->GetPvs().GetSize() * vc1->GetVolume(); 
    32833303                cost2 = vc2->GetPvs().GetSize() * vc2->GetVolume(); 
    3284         }*/ 
     3304        } 
     3305#else 
     3306        cost1 = vc1->GetPvs().GetSize();  
     3307        cost2 = vc2->GetPvs().GetSize();  
     3308#endif 
    32853309 
    32863310        const float oldCost = cost1 + cost2; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r564 r573  
    411411                @returns the cost of the candidate split plane 
    412412        */ 
    413         float SplitPlaneCost(const Plane3 &candidatePlane,  
    414                                                 const VspBspTraversalData &data, 
    415                                                 BspNodeGeometry &geomFront, 
    416                                                 BspNodeGeometry &geomBack, 
    417                                                 float &pFront, 
    418                                                 float &pBack) const; 
     413        float EvalSplitPlaneCost(const Plane3 &candidatePlane,  
     414                                                        const VspBspTraversalData &data, 
     415                                                        BspNodeGeometry &geomFront, 
     416                                                        BspNodeGeometry &geomBack, 
     417                                                        float &pFront, 
     418                                                        float &pBack) const; 
    419419 
    420420        /** Subdivide leaf. 
Note: See TracChangeset for help on using the changeset viewer.