Ignore:
Timestamp:
10/10/05 04:19:59 (19 years ago)
Author:
mattausch
Message:

bsp viewcells now work

File:
1 edited

Legend:

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

    r312 r313  
    6767  
    6868        // add object to view cell 
    69         for (j=0; j < ray.viewCells.size(); j++)  
     69        for (j=0; j < ray.viewCells.size(); ++ j)  
    7070        {  
    7171                ViewCell *vc = ray.viewCells[j]; 
     72 
     73                for (int i = 0; i < 5; ++ i) 
     74                        if (vc == mViewCells[i]) 
     75                                Debug << "adding sample to vc " << i << endl; 
    7276                contributingSamples += vc->GetPvs().AddSample(obj); 
    7377        } 
    7478  
    7579        if (mPass > 1) 
    76                 for (j=1; j < ((int)ray.viewCells.size() - 1); j++)  
     80                for (j=1; j < ((int)ray.viewCells.size() - 1); ++ j)  
    7781                { 
    7882            ray.viewCells[j]->AddPassingRay(ray, contributingSamples ? 1 : 0); 
     
    112116                sampleContributions += AddObjectSamples(object, ray); 
    113117                                 
    114                 if (ray.intersections.size() > 0) // view cell found 
     118                if (ray.intersections.size() > 0) // second intersection found 
    115119                { 
    116120                        sampleContributions +=  
     
    230234 
    231235  int pvsOut = Min((int)objects.size(), 10); 
    232    
     236  int vcPvsOut = Min((int)mViewCells.size(), 5); 
     237 
    233238  vector<Ray> rays[10]; 
    234    
     239  vector<Ray> vcRays[5]; 
     240 
    235241  while (totalSamples < mTotalSamples) { 
    236242                int passContributingSamples = 0; 
     
    330336                                        sampleContributions = CastRay(object, ray); 
    331337                                         
     338                                        if (mViewCellsType == BSP_VIEW_CELLS)  
     339                                        { 
     340                                                // check whether we can add this to the rays 
     341                                                for (int k = 0; k < ray.viewCells.size(); ++ k) 
     342                                                        for (int j = 0; j < vcPvsOut; ++ j)  
     343                                                                if (mViewCells[j] == ray.viewCells[k])  
     344                                                                { 
     345                                                                        Debug << "Pushing back ray" << endl; 
     346                                                                        vcRays[j].push_back(ray); 
     347                                                                } 
     348                                        } 
    332349                                } 
    333350                        } else { 
     
    350367                                } 
    351368                        } 
    352                  
     369                         
    353370                        passSamples++; 
    354371                         
     
    369386                int pvsSize = 0; 
    370387         
    371                 if (mViewCellsType == BSP_VIEW_CELLS) 
    372                 { 
     388                if (mViewCellsType == BSP_VIEW_CELLS) { 
    373389                        for (i=0; i < mViewCells.size(); i++) { 
    374390                                ViewCell *vc = mViewCells[i]; 
    375391                                pvsSize += vc->GetPvs().GetSize(); 
    376392                        } 
    377                 } else 
    378                 { 
     393                } else  { 
    379394                        for (i=0; i < objects.size(); i++) { 
    380395                                Intersectable *object = objects[i]; 
     
    435450      if (mViewCellsType == BSP_VIEW_CELLS) 
    436451          { 
    437                    int limit = Min((int)mViewCells.size(), 1); 
    438  
    439                    //char s[64]; sprintf(s, "bsp-pvs%04d.x3d", k); 
    440                    Exporter *exporter = Exporter::GetExporter("bsp-pvs.x3d"); 
    441                    exporter->SetFilled(); 
    442  
    443                    Intersectable::NewMail(); 
    444  
    445                    for (int j = 0; j < limit; ++ j) 
    446                    {                    
    447                            // j random view cells 
    448                            int k = Random((int)mViewCells.size()); 
    449  
    450                            Debug << "next vc: " << k << endl; 
    451                            ViewCellPvsMap::iterator it = mViewCells[k]->GetPvs().mEntries.begin(); 
     452                   for (int j = 0; j < vcPvsOut; ++ j) 
     453                   { 
     454                           ViewCell *vc = mViewCells[j]; 
     455 
     456                           Intersectable::NewMail(); 
     457     
     458                           char s[64]; sprintf(s, "bsp-pvs%04d.x3d", j); 
     459                           Exporter *exporter = Exporter::GetExporter(s); 
     460                           exporter->SetFilled(); 
     461 
     462                           ViewCellPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 
    452463 
    453464                           Material m;//= RandomMaterial(); 
     
    455466                           exporter->SetForcedMaterial(m); 
    456467 
    457                            exporter->ExportViewCell(mViewCells[k]); 
     468                           exporter->ExportViewCell(vc); 
     469 
     470                           Debug << "pvs size: " << (int)vc->GetPvs().GetSize() << " of " << objects.size(); 
     471                           Debug << " exporting rays: " << (int)vcRays[j].size() << endl; 
     472 
     473                           exporter->SetWireframe(); 
     474                            
     475                           m.mDiffuseColor = RgbColor(1, 0, 1); 
     476                           exporter->SetForcedMaterial(m); 
     477 
     478                           exporter->ExportBspTree(*mBspTree); 
     479                           exporter->ExportRays(vcRays[j], 1000, RgbColor(0, 1, 0)); 
    458480 
    459481                           m.mDiffuseColor = RgbColor(1, 0, 0); 
    460482                           exporter->SetForcedMaterial(m); 
    461483 
    462                            Debug << "pvs size: " << mViewCells[k]->GetPvs().GetSize() << " of " << objects.size() << endl; 
    463  
    464                            for (; it != mViewCells[k]->GetPvs().mEntries.end(); ++ it)  
     484                           // output pvs of view cell 
     485                           for (; it != vc->GetPvs().mEntries.end(); ++ it)  
    465486                           { 
    466487                                   Intersectable *intersect = (*it).first; 
     
    469490                                           exporter->ExportIntersectable(intersect); 
    470491                                           intersect->Mail(); 
    471                                    } 
    472                             
     492                                   }                     
    473493                           } 
     494 
     495                           // output rest of the objects 
     496                           if (1) 
     497                           { 
     498                                   Material m;//= RandomMaterial(); 
     499                                   m.mDiffuseColor = RgbColor(0, 0, 1); 
     500                                   exporter->SetForcedMaterial(m); 
     501                  
     502                                   for (int j = 0; j < objects.size(); ++ j) 
     503                                           if (!objects[j]->Mailed()) 
     504                                           { 
     505                                                   exporter->ExportIntersectable(objects[j]); 
     506                                                   objects[j]->Mail(); 
     507                                           } 
     508                           } 
     509                           DEL_PTR(exporter); 
    474510                   } 
    475                          
    476                    // output rest of the objects 
    477                    Material m;//= RandomMaterial(); 
    478                    m.mDiffuseColor = RgbColor(0, 0, 1); 
    479                    exporter->SetForcedMaterial(m); 
    480  
    481                    for (int j = 0; j < objects.size(); ++ j) 
    482                            if (!objects[j]->Mailed()) 
    483                            { 
    484                                    exporter->ExportIntersectable(objects[j]); 
    485                                    objects[j]->Mail(); 
    486                            } 
    487  
    488                    DEL_PTR(exporter); 
    489511          }        
    490512 
     
    529551  return true; 
    530552} 
    531  
    532    
    533  
    534      
Note: See TracChangeset for help on using the changeset viewer.