Changeset 478


Ignore:
Timestamp:
12/22/05 18:32:39 (18 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
12 edited

Legend:

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

    r475 r478  
    1313#;../data/vienna/vienna-plane.x3d 
    1414#       filename ../data/vienna/viewcells-25-sel.x3d 
    15 #       filename ../data/atlanta/atlanta2.x3d 
     15        filename ../data/atlanta/atlanta2.x3d 
    1616#       filename ../data/soda/soda.dat 
    17         filename ../data/soda/soda5.dat 
     17#       filename ../data/soda/soda5.dat 
    1818} 
    1919 
     
    155155        maxViewCells 100 
    156156         
    157         PostProcessing { 
     157        PostProcess { 
    158158                minPvsDif 100 
    159159                minPvs 10 
     
    240240         
    241241        # maximal tested rays for split cost heuristics 
    242         maxTests 1000 
     242        maxTests 10000 
    243243         
    244244        # factors for evaluating split plane costs 
     
    261261                #maxAccRayLength        100 
    262262                 
     263                maxViewCells            1500 
     264                 
    263265                # used for pvs criterium 
    264266                ct_div_ci 0.0 
     
    283285                exportRays true 
    284286                exportGeometry false 
     287        } 
     288         
     289        PostProcess { 
     290                maxCostRatio 5000000 
     291                minViewCells 1000 
     292                maxPvsSize   50000 
    285293        } 
    286294} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r473 r478  
    11871187                 "bspTree"); 
    11881188 
    1189   RegisterOption("ViewCells.PostProcessing.samples", 
     1189  RegisterOption("ViewCells.PostProcess.samples", 
    11901190          optInt, 
    1191           "-bsp_postprocessing_samples=", 
     1191          "-view_cells_postprocess_samples=", 
    11921192          "200000"); 
    11931193 
     
    12071207                 "0"); 
    12081208 
    1209   RegisterOption("ViewCells.PostProcessing.minPvsDif", 
     1209  RegisterOption("ViewCells.PostProcess.minPvsDif", 
    12101210                 optInt, 
    1211                  "-view_cells_post_processing_min_pvs_dif", 
     1211                 "-view_cells_post_process_min_pvs_dif", 
    12121212                 "10"); 
    12131213 
    1214   RegisterOption("ViewCells.PostProcessing.maxPvs", 
     1214  RegisterOption("ViewCells.PostProcess.maxPvs", 
    12151215                 optInt, 
    1216                  "-view_cells_post_processing_max_pvs", 
     1216                 "-view_cells_post_process_max_pvs", 
    12171217                 "300"); 
    12181218 
    1219   RegisterOption("ViewCells.PostProcessing.minPvs", 
     1219  RegisterOption("ViewCells.PostProcess.minPvs", 
    12201220                 optString, 
    1221                  "-view_cells_post_processing_min_pvs", 
     1221                 "-view_cells_post_process_min_pvs", 
    12221222                 "10"); 
    12231223 
     
    16671667                        "1.5"); 
    16681668 
     1669        RegisterOption("VspBspTree.Termination.maxViewCells", 
     1670                        optInt, 
     1671                        "-vsp_bsp_term_axis_aligned_max_view_cells=", 
     1672                        "1000"); 
     1673 
    16691674        RegisterOption("VspBspTree.Termination.maxCostRatio", 
    16701675                optFloat, 
     
    17501755        RegisterOption("VspBspTree.Factor.pvs", optFloat, "-vsp_bsp_factor_pvs=", "1.0"); 
    17511756 
     1757        RegisterOption("VspBspTree.PostProcess.maxCostRatio", 
     1758                        optFloat, 
     1759                        "-vsp_bsp_post_process_max_cost_ratio=", 
     1760                        "1.5"); 
     1761 
     1762        RegisterOption("VspBspTree.PostProcess.minViewCells",  
     1763                optInt,  
     1764                "vsp_bsp_term_post_process_min_view_cells=",  
     1765                "1000"); 
     1766 
     1767        RegisterOption("VspBspTree.PostProcess.maxPvsSize",  
     1768                optInt,  
     1769                "vsp_bsp_term_post_process_max_pvs_size=",  
     1770                "100"); 
     1771         
    17521772        ////////////////////////////////////////////////////////////////////////////////// 
    17531773} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r475 r478  
    231231        int visSamples = 0; 
    232232 
    233         environment->GetIntValue("ViewCells.PostProcessing.samples", postProcessSamples); 
     233        environment->GetIntValue("ViewCells.PostProcess.samples", postProcessSamples); 
    234234        environment->GetIntValue("ViewCells.Visualization.samples", visSamples); 
    235235 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r469 r478  
    77#include <iomanip> 
    88 
    9 ViewCell::ViewCell(): MeshInstance(NULL), mPiercingRays(0) 
     9ViewCell::ViewCell():  
     10MeshInstance(NULL),  
     11mPiercingRays(0), 
     12mArea(0), 
     13mVolume(0) 
    1014{ 
    1115} 
    1216 
    13 ViewCell::ViewCell(Mesh *mesh): MeshInstance(mesh), mPiercingRays(0) 
     17ViewCell::ViewCell(Mesh *mesh):  
     18MeshInstance(mesh),  
     19mPiercingRays(0), 
     20mArea(0), 
     21mVolume(0) 
    1422{ 
    1523} 
     
    3543} 
    3644 
     45 
    3746float ViewCell::GetVolume() const 
    3847{ 
     
    4049} 
    4150 
     51 
    4252void ViewCell::SetVolume(float volume)  
    4353{ 
    4454        mVolume = volume; 
    4555} 
     56 
     57 
     58float ViewCell::GetArea() const 
     59{ 
     60        return mArea; 
     61} 
     62 
     63 
     64void ViewCell::SetArea(float area)  
     65{ 
     66        mArea = area; 
     67} 
     68 
    4669 
    4770/************************************************************************/ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h

    r471 r478  
    4545        /** Returns volume of the view cell. 
    4646        */ 
    47         virtual float GetVolume() const; 
     47        float GetVolume() const; 
    4848 
    49         /** Sets volume of the view cell. 
     49        /** Returns area of the view cell. 
    5050        */ 
    51         void SetVolume(float size); 
     51        float GetArea() const; 
     52 
     53        /** Sets the volume of the view cell. 
     54        */ 
     55        void SetVolume(float volume); 
     56         
     57        /** Sets the area of the view cell. 
     58        */ 
     59        void SetArea(float area); 
    5260 
    5361        /// Ray set description of the rays passing through this node. 
     
    6371 
    6472        float mVolume; 
     73        float mArea; 
    6574}; 
    6675 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r475 r478  
    11481148        if (!data.mPolygons->empty()) 
    11491149                { 
    1150                         Polygon3 *nextPoly = (*data.mPolygons)[(int)RandomValue(0, (int)data.mPolygons->size() - 1)]; 
     1150                        Polygon3 *nextPoly =  
     1151                                (*data.mPolygons)[(int)RandomValue(0, (Real)((int)data.mPolygons->size() - 1))]; 
    11511152                        return nextPoly->GetSupportingPlane(); 
    11521153                } 
     
    11751176} 
    11761177 
     1178 
     1179Plane3 BspTree::ChooseCandidatePlane(const BoundedRayContainer &rays) const 
     1180{       return Plane3(); 
     1181        /*const int candidateIdx = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 
     1182         
     1183        const Vector3 minPt = rays[candidateIdx].ExtrapOrigin(); 
     1184        const Vector3 maxPt = rays[candidateIdx].ExtrapTermination(); 
     1185 
     1186        const Vector3 pt = (maxPt + minPt) * 0.5; 
     1187        const Vector3 normal = Normalize(rays[candidateIdx].mRay->GetDir()); 
     1188 
     1189        return Plane3(normal, pt);*/ 
     1190} 
     1191 
     1192Plane3 BspTree::ChooseCandidatePlane2(const BoundedRayContainer &rays) const 
     1193{       return Plane3(); 
     1194        /*Vector3 pt[3]; 
     1195         
     1196        int idx[3]; 
     1197        int cmaxT = 0; 
     1198        int cminT = 0; 
     1199        bool chooseMin = false; 
     1200 
     1201        for (int j = 0; j < 3; ++ j) 
     1202        { 
     1203                idx[j] = (int)RandomValue(0, (Real)((int)rays.size() * 2 - 1)); 
     1204                         
     1205                if (idx[j] >= (int)rays.size()) 
     1206                { 
     1207                        idx[j] -= (int)rays.size(); 
     1208                                 
     1209                        chooseMin = (cminT < 2); 
     1210                } 
     1211                else 
     1212                        chooseMin = (cmaxT < 2); 
     1213 
     1214                RayInfo rayInf = rays[idx[j]]; 
     1215                pt[j] = chooseMin ? rayInf.ExtrapOrigin() : rayInf.ExtrapTermination(); 
     1216        }        
     1217 
     1218        return Plane3(pt[0], pt[1], pt[2]);*/ 
     1219} 
     1220 
     1221Plane3 BspTree::ChooseCandidatePlane3(const BoundedRayContainer &rays) const 
     1222{       return Plane3();/* 
     1223        Vector3 pt[3]; 
     1224         
     1225        int idx1 = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 
     1226        int idx2 = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 
     1227 
     1228        // check if rays different 
     1229        if (idx1 == idx2) 
     1230                idx2 = (idx2 + 1) % (int)rays.size(); 
     1231 
     1232        const RayInfo ray1 = rays[idx1]; 
     1233        const RayInfo ray2 = rays[idx2]; 
     1234 
     1235        // normal vector of the plane parallel to both lines 
     1236        const Vector3 norm = Normalize(CrossProd(ray1.mRay->GetDir(), ray2.mRay->GetDir())); 
     1237 
     1238        // vector from line 1 to line 2 
     1239        const Vector3 vd = (ray2.ExtrapOrigin() - ray1.ExtrapOrigin()); 
     1240         
     1241        // project vector on normal to get distance 
     1242        const float dist = DotProd(vd, norm); 
     1243 
     1244        // point on plane lies halfway between the two planes 
     1245        const Vector3 planePt = ray1.ExtrapOrigin() + norm * dist * 0.5; 
     1246 
     1247        return Plane3(norm, planePt);*/ 
     1248} 
     1249 
     1250 
    11771251Plane3 BspTree::SelectPlaneHeuristics(BspLeaf *leaf, BspTraversalData &data) 
    11781252{ 
    11791253        float lowestCost = MAX_FLOAT; 
    11801254        Plane3 bestPlane; 
     1255        // intermediate plane 
    11811256        Plane3 plane; 
    11821257 
    1183         int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 
    1184          
    1185         int candidateIdx = limit - 1; 
    1186  
     1258        const int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 
     1259        int maxIdx = (int)data.mPolygons->size(); 
     1260         
    11871261        for (int i = 0; i < limit; ++ i) 
    11881262        { 
    1189                 candidateIdx = GetNextCandidateIdx(candidateIdx, *data.mPolygons); 
     1263                // assure that no index is taken twice 
     1264                const int candidateIdx = (int)RandomValue(0, (Real)(-- maxIdx)); 
     1265                //Debug << "current Idx: " << maxIdx << " cand idx " << candidateIdx << endl; 
    11901266                 
    11911267                Polygon3 *poly = (*data.mPolygons)[candidateIdx]; 
     1268 
     1269                // swap candidate to the end to avoid testing same plane 
     1270                std::swap((*data.mPolygons)[maxIdx], (*data.mPolygons)[candidateIdx]); 
     1271         
     1272                //Polygon3 *poly = (*data.mPolygons)[(int)RandomValue(0, (int)polys.size() - 1)]; 
     1273 
    11921274                // evaluate current candidate 
    11931275                const float candidateCost =  
     
    12011283        } 
    12021284         
    1203         //Debug << "lowest: " << lowestCost << endl; 
    1204  
    12051285        //-- choose candidate planes extracted from rays 
    1206         // we currently use two methods 
    1207         // 1) take 3 ray endpoints, where two are minimum and one a maximum 
    1208         //    point or the other way round 
    1209         // 2) take plane normal as plane normal and the midpoint of the ray. 
    1210         //    PROBLEM: does not resemble any point where visibility is likely to change 
    1211         const BoundedRayContainer *rays = data.mRays; 
    1212  
    1213         for (int i = 0; i < mMaxRayCandidates / 2; ++ i) 
    1214         { 
    1215                 candidateIdx = (int)RandomValue(0, (int)rays->size() - 1); 
    1216                 BoundedRay *bRay = (*rays)[candidateIdx]; 
    1217  
    1218                 Ray *ray = bRay->mRay; 
    1219                                                  
    1220                 const Vector3 minPt = ray->Extrap(bRay->mMinT); 
    1221                 const Vector3 maxPt = ray->Extrap(bRay->mMaxT); 
    1222  
    1223                 const Vector3 pt = (maxPt + minPt) * 0.5; 
    1224  
    1225                 const Vector3 normal = ray->GetDir(); 
    1226                          
    1227                 plane = Plane3(normal, pt); 
    1228          
     1286        //-- different methods are available 
     1287        for (int i = 0; i < mMaxRayCandidates; ++ i) 
     1288        { 
     1289                plane = ChooseCandidatePlane3(*data.mRays); 
    12291290                const float candidateCost = SplitPlaneCost(plane, data); 
    12301291 
    12311292                if (candidateCost < lowestCost) 
    12321293                { 
    1233                         bestPlane = plane; 
    1234                          
     1294                        bestPlane = plane;       
    12351295                        lowestCost = candidateCost; 
    12361296                } 
    12371297        } 
    1238  
    1239         //Debug << "lowest: " << lowestCost << endl; 
    1240         for (int i = 0; i < mMaxRayCandidates / 2; ++ i) 
    1241         { 
    1242                 Vector3 pt[3]; 
    1243                 int idx[3]; 
    1244                 int cmaxT = 0; 
    1245                 int cminT = 0; 
    1246                 bool chooseMin = false; 
    1247  
    1248                 for (int j = 0; j < 3; j ++) 
    1249                 { 
    1250                         idx[j] = (int)RandomValue(0, (int)rays->size() * 2 - 1); 
    1251                                  
    1252                         if (idx[j] >= (int)rays->size()) 
    1253                         { 
    1254                                 idx[j] -= (int)rays->size(); 
    1255                                  
    1256                                 chooseMin = (cminT < 2); 
    1257                         } 
    1258                         else 
    1259                                 chooseMin = (cmaxT < 2); 
    1260  
    1261                         BoundedRay *bRay = (*rays)[idx[j]]; 
    1262                         pt[j] = chooseMin ? bRay->mRay->Extrap(bRay->mMinT) :  
    1263                                                                 bRay->mRay->Extrap(bRay->mMaxT); 
    1264                 }        
    1265                          
    1266                 plane = Plane3(pt[0], pt[1], pt[2]); 
    1267  
    1268                 const float candidateCost = SplitPlaneCost(plane, data); 
    1269  
    1270                 if (candidateCost < lowestCost) 
    1271                 { 
    1272                         //Debug << "choose ray plane 2: " << candidateCost << endl; 
    1273                         bestPlane = plane; 
    1274                          
    1275                         lowestCost = candidateCost; 
    1276                 } 
    1277         }        
    12781298 
    12791299#ifdef _DEBUG 
    12801300        Debug << "plane lowest cost: " << lowestCost << endl; 
    12811301#endif 
     1302 
    12821303        return bestPlane; 
    12831304} 
    12841305 
    1285 int BspTree::GetNextCandidateIdx(int currentIdx, PolygonContainer &polys) 
    1286 { 
    1287         const int candidateIdx = (int)RandomValue(0, currentIdx --); 
    1288  
    1289         // swap candidates to avoid testing same plane 2 times 
    1290         std::swap(polys[currentIdx], polys[candidateIdx]); 
    1291          
    1292         return currentIdx; 
    1293         //return (int)RandomValue(0, (int)polys.size() - 1); 
    1294 } 
    12951306 
    12961307float BspTree::SplitPlaneCost(const Plane3 &candidatePlane,  
     
    13311342                limit = (int)polys.size(); 
    13321343        } 
    1333          
    13341344 
    13351345        for (int i = 0; i < limit; ++ i) 
    13361346        { 
    1337                 const int testIdx = useRand ? (int)RandomValue(0, limit - 1) : i; 
     1347                const int testIdx = useRand ? (int)RandomValue(0, (Real)(limit - 1)) : i; 
    13381348 
    13391349                Polygon3 *poly = polys[testIdx]; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r475 r478  
    586586                                                PolygonContainer *backPolys); 
    587587 
     588        /** Take 3 ray endpoints, where two are minimum and one a maximum 
     589                point or the other way round. 
     590        */ 
     591        Plane3 ChooseCandidatePlane(const BoundedRayContainer &rays) const; 
     592 
     593        /** Take plane normal as plane normal and the midpoint of the ray. 
     594                PROBLEM: does not resemble any point where visibility is likely to change 
     595        */ 
     596        Plane3 ChooseCandidatePlane2(const BoundedRayContainer &rays) const; 
     597 
     598        /** Fit the plane between the two lines so that the plane has equal shortest  
     599                distance to both lines. 
     600        */ 
     601        Plane3 ChooseCandidatePlane3(const BoundedRayContainer &rays) const; 
     602 
    588603        /** Selects the split plane in order to construct a tree with 
    589604                certain characteristics (e.g., balanced tree, least splits,  
     
    619634        */ 
    620635        int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent); 
    621  
    622         /** returns next candidate index and reorders polygons so no candidate is chosen two times 
    623                 @param the current candidate index 
    624                 @param max the range of candidates 
    625         */ 
    626         int GetNextCandidateIdx(int currentIdx, PolygonContainer &polys); 
    627636 
    628637        /** Helper function which extracts a view cell on the front and the back 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r477 r478  
    2222{ 
    2323        // post processing stuff 
    24         environment->GetIntValue("ViewCells.PostProcessing.minPvsDif", mMinPvsDif); 
    25         environment->GetIntValue("ViewCells.PostProcessing.minPvs", mMinPvs); 
    26         environment->GetIntValue("ViewCells.PostProcessing.maxPvs", mMaxPvs); 
     24        environment->GetIntValue("ViewCells.PostProcess.minPvsDif", mMinPvsDif); 
     25        environment->GetIntValue("ViewCells.PostProcess.minPvs", mMinPvs); 
     26        environment->GetIntValue("ViewCells.PostProcess.maxPvs", mMaxPvs); 
    2727} 
    2828 
     
    3434{ 
    3535        // post processing stuff 
    36         environment->GetIntValue("ViewCells.PostProcessing.minPvsDif", mMinPvsDif); 
    37         environment->GetIntValue("ViewCells.PostProcessing.minPvs", mMinPvs); 
    38         environment->GetIntValue("ViewCells.PostProcessing.maxPvs", mMaxPvs); 
     36        environment->GetIntValue("ViewCells.PostProcess.minPvsDif", mMinPvsDif); 
     37        environment->GetIntValue("ViewCells.PostProcess.minPvs", mMinPvs); 
     38        environment->GetIntValue("ViewCells.PostProcess.maxPvs", mMaxPvs); 
    3939} 
    4040 
     
    7575{ 
    7676        mViewCells.push_back(viewCell); 
     77} 
     78 
     79float ViewCellsManager::GetArea(ViewCell *viewCell) const 
     80{ 
     81        return viewCell->GetArea(); 
     82} 
     83 
     84 
     85float ViewCellsManager::GetVolume(ViewCell *viewCell) const 
     86{ 
     87        return viewCell->GetVolume(); 
    7788} 
    7889 
     
    282293 
    283294 
    284 float ViewCellsManager::GetVolume(ViewCell *viewCell) const 
    285 { 
    286         return viewCell->GetVolume(); 
    287 } 
    288  
    289  
    290 float ViewCellsManager::GetArea(ViewCell *viewCell) const 
    291 { 
    292         return 0.0f; 
    293 } 
    294  
    295  
    296295float ViewCellsManager::GetAccVcArea() 
    297296{ 
     
    390389 
    391390        return sampleContributions; 
    392 } 
    393  
    394 float BspViewCellsManager::GetArea(ViewCell *viewCell) const 
    395 { 
    396         PolygonContainer geom; 
    397  
    398         // compute view cell area 
    399         mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(viewCell), geom); 
    400          
    401         const float area = Polygon3::GetArea(geom); 
    402         CLEAR_CONTAINER(geom); 
    403  
    404         return area; 
    405391} 
    406392 
     
    656642        //-- some rays for output 
    657643        const int raysOut = min((int)mBspRays.size(), mVisualizationSamples); 
     644         
    658645        cout << "visualization using " << mVisualizationSamples << " samples" << endl; 
    659646        Debug << "\nOutput view cells: " << endl; 
    660  
    661         if (1) 
    662         { 
    663                 //-- some random view cells and rays for output 
    664                 vector<BspLeaf *> vspBspLeaves; 
    665  
    666                 for (int i = 0; i < leafOut; ++ i) 
    667                         vspBspLeaves.push_back(mBspTree->GetRandomLeaf());       
    668                  
    669                 for (int i = 0; i < (int)vspBspLeaves.size(); ++ i) 
    670                 { 
    671                         VssRayContainer vcRays; 
    672                         cout << "creating output for view cell " << i << " ... "; 
    673  
    674                         // check whether we can add the current ray to the output rays 
    675                         for (int k = 0; k < raysOut; ++ k)  
     647         
     648        // sort view cells to get largest view cells 
     649#if 0 
     650        stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 
     651#endif 
     652        int limit = min(leafOut, (int)mViewCells.size());  
     653                 
     654        for (int i = 0; i < limit; ++ i) 
     655        { 
     656                cout << "creating output for view cell " << i << " ... "; 
     657                VssRayContainer vcRays; 
     658                Intersectable::NewMail(); 
     659#if 0 
     660                BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[i]); 
     661#else 
     662                BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[Random((int)mViewCells.size())]); 
     663#endif 
     664                cout << "creating output for view cell " << i << " ... "; 
     665 
     666#if 0 
     667                // check whether we can add the current ray to the output rays 
     668                for (int k = 0; k < raysOut; ++ k)  
     669                { 
     670                        BspRay *ray = mBspRays[k]; 
     671                        for     (int j = 0; j < (int)ray->intersections.size(); ++ j) 
    676672                        { 
    677                                 BspRay *ray = mBspRays[k]; 
    678  
    679                                 for     (int j = 0; j < (int)ray->intersections.size(); ++ j) 
    680                                 { 
    681                                         BspLeaf *leaf = ray->intersections[j].mLeaf; 
    682  
    683                                         if (vspBspLeaves[i]->GetViewCell() == leaf->GetViewCell())  
    684                                         { 
    685                                                 vcRays.push_back(ray->vssRay); 
    686                                         } 
    687                                 } 
     673                                BspLeaf *leaf = ray->intersections[j].mLeaf; 
     674                                if (vc == leaf->GetViewCell())  
     675                                        vcRays.push_back(ray->vssRay); 
    688676                        } 
    689  
    690                         Intersectable::NewMail(); 
    691  
    692                         BspViewCell *vc = dynamic_cast<BspViewCell *> 
    693                                 (vspBspLeaves[i]->GetViewCell()); 
    694  
    695                         //bspLeaves[j]->Mail(); 
    696                         char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
    697  
    698                         Exporter *exporter = Exporter::GetExporter(s); 
    699                         exporter->SetFilled(); 
    700  
    701                         ObjectPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 
    702  
    703                         exporter->SetWireframe(); 
    704                         //exporter->SetFilled(); 
    705  
    706                         Material m;//= RandomMaterial(); 
    707                         m.mDiffuseColor = RgbColor(0, 1, 0); 
    708                         exporter->SetForcedMaterial(m); 
    709  
    710                         if (vc->GetMesh()) 
    711                                 exporter->ExportViewCell(vc); 
    712                         else 
     677                } 
     678#endif 
     679                //bspLeaves[j]->Mail(); 
     680                char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
     681 
     682                Exporter *exporter = Exporter::GetExporter(s); 
     683                         
     684                exporter->SetWireframe(); 
     685 
     686                Material m;//= RandomMaterial(); 
     687                m.mDiffuseColor = RgbColor(0, 1, 0); 
     688                exporter->SetForcedMaterial(m); 
     689 
     690                if (vc->GetMesh()) 
     691                        exporter->ExportViewCell(vc); 
     692                else 
     693                { 
     694                        PolygonContainer vcGeom; 
     695                         
     696                        //-- export view cell 
     697                        mBspTree->ConstructGeometry(vc, vcGeom); 
     698                        exporter->ExportPolygons(vcGeom); 
     699                        CLEAR_CONTAINER(vcGeom); 
     700                } 
     701                         
     702                Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
     703                          << ", piercing rays=" << (int)vcRays.size() << endl; 
     704 
     705                         
     706                // export rays piercing this view cell 
     707#if 0 
     708                exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 
     709#else 
     710                vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 
     711                for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 
     712                        exporter->ExportRays((*lit)->mVssRays); 
     713#endif 
     714                m.mDiffuseColor = RgbColor(1, 0, 0); 
     715                exporter->SetForcedMaterial(m); 
     716 
     717                ObjectPvsMap::const_iterator it, 
     718                        it_end = vc->GetPvs().mEntries.end(); 
     719 
     720                exporter->SetFilled(); 
     721 
     722                // output PVS of view cell 
     723                for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it)  
     724                { 
     725                        Intersectable *intersect = (*it).first; 
     726 
     727                        if (!intersect->Mailed()) 
    713728                        { 
    714                                 PolygonContainer vcGeom; 
    715  
    716                                 // export view cell geometry 
    717                                 mBspTree->ConstructGeometry(vc, vcGeom); 
    718                                 exporter->ExportPolygons(vcGeom); 
    719                                 CLEAR_CONTAINER(vcGeom); 
    720                         } 
    721  
    722                         Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
    723                                         << ", piercing rays=" << (int)vcRays.size() << endl; 
    724  
    725                         // export rays piercing this view cell 
    726                         if (exportRays) 
    727                         { 
    728                                 //exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 
    729                                 exporter->ExportRays(vspBspLeaves[i]->mVssRays, RgbColor(1, 1, 1)); 
    730                         } 
    731  
    732                         m.mDiffuseColor = RgbColor(0, 1, 1); 
    733                         exporter->SetForcedMaterial(m); 
    734  
    735                         //exporter->SetWireframe(); 
    736                         exporter->SetFilled(); 
    737  
    738                         // output PVS of view cell 
    739                         for (; it != vc->GetPvs().mEntries.end(); ++ it)  
    740                         { 
    741                                 Intersectable *intersect = (*it).first; 
    742                                 if (!intersect->Mailed()) 
    743                                 { 
    744                                         exporter->ExportIntersectable(intersect); 
    745                                         intersect->Mail(); 
    746                                 }                        
    747                         } 
    748                         Debug << "here1 exportgeom: " << exportGeometry << endl; 
    749                         // output rest of the objects 
    750                         if (exportGeometry) 
    751                         { 
    752                                 Material m;//= RandomMaterial(); 
    753                                 m.mDiffuseColor = RgbColor(0, 0, 1); 
     729                                Material m = RandomMaterial(); 
    754730                                exporter->SetForcedMaterial(m); 
    755731 
    756                                 for (int j = 0; j < objects.size(); ++ j) 
    757                                         if (!objects[j]->Mailed()) 
    758                                         { 
    759                                                 exporter->SetForcedMaterial(m); 
    760                                                 exporter->ExportIntersectable(objects[j]); 
    761                                                 objects[j]->Mail(); 
    762                                         } 
    763                         } 
    764                         DEL_PTR(exporter); 
    765                         cout << "finished" << endl; 
    766                 } 
    767         } 
    768         else 
    769         { 
    770                 ViewCellContainer viewCells; 
    771  
    772                 mBspTree->CollectViewCells(viewCells); 
    773                 stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 
    774  
    775                 int limit = min(leafOut, (int)viewCells.size());  
    776                  
    777                 for (int i = 0; i < limit; ++ i) 
    778                 { 
    779                         cout << "creating output for view cell " << i << " ... "; 
    780                         VssRayContainer vcRays; 
    781             Intersectable::NewMail(); 
    782                         BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]); 
    783  
    784                         cout << "creating output for view cell " << i << " ... "; 
    785  
    786                         // check whether we can add the current ray to the output rays 
    787                         for (int k = 0; k < raysOut; ++ k)  
    788                         { 
    789                                 BspRay *ray = mBspRays[k]; 
    790  
    791                                 for     (int j = 0; j < (int)ray->intersections.size(); ++ j) 
    792                                 { 
    793                                         BspLeaf *leaf = ray->intersections[j].mLeaf; 
    794  
    795                                         if (vc == leaf->GetViewCell())  
    796                                         { 
    797                                                 vcRays.push_back(ray->vssRay); 
    798                                         } 
    799                                 } 
    800                         } 
    801  
    802                         //bspLeaves[j]->Mail(); 
    803                         char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
    804  
    805                         Exporter *exporter = Exporter::GetExporter(s); 
    806                          
    807                         exporter->SetWireframe(); 
    808  
    809                         Material m;//= RandomMaterial(); 
    810                         m.mDiffuseColor = RgbColor(0, 1, 0); 
    811                         exporter->SetForcedMaterial(m); 
    812  
    813                         if (vc->GetMesh()) 
    814                                 exporter->ExportViewCell(vc); 
    815                         else 
    816                         { 
    817                                 PolygonContainer vcGeom; 
    818                                 // export view cell 
    819                                 mBspTree->ConstructGeometry(vc, vcGeom); 
    820                                 exporter->ExportPolygons(vcGeom); 
    821                                 CLEAR_CONTAINER(vcGeom); 
    822                         } 
    823  
    824                          
    825                         Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
    826                                   << ", piercing rays=" << (int)vcRays.size() << endl; 
    827  
    828                          
    829                         // export rays piercing this view cell 
    830                         exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 
    831          
    832                         m.mDiffuseColor = RgbColor(1, 0, 0); 
    833                         exporter->SetForcedMaterial(m); 
    834  
    835                         ObjectPvsMap::const_iterator it, 
    836                                 it_end = vc->GetPvs().mEntries.end(); 
    837  
    838                         // output PVS of view cell 
    839                         for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it)  
    840                         { 
    841                                 Intersectable *intersect = (*it).first; 
    842  
    843                                 if (!intersect->Mailed()) 
    844                                 { 
    845                                         Material m = RandomMaterial(); 
    846                          
    847                                         exporter->SetForcedMaterial(m); 
    848  
    849                                         exporter->ExportIntersectable(intersect); 
    850                                         intersect->Mail(); 
    851                                 }                        
    852                         } 
     732                                exporter->ExportIntersectable(intersect); 
     733                                intersect->Mail(); 
     734                        }                        
     735                } 
    853736                                 
    854                         DEL_PTR(exporter); 
    855                         cout << "finished" << endl; 
    856                 } 
     737                DEL_PTR(exporter); 
     738                cout << "finished" << endl; 
    857739        } 
    858740 
     
    864746{ 
    865747        BspViewCell *viewCell =  
    866                 dynamic_cast<BspViewCell *>(MergeViewCells(*front->GetViewCell(), *back->GetViewCell())); 
     748                dynamic_cast<BspViewCell *>(MergeViewCells(*front->GetViewCell(),  
     749                                                                                                   *back->GetViewCell())); 
    867750         
    868751        if (!viewCell) 
     
    12071090 
    12081091 
    1209  
    12101092/**********************************************************************/ 
    12111093/*                   VspKdViewCellsManager implementation             */ 
     
    14361318mVspBspTree(vspBspTree) 
    14371319{ 
     1320        mVspBspTree->SetViewCellsManager(this); 
    14381321} 
    14391322 
     
    14681351} 
    14691352 
    1470  
    14711353float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell,  
    14721354                                                                                        float objRendercost) const 
     
    15111393        mVspBspTree->CollectViewCells(mViewCells); 
    15121394        mVspBspTree->EvaluateViewCellsStats(mViewCellsStats); 
    1513          
     1395 
    15141396        Debug << mVspBspTree->GetStatistics() << endl; 
    15151397         
     
    15511433                                                                                const VssRayContainer &rays) 
    15521434{ 
     1435        if (!ViewCellsConstructed()) 
     1436        { 
     1437                Debug << "view cells not constructed" << endl; 
     1438                return 0; 
     1439        } 
     1440 
    15531441        if (mBspRays.empty()) 
    15541442                ConstructBspRays(rays, mConstructionSamples); 
    1555          
    1556         if (!ViewCellsConstructed()) 
    1557         { 
    1558                 Debug << "view cells not constructed" << endl; 
    1559                 return 0; 
    1560         } 
    15611443 
    15621444        //-- post processing of bsp view cells 
     
    15751457                        //exporter->SetWireframe(); 
    15761458                        exporter->SetFilled(); 
    1577                         exporter->ExportBspViewCellPartition(*mVspBspTree, mViewCellsStats.maxPvs); 
    1578                                  
     1459                        //exporter->ExportBspViewCellPartition(*mVspBspTree, mViewCellsStats.maxPvs); 
     1460                        exporter->ExportBspViewCellPartition(*mVspBspTree); 
     1461 
    15791462                        if (0) 
    15801463                        { 
     
    16051488        vector<BspIntersection>::const_iterator iit; 
    16061489 
     1490        if (0) 
    16071491        for (int i = 0; i < (int)mBspRays.size(); ++ i) 
    16081492        {   
     
    16331517                } 
    16341518        } 
     1519        else 
     1520        { 
     1521                merged = mVspBspTree->MergeLeaves(); 
     1522        } 
    16351523 
    16361524        //-- stats and visualizations 
     
    16681556        if (1) // export view cells 
    16691557        { 
    1670                 cout << "exporting view cells after merge ... "; 
     1558                cout << "exporting view cells after post process ... "; 
    16711559                Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
    16721560 
    16731561                if (exporter) 
    16741562                { 
    1675                         exporter->ExportBspViewCellPartition(*mVspBspTree, mViewCellsStats.maxPvs); 
     1563                        //exporter->ExportBspViewCellPartition(*mVspBspTree, mViewCellsStats.maxPvs); 
     1564                        exporter->ExportBspViewCellPartition(*mVspBspTree); 
    16761565                        delete exporter; 
    16771566                } 
     
    17511640        //-- some rays for output 
    17521641        const int raysOut = min((int)mBspRays.size(), mVisualizationSamples); 
     1642         
    17531643        cout << "visualization using " << mVisualizationSamples << " samples" << endl; 
    17541644        Debug << "\nOutput view cells: " << endl; 
    1755  
    1756         if (1) 
    1757         { 
    1758                 //-- some random view cells and rays for output 
    1759                 vector<BspLeaf *> vspBspLeaves; 
    1760  
    1761                 for (int i = 0; i < leafOut; ++ i) 
    1762                         vspBspLeaves.push_back(mVspBspTree->GetRandomLeaf());    
    1763                  
    1764                 for (int i = 0; i < (int)vspBspLeaves.size(); ++ i) 
    1765                 { 
    1766                         VssRayContainer vcRays; 
    1767                         cout << "creating output for view cell " << i << " ... "; 
    1768  
    1769                         // check whether we can add the current ray to the output rays 
    1770                         for (int k = 0; k < raysOut; ++ k)  
     1645         
     1646        // sort view cells to get largest view cells 
     1647#if 0 
     1648        stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 
     1649#endif 
     1650        int limit = min(leafOut, (int)mViewCells.size());  
     1651                 
     1652        for (int i = 0; i < limit; ++ i) 
     1653        { 
     1654                cout << "creating output for view cell " << i << " ... "; 
     1655                VssRayContainer vcRays; 
     1656           Intersectable::NewMail(); 
     1657#if 0 
     1658                BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[i]); 
     1659#else 
     1660                BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[Random((int)mViewCells.size())]); 
     1661#endif 
     1662                cout << "creating output for view cell " << i << " ... "; 
     1663 
     1664#if 0 
     1665                // check whether we can add the current ray to the output rays 
     1666                for (int k = 0; k < raysOut; ++ k)  
     1667                { 
     1668                        BspRay *ray = mBspRays[k]; 
     1669                        for     (int j = 0; j < (int)ray->intersections.size(); ++ j) 
    17711670                        { 
    1772                                 BspRay *ray = mBspRays[k]; 
    1773  
    1774                                 for     (int j = 0; j < (int)ray->intersections.size(); ++ j) 
    1775                                 { 
    1776                                         BspLeaf *leaf = ray->intersections[j].mLeaf; 
    1777  
    1778                                         if (vspBspLeaves[i]->GetViewCell() == leaf->GetViewCell())  
    1779                                         { 
    1780                                                 vcRays.push_back(ray->vssRay); 
    1781                                         } 
    1782                                 } 
     1671                                BspLeaf *leaf = ray->intersections[j].mLeaf; 
     1672                                if (vc == leaf->GetViewCell())  
     1673                                        vcRays.push_back(ray->vssRay); 
    17831674                        } 
    1784  
    1785                         Intersectable::NewMail(); 
    1786  
    1787                         BspViewCell *vc = dynamic_cast<BspViewCell *> 
    1788                                 (vspBspLeaves[i]->GetViewCell()); 
    1789  
    1790                         //bspLeaves[j]->Mail(); 
    1791                         char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
    1792  
    1793                         Exporter *exporter = Exporter::GetExporter(s); 
    1794                         exporter->SetFilled(); 
    1795  
    1796                         ObjectPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 
    1797  
    1798                         exporter->SetWireframe(); 
    1799                         //exporter->SetFilled(); 
    1800  
    1801                         Material m;//= RandomMaterial(); 
    1802                         m.mDiffuseColor = RgbColor(0, 1, 0); 
    1803                         exporter->SetForcedMaterial(m); 
    1804  
    1805                         if (vc->GetMesh()) 
    1806                                 exporter->ExportViewCell(vc); 
    1807                         else 
     1675                } 
     1676#endif 
     1677                //bspLeaves[j]->Mail(); 
     1678                char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
     1679 
     1680                Exporter *exporter = Exporter::GetExporter(s); 
     1681                         
     1682                exporter->SetWireframe(); 
     1683 
     1684                Material m;//= RandomMaterial(); 
     1685                m.mDiffuseColor = RgbColor(0, 1, 0); 
     1686                exporter->SetForcedMaterial(m); 
     1687 
     1688                if (vc->GetMesh()) 
     1689                        exporter->ExportViewCell(vc); 
     1690                else 
     1691                { 
     1692                        PolygonContainer vcGeom; 
     1693                        // export view cell 
     1694                        mVspBspTree->ConstructGeometry(vc, vcGeom); 
     1695                        exporter->ExportPolygons(vcGeom); 
     1696                        CLEAR_CONTAINER(vcGeom); 
     1697                } 
     1698                         
     1699                Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
     1700                          << ", piercing rays=" << (int)vcRays.size() << endl; 
     1701 
     1702                         
     1703                // export rays piercing this view cell 
     1704#if 0 
     1705                exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 
     1706#else 
     1707                vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 
     1708                for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 
     1709                        exporter->ExportRays((*lit)->mVssRays); 
     1710#endif 
     1711                m.mDiffuseColor = RgbColor(1, 0, 0); 
     1712                exporter->SetForcedMaterial(m); 
     1713 
     1714                ObjectPvsMap::const_iterator it, 
     1715                        it_end = vc->GetPvs().mEntries.end(); 
     1716 
     1717                exporter->SetFilled(); 
     1718 
     1719                // output PVS of view cell 
     1720                for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it)  
     1721                { 
     1722                        Intersectable *intersect = (*it).first; 
     1723 
     1724                        if (!intersect->Mailed()) 
    18081725                        { 
    1809                                 PolygonContainer vcGeom; 
    1810  
    1811                                 // export view cell geometry 
    1812                                 mVspBspTree->ConstructGeometry(vc, vcGeom); 
    1813                                 exporter->ExportPolygons(vcGeom); 
    1814                                 CLEAR_CONTAINER(vcGeom); 
    1815                         } 
    1816  
    1817                         Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
    1818                                         << ", piercing rays=" << (int)vcRays.size() << endl; 
    1819  
    1820                         // export rays piercing this view cell 
    1821                         if (exportRays) 
    1822                         { 
    1823                                 //exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 
    1824                                 exporter->ExportRays(vspBspLeaves[i]->mVssRays, RgbColor(1, 1, 1)); 
    1825                         } 
    1826  
    1827                         m.mDiffuseColor = RgbColor(0, 1, 1); 
    1828                         exporter->SetForcedMaterial(m); 
    1829  
    1830                         //exporter->SetWireframe(); 
    1831                         exporter->SetFilled(); 
    1832  
    1833                         // output PVS of view cell 
    1834                         for (; it != vc->GetPvs().mEntries.end(); ++ it)  
    1835                         { 
    1836                                 Intersectable *intersect = (*it).first; 
    1837                                 if (!intersect->Mailed()) 
    1838                                 { 
    1839                                         exporter->ExportIntersectable(intersect); 
    1840                                         intersect->Mail(); 
    1841                                 }                        
    1842                         } 
    1843                         Debug << "here1 exportgeom: " << exportGeometry << endl; 
    1844                         // output rest of the objects 
    1845                         if (exportGeometry) 
    1846                         { 
    1847                                 Material m;//= RandomMaterial(); 
    1848                                 m.mDiffuseColor = RgbColor(0, 0, 1); 
     1726                                Material m = RandomMaterial(); 
    18491727                                exporter->SetForcedMaterial(m); 
    18501728 
    1851                                 for (int j = 0; j < objects.size(); ++ j) 
    1852                                         if (!objects[j]->Mailed()) 
    1853                                         { 
    1854                                                 exporter->SetForcedMaterial(m); 
    1855                                                 exporter->ExportIntersectable(objects[j]); 
    1856                                                 objects[j]->Mail(); 
    1857                                         } 
    1858                         } 
    1859                         DEL_PTR(exporter); 
    1860                         cout << "finished" << endl; 
    1861                 } 
    1862         } 
    1863         else 
    1864         { 
    1865                 ViewCellContainer viewCells; 
    1866  
    1867                 mVspBspTree->CollectViewCells(viewCells); 
    1868                 stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 
    1869  
    1870                 int limit = min(leafOut, (int)viewCells.size());  
    1871                  
    1872                 for (int i = 0; i < limit; ++ i) 
    1873                 { 
    1874                         cout << "creating output for view cell " << i << " ... "; 
    1875                         VssRayContainer vcRays; 
    1876             Intersectable::NewMail(); 
    1877                         BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]); 
    1878  
    1879                         cout << "creating output for view cell " << i << " ... "; 
    1880  
    1881                         // check whether we can add the current ray to the output rays 
    1882                         for (int k = 0; k < raysOut; ++ k)  
    1883                         { 
    1884                                 BspRay *ray = mBspRays[k]; 
    1885  
    1886                                 for     (int j = 0; j < (int)ray->intersections.size(); ++ j) 
    1887                                 { 
    1888                                         BspLeaf *leaf = ray->intersections[j].mLeaf; 
    1889  
    1890                                         if (vc == leaf->GetViewCell())  
    1891                                         { 
    1892                                                 vcRays.push_back(ray->vssRay); 
    1893                                         } 
    1894                                 } 
    1895                         } 
    1896  
    1897                         //bspLeaves[j]->Mail(); 
    1898                         char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
    1899  
    1900                         Exporter *exporter = Exporter::GetExporter(s); 
    1901                          
    1902                         exporter->SetWireframe(); 
    1903  
    1904                         Material m;//= RandomMaterial(); 
    1905                         m.mDiffuseColor = RgbColor(0, 1, 0); 
    1906                         exporter->SetForcedMaterial(m); 
    1907  
    1908                         if (vc->GetMesh()) 
    1909                                 exporter->ExportViewCell(vc); 
    1910                         else 
    1911                         { 
    1912                                 PolygonContainer vcGeom; 
    1913                                 // export view cell 
    1914                                 mVspBspTree->ConstructGeometry(vc, vcGeom); 
    1915                                 exporter->ExportPolygons(vcGeom); 
    1916                                 CLEAR_CONTAINER(vcGeom); 
    1917                         } 
    1918  
    1919                          
    1920                         Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
    1921                                   << ", piercing rays=" << (int)vcRays.size() << endl; 
    1922  
    1923                          
    1924                         // export rays piercing this view cell 
    1925                         exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 
    1926          
    1927                         m.mDiffuseColor = RgbColor(1, 0, 0); 
    1928                         exporter->SetForcedMaterial(m); 
    1929  
    1930                         ObjectPvsMap::const_iterator it, 
    1931                                 it_end = vc->GetPvs().mEntries.end(); 
    1932  
    1933                         // output PVS of view cell 
    1934                         for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it)  
    1935                         { 
    1936                                 Intersectable *intersect = (*it).first; 
    1937  
    1938                                 if (!intersect->Mailed()) 
    1939                                 { 
    1940                                         Material m = RandomMaterial(); 
    1941                          
    1942                                         exporter->SetForcedMaterial(m); 
    1943  
    1944                                         exporter->ExportIntersectable(intersect); 
    1945                                         intersect->Mail(); 
    1946                                 }                        
    1947                         } 
     1729                                exporter->ExportIntersectable(intersect); 
     1730                                intersect->Mail(); 
     1731                        }                        
     1732                } 
    19481733                                 
    1949                         DEL_PTR(exporter); 
    1950                         cout << "finished" << endl; 
    1951                 } 
     1734                DEL_PTR(exporter); 
     1735                cout << "finished" << endl; 
    19521736        } 
    19531737 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r477 r478  
    198198  /** Returns area of one view cell. 
    199199  */ 
    200   float GetArea(ViewCell *viewCell) const; 
     200  virtual float GetArea(ViewCell *viewCell) const; 
    201201 
    202202  /** Returns volume of view cells. 
    203203  */ 
    204   float GetVolume(ViewCell *viewCell) const; 
     204  virtual float GetVolume(ViewCell *viewCell) const; 
    205205 
    206206  virtual AxisAlignedBox3 GetSceneBbox() const = 0; 
     
    273273        float GetRendercost(ViewCell *viewCell, float objRendercost) const; 
    274274 
    275         float GetArea(ViewCell *viewCell) const; 
    276  
    277275        AxisAlignedBox3 GetSceneBbox() const; 
    278276 
     
    320318                                  AxisAlignedBox3 *sceneBbox); 
    321319 
    322   int CastLineSegment(const Vector3 &origin, 
    323                                           const Vector3 &termination, 
    324                                           ViewCellContainer &viewcells 
    325                                           ) ; 
     320        int CastLineSegment(const Vector3 &origin, 
     321                                                const Vector3 &termination, 
     322                                                ViewCellContainer &viewcells); 
    326323 
    327324        int PostProcess(const ObjectContainer &objects,  
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r475 r478  
     1#include <stack> 
     2#include <time.h> 
     3#include <iomanip> 
     4 
    15#include "Plane3.h" 
    26#include "VspBspTree.h" 
     
    812#include "Ray.h" 
    913#include "AxisAlignedBox3.h" 
    10 #include <stack> 
    11 #include <time.h> 
    12 #include <iomanip> 
    1314#include "Exporter.h" 
    1415#include "Plane3.h" 
    1516#include "ViewCellBsp.h" 
     17#include "ViewCellsManager.h" 
     18 
    1619 
    1720//-- static members 
     
    3033int VspBspTree::sFrontAndBackId = 0; 
    3134 
     35float BspMergeCandidate::sOverallCost = Limits::Small; 
    3236 
    3337/****************************************************************/ 
     
    3842mRoot(NULL), 
    3943mPvsUseArea(true), 
    40 mCostNormalizer(Limits::Small) 
     44mCostNormalizer(Limits::Small), 
     45mViewCellsManager(NULL), 
     46mStoreRays(true) 
    4147{ 
    4248        mRootCell = new BspViewCell(); 
     
    7581        environment->GetIntValue("VspBspTree.maxTests", mMaxTests); 
    7682 
    77         // maximum number of view cells 
    78         environment->GetIntValue("ViewCells.maxViewCells", mMaxViewCells); 
    79  
    80         //-- 
     83        // maximum and minimum number of view cells 
     84        environment->GetIntValue("VspBspTree.Termination.maxViewCells", mMaxViewCells); 
     85        environment->GetIntValue("VspBspTree.PostProcess.minViewCells", mMergeMinViewCells); 
     86        environment->GetIntValue("VspBspTree.PostProcess.maxCostRatio", mMergeMaxCostRatio); 
     87 
     88 
     89        //-- debug output 
    8190        Debug << "******* VSP BSP options ******** " << endl; 
    8291    Debug << "max depth: " << mTermMaxDepth << endl; 
     
    313322        long startTime = GetTime(); 
    314323         
    315         while (!tStack.empty())  
     324        while (!tStack.empty()) 
    316325        { 
    317326                tData = tStack.top(); 
    318327 
    319328            tStack.pop(); 
     329 
    320330                // subdivide leaf node 
    321331                BspNode *r = Subdivide(tStack, tData); 
     
    331341} 
    332342 
    333 bool VspBspTree::TerminationCriteriaMet(const VspBspTraversalData &data,  
    334                                                                                 const int numLeaves) const 
     343bool VspBspTree::TerminationCriteriaMet(const VspBspTraversalData &data) const 
    335344{ 
    336345        return  
     
    338347                 (data.mPvs <= mTermMinPvs)   || 
    339348                 (data.mArea <= mTermMinArea) || 
    340                  ((mStat.nodes / 2 + 1) >= mMaxViewCells) || 
     349                 (mStat.nodes / 2 + 1 >= mMaxViewCells) || 
    341350                // (data.GetAvgRayContribution() >= mTermMaxRayContribution) || 
    342351                 (data.mDepth >= mTermMaxDepth)); 
     
    348357        BspNode *newNode = tData.mNode; 
    349358 
    350         if (!TerminationCriteriaMet(tData, (int)tStack.size())) 
     359        if (!TerminationCriteriaMet(tData)) 
    351360        { 
    352361                PolygonContainer coincident; 
     
    370379        } 
    371380         
    372         //-- terminate traversal   
     381        //-- terminate traversal and create new view cell 
    373382        if (newNode->IsLeaf()) 
    374383        { 
     
    378387                BspViewCell *viewCell = new BspViewCell(); 
    379388                leaf->SetViewCell(viewCell); 
     389                 
     390                if (mStoreRays) 
     391                { 
     392                        RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 
     393                        for (it = tData.mRays->begin(); it != it_end; ++ it) 
     394                                leaf->mVssRays.push_back((*it).mRay); 
     395                } 
     396 
    380397                viewCell->mLeaves.push_back(leaf); 
     398                viewCell->SetArea(tData.mArea); 
    381399 
    382400                //-- update pvs 
     
    392410                 
    393411        //-- cleanup 
    394         DEL_PTR(tData.mPolygons); 
    395         DEL_PTR(tData.mRays); 
    396         DEL_PTR(tData.mGeometry); 
     412        tData.Clear(); 
    397413 
    398414        return newNode; 
     
    18721888        return hits; 
    18731889} 
     1890 
     1891int VspBspTree::MergeLeaves() 
     1892{ 
     1893        vector<BspLeaf *> leaves; 
     1894        priority_queue<BspMergeCandidate> mergeQueue; 
     1895 
     1896        // collect the leaves, e.g., the "voxels" that will build the view cells 
     1897        CollectLeaves(leaves); 
     1898 
     1899        int vcSize = (int)leaves.size(); 
     1900        int savedVcSize = vcSize; 
     1901 
     1902        BspLeaf::NewMail(); 
     1903 
     1904        vector<BspLeaf *>::const_iterator it, it_end = leaves.end(); 
     1905 
     1906        // find merge candidates and push them into queue 
     1907        for (it = leaves.begin(); it != it_end; ++ it) 
     1908        { 
     1909                BspLeaf *leaf = *it; 
     1910 
     1911                // no leaf is part of two merge candidates 
     1912                if (!leaf->Mailed()) 
     1913                { 
     1914                        leaf->Mail(); 
     1915 
     1916                        vector<BspLeaf *> neighbors; 
     1917                        FindNeighbors(leaf, neighbors, true); 
     1918 
     1919                        vector<BspLeaf *>::const_iterator nit, 
     1920                                nit_end = neighbors.end(); 
     1921 
     1922                        for (nit = neighbors.begin(); nit != nit_end; ++ nit) 
     1923                        { 
     1924                                BspMergeCandidate mc = BspMergeCandidate(leaf, *nit); 
     1925                                mergeQueue.push(mc); 
     1926 
     1927                                BspMergeCandidate::sOverallCost += mc.GetLeaf1Cost(); 
     1928                                BspMergeCandidate::sOverallCost += mc.GetLeaf2Cost(); 
     1929                        } 
     1930                } 
     1931        } 
     1932 
     1933        int merged = 0; 
     1934 
     1935        Debug << "here234: " << mMergeMaxCostRatio << endl; 
     1936 
     1937        // use priority queue to merge leaves 
     1938        while (!mergeQueue.empty() && (vcSize > mMergeMinViewCells) )//&& 
     1939                   //(mergeQueue.top().GetMergeCost() <  
     1940                    //mMergeMaxCostRatio / BspMergeCandidate::sOverallCost)) 
     1941        { 
     1942                Debug << "mergecost: " << mergeQueue.top().GetMergeCost() << " " << mMergeMaxCostRatio << endl; 
     1943                BspMergeCandidate mc = mergeQueue.top(); 
     1944                mergeQueue.pop(); 
     1945 
     1946                // both view cells equal! 
     1947                if (mc.GetLeaf1()->GetViewCell() == mc.GetLeaf2()->GetViewCell()) 
     1948                        continue; 
     1949 
     1950                if (mc.Valid()) 
     1951                { 
     1952                        ViewCell::NewMail(); 
     1953                        MergeViewCells(mc.GetLeaf1(), mc.GetLeaf2()); 
     1954 
     1955                        ++ merged; 
     1956                        -- vcSize; 
     1957                        // increase absolute merge cost 
     1958                        BspMergeCandidate::sOverallCost += mc.GetMergeCost(); 
     1959                } 
     1960                // merge candidate not valid, because one of the leaves was already 
     1961                // merged with another one 
     1962                else 
     1963                { 
     1964                        // validate and reinsert into queue 
     1965                        mc.SetValid(); 
     1966                        mergeQueue.push(mc); 
     1967                        //Debug << "validate " << mc.GetMergeCost() << endl; 
     1968                } 
     1969        } 
     1970 
     1971        // collapse tree according to view cell partition 
     1972        //CollapseTree(mRoot); 
     1973 
     1974        // revalidate leaves 
     1975        //ValidateViewCellLeaves(); 
     1976 
     1977        //Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl; 
     1978 
     1979        //TODO: should return sample contributions 
     1980        return merged; 
     1981} 
     1982 
     1983 
     1984bool VspBspTree::MergeViewCells(BspLeaf *l1, BspLeaf *l2) 
     1985{ 
     1986        //-- change pointer to view cells of all leaves associated  
     1987        //-- with the previous view cells 
     1988        BspViewCell *fVc = l1->GetViewCell(); 
     1989        BspViewCell *bVc = l2->GetViewCell(); 
     1990 
     1991        BspViewCell *vc = dynamic_cast<BspViewCell *>( 
     1992                mViewCellsManager->MergeViewCells(*fVc, *bVc)); 
     1993 
     1994        // if merge was unsuccessful 
     1995        if (!vc) return false; 
     1996 
     1997        // set new size of view cell 
     1998        vc->SetArea(fVc->GetVolume() + bVc->GetVolume()); 
     1999 
     2000        vector<BspLeaf *> fLeaves = fVc->mLeaves; 
     2001        vector<BspLeaf *> bLeaves = bVc->mLeaves; 
     2002 
     2003        vector<BspLeaf *>::const_iterator it; 
     2004 
     2005        //-- change view cells of all the other leaves the view cell belongs to 
     2006        for (it = fLeaves.begin(); it != fLeaves.end(); ++ it) 
     2007        { 
     2008                (*it)->SetViewCell(vc); 
     2009                vc->mLeaves.push_back(*it); 
     2010        } 
     2011 
     2012        for (it = bLeaves.begin(); it != bLeaves.end(); ++ it) 
     2013        { 
     2014                (*it)->SetViewCell(vc); 
     2015                vc->mLeaves.push_back(*it); 
     2016        } 
     2017 
     2018        vc->Mail(); 
     2019 
     2020        // clean up old view cells 
     2021        DEL_PTR(fVc); 
     2022        DEL_PTR(bVc); 
     2023 
     2024        return true; 
     2025} 
     2026 
     2027 
     2028void VspBspTree::SetViewCellsManager(ViewCellsManager *vcm) 
     2029{ 
     2030        mViewCellsManager = vcm; 
     2031} 
     2032 
     2033/************************************************************************/ 
     2034/*                BspMergeCandidate implementation                      */ 
     2035/************************************************************************/ 
     2036 
     2037 
     2038BspMergeCandidate::BspMergeCandidate(BspLeaf *l1, BspLeaf *l2): 
     2039mMergeCost(0), 
     2040mLeaf1(l1), 
     2041mLeaf2(l2), 
     2042mLeaf1Id(l1->GetViewCell()->mMailbox), 
     2043mLeaf2Id(l2->GetViewCell()->mMailbox) 
     2044{ 
     2045        EvalMergeCost(); 
     2046} 
     2047 
     2048float BspMergeCandidate::GetLeaf1Cost() const 
     2049{ 
     2050        BspViewCell *vc = mLeaf1->GetViewCell(); 
     2051        return vc->GetPvs().GetSize() * vc->GetArea(); 
     2052} 
     2053 
     2054float BspMergeCandidate::GetLeaf2Cost() const 
     2055{ 
     2056        BspViewCell *vc = mLeaf2->GetViewCell(); 
     2057        return vc->GetPvs().GetSize() * vc->GetVolume(); 
     2058} 
     2059 
     2060void BspMergeCandidate::EvalMergeCost() 
     2061{ 
     2062        //-- compute pvs difference 
     2063        BspViewCell *vc1 = mLeaf1->GetViewCell(); 
     2064        BspViewCell *vc2 = mLeaf2->GetViewCell(); 
     2065 
     2066        const int diff1 = vc1->GetPvs().Diff(vc2->GetPvs()); 
     2067        const int vcPvs = diff1 + vc1->GetPvs().GetSize(); 
     2068 
     2069        //-- compute ratio of old cost 
     2070        //-- (added size of left and right view cell times pvs size) 
     2071        //-- to new rendering cost (size of merged view cell times pvs size) 
     2072        const float oldCost = GetLeaf1Cost() + GetLeaf2Cost(); 
     2073         
     2074        const float newCost = 
     2075                (float)vcPvs * (vc1->GetArea() + vc2->GetArea()); 
     2076 
     2077        mMergeCost = newCost - oldCost; 
     2078 
     2079//      if (vcPvs > sMaxPvsSize) // strong penalty if pvs size too large 
     2080//              mMergeCost += 1.0; 
     2081} 
     2082 
     2083void BspMergeCandidate::SetLeaf1(BspLeaf *l) 
     2084{ 
     2085        mLeaf1 = l; 
     2086} 
     2087 
     2088void BspMergeCandidate::SetLeaf2(BspLeaf *l) 
     2089{ 
     2090        mLeaf2 = l; 
     2091} 
     2092 
     2093BspLeaf *BspMergeCandidate::GetLeaf1() 
     2094{ 
     2095        return mLeaf1; 
     2096} 
     2097 
     2098BspLeaf *BspMergeCandidate::GetLeaf2() 
     2099{ 
     2100        return mLeaf2; 
     2101} 
     2102 
     2103bool BspMergeCandidate::Valid() const 
     2104{ 
     2105        return 
     2106                (mLeaf1->GetViewCell()->mMailbox == mLeaf1Id) && 
     2107                (mLeaf2->GetViewCell()->mMailbox == mLeaf2Id); 
     2108} 
     2109 
     2110float BspMergeCandidate::GetMergeCost() const 
     2111{ 
     2112        return mMergeCost; 
     2113} 
     2114 
     2115void BspMergeCandidate::SetValid() 
     2116{ 
     2117        mLeaf1Id = mLeaf1->GetViewCell()->mMailbox; 
     2118        mLeaf2Id = mLeaf2->GetViewCell()->mMailbox; 
     2119 
     2120        EvalMergeCost(); 
     2121} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r475 r478  
    2020class Ray; 
    2121class ViewCellsStatistics; 
    22  
    23 /*class BspNodeGeometry; 
    24 class BspTreeStatistics; 
    25 class ViewCellsStatistics; 
    26 class BspNode; 
    27 class BspLeaf; 
    28 class BspInterior; 
    29 */ 
     22class ViewCellsManager; 
     23 
    3024 
    3125/** 
     
    130124                } 
    131125 
     126                // deletes contents and sets them to NULL 
     127                void Clear() 
     128                { 
     129                        DEL_PTR(mPolygons); 
     130                        DEL_PTR(mRays); 
     131                        DEL_PTR(mGeometry); 
     132                } 
     133 
    132134                friend bool operator<(const VspBspTraversalData &a, const VspBspTraversalData &b) 
    133135                { 
     
    237239 
    238240 
    239     int 
    240         CastLineSegment(const Vector3 &origin, 
    241                                         const Vector3 &termination, 
    242                                         ViewCellContainer &viewcells 
    243                                         ); 
     241    int CastLineSegment(const Vector3 &origin, 
     242                                                const Vector3 &termination, 
     243                                                ViewCellContainer &viewcells); 
     244 
     245        /** Merges leaves with similar PVS. 
     246        */ 
     247        int MergeLeaves(); 
     248 
     249 
     250                 
     251        /** Sets pointer to view cells manager. 
     252        */ 
     253        void SetViewCellsManager(ViewCellsManager *vcm); 
    244254 
    245255protected: 
     
    428438        /** Returns true if tree can be terminated. 
    429439        */ 
    430         inline bool TerminationCriteriaMet(const VspBspTraversalData &data, const int numLeaves) const; 
     440        inline bool TerminationCriteriaMet(const VspBspTraversalData &data) const; 
    431441 
    432442        /** Computes accumulated ray lenght of this rays. 
     
    477487        Plane3 ChooseCandidatePlane3(const RayInfoContainer &rays) const; 
    478488   
     489        /** Merge view cells of leaves l1 and l2. 
     490        */ 
     491        bool MergeViewCells(BspLeaf *l1, BspLeaf *l2); 
     492 
    479493        /// Pointer to the root of the tree 
    480494        BspNode *mRoot; 
     
    549563        /// maximal number of view cells 
    550564        int mMaxViewCells; 
     565        /// minimal number of view cells 
     566        int mMergeMinViewCells; 
     567        /// maximal cost ratio for the merge 
     568        int mMergeMaxCostRatio; 
     569 
     570        ViewCellsManager *mViewCellsManager; 
     571 
     572        // if rays should be stored in leaves 
     573        bool mStoreRays; 
    551574 
    552575private: 
     
    567590}; 
    568591 
     592/** 
     593        Candidate for leaf merging based on priority. 
     594*/ 
     595class BspMergeCandidate 
     596 
     597public: 
     598 
     599        BspMergeCandidate(BspLeaf *l1, BspLeaf *l2); 
     600 
     601        /** If this merge pair is still valid. 
     602        */ 
     603        bool Valid() const; 
     604 
     605        /** Sets this merge candidate to be valid. 
     606        */ 
     607        void SetValid(); 
     608 
     609        friend bool operator<(const BspMergeCandidate &leafa, const BspMergeCandidate &leafb) 
     610        { 
     611                return leafb.GetMergeCost() < leafa.GetMergeCost(); 
     612        } 
     613 
     614        void SetLeaf1(BspLeaf *l); 
     615        void SetLeaf2(BspLeaf *l); 
     616 
     617        BspLeaf *GetLeaf1(); 
     618        BspLeaf *GetLeaf2(); 
     619 
     620        /** Merge cost of this candidate pair. 
     621        */ 
     622        float GetMergeCost() const; 
     623 
     624        /** Returns cost of leaf 1. 
     625        */ 
     626        float GetLeaf1Cost() const; 
     627        /** Returns cost of leaf 2. 
     628        */ 
     629        float GetLeaf2Cost() const; 
     630 
     631        /// maximal pvs size 
     632        static int sMaxPvsSize; 
     633        /// overall cost used to normalize cost ratio 
     634        static float sOverallCost; 
     635 
     636protected: 
     637         
     638        /** Evaluates the merge costs of the leaves. 
     639        */ 
     640        void EvalMergeCost(); 
     641 
     642        int mLeaf1Id; 
     643        int mLeaf2Id; 
     644 
     645        float mMergeCost; 
     646         
     647        BspLeaf *mLeaf1; 
     648        BspLeaf *mLeaf2; 
     649}; 
     650 
     651 
    569652#endif 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp

    r473 r478  
    19101910 
    19111911 
    1912  
    19131912void VspKdTree::SetViewCellsManager(ViewCellsManager *vcm) 
    19141913{ 
     
    20232022        leaf->SetViewCell(vc); 
    20242023 
    2025         vc->SetVolume(GetBBox(leaf).GetVolume()); 
     2024        vc->SetArea(GetBBox(leaf).GetVolume()); 
    20262025        vc->mLeaves.push_back(leaf); 
    20272026 
     
    21072106 
    21082107        // set new size of view cell 
    2109         vc->SetVolume(fVc->GetVolume() + bVc->GetVolume()); 
     2108        vc->SetArea(fVc->GetVolume() + bVc->GetVolume()); 
    21102109 
    21112110        vector<VspKdLeaf *> fLeaves = fVc->mLeaves; 
     
    22292228        ValidateViewCellLeaves(); 
    22302229 
    2231         Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl; 
     2230        //Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl; 
    22322231 
    22332232        //TODO: should return sample contributions 
Note: See TracChangeset for help on using the changeset viewer.