Changeset 1473


Ignore:
Timestamp:
09/22/06 16:31:02 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
8 edited

Legend:

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

    r1460 r1473  
    22#include "GvsPreprocessor.h" 
    33#include "GlRenderer.h" 
     4#include "VssRay.h" 
     5#include "ViewCellsManager.h" 
     6 
     7 
    48 
    59namespace GtpVisibilityPreprocessor 
     
    711   
    812 
    9 GvsPreprocessor::GvsPreprocessor():Preprocessor() 
     13GvsPreprocessor::GvsPreprocessor(): Preprocessor(), mSamplingType(0) 
    1014{ 
    11   environment->GetIntValue("RenderSampler.samples", mSamples); 
    12   cout << "number of render samples: " << mSamples << endl; 
    13 } 
    14    
     15        Environment::GetSingleton()->GetIntValue("RenderSampler.samples", mSamples); 
     16        //Environment::GetSingleton()->GetIntValue("Render.samples", mTotalSamples); 
    1517 
    16 void 
    17 GvsPreprocessor::GenerateRandomRay(Ray &ray) 
    18 { 
    19   int objId = RandomValue(0, mObjects.size()); 
    20   Intersectable *object = objects[objId]; 
    21   object->GetRandomSurfacePoint(point, normal); 
    22   direction = UniformRandomVector(normal); 
    23   SetupRay(ray, point, direction); 
     18        cout << "number of render samples: " << mSamples << endl; 
    2419} 
    2520 
    26 void 
    27 GvsPreprocessor::HandleRay(Ray &ray) 
     21 
     22int GvsPreprocessor::HandleRay(VssRay &ray) 
    2823{ 
    29   int sampleContributions = 0; 
    30    
    31   mKdTree->CastRay(ray); 
    32    
    33   if (ray.leaves.size()) { 
    34         sampleContributions += AddNodeSamples(object, ray, pass); 
    35      
    36         if (ray.intersections.size()) { 
    37           sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray, pass); 
     24        int sampleContributions = 0; 
     25 
     26        if (mViewCellsManager->ComputeSampleContribution(ray, true, false)) 
     27        { 
     28                return AdaptiveBorderSampling(ray); 
    3829        } 
    39   } 
     30        else 
     31        { 
     32                return ReverseSampling(ray); 
     33        } 
    4034} 
    4135 
    42 void 
    43 GvsPreprocessor::BorderSampling(Ray &ray) 
     36 
     37int GvsPreprocessor::AdaptiveBorderSampling(VssRay &ray) 
    4438{ 
    45    
    46    
     39        // TODO 
     40        return 0; 
    4741} 
    4842 
    49 void 
    50 GvsPreprocessor::Pass() 
     43 
     44int GvsPreprocessor::ReverseSampling(VssRay &ray) 
    5145{ 
    52   Ray ray; 
    53   while (1) { 
    54         AvsGenerateRay(ray); 
    55         HandleRay(ray); 
    56         while ( !mRayQueue.empty() ) { 
    57           Ray ray = mRayQueue.pop(); 
    58           mRayQueue.pop(); 
    59           AdaptiveBorderSampling(ray); 
     46        // TODO 
     47        return 0; 
     48} 
     49 
     50int GvsPreprocessor::CastAvsSamples(const int samplesPerPass,  
     51                                                                        const int sampleType,  
     52                                                                        RayQueue &passSamples) 
     53{ 
     54        SimpleRayContainer simpleRays; 
     55        const long startTime = GetTime(); 
     56 
     57        GenerateRays(samplesPerPass, sampleType, simpleRays); 
     58        Debug << "generated " <<  samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     59 
     60        VssRayContainer samples; 
     61 
     62        // cast the rays and optain hitpoints with geometry 
     63        CastRays(simpleRays, samples); 
     64        Debug << "cast " <<  samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     65 
     66        // add to ray queue 
     67        VssRayContainer::const_iterator vit, vit_end = samples.end(); 
     68 
     69        for (vit = samples.begin(); vit != vit_end; ++ vit) 
     70        { 
     71                mRayQueue.push(*vit); 
    6072        } 
    61   } 
     73 
     74        return (int)mRayQueue.size(); 
     75} 
     76 
     77 
     78int GvsPreprocessor::Pass(const int passSamples) 
     79{ 
     80        int castSamples = 0; 
     81        const int uniformSamples = 1000; 
     82 
     83        while (castSamples < passSamples)  
     84        { 
     85                // Ray queue empty =>  
     86                // cast a number of uniform samples to fill ray Queue 
     87                CastAvsSamples(uniformSamples, mSamplingType, mRayQueue); 
     88                castSamples += Pass(passSamples); 
     89        } 
     90 
     91        return castSamples; 
     92} 
     93 
     94 
     95int GvsPreprocessor::RunSampling() 
     96{ 
     97        int castSamples = 0; 
     98 
     99        while (!mRayQueue.empty())  
     100        { 
     101                // handle next ray 
     102                VssRay *ray = mRayQueue.top(); 
     103                mRayQueue.pop(); 
     104                 
     105                castSamples += HandleRay(*ray); 
     106        } 
     107 
     108        return castSamples; 
    62109} 
    63110 
     
    66113GvsPreprocessor::ComputeVisibility() 
    67114{ 
    68   long startTime = GetTime(); 
     115        Randomize(0); 
     116        const long startTime = GetTime(); 
     117         
     118        cout<<"Gvs Preprocessor started\n"<<flush; 
     119         
     120        /// construct the view cells first 
     121        ConstructViewCells(); 
    69122 
     123        int samples = 0; 
    70124 
    71   Debug << "type: gvs" << endl; 
    72    
    73   cout<<"Gvs Preprocessor started\n"<<flush; 
    74   //  cout<<"Memory/ray "<<sizeof(VssRay)+sizeof(RssTreeNode::RayInfo)<<endl; 
     125        while (samples < mTotalSamples)  
     126        { 
     127                samples += Pass(mSamplesPerPass); 
     128                 
     129                cout<<"+"; 
     130                 
     131                // mVssRays.PrintStatistics(mStats); 
     132                //mStats << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl 
     133                //         << "#TotalSamples\n" << samples << endl; 
    75134 
    76   Randomize(0); 
    77    
    78   long startTime = GetTime(); 
    79    
    80   int totalSamples = 0; 
    81    
    82   ConstructViewCells(); 
    83    
    84   int samples = 0; 
    85   int i=0; 
    86   while (samples < mTotalSamples) { 
    87         for (i=0; i < mSamplesPerPass; i++, samples++) { 
    88            
    89           if (i%10000 == 0) 
    90                 cout<<"+"; 
    91            
    92           Vector3 origin, direction; 
    93           mViewCellsManager->GetViewPoint(origin); 
    94           direction = UniformRandomVector(); 
    95            
    96           ViewCell *viewcell = mViewCellsManager->GetViewCell(origin); 
    97            
    98           if (viewcell && viewcell->GetValid()) { 
    99                 // cast rays in both directions to make the number of samples comparable 
    100                 // with the global sampling method which also casts a "double" ray per sample 
    101                 for (int j=0; j < 2; j++) { 
    102                   Intersectable *object = CastRay(origin, direction); 
    103                   if (object) { 
    104                         // if ray not outside of view space 
    105                         float contribution; 
    106                         int pvsContribution = 0; 
    107                         float relativePvsContribution = 0; 
    108                         if (object) { 
    109                           float pdf = 1.0f; 
    110                           if (viewcell->GetPvs().GetSampleContribution(object, 
    111                                                                                                                    pdf, 
    112                                                                                                                    contribution)) 
    113                                 ++pvsContribution; 
    114                           relativePvsContribution += contribution; 
    115                           viewcell->GetPvs().AddSample(object, pdf); 
    116                         } 
    117                   } 
    118                   direction = -direction; 
    119                 } 
    120           } 
    121            
    122           if (samples > mTotalSamples) 
    123                 break; 
     135                mViewCellsManager->PrintPvsStatistics(mStats); 
     136                // ComputeRenderError(); 
    124137        } 
    125          
    126         //      mVssRays.PrintStatistics(mStats); 
    127         mStats << 
    128           "#Time\n" << TimeDiff(startTime, GetTime())*1e-3<<endl<< 
    129           "#TotalSamples\n" <<samples<<endl; 
    130138 
    131         mViewCellsManager->PrintPvsStatistics(mStats); 
    132         // ComputeRenderError(); 
    133   } 
    134    
    135   //  HoleSamplingPass(); 
    136         if (0) { 
    137           Exporter *exporter = Exporter::GetExporter("ray-density.x3d");  
    138           exporter->SetExportRayDensity(true); 
    139           exporter->ExportKdTree(*mKdTree); 
    140           delete exporter; 
    141         } 
    142          
    143          
    144         // $$JB temporary removed 
    145         //      mViewCellsManager->PostProcess(objects, mSampleRays); 
    146          
    147         //-- several visualizations and statistics 
    148         Debug << "view cells after post processing: " << endl; 
    149         mViewCellsManager->PrintStatistics(Debug); 
    150          
    151         //-- render simulation after merge 
    152         cout << "\nevaluating bsp view cells render time after merge ... "; 
    153          
    154         mRenderSimulator->RenderScene(); 
    155         SimulationStatistics ss; 
    156         mRenderSimulator->GetStatistics(ss); 
    157          
    158         cout << " finished" << endl; 
    159         cout << ss << endl; 
    160         Debug << ss << endl; 
    161          
    162         // $$JB temporary removed 
    163         //mViewCellsManager->Visualize(objects, mSampleRays);    
    164  
    165   return true; 
     139        return true; 
    166140} 
    167141 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h

    r1460 r1473  
    33 
    44#include <fstream> 
     5#include <stack> 
    56using namespace std; 
    67 
     
    1011 
    1112class Exporter; 
     13class VssRay; 
    1214 
    13 /** Sampling based visibility preprocessing. The implementation is based on heuristical 
    14     sampling of view space */ 
     15 
     16typedef stack<VssRay *> RayQueue; 
     17 
     18/** Sampling based visibility preprocessing. The implementation is  
     19        based on heuristical sampling of view space. 
     20*/ 
    1521class GvsPreprocessor : public Preprocessor { 
    1622 
    1723public: 
    18   int mSamples; 
    19    
    20   GvsPreprocessor(); 
    21   ~GvsPreprocessor() {} 
    22    
    23   virtual bool ComputeVisibility(); 
    24    
    25    
     24 
     25        GvsPreprocessor(); 
     26        ~GvsPreprocessor() {} 
     27 
     28        virtual bool ComputeVisibility(); 
     29         
     30 
    2631protected: 
    27   ofstream mStats; 
    28    
     32 
     33        /** Runs the adaptive sampling. The method starts with a number of random rays given 
     34                by the queue and continues as long it finds new visible geometry (i.e., the queue is 
     35                not empty). 
     36 
     37                @returns the number of samples cast. 
     38        */ 
     39        int RunSampling(); 
     40 
     41        /** One pass of the sampling preprocessor. Continues as long as at least passSample 
     42                rays have been cast. 
     43                @returns the number of samples cast. 
     44        */ 
     45        int Pass(const int passSamples); 
     46 
     47        /** Generates the rays starting the adaptive visibility sampling process. 
     48        */ 
     49        int CastAvsSamples( 
     50                const int samplesPerPass,  
     51                const int sampleType,  
     52                RayQueue &passSamples); 
     53 
     54        /** Uses the information gained from the ray for doing adaptive border sampling. 
     55                This function tries to find the border of the triangle found visible by the 
     56                current ray. New rays are generated which sample this border. 
     57                 
     58                We use the following strategies: 
     59 
     60                a) if new triangle was found: adaptive border sampling 
     61                b) if triangle was found reverse sampling 
     62        */ 
     63        int HandleRay(VssRay &ray); 
     64 
     65        /**  
     66        */       
     67        int AdaptiveBorderSampling(VssRay &ray); 
     68         
     69        int ReverseSampling(VssRay &ray); 
     70 
     71        /** Cast samples according to a specific sampling strategy. 
     72        */ 
     73        int CastPassSamples( 
     74                const int samplesPerPass,  
     75                const int sampleType,  
     76                VssRayContainer &passSamples) const; 
     77 
     78 
     79 
     80        ////////////////////// 
     81 
     82        ofstream mStats; 
     83        int mSamples; 
     84        int mSamplesPerPass; 
     85        RayQueue mRayQueue;  
     86        int mSamplingType; 
     87        int mTotalSamples; 
    2988}; 
    3089 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1449 r1473  
    603603void HierarchyManager::ResetObjectSpaceSubdivision(const ObjectContainer &objects) 
    604604{ 
    605         Debug << "old bv hierarchy: " << mBvHierarchy->mBvhStats << endl; 
     605        Debug << "old bv hierarchy:\n " << mBvHierarchy->mBvhStats << endl; 
     606        cout << "resetting bv hierarchy" << endl; 
    606607        mHierarchyStats.nodes -= mBvHierarchy->mBvhStats.nodes; 
    607608        mHierarchyStats.mGlobalCostMisses = 0; // hack: reset global cost misses 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1449 r1473  
    132132        of split is chosen for view space / object space, the candidates for the next split of  
    133133        object space / view space must be reevaluated. 
    134          
    135134*/ 
    136135class HierarchyManager 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj

    r1315 r1473  
    328328                        <File 
    329329                                RelativePath="..\src\glInterface.h"> 
     330                        </File> 
     331                        <File 
     332                                RelativePath=".\GvsPreprocessor.cpp"> 
     333                        </File> 
     334                        <File 
     335                                RelativePath=".\GvsPreprocessor.h"> 
    330336                        </File> 
    331337                        <File 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h

    r1281 r1473  
    55#include "Matrix4x4.h" 
    66#include "Vector3.h" 
    7 //#include "ViewCellBsp.h" 
     7 
    88 
    99namespace GtpVisibilityPreprocessor { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h

    r1313 r1473  
    1717        enum {OBJECT_SPACE, VIEW_SPACE}; 
    1818 
    19         /// the current split plane 
    20         //AxisAlignedPlane mSplitPlane; 
    21         /// split axis of this plane (0, 1, 2, or 3 if non-axis-aligned) 
    22         int mSplitAxis; 
    23         /// the number of misses of max cost ratio until this split 
    24         int mMaxCostMisses; 
    25  
    2619        SubdivisionCandidate(): mRenderCostDecrease(0) {}; 
    2720 
     
    3326        /** Set render cost decrease achieved through this split. 
    3427        */ 
    35         void SetRenderCostDecrease(const float renderCostDecr) 
     28        inline void SetRenderCostDecrease(const float renderCostDecr) 
    3629        { 
    3730                mRenderCostDecrease = renderCostDecr; 
    3831        } 
    3932         
    40         float GetRenderCostDecrease() const 
     33        inline float GetRenderCostDecrease() const 
    4134        { 
    4235                return mRenderCostDecrease; 
     
    4942                return mPosition; 
    5043        } 
     44 
     45        /// split axis of this plane (0, 1, 2, or 3 if non-axis-aligned) 
     46        int mSplitAxis; 
     47        /// the number of misses of max cost ratio until this split 
     48        int mMaxCostMisses; 
    5149 
    5250protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1454 r1473  
    267267 
    268268        mPreprocessor->GenerateRays(samplesPerPass, sampleType, simpleRays); 
    269         Debug << "generated " <<  mInitialSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     269        Debug << "generated " << samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    270270 
    271271        // shoot simple ray and add it to importance samples 
    272272        mPreprocessor->CastRays(simpleRays, passSamples); 
    273         Debug << "cast " <<  mInitialSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     273        Debug << "cast " <<  samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    274274 
    275275        return (int)passSamples.size(); 
     
    18351835                        if (ray.mTerminationObject)  
    18361836                        { 
    1837                           //                            cout << "f"; 
    1838                                 if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject, 
    1839                                         ray.mPdf, 
    1840                                         contribution)) 
     1837                                if (viewcell->GetPvs().GetSampleContribution( 
     1838                                                ray.mTerminationObject, 
     1839                                                ray.mPdf, 
     1840                                                contribution)) 
    18411841                                { 
    18421842                                        ++ ray.mPvsContribution; 
Note: See TracChangeset for help on using the changeset viewer.