Changeset 1381


Ignore:
Timestamp:
09/15/06 20:55:07 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
3 edited

Legend:

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

    r1379 r1381  
    732732} 
    733733 
    734 #if 0 // matt: implemented interface samplestrategy 
    735 bool 
    736 Preprocessor::GenerateRays( 
    737                                                    const int number, 
    738                                                    const int sampleType, 
    739                                                    SimpleRayContainer &rays 
    740                                                    ) 
    741 { 
    742   Vector3 origin, direction;  
    743   int startSize = (int)rays.size(); 
    744   for (int i=0; (int)rays.size() - startSize  < number; i ++) { 
    745         // now get the direction 
    746         switch (sampleType) { 
    747         case OBJECT_BASED_DISTRIBUTION: { 
    748           mViewCellsManager->GetViewPoint(origin); 
    749           Vector3 point; 
    750           Vector3 normal; 
    751           int i = RandomValue(0, mObjects.size() - 1); 
    752           Intersectable *object = mObjects[i]; 
    753           object->GetRandomSurfacePoint(point, normal); 
    754           direction = point - origin; 
    755         } 
    756           break; 
    757         case OBJECT_DIRECTION_BASED_DISTRIBUTION: { 
    758           int i = RandomValue(0, mObjects.size() - 1); 
    759           Intersectable *object = mObjects[i]; 
    760           Vector3 normal; 
    761           object->GetRandomSurfacePoint(origin, normal); 
    762           direction = UniformRandomVector(normal); 
    763           origin += 0.1f*direction; 
    764         } 
    765           break; 
    766         case DIRECTION_BASED_DISTRIBUTION: 
    767           mViewCellsManager->GetViewPoint(origin); 
    768           direction = UniformRandomVector(); 
    769           break; 
    770         case DIRECTION_BOX_BASED_DISTRIBUTION: { 
    771           mViewCellsManager->GetViewPoint(origin); 
    772           float alpha = RandomValue(0.0f, 2*M_PI); 
    773           float beta = RandomValue(-M_PI/2, M_PI/2); 
    774           direction = VssRay::GetDirection(alpha, beta); 
    775           break; 
    776         } 
    777         case SPATIAL_BOX_BASED_DISTRIBUTION: 
    778           mViewCellsManager->GetViewPoint(origin); 
    779           direction = mKdTree->GetBox().GetRandomPoint() - origin; 
    780           break; 
    781         default: 
    782           // unsuported distribution type 
    783           return false; 
    784         } 
    785         // $$ jb the pdf is yet not correct for all sampling methods! 
    786         float pdf = 1.0f; 
    787         float c = Magnitude(direction); 
    788         if (c > Limits::Small) { 
    789           direction*=1.0f/c; 
    790           rays.AddRay(SimpleRay(origin, direction, pdf)); 
    791         } 
    792   } 
    793   return true; 
    794 } 
    795 #endif 
    796734bool Preprocessor::GenerateRays(const int number, 
    797735                                                                const int sampleType, 
    798736                                                                SimpleRayContainer &rays) 
    799737{ 
    800         Vector3 origin, direction;  
    801          
    802738        const int startSize = (int)rays.size(); 
    803739        SamplingStrategy *strategy = GenerateSamplingStrategy(sampleType); 
    804740 
    805741        if (!strategy) 
     742        { 
    806743                return false; 
     744        } 
    807745 
    808746        for (int i=0; (int)rays.size() - startSize < number; ++ i)  
    809747        { 
    810748                SimpleRay newRay; 
    811                 bool success = strategy->GenerateSample(newRay); 
    812  
    813                 if (success) 
     749 
     750                if (strategy->GenerateSample(newRay)) 
     751                { 
     752#if 1 
    814753                        rays.AddRay(newRay); 
     754#else 
     755                        GenerateRayBundle(rays, newRay, 16, 0); 
     756#endif 
     757                }        
    815758        } 
    816759 
    817760        delete strategy; 
    818  
    819761    return true; 
    820762} 
     
    14171359                return CastInternalRay(viewPoint, direction, probability, vssRays, box); 
    14181360        } 
    1419 #if DEBUG_RAYCAST 
     1361#if DEBUG_RAYCAST        
    14201362  Debug<<"CRF "<<flush; 
    14211363#endif   
     1364} 
     1365 
     1366 
     1367bool Preprocessor::GenerateRayBundle(SimpleRayContainer &rayBundle,                                                                      
     1368                                                                         const SimpleRay &mainRay, 
     1369                                                                         const int number, 
     1370                                                                         const int pertubType) const 
     1371{ 
     1372        rayBundle.push_back(mainRay); 
     1373 
     1374        const float pertubOrigin = 10.0f; 
     1375        const float pertubDir = 0.0f; 
     1376 
     1377        for (int i = 0; i < number - 1; ++ i) 
     1378        { 
     1379                Vector3 pertub; 
     1380 
     1381                pertub.x = RandomValue(0.0f, pertubDir); 
     1382                pertub.y = RandomValue(0.0f, pertubDir); 
     1383                pertub.z = RandomValue(0.0f, pertubDir); 
     1384                const Vector3 newDir = mainRay.mDirection + pertub; 
     1385                //const Vector3 newDir = mainRay.mDirection; 
     1386 
     1387                pertub.x = RandomValue(0.0f, pertubOrigin); 
     1388                pertub.y = RandomValue(0.0f, pertubOrigin); 
     1389                pertub.z = RandomValue(0.0f, pertubOrigin); 
     1390                const Vector3 newOrigin = mainRay.mOrigin + pertub; 
     1391                //const Vector3 newOrigin = mainRay.mOrigin; 
     1392 
     1393                rayBundle.push_back(SimpleRay(newOrigin, newDir, 0)); 
     1394        } 
     1395 
     1396        return true; 
    14221397} 
    14231398 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1379 r1381  
    150150                           ); 
    151151   
     152  bool GenerateRayBundle( 
     153          SimpleRayContainer &rayBundle, 
     154          const SimpleRay &mainRay, 
     155          const int number, 
     156          const int shuffleType) const; 
     157 
    152158  virtual void CastRays(SimpleRayContainer &rays, 
    153159                                                VssRayContainer &vssRays); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1344 r1381  
    324324int ViewCellsManager::Construct(Preprocessor *preprocessor, VssRayContainer *outRays) 
    325325{ 
    326         mPreprocessor = preprocessor; 
    327  
    328326        int numSamples = 0; 
    329327 
     
    331329        VssRayContainer initialSamples; 
    332330 
     331        // store pointer to preprocessor for further use during construction 
     332        mPreprocessor = preprocessor; 
     333         
     334         
     335        /////////////////////////////////////////////////////// 
     336        //-- Initial sampling for the construction of the view cell hierarchy.  
     337        //-- We use uniform sampling / box based sampling. 
     338         
     339        long startTime = GetTime(); 
     340 
    333341        cout << "view cell construction: casting " << mInitialSamples << " initial samples ... "; 
    334  
    335         long startTime = GetTime(); 
    336  
    337         //-- construction rays => we use uniform samples for this 
    338  
     342        // cast initial samples 
    339343        CastPassSamples(mInitialSamples, mSamplingType, initialSamples); 
    340          
     344 
    341345        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    342346 
     
    356360                  << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    357361 
    358         // take post processing time 
    359         startTime = GetTime(); 
    360  
    361         //-- stats after construction 
     362 
     363        /////////////////////////////////////////// 
     364        //-- Initial hierarchy construction finished 
     365        //-- We can do some stats and visualization 
     366         
    362367        ResetViewCells(); 
    363368        Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl; 
    364369 
    365         if (0) // export initial view cells 
     370 
     371        //-- optionally export initial view cells 
     372        if (0)  
    366373        { 
    367374                const char filename[] = "view_cells.wrl"; 
    368375                Exporter *exporter = Exporter::GetExporter(filename); 
    369  
    370376         
    371377                if (exporter) 
     
    385391        } 
    386392 
    387         //-- guided rays are used for further sampling 
     393 
     394        //////////////////////////////////////////////// 
     395        // 
     396        //-- Cast some more sampling after initial construction. 
     397        //-- The additional rays can be used to gain 
     398        //-- some more information before the bottom-up merge 
     399        //-- note: guided rays could be used for this task 
     400 
     401        // time spent after initial construction 
     402        startTime = GetTime(); 
     403 
    388404        const int n = mConstructionSamples; //+initialSamples; 
    389  
    390405        // should we use directional samples? 
    391406        bool dirSamples = (mSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION); 
    392407 
    393         //-- do some more sampling 
    394408        while (numSamples < n) 
    395409        { 
     
    412426 
    413427                cout << "finished" << endl; 
    414  
    415428                cout << "computing sample contribution for " << (int)constructionSamples.size() << " samples ... "; 
    416429 
     
    421434                cout << "finished" << endl; 
    422435 
    423  
    424436                disposeRays(constructionSamples, outRays); 
    425  
    426437                cout << "total samples: " << numSamples << endl; 
    427438        } 
    428439 
    429         //-- post processing 
    430         VssRayContainer postProcessSamples; 
    431  
    432         cout << "casting " << mPostProcessSamples << " post processing samples ... "; 
    433  
    434         // cast post processing samples rays  (storing the view cells if wanted) 
    435         CastPassSamples(mPostProcessSamples, 
    436                                         mSamplingType,  
    437                                         postProcessSamples); 
    438  
    439         cout << "finished" << endl; 
    440  
    441         // stats before post processing (i.e., merge) 
     440         
     441        //////////////////////////////////////////////// 
     442        //-- get stats after the additional sampling step 
     443        //-- and before the bottom-up merge step 
     444 
    442445        EvaluateViewCellsStats(); 
    443         Debug << "\noriginal view cell partition before post process:\n" << mCurrentViewCellsStats << endl; 
     446        Debug << "\noriginal view cell partition before post process:\n"  
     447                  << mCurrentViewCellsStats << endl; 
    444448 
    445449        mRenderer->RenderScene(); 
     
    450454 
    451455 
     456 
     457        /////////////////////////////////////////////// 
     458        // 
     459        //-- post processing of the initial construction 
     460        //-- We can bottom-up merge the view cells in this step 
     461 
     462 
     463        // we can additionally cast some post processing sample rays. 
     464        // These rays can be used to store the view cells with the rays 
     465        VssRayContainer postProcessSamples; 
     466        cout << "casting " << mPostProcessSamples << " post processing samples ... "; 
     467         
     468        CastPassSamples(mPostProcessSamples, mSamplingType, postProcessSamples); 
     469 
     470        cout << "finished" << endl; 
    452471        cout << "starting post processing and visualization" << endl; 
    453472 
    454         // store view cells for postprocessing 
     473        // store view cells for post processing? 
    455474        const bool storeViewCells = true; 
    456475 
     
    458477                ComputeSampleContributions(postProcessSamples, true, storeViewCells); 
    459478 
    460         //-- post processing (e.g.,merging) of the view cells 
    461         if (1) PostProcess(preprocessor->mObjects, postProcessSamples); 
     479        PostProcess(preprocessor->mObjects, postProcessSamples); 
    462480 
    463481        cout << "time needed for post processing (merge) step: " 
     
    470488 
    471489         
    472         //return 1; 
    473         // evaluation of the paritition, i.e., a number of new samples are cast 
     490        ///////////////////////////////////////////////////////////////////// 
     491        //-- Evaluation of the resulting view cell partition.  
     492        //-- We cast a number of new samples and measure the render cost 
     493 
    474494        if (mEvaluateViewCells) 
    475495        { 
     
    477497        } 
    478498 
     499         
     500        /////////////////////////////////// 
     501        //-- Finally, we do some visualization 
     502 
    479503        if (mShowVisualization) 
    480504        { 
    481                 //-- visualization 
    482505                VssRayContainer visualizationSamples; 
    483506 
    484                 //-- construction rays => we use uniform samples for this 
     507                //-- visualization rays, e.g., to show some samples in the scene 
    485508                CastPassSamples(mVisualizationSamples, 
    486509                                            Preprocessor::DIRECTION_BASED_DISTRIBUTION,  
Note: See TracChangeset for help on using the changeset viewer.