Ignore:
Timestamp:
09/26/06 10:05:29 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
4 edited

Legend:

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

    r1486 r1489  
    24322432                                        optBool, 
    24332433                                        "bvh_construction_use_global_sorting=", 
    2434                                         "false"); 
     2434                                        "true"); 
    24352435 
    24362436         
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp

    r1486 r1489  
    55#include "ViewCellsManager.h" 
    66#include "Triangle3.h" 
    7  
     7#include "IntersectableWrapper.h" 
    88 
    99 
     
    2929 
    3030 
    31 const bool GvsPreprocessor::DiscontinuityFound(const VssRay &ray) const 
    32 { 
     31const bool GvsPreprocessor::DiscontinuityFound(const VssRay &ray,  
     32                                                                                           const VssRay &oldRay) const 
     33{ 
     34    //const Plane3 plane = tri->GetPlane(); 
    3335        return false; 
    3436} 
     
    5254} 
    5355 
    54  
    55 void GvsPreprocessor::CreateNewSamples(VertexContainer &samples,  
    56                                                                            const VssRay &ray,  
    57                                                                            const Triangle3 &hitTriangle,  
    58                                                                            const int index, 
    59                                                                            const float eps) 
     56/** Hepler function for adaptive border sampling. It finds  
     57        new sample points around a triangle in a eps environment 
     58*/ 
     59static void CreateNewSamples(VertexContainer &samples,  
     60                                                         const Triangle3 &hitTriangle, 
     61                                                         const VssRay &ray,  
     62                                                         const int index, 
     63                                                         const float eps) 
    6064{ 
    6165        const int indexU = (index + 1) % 3; 
     
    8690 
    8791 
    88 int GvsPreprocessor::AdaptiveBorderSampling(const VssRay &ray) 
     92/** Generate rays from sample points. 
     93*/ 
     94static void CreateRays(VssRayContainer &rays, 
     95                                           const VertexContainer &samples) 
     96{ 
     97        VertexContainer::const_iterator vit, vit_end = samples.end(); 
     98         
     99        for (vit = samples.begin(); vit != vit_end; ++ vit) 
     100        { 
     101                const Vector3 currentSample = *vit; 
     102                VssRay *ray;// = new VssRay(ray->mOrigin, currentSample); 
     103        } 
     104} 
     105 
     106 
     107int GvsPreprocessor::AdaptiveBorderSampling(const VssRay &prevRay) 
    89108{ 
    90109        cout << "a"; 
    91         //Intersectable *tObj = ray->GetTerminationObject; 
     110        Intersectable *tObj = prevRay.mTerminationObject; 
    92111        Triangle3 hitTriangle; 
    93         vector<Vector3> samples; 
     112 
     113        // other types not implemented yet 
     114        if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 
     115        { 
     116                hitTriangle = dynamic_cast<TriangleIntersectable *>(tObj)->GetItem(); 
     117        } 
     118 
     119        VertexContainer samples; 
    94120        samples.reserve(9); 
    95121 
    96         CreateNewSamples(samples, ray, hitTriangle, 0, mEps); 
    97         CreateNewSamples(samples, ray, hitTriangle, 1, mEps); 
    98         CreateNewSamples(samples, ray, hitTriangle, 2, mEps); 
    99  
    100         VertexContainer::const_iterator vit, vit_end = samples.end(); 
    101          
    102         for (vit = samples.begin(); vit != vit_end; ++ vit) 
    103         { 
    104                 VssRay *ray;// = CreateRay(*vit); 
    105  
    106                 if (DiscontinuityFound(*ray)) 
    107                 { 
    108                         // schedule for reverse sampling 
    109                         mRayQueue.push(GvsRayInfo(ray, true)); 
    110                 } 
    111                 else 
    112                 { 
    113                         // schedule for adaptive border sampling 
    114                         mRayQueue.push(GvsRayInfo(ray, false)); 
    115                 } 
    116         } 
    117  
    118         // TODO 
    119         return 1; 
     122        CreateNewSamples(samples, hitTriangle, prevRay, 0, mEps); 
     123        CreateNewSamples(samples, hitTriangle, prevRay, 1, mEps); 
     124        CreateNewSamples(samples, hitTriangle, prevRay, 2, mEps); 
     125 
     126        VssRayContainer vssRays; 
     127        CreateRays(vssRays, samples); 
     128 
     129        VssRayContainer::const_iterator rit, rit_end = vssRays.end(); 
     130         
     131        for (rit = vssRays.begin(); rit != rit_end; ++ rit) 
     132        { 
     133                VssRay *ray = *rit; 
     134 
     135                // discontinuity found?  
     136                // schedule for reverse sampling or adaptive border sampling 
     137                const bool gap = DiscontinuityFound(*ray, prevRay); 
     138                mRayQueue.push(GvsRayInfo(ray, gap)); 
     139        } 
     140 
     141        return 9; 
    120142} 
    121143 
     
    128150} 
    129151 
    130 int GvsPreprocessor::CastAvsSamples(const int samplesPerPass,  
    131                                                                         const int sampleType,  
    132                                                                         RayQueue &passSamples) 
    133 { 
     152 
     153int GvsPreprocessor::CastInitialSamples(const int numSamples,  
     154                                                                                const int sampleType) 
     155{        
     156        const long startTime = GetTime(); 
     157 
     158        // generate simple rays 
    134159        SimpleRayContainer simpleRays; 
    135         const long startTime = GetTime(); 
    136  
    137         GenerateRays(samplesPerPass, sampleType, simpleRays); 
    138         Debug << "generated " <<  samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    139  
    140         // cast the rays and optain hitpoints with geometry 
     160        GenerateRays(numSamples, sampleType, simpleRays); 
     161         
     162        // generate vss rays 
    141163        VssRayContainer samples; 
    142164        CastRays(simpleRays, samples); 
    143  
    144         Debug << "cast " <<  samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    145  
     165         
     166        // add to ray queue 
     167        EnqueueSamples(samples); 
     168 
     169        Debug << "generated " <<  numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     170 
     171        return (int)samples.size(); 
     172} 
     173 
     174 
     175void GvsPreprocessor::EnqueueSamples(VssRayContainer &samples, VssRay *oldRay) 
     176{ 
    146177        // add samples to ray queue 
    147178        VssRayContainer::const_iterator vit, vit_end = samples.end(); 
    148179        for (vit = samples.begin(); vit != vit_end; ++ vit) 
    149180        { 
    150                 mRayQueue.push(*vit); 
    151         } 
    152  
    153         return (int)mRayQueue.size(); 
     181                /// if there is no old ray, no discontinuity 
     182                const bool gap = oldRay ? DiscontinuityFound(*(*vit), *oldRay) : false; 
     183                mRayQueue.push(GvsRayInfo(*vit, gap)); 
     184        } 
     185 
    154186} 
    155187 
     
    158190{ 
    159191        int castSamples = 0; 
    160          
     192        const int mSampleType = 0; 
    161193        while (castSamples < mSamplesPerPass)  
    162194        { 
    163195                // Ray queue empty =>  
    164196                // cast a number of uniform samples to fill ray Queue 
    165                 CastAvsSamples(mInitialSamples, mSamplingType, mRayQueue); 
    166                  
    167                 const int gvsSamples = RunSampling(); 
     197                CastInitialSamples(mInitialSamples, mSampleType); 
     198 
     199                const int gvsSamples = ProcessQueue(); 
    168200                castSamples += gvsSamples; 
    169                 //cout << "\ngvs samples: " << gvsSamples << endl; 
    170                 //cout << "cast " << castSamples << " of " << mSamplesPerPass << endl; 
     201                //cout << "\ncast " << castSamples << " of " << mSamplesPerPass << endl; 
    171202        } 
    172203 
     
    175206 
    176207 
    177 int GvsPreprocessor::RunSampling() 
     208int GvsPreprocessor::ProcessQueue() 
    178209{ 
    179210        int castSamples = 0; 
     
    182213        { 
    183214                // handle next ray 
    184                 VssRay *ray = mRayQueue.top(); 
     215                GvsRayInfo rayInfo = mRayQueue.top(); 
    185216                mRayQueue.pop(); 
    186217                 
    187                 castSamples += HandleRay(*ray); 
     218                castSamples += HandleRay(rayInfo); 
    188219        } 
    189220 
     
    192223 
    193224 
    194 bool 
    195 GvsPreprocessor::ComputeVisibility() 
     225bool GvsPreprocessor::ComputeVisibility() 
    196226{ 
    197227        Randomize(0); 
     
    213243                const int passSamples = Pass(); 
    214244                castSamples += passSamples; 
     245                 
     246                ///////////// 
     247                // -- stats 
    215248                cout << "+"; 
    216249                cout << "\nsamples cast " << passSamples << " (=" << castSamples << " of " << mTotalSamples << ")" << endl; 
    217250                //mVssRays.PrintStatistics(mStats); 
    218                 //mStats << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl 
    219                 //         << "#TotalSamples\n" << samples << endl; 
     251                mStats << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl 
     252                           << "#TotalSamples\n" << castSamples << endl; 
    220253 
    221254                mViewCellsManager->PrintPvsStatistics(mStats); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h

    r1486 r1489  
    1212class Exporter; 
    1313class VssRay; 
     14 
    1415 
    1516 
     
    3132        struct GvsRayInfo 
    3233        { 
     34                GvsRayInfo(VssRay *ray, const bool d) 
     35                        : mRay(ray), mFoundDiscontinuity(d)  
     36                {} 
     37 
    3338                VssRay *mRay; 
    3439                bool mFoundDiscontinuity; 
    35         } 
     40        }; 
    3641 
    37          
     42 
    3843        typedef stack<GvsRayInfo> RayQueue; 
    3944 
    40         /** Runs the adaptive sampling. The method starts with a number of random rays given 
    41                 by the queue and continues as long it finds new visible geometry (i.e., the queue is 
    42                 not empty). 
     45        /** Runs the adaptive sampling until the ray queue is empty.  
     46                The method starts with a number of random rays given 
     47                by the queue and continues as long it finds new visible geometry  
     48                (i.e., the queue is     not empty). 
    4349 
    4450                @returns the number of samples cast. 
    4551        */ 
    46         int RunSampling(); 
     52        int ProcessQueue(); 
    4753 
    48         /** One pass of the sampling preprocessor. Continues as long as at least passSample 
    49                 rays have been cast. 
     54        /** One pass of the sampling preprocessor.  
     55                Continues as long as at least passSample rays have been cast. 
    5056                @returns the number of samples cast. 
    5157        */ 
     
    5460        /** Generates the rays starting the adaptive visibility sampling process. 
    5561        */ 
    56         int CastAvsSamples( 
    57                 const int samplesPerPass,  
    58                 const int sampleType,  
    59                 RayQueue &passSamples); 
     62        int CastInitialSamples(const int numSamples, const int sampleType); 
    6063 
    6164        /** Uses the information gained from the ray for doing adaptive border sampling. 
     
    7073        int HandleRay(const GvsRayInfo &ray); 
    7174 
    72         /**  
     75        /** The adaptive border sampling step. It aims to find neighbouring  
     76                triangles of the one hit by the previous ray. 
    7377        */       
    74         int AdaptiveBorderSampling(const VssRay &ray); 
     78        int AdaptiveBorderSampling(const VssRay &prevRay); 
    7579         
    76         int ReverseSampling(const VssRay &ray); 
     80        /** The reverse sampling step. It is started once the cast 
     81                ray finds a discontinuity, i.e., a closer triangle. 
     82                Then the process tries to find a ray from the old 
     83                triangle passing through a gap. 
     84        */ 
     85        int ReverseSampling(const VssRay &prevRay); 
    7786 
    78         /** Cast samples according to a specific sampling strategy. 
     87        /** Returns true if we sampled a closer triangle than with the previous ray. 
    7988        */ 
    80         int CastPassSamples( 
    81                 const int samplesPerPass,  
    82                 const int sampleType,  
    83                 VssRayContainer &passSamples) const; 
     89        const bool DiscontinuityFound(const VssRay &ray, const VssRay &prevRay) const; 
    8490 
    85         void CreateNewSamples( 
    86                 VertexContainer &samples,  
    87                 const VssRay &ray,  
    88                 const Triangle3 &hitTriangle,  
    89                 const int index, 
    90                 const float eps); 
    91  
    92         const bool DiscontinuityFound(const VssRay &ray) const; 
    93  
    94  
     91        /** Adds new samples to the ray queue and classifies them 
     92                with respect to the previous ray. 
     93        */ 
     94        void EnqueueSamples(VssRayContainer &samples, VssRay *prevRay = NULL); 
     95         
    9596        ////////////////////// 
    9697 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1416 r1489  
    14851485{ 
    14861486         stats << "#Pass\n" << pass << endl 
    1487                 //<< "#Merged\n" << mergeStats.merged << endl  
    14881487                << "#ViewCells\n" << viewCells << endl  
    14891488        << "#RenderCostDecrease\n" << renderCostDecrease << endl // TODO 
     
    14991498                << endl; 
    15001499} 
     1500 
    15011501 
    15021502void ViewCellsTree::ExportStats(const string &mergeStats) 
Note: See TracChangeset for help on using the changeset viewer.