Changeset 1570


Ignore:
Timestamp:
10/04/06 20:43:07 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
9 edited

Legend:

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

    r1566 r1570  
    6565        { 
    6666                VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay); 
     67                // ray is not pushed into the queue => can delete ray 
    6768                if (!HandleRay(newRay)) 
    68                 { 
    6969                        delete newRay; 
    70                 } 
     70                 
    7171                return true; 
    7272        } 
     
    7878bool GvsPreprocessor::HandleRay(VssRay *vssRay) 
    7979{ 
    80         mViewCellsManager->ComputeSampleContribution(*vssRay, true, false); 
     80        const bool storeRaysForViz = true; 
     81        mViewCellsManager->ComputeSampleContribution(*vssRay, true, storeRaysForViz); 
    8182                 
    8283        // some pvs contribution for this ray? 
     
    8586                //cout << " h " << mSampleContriPerPass << " " << mSamplesPerPass << " " << mTotalSamples << endl; 
    8687                mRayQueue.push(vssRay); 
    87                 mVssRays.push_back(new VssRay(*vssRay)); 
     88 
     89                if (storeRaysForViz) 
     90                { 
     91                        ViewCellContainer::const_iterator vit, vit_end = vssRay->mViewCells.end(); 
     92                        for (vit = vssRay->mViewCells.begin(); vit != vit_end; ++ vit) 
     93                        { 
     94                                (*vit)->mVssRays.push_back(new VssRay(*vssRay)); 
     95                        } 
     96                } 
     97                //mVssRays.push_back(new VssRay(*vssRay)); 
    8898        ++ mSampleContriPerPass; 
    8999 
     
    443453                mViewCellsManager->PrintPvsStatistics(mStats); 
    444454 
     455                char str[64]; sprintf(str, "tmp/pass%04d-", mPass); 
     456                 
    445457                // visualization 
    446 //              mViewCellsManager->Visualize(mVssRays); 
     458                const bool exportRays = true; 
     459                const bool exportPvs = true; 
     460                mViewCellsManager->ExportSingleViewCells(mObjects, 10, false, exportPvs, exportRays, 100, str); 
     461                // remove pass samples 
     462                ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end(); 
     463 
     464                for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit) 
     465                { 
     466                        CLEAR_CONTAINER((*vit)->mVssRays); 
     467                } 
     468 
    447469                CLEAR_CONTAINER(mVssRays); 
    448470                // ComputeRenderError(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1344 r1570  
    3939  /// unique object Id 
    4040  int mId; 
    41    
    4241  /// universal counter 
    4342  int mCounter; 
    44          
    45   /// object based pvs 
    46   KdPvs mKdPvs; 
    47    
    48   /// view cell based pvs per object 
    49   ViewCellPvs mViewCellPvs; 
    5043 
    5144  /// pointer to the container bvh leaf 
    5245  BvhLeaf *mBvhLeaf; 
    53  
     46  /// some rays piercing this intersectable 
    5447  VssRayContainer mVssRays; 
    5548 
    5649  /// # of references to this instance 
    5750  int mReferences; 
     51 
     52  ////////////////// 
     53  // note matt: delete these, they are only taking memory+ 
     54 
     55  /// object based pvs 
     56  KdPvs mKdPvs; 
     57  /// view cell based pvs per object 
     58  ViewCellPvs mViewCellPvs; 
     59         
     60  /////////////////////// 
    5861 
    5962  enum { MESH_INSTANCE,  
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp

    r1551 r1570  
    2727 
    2828 
     29        //////////// 
    2930//-- static members 
    3031 
     
    3940{ 
    4041        MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
    41 //return false; 
     42 
    4243        if (vdata) 
    4344        { 
     
    19681969{        
    19691970        contribution = 0; // todo 
    1970  
    19711971        MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
    19721972 
     
    19791979                obj->mViewCellPvs.AddSample(vc, 1); 
    19801980        } 
    1981          
    19821981        vdata->Mail(); 
    19831982 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1564 r1570  
    803803        } 
    804804 
    805         // should never come here 
    806         return NULL; 
     805        return NULL; // should never come here 
    807806} 
    808807 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1551 r1570  
    114114//mMailbox(0) 
    115115{ 
     116        mId = -100; 
    116117} 
    117118 
     
    127128//mMailbox(0) 
    128129{ 
     130        mId = -100; 
    129131} 
    130132 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1566 r1570  
    822822        int numSamples; 
    823823        int castSamples = 0; 
    824  
    825         char s[64];  
     824        char str[64];  
    826825 
    827826        Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesPerPass", samplesPerPass); 
     
    851850                // statistics before casting more samples 
    852851                cout << "compute new statistics ... "; 
    853                 sprintf(s, "-%09d-eval.log", castSamples); 
    854                 string fName = string(statsPrefix) + string(s); 
     852                sprintf(str, "-%09d-eval.log", castSamples); 
     853                string fName = string(statsPrefix) + string(str); 
    855854 
    856855                mViewCellsTree->ExportStats(fName); 
    857856                cout << "finished" << endl; 
    858857        } 
     858 
    859859        cout << "finished" << endl; 
    860  
    861860    cout << "Evaluating view cell partition ... " << endl; 
    862861 
     
    897896 
    898897                startTime = GetTime(); 
    899  
    900898                cout << "compute new statistics ... " << endl; 
    901899         
     
    905903 
    906904                //-- output stats 
    907                 sprintf(s, "-%09d-eval.log", castSamples); 
    908                 string fileName = string(statsPrefix) + string(s); 
     905                sprintf(str, "-%09d-eval.log", castSamples); 
     906                string fileName = string(statsPrefix) + string(str); 
    909907 
    910908                mViewCellsTree->ExportStats(fileName); 
     
    918916         
    919917 
    920         ////////////7 
     918        //////////// 
    921919        //-- histogram 
    922920 
     
    28242822        } 
    28252823 
    2826         // export single view cells 
    2827         ExportBspPvs(objects); 
     2824        int leafOut; 
     2825        Environment::GetSingleton()->GetIntValue("ViewCells.Visualization.maxOutput", leafOut); 
     2826        const int raysOut = 100; 
     2827        ExportSingleViewCells(objects, leafOut, false, true, false, raysOut, ""); 
    28282828} 
    28292829 
     
    28582858 
    28592859 
    2860 void BspViewCellsManager::ExportBspPvs(const ObjectContainer &objects) 
    2861 { 
    2862         const int leafOut = 10; 
     2860void BspViewCellsManager::ExportSingleViewCells(const ObjectContainer &objects, 
     2861                                                                                                const int maxViewCells, 
     2862                                                                                                const bool sortViewCells, 
     2863                                                                                                const bool exportPvs, 
     2864                                                                                                const bool exportRays, 
     2865                                                                                                const int maxRays, 
     2866                                                                                                const string prefix, 
     2867                                                                                                VssRayContainer *visRays) 
     2868{ 
     2869        if (sortViewCells) 
     2870        {       // sort view cells to visualize the largest view cells 
     2871                stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::LargerRenderCost); 
     2872        } 
     2873 
     2874        ////////// 
     2875        //-- some view cells for output 
     2876 
    28632877        ViewCell::NewMail(); 
    2864  
    2865         ////////// 
    2866         //-- some rays for output 
    2867         const int raysOut = min((int)mBspRays.size(), mVisualizationSamples); 
    2868  
    2869         cout << "visualization using " << mVisualizationSamples << " samples" << endl; 
    2870         Debug << "\nOutput view cells: " << endl; 
    2871  
    2872         // sort view cells in order to find the largest view cells 
    2873         if (0) stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 
    2874  
    2875         int limit = min(leafOut, (int)mViewCells.size()); 
    2876  
     2878        const int limit = min(maxViewCells, (int)mViewCells.size()); 
     2879         
    28772880        for (int i = 0; i < limit; ++ i) 
    28782881        { 
    2879                 cout << "creating output for view cell " << i << " ... "; 
    2880                 VssRayContainer vcRays; 
    2881                 Intersectable::NewMail(); 
    2882                 ViewCell *vc; 
    2883  
    2884                 if (0 || ((int)mViewCells.size() <= limit)) 
    2885                         vc = mViewCells[i]; 
    2886                 else 
    2887                         vc = mViewCells[Random((int)mViewCells.size())]; 
    2888  
    2889                 cout << "creating output for view cell " << i << " ... "; 
    2890  
    2891                 if(0) 
    2892                 { 
    2893                         // check whether we can add the current ray to the output rays 
    2894                         for (int k = 0; k < raysOut; ++ k) 
    2895                         { 
    2896                                 BspRay *ray = mBspRays[k]; 
    2897                                 for     (int j = 0; j < (int)ray->intersections.size(); ++ j) 
     2882                const int idx = sortViewCells ? (int)RandomValue(0, (float)mViewCells.size() - 0.5f) : i; 
     2883                ViewCell *vc = mViewCells[idx]; 
     2884 
     2885                if (vc->Mailed() || vc->GetId() == OUT_OF_BOUNDS_ID) 
     2886                        continue; 
     2887 
     2888                vc->Mail(); 
     2889 
     2890                ObjectPvs pvs; 
     2891                mViewCellsTree->GetPvs(vc, pvs); 
     2892 
     2893                char s[64]; sprintf(s, "%sviewcell%04d.wrl", prefix.c_str(), i); 
     2894                Exporter *exporter = Exporter::GetExporter(s); 
     2895                 
     2896                cout << "view cell " << idx << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 
     2897 
     2898                if (exportRays) 
     2899                { 
     2900                        //////////// 
     2901                        //-- export rays piercing this view cell 
     2902 
     2903                        // take rays stored with the view cells during subdivision 
     2904                        VssRayContainer vcRays; 
     2905            VssRayContainer collectRays; 
     2906 
     2907                        // collect initial view cells 
     2908                        ViewCellContainer leaves; 
     2909                        mViewCellsTree->CollectLeaves(vc, leaves); 
     2910 
     2911                        ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 
     2912                for (vit = leaves.begin(); vit != vit_end; ++ vit) 
     2913                        {        
     2914                                BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaves[0]; 
     2915                                VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 
     2916 
     2917                                for (rit = vcLeaf->mVssRays.begin(); rit != rit_end; ++ rit) 
    28982918                                { 
    2899                                         BspLeaf *leaf = ray->intersections[j].mLeaf; 
    2900                                         if (vc == leaf->GetViewCell()) 
    2901                                         { 
    2902                                                 vcRays.push_back(ray->vssRay); 
    2903                                         } 
     2919                                        collectRays.push_back(*rit); 
    29042920                                } 
    29052921                        } 
    2906                 } 
    2907  
    2908                 //bspLeaves[j]->Mail(); 
    2909                 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
    2910  
    2911                 Exporter *exporter = Exporter::GetExporter(s); 
     2922 
     2923                        const int raysOut = min((int)collectRays.size(), maxRays); 
     2924cout << "here500 " << raysOut << endl; 
     2925                        // prepare some rays for output 
     2926                        VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 
     2927                        for (rit = collectRays.begin(); rit != rit_end; ++ rit) 
     2928                        { 
     2929                                const float p = RandomValue(0.0f, (float)collectRays.size()); 
     2930                         
     2931                                if (p < raysOut) 
     2932                                { 
     2933                                        vcRays.push_back(*rit); 
     2934                                } 
     2935                        } 
     2936                        exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 
     2937                } 
     2938                 
     2939                //////////////// 
     2940                //-- export view cell geometry 
    29122941 
    29132942                exporter->SetWireframe(); 
     
    29182947 
    29192948                ExportViewCellGeometry(exporter, vc, NULL, NULL); 
     2949                exporter->SetFilled(); 
     2950 
     2951                if (exportPvs) 
     2952                { 
     2953                        Intersectable::NewMail(); 
     2954 
     2955                        ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 
     2956                        cout << endl; 
     2957                        // output PVS of view cell 
     2958                        for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
     2959                        {                
     2960                                Intersectable *intersect = (*oit).first; 
     2961                                 
     2962                                if (!intersect->Mailed()) 
     2963                                { 
     2964                                        intersect->Mail(); 
     2965                                        m = RandomMaterial(); 
     2966                                        exporter->SetForcedMaterial(m); 
     2967                                        exporter->ExportIntersectable(intersect); 
     2968                                        cout << " i: " << intersect; 
     2969                                } 
     2970                        } 
     2971                        cout << endl; 
     2972                } 
    29202973                 
    2921                 // export rays piercing this view cell 
    2922                 exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 
    2923  
    2924                 m.mDiffuseColor = RgbColor(1, 0, 0); 
    2925                 exporter->SetForcedMaterial(m); 
    2926  
    2927                 ObjectPvsMap::const_iterator it, 
    2928                         it_end = vc->GetPvs().mEntries.end(); 
    2929  
    2930                 exporter->SetFilled(); 
    2931  
    2932                 // output PVS of view cell 
    2933                 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 
    2934                 { 
    2935                         Intersectable *intersect = (*it).first; 
    2936  
    2937                         if (!intersect->Mailed()) 
    2938                         { 
    2939                                 Material m = RandomMaterial(); 
    2940                                 exporter->SetForcedMaterial(m); 
    2941  
    2942                                 exporter->ExportIntersectable(intersect); 
    2943                                 intersect->Mail(); 
    2944                         } 
    2945                 } 
    2946  
    29472974                DEL_PTR(exporter); 
    29482975                cout << "finished" << endl; 
    29492976        } 
    2950  
    2951         Debug << endl; 
    29522977} 
    29532978 
     
    29893014                                                                                                 const AxisAlignedBox3 *sceneBox, 
    29903015                                                                                                 const AxisAlignedPlane *clipPlane 
    2991                                                                                                         ) const 
     3016                                                                                                 ) const 
    29923017{ 
    29933018        if (clipPlane) 
     
    33363361 
    33373362 
     3363void KdViewCellsManager::ExportSingleViewCells(const ObjectContainer &objects, 
     3364                                                                                           const int maxViewCells, 
     3365                                                                                           const bool sortViewCells, 
     3366                                                                                           const bool exportPvs, 
     3367                                                                                           const bool exportRays, 
     3368                                                                                           const int maxRays, 
     3369                                                                                           const string prefix, 
     3370                                                                                           VssRayContainer *visRays) 
     3371{ 
     3372        // TODO 
     3373} 
     3374 
     3375 
    33383376void KdViewCellsManager::Visualize(const ObjectContainer &objects, 
    33393377                                                                   const VssRayContainer &sampleRays) 
     
    33923430 
    33933431                        ViewCell *vc = leaf->mViewCell; 
    3394  
    3395                         //bspLeaves[j]->Mail(); 
    3396                         char s[64]; sprintf(s, "kd-pvs%04d.x3d", i); 
    3397  
    3398                         Exporter *exporter = Exporter::GetExporter(s); 
     3432                        char str[64]; sprintf(str, "viewcell%04d.wrl", i); 
     3433 
     3434                        Exporter *exporter = Exporter::GetExporter(str); 
    33993435                        exporter->SetFilled(); 
    34003436 
     
    34633499 
    34643500                        exporter->SetFilled(); 
    3465  
    34663501                        delete exporter; 
    34673502                } 
     
    34703505                { 
    34713506                        Intersectable *object = objects[k]; 
    3472                         char s[64]; 
    3473                         sprintf(s, "sample-pvs%04d.x3d", k); 
    3474  
    3475                         Exporter *exporter = Exporter::GetExporter(s); 
     3507                        char str[64]; sprintf(str, "viewcell%04d.wrl", i); 
     3508 
     3509                        Exporter *exporter = Exporter::GetExporter(str); 
    34763510                        exporter->SetWireframe(); 
    34773511 
     
    37073741        ////////////////////// 
    37083742        //-- recast the rest of the rays 
     3743 
    37093744        startTime = GetTime(); 
    37103745 
     
    41654200        //////// 
    41664201        //-- export single view cells 
    4167         ExportBspPvs(objects, visRays); 
     4202         
     4203        int leafOut; 
     4204        Environment::GetSingleton()->GetIntValue("ViewCells.Visualization.maxOutput", leafOut); 
     4205        const int raysOut = 100; 
     4206         
     4207        ExportSingleViewCells(objects, leafOut, false, true, false, raysOut, ""); 
    41684208} 
    41694209 
     
    42004240                        exporter->ExportGeometry(objects); 
    42014241                } 
    4202  
    42034242                delete exporter; 
    42044243        } 
     
    42064245 
    42074246 
    4208 void VspBspViewCellsManager::ExportBspPvs(const ObjectContainer &objects, 
    4209                                                                                   const VssRayContainer &rays) 
    4210 { 
    4211         int leafOut; 
    4212         Environment::GetSingleton()->GetIntValue("ViewCells.Visualization.maxOutput", leafOut); 
     4247void VspBspViewCellsManager::ExportSingleViewCells(const ObjectContainer &objects, 
     4248                                                                                                   const int maxViewCells, 
     4249                                                                                                   const bool sortViewCells, 
     4250                                                                                                   const bool exportPvs, 
     4251                                                                                                   const bool exportRays, 
     4252                                                                                                   const int maxRays, 
     4253                                                                                                   const string prefix, 
     4254                                                                                                   VssRayContainer *visRays) 
     4255{        
     4256        if (sortViewCells) 
     4257        { 
     4258                // sort view cells to visualize the largest view cells 
     4259                stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::LargerRenderCost); 
     4260        } 
     4261 
     4262        ////////// 
     4263        //-- some view cells for output 
    42134264 
    42144265        ViewCell::NewMail(); 
    4215  
    4216         cout << "visualization using " << (int)rays.size() << " samples" << endl; 
    4217         Debug << "visualization using " << (int)rays.size() << " samples" << endl; 
    4218         Debug << "\nOutput view cells: " << endl; 
    4219  
    4220         const bool sortViewCells = true; 
    4221  
    4222         // sort view cells to visualize the largest view cells 
    4223         if (sortViewCells) 
    4224         { 
    4225                 //stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 
    4226                 stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::LargerRenderCost); 
    4227         } 
    4228  
    4229         ////////// 
    4230         //-- some rays for output 
    4231  
    4232         const int limit = min(leafOut, (int)mViewCells.size()); 
    4233         const int raysOut = min((int)rays.size(), 100); 
    4234  
     4266        const int limit = min(maxViewCells, (int)mViewCells.size()); 
     4267         
    42354268        for (int i = 0; i < limit; ++ i) 
    42364269        { 
    42374270                cout << "creating output for view cell " << i << " ... "; 
    42384271 
    4239                 ViewCell *vc; 
    4240          
    4241                 if (sortViewCells) // largest view cell pvs first 
    4242                         vc = mViewCells[i]; 
    4243                 else 
    4244                         vc = mViewCells[(int)RandomValue(0, (float)mViewCells.size() - 1)]; 
     4272                ViewCell *vc = sortViewCells ? // largest view cell pvs first? 
     4273                        mViewCells[(int)RandomValue(0, (float)mViewCells.size() - 0.5f)] : mViewCells[i]; 
     4274 
     4275                if (vc->Mailed() || vc->GetId() == OUT_OF_BOUNDS_ID) 
     4276                        continue; 
     4277 
     4278                vc->Mail(); 
    42454279 
    42464280                ObjectPvs pvs; 
    42474281                mViewCellsTree->GetPvs(vc, pvs); 
    42484282 
    4249                 char s[64]; sprintf(s, "bsp-pvs%04d.wrl", i); 
     4283                char s[64]; sprintf(s, "%sviewcell%04d.wrl", prefix.c_str(), i); 
    42504284                Exporter *exporter = Exporter::GetExporter(s); 
    42514285                 
    4252                 Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 
    4253  
    4254                 if (mExportRays) 
     4286                cout << "view cell " << vc->GetId() << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 
     4287 
     4288                if (exportRays) 
    42554289                { 
    42564290                        //////////// 
     
    42674301                        ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 
    42684302                for (vit = leaves.begin(); vit != vit_end; ++ vit) 
    4269                         { 
     4303                        {        
    42704304                                BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaves[0]; 
    42714305                                VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 
     
    42774311                        } 
    42784312 
     4313                        const int raysOut = min((int)collectRays.size(), maxRays); 
     4314                        cout << "here500 " << raysOut << endl; 
    42794315                        // prepare some rays for output 
    42804316                        VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 
     
    43044340                exporter->SetFilled(); 
    43054341 
    4306                 if (1) 
    4307                 { 
    4308                         //////// 
    4309                         //-- export pvs 
     4342                if (exportPvs) 
     4343                { 
    43104344                        Intersectable::NewMail(); 
     4345 
    43114346                        ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 
    4312                          
     4347                        cout << endl; 
    43134348                        // output PVS of view cell 
    43144349                        for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
    43154350                        {                
    43164351                                Intersectable *intersect = (*oit).first; 
     4352                                 
    43174353                                if (!intersect->Mailed()) 
    43184354                                { 
     4355                                        intersect->Mail(); 
    43194356                                        m = RandomMaterial(); 
    43204357                                        exporter->SetForcedMaterial(m); 
    4321  
    43224358                                        exporter->ExportIntersectable(intersect); 
    4323                                         intersect->Mail(); 
     4359                                        cout << " i: " << intersect; 
    43244360                                } 
    43254361                        } 
     4362                        cout << endl; 
    43264363                } 
    43274364                 
    4328                 if (0) 
    4329                 {   // export scene geometry 
    4330                         m.mDiffuseColor = RgbColor(1, 0, 0); 
    4331                         exporter->SetForcedMaterial(m); 
    4332  
    4333                         exporter->ExportGeometry(objects); 
    4334                 } 
    4335  
    43364365                DEL_PTR(exporter); 
    43374366                cout << "finished" << endl; 
    43384367        } 
    4339  
    4340         Debug << endl; 
    43414368} 
    43424369 
     
    51055132        } 
    51065133         
    5107         // export pvss of some view cell 
    5108         ExportPvs(objects, visRays); 
    5109 } 
    5110  
    5111  
    5112 void VspOspViewCellsManager::ExportPvs(const ObjectContainer &objects, 
    5113                                                                            const VssRayContainer &rays) 
    5114 { 
     5134        // export some view cell 
    51155135        int leafOut; 
    51165136        Environment::GetSingleton()->GetIntValue("ViewCells.Visualization.maxOutput", leafOut); 
    5117  
    5118         ViewCell::NewMail(); 
    5119  
    5120         cout << "visualization using " << (int)rays.size() << " samples" << endl; 
    5121         Debug << "visualization using " << (int)rays.size() << " samples" << endl; 
    5122          
    5123         const bool sortedViewCells = false; 
    5124  
    5125         if (sortedViewCells) 
     5137        const int raysOut = 100; 
     5138 
     5139        ExportSingleViewCells(objects, leafOut, false, true, false, raysOut, ""); 
     5140} 
     5141 
     5142 
     5143void VspOspViewCellsManager::ExportSingleViewCells(const ObjectContainer &objects, 
     5144                                                                                                   const int maxViewCells, 
     5145                                                                                                   const bool sortViewCells, 
     5146                                                                                                   const bool exportPvs, 
     5147                                                                                                   const bool exportRays, 
     5148                                                                                                   const int maxRays, 
     5149                                                                                                   const string prefix, 
     5150                                                                                                   VssRayContainer *visRays) 
     5151{ 
     5152        if (sortViewCells) 
    51265153        { 
    51275154                // sort view cells to visualize the view cells with highest render cost 
     
    51295156        } 
    51305157 
    5131         int limit = min(leafOut, (int)mViewCells.size()); 
    5132         int raysOut = 0; 
    5133  
    5134         cout << "\nOutput of " << limit << " view cells: " << endl; 
    5135  
    5136         /////////////// 
    5137         //-- some rays for output 
     5158        ViewCell::NewMail(); 
     5159        const int limit = min(maxViewCells, (int)mViewCells.size()); 
     5160         
     5161        cout << "\nExporting " << limit << " single view cells: " << endl; 
    51385162         
    51395163        for (int i = 0; i < limit; ++ i) 
     
    51425166                 
    51435167                // largest view cell pvs first of random view cell 
    5144                 ViewCell *vc = sortedViewCells ?  
     5168                ViewCell *vc = sortViewCells ?  
    51455169                        mViewCells[i] : mViewCells[(int)RandomValue(0, (float)mViewCells.size() - 1)]; 
    51465170                 
     5171                if (vc->Mailed()) // already used 
     5172                        continue; 
     5173 
     5174                vc->Mail(); 
     5175 
    51475176                ObjectPvs pvs; 
    51485177                mViewCellsTree->GetPvs(vc, pvs); 
    51495178 
    5150                 char s[64]; sprintf(s, "bsp-pvs%04d.wrl", i); 
     5179                char s[64]; sprintf(s, "%sviewcell%04d.wrl", prefix.c_str(), i); 
    51515180                Exporter *exporter = Exporter::GetExporter(s); 
    51525181                 
    5153                 Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 
    5154  
    5155                 //////////// 
    5156                 //-- export the sample rays 
    5157  
    5158                 if (1 || mExportRays) 
    5159                 { 
    5160                         // output rays stored with the view cells during subdivision 
    5161                         if (1) 
    5162                         { 
    5163                                 VssRayContainer vcRays; 
    5164                 VssRayContainer collectRays; 
    5165  
    5166                                 raysOut = min((int)rays.size(), 100); 
    5167  
    5168                                 // collect intial view cells 
    5169                                 ViewCellContainer leaves; 
    5170                                 mViewCellsTree->CollectLeaves(vc, leaves); 
    5171  
    5172                                 ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 
    5173         
    5174                                 for (vit = leaves.begin(); vit != vit_end; ++ vit) 
     5182                cout << "view cell " << vc->GetId() << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 
     5183 
     5184                if (exportPvs) 
     5185                { 
     5186                        Material m; 
     5187 
     5188                        Intersectable::NewMail(); 
     5189                        ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 
     5190                         
     5191                        // output PVS of view cell 
     5192                        for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
     5193                        {                
     5194                                Intersectable *intersect = (*oit).first; 
     5195                                if (!intersect->Mailed()) 
    51755196                                { 
    5176                                         VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLeaves[0]; 
    5177                                         VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 
    5178  
    5179                                         for (rit = vcLeaf->mVssRays.begin(); rit != rit_end; ++ rit) 
    5180                                         { 
    5181                                                 collectRays.push_back(*rit); 
    5182                                         } 
    5183                                 } 
    5184  
    5185                                 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 
    5186  
    5187                                 for (rit = collectRays.begin(); rit != rit_end; ++ rit) 
    5188                                 { 
    5189                                         const float p = RandomValue(0.0f, (float)collectRays.size()); 
    5190                          
    5191                                         if (p < raysOut) 
    5192                                                 vcRays.push_back(*rit); 
    5193                                 } 
    5194                                  
    5195                                 //-- export rays piercing this view cell 
    5196                                 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 
    5197  
    5198                                 //-- export objects seen from the rays 
    5199                                 Intersectable::NewMail(); 
    5200                                  
    5201                                 VssRayContainer::const_iterator vcit, vcit_end = vcRays.end(); 
    5202                                 for (vcit = vcRays.begin(); vcit != vcit_end; ++ vcit) 
    5203                                 { 
    5204                                         VssRay *ray = *vcit; 
    5205                                         //Intersectable *obj = ray->mTerminationObject; 
    5206                                         Intersectable *obj = mHierarchyManager->GetIntersectable(*ray, true); 
    5207                                          
    5208                                         if (obj && !obj->Mailed()) 
    5209                                         { 
    5210                                                 obj->Mail(); 
    5211                                                 exporter->ExportIntersectable(obj); 
    5212                                         } 
     5197                                        m = RandomMaterial(); 
     5198                                        exporter->SetForcedMaterial(m); 
     5199 
     5200                                        exporter->ExportIntersectable(intersect); 
     5201                                        intersect->Mail(); 
    52135202                                } 
    52145203                        } 
    52155204                } 
    52165205 
     5206                if (exportRays) 
     5207                { 
     5208                        //////////// 
     5209                        //-- export the sample rays 
     5210 
     5211                        // output rays stored with the view cells during subdivision 
     5212                        VssRayContainer vcRays; 
     5213                        VssRayContainer collectRays; 
     5214 
     5215                        // collect intial view cells 
     5216                        ViewCellContainer leaves; 
     5217                        mViewCellsTree->CollectLeaves(vc, leaves); 
     5218 
     5219                        ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 
     5220 
     5221                        for (vit = leaves.begin(); vit != vit_end; ++ vit) 
     5222                        { 
     5223                                VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLeaves[0]; 
     5224                                VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 
     5225 
     5226                                for (rit = vcLeaf->mVssRays.begin(); rit != rit_end; ++ rit) 
     5227                                { 
     5228                                        collectRays.push_back(*rit); 
     5229                                } 
     5230                        } 
     5231 
     5232                        const int raysOut = min((int)collectRays.size(), maxRays); 
     5233 
     5234                        VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 
     5235 
     5236                        for (rit = collectRays.begin(); rit != rit_end; ++ rit) 
     5237                        { 
     5238                                const float p = RandomValue(0.0f, (float)collectRays.size()); 
     5239 
     5240                                if (p < raysOut) 
     5241                                        vcRays.push_back(*rit); 
     5242                        } 
     5243 
     5244                        exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 
     5245                } 
     5246                 
     5247         
    52175248                ///////////////// 
    52185249                //-- export view cell geometry 
     
    52315262        } 
    52325263 
    5233         Debug << endl; 
     5264        cout << endl; 
    52345265} 
    52355266 
     
    55355566void VspOspViewCellsManager::EvalViewCellPartition() 
    55365567{ 
    5537         int castSamples = (int)storedRays.size(); 
    5538  
     5568        const int castSamples = (int)storedRays.size(); 
    55395569        char s[64];  
    55405570        char statsPrefix[100]; 
     
    55455575 
    55465576        // should directional sampling be used? 
    5547         bool dirSamples = (mEvaluationSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION); 
     5577        const bool dirSamples = (mEvaluationSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION); 
    55485578 
    55495579        cout << "reseting pvs ... "; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1557 r1570  
    113113        /** Computes sample contribution of a simgle ray to the view cells PVS. 
    114114                @param ray finds intersections with view cells and holds the contribution 
    115                 @param castRay true if ray should be cast to gain the information, false if ray 
    116                 is already holding the information and need not be recast. 
    117            
     115                @param addSample if sample should be added to the pvs 
     116                   
    118117                @returns number of sample contributions 
    119118        */ 
     
    497496        bool GetStoreKdPVs() const; 
    498497 
     498        /** Adds a sample to the pvs of the specified view cell. 
     499                @param obj the hit object 
     500                @param hitPoint the point where the object is hit. 
     501                @param vc the sanpled view cell 
     502                @param pdf probability of the ray 
     503                @param contribution the relative pvs contribution 
     504                @returns true if the sample gives a contribution to the pvs. 
     505        */ 
    499506        virtual bool AddSampleToPvs( 
    500507                Intersectable *obj,  
     
    503510                const float pdf,  
    504511                float &contribution) const; 
     512 
     513        /** Exports single view cells for visualization. 
     514                @param objects the scene objects 
     515                @param limit the maximal number of output view cells 
     516                @param sortViewCells if the view cells should be sorted by pvs size 
     517                @param exportPvs if the pvs should also be exported 
     518                @param exportRays if sample rays should be exported as well 
     519                @param visRays additional rays 
     520        */ 
     521        virtual  
     522                void ExportSingleViewCells( 
     523                const ObjectContainer &objects, 
     524                const int maxViewCells, 
     525                const bool sortViewCells, 
     526                const bool exportPvs, 
     527                const bool exportRays, 
     528                const int maxRays, 
     529                const string prefix, 
     530                VssRayContainer *visRays = NULL) = NULL; 
    505531 
    506532protected: 
     
    662688        /// the width of the box filter 
    663689        float mFilterWidth; 
     690        /// Maximal size of the filter in terms of contributing view cells 
    664691        int mMaxFilterSize; 
    665  
    666         bool mStoreObjectPvs; 
     692         
     693         
    667694 
    668695        ////////////////// 
     
    670697         
    671698        /// color code for view cells visualization 
    672                 bool mShowVisualization; 
     699        bool mShowVisualization; 
    673700        int mColorCode; 
    674701        bool mExportGeometry; 
     
    751778        ViewCell *ConstructSpatialMergeTree(BspNode *root); 
    752779 
     780        void ExportSingleViewCells( 
     781                const ObjectContainer &objects, 
     782                const int maxViewCells, 
     783                const bool sortViewCells, 
     784                const bool exportPvs, 
     785                const bool exportRays, 
     786                const int maxRays, 
     787                const string prefix, 
     788                VssRayContainer *visRays = NULL); 
    753789 
    754790protected: 
     
    769805        */ 
    770806        void ExportSplits(const ObjectContainer &objects); 
    771  
    772         /** Exports visualization of the BSP PVS. 
    773         */ 
    774         void ExportBspPvs(const ObjectContainer &objects); 
    775807 
    776808        /** test if subdivision is valid in terms of volume / area. 
     
    830862                                                                vector<MergeCandidate> &candidates); 
    831863 
     864        void ExportSingleViewCells( 
     865                const ObjectContainer &objects, 
     866                const int maxViewCells, 
     867                const bool sortViewCells, 
     868                const bool exportPvs, 
     869                const bool exportRays, 
     870                const int maxRays, 
     871                const string prefix, 
     872                VssRayContainer *visRays = NULL); 
    832873 
    833874protected: 
     
    839880        KdNode *GetNodeForPvs(KdLeaf *leaf); 
    840881 
     882        //////////////////////////////////////// 
    841883 
    842884        /// the BSP tree. 
     
    849891}; 
    850892 
    851 /** 
    852         Manages different higher order operations on the view cells. 
     893 
     894/** Manages different higher order operations on the view cells. 
    853895*/ 
    854896class VspBspViewCellsManager: public ViewCellsManager 
     
    914956 
    915957 
     958        void ExportSingleViewCells( 
     959                const ObjectContainer &objects, 
     960                const int maxViewCells, 
     961                const bool sortViewCells, 
     962                const bool exportPvs, 
     963                const bool exportRays, 
     964                const int maxRays, 
     965                const string prefix, 
     966                VssRayContainer *visRays = NULL); 
     967 
     968 
    916969protected: 
    917970 
     
    9611014        void ExportSplits(const ObjectContainer &objects,  
    9621015                                          const VssRayContainer &rays); 
    963  
    964         /** Exports visualization of the BSP PVS. 
    965         */ 
    966         void ExportBspPvs(const ObjectContainer &objects, 
    967                                           const VssRayContainer &rays); 
    968  
    9691016 
    9701017        /// the view space partition BSP tree. 
     
    10491096        float &contribution) const; 
    10501097 
     1098        void ExportSingleViewCells( 
     1099                const ObjectContainer &objects, 
     1100                const int maxViewCells, 
     1101                const bool sortViewCells, 
     1102                const bool exportPvs, 
     1103                const bool exportRays, 
     1104                const int maxRays, 
     1105                const string prefix, 
     1106                VssRayContainer *visRays = NULL); 
     1107 
    10511108protected: 
    10521109 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1551 r1570  
    5656} 
    5757 
    58  
     58#if WORK_WITH_VIEWCELLS 
    5959static bool ViewCellHasMultipleReferences(Intersectable *obj,  
    6060                                                                                  ViewCell *vc,  
     
    7575                } 
    7676        } 
    77  
     77         
    7878        return false; 
    7979} 
    8080 
     81 
     82void VspTree::RemoveParentViewCellReferences(ViewCell *parent) const 
     83{ 
     84        KdLeaf::NewMail(); 
     85 
     86        // remove the parents from the object pvss 
     87        ObjectPvsMap::const_iterator oit, oit_end = parent->GetPvs().mEntries.end(); 
     88 
     89        for (oit = parent->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     90        { 
     91                Intersectable *object = (*oit).first; 
     92                // HACK: make sure that the view cell is removed from the pvs 
     93                const float high_contri = 9999999; 
     94 
     95                // remove reference count of view cells 
     96                object->mViewCellPvs.RemoveSample(parent, high_contri); 
     97        } 
     98} 
     99 
     100 
     101void VspTree::AddViewCellReferences(ViewCell *vc) const 
     102{ 
     103        KdLeaf::NewMail(); 
     104 
     105        // Add front view cell to the object pvsss 
     106        ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end(); 
     107 
     108        for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     109        { 
     110                Intersectable *object = (*oit).first; 
     111 
     112                // increase reference count of view cells 
     113                object->mViewCellPvs.AddSample(vc, 1); 
     114        } 
     115} 
     116 
     117#endif 
    81118 
    82119void VspTreeStatistics::Print(ostream &app) const 
     
    826863        ++ mVspStats.splits[splitPlane.mAxis]; 
    827864 
    828     /////////////////////////////////////////// 
     865 
     866    /////////////////////// 
    829867        //-- create front and back and subdivide further 
    830868 
     
    837875                parent->ReplaceChildLink(leaf, interior); 
    838876                interior->SetParent(parent); 
    839  
     877#if WORK_WITH_VIEWCELLS 
    840878                // remove "parent" view cell from pvs of all objects (traverse trough rays) 
    841879                RemoveParentViewCellReferences(tData.mNode->GetViewCell()); 
     880#endif 
    842881        } 
    843882        else // new root 
     
    866905#if WORK_WITH_VIEWCELL_PVS 
    867906        // create front and back view cell 
    868         // add front and back view cell to "Potentially Visbilie View Cells"  
     907        // add front and back view cell to  
     908        // "potentially visible view cells"  
    869909        // of the objects in front and back pvs 
    870910 
     
    880920 
    881921 
    882 void VspTree::RemoveParentViewCellReferences(ViewCell *parent) const 
    883 { 
    884         KdLeaf::NewMail(); 
    885  
    886         // remove the parents from the object pvss 
    887         ObjectPvsMap::const_iterator oit, oit_end = parent->GetPvs().mEntries.end(); 
    888  
    889         for (oit = parent->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
    890         { 
    891                 Intersectable *object = (*oit).first; 
    892                 // HACK: make sure that the view cell is removed from the pvs 
    893                 const float high_contri = 9999999; 
    894  
    895                 // remove reference count of view cells 
    896                 object->mViewCellPvs.RemoveSample(parent, high_contri); 
    897         } 
    898 } 
    899  
    900  
    901 void VspTree::AddViewCellReferences(ViewCell *vc) const 
    902 { 
    903         KdLeaf::NewMail(); 
    904  
    905         // Add front view cell to the object pvsss 
    906         ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end(); 
    907  
    908         for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
    909         { 
    910                 Intersectable *object = (*oit).first; 
    911  
    912                 // increase reference count of view cells 
    913                 object->mViewCellPvs.AddSample(vc, 1); 
    914         } 
    915 } 
    916922 
    917923 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r1449 r1570  
    615615                                                                ViewCellContainer &viewCells) const; 
    616616 
     617        /** Returns view cells of this ray, either taking precomputed cells 
     618                or by recomputation. 
     619        */ 
     620        void GetViewCells(const VssRay &ray, ViewCellContainer &viewCells); 
     621 
     622        /** Returns view cells tree. 
     623        */ 
     624        ViewCellsTree *GetViewCellsTree() const { return mViewCellsTree; } 
     625 
     626        /** Sets the view cells tree. 
     627        */ 
     628        void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; } 
     629 
     630#if WORK_WITH_VIEWCELLS 
    617631        /** Remove the references of the parent view cell from the kd nodes associated with 
    618632                the objects. 
     
    623637        */ 
    624638        void AddViewCellReferences(ViewCell *vc) const; 
    625  
    626         /** Returns view cells of this ray, either taking precomputed cells 
    627                 or by recomputation. 
    628         */ 
    629         void GetViewCells(const VssRay &ray, ViewCellContainer &viewCells); 
    630  
    631         /** Returns view cells tree. 
    632         */ 
    633         ViewCellsTree *GetViewCellsTree() const { return mViewCellsTree; } 
    634  
    635         /** Sets the view cells tree. 
    636         */ 
    637         void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; } 
    638  
     639#endif 
    639640 
    640641protected: 
Note: See TracChangeset for help on using the changeset viewer.