Changeset 1968


Ignore:
Timestamp:
01/11/07 04:18:36 (17 years ago)
Author:
mattausch
Message:

early exit for global lines
preprocessor support

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
10 edited

Legend:

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

    r1966 r1968  
    11881188                                 "1000000"); 
    11891189 
     1190  RegisterOption("Preprocessor.useHwGlobalLines", 
     1191                                 optBool, 
     1192                                 "preprocessor_use_hw_global_lines=", 
     1193                                 "false"); 
     1194 
     1195   RegisterOption("Preprocessor.HwGlobalLines.texHeight", 
     1196                                  optInt, 
     1197                                  "preprocessor_hw_global_lines_texheight=", 
     1198                                  "128"); 
     1199 
     1200    RegisterOption("Preprocessor.HwGlobalLines.texWidth", 
     1201                                   optInt, 
     1202                                   "preprocessor_hw_global_lines_texwidth=", 
     1203                                   "128"); 
     1204 
     1205        RegisterOption("Preprocessor.HwGlobalLines.stepSize", 
     1206                                   optFloat, 
     1207                                   "preprocessor_hw_global_lines_stepsize=", 
     1208                                   "0.0001"); 
     1209 
     1210        RegisterOption("Preprocessor.HwGlobalLines.maxDepth", 
     1211                                   optInt, 
     1212                                   "preprocessor_hw_global_lines_max_depth=", 
     1213                                   "50"); 
     1214 
     1215        RegisterOption("Preprocessor.HwGlobalLines.sampleReverse", 
     1216                                   optBool, 
     1217                                   "preprocessor_hw_global_lines_sample_reverse=", 
     1218                                   "true"); 
     1219 
    11901220  RegisterOption("RenderSampler.samples", 
    11911221                                 optInt, 
     
    11981228                                 "0"); 
    11991229 
    1200  
    12011230   RegisterOption("RenderSampler.useOcclusionQueries", 
    12021231                                 optBool, 
     
    12521281 
    12531282 
    1254    /************************************************************************************/ 
    1255    /*                         GvsPrerpocessor related options                          */ 
    1256    /************************************************************************************/ 
     1283   /*************************************************************************/ 
     1284   /*                       GvsPrerpocessor related options                 */ 
     1285   /*************************************************************************/ 
    12571286 
    12581287 
     
    12871316                                        "gvsStats.log"); 
    12881317 
    1289   /***********************************************************************************/ 
    1290   /*                         View cells related options                              */ 
    1291   /***********************************************************************************/ 
     1318         
     1319  /**********************************************************************/ 
     1320  /*                     View cells related options                     */ 
     1321  /**********************************************************************/ 
    12921322 
    12931323 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h

    r1960 r1968  
    224224public: 
    225225 
    226 GlRendererBuffer(SceneGraph *sceneGraph, 
    227                                  ViewCellsManager *viewcells, 
    228                                  KdTree *tree); 
    229  
    230   virtual ~GlRendererBuffer(); 
     226        GlRendererBuffer(SceneGraph *sceneGraph, 
     227                ViewCellsManager *viewcells, 
     228                KdTree *tree); 
     229 
     230        virtual ~GlRendererBuffer(); 
    231231 
    232232        /** Evaluates render cost of a point sample. 
    233                 @param sample the render cost sample to be evaluated 
    234                 @param useOcclusionQueries if occlusion queries should be used or item buffer 
    235                 @param threshold number of pixels / samples from where an object is considered visible. 
    236         */ 
    237   virtual void EvalRenderCostSample(RenderCostSample &sample, 
    238                                                           const bool useOcclusionQueries, 
    239                                                           const int threshold); 
     233        @param sample the render cost sample to be evaluated 
     234        @param useOcclusionQueries if occlusion queries should be used or item buffer 
     235        @param threshold number of pixels / samples from where an object is considered visible. 
     236        */ 
     237        virtual void EvalRenderCostSample(RenderCostSample &sample, 
     238                const bool useOcclusionQueries, 
     239                const int threshold); 
    240240 
    241241        /** Evaluates render cost of a number of point samples. The point samples 
    242                 are distributed uniformly over the defined view space. 
    243  
    244                 @param numSamples the number of point samples taken 
    245                 @param samples stores the taken point samples in a container 
    246                 @param useOcclusionQueries if occlusion queries should be used or item buffer 
    247                 @param threshold number of pixels / samples from where an object is considered visible. 
    248         */ 
    249   virtual void SampleRenderCost(const int numSamples,  
    250                                                                 vector<RenderCostSample> &samples, 
    251                                                                 const bool useOcclusionQueries, 
    252                                                                 const int threshold = 0); 
    253    
     242        are distributed uniformly over the defined view space. 
     243 
     244        @param numSamples the number of point samples taken 
     245        @param samples stores the taken point samples in a container 
     246        @param useOcclusionQueries if occlusion queries should be used or item buffer 
     247        @param threshold number of pixels / samples from where an object is considered visible. 
     248        */ 
     249        virtual void SampleRenderCost(const int numSamples,  
     250                vector<RenderCostSample> &samples, 
     251                const bool useOcclusionQueries, 
     252                const int threshold = 0); 
     253 
    254254 
    255255        /** Implerment in subclasses. 
    256256        */ 
    257   virtual void EvalPvsStat(); 
    258  
    259  
    260   virtual int GetWidth() const = 0; 
    261   virtual int GetHeight() const  = 0;  
    262  
    263   virtual void MakeCurrent() = 0; 
    264   virtual void DoneCurrent() = 0; 
    265    
    266  
    267   virtual void SampleBeamContributions( 
    268                                                            Intersectable *sourceObject, 
    269                                                            Beam &beam, 
    270                                                            const int samples, 
    271                                                            BeamSampleStatistics &stat 
    272                                                            ); 
    273  
    274   virtual void 
    275   SampleViewpointContributions( 
    276                                                            Intersectable *sourceObject, 
    277                                                            const Vector3 viewPoint, 
    278                                                            Beam &beam, 
    279                                                            const int desiredSamples, 
    280                                                            BeamSampleStatistics &stat 
    281                                                            ); 
    282  
    283   virtual void InitGL(); 
    284  
    285   /** Computes rays from information gained with hw sampling- 
    286   */ 
    287   virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays); 
    288  
    289   virtual int ComputePvs() const = 0; 
    290  
    291    
    292   virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0; 
    293  
    294  
    295  
    296    
     257        virtual void EvalPvsStat(); 
     258 
     259 
     260        virtual int GetWidth() const = 0; 
     261        virtual int GetHeight() const  = 0;  
     262 
     263        virtual void MakeCurrent() = 0; 
     264        virtual void DoneCurrent() = 0; 
     265 
     266 
     267        virtual void SampleBeamContributions( 
     268                Intersectable *sourceObject, 
     269                Beam &beam, 
     270                const int samples, 
     271                BeamSampleStatistics &stat 
     272                ); 
     273 
     274        virtual void 
     275                SampleViewpointContributions( 
     276                Intersectable *sourceObject, 
     277                const Vector3 viewPoint, 
     278                Beam &beam, 
     279                const int desiredSamples, 
     280                BeamSampleStatistics &stat 
     281                ); 
     282 
     283        virtual void InitGL(); 
     284 
     285        /** Computes rays from information gained with hw sampling- 
     286        */ 
     287        virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays); 
     288 
     289        virtual int ComputePvs() const = 0; 
     290 
     291        virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0; 
     292 
     293 
    297294protected: 
    298   unsigned int *mPixelBuffer; 
    299    
    300   static void GenQueries(const int numQueries); 
    301          
    302   virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,  
    303                                                                          const Beam &beam,  
    304  
    305                                                                          Intersectable *sourceObject); 
     295 
     296        unsigned int *mPixelBuffer; 
     297 
     298        static void GenQueries(const int numQueries); 
     299 
     300        virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,  
     301                const Beam &beam,  
     302 
     303                Intersectable *sourceObject); 
    306304 
    307305        /** Evaluates query for one direction using item buffer. 
    308306        */ 
    309   virtual void EvalQueryWithItemBuffer(); 
     307        virtual void EvalQueryWithItemBuffer(); 
    310308 
    311309        /** Evaluates query for one direction using occlusion queries. 
    312310        */ 
    313   virtual void EvalQueryWithOcclusionQueries(); 
     311        virtual void EvalQueryWithOcclusionQueries(); 
    314312 
    315313public: 
    316314        // matt: remove qt dependencies 
    317  // signals: 
    318 //      void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &); 
     315        // signals: 
     316        //      void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &); 
    319317}; 
    320318 
     
    325323{ 
    326324public: 
    327          
     325 
    328326        GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree): 
    329327          GlRenderer(sceneGraph, vcm, kdTree) 
    330         {} 
    331  
    332     GlRendererWidget() {} 
    333  
    334     virtual ~GlRendererWidget() {} 
    335  
    336         //virtual void Create() {} 
    337         virtual void Show() {} 
    338          
     328          {} 
     329 
     330          GlRendererWidget() {} 
     331 
     332          virtual ~GlRendererWidget() {} 
     333 
     334          //virtual void Create() {} 
     335          virtual void Show() {} 
     336 
    339337 
    340338protected: 
    341339 
    342340 
    343   //    SceneGraph *mSceneGraph; 
    344   //    ViewCellsManager *mViewCellsManager; 
    345   //    KdTree *mKdTree; 
     341        //      SceneGraph *mSceneGraph; 
     342        //      ViewCellsManager *mViewCellsManager; 
     343        //      KdTree *mKdTree; 
    346344}; 
    347345 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.cpp

    r1964 r1968  
    200200 
    201201 
    202 /*GlobalLinesRenderer::GlobalLinesRenderer(RenderTexture *buffer1,  
    203                                                                                  RenderTexture *buffer2,  
    204                                                                                  Preprocessor *preprocessor, 
    205                                                                                  GlRenderer *renderer) 
    206 : mNewTexture(buffer1), mOldTexture(buffer2), mPreprocessor(preprocessor), mMaxDepth(100), 
    207 mRenderer(renderer) 
    208 { 
    209 } 
    210 */ 
    211  
    212  
    213202GlobalLinesRenderer::GlobalLinesRenderer(Preprocessor *preprocessor,  
    214                                                                                  GlRenderer *renderer, 
    215                                                                                  const float mTexHeight, 
    216                                                                                  const float mTexWidth, 
    217                                                                                  const float eps):  
     203                                                                                 const int texHeight, 
     204                                                                                 const int texWidth, 
     205                                                                                 const float eps, 
     206                                                                                 const int maxDepth, 
     207                                                                                 const bool sampleReverse): 
    218208mNewTexture(NULL),  
    219209mOldTexture(NULL),  
    220 mMaxDepth(0),  
    221 mRenderer(renderer),  
    222210mPreprocessor(preprocessor), 
    223211mTexHeight(mTexHeight), 
    224212mTexWidth(mTexWidth), 
    225 mEpsilon(eps) 
    226 { 
    227 } 
    228  
    229  
    230 GlobalLinesRenderer::GlobalLinesRenderer(Preprocessor *preprocessor,  
    231                                                                                  GlRenderer *renderer): 
     213mEpsilon(eps), 
     214mMaxDepth(maxDepth), 
     215mSampleReverse(sampleReverse) 
     216{ 
     217        mRenderer = new GlRenderer(mPreprocessor->mSceneGraph, 
     218                                                           mPreprocessor->mViewCellsManager, 
     219                                                           mPreprocessor->mKdTree); 
     220 
     221} 
     222 
     223 
     224GlobalLinesRenderer::GlobalLinesRenderer(Preprocessor *preprocessor): 
    232225mNewTexture(NULL),  
    233226mOldTexture(NULL),  
    234 mMaxDepth(0),  
    235 mRenderer(renderer),  
     227mMaxDepth(40),  
    236228mPreprocessor(preprocessor), 
    237229mTexHeight(128), 
    238230mTexWidth(128), 
    239 mEpsilon(0.0001) 
    240 {} 
     231mEpsilon(0.0001), 
     232mSampleReverse(true) 
     233{ 
     234        mRenderer = new GlRenderer(mPreprocessor->mSceneGraph, 
     235                                                           mPreprocessor->mViewCellsManager, 
     236                                                           mPreprocessor->mKdTree); 
     237} 
    241238 
    242239 
     
    288285        delete mNewItemBuffer; 
    289286        delete mOldItemBuffer; 
     287 
     288        DEL_PTR(mRenderer); 
    290289} 
    291290 
    292291  
    293 void GlobalLinesRenderer::InitScene(const float alpha, const float beta) 
    294 { 
    295         AxisAlignedBox3 bbox = globalLinesRenderer->mPreprocessor->mKdTree->GetBox(); 
    296          
    297         const float sceneSize = Magnitude(bbox.Diagonal()); 
    298  
    299         // compute the center of the scene 
    300         Vector3 midPoint = bbox.Center(); 
    301          
    302         // add a small offset to provide some randomness in the sampling 
    303         Vector3 offset(Random(sceneSize * 1e-3f),  
    304                                    Random(sceneSize * 1e-3f),  
    305                                    Random(sceneSize * 1e-3f)); 
    306  
    307         midPoint += offset; 
    308                  
    309         mNear = 1; 
    310         mFar = sceneSize * 2; 
    311         mWidth = sceneSize; 
    312  
    313         ComputeLookAt(alpha,  
    314                                   beta, 
    315                                   mEyeVec,  
    316                                   mUpVec, 
    317                                   mLeftVec); 
    318          
    319         mViewPoint = midPoint - 0.5f * sceneSize * mEyeVec; 
    320  
    321         cout << "mid point: " << midPoint << endl; 
    322         cout << "view point: " << mViewPoint << endl; 
    323         cout << "scene: " << bbox << endl; 
    324  
     292void GlobalLinesRenderer::InitRenderTexture(RenderTexture *rt) 
     293{ 
    325294         // setup the rendering context for the RenderTexture 
    326         mNewTexture->BeginCapture(); 
     295        rt->BeginCapture(); 
    327296        { 
    328297                //Reshape(mTexWidth, mTexHeight); 
     
    346315                glLoadIdentity(); 
    347316                gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z,  
    348                                   midPoint.x, midPoint.y, midPoint.z,  
     317                                  mTermination.x, mTermination.y, mTermination.z,  
    349318                                  mUpVec.x, mUpVec.y, mUpVec.z); 
    350319 
    351320        } 
    352         mNewTexture->EndCapture(); 
    353  
    354         // setup the rendering context for the other depth buffer 
    355         mOldTexture->BeginCapture(); 
    356         { 
    357                 // for item buffer: white means no color 
    358                 glClearColor(1, 1, 1, 1); 
    359         
    360                 //Reshape(mTexWidth, mTexHeight); 
    361                 glViewport(0, 0, mTexWidth, mTexHeight); 
    362                 SetFrustum(mWidth, mWidth, mNear, mFar); 
    363  
    364                 glMatrixMode(GL_MODELVIEW); 
    365                 glLoadIdentity(); 
     321        rt->EndCapture(); 
     322} 
     323 
     324 
     325void GlobalLinesRenderer::InitScene(const float alpha, const float beta) 
     326{ 
     327        AxisAlignedBox3 bbox =  
     328                globalLinesRenderer->mPreprocessor->mKdTree->GetBox(); 
     329         
     330        const float sceneSize = Magnitude(bbox.Diagonal()); 
     331 
     332        // compute the center of the scene 
     333        mTermination = bbox.Center(); 
     334         
     335        // add a small offset to provide some randomness in the sampling 
     336        if (0) 
     337        { 
     338                Vector3 offset( 
     339                        Random(sceneSize * 1e-3f),  
     340                        Random(sceneSize * 1e-3f),  
     341                        Random(sceneSize * 1e-3f)); 
     342 
     343                mTermination += offset; 
     344        } 
    366345                 
    367                 glFrontFace(GL_CCW); 
    368                 glCullFace(GL_BACK); 
    369                  
    370                 glDisable(GL_CULL_FACE); 
    371                 //glEnable(GL_CULL_FACE); 
    372                  
    373                 glShadeModel(GL_FLAT); 
    374                 glEnable(GL_DEPTH_TEST); 
    375                  
    376                 gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z,  
    377                                   midPoint.x, midPoint.y, midPoint.z,  
    378                                   mUpVec.x, mUpVec.y, mUpVec.z); 
    379         } 
    380         mOldTexture->EndCapture(); 
    381  
     346        mNear = 1; 
     347        mFar = sceneSize * 2; 
     348        mWidth = sceneSize; 
     349 
     350        ComputeLookAt(alpha,  
     351                                  beta, 
     352                                  mEyeVec,  
     353                                  mUpVec, 
     354                                  mLeftVec); 
     355         
     356        mViewPoint = mTermination - 0.5f * sceneSize * mEyeVec; 
     357 
     358        cout << "termination point: " << mTermination << endl; 
     359        cout << "view point: " << mViewPoint << endl; 
     360        cout << "scene: " << bbox << endl; 
     361 
     362        InitRenderTexture(mNewTexture); 
     363        InitRenderTexture(mOldTexture); 
     364         
     365        cout << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl; 
     366} 
     367 
     368 
     369void GlobalLinesRenderer::InitScene(const SimpleRay &ray) 
     370{ 
     371        AxisAlignedBox3 bbox =  
     372                globalLinesRenderer->mPreprocessor->mKdTree->GetBox(); 
     373         
     374        const float sceneSize = Magnitude(bbox.Diagonal()); 
     375 
     376        // compute the center of the scene 
     377        mViewPoint = ray.mOrigin; 
     378        mTermination = ray.mOrigin + ray.mDirection; 
     379 
     380        mEyeVec = Normalize(ray.mDirection); 
     381 
     382        mNear = 1; 
     383        mFar = sceneSize * 2; 
     384        mWidth = sceneSize; 
     385 
     386        mEyeVec.RightHandedBase(mUpVec, mLeftVec); 
     387    mViewPoint = mTermination - 0.5f * sceneSize * mEyeVec; 
     388 
     389        cout << "termination point: " << mTermination << endl; 
     390        cout << "view point: " << mViewPoint << endl; 
     391        cout << "scene: " << bbox << endl; 
     392 
     393        InitRenderTexture(mNewTexture); 
     394        InitRenderTexture(mOldTexture); 
     395         
    382396        cout << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl; 
    383397} 
     
    395409} 
    396410 
     411 
     412void GlobalLinesRenderer::CastGlobalLines(const SimpleRay &ray,  
     413                                                                                  VssRayContainer &rays) 
     414{ 
     415        InitScene(ray); 
     416 
     417        // bind pixel shader implementing the front depth buffer functionality 
     418        ApplyDepthPeeling(rays); 
     419} 
    397420 
    398421void GlobalLinesRenderer::RenderObject(Intersectable *obj) 
     
    438461                                                                                Vector3 &left) 
    439462{ 
    440         //float x = cos(alpha); 
    441         //float y = sin(alpha); 
    442463        eye.x = sin(alpha) * cos(beta); 
    443464        eye.y = sin(alpha) * sin(beta); 
    444465        eye.z = cos(alpha); 
    445466 
    446         //eye = Normalize(eye); 
    447467        eye.RightHandedBase(up, left); 
    448468} 
     
    637657 
    638658 
    639 void GlobalLinesRenderer::ProcessDepthBuffer(VssRayContainer &vssRays,  
     659bool GlobalLinesRenderer::ProcessDepthBuffer(VssRayContainer &vssRays,  
    640660                                                                                         const bool oldBufferInitialised, 
    641661                                                                                         const int pass) 
     
    660680                        mOldItemBuffer[i * 4 + 3] = 255; 
    661681                } 
     682        } 
     683 
     684        ///////////////// 
     685        // test for validity 
     686 
     687        bool buffersEqual = true; 
     688        bool bufferEmpty = true; 
     689 
     690        for (int y = 0; y < mTexHeight; ++ y) 
     691        { 
     692                for (int x = 0; x < mTexWidth; ++ x) 
     693                { 
     694                        const int depthIndex = x + mTexWidth * y;    
     695                        const int itemIndex = 4 * depthIndex; 
     696                 
     697                        if (mOldItemBuffer[itemIndex] != mNewItemBuffer[itemIndex]) 
     698                        { 
     699                                buffersEqual = false; 
     700                        } 
     701 
     702                        unsigned char r = mNewItemBuffer[itemIndex]; 
     703                        unsigned char g = mNewItemBuffer[itemIndex + 1]; 
     704                        unsigned char b = mNewItemBuffer[itemIndex + 2]; 
     705 
     706                        // 3 times 255 means no valid object 
     707                        if (!((r == 255) && (g == 255) && (b == 255))) 
     708                        { 
     709                                bufferEmpty = false; 
     710                        } 
     711                } 
     712                 
     713                // early exit 
     714                if (!buffersEqual && !bufferEmpty) 
     715                        break; 
     716        } 
     717 
     718        // depth buffer not valid 
     719        if (buffersEqual || bufferEmpty) 
     720        { 
     721                cout << "stopped at layer " << pass << endl; 
     722                return false; 
    662723        } 
    663724 
     
    698759                        } 
    699760 
    700                         if (termObj2) 
     761                        if (mSampleReverse && termObj2) 
    701762                        { 
    702763                                vssRays.push_back(new VssRay(clippedNewPt, clippedOldPt, NULL, termObj2, pass)); 
     
    705766                } 
    706767        } 
     768 
     769        return true; 
    707770} 
    708771 
     
    912975 
    913976                // process the buffers for following layer 
    914                 ProcessDepthBuffer(rays, true, i); 
     977                // jump out of loop for the first invalid buffer 
     978                if (!ProcessDepthBuffer(rays, true, i)) 
     979                        break; 
    915980        } 
    916981 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h

    r1964 r1968  
    1515class Preprocessor; 
    1616class GlRenderer; 
     17struct SimpleRay; 
    1718 
    1819struct VssRayContainer; 
     
    2324         
    2425        GlobalLinesRenderer(Preprocessor *preprocessor,  
    25                                                 GlRenderer *renderer, 
    26                                                 const float texHeight, 
    27                                                 const float mTexWidth, 
    28                                                 const float eps); 
     26                                                const int texHeight, 
     27                                                const int mTexWidth, 
     28                                                const float eps, 
     29                                                const int maxDepth, 
     30                                                const bool sampleReverse); 
    2931 
    30         GlobalLinesRenderer(Preprocessor *preprocessor, GlRenderer *renderer); 
     32        GlobalLinesRenderer(Preprocessor *preprocessor); 
    3133 
    3234        ~GlobalLinesRenderer(); 
     
    3941                                                 const float beta,  
    4042                                                 VssRayContainer &rays); 
     43 
     44        /** Casts global lines using the given ray as origin and  
     45                direction vector. 
     46                @returns Computed samples in the container rays 
     47        */ 
     48        void CastGlobalLines(const SimpleRay &ray,  
     49                                                 VssRayContainer &rays); 
     50 
    4151 
    4252        void InitGl(); 
     
    6272        void ExportDepthBuffer(); 
    6373        void ExportItemBuffer(); 
    64         void ProcessDepthBuffer(VssRayContainer &vssRays,  
     74        bool ProcessDepthBuffer(VssRayContainer &vssRays,  
    6575                                                        const bool oldBufferInitialised,  
    6676                                                        const int pass); 
     
    8393 
    8494        int mMaxDepth; 
     95         
    8596        Vector3 mEyeVec; 
    8697        Vector3 mLeftVec; 
    8798        Vector3 mUpVec; 
     99        Vector3 mTermination; 
     100 
    88101        float mFar; 
    89102        float mNear; 
     
    94107        float *mNewDepthBuffer; 
    95108        float *mOldDepthBuffer; 
     109 
    96110        unsigned char *mNewItemBuffer; 
    97111        unsigned char *mOldItemBuffer; 
     
    105119                                           Vector3 &up,  
    106120                                           Vector3 &left); 
     121 
    107122protected: 
    108123 
     
    110125 
    111126        void InitScene(const float alpha, const float beta); 
     127        void InitScene(const SimpleRay &ray); 
     128 
     129        void InitRenderTexture(RenderTexture *rt); 
    112130 
    113131        Preprocessor *mPreprocessor; 
     
    118136        int mTexHeight; 
    119137        float mEpsilon; 
     138 
     139        bool mSampleReverse; 
    120140}; 
    121141 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1966 r1968  
    2121#include "IntelRayCaster.h" 
    2222#include "InternalRayCaster.h" 
    23  
     23#include "GlobalLinesRenderer.h" 
    2424 
    2525 
     
    134134mRayCaster(NULL), 
    135135mStopComputation(false), 
    136 mThread(NULL) 
     136mThread(NULL), 
     137mGlobalLinesRenderer(NULL) 
    137138{ 
    138139        Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer); 
     
    174175                                                                                         mSamplesPerEvaluation); 
    175176 
    176          
    177177        Debug << "******* Preprocessor Options **********" << endl; 
    178178        Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl; 
     
    211211        DEL_PTR(renderer); 
    212212        DEL_PTR(mRayCaster); 
     213 
     214        DEL_PTR(mGlobalLinesRenderer); 
    213215} 
    214216 
     
    10741076 
    10751077 
    1076 bool Preprocessor::InitRayCast(const string externKdTree, const string internKdTree) 
     1078bool Preprocessor::InitRayCast(const string externKdTree,  
     1079                                                           const string internKdTree) 
    10771080{ 
    10781081        // always try to load the kd tree 
     
    10811084        if (!LoadKdTree(internKdTree)) 
    10821085        { 
    1083                 cout << "error loading kd tree with filename " << internKdTree << ", rebuilding it instead ... " << endl; 
     1086                cout << "error loading kd tree with filename "  
     1087                         << internKdTree << ", rebuilding it instead ... " << endl; 
    10841088                // build new kd tree from scene geometry 
    10851089                BuildKdTree(); 
     
    10911095                if (!ExportKdTree(internKdTree)) 
    10921096                { 
    1093                         cout << " error exporting kd tree with filename " << internKdTree << endl; 
     1097                        cout << " error exporting kd tree with filename "  
     1098                                 << internKdTree << endl; 
    10941099                } 
    10951100                else 
    10961101                { 
    1097                         cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     1102                        cout << "finished in "  
     1103                                 << TimeDiff(startTime, GetTime()) * 1e-3  
     1104                                 << " secs" << endl; 
    10981105                } 
    10991106        } 
     
    11141121 
    11151122        int rayCastMethod; 
    1116         Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 
     1123        Environment::GetSingleton()-> 
     1124                GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 
    11171125 
    11181126        if (rayCastMethod == 0) 
     
    11451153        for (int i = 0; i < (int)rays.size();) 
    11461154        { 
     1155                // HACK: does not really go together with the 16 ray bundles 
     1156                if (rays[i].mDistribution == SamplingStrategy::HW_GLOBAL_LINES_DISTRIBUTION) 
     1157                { 
     1158                        mGlobalLinesRenderer->CastGlobalLines(rays[i], vssRays); 
     1159                        i ++; 
     1160                        continue; 
     1161                } 
     1162 
    11471163                if (i + 16 < (int)rays.size())  
    11481164                { 
     
    11731189        if (rays.size() > 10000)  
    11741190        { 
    1175           cout<<endl; 
    1176          
    1177         long t2 = GetTime(); 
     1191                cout << endl; 
     1192 
     1193                long t2 = GetTime(); 
    11781194 
    11791195#if SHOW_RAYCAST_TIMING 
    1180         if (castDoubleRays) 
    1181                 cout << 2 * rays.size() / (1e3f * TimeDiff(t1, t2)) << "M rays/s" << endl; 
    1182         else 
    1183                 cout << rays.size() / (1e3f * TimeDiff(t1, t2)) << "M rays/s" << endl; 
     1196                if (castDoubleRays) 
     1197            cout << 2 * rays.size() / (1e3f * TimeDiff(t1, t2)) << "M rays/s" << endl; 
     1198                else 
     1199                        cout << rays.size() / (1e3f * TimeDiff(t1, t2)) << "M rays/s" << endl; 
    11841200#endif 
    11851201        } 
     
    12301246        ray.Init(point, direction, Ray::LOCAL_RAY);      
    12311247} 
     1248 
    12321249 
    12331250void Preprocessor::EvalViewCellHistogram() 
     
    13261343} 
    13271344 
    1328 } 
     1345 
     1346void Preprocessor::PrepareHwGlobalLines() 
     1347{ 
     1348        int texHeight, texWidth; 
     1349        float eps; 
     1350        int maxDepth; 
     1351        bool sampleReverse; 
     1352 
     1353        Environment::GetSingleton()->GetIntValue("Preprocessor.HwGlobalLines.texHeight", texHeight); 
     1354        Environment::GetSingleton()->GetIntValue("Preprocessor.HwGlobalLines.texHeight", texWidth); 
     1355        Environment::GetSingleton()->GetFloatValue("Preprocessor.HwGlobalLines.stepSize", eps); 
     1356        Environment::GetSingleton()->GetIntValue("Preprocessor.HwGlobalLines.maxDepth", maxDepth); 
     1357        Environment::GetSingleton()->GetBoolValue("Preprocessor.HwGlobalLines.sampleReverse", sampleReverse); 
     1358 
     1359        mGlobalLinesRenderer =  
     1360                new GlobalLinesRenderer(this, 
     1361                                                                texHeight, 
     1362                                                                texWidth, 
     1363                                                                eps, 
     1364                                                                maxDepth, 
     1365                                                                sampleReverse); 
     1366 
     1367        mGlobalLinesRenderer->InitGl(); 
     1368} 
     1369 
     1370} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1966 r1968  
    2929class VssRay; 
    3030class RayCaster; 
    31  
     31class GlobalLinesRenderer; 
    3232 
    3333 
     
    174174        Intersectable *GetObjectById(const int id); 
    175175 
    176  
     176        void PrepareHwGlobalLines(); 
    177177        //////////////////////////////////////////////// 
    178178 
     
    234234   
    235235        int mTotalSamples; 
    236   int mSamplesPerPass; 
    237   int mSamplesPerEvaluation; 
     236        int mSamplesPerPass; 
     237        int mSamplesPerEvaluation; 
    238238 
    239239protected: 
     
    253253        ///////////////////////// 
    254254 
     255        GlobalLinesRenderer *mGlobalLinesRenderer; 
    255256        RayCaster *mRayCaster; 
    256257        /// samples used for construction of the BSP view cells tree. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj

    r1958 r1968  
    316316                                OptimizeForWindowsApplication="TRUE" 
    317317                                AdditionalIncludeDirectories="..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;..\MultiLevelRayTracing;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include\QtGui&quot;;&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;&quot;$(CG_INC_PATH)&quot;" 
    318                                 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;USE_QT" 
     318                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB;USE_QT;ATI" 
    319319                                ExceptionHandling="TRUE" 
    320320                                RuntimeLibrary="2" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r1966 r1968  
    1818HaltonSequence ObjectDirectionBasedDistribution::sHalton; 
    1919HaltonSequence DirectionBasedDistribution::sHalton; 
     20HaltonSequence HwGlobalLinesDistribution::sHalton; 
    2021 
    2122 
    2223SamplingStrategy::SamplingStrategy(Preprocessor &preprocessor):  
    23   mPreprocessor(preprocessor), mRatio(1.0f),  mTotalRays(0), mTotalContribution(0.0f) 
    24 { 
    25    
     24mPreprocessor(preprocessor),  
     25mRatio(1.0f),   
     26mTotalRays(0),  
     27mTotalContribution(0.0f) 
     28 
    2629} 
    2730 
     
    415418        return true; 
    416419} 
    417  
    418  
    419420 
    420421 
     
    839840} 
    840841 
    841 } 
    842  
    843  
     842 
     843bool HwGlobalLinesDistribution::GenerateSample(SimpleRay &ray)  
     844{ 
     845        Vector3 origin, termination, direction;  
     846 
     847        float radius = 0.5f *  
     848                Magnitude(mPreprocessor.mViewCellsManager->GetViewSpaceBox().Size()); 
     849 
     850        Vector3 center = mPreprocessor.mViewCellsManager->GetViewSpaceBox().Center(); 
     851 
     852        const int tries = 1000; 
     853        int i; 
     854        for (i=0; i < tries; i++)  
     855        { 
     856                float r[2]; 
     857                sHalton.GetNext(2, r); 
     858 
     859                origin = center + (radius * UniformRandomVector(r[0], r[1])); 
     860                termination = center; 
     861                 
     862                if (0) 
     863                { 
     864                        // add a small offset to provide some more randomness in the sampling 
     865                        Vector3 offset(Random(radius * 1e-3f),  
     866                                                   Random(radius * 1e-3f),  
     867                                                   Random(radius * 1e-3f)); 
     868                        termination += offset; 
     869                } 
     870 
     871                direction = termination - origin; 
     872 
     873                // $$ jb the pdf is yet not correct for all sampling methods! 
     874                const float c = Magnitude(direction); 
     875 
     876                if (c <= Limits::Small)  
     877                        return false; 
     878 
     879                direction *= 1.0f / c; 
     880 
     881                // check if the ray intersects the view space box 
     882                static Ray ray; 
     883                ray.Init(origin, direction, Ray::LOCAL_RAY);     
     884 
     885                float tmin, tmax; 
     886                if (mPreprocessor.mViewCellsManager-> 
     887                        GetViewSpaceBox().ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax)) 
     888                        break; 
     889        } 
     890 
     891        if (i != tries)  
     892        { 
     893                // $$ jb the pdf is yet not correct for all sampling methods! 
     894                const float pdf = 1.0f; 
     895 
     896                ray = SimpleRay(origin, direction, HW_GLOBAL_LINES_DISTRIBUTION, pdf); 
     897                ray.mType = Ray::GLOBAL_RAY; 
     898                return true; 
     899        } 
     900 
     901        return false; 
     902} 
     903 
     904 
     905} 
     906 
     907 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h

    r1966 r1968  
    2525        enum  
    2626        { 
    27           DUMMY_DISTRIBUTION = 0, 
    28           DIRECTION_BASED_DISTRIBUTION, 
     27                DUMMY_DISTRIBUTION = 0, 
     28                DIRECTION_BASED_DISTRIBUTION, 
    2929                OBJECT_BASED_DISTRIBUTION, 
    3030                DIRECTION_BOX_BASED_DISTRIBUTION, 
     
    3939                VIEWSPACE_BORDER_BASED_DISTRIBUTION, 
    4040                REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION, 
    41           GLOBAL_LINES_DISTRIBUTION, 
    42           GVS, 
    43           MUTATION_BASED_DISTRIBUTION 
    44  
     41                GLOBAL_LINES_DISTRIBUTION, 
     42                GVS, 
     43                MUTATION_BASED_DISTRIBUTION, 
     44                HW_GLOBAL_LINES_DISTRIBUTION 
    4545        }; 
    4646 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1949 r1968  
    258258        } 
    259259         
     260         
     261        bool useHwGlobalLines; 
     262        Environment::GetSingleton()->GetBoolValue("Preprocessor.useHwGlobalLines", 
     263                                                                                           useHwGlobalLines); 
     264 
     265        if (useHwGlobalLines) 
     266                preprocessor->PrepareHwGlobalLines(); 
     267 
    260268        // create a preprocessor thread (note: capsulates calls to boost fuctions!) 
    261269        PreprocessorThread *pt = NULL; 
    262270 
    263271#ifdef TRY_GLOBAL_LINES 
    264         GlRenderer *renderer = new GlRenderer(preprocessor->mSceneGraph, 
    265                                                                                   preprocessor->mViewCellsManager, 
    266                                                                                   preprocessor->mKdTree); 
    267  
    268         globalLinesRenderer = new GlobalLinesRenderer(preprocessor, renderer); 
     272         
     273        globalLinesRenderer = new GlobalLinesRenderer(preprocessor); 
    269274        globalLinesRenderer->InitGl(); 
    270275        globalLinesRenderer->Run(); 
    271276 
     277        //delete renderer; 
    272278#else 
    273279 
Note: See TracChangeset for help on using the changeset viewer.