Ignore:
Timestamp:
02/14/06 17:13:42 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r612 r639  
    1616#include "RssPreprocessor.h" 
    1717 
    18 #define SAMPLE_AFTER_SUBDIVISION 0 
     18#define SAMPLE_AFTER_SUBDIVISION 1 
    1919 
    2020 
     
    115115 
    116116/// helper function which destroys rays or copies them into the output ray container 
    117 inline void addOutRays(VssRayContainer &rays, VssRayContainer *outRays) 
     117inline void disposeRays(VssRayContainer &rays, VssRayContainer *outRays) 
    118118{ 
    119119        cout << "disposing samples ... "; 
     
    132132        else 
    133133        { 
    134                 CLEAR_CONTAINER(rays); 
    135         } 
     134                VssRayContainer::const_iterator it, it_end = rays.end(); 
     135 
     136                for (it = rays.begin(); it != it_end; ++ it) 
     137                { 
     138                        //(*it)->Unref(); 
     139                        if (!(*it)->IsActive()) 
     140                                delete (*it); 
     141                } 
     142        } 
     143 
    136144        cout << "finished" << endl; 
    137145        Debug << "disposed " << n << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     
    162170 
    163171        // rays can be passed or deleted 
    164         addOutRays(initialSamples, outRays); 
     172        disposeRays(initialSamples, outRays); 
    165173         
    166174 
     
    196204 
    197205 
    198                 addOutRays(constructionSamples, outRays); 
     206                disposeRays(constructionSamples, outRays); 
    199207 
    200208                cout << "total samples: " << numSamples << endl; 
     
    236244        Visualize(preprocessor->mObjects, visualizationSamples); 
    237245 
    238         addOutRays(visualizationSamples, outRays); 
     246        disposeRays(visualizationSamples, outRays); 
    239247 
    240248        return numSamples; 
     
    30563064                                                                                  const VssRayContainer &rays) 
    30573065{ 
    3058         const int leafOut = 10; 
     3066        const int leafOut = 20; 
    30593067 
    30603068        ViewCell::NewMail(); 
    30613069 
    3062         cout << "visualization using " << mVisualizationSamples << " samples" << endl; 
     3070        cout << "visualization using " << (int)rays.size() << " samples" << endl; 
     3071        Debug << "visualization using " << (int)rays.size() << " samples" << endl; 
    30633072        Debug << "\nOutput view cells: " << endl; 
    30643073 
     
    30663075        if (0) 
    30673076                stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 
    3068  
     3077         
    30693078        int limit = min(leafOut, (int)mViewCells.size()); 
    30703079 
    3071         int raysOut; 
     3080        int raysOut = 0; 
    30723081 
    30733082        //-- some rays for output 
    3074         if (1) 
    3075                 raysOut = min((int)rays.size(), mVisualizationSamples); 
    3076  
    30773083        for (int i = 0; i < limit; ++ i) 
    30783084        { 
    30793085                cout << "creating output for view cell " << i << " ... "; 
    30803086 
    3081                 VssRayContainer vcRays; 
    3082                 Intersectable::NewMail(); 
     3087         
    30833088                ViewCell *vc; 
    30843089         
     
    30863091                        vc = mViewCells[i]; 
    30873092                else 
    3088                         vc = mViewCells[Random((int)mViewCells.size())]; 
    3089  
    3090                 vector<ViewCell *> leaves; 
    3091                 mViewCellsTree->CollectLeaves(vc, leaves); 
    3092  
    3093         if (1) 
    3094                 { 
    3095                         // check whether we can add the current ray to the output rays 
    3096                         for (int k = 0; k < raysOut; ++ k) 
    3097                         { 
    3098                                 VssRay *ray = rays[k]; 
    3099                                 for     (int j = 0; j < (int)ray->mViewCells.size(); ++ j) 
    3100                                 { 
    3101                                         ViewCell *rayvc = ray->mViewCells[j]; 
    3102  
    3103                                         if (leaves[0] == rayvc) 
    3104                                                 vcRays.push_back(ray); 
    3105                                 } 
    3106                         } 
    3107                 } 
     3093                        vc = mViewCells[(int)RandomValue(0, (float)mViewCells.size() - 1)]; 
    31083094 
    31093095                //bspLeaves[j]->Mail(); 
    31103096                char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
    31113097                Exporter *exporter = Exporter::GetExporter(s); 
     3098                 
     3099                Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 
     3100 
     3101                if (1 || mExportRays) 
     3102                { 
     3103                        if (1) 
     3104                        { 
     3105                                VssRayContainer vcRays; 
     3106                VssRayContainer collectRays; 
     3107 
     3108                                raysOut = min((int)rays.size(), 100); 
     3109 
     3110                                // collect intial view cells 
     3111                                ViewCellContainer leaves; 
     3112                                mViewCellsTree->CollectLeaves(vc, leaves); 
     3113 
     3114                                ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 
     3115        
     3116                                for (vit = leaves.begin(); vit != vit_end; ++ vit) 
     3117                                { 
     3118                                        BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaf; 
     3119                                 
     3120                                        VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 
     3121 
     3122                                        for (rit = vcLeaf->mVssRays.begin(); rit != rit_end; ++ rit) 
     3123                                        { 
     3124                                                collectRays.push_back(*rit); 
     3125                                        } 
     3126                                } 
     3127 
     3128                                VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 
     3129 
     3130                                for (rit = collectRays.begin(); rit != rit_end; ++ rit) 
     3131                                { 
     3132                                        float p = RandomValue(0.0f, (float)collectRays.size()); 
     3133                         
     3134                                        if (p < raysOut) 
     3135                                                vcRays.push_back(*rit); 
     3136                                } 
     3137                                //-- export rays piercing this view cell 
     3138                                exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 
     3139                        } 
     3140 
     3141                         
     3142 
     3143                        if (0) 
     3144                        { 
     3145                                VssRayContainer vcRays; 
     3146                                raysOut = min((int)rays.size(), mVisualizationSamples); 
     3147                                // check whether we can add the current ray to the output rays 
     3148                                for (int k = 0; k < raysOut; ++ k) 
     3149                                { 
     3150                                        VssRay *ray = rays[k]; 
     3151                                        for     (int j = 0; j < (int)ray->mViewCells.size(); ++ j) 
     3152                                        { 
     3153                                                ViewCell *rayvc = ray->mViewCells[j]; 
     3154         
     3155                                                if (rayvc == vc) 
     3156                                                        vcRays.push_back(ray); 
     3157                                        } 
     3158                                }        
     3159                                 
     3160                                //-- export rays piercing this view cell 
     3161                                exporter->ExportRays(vcRays, RgbColor(1, 1, 0)); 
     3162                        } 
     3163 
     3164                } 
     3165                 
     3166                 
     3167 
     3168 
    31123169                exporter->SetWireframe(); 
    31133170 
     
    31173174 
    31183175                ExportViewCellGeometry(exporter, vc); 
    3119  
    3120  
    3121                 Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) 
    3122                           << ", piercing rays=" << (int)vcRays.size() << endl; 
    3123                         //  << ", leaves=" << (int)vc->mLeaves.size() << endl; 
    3124  
    3125                  
    3126                 //-- export rays piercing this view cell 
     3176         
     3177 
     3178                m.mDiffuseColor = RgbColor(1, 0, 0); 
     3179            exporter->SetForcedMaterial(m); 
     3180 
     3181                exporter->SetFilled(); 
     3182 
     3183 
    31273184                if (1) 
    31283185                { 
    3129                         exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 
     3186                        ObjectPvsMap::const_iterator oit, 
     3187                                oit_end = vc->GetPvs().mEntries.end(); 
     3188 
     3189 
     3190                        exporter->SetFilled(); 
     3191 
     3192                        Intersectable::NewMail(); 
     3193         
     3194                        // output PVS of view cell 
     3195                        for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     3196                        {                
     3197                                Intersectable *intersect = (*oit).first; 
     3198 
     3199                                if (!intersect->Mailed()) 
     3200                                { 
     3201                                        //m = RandomMaterial(); 
     3202                                        //exporter->SetForcedMaterial(m); 
     3203 
     3204                                        exporter->ExportIntersectable(intersect); 
     3205                                        intersect->Mail(); 
     3206                                } 
     3207                        } 
    31303208                } 
    31313209                else 
    31323210                { 
    3133  
    3134                         ViewCellContainer leaves; 
    3135                         mViewCellsTree->CollectLeaves(vc, leaves); 
    3136  
    3137                         ViewCellContainer::const_iterator lit, lit_end = leaves.end(); 
    3138  
    3139                         for (lit = leaves.begin(); lit != lit_end; ++ lit) 
    3140                         { 
    3141                                 BspLeaf *l = dynamic_cast<BspViewCell *>(*lit)->mLeaf; 
    3142                                 exporter->ExportRays(l->mVssRays); 
    3143                         } 
    3144                 } 
    3145  
    3146          
    3147                 m.mDiffuseColor = RgbColor(1, 0, 0); 
    3148                 exporter->SetForcedMaterial(m); 
    3149  
    3150                 ObjectPvsMap::const_iterator it, 
    3151                         it_end = vc->GetPvs().mEntries.end(); 
    3152  
    3153                 exporter->SetFilled(); 
    3154  
    3155          
    3156                 // output PVS of view cell 
    3157                 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 
    3158                 { 
    3159                  
    3160                         Intersectable *intersect = (*it).first; 
    3161  
    3162                         if (!intersect->Mailed()) 
    3163                         { 
    3164                                 Material m = RandomMaterial(); 
    3165                                 exporter->SetForcedMaterial(m); 
    3166  
    3167                                 exporter->ExportIntersectable(intersect); 
    3168                                 intersect->Mail(); 
    3169                         } 
    3170                 } 
    3171  
    3172                  
     3211                        exporter->ExportGeometry(objects); 
     3212                } 
     3213 
    31733214                DEL_PTR(exporter); 
    31743215                cout << "finished" << endl; 
Note: See TracChangeset for help on using the changeset viewer.