Ignore:
Timestamp:
11/30/05 18:02:55 (19 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r439 r440  
    4040         
    4141        filenames.push_back(string(str, pos, str.size() - pos)); 
    42         return filenames.size(); 
     42        return (int)filenames.size(); 
    4343} 
    4444 
     
    161161} 
    162162 
    163  
    164 void Preprocessor::ExportSplits(const ObjectContainer &objects, 
    165                                                                 const RayContainer &sampleRays, 
    166                                                                 const int visSamples) 
    167 { 
    168         Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 
    169  
    170         if (exporter)  
    171         {        
    172                 Material m;  
    173                 m.mDiffuseColor = RgbColor(1, 0, 0); 
    174                 exporter->SetForcedMaterial(m); 
    175                 exporter->SetWireframe(); 
    176                 exporter->ExportBspSplits(*mBspTree, true); 
    177  
    178                 // take forced material, else big scenes cannot be viewed 
    179                 m.mDiffuseColor = RgbColor(0, 1, 0); 
    180                 exporter->SetForcedMaterial(m); 
    181                 exporter->SetFilled(); 
    182  
    183                 exporter->ResetForcedMaterial(); 
    184                  
    185                 // export rays 
    186                 if (0) 
    187                 { 
    188                         RayContainer outRays; 
    189                  
    190                         for (int i = 0; i < sampleRays.size(); ++ i) 
    191                         { 
    192                                 // only rays piercing geometry 
    193                                 if (!sampleRays[i]->intersections.empty()) 
    194                                         outRays.push_back(sampleRays[i]); 
    195                         } 
    196                         if (BspTree::sConstructionMethod == BspTree::FROM_SAMPLES) 
    197                         { 
    198                                 // export rays  
    199                                 exporter->ExportRays(outRays, 1000, RgbColor(1, 1, 0)); 
    200                         } 
    201                 } 
    202  
    203                 if (1) 
    204                         ExportSceneGeometry(exporter, objects); 
    205  
    206                 delete exporter; 
    207         } 
    208 } 
    209  
    210 inline bool vc_gt(ViewCell *a, ViewCell *b)  
    211 {  
    212         return a->GetPvs().GetSize() > b->GetPvs().GetSize(); 
    213 } 
    214  
    215 void Preprocessor::ExportBspPvs(const ObjectContainer &objects, 
    216                                                                 const RayContainer &sampleRays, 
    217                                                                 const int visSamples) 
    218 { 
    219         const int leafOut = 10; 
    220          
    221         ViewCell::NewMail(); 
    222  
    223         //-- some rays for output 
    224         const int raysOut = min((int)sampleRays.size(), visSamples); 
    225         cout << "visualization using " << visSamples << " samples" << endl; 
    226         vector<Ray *> vcRays[leafOut]; 
    227  
    228         if (0) 
    229         { 
    230                 //-- some random view cells and rays for output 
    231                 vector<BspLeaf *> bspLeaves; 
    232  
    233                 for (int i = 0; i < leafOut; ++ i) 
    234                         bspLeaves.push_back(mBspTree->GetRandomLeaf());  
    235                  
    236                 for (int i = 0; i < bspLeaves.size(); ++ i) 
    237                 { 
    238                         cout << "creating output for view cell " << i << " ... "; 
    239                         // check whether we can add the current ray to the output rays 
    240                         for (int k = 0; k < raysOut; ++ k)  
    241                         { 
    242                                 Ray *ray = sampleRays[k]; 
    243  
    244                                 for     (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
    245                                 { 
    246                                         BspLeaf *leaf = ray->bspIntersections[j].mLeaf; 
    247  
    248                                         if (bspLeaves[i]->GetViewCell() == leaf->GetViewCell())  
    249                                         { 
    250                                                 vcRays[i].push_back(ray); 
    251                                         } 
    252                                 } 
    253                         } 
    254  
    255                         Intersectable::NewMail(); 
    256  
    257                         BspViewCell *vc = dynamic_cast<BspViewCell *>(bspLeaves[i]->GetViewCell()); 
    258  
    259                         //bspLeaves[j]->Mail(); 
    260                         char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
    261  
    262                         Exporter *exporter = Exporter::GetExporter(s); 
    263                         exporter->SetFilled(); 
    264  
    265                         ViewCellPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 
    266  
    267                         exporter->SetWireframe(); 
    268                         //exporter->SetFilled(); 
    269  
    270                         Material m;//= RandomMaterial(); 
    271                         m.mDiffuseColor = RgbColor(0, 1, 0); 
    272                         exporter->SetForcedMaterial(m); 
    273  
    274                         if (vc->GetMesh()) 
    275                                 exporter->ExportViewCell(vc); 
    276                         else 
    277                         { 
    278                                 PolygonContainer cell; 
    279                                 // export view cell geometry 
    280                                 mBspTree->ConstructGeometry(vc, cell); 
    281                                 exporter->ExportPolygons(cell); 
    282                                 CLEAR_CONTAINER(cell); 
    283                         } 
    284  
    285                         Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
    286                                         << ", piercing rays=" << (int)vcRays[i].size() << endl; 
    287  
    288                         // export rays piercing this view cell 
    289                         exporter->ExportRays(vcRays[i], 1000, RgbColor(0, 1, 0)); 
    290  
    291                         m.mDiffuseColor = RgbColor(1, 0, 0); 
    292                         exporter->SetForcedMaterial(m); 
    293  
    294                         // exporter->SetWireframe(); 
    295                         exporter->SetFilled(); 
    296  
    297                         // output PVS of view cell 
    298                         for (; it != vc->GetPvs().mEntries.end(); ++ it)  
    299                         { 
    300                                 Intersectable *intersect = (*it).first; 
    301                                 if (!intersect->Mailed()) 
    302                                 { 
    303                                         exporter->ExportIntersectable(intersect); 
    304                                         intersect->Mail(); 
    305                                 }                        
    306                         } 
    307                                  
    308                         // output rest of the objects 
    309                         if (0) 
    310                         { 
    311                                 Material m;//= RandomMaterial(); 
    312                                 m.mDiffuseColor = RgbColor(0, 0, 1); 
    313                                 exporter->SetForcedMaterial(m); 
    314  
    315                                 for (int j = 0; j < objects.size(); ++ j) 
    316                                         if (!objects[j]->Mailed()) 
    317                                         { 
    318                                                 exporter->SetForcedMaterial(m); 
    319                                                 exporter->ExportIntersectable(objects[j]); 
    320                                                 objects[j]->Mail(); 
    321                                         } 
    322                         } 
    323                         DEL_PTR(exporter); 
    324                         cout << "finished" << endl; 
    325                 } 
    326         } 
    327         else 
    328         { 
    329                 ViewCellContainer viewCells; 
    330  
    331                 mBspTree->CollectViewCells(viewCells); 
    332                 stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 
    333  
    334                 int limit = min(leafOut, (int)viewCells.size());  
    335                  
    336                 for (int i = 0; i < limit; ++ i) 
    337                 { 
    338                         cout << "creating output for view cell " << i << " ... "; 
    339                          
    340             Intersectable::NewMail(); 
    341                         BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]); 
    342  
    343                         cout << "creating output for view cell " << i << " ... "; 
    344                         // check whether we can add the current ray to the output rays 
    345                         for (int k = 0; k < raysOut; ++ k)  
    346                         { 
    347                                 Ray *ray = sampleRays[k]; 
    348  
    349                                 for     (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
    350                                 { 
    351                                         BspLeaf *leaf = ray->bspIntersections[j].mLeaf; 
    352  
    353                                         if (vc == leaf->GetViewCell())  
    354                                         { 
    355                                                 vcRays[i].push_back(ray); 
    356                                         } 
    357                                 } 
    358                         } 
    359  
    360                         //bspLeaves[j]->Mail(); 
    361                         char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
    362  
    363                         Exporter *exporter = Exporter::GetExporter(s); 
    364                          
    365                         exporter->SetWireframe(); 
    366  
    367                         Material m;//= RandomMaterial(); 
    368                         m.mDiffuseColor = RgbColor(0, 1, 0); 
    369                         exporter->SetForcedMaterial(m); 
    370  
    371                         if (vc->GetMesh()) 
    372                                 exporter->ExportViewCell(vc); 
    373                         else 
    374                         { 
    375                                 PolygonContainer cell; 
    376                                 // export view cell 
    377                                 mBspTree->ConstructGeometry(vc, cell); 
    378                                 exporter->ExportPolygons(cell); 
    379                                 CLEAR_CONTAINER(cell); 
    380                         } 
    381  
    382                          
    383                         Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
    384                                         << ", piercing rays=" << (int)vcRays[i].size() << endl; 
    385  
    386                          
    387                         // export rays piercing this view cell 
    388                         exporter->ExportRays(vcRays[i], 1000, RgbColor(0, 1, 0)); 
    389          
    390                         m.mDiffuseColor = RgbColor(1, 0, 0); 
    391                         exporter->SetForcedMaterial(m); 
    392  
    393                         ViewCellPvsMap::const_iterator it, 
    394                                 it_end = vc->GetPvs().mEntries.end(); 
    395  
    396                         // output PVS of view cell 
    397                         for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it)  
    398                         { 
    399                                 Intersectable *intersect = (*it).first; 
    400                                 if (!intersect->Mailed()) 
    401                                 { 
    402                                         Material m = RandomMaterial(); 
    403                          
    404                                         exporter->SetForcedMaterial(m); 
    405  
    406                                         exporter->ExportIntersectable(intersect); 
    407                                         intersect->Mail(); 
    408                                 }                        
    409                         } 
    410                                  
    411                         DEL_PTR(exporter); 
    412                         cout << "finished" << endl; 
    413                 } 
    414         } 
    415 } 
    416  
    417  
    418 void Preprocessor::ExportSceneGeometry(Exporter *exporter,  
    419                                                                            const ObjectContainer &objects) 
    420 { 
    421         Material m;//= RandomMaterial(); 
    422         m.mDiffuseColor = RgbColor(0, 1, 0); 
    423         exporter->SetForcedMaterial(m); 
    424         exporter->SetWireframe(); 
    425  
    426         for (int j = 0; j < objects.size(); ++ j) 
    427                 exporter->ExportIntersectable(objects[j]); 
    428 } 
    429  
    430163bool Preprocessor::PrepareViewCells() 
    431164{ 
     
    436169        if (strcmp(viewCellsStr, "kdTree") == 0) 
    437170        { 
    438                 //mViewCellsManager = new KdViewCellsManager(mKdTree); 
     171                mViewCellsManager = new KdViewCellsManager(mKdTree); 
    439172        } 
    440173        if (strcmp(viewCellsStr, "bspTree") == 0) 
    441174        { 
    442                 //mViewCellsManager = new BspViewCellsManager(mBspTree, mBspConstructionSamples); 
     175                int bspConstructionSamples = 0; 
     176 
     177                environment->GetIntValue("BspTree.Construction.samples", bspConstructionSamples); 
     178                mViewCellsManager = new BspViewCellsManager(mBspTree, bspConstructionSamples); 
    443179        } 
    444180        else if (strcmp(viewCellsStr, "vspTree") == 0) 
    445181        { 
    446                 //mViewCellsManager = new VspKdViewCellContaienr(mVspKdTree, mVspKdConstructionSamples); 
     182                int vspKdConstructionSamples = 0; 
     183                 
     184                environment->GetIntValue("VspKdTree.Construction.samples", vspKdConstructionSamples); 
     185        mViewCellsManager = new VspKdViewCellsManager(mVspKdTree, vspKdConstructionSamples); 
    447186        } 
    448187        else if (strcmp(viewCellsStr, "sceneDependent") == 0) 
    449188        { 
    450189                //TODO 
    451                 //mViewCellsManager = new BspViewCellContainer(mBspTree); 
     190                int bspConstructionSamples = 0; 
     191 
     192                environment->GetIntValue("BspTree.Construction.samples", bspConstructionSamples); 
     193                mViewCellsManager = new BspViewCellsManager(mBspTree, bspConstructionSamples); 
    452194        } 
    453195        else 
     
    457199        } 
    458200 
     201        int postProcessSamples = 0; 
     202        int visSamples = 0; 
     203 
     204        environment->GetIntValue("ViewCells.PostProcessing.samples", postProcessSamples); 
     205        environment->GetIntValue("BspTree.Visualization.samples", visSamples); 
     206 
     207        mViewCellsManager->SetPostProcessSamples(postProcessSamples); 
     208        mViewCellsManager->SetVisualizationSamples(visSamples); 
     209 
     210 
    459211        //-- parse view cells construction method 
     212 
    460213        bool loadViewCells = false; 
    461214        environment->GetBoolValue("ViewCell.Construction.loadFromFile", loadViewCells); 
Note: See TracChangeset for help on using the changeset viewer.