Ignore:
Timestamp:
12/14/05 19:38:39 (19 years ago)
Author:
bittner
Message:

changed the viewcellsmanager interface to use vssrays - some functionality like the bsp merging is now restricted

File:
1 edited

Legend:

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

    r465 r466  
    6767} 
    6868 
    69 void ViewCellsManager::ComputeSampleContributions(const RayContainer &rays,  
    70                                                                                                   int &sampleContributions, 
    71                                                                                                   int &contributingSamples, 
    72                                                                                                   const bool castRays) 
    73 { 
    74         // view cells not yet constructed 
    75         if (!ViewCellsConstructed()) 
    76                 return; 
    77  
    78         RayContainer::const_iterator it, it_end = rays.end(); 
    79  
    80         sampleContributions = 0; 
    81         contributingSamples = 0; 
    82  
    83     for (it = rays.begin(); it != it_end; ++ it) 
    84         { 
    85                 sampleContributions += ComputeSampleContributions(*(*it), castRays); 
    86                 contributingSamples += sampleContributions > 0; 
    87         } 
     69void 
     70ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays 
     71                                                                                         ) 
     72{ 
     73  // view cells not yet constructed 
     74  if (!ViewCellsConstructed()) 
     75        return; 
     76   
     77  VssRayContainer::const_iterator it, it_end = rays.end(); 
     78  for (it = rays.begin(); it != it_end; ++ it) { 
     79        ComputeSampleContributions(*(*it)); 
     80  } 
    8881} 
    8982 
     
    277270} 
    278271 
    279 int BspViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 
    280 { 
    281         // view cells not yet constructed 
    282         if (!ViewCellsConstructed()) 
    283                 return 0; 
    284  
    285         int contributingSamples = 0; 
    286  
    287         if (castRay) 
    288                 mBspTree->CastRay(ray); 
    289          
    290         //if (mBspTree->bspIntersections.empty()) return 0; 
    291  
    292         Intersectable *tObject =  
    293                 !ray.intersections.empty() ? ray.intersections[0].mObject : NULL; 
    294  
    295         Intersectable *sObject = ray.sourceObject.mObject; 
    296  
    297         if (sObject || tObject) 
    298         { 
    299                 // object can be seen from the view cell => add to view cell pvs 
    300                 for (int j = 0; j < (int)ray.bspIntersections.size(); ++ j) 
    301                 {        
    302                         BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 
    303                  
    304                         // if ray not outside of view space 
    305                         if (leaf->GetViewCell() != mBspTree->GetRootCell()) 
    306                         { 
    307                                 if (sObject) 
    308                                 { 
    309                                         contributingSamples +=  
    310                                                 leaf->GetViewCell()->GetPvs().AddSample(sObject); 
    311                                 } 
    312  
    313                                 if (tObject) 
    314                                 { 
    315                                         contributingSamples +=  
    316                                                 leaf->GetViewCell()->GetPvs().AddSample(tObject); 
    317                                 } 
    318                         } 
    319                 } 
    320         } 
    321  
    322         // rays passing through this viewcell 
    323         if (0) 
    324                 for (int j = 1; j < ((int)ray.bspIntersections.size() - 1); ++ j)  
    325                 { 
    326                         BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 
    327  
    328                         if (leaf->GetViewCell() != mBspTree->GetRootCell()) 
    329                                 leaf->GetViewCell()-> 
    330                                         AddPassingRay(ray, contributingSamples ? 1 : 0); 
    331                 } 
    332  
    333         return contributingSamples; 
    334 } 
    335  
    336 int BspViewCellsManager::PostProcess(const ObjectContainer &objects,  
    337                                                                          const RayContainer &rays) 
    338 { 
    339         if (!ViewCellsConstructed()) 
     272void 
     273ViewCellsManager::ComputeSampleContributions(VssRay &ray) 
     274{ 
     275 
     276  ViewCellContainer viewcells; 
     277   
     278  CastLineSegment(ray.mOrigin, 
     279                                  ray.mTermination, 
     280                                  viewcells 
     281                                  ); 
     282   
     283  ViewCellContainer::const_iterator it = viewcells.begin(); 
     284  for (; it != viewcells.end(); ++it) {          
     285        ViewCell *viewcell = *it; 
     286         
     287        // if ray not outside of view space 
     288        float contribution; 
     289        bool added =  
     290          viewcell->GetPvs().AddSample(ray.mTerminationObject, 
     291                                                                   contribution 
     292                                                                   ); 
     293        if (added) 
     294          ray.mPvsContribution++; 
     295         
     296        ray.mRelativePvsContribution += contribution; 
     297  } 
     298   
     299} 
     300 
     301int 
     302BspViewCellsManager::CastLineSegment(const Vector3 &origin, 
     303                                                                         const Vector3 &termination, 
     304                                                                         ViewCellContainer &viewcells 
     305                                                                         ) 
     306{ 
     307  return mBspTree->CastLineSegment(origin, termination, viewcells); 
     308} 
     309 
     310int 
     311BspViewCellsManager::PostProcess(const ObjectContainer &objects,  
     312                                                                 const VssRayContainer &rays) 
     313{ 
     314  if (!ViewCellsConstructed()) 
    340315        { 
    341316                Debug << "view cells not constructed" << endl; 
     
    391366        long startTime = GetTime(); 
    392367 
     368        // $$JB we do not have connectivity information from the ray in the moment 
     369        // perhaps we could recast the rays or rember the cells traversed inside the 
     370        // vssray (which would on other hand create some overhead) 
    393371        //-- merge or subdivide view cells 
    394372        int merged = 0; 
     373#if 0 
    395374 
    396375        RayContainer::const_iterator rit, rit_end = rays.end(); 
     
    427406                } 
    428407        } 
    429  
     408#endif 
    430409        //-- stats and visualizations 
    431410        cout << "finished" << endl; 
     
    443422 
    444423void BspViewCellsManager::Visualize(const ObjectContainer &objects, 
    445                                                                         const RayContainer &sampleRays) 
    446 { 
    447         if (!ViewCellsConstructed()) 
    448                 return; 
    449  
    450         //-- recount pvs 
    451         ViewCellsStatistics vcStats; 
    452         mBspTree->EvaluateViewCellsStats(vcStats); 
    453  
    454         if (1) // export view cells 
    455         { 
    456                 cout << "exporting view cells after merge ... "; 
    457                 Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
    458  
    459                 if (exporter) 
    460                 { 
    461                         exporter->ExportBspViewCellPartition(*mBspTree, vcStats.maxPvs); 
    462                         //exporter->ExportBspViewCellPartition(*mBspTree, 0); 
    463                         delete exporter; 
    464                 } 
    465  
    466                 cout << "finished" << endl; 
     424                                                                        const VssRayContainer &sampleRays) 
     425{ 
     426  if (!ViewCellsConstructed()) 
     427        return; 
     428   
     429  //-- recount pvs 
     430  ViewCellsStatistics vcStats; 
     431  mBspTree->EvaluateViewCellsStats(vcStats); 
     432   
     433  if (1) // export view cells 
     434        { 
     435          cout << "exporting view cells after merge ... "; 
     436          Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
     437           
     438          if (exporter) 
     439                { 
     440                  exporter->ExportBspViewCellPartition(*mBspTree, vcStats.maxPvs); 
     441                  //exporter->ExportBspViewCellPartition(*mBspTree, 0); 
     442                  delete exporter; 
     443                } 
     444           
     445          cout << "finished" << endl; 
    467446        }        
    468  
    469         //-- visualization of the BSP splits 
    470         bool exportSplits = false; 
    471                 environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits); 
    472          
    473         if (exportSplits) 
    474         { 
    475                 cout << "exporting splits ... "; 
    476                 ExportSplits(objects, sampleRays); 
    477                 cout << "finished" << endl; 
    478         } 
    479  
    480         ExportBspPvs(objects, sampleRays); 
     447   
     448  //-- visualization of the BSP splits 
     449  bool exportSplits = false; 
     450  environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits); 
     451   
     452  if (exportSplits) 
     453        { 
     454          cout << "exporting splits ... "; 
     455          ExportSplits(objects, sampleRays); 
     456          cout << "finished" << endl; 
     457        } 
     458   
     459  ExportBspPvs(objects, sampleRays); 
    481460} 
    482461 
     
    488467 
    489468void BspViewCellsManager::ExportSplits(const ObjectContainer &objects, 
    490                                                                            const RayContainer &sampleRays) 
     469                                                                           const VssRayContainer &sampleRays) 
    491470{ 
    492471        Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 
     
    510489                if (0) 
    511490                { 
    512                         RayContainer outRays; 
    513                  
    514                         int raysSize = min((int)sampleRays.size(), mVisualizationSamples); 
    515  
    516                         for (int i = 0; i < raysSize; ++ i) 
    517                         { 
    518                                 // only rays piercing geometry 
    519                                 if (!sampleRays[i]->intersections.empty()) 
    520                                         outRays.push_back(sampleRays[i]); 
    521                         } 
    522                          
    523                         // export rays  
    524                         exporter->ExportRays(outRays, 1000, RgbColor(1, 1, 0)); 
    525                 } 
    526  
     491                  VssRayContainer outRays; 
     492                   
     493                  int raysSize = min((int)sampleRays.size(), mVisualizationSamples); 
     494                   
     495                  for (int i = 0; i < raysSize; ++ i) 
     496                        { 
     497                          // only rays piercing geometry 
     498                          outRays.push_back(sampleRays[i]); 
     499                        } 
     500                   
     501                  // export rays  
     502                  exporter->ExportRays(outRays, RgbColor(1, 1, 0)); 
     503                } 
     504                 
    527505                if (0) 
    528                         exporter->ExportGeometry(objects); 
    529  
     506                  exporter->ExportGeometry(objects); 
     507                 
    530508                delete exporter; 
    531509        } 
     
    533511 
    534512void BspViewCellsManager::ExportBspPvs(const ObjectContainer &objects, 
    535                                                                            const RayContainer &sampleRays) 
    536 { 
    537         const int leafOut = 10; 
    538          
    539         ViewCell::NewMail(); 
    540  
    541         //-- some rays for output 
    542         const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 
    543         Debug << "visualization using " << raysOut << " samples" << endl; 
    544          
    545  
    546         if (1) 
    547         { 
    548                 //-- some random view cells and rays for output 
    549                 vector<BspLeaf *> bspLeaves; 
    550  
    551                 for (int i = 0; i < leafOut; ++ i) 
    552                         bspLeaves.push_back(mBspTree->GetRandomLeaf());  
    553                  
    554                 for (int i = 0; i < bspLeaves.size(); ++ i) 
    555                 { 
    556                         BspLeaf *leaf = bspLeaves[i]; 
    557  
    558                         RayContainer vcRays; 
    559                  
    560                         cout << "creating output for view cell " << i << " ... "; 
    561  
    562                         // check whether we can add the current ray to the output rays 
    563                         for (int k = 0; k < raysOut; ++ k)  
    564                         { 
    565                                 Ray *ray = sampleRays[k]; 
    566  
    567                                 for     (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
     513                                                                           const VssRayContainer &sampleRays) 
     514{ 
     515  const int leafOut = 10; 
     516   
     517  ViewCell::NewMail(); 
     518   
     519  //-- some rays for output 
     520  const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 
     521  Debug << "visualization using " << raysOut << " samples" << endl; 
     522 
     523  //$$ JB 
     524#if 0 
     525 
     526  if (1) 
     527        { 
     528          //-- some random view cells and rays for output 
     529          vector<BspLeaf *> bspLeaves; 
     530           
     531          for (int i = 0; i < leafOut; ++ i) 
     532                bspLeaves.push_back(mBspTree->GetRandomLeaf());  
     533 
     534           
     535          for (int i = 0; i < bspLeaves.size(); ++ i) 
     536                { 
     537                  BspLeaf *leaf = bspLeaves[i]; 
     538                   
     539                  RayContainer vcRays; 
     540                   
     541                  cout << "creating output for view cell " << i << " ... "; 
     542                   
     543                  // check whether we can add the current ray to the output rays 
     544                  for (int k = 0; k < raysOut; ++ k)  
     545                        { 
     546                          Ray *ray = sampleRays[k]; 
     547                           
     548                          for   (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
    568549                                { 
    569                                         BspLeaf *leaf2 = ray->bspIntersections[j].mLeaf; 
    570  
    571                                         if (leaf->GetViewCell() == leaf2->GetViewCell())  
     550                                  BspLeaf *leaf2 = ray->bspIntersections[j].mLeaf; 
     551                                   
     552                                  if (leaf->GetViewCell() == leaf2->GetViewCell())  
    572553                                        { 
    573                                                 vcRays.push_back(ray); 
     554                                          vcRays.push_back(ray); 
    574555                                        } 
    575556                                } 
    576557                        } 
    577  
    578             Intersectable::NewMail(); 
    579  
    580                         BspViewCell *vc = dynamic_cast<BspViewCell *>(leaf->GetViewCell()); 
    581  
    582                         //bspLeaves[j]->Mail(); 
    583                         char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
    584  
    585                         Exporter *exporter = Exporter::GetExporter(s); 
    586                         exporter->SetFilled(); 
    587  
    588                         exporter->SetWireframe(); 
    589                         //exporter->SetFilled(); 
    590  
    591                         Material m;//= RandomMaterial(); 
    592                         m.mDiffuseColor = RgbColor(1, 1, 0); 
    593                         exporter->SetForcedMaterial(m); 
    594  
    595                         if (vc->GetMesh()) 
    596                                 exporter->ExportViewCell(vc); 
    597                         else 
    598                         { 
    599                                 PolygonContainer vcGeom; 
    600                                 // export view cell geometry 
    601                                 mBspTree->ConstructGeometry(vc, vcGeom); 
    602                                 exporter->ExportPolygons(vcGeom); 
     558                   
     559                  Intersectable::NewMail(); 
     560                   
     561                  BspViewCell *vc = dynamic_cast<BspViewCell *>(leaf->GetViewCell()); 
     562                   
     563                  //bspLeaves[j]->Mail(); 
     564                  char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
     565                   
     566                  Exporter *exporter = Exporter::GetExporter(s); 
     567                  exporter->SetFilled(); 
     568 
     569                  exporter->SetWireframe(); 
     570                  //exporter->SetFilled(); 
     571                   
     572                  Material m;//= RandomMaterial(); 
     573                  m.mDiffuseColor = RgbColor(1, 1, 0); 
     574                  exporter->SetForcedMaterial(m); 
     575                   
     576                  if (vc->GetMesh()) 
     577                        exporter->ExportViewCell(vc); 
     578                  else 
     579                        { 
     580                          PolygonContainer vcGeom; 
     581                          // export view cell geometry 
     582                          mBspTree->ConstructGeometry(vc, vcGeom); 
     583                          exporter->ExportPolygons(vcGeom); 
    603584                                CLEAR_CONTAINER(vcGeom); 
    604585                        } 
    605  
    606                         Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
    607                                   << ", piercing rays=" << (int)vcRays.size() << endl; 
    608  
    609                         // export rays piercing this view cell 
    610                         exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0));   
    611                          
    612                         m.mDiffuseColor = RgbColor(1, 0, 0); 
    613                         exporter->SetForcedMaterial(m); 
    614  
    615                         // exporter->SetWireframe(); 
    616                         exporter->SetFilled(); 
    617  
    618                         ViewCellPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 
    619                         // output PVS of view cell 
    620                         for (it = vc->GetPvs().mEntries.begin(); it !=  it_end; ++ it)  
    621                         { 
    622                                 Intersectable *intersect = (*it).first; 
    623                                 if (!intersect->Mailed()) 
     586                   
     587                  Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
     588                                << ", piercing rays=" << (int)vcRays.size() << endl; 
     589                   
     590                  // export rays piercing this view cell 
     591                  exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0));         
     592                   
     593                  m.mDiffuseColor = RgbColor(1, 0, 0); 
     594                  exporter->SetForcedMaterial(m); 
     595                   
     596                  // exporter->SetWireframe(); 
     597                  exporter->SetFilled(); 
     598                   
     599                  ViewCellPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 
     600                  // output PVS of view cell 
     601                  for (it = vc->GetPvs().mEntries.begin(); it !=  it_end; ++ it)  
     602                        { 
     603                          Intersectable *intersect = (*it).first; 
     604                          if (!intersect->Mailed()) 
    624605                                { 
    625                                         exporter->ExportIntersectable(intersect); 
    626                                         intersect->Mail(); 
     606                                  exporter->ExportIntersectable(intersect); 
     607                                  intersect->Mail(); 
    627608                                }                        
    628609                        } 
    629  
    630                         DEL_PTR(exporter); 
    631                         cout << "finished" << endl; 
    632                 } 
    633         } 
    634         else 
    635         { 
    636                 ViewCellContainer viewCells; 
    637                 RayContainer vcRays; 
    638  
    639                 mBspTree->CollectViewCells(viewCells); 
    640                 stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 
    641  
    642                 int limit = min(leafOut, (int)viewCells.size());  
    643                  
    644                 for (int i = 0; i < limit; ++ i) 
    645                 { 
    646                         cout << "creating output for view cell " << i << " ... "; 
     610                   
     611                  DEL_PTR(exporter); 
     612                  cout << "finished" << endl; 
     613                } 
     614        } 
     615  else 
     616        { 
     617          ViewCellContainer viewCells; 
     618          RayContainer vcRays; 
     619           
     620          mBspTree->CollectViewCells(viewCells); 
     621          stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 
     622           
     623          int limit = min(leafOut, (int)viewCells.size());  
     624           
     625          for (int i = 0; i < limit; ++ i) 
     626                { 
     627                  cout << "creating output for view cell " << i << " ... "; 
    647628                         
    648629            Intersectable::NewMail(); 
     
    721702                } 
    722703        } 
     704#endif 
    723705} 
    724706 
     
    822804 
    823805int KdViewCellsManager::PostProcess(const ObjectContainer &objects,  
    824                                                                         const RayContainer &rays) 
     806                                                                        const VssRayContainer &rays) 
    825807{ 
    826808        return 0; 
     
    828810 
    829811void KdViewCellsManager::Visualize(const ObjectContainer &objects, 
    830                                                                    const RayContainer &sampleRays) 
     812                                                                   const VssRayContainer &sampleRays) 
    831813{ 
    832814        if (!ViewCellsConstructed()) 
     
    837819        int limit = min(mVisualizationSamples, (int)sampleRays.size()); 
    838820 
    839         RayContainer *rays = new RayContainer[pvsOut]; 
     821        VssRayContainer *rays = new VssRayContainer[pvsOut]; 
    840822 
    841823        for  (int i = 0; i < limit; ++ i) 
    842824        { 
    843                 Ray *ray = sampleRays[i]; 
    844  
    845                 if (!ray->intersections.empty())  
    846                 { 
    847                         // check whether we can add this to the rays 
    848                         for (int j = 0; j < pvsOut; j++)  
    849                         { 
    850                                 if (objects[j] == ray->intersections[0].mObject)  
    851                                 { 
    852                                         rays[j].push_back(ray); 
    853                                 } 
    854                         } 
    855                 } 
    856         } 
     825          VssRay *ray = sampleRays[i]; 
     826           
     827          // check whether we can add this to the rays 
     828          for (int j = 0; j < pvsOut; j++)  
     829                { 
     830                  if (objects[j] == ray->mTerminationObject) 
     831                        { 
     832                          rays[j].push_back(ray); 
     833                        } 
     834                } 
     835        } 
     836         
    857837 
    858838        bool exportRays = false; 
    859839        if (exportRays) { 
    860                 Exporter *exporter = NULL; 
     840          Exporter *exporter = NULL; 
    861841                exporter = Exporter::GetExporter("sample-rays.x3d"); 
    862842                exporter->SetWireframe(); 
     
    864844                 
    865845                for (i=0; i < pvsOut; i++)  
    866                         exporter->ExportRays(rays[i], 1000, RgbColor(1, 0, 0)); 
     846                        exporter->ExportRays(rays[i], RgbColor(1, 0, 0)); 
    867847                exporter->SetFilled(); 
    868848                 
     
    893873                } 
    894874 
    895                 exporter->ExportRays(rays[k], 1000, RgbColor(0, 1, 0)); 
     875                exporter->ExportRays(rays[k], RgbColor(0, 1, 0)); 
    896876                exporter->SetFilled(); 
    897877                  
     
    914894} 
    915895 
    916 int KdViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 
    917 { 
    918         // view cells not yet constructed 
    919         if (!ViewCellsConstructed()) 
    920                 return 0; 
    921  
    922         if (castRay) 
    923                 mKdTree->CastRay(ray); 
    924  
    925         if (ray.kdLeaves.empty()) 
    926                 return 0; 
    927  
    928         Intersectable *tObject = 
    929                 !ray.intersections.empty() ? ray.intersections[0].mObject : NULL; 
    930  
    931         Intersectable *sObject = 
    932                 ray.sourceObject.mObject; 
    933  
    934         int contributingSamples = 0; 
    935          
    936         int objects = 0; 
    937  
    938         if (sObject) 
    939                 objects++; 
    940         if (tObject) 
    941                 objects++; 
    942  
    943         for (int j = 1; j < ((int)ray.kdLeaves.size() - 1); ++ j)  
    944         { 
    945                 ray.kdLeaves[j]->AddPassingRay2(ray, objects, 
    946                                                                                 (int)ray.kdLeaves.size()); 
    947         } 
    948  
    949         if (!objects) 
    950                 return 0; 
    951          
    952         for (int j=0; j < ray.kdLeaves.size(); j++)  
    953         { 
    954                 KdNode *node = GetNodeForPvs(ray.kdLeaves[j]); 
    955  
    956                 if (sObject) 
    957                         contributingSamples += sObject->mKdPvs.AddSample(node); 
    958                 if (tObject) 
    959                         contributingSamples += tObject->mKdPvs.AddSample(node); 
    960         } 
    961  
    962         return contributingSamples; 
    963 } 
    964896 
    965897 
     
    976908void KdViewCellsManager::PrintStatistics(ostream &s) const 
    977909{ 
     910} 
     911 
     912 
     913int 
     914KdViewCellsManager::CastLineSegment(const Vector3 &origin, 
     915                                                                        const Vector3 &termination, 
     916                                                                        ViewCellContainer &viewcells 
     917                                                                        ) 
     918{ 
     919 
     920  return 0; 
    978921} 
    979922 
     
    1031974} 
    1032975 
    1033 int VspKdViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 
    1034 { 
    1035         // view cells not yet constructed 
     976 
     977ViewCell *VspKdViewCellsManager::GenerateViewCell(Mesh *mesh) const 
     978{ 
     979        return new VspKdViewCell(mesh); 
     980} 
     981 
     982int VspKdViewCellsManager::PostProcess(const ObjectContainer &objects,  
     983                                                                           const VssRayContainer &rays) 
     984{ 
    1036985        if (!ViewCellsConstructed()) 
    1037986                return 0; 
    1038987 
    1039 //      if (castRay) 
    1040 //              mVspKdTree->CastRay(ray); 
    1041  
    1042         int sampleContributions = 0; 
    1043  
    1044         return sampleContributions; 
    1045 } 
    1046  
    1047 ViewCell *VspKdViewCellsManager::GenerateViewCell(Mesh *mesh) const 
    1048 { 
    1049         return new VspKdViewCell(mesh); 
    1050 } 
    1051  
    1052 int VspKdViewCellsManager::PostProcess(const ObjectContainer &objects,  
    1053                                                                            const RayContainer &rays) 
    1054 { 
    1055         if (!ViewCellsConstructed()) 
    1056                 return 0; 
    1057  
    1058988        return mVspKdTree->MergeLeaves(); 
    1059989} 
    1060990 
    1061991void VspKdViewCellsManager::Visualize(const ObjectContainer &objects, 
    1062                                                                           const RayContainer &sampleRays) 
     992                                                                          const VssRayContainer &sampleRays) 
    1063993{ 
    1064994        if (!ViewCellsConstructed()) 
     
    10791009 
    10801010                if (exportRays)  
    1081                 { 
     1011                  { 
    10821012                        int raysSize = 2000; 
    10831013                        float prob = raysSize / (float)sampleRays.size(); 
     
    10851015                        exporter->SetWireframe(); 
    10861016                         
    1087                         RayContainer rays; 
     1017                        VssRayContainer rays; 
    10881018                 
    10891019                        for (int i = 0; i < sampleRays.size(); ++ i) 
     
    10931023                        } 
    10941024 
    1095                         exporter->ExportRays(rays, 1000, RgbColor(1, 0, 0)); 
     1025                        exporter->ExportRays(rays, RgbColor(1, 0, 0)); 
    10961026                } 
    10971027 
     
    11651095                exporter->SetWireframe(); 
    11661096                         
    1167                 RayContainer rays; 
     1097                VssRayContainer rays; 
    11681098                 
    11691099                for (int i = 0; i < sampleRays.size(); ++ i) 
    11701100                { 
    1171                         if (RandomValue(0,1) < prob) 
    1172                                 rays.push_back(sampleRays[i]); 
    1173                 } 
    1174                 exporter->ExportRays(rays, 1000, RgbColor(1, 0, 0)); 
     1101                  if (RandomValue(0,1) < prob) 
     1102                        rays.push_back(sampleRays[i]); 
     1103                } 
     1104                exporter->ExportRays(rays, RgbColor(1, 0, 0)); 
    11751105        } 
    11761106 
     
    11911121} 
    11921122 
     1123 
     1124int 
     1125VspKdViewCellsManager::CastLineSegment(const Vector3 &origin, 
     1126                                                                           const Vector3 &termination, 
     1127                                                                           ViewCellContainer &viewcells 
     1128                                                                           ) 
     1129{ 
     1130   
     1131  return 0; 
     1132} 
    11931133 
    11941134/**********************************************************************/ 
     
    12521192} 
    12531193 
    1254 int VspBspViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 
    1255 { 
    1256         // view cells not yet constructed 
    1257         if (!ViewCellsConstructed()) 
    1258                 return 0; 
    1259  
    1260         int contributingSamples = 0; 
    1261  
    1262         if (castRay) 
    1263                 mVspBspTree->CastRay(ray); 
    1264  
    1265         Intersectable *tObject =  
    1266                 !ray.intersections.empty() ? ray.intersections[0].mObject : NULL; 
    1267  
    1268         Intersectable *sObject = ray.sourceObject.mObject; 
    1269  
    1270         if (sObject || tObject) 
    1271         { 
    1272                 // object can be seen from the view cell => add to view cell pvs 
    1273                 for (int j = 0; j < (int)ray.bspIntersections.size(); ++ j) 
    1274                 {        
    1275                         BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 
    1276                  
    1277                         // if ray not in unbounded space 
    1278                         if (leaf->GetViewCell() != mVspBspTree->GetRootCell()) 
    1279                         { 
    1280                                 if (sObject) 
    1281                                 { 
    1282                                         contributingSamples +=  
    1283                                                 leaf->GetViewCell()->GetPvs().AddSample(sObject); 
    1284                                 } 
    1285  
    1286                                 if (tObject) 
    1287                                 { 
    1288                                         contributingSamples +=  
    1289                                                 leaf->GetViewCell()->GetPvs().AddSample(tObject); 
    1290                                 } 
    1291                         } 
    1292                 } 
    1293         } 
    1294  
    1295         // rays passing through this viewcell 
    1296         if (0) 
    1297                 for (int j = 1; j < ((int)ray.bspIntersections.size() - 1); ++ j)  
    1298                 { 
    1299                         BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 
    1300  
    1301                         if (leaf->GetViewCell() != mVspBspTree->GetRootCell()) 
    1302                                 leaf->GetViewCell()-> 
    1303                                         AddPassingRay(ray, contributingSamples ? 1 : 0); 
    1304                 } 
    1305  
    1306         return contributingSamples; 
    1307 } 
    13081194 
    13091195int VspBspViewCellsManager::PostProcess(const ObjectContainer &objects,  
    1310                                                                                 const RayContainer &rays) 
     1196                                                                                const VssRayContainer &rays) 
    13111197{ 
    13121198        if (!ViewCellsConstructed()) 
     
    13561242 
    13571243 
     1244        // $$JB we do not have connectivity information from the ray in the moment 
     1245        // perhaps we could recast the rays or rember the cells traversed inside the 
     1246        // vssray (which would on other hand create some overhead) 
    13581247        //-- merge or subdivide view cells 
    13591248        int merged = 0; 
     1249#if 0 
    13601250 
    13611251        RayContainer::const_iterator rit, rit_end = rays.end(); 
     
    13661256        for (int i = 0; i < limit; ++ i) 
    13671257        {   
    1368                 Ray *ray = rays[i]; 
    1369  
    1370                 // traverse leaves stored in the rays and compare and merge consecutive 
    1371                 // leaves (i.e., the neighbors in the tree) 
    1372                 if (ray->bspIntersections.size() < 2) 
    1373                         continue; 
    1374  
    1375                 iit = ray->bspIntersections.begin(); 
     1258          VssRay *ray = rays[i]; 
     1259           
     1260          // traverse leaves stored in the rays and compare and merge consecutive 
     1261          // leaves (i.e., the neighbors in the tree) 
     1262          if (ray->bspIntersections.size() < 2) 
     1263                continue; 
     1264           
     1265          iit = ray->bspIntersections.begin(); 
    13761266 
    13771267                BspLeaf *previousLeaf = (*iit).mLeaf; 
     
    13921282                } 
    13931283        } 
    1394  
     1284#endif 
    13951285        //-- stats and visualizations 
    13961286        cout << "finished" << endl; 
     
    14091299 
    14101300void VspBspViewCellsManager::Visualize(const ObjectContainer &objects, 
    1411                                                                            const RayContainer &sampleRays) 
     1301                                                                           const VssRayContainer &sampleRays) 
    14121302{ 
    14131303        if (!ViewCellsConstructed()) 
     
    14481338 
    14491339void VspBspViewCellsManager::ExportSplits(const ObjectContainer &objects, 
    1450                                                                                   const RayContainer &sampleRays) 
     1340                                                                                  const VssRayContainer &sampleRays) 
    14511341{ 
    14521342        Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 
     
    14711361                if (0) 
    14721362                { 
    1473                         RayContainer outRays; 
     1363                  VssRayContainer outRays; 
    14741364                 
    14751365                        int raysSize = min((int)sampleRays.size(), mVisualizationSamples); 
     
    14781368                        { 
    14791369                                // only rays piercing geometry 
    1480                                 if (!sampleRays[i]->intersections.empty()) 
    1481                                         outRays.push_back(sampleRays[i]); 
     1370                          outRays.push_back(sampleRays[i]); 
    14821371                        } 
    14831372                         
    14841373                        // export rays  
    1485                         exporter->ExportRays(outRays, 1000, RgbColor(1, 1, 0)); 
     1374                        exporter->ExportRays(outRays, RgbColor(1, 1, 0)); 
    14861375                } 
    14871376 
     
    14941383 
    14951384void VspBspViewCellsManager::ExportBspPvs(const ObjectContainer &objects, 
    1496                                                                                   const RayContainer &sampleRays) 
     1385                                                                                  const VssRayContainer &sampleRays) 
    14971386{ 
    14981387        const int leafOut = 10; 
     
    15141403                for (int i = 0; i < (int)vspBspLeaves.size(); ++ i) 
    15151404                { 
    1516                         RayContainer vcRays; 
    1517                         cout << "creating output for view cell " << i << " ... "; 
    1518                          
     1405                  VssRayContainer vcRays; 
     1406                  cout << "creating output for view cell " << i << " ... "; 
     1407 
     1408                  //$$JB 
     1409#if 0 
    15191410                        // check whether we can add the current ray to the output rays 
    15201411                        for (int k = 0; k < raysOut; ++ k)  
    15211412                        { 
    1522                                 Ray *ray = sampleRays[k]; 
     1413                          VssRay *ray = sampleRays[k]; 
    15231414 
    15241415                                for     (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
     
    15321423                                } 
    15331424                        } 
    1534                          
     1425#endif 
    15351426 
    15361427                        Intersectable::NewMail(); 
     
    15701461 
    15711462                        // export rays piercing this view cell 
    1572                         exporter->ExportRays(vcRays, 1000, RgbColor(1, 0, 0)); 
     1463                        exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 
    15731464                        exporter->ExportRays(vspBspLeaves[i]->mVssRays, RgbColor(1, 1, 1)); 
    15741465                         
     
    16211512                { 
    16221513                        cout << "creating output for view cell " << i << " ... "; 
    1623                         RayContainer vcRays; 
     1514                        VssRayContainer vcRays; 
    16241515            Intersectable::NewMail(); 
    16251516                        BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]); 
    16261517 
    16271518                        cout << "creating output for view cell " << i << " ... "; 
     1519                        //$$ JB 
     1520#if 0 
    16281521                        // check whether we can add the current ray to the output rays 
    16291522                        for (int k = 0; k < raysOut; ++ k)  
    16301523                        { 
    1631                                 Ray *ray = sampleRays[k]; 
     1524                          Ray *ray = sampleRays[k]; 
    16321525 
    16331526                                for     (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
     
    16411534                                } 
    16421535                        } 
    1643  
     1536#endif 
    16441537                        //bspLeaves[j]->Mail(); 
    16451538                        char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
     
    16701563                         
    16711564                        // export rays piercing this view cell 
    1672                         exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0)); 
     1565                        exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 
    16731566         
    16741567                        m.mDiffuseColor = RgbColor(1, 0, 0); 
     
    17711664} 
    17721665 
     1666 
     1667int 
     1668VspBspViewCellsManager::CastLineSegment(const Vector3 &origin, 
     1669                                                                                const Vector3 &termination, 
     1670                                                                                ViewCellContainer &viewcells 
     1671                                                                                ) 
     1672{ 
     1673  return mVspBspTree->CastLineSegment(origin, termination, viewcells); 
     1674} 
Note: See TracChangeset for help on using the changeset viewer.