Changeset 367


Ignore:
Timestamp:
11/02/05 02:50:57 (19 years ago)
Author:
mattausch
Message:

started pvs surface area heuristics

Location:
trunk/VUT
Files:
10 edited

Legend:

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

    r366 r367  
    5656 
    5757Sampling { 
    58         totalSamples    20000000 
     58        totalSamples    300000 
    5959        samplesPerPass  3 
    6060} 
     
    8282        #       input fromViewCells 
    8383        #       input fromSceneGeometry 
    84                 samples 100000 
     84                samples 10000 
    8585                sideTolerance 0.005 
    8686        } 
     
    9797        # least ray splits     = 256 
    9898        # balanced rays        = 512 
     99        # pvs                  = 1024 
    99100 
    100101        # least splits + balanced polygons 
     
    119120        #splitPlaneStrategy 130 
    120121         
    121         splitPlaneStrategy 130 
     122        splitPlaneStrategy 1024 
    122123         
    123124        maxCandidates 80 
     
    125126        Termination { 
    126127                # autopartition 
    127                 maxRays 80 
    128                 maxPolygons 0 
     128                maxRays 200 
     129                maxPolygons 5 
    129130                maxDepth 100 
    130131                 
    131132                # axis aligned splits 
    132133                AxisAligned { 
    133                         maxPolys 500 
    134                         maxRays 300 
    135                         maxObjects 20 
     134                        maxPolys 5000 
     135                        maxRays 5000 
     136                        maxObjects 2000 
    136137                        maxCostRatio 0.9 
    137138                        ct_div_ci 0.5 
     
    142143                splitBorder 0.01 
    143144        } 
     145         
     146        PostProcessing { 
     147                samples 100000 
     148        } 
    144149                 
    145150        # if split polys are stored for visualization 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r362 r367  
    11801180          "100000"); 
    11811181 
     1182  RegisterOption("BspTree.PostProcessing.samples", 
     1183          optInt, 
     1184          "-bsp_postprocessing_samples=", 
     1185          "200000"); 
     1186 
    11821187  RegisterOption("BspTree.Construction.sideTolerance", 
    11831188          optFloat, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r362 r367  
    351351                                               Polygon3 &back_piece) const 
    352352{ 
     353        if (mPiercingRays.empty()) 
     354                return; 
     355 
    353356        RayContainer::const_iterator it,  
    354357                it_end = mPiercingRays.end(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp

    r366 r367  
    195195 
    196196 
    197 void Ray::Insert(const BspIntersection &bspi) 
    198 { 
    199         vector<BspIntersection>::iterator it; 
    200  
    201         while (it != 
    202 } 
    203  
    204197ostream & 
    205198operator<<(ostream &s, const PassingRaySet &set) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h

    r366 r367  
    5555     
    5656  }; 
    57    
    58   struct BspIntersection 
    59   { 
    60           float mT; 
    61           BspLeaf *leaf; 
    62           BspIntersection(float t, BspLeaf *l): mT(t), leaf(l) 
    63           {} 
    64  
    65           bool operator<(const BspIntersection &b) const  
    66           { 
    67                   return mT     < b.mT; 
    68           } 
    69   }; 
     57 
    7058 
    7159  // I should have some abstract cell data type !!! here 
     
    7563   
    7664  vector<Intersection> intersections; 
    77   vector<BspIntersection> bspIntersections; 
     65  vector<BspLeaf *> bspLeaves; 
    7866  vector<KdLeaf *> kdLeaves; 
    7967  vector<MeshInstance *> meshes; 
     
    210198  int ClassifyPlane(const Plane3 &plane, const float minT, const float maxT) const; 
    211199 
    212   void Insert(const BspIntersection &bspi); 
    213  
    214200private: 
    215201  Vector3 loc, dir;             // Describes ray origin and vector 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r366 r367  
    1414  environment->GetIntValue("Sampling.totalSamples", mTotalSamples); 
    1515  environment->GetIntValue("BspTree.Construction.samples", mBspConstructionSamples); 
    16  
     16  environment->GetIntValue("BspTree.PostProcessing.samples", mPostProcessSamples); 
    1717  mKdPvsDepth = 100; 
    1818  mStats.open("stats.log"); 
     
    121121                for (j=1; j < ((int)ray.bspLeaves.size() - 1); ++ j)  
    122122                { 
    123                         BspLeaf *leaf = ray.bspIntersections.leaf; 
     123                        BspLeaf *leaf = ray.bspLeaves[j]; 
    124124 
    125125                        if (leaf->GetViewCell() != &mUnbounded) 
     
    380380                 
    381381                int reverseSamples = 0; 
    382                 bool collectSamplesForBsp =  
    383                         (ViewCell::sHierarchy == ViewCell::BSP) && 
    384                         (BspTree::sConstructionMethod == BspTree::FROM_RAYS) && 
    385                         (totalSamples < mBspConstructionSamples); 
     382                 
    386383                         
    387384                //cout << "totalSamples: "  << totalSamples << endl; 
     
    457454                                        if (ViewCell::sHierarchy == ViewCell::BSP)  
    458455                                        { 
    459                                                 ProcessBspViewCells(collectSamplesForBsp, 
    460                                                                                         ray, 
     456                                                ProcessBspViewCells(ray, 
    461457                                                                                        object, 
    462458                                                                                        faceIndex, 
     
    523519        if (mBspTree) 
    524520        { 
    525                 cout << "starting post processing ... "; 
     521                cout << "starting post processing using " << mSampleRays.size() << " samples ... "; 
    526522 
    527523                Debug << "original pvs size: " << mBspTree->CountViewCellPvs() << endl; 
     
    620616} 
    621617 
    622 bool SamplingPreprocessor::ProcessBspViewCells(bool collectSamplesForBsp, 
    623                                                                                            Ray &ray, 
     618bool SamplingPreprocessor::ProcessBspViewCells(Ray &ray, 
    624619                                                                                           Intersectable *object, 
    625620                                                                                           int faceIndex, 
     
    628623{ 
    629624        // save rays for bsp tree construction 
    630         if (collectSamplesForBsp) 
     625        if ((BspTree::sConstructionMethod == BspTree::FROM_RAYS) && 
     626                (mSampleRays.size() < mBspConstructionSamples)) 
    631627        { 
    632628                // also add origin to sample in order to extract it as input polygons 
     
    639635        } 
    640636         
    641         // construct BSP tree using the samples 
    642         if (!mBspTree) 
     637        if (!mBspTree) // construct BSP tree using the samples 
    643638        { 
     639        cout << "building bsp tree from " << mSampleRays.size() << " samples " << endl; 
    644640                BuildBspTree(); 
    645641                 
     642                // add contributions of saved samples to PVS 
    646643                contributingSamples += mBspTree->GetStat().contributingSamples; 
    647644                sampleContributions += mBspTree->GetStat().sampleContributions; 
    648645 
    649646                BspTreeStatistics(Debug);        
     647 
    650648                if (0) Export("vc_bsptree.x3d", false, false, true); 
     649 
     650                // throw away samples because BSP leaves not stored in order  
     651                // Need ordered rays for post processing => collect new rays 
     652                CLEAR_CONTAINER(mSampleRays); 
     653        } 
     654         
     655        if ((int)mSampleRays.size() < mPostProcessSamples) 
     656        { 
     657                mSampleRays.push_back(new Ray(ray)); 
    651658        } 
    652659 
     
    676683                { 
    677684                        BspLeaf *leaf = *lit; 
     685 
    678686                        if (mBspTree->ShouldMerge(leaf, previousLeaf)) 
    679687                        {                        
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h

    r362 r367  
    2525  RayContainer mSampleRays; 
    2626  int mBspConstructionSamples; 
    27  
     27  int mPostProcessSamples; 
    2828         
    2929  SamplingPreprocessor(); 
     
    6565 
    6666        /** Processes the BSP based view cells during a pass. 
    67                 @param collectSamplesForBps if still in sample collection phase 
     67                 
    6868                @param ray the current ray 
    6969                @param object the currently processed object 
     
    7575 
    7676        */ 
    77         bool ProcessBspViewCells(bool collectSamplesForBsp, 
    78                                                          Ray &ray, 
     77        bool ProcessBspViewCells(Ray &ray, 
    7978                                                         Intersectable *object, 
    8079                                                         int faceIndex, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r366 r367  
    4141float BspTree::sLeastRaySplitsFactor = 1.0f; 
    4242float BspTree::sBalancedRaysFactor = 1.0f; 
     43float BspTree::sPvsFactor = 1.0f; 
    4344 
    4445bool BspTree::sStoreSplitPolys = false; 
     
    194195 
    195196                // classify polygon 
    196                 const int classification = poly->ClassifyPlane(mPlane); 
     197                const int cf = poly->ClassifyPlane(mPlane); 
    197198 
    198199                Polygon3 *front_piece = NULL; 
     
    201202                VertexContainer splitVertices; 
    202203 
    203                 switch (classification) 
     204                switch (cf) 
    204205                { 
    205206                        case Polygon3::COINCIDENT: 
     
    224225                                ++ splits; // increase number of splits 
    225226 
    226                                 //-- inherit rays from parent polygon 
     227                                //-- inherit rays from parent polygon for blocked ray criterium 
    227228                                poly->InheritRays(*front_piece, *back_piece); 
    228229                                //Debug << "p: " << poly->mPiercingRays.size() << " f: " << front_piece->mPiercingRays.size() << " b: " << back_piece->mPiercingRays.size() << endl; 
     
    291292void BspLeaf::GenerateViewCell(const BoundedRayContainer &rays,  
    292293                                                           int &sampleContributions, 
    293                                                            int &contributingSamples, 
    294                                                            const bool storeRays) 
     294                                                           int &contributingSamples) 
    295295{ 
    296296        sampleContributions = 0; 
     
    321321                } 
    322322 
    323                 ray->bspIntersections.push_back(BspIntersection(this, (*it)->mMinT); 
    324  
    325                 if (storeRays) 
    326                         mViewCell->mPiercingRays.push_back(ray); 
     323                ray->bspLeaves.push_back(this); 
    327324        } 
    328325} 
     
    628625                        if (it != facePolyMap.end())  
    629626                        { 
    630                                 (*it).second->mPiercingRays.push_back(ray); 
     627                                //store rays if needed for heuristics 
     628                                if (sSplitPlaneStrategy & BLOCKED_RAYS) 
     629                                        (*it).second->mPiercingRays.push_back(ray); 
    631630                        }  
    632631                        else 
    633                         { 
     632                        {       //store rays if needed for heuristics 
    634633                                Polygon3 *poly = new Polygon3(face, obj->GetMesh()); 
    635634                                poly->mParent = obj; 
    636635                                polys->push_back(poly); 
    637                                 poly->mPiercingRays.push_back(ray); 
     636 
     637                                if (sSplitPlaneStrategy & BLOCKED_RAYS) 
     638                                        poly->mPiercingRays.push_back(ray); 
    638639 
    639640                                facePolyMap[face] = poly; 
     
    642643        } 
    643644         
     645        facePolyMap.clear(); 
     646 
     647        // compue bounding box 
    644648        Polygon3::IncludeInBox(*polys, mBox); 
    645649 
     
    848852         
    849853        // subdivide polygons with plane 
    850         mStat.splits +=  
    851                 interior->SplitPolygons(polys, frontPolys, backPolys,  
    852                                                                 coincident, sStoreSplitPolys); 
     854        mStat.splits += interior->SplitPolygons(polys,  
     855                                                    frontPolys,  
     856                                                                                        backPolys,  
     857                                                                                        coincident,  
     858                                                                                        sStoreSplitPolys); 
    853859 
    854860        BspInterior *parent = leaf->GetParent(); 
     
    12471253        float sumRaySplits = 0; 
    12481254        float pvsSize = 0; 
    1249  
     1255        float totalSize = 0; 
     1256 
     1257        // need three unique ids for small pvs criterium 
    12501258        Intersectable::NewMail(); 
     1259        const int backId = ViewCell::sMailId; 
     1260        Intersectable::NewMail(); 
     1261        const int frontId = ViewCell::sMailId; 
     1262        Intersectable::NewMail(); 
     1263        const int frontAndBackId = ViewCell::sMailId; 
     1264        //Debug << "f " << frontId <<  " b " << backId << " fb " << frontAndBackId << endl; 
    12511265 
    12521266        BoundedRayContainer::const_iterator rit, rit_end = rays.end(); 
     
    12581272                const float maxT = (*rit)->mMaxT; 
    12591273 
    1260                 const int classification =  
     1274                const int cf =  
    12611275                        ray->ClassifyPlane(candidatePlane, minT, maxT); 
    12621276 
    12631277                if (sSplitPlaneStrategy & LEAST_RAY_SPLITS) 
    12641278                { 
    1265                         sumBalancedRays += sBalancedRaysTable[classification]; 
     1279                        sumBalancedRays += sBalancedRaysTable[cf]; 
    12661280                } 
    12671281                 
    12681282                if (sSplitPlaneStrategy & BALANCED_RAYS) 
    12691283                { 
    1270                         sumRaySplits += sLeastRaySplitsTable[classification]; 
     1284                        sumRaySplits += sLeastRaySplitsTable[cf]; 
    12711285                } 
    12721286 
     
    12761290                                it_end = ray->intersections.end(); 
    12771291 
    1278                         for (it = ray->intersections.begin(); it != it_end; ++ it) 
     1292                        if (!ray->intersections.empty()) 
    12791293                        { 
    1280                                 if (!(*it).mObject->Mailed()) 
    1281                                 { 
    1282                                         (*it).mObject->Mail(); 
    1283                                 } 
     1294 
     1295                                // assure that we only count a object  
     1296                                // once for the front and once for the back side of the plane 
     1297                                pvsSize += PvsValue(*ray->intersections[0].mObject,  
     1298                                                                        cf,  
     1299                                                                        frontId,  
     1300                                                                        backId,  
     1301                                                                        frontAndBackId); 
     1302 
     1303                                // always add 2 for each object (= maximal large PVS) 
     1304                                //if (inc > 0.01)       totalSize += 2.0; 
    12841305                        } 
     1306                        //todo emerging obj 
    12851307                } 
    12861308        } 
     
    12941316                        val += sBalancedRaysFactor * fabs(sumBalancedRays) / (float)rays.size(); 
    12951317 
     1318        if (sSplitPlaneStrategy & PVS) 
     1319                if (!rays.empty()) // HACK (should be maximal possible pvs) 
     1320                        val += sPvsFactor * pvsSize / (float)rays.size();  
     1321 
     1322        //Debug << "pvs: " << pvsSize << " val " << val << endl; 
    12961323        return val; 
     1324} 
     1325 
     1326 
     1327float BspTree::PvsValue(Intersectable &obj,  
     1328                                            const int cf,  
     1329                                            const int frontId,  
     1330                                            const int backId,  
     1331                                            const int frontAndBackId) const 
     1332{ 
     1333        float pvsVal = 0; 
     1334 
     1335        if (cf == Ray::COINCIDENT) 
     1336                return pvsVal; 
     1337 
     1338        if (cf == Ray::FRONT) 
     1339        { 
     1340                if ((obj.mMailbox != frontId) &&  
     1341                        (obj.mMailbox != frontAndBackId)) 
     1342                        pvsVal = 1.0; 
     1343 
     1344                if (obj.mMailbox != backId) 
     1345                        obj.mMailbox = frontId; 
     1346                else 
     1347                        obj.mMailbox = frontAndBackId;                                   
     1348        } 
     1349        else if (cf == Ray::BACK) 
     1350        { 
     1351                if ((obj.mMailbox != backId) && 
     1352                        (obj.mMailbox != frontAndBackId)) 
     1353                { 
     1354                        pvsVal = 1.0; 
     1355 
     1356                        if (obj.mMailbox != frontId) 
     1357                                obj.mMailbox = backId; 
     1358                        else 
     1359                                obj.mMailbox = frontAndBackId;  
     1360                } 
     1361        } 
     1362        else if ((cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 
     1363        { 
     1364                if ((obj.mMailbox == backId) || (obj.mMailbox == frontId)) 
     1365                        pvsVal = 1.0; 
     1366                else if (obj.mMailbox != frontAndBackId) 
     1367                        pvsVal = 2.0; 
     1368                         
     1369                obj.mMailbox = frontAndBackId; 
     1370        } 
     1371 
     1372        return pvsVal; 
    12971373} 
    12981374 
     
    13241400        // the following criteria loop over all rays to find the cost value 
    13251401        if ((sSplitPlaneStrategy & BALANCED_RAYS)      || 
    1326                 (sSplitPlaneStrategy & LEAST_RAY_SPLITS)) 
     1402                (sSplitPlaneStrategy & LEAST_RAY_SPLITS)   || 
     1403                (sSplitPlaneStrategy & PVS)) 
    13271404        { 
    13281405                val += SplitPlaneCost(candidatePlane, rays); 
     
    14031480        if (sSplitPlaneStrategy & BLOCKED_RAYS) 
    14041481                Debug << "blocked rays "; 
    1405  
     1482        if (sSplitPlaneStrategy & PVS) 
     1483                Debug << "pvs"; 
    14061484        Debug << endl; 
    14071485} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r366 r367  
    194194                @param coincident returns the polygons coincident to the split plane 
    195195                @param storePolys if the polygons should be stored in the node 
     196                 
    196197                @returns the number of splits    
    197198        */ 
     
    250251                @param sampleContributions the number contributions of the sampels 
    251252                @param contributingSampels the number of contributing rays 
    252                 @param storeRays if ray set should be stored in view cell 
     253                 
    253254        */ 
    254255        void GenerateViewCell(const BoundedRayContainer &rays,  
    255256                                              int &sampleContributions, 
    256                                                   int &contributingSamples, 
    257                                                   const bool storeRays = false); 
     257                                                  int &contributingSamples); 
    258258 
    259259protected: 
     
    657657 
    658658        int CountPvs(const BoundedRayContainer &rays) const; 
     659         
     660        float PvsValue(Intersectable &obj,  
     661                                   const int cf,  
     662                                   const int frontId,  
     663                                   const int backId,  
     664                                   const int frontAndBackId) const; 
     665         
    659666        /// Pointer to the root of the tree 
    660667        BspNode *mRoot; 
     
    729736        static float sLeastRaySplitsFactor; 
    730737        static float sBalancedRaysFactor; 
     738        static float sPvsFactor; 
    731739 
    732740        /// if polygons should be stored in the tree 
Note: See TracChangeset for help on using the changeset viewer.