Changeset 477


Ignore:
Timestamp:
12/22/05 01:36:06 (18 years ago)
Author:
mattausch
Message:

changed render simulator (probability that view cell is crossed)

Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp

    r476 r477  
    8080                // compute render time of PVS times probability that view point is in view cell 
    8181                const float vcCost = pInVc * mViewCellsManager->GetRendercost(vc, mObjRenderCost); 
    82                 Debug << "cost: " << vcCost << " rcost: " << mViewCellsManager->GetRendercost(vc, mObjRenderCost) << endl; 
     82                Debug << "cost: " << vcCost << " rcost: " 
     83                          << mViewCellsManager->GetRendercost(vc, mObjRenderCost) << endl; 
    8384 
    8485                // crossing the border of a view cell is depending on the move speed 
     
    104105} 
    105106 
    106 float RenderSimulator::GetCrossVcProbability() 
     107float RenderSimulator::GetCrossVcProbability() const 
    107108{ 
    108         /*const float avgArea = mViewCellsManager->GetTotalArea() /  
    109                 mViewCellsManager->GetViewCells().size(); 
     109        // assume the view cells are uniformly distributed 
     110        const float vcNum =  
     111                (float)mViewCellsManager->GetViewCells().size(); 
    110112 
    111         return mMoveSpeed * mViewCellsManager->GetSceneBbox()->SurfaceArea() /  */ 
    112         return 0; 
     113        return 1.0f - (1 / mMoveSpeed * vcNum); 
    113114} 
    114115 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h

    r473 r477  
    8282        /** Probability for crossing one view cell. 
    8383        */ 
    84         float GetCrossVcProbability(); 
     84        float GetCrossVcProbability() const; 
    8585 
    8686        /// render time for single object of the PVS 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp

    r475 r477  
    176176  if (!use2dSampling) { 
    177177        Vector3 normal; 
    178         int i = (int)RandomValue(0, mObjects.size()-1); 
     178        int i = (int)RandomValue(0, (Real)((int)mObjects.size()-1)); 
    179179        Intersectable *object = mObjects[i]; 
    180180        object->GetRandomSurfacePoint(point, normal); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r475 r477  
    151151                // pickup a random face of each mesh  
    152152                Mesh *mesh = mi->GetMesh(); 
    153                 int face = (int)RandomValue(0, (int)mesh->mFaces.size() - 1); 
     153                int face = (int)RandomValue(0, (Real)((int)mesh->mFaces.size() - 1)); 
    154154                 
    155155                Polygon3 poly(mesh->mFaces[face], mesh); 
    156156                poly.Scale(1.001f); 
    157157                // now extend a random edge of the face 
    158                 int edge = (int)RandomValue(0, (int)poly.mVertices.size() - 1); 
     158                int edge = (int)RandomValue(0, (Real)((int)poly.mVertices.size() - 1)); 
    159159                float t = RandomValue(0.0f, 1.0f); 
    160160                Vector3 target = t*poly.mVertices[edge] + (1.0f-t)*poly.mVertices[(edge + 1)% 
     
    192192                Debug << "Finding random neighbour" << endl;     
    193193                for (int tries = 0; tries < 10; tries++) { 
    194                         int index = (int)RandomValue(0, pvsSize - 1); 
     194                        int index = (int)RandomValue(0, (Real)(pvsSize - 1)); 
    195195                        KdPvsData data; 
    196196                        KdNode *node; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r475 r477  
    281281} 
    282282 
     283 
    283284float ViewCellsManager::GetVolume(ViewCell *viewCell) const 
    284285{ 
     
    287288 
    288289 
    289  
    290290float ViewCellsManager::GetArea(ViewCell *viewCell) const 
    291291{ 
     
    294294 
    295295 
    296  
    297 float ViewCellsManager::GetTotalArea() 
     296float ViewCellsManager::GetAccVcArea() 
    298297{ 
    299298        // if already computed 
     
    316315        s << mViewCellsStats << endl; 
    317316} 
     317 
    318318 
    319319/**********************************************************************/ 
     
    409409{ 
    410410        // compute view cell area as subsititute for probability 
     411#if 0 
    411412        return GetArea(viewCell) / mBspTree->GetBoundingBox().SurfaceArea(); 
    412         //return GetArea(viewCell) / GetTotalArea(); 
    413 } 
     413#else 
     414        return GetArea(viewCell) / GetAccVcArea(); 
     415#endif 
     416} 
     417 
    414418 
    415419float BspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) const 
    416420{ 
    417421        return viewCell->GetPvs().GetSize() * objRendercost; 
     422} 
     423 
     424 
     425AxisAlignedBox3 BspViewCellsManager::GetSceneBbox() const 
     426{ 
     427        return mBspTree->GetBoundingBox(); 
    418428} 
    419429 
     
    430440                                                                         const VssRayContainer &rays) 
    431441{ 
     442        if (mBspRays.empty()) 
     443                ConstructBspRays(rays, mConstructionSamples); 
     444         
    432445        if (!ViewCellsConstructed()) 
    433446        { 
     
    442455        Debug << "original view cell partition:\n" << mViewCellsStats << endl; 
    443456                 
    444         if (1) // export view cells before merge 
     457        if (1) // export view cells 
    445458        { 
    446459                cout << "exporting initial view cells (=leaves) ... "; 
     
    449462                if (exporter) 
    450463                { 
    451                         exporter->SetWireframe(); 
    452                         exporter->ExportBspLeaves(*mBspTree, mViewCellsStats.maxPvs); 
    453                         //exporter->ExportBspViewCellPartition(*mBspTree, 0); 
     464                        //exporter->SetWireframe(); 
     465                        exporter->SetFilled(); 
     466                        exporter->ExportBspViewCellPartition(*mBspTree,  
     467                                mViewCellsStats.maxPvs); 
    454468                                 
    455469                        if (0) 
    456470                        { 
    457                                 Material m;//= RandomMaterial(); 
     471                                Material m; 
    458472                                m.mDiffuseColor = RgbColor(0, 1, 0); 
    459473                                exporter->SetForcedMaterial(m); 
     
    466480                } 
    467481                cout << "finished" << endl; 
    468  
    469                 //-- render simulation after merge 
    470                 cout << "\nevaluating bsp view cells render time after merge ... "; 
    471    
    472                  mRenderSimulator->RenderScene(); 
    473                  SimulationStatistics ss; 
    474                  mRenderSimulator->GetStatistics(ss); 
    475           
    476                  cout << " finished" << endl; 
    477                  cout << ss << endl; 
    478                  Debug << ss << endl; 
    479  
    480482        } 
    481483 
    482484        cout << "starting post processing using " << mPostProcessSamples << " samples ... "; 
    483  
     485                 
    484486        long startTime = GetTime(); 
     487 
    485488 
    486489        // $$JB we do not have connectivity information from the ray in the moment 
     
    489492        //-- merge or subdivide view cells 
    490493        int merged = 0; 
    491 #if 0 
    492  
    493         RayContainer::const_iterator rit, rit_end = rays.end(); 
     494 
    494495        vector<BspIntersection>::const_iterator iit; 
    495496 
    496         int limit = min((int)rays.size(), mPostProcessSamples); 
    497  
    498         for (int i = 0; i < limit; ++ i) 
     497        for (int i = 0; i < (int)mBspRays.size(); ++ i) 
    499498        {   
    500                 Ray *ray = rays[i]; 
    501  
     499                BspRay *ray = mBspRays[i]; 
     500           
    502501                // traverse leaves stored in the rays and compare and merge consecutive 
    503502                // leaves (i.e., the neighbors in the tree) 
    504                 if (ray->bspIntersections.size() < 2) 
     503                if (ray->intersections.size() < 2) 
    505504                        continue; 
    506  
    507                 iit = ray->bspIntersections.begin(); 
     505           
     506                iit = ray->intersections.begin(); 
    508507 
    509508                BspLeaf *previousLeaf = (*iit).mLeaf; 
    510509                ++ iit; 
    511510                 
    512                 for (; iit != ray->bspIntersections.end(); ++ iit) 
     511                for (; iit != ray->intersections.end(); ++ iit) 
    513512                { 
    514513                        BspLeaf *leaf = (*iit).mLeaf; 
     
    524523                } 
    525524        } 
    526 #endif 
     525 
    527526        //-- stats and visualizations 
    528527        cout << "finished" << endl; 
     
    531530 
    532531        Debug << "Postprocessing: Merged " << merged << " view cells in " 
    533                   << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
    534  
    535         //-- recount pvs 
     532                  << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 
     533         
     534        // reset view cells and stats 
     535        mViewCells.clear(); 
     536        mBspTree->CollectViewCells(mViewCells); 
    536537        mViewCellsStats.Reset(); 
    537538        mBspTree->EvaluateViewCellsStats(mViewCellsStats); 
     
    540541} 
    541542 
     543 
     544BspViewCellsManager::~BspViewCellsManager() 
     545{ 
     546        CLEAR_CONTAINER(mBspRays); 
     547} 
     548 
     549 
    542550int BspViewCellsManager::GetType() const 
    543551{ 
     
    551559        if (!ViewCellsConstructed()) 
    552560                return; 
    553    
    554         //-- recount pvs 
    555         ViewCellsStatistics vcStats; 
    556         mBspTree->EvaluateViewCellsStats(vcStats); 
    557    
     561 
     562        if (mBspRays.empty()) 
     563                ConstructBspRays(sampleRays, mConstructionSamples); 
     564         
    558565        if (1) // export view cells 
    559566        { 
    560567                cout << "exporting view cells after merge ... "; 
    561568                Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
    562            
     569 
    563570                if (exporter) 
    564571                { 
    565                         exporter->ExportBspViewCellPartition(*mBspTree, vcStats.maxPvs); 
    566                         //exporter->ExportBspViewCellPartition(*mBspTree, 0); 
     572                        exporter->ExportBspViewCellPartition(*mBspTree,  
     573                                mViewCellsStats.maxPvs); 
    567574                        delete exporter; 
    568575                } 
    569            
     576                 
    570577                cout << "finished" << endl; 
    571578        }        
    572    
     579 
    573580        //-- visualization of the BSP splits 
    574581        bool exportSplits = false; 
    575582        environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits); 
    576    
     583         
    577584        if (exportSplits) 
    578585        { 
    579586                cout << "exporting splits ... "; 
    580                 ExportSplits(objects, sampleRays); 
     587                ExportSplits(objects); 
    581588                cout << "finished" << endl; 
    582589        } 
    583    
    584         ExportBspPvs(objects, sampleRays); 
     590 
     591        ExportBspPvs(objects); 
    585592} 
    586593 
     
    591598} 
    592599 
    593 void BspViewCellsManager::ExportSplits(const ObjectContainer &objects, 
    594                                                                            const VssRayContainer &sampleRays) 
     600 
     601void BspViewCellsManager::ExportSplits(const ObjectContainer &objects) 
    595602{ 
    596603        Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 
     
    602609                exporter->SetForcedMaterial(m); 
    603610                exporter->SetWireframe(); 
     611                 
    604612                exporter->ExportBspSplits(*mBspTree, true); 
    605613 
     
    611619                exporter->ResetForcedMaterial(); 
    612620                 
    613                 bool exportRays = false; 
    614                 bool exportGeometry = false; 
    615  
    616                 environment->GetBoolValue("BspTree.Visualization.exportRays", exportRays); 
    617                 environment->GetBoolValue("BspTree.Visualization.exportGeometry", exportGeometry); 
    618  
    619621                // export rays 
    620                 if (exportRays) 
     622                if (0) 
    621623                { 
    622624                        VssRayContainer outRays; 
    623                    
    624                         int raysSize = min((int)sampleRays.size(), mVisualizationSamples); 
     625                 
     626                        int raysSize = min((int)mBspRays.size(), mVisualizationSamples); 
     627 
    625628                        for (int i = 0; i < raysSize; ++ i) 
    626                         { 
    627629                                // only rays piercing geometry 
    628                                 outRays.push_back(sampleRays[i]);                        
    629                         } 
    630                          
     630                                outRays.push_back(mBspRays[i]->vssRay); 
     631                                                 
    631632                        // export rays  
    632633                        exporter->ExportRays(outRays, RgbColor(1, 1, 0)); 
    633634                } 
    634                  
    635                 if (exportGeometry) 
     635 
     636                if (0) 
    636637                        exporter->ExportGeometry(objects); 
    637                  
     638 
    638639                delete exporter; 
    639640        } 
    640641} 
    641642 
    642 void BspViewCellsManager::ExportBspPvs(const ObjectContainer &objects, 
    643                                                                            const VssRayContainer &sampleRays) 
    644 { 
    645   const int leafOut = 10; 
    646    
    647   ViewCell::NewMail(); 
    648    
    649   //-- some rays for output 
    650   const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 
    651  
    652   Debug << "Output view cells:" << endl; 
    653  
    654   if (1) 
    655   { 
    656           //-- some random view cells and rays for output 
    657           vector<BspLeaf *> bspLeaves; 
    658            
    659           for (int i = 0; i < leafOut; ++ i) 
    660                   bspLeaves.push_back(mBspTree->GetRandomLeaf());        
    661  
    662           for (int i = 0; i < bspLeaves.size(); ++ i) 
    663           { 
    664                   BspLeaf *leaf = bspLeaves[i]; 
    665                   RayContainer vcRays; 
    666                    
    667                   cout << "creating output for view cell " << i << " ... "; 
    668                    
    669                   // TODO matt 
    670                   // check whether we can add the current ray to the output rays 
    671                   /*for (int k = 0; k < raysOut; ++ k)  
    672                   { 
    673                           Ray *ray = sampleRays[k]; 
    674                            
    675                           for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
    676                           { 
    677                                   BspLeaf *leaf2 = ray->bspIntersections[j].mLeaf; 
    678                                    
    679                                   if (leaf->GetViewCell() == leaf2->GetViewCell())  
    680                                   { 
    681                                           vcRays.push_back(ray); 
    682                                   } 
    683                           } 
    684                   }*/ 
    685                    
    686                   Intersectable::NewMail(); 
    687                    
    688                   BspViewCell *vc = dynamic_cast<BspViewCell *>(leaf->GetViewCell()); 
    689                    
    690                   //bspLeaves[j]->Mail(); 
    691                   char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
    692                    
    693                   Exporter *exporter = Exporter::GetExporter(s); 
    694                   exporter->SetFilled(); 
    695  
    696                   exporter->SetWireframe(); 
    697                   //exporter->SetFilled(); 
    698                    
    699                   Material m;//= RandomMaterial(); 
    700                   m.mDiffuseColor = RgbColor(1, 1, 0); 
    701                   exporter->SetForcedMaterial(m); 
    702                    
    703                   if (vc->GetMesh()) 
    704                           exporter->ExportViewCell(vc); 
    705                   else 
    706                   { 
    707                           PolygonContainer vcGeom; 
    708                           // export view cell geometry 
    709                           mBspTree->ConstructGeometry(vc, vcGeom); 
    710                           exporter->ExportPolygons(vcGeom); 
    711                           CLEAR_CONTAINER(vcGeom); 
    712                   }                
    713  
    714                   Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
    715                                 << ", piercing rays=" << (int)vcRays.size() << endl; 
    716                    
    717                   // export rays piercing this view cell 
    718                   //exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0));       
    719                    
    720                   m.mDiffuseColor = RgbColor(1, 0, 0); 
    721                   exporter->SetForcedMaterial(m); 
    722                    
    723                   // exporter->SetWireframe(); 
    724                   exporter->SetFilled(); 
    725                    
    726                   ObjectPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 
    727                   // output PVS of view cell 
    728                   for (it = vc->GetPvs().mEntries.begin(); it !=  it_end; ++ it)  
    729                   { 
    730                           Intersectable *intersect = (*it).first; 
    731                           if (!intersect->Mailed()) 
    732                           { 
    733                                   exporter->ExportIntersectable(intersect); 
    734                                   intersect->Mail(); 
    735                           }                      
    736                   } 
    737                    
    738                   DEL_PTR(exporter); 
    739                   cout << "finished" << endl; 
    740           } 
    741   } 
    742   else 
    743   { 
    744           ViewCellContainer viewCells; 
    745           RayContainer vcRays; 
    746            
    747           mBspTree->CollectViewCells(viewCells); 
    748           stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 
    749            
    750           const int limit = min(leafOut, (int)viewCells.size());  
    751            
    752           for (int i = 0; i < limit; ++ i) 
    753           { 
    754                   cout << "creating output for view cell " << i << " ... "; 
    755                          
    756                   Intersectable::NewMail(); 
    757                   BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]); 
    758  
    759                   cout << "creating output for view cell " << i << " ... "; 
    760  
    761                   // TODO matt 
    762                   // check whether we can add the current ray to the output rays 
    763                   /*for (int k = 0; k < raysOut; ++ k)  
    764                   { 
    765                           Ray *ray = sampleRays[k]; 
    766  
    767                           for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
    768                           { 
    769                                   BspLeaf *leaf = ray->bspIntersections[j].mLeaf; 
    770  
    771                                   if (vc == leaf->GetViewCell())  
    772                                           vcRays.push_back(ray); 
    773                           } 
    774                   }*/ 
    775  
    776                   //bspLeaves[j]->Mail(); 
    777                   char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
    778  
    779                   Exporter *exporter = Exporter::GetExporter(s);         
    780                   exporter->SetWireframe(); 
    781  
    782                   Material m;//= RandomMaterial(); 
    783                   m.mDiffuseColor = RgbColor(0, 1, 0); 
    784                   exporter->SetForcedMaterial(m); 
    785  
    786                   if (vc->GetMesh()) 
    787                           exporter->ExportViewCell(vc); 
    788                   else 
    789                   { 
    790                           PolygonContainer cell; 
    791                           // export view cell 
    792                           mBspTree->ConstructGeometry(vc, cell); 
    793                           exporter->ExportPolygons(cell); 
    794                           CLEAR_CONTAINER(cell); 
    795                   } 
    796                   Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
    797                             << ", piercing rays=" << (int)vcRays.size() << endl; 
    798  
    799                   // export rays piercing this view cell 
    800                   exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0)); 
    801          
    802                   m.mDiffuseColor = RgbColor(1, 0, 0); 
    803                   exporter->SetForcedMaterial(m); 
    804  
    805                   ObjectPvsMap::const_iterator it, it_end = vc->GetPvs().mEntries.end(); 
    806  
    807                   // output PVS of view cell 
    808                   for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it)  
    809                   { 
    810                           Intersectable *intersect = (*it).first; 
    811  
    812                           if (!intersect->Mailed()) 
    813                           { 
    814                                   Material m = RandomMaterial(); 
    815                                   exporter->SetForcedMaterial(m); 
    816  
    817                                   exporter->ExportIntersectable(intersect); 
    818                          
    819                                   intersect->Mail(); 
    820                           }                      
    821                   } 
     643 
     644void BspViewCellsManager::ExportBspPvs(const ObjectContainer &objects) 
     645{ 
     646        bool exportRays = false; 
     647        bool exportGeometry = false; 
     648 
     649        environment->GetBoolValue("VspBspTree.Visualization.exportRays", exportRays); 
     650        environment->GetBoolValue("VspBspTree.Visualization.exportGeometry", exportGeometry); 
     651 
     652        const int leafOut = 10; 
     653         
     654        ViewCell::NewMail(); 
     655 
     656        //-- some rays for output 
     657        const int raysOut = min((int)mBspRays.size(), mVisualizationSamples); 
     658        cout << "visualization using " << mVisualizationSamples << " samples" << endl; 
     659        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)  
     676                        { 
     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                                } 
     688                        } 
     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 
     713                        { 
     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); 
     754                                exporter->SetForcedMaterial(m); 
     755 
     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                        } 
    822853                                 
    823                   DEL_PTR(exporter); 
    824                   cout << "finished" << endl; 
    825           } 
    826   } 
     854                        DEL_PTR(exporter); 
     855                        cout << "finished" << endl; 
     856                } 
     857        } 
     858 
     859        Debug << endl; 
    827860} 
    828861 
     
    886919 
    887920 
     921void BspViewCellsManager::ConstructBspRays(const VssRayContainer &rays, 
     922                                                                                   const int numSamples) 
     923{ 
     924        VssRayContainer::const_iterator it, it_end = rays.end(); 
     925 
     926        for (it = rays.begin(); it != rays.end() && mBspRays.size() < numSamples; ++ it) 
     927        { 
     928                VssRay *vssRay = *it; 
     929                BspRay *ray = new BspRay(vssRay); 
     930 
     931                ViewCellContainer viewCells; 
     932 
     933                CastLineSegment(vssRay->mTermination, vssRay->mOrigin, viewCells); 
     934 
     935                ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     936                 
     937                for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     938                { 
     939                        BspViewCell *vc = dynamic_cast<BspViewCell *>(*vit); 
     940                        ray->intersections.push_back(BspIntersection(0, vc->mLeaves[0])); 
     941                } 
     942 
     943                mBspRays.push_back(ray); 
     944        } 
     945} 
     946 
    888947 
    889948/**********************************************************************/ 
     
    900959        // compute view cell area as subsititute for probability 
    901960        AxisAlignedBox3 box = mKdTree->GetBox(mKdTree->GetRoot()); 
    902  
     961#if 0 
    903962        return GetArea(viewCell) / box.SurfaceArea(); 
    904         //return GetArea(viewCell) / GetTotalArea(); 
     963#else 
     964        return GetArea(viewCell) / GetAccVcArea(); 
     965#endif 
    905966} 
    906967 
     
    909970{ 
    910971        return viewCell->GetPvs().GetSize() * objRendercost; 
     972} 
     973 
     974AxisAlignedBox3 KdViewCellsManager::GetSceneBbox() const 
     975{ 
     976        return mKdTree->GetBox(); 
    911977} 
    912978 
     
    11601226 
    11611227        return GetArea(viewCell) / box.SurfaceArea(); 
    1162         //return GetArea(viewCell) / GetTotalArea(); 
     1228        //return GetArea(viewCell) / GetAccVcArea(); 
    11631229} 
    11641230 
     
    12191285 
    12201286        return 0; 
     1287} 
     1288 
     1289AxisAlignedBox3 VspKdViewCellsManager::GetSceneBbox() const 
     1290{ 
     1291        return mVspKdTree->GetBBox(mVspKdTree->GetRoot()); 
    12211292} 
    12221293 
     
    13541425} 
    13551426 
     1427 
     1428 
    13561429/**********************************************************************/ 
    13571430/*                 VspBspViewCellsManager implementation              */ 
     
    13651438} 
    13661439 
     1440 
    13671441VspBspViewCellsManager::~VspBspViewCellsManager() 
    13681442{ 
     
    13701444} 
    13711445 
     1446 
    13721447float VspBspViewCellsManager::GetProbability(ViewCell *viewCell) 
    13731448{ 
    1374         return GetArea(viewCell) / mVspBspTree->GetBoundingBox().SurfaceArea(); 
    1375         //return GetArea(viewCell) / GetTotalArea(); 
    1376 } 
     1449#if 0 
     1450        return GetArea(viewCell) / mVspBspTree->GetBbox().SurfaceArea(); 
     1451#else 
     1452        return GetArea(viewCell) / GetAccVcArea(); 
     1453#endif 
     1454} 
     1455 
    13771456 
    13781457float VspBspViewCellsManager::GetArea(ViewCell *viewCell) const 
     
    13891468} 
    13901469 
    1391 float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) const 
     1470 
     1471float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell,  
     1472                                                                                        float objRendercost) const 
    13921473{ 
    13931474        return viewCell->GetPvs().GetSize() * objRendercost; 
     1475} 
     1476 
     1477 
     1478AxisAlignedBox3 VspBspViewCellsManager::GetSceneBbox() const 
     1479{ 
     1480        return mVspBspTree->GetBoundingBox(); 
    13941481} 
    13951482 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r475 r477  
    160160        virtual bool ViewCellsConstructed() const = 0; 
    161161 
    162   /** cast line segment to get a list of unique viewcells which are intersected 
    163           by this line segment */ 
     162        /** cast line segment to get a list of unique viewcells which are intersected 
     163                by this line segment  
     164        */ 
    164165   
    165   virtual int CastLineSegment(const Vector3 &origin, 
     166        virtual int CastLineSegment(const Vector3 &origin, 
    166167                                                          const Vector3 &termination, 
    167168                                                          ViewCellContainer &viewcells 
    168169                                                          ) = 0; 
    169170 
    170   virtual void GetPvsStatistics(PvsStatistics &stat); 
    171  
    172   virtual void 
    173   PrintPvsStatistics(ostream &s); 
    174  
    175   /** Returns probability that view point lies in one view cell. 
     171        virtual void GetPvsStatistics(PvsStatistics &stat); 
     172 
     173        virtual void PrintPvsStatistics(ostream &s); 
     174 
     175        /** Returns probability that view point lies in one view cell. 
     176        */ 
     177        virtual float GetProbability(ViewCell *viewCell) = 0; 
     178 
     179        /** Returns render cost of a single view cell given the render cost of an object. 
     180        */ 
     181        virtual float GetRendercost(ViewCell *viewCell, float objRendercost) const = 0; 
     182 
     183        /** Returns vector of loaded / generated view cells. 
     184        */ 
     185        ViewCellContainer &GetViewCells(); 
     186 
     187        /** Helper function used to split ray set into one used for view cell 
     188                construction and one cast after construction. 
     189        */ 
     190        void GetRaySets(const VssRayContainer &sourceRays, 
     191                                        VssRayContainer &constructionRays,  
     192                                        VssRayContainer &savedRays) const; 
     193 
     194  /** Returns accumulated area of all view cells. 
    176195  */ 
    177   virtual float GetProbability(ViewCell *viewCell) = 0; 
    178  
    179   /** Returns render cost of a single view cell given the render cost of an object. 
    180   */ 
    181   virtual float GetRendercost(ViewCell *viewCell, float objRendercost) const = 0; 
    182  
    183   /** Returns vector of loaded / generated view cells. 
    184   */ 
    185   ViewCellContainer &GetViewCells(); 
    186  
    187   /** Helper function used to split ray set into one used for view cell 
    188       construction and one cast after construction. 
    189   */ 
    190   void GetRaySets(const VssRayContainer &sourceRays, 
    191                                   VssRayContainer &constructionRays,  
    192                                   VssRayContainer &savedRays) const; 
    193  
    194   /** Returns total area of view cells. 
    195   */ 
    196   float GetTotalArea(); 
     196  float GetAccVcArea(); 
    197197 
    198198  /** Returns area of one view cell. 
     
    203203  */ 
    204204  float GetVolume(ViewCell *viewCell) const; 
     205 
     206  virtual AxisAlignedBox3 GetSceneBbox() const = 0; 
    205207 
    206208protected: 
     
    243245        BspViewCellsManager(BspTree *tree, int constructionSamples); 
    244246 
     247        ~BspViewCellsManager(); 
     248 
    245249        int Construct(const ObjectContainer &objects,  
    246250                                  const VssRayContainer &rays, 
     
    271275        float GetArea(ViewCell *viewCell) const; 
    272276 
     277        AxisAlignedBox3 GetSceneBbox() const; 
     278 
    273279protected: 
    274280 
     
    281287        bool ShouldMerge(BspLeaf *front, BspLeaf *back) const; 
    282288 
     289        void ConstructBspRays(const VssRayContainer &rays, 
     290                                                  const int numSamples); 
    283291        /// the BSP tree. 
    284292        BspTree *mBspTree; 
     
    290298        /** Exports visualization of the BSP splits. 
    291299        */ 
    292         void ExportSplits(const ObjectContainer &objects, const VssRayContainer &sampleRays); 
     300        void ExportSplits(const ObjectContainer &objects); 
    293301 
    294302        /** Exports visualization of the BSP PVS. 
    295303        */ 
    296         void ExportBspPvs(const ObjectContainer &objects, const VssRayContainer &sampleRays); 
     304        void ExportBspPvs(const ObjectContainer &objects); 
    297305 
    298306}; 
     
    334342        float GetProbability(ViewCell *viewCell); 
    335343        float GetRendercost(ViewCell *viewCell, float objRendercost) const; 
     344         
     345        AxisAlignedBox3 GetSceneBbox() const; 
    336346 
    337347protected: 
     
    385395        float GetRendercost(ViewCell *viewCell, float objRendercost) const; 
    386396 
     397        AxisAlignedBox3 GetSceneBbox() const; 
     398 
    387399protected: 
    388400 
     
    431443        float GetArea(ViewCell *viewCell) const; 
    432444 
     445        AxisAlignedBox3 GetSceneBbox() const; 
     446 
    433447protected: 
    434448 
Note: See TracChangeset for help on using the changeset viewer.