Changeset 1964


Ignore:
Timestamp:
01/10/07 18:20:53 (17 years ago)
Author:
mattausch
Message:

worked on global lines

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

Legend:

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

    r1963 r1964  
    2828static CGprofile sCgFragmentProfile; 
    2929static CGparameter sTextureParam; 
     30static CGparameter sTexWidthParam;  
     31static CGparameter sStepSizeParam; 
    3032 
    3133GlobalLinesRenderer *globalLinesRenderer = NULL; 
    32  
    33 //static int texWidth = 32; 
    34 //static int texHeight = 32; 
    35 static int texWidth = 256; 
    36 static int texHeight = 256; 
    3734 
    3835static bool isDepth = true; 
     
    137134 
    138135                        ++ globalLinesRenderer->mMaxDepth; 
    139                         globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0); 
     136                        globalLinesRenderer->ApplyDepthPeeling(rays); 
    140137 
    141138                        cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl; 
     
    150147                        cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl; 
    151148                         
    152                         globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0); 
     149                        globalLinesRenderer->ApplyDepthPeeling(rays); 
    153150                        CLEAR_CONTAINER(rays); 
    154151                        return; 
     
    156153        case '3': 
    157154                { 
    158                         //globalLinesRenderer->ApplyDepthPeeling(Beam(), 0); 
    159155                        globalLinesRenderer->ExportDepthBuffer(); 
    160                          
    161156                        return; 
    162157                } 
    163158        case '4': 
    164159                { 
    165                         //globalLinesRenderer->ApplyDepthPeeling(Beam(), 0); 
    166160                        globalLinesRenderer->ExportItemBuffer(); 
    167                          
    168161                        return; 
    169162                } 
     
    176169                { 
    177170                        VssRayContainer rays; 
    178                         globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0); 
     171                        globalLinesRenderer->ApplyDepthPeeling(rays); 
    179172                        VssRayContainer outRays; 
    180173                        VssRayContainer::const_iterator vit, vit_end = rays.end(); 
     
    197190                { 
    198191                        VssRayContainer rays; 
    199                         globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0); 
     192                        globalLinesRenderer->ApplyDepthPeeling(rays); 
    200193                        CLEAR_CONTAINER(rays); 
    201194                        return; 
     
    219212 
    220213GlobalLinesRenderer::GlobalLinesRenderer(Preprocessor *preprocessor,  
    221                                                                                  GlRenderer *renderer):  
     214                                                                                 GlRenderer *renderer, 
     215                                                                                 const float mTexHeight, 
     216                                                                                 const float mTexWidth, 
     217                                                                                 const float eps):  
    222218mNewTexture(NULL),  
    223219mOldTexture(NULL),  
    224220mMaxDepth(0),  
    225221mRenderer(renderer),  
    226 mPreprocessor(preprocessor) 
    227 { 
    228 } 
     222mPreprocessor(preprocessor), 
     223mTexHeight(mTexHeight), 
     224mTexWidth(mTexWidth), 
     225mEpsilon(eps) 
     226{ 
     227} 
     228 
     229 
     230GlobalLinesRenderer::GlobalLinesRenderer(Preprocessor *preprocessor,  
     231                                                                                 GlRenderer *renderer): 
     232mNewTexture(NULL),  
     233mOldTexture(NULL),  
     234mMaxDepth(0),  
     235mRenderer(renderer),  
     236mPreprocessor(preprocessor), 
     237mTexHeight(128), 
     238mTexWidth(128), 
     239mEpsilon(0.0001) 
     240{} 
    229241 
    230242 
     
    279291 
    280292  
    281 void GlobalLinesRenderer::CastGlobalLines(Beam &beam, const int samples) 
    282 { 
    283         VssRayContainer rays; 
    284  
    285         // bind pixel shader implementing the front depth buffer functionality 
    286         ApplyDepthPeeling(rays, beam, samples); 
    287 } 
    288  
    289  
    290 void GlobalLinesRenderer::RenderObject(Intersectable *obj) 
    291 { 
    292         mRenderer->RenderIntersectable(obj); 
    293 } 
    294  
    295  
    296 void GlobalLinesRenderer::DrawGeometry() 
    297 {  
    298         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    299         glMatrixMode(GL_MODELVIEW); 
    300  
    301         glPushMatrix(); 
    302         {  
    303                 //glLoadIdentity(); 
    304                 ObjectContainer::const_iterator oit, oit_end = mPreprocessor->mObjects.end(); 
    305  
    306                 Intersectable::NewMail(); 
    307  
    308                 for (oit = mPreprocessor->mObjects.begin(); oit != oit_end; ++ oit) 
    309                 { 
    310                         //cout << (*oit)->GetId() << " "; 
    311                         RenderObject(*oit); 
    312                 } 
    313         } 
    314         glPopMatrix(); 
    315 } 
    316  
    317  
    318 void GlobalLinesRenderer::SwitchRenderTextures() 
    319 { 
    320         RenderTexture *buffer = mOldTexture; 
    321         mOldTexture = mNewTexture; 
    322         mNewTexture = buffer; 
    323 } 
    324  
    325  
    326 void GlobalLinesRenderer::ComputeLookAt(const float alpha,  
    327                                                                                 const float beta, 
    328                                                                                 Vector3 &eye,  
    329                                                                                 Vector3 &up,  
    330                                                                                 Vector3 left) 
    331 { 
    332         //float x = cos(alpha); 
    333         //float y = sin(alpha); 
    334         eye.x = sin(alpha) * cos(beta); 
    335         eye.y = sin(alpha) * sin(beta); 
    336         eye.z = cos(beta); 
    337  
    338         eye.RightHandedBase(up, left); 
    339 } 
    340  
    341  
    342 void GlobalLinesRenderer::InitGl() 
    343 { 
    344         InitDevIl(); 
    345  
    346     glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); 
    347         glutInitWindowPosition(50, 50); 
    348         glutInitWindowSize(512, 512); 
    349         glutCreateWindow("TestRenderDepthTexture");   
    350  
    351         int err = glewInit(); 
    352         if (GLEW_OK != err) 
    353         { 
    354                 // problem: glewInit failed, something is seriously wrong 
    355                 fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err)); 
    356                 exit(-1); 
    357         }   
    358          
    359         glutKeyboardFunc(Keyboard); 
    360         glutDisplayFunc(Display); 
    361         glutIdleFunc(Idle); 
    362         glutReshapeFunc(Reshape); 
    363  
    364         Reshape(512, 512); 
    365         glMatrixMode(GL_MODELVIEW); 
    366         glLoadIdentity(); 
    367  
    368         // initialise the receiving buffers 
    369         mNewDepthBuffer = new float[texWidth * texHeight]; 
    370         mNewItemBuffer = new unsigned char[texWidth * texHeight * 4]; 
    371  
    372         mOldDepthBuffer = new float[texWidth * texHeight]; 
    373     mOldItemBuffer = new unsigned char[texWidth * texHeight * 4]; 
    374  
    375         for (int i = 0; i < texWidth * texHeight; ++ i) 
    376         { 
    377                 mNewDepthBuffer[i] = 1; 
    378                 mOldDepthBuffer[i] = 1; 
    379  
    380                 mNewItemBuffer[i * 4]     = 255; 
    381                 mNewItemBuffer[i * 4 + 1] = 255; 
    382                 mNewItemBuffer[i * 4 + 2] = 255; 
    383                 mNewItemBuffer[i * 4 + 3] = 255; 
    384  
    385                 mOldItemBuffer[i * 4]     = 255; 
    386                 mOldItemBuffer[i * 4 + 1] = 255; 
    387                 mOldItemBuffer[i * 4 + 2] = 255; 
    388                 mOldItemBuffer[i * 4 + 3] = 255; 
    389         } 
    390  
     293void GlobalLinesRenderer::InitScene(const float alpha, const float beta) 
     294{ 
    391295        AxisAlignedBox3 bbox = globalLinesRenderer->mPreprocessor->mKdTree->GetBox(); 
    392296         
     297        const float sceneSize = Magnitude(bbox.Diagonal()); 
     298 
     299        // compute the center of the scene 
    393300        Vector3 midPoint = bbox.Center(); 
    394301         
    395         const float sceneSize = Magnitude(bbox.Diagonal()); 
    396         mViewPoint = midPoint + Vector3(0.5 * sceneSize, 0, 0.5 * sceneSize); 
    397          
     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 
    398321        cout << "mid point: " << midPoint << endl; 
    399322        cout << "view point: " << mViewPoint << endl; 
    400323        cout << "scene: " << bbox << endl; 
    401324 
    402         mNear = 1; 
    403         mFar = sceneSize * 2; 
    404         mWidth = sceneSize; 
    405  
    406         mEyeVec = Normalize(midPoint - mViewPoint); 
    407         mEyeVec.RightHandedBase(mUpVec, mLeftVec); 
    408  
    409         /*gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z,  
    410                           midPoint.x, midPoint.y, midPoint.z,  
    411                           0, 1, 0); 
    412 */ 
    413         gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0); 
    414  
    415         //glDisable(GL_CULL_FACE); 
    416         glEnable(GL_CULL_FACE); 
    417         glDisable(GL_LIGHTING); 
    418         glDisable(GL_COLOR_MATERIAL); 
    419         glEnable(GL_DEPTH_TEST);  
    420         glClearColor(0.1, 0.2, 0.3, 1); 
    421          
    422         // A square, mipmapped, anisotropically filtered 8-bit RGBA texture with 
    423         // depth and stencil. 
    424         // Note that RT_COPY_TO_TEXTURE is required for depth textures on ATI hardware 
    425          
    426         mNewTexture = new RenderTexture(texWidth, texHeight, true, true); 
    427         //mNewTexture->Initialize(true, true, false, true, true, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE); 
    428         mNewTexture->Initialize(true, true, false, true, true, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE); 
    429          
    430         mOldTexture = new RenderTexture(texWidth, texHeight, true, true); 
    431         //mOldTexture ->Initialize(true, true, false, true, true, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE); 
    432         mOldTexture ->Initialize(true, true, false, true, true, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE); 
    433  
    434         // Setup Cg 
    435         cgSetErrorCallback(cgErrorCallback); 
    436  
    437         // Create cgContext. 
    438         sCgContext = cgCreateContext(); 
    439  
    440         // get the best profile for this hardware 
    441         sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); 
    442          
    443         //assert(sCgFragmentProfile != CG_PROFILE_UNKNOWN); 
    444         cgGLSetOptimalOptions(sCgFragmentProfile); 
    445  
    446         sCgDepthPeelingProgram =  
    447                 cgCreateProgramFromFile(sCgContext,  
    448                                                                 CG_SOURCE, 
    449                                                                 mNewTexture->IsRectangleTexture() ?  
    450                                                                 "../src/depth_peelingRect.cg" : "../src/depth_peeling2d.cg",  
    451                                                                 GLEW_ARB_fragment_program ? CG_PROFILE_ARBFP1 : CG_PROFILE_FP30, 
    452                                                                 NULL, 
    453                                                                 NULL); 
    454  
    455         if(sCgDepthPeelingProgram != NULL) 
    456         { 
    457                 cgGLLoadProgram(sCgDepthPeelingProgram); 
    458                 sTextureParam = cgGetNamedParameter(sCgDepthPeelingProgram, "depthTex");   
    459         } 
    460  
    461         sCgPassThroughProgram =  
    462                 cgCreateProgramFromFile(sCgContext,  
    463                                                                 CG_SOURCE, 
    464                                                                 "../src/passthrough.cg",  
    465                                                                 GLEW_ARB_fragment_program ? CG_PROFILE_ARBFP1 : CG_PROFILE_FP30, 
    466                                                                 NULL, 
    467                                                                 NULL); 
    468  
    469         if(sCgPassThroughProgram != NULL) 
    470         { 
    471                 cgGLLoadProgram(sCgPassThroughProgram); 
    472         } 
    473  
    474     // setup the rendering context for the RenderTexture 
     325         // setup the rendering context for the RenderTexture 
    475326        mNewTexture->BeginCapture(); 
    476327        { 
    477                 //Reshape(texWidth, texHeight); 
    478                 glViewport(0, 0, texWidth, texHeight); 
     328                //Reshape(mTexWidth, mTexHeight); 
     329                glViewport(0, 0, mTexWidth, mTexHeight); 
    479330                SetFrustum(mWidth, mWidth, mNear, mFar); 
    480331 
     
    496347                gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z,  
    497348                                  midPoint.x, midPoint.y, midPoint.z,  
    498                                   0, 1, 0); 
     349                                  mUpVec.x, mUpVec.y, mUpVec.z); 
    499350 
    500351        } 
     
    507358                glClearColor(1, 1, 1, 1); 
    508359        
    509                 //Reshape(texWidth, texHeight); 
    510                 glViewport(0, 0, texWidth, texHeight); 
     360                //Reshape(mTexWidth, mTexHeight); 
     361                glViewport(0, 0, mTexWidth, mTexHeight); 
    511362                SetFrustum(mWidth, mWidth, mNear, mFar); 
    512363 
     
    525376                gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z,  
    526377                                  midPoint.x, midPoint.y, midPoint.z,  
    527                                   0, 1, 0); 
    528  
    529                 //SetFrustum(sceneSize, sceneSize, 1, sceneSize); 
     378                                  mUpVec.x, mUpVec.y, mUpVec.z); 
    530379        } 
    531380        mOldTexture->EndCapture(); 
     381 
     382        cout << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl; 
     383} 
     384 
     385 
     386void GlobalLinesRenderer::CastGlobalLines(const float alpha,  
     387                                                                                  const float beta,  
     388                                                                                  //const int samples, 
     389                                                                                  VssRayContainer &rays) 
     390{ 
     391        InitScene(alpha, beta); 
     392 
     393        // bind pixel shader implementing the front depth buffer functionality 
     394        ApplyDepthPeeling(rays); 
     395} 
     396 
     397 
     398void GlobalLinesRenderer::RenderObject(Intersectable *obj) 
     399{ 
     400        mRenderer->RenderIntersectable(obj); 
     401} 
     402 
     403 
     404void GlobalLinesRenderer::DrawGeometry() 
     405{  
     406        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     407        glMatrixMode(GL_MODELVIEW); 
     408 
     409        glPushMatrix(); 
     410        {  
     411                //glLoadIdentity(); 
     412                ObjectContainer::const_iterator oit, oit_end = mPreprocessor->mObjects.end(); 
     413 
     414                Intersectable::NewMail(); 
     415 
     416                for (oit = mPreprocessor->mObjects.begin(); oit != oit_end; ++ oit) 
     417                { 
     418                        //cout << (*oit)->GetId() << " "; 
     419                        RenderObject(*oit); 
     420                } 
     421        } 
     422        glPopMatrix(); 
     423} 
     424 
     425 
     426void GlobalLinesRenderer::SwitchRenderTextures() 
     427{ 
     428        RenderTexture *buffer = mOldTexture; 
     429        mOldTexture = mNewTexture; 
     430        mNewTexture = buffer; 
     431} 
     432 
     433 
     434void GlobalLinesRenderer::ComputeLookAt(const float alpha,  
     435                                                                                const float beta, 
     436                                                                                Vector3 &eye,  
     437                                                                                Vector3 &up,  
     438                                                                                Vector3 &left) 
     439{ 
     440        //float x = cos(alpha); 
     441        //float y = sin(alpha); 
     442        eye.x = sin(alpha) * cos(beta); 
     443        eye.y = sin(alpha) * sin(beta); 
     444        eye.z = cos(alpha); 
     445 
     446        //eye = Normalize(eye); 
     447        eye.RightHandedBase(up, left); 
     448} 
     449 
     450 
     451void GlobalLinesRenderer::InitGl() 
     452{ 
     453        InitDevIl(); 
     454 
     455    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); 
     456        glutInitWindowPosition(50, 50); 
     457        glutInitWindowSize(512, 512); 
     458        glutCreateWindow("TestRenderDepthTexture");   
     459 
     460        int err = glewInit(); 
     461        if (GLEW_OK != err) 
     462        { 
     463                // problem: glewInit failed, something is seriously wrong 
     464                fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err)); 
     465                exit(-1); 
     466        }   
     467         
     468        glutKeyboardFunc(Keyboard); 
     469        glutDisplayFunc(Display); 
     470        glutIdleFunc(Idle); 
     471        glutReshapeFunc(Reshape); 
     472 
     473        Reshape(512, 512); 
     474        glMatrixMode(GL_MODELVIEW); 
     475        glLoadIdentity(); 
     476 
     477        // initialise the receiving buffers 
     478        mNewDepthBuffer = new float[mTexWidth * mTexHeight]; 
     479        mNewItemBuffer = new unsigned char[mTexWidth * mTexHeight * 4]; 
     480 
     481        mOldDepthBuffer = new float[mTexWidth * mTexHeight]; 
     482    mOldItemBuffer = new unsigned char[mTexWidth * mTexHeight * 4]; 
     483 
     484        for (int i = 0; i < mTexWidth * mTexHeight; ++ i) 
     485        { 
     486                mNewDepthBuffer[i] = 1; 
     487                mOldDepthBuffer[i] = 1; 
     488 
     489                mNewItemBuffer[i * 4]     = 255; 
     490                mNewItemBuffer[i * 4 + 1] = 255; 
     491                mNewItemBuffer[i * 4 + 2] = 255; 
     492                mNewItemBuffer[i * 4 + 3] = 255; 
     493 
     494                mOldItemBuffer[i * 4]     = 255; 
     495                mOldItemBuffer[i * 4 + 1] = 255; 
     496                mOldItemBuffer[i * 4 + 2] = 255; 
     497                mOldItemBuffer[i * 4 + 3] = 255; 
     498        } 
     499 
     500        /*gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z,  
     501                          midPoint.x, midPoint.y, midPoint.z,  
     502                          0, 1, 0); 
     503*/ 
     504        gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0); 
     505 
     506        //glDisable(GL_CULL_FACE); 
     507        glEnable(GL_CULL_FACE); 
     508        glDisable(GL_LIGHTING); 
     509        glDisable(GL_COLOR_MATERIAL); 
     510        glEnable(GL_DEPTH_TEST);  
     511        glClearColor(0.1, 0.2, 0.3, 1); 
     512         
     513        // A square, mipmapped, anisotropically filtered 8-bit RGBA texture with 
     514        // depth and stencil. 
     515        // Note that RT_COPY_TO_TEXTURE is required for depth textures on ATI hardware 
     516         
     517        mNewTexture = new RenderTexture(mTexWidth, mTexHeight, true, true); 
     518#ifdef ATI 
     519        mNewTexture->Initialize(true, true, false, true, true, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE); 
     520#else 
     521        mNewTexture->Initialize(true, true, false, true, true, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE); 
     522#endif 
     523 
     524        mOldTexture = new RenderTexture(mTexWidth, mTexHeight, true, true); 
     525 
     526#ifdef ATI 
     527        mOldTexture ->Initialize(true, true, false, true, true, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE); 
     528#else 
     529        mOldTexture ->Initialize(true, true, false, true, true, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE); 
     530#endif 
     531 
     532        // Setup Cg 
     533        cgSetErrorCallback(cgErrorCallback); 
     534 
     535        // Create cgContext. 
     536        sCgContext = cgCreateContext(); 
     537 
     538        // get the best profile for this hardware 
     539        sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); 
     540         
     541        //assert(sCgFragmentProfile != CG_PROFILE_UNKNOWN); 
     542        cgGLSetOptimalOptions(sCgFragmentProfile); 
     543 
     544        sCgDepthPeelingProgram =  
     545                cgCreateProgramFromFile(sCgContext,  
     546                                                                CG_SOURCE, 
     547                                                                mNewTexture->IsRectangleTexture() ?  
     548                                                                "../src/depth_peelingRect.cg" : "../src/depth_peeling2d.cg",  
     549                                                                GLEW_ARB_fragment_program ? CG_PROFILE_ARBFP1 : CG_PROFILE_FP30, 
     550                                                                NULL, 
     551                                                                NULL); 
     552 
     553        if(sCgDepthPeelingProgram != NULL) 
     554        { 
     555                cgGLLoadProgram(sCgDepthPeelingProgram); 
     556                sTextureParam = cgGetNamedParameter(sCgDepthPeelingProgram, "depthTex");   
     557                 
     558                // we need size of texture for scaling 
     559                if (!mNewTexture->IsRectangleTexture())  
     560                { 
     561                        sTexWidthParam = cgGetNamedParameter(sCgDepthPeelingProgram, "texWidth"); 
     562                } 
     563 
     564                sStepSizeParam = cgGetNamedParameter(sCgDepthPeelingProgram, "stepSize");  
     565 
     566                cgGLSetParameter1f(sTexWidthParam, (float)mTexWidth); 
     567                cgGLSetParameter1f(sStepSizeParam, mEpsilon); 
     568        } 
     569 
     570        sCgPassThroughProgram =  
     571                cgCreateProgramFromFile(sCgContext,  
     572                                                                CG_SOURCE, 
     573                                                                "../src/passthrough.cg",  
     574                                                                GLEW_ARB_fragment_program ? CG_PROFILE_ARBFP1 : CG_PROFILE_FP30, 
     575                                                                NULL, 
     576                                                                NULL); 
     577 
     578        if(sCgPassThroughProgram != NULL) 
     579        { 
     580                cgGLLoadProgram(sCgPassThroughProgram); 
     581        } 
     582 
     583        const float alpha = 1.1; 
     584        const float beta = 0.9; 
     585        InitScene(alpha, beta); 
    532586 
    533587        PrintGLerror("init"); 
     
    542596                                                                                                           const bool isFrontBuffer) const 
    543597{ 
    544         const int depthIndex = x + texWidth * y; 
     598        const int depthIndex = x + mTexWidth * y; 
    545599        const int itemIndex = 4 * depthIndex; 
    546600 
     
    548602        const float eyeDist = mNear + (mFar - mNear) * depth; 
    549603         
    550         const float leftDist = 0.5f * mWidth - mWidth * ((float)x + 0.5f) / texWidth; 
    551         //const float upDist = 0.5f * mWidth - (float)mWidth * ((float)y + 0.5f) / texHeight; 
    552         const float upDist = -0.5f * mWidth + mWidth * ((float)y + 0.5f) / texHeight; 
    553          
     604        const float leftDist = -0.5f * mWidth + mWidth * ((float)x + 0.5f) / mTexWidth; 
     605        //const float leftDist = 0.5f * mWidth - mWidth * ((float)x + 0.5f) / mTexWidth; 
     606         
     607        const float upDist = -0.5f * mWidth + mWidth * ((float)y + 0.5f) / mTexHeight; 
     608        //const float upDist = 0.5f * mWidth - mWidth * ((float)y + 0.5f) / mTexHeight; 
     609 
    554610        hitPoint = mViewPoint +  
    555611                       eyeDist * mEyeVec +  
    556                            leftDist * mUpVec +  
    557                            upDist * mLeftVec; 
     612                           upDist * mUpVec + 
     613                           leftDist * mLeftVec; 
    558614                                 
    559615        unsigned char r = itemBuffer[itemIndex]; 
     
    595651        else 
    596652        { 
    597                 for (int i = 0; i < texWidth * texHeight; ++ i) 
     653                for (int i = 0; i < mTexWidth * mTexHeight; ++ i) 
    598654                { 
    599655                        mOldDepthBuffer[i] = 0; 
     
    606662        } 
    607663 
    608         //cout << "vp: " << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl; 
    609  
    610         for (int y = 0; y < texHeight; ++ y) 
    611         { 
    612                 for (int x = 0; x < texWidth; ++ x) 
     664        for (int y = 0; y < mTexHeight; ++ y) 
     665        { 
     666                for (int x = 0; x < mTexWidth; ++ x) 
    613667                { 
    614668                        Vector3 newPt, oldPt; 
     
    724778                } 
    725779 
    726                 if (ray->mPass == 4) 
     780                //if (ray->mPass == 4) 
    727781                        outRays.push_back(ray); 
    728782        }        
     
    738792        rt->BindDepth(); 
    739793        rt->EnableTextureTarget(); 
    740         //cout << "depth: " << mNewTexture->GetDepthBits() << endl; 
    741794 
    742795        const int texFormat = GL_DEPTH_COMPONENT; 
     
    751804        rt->Bind(); 
    752805        rt->EnableTextureTarget(); 
    753         //cout << "depth: " << mNewTexture->GetDepthBits() << endl; 
    754806 
    755807        const int texFormat = GL_RGBA; 
     
    768820        const int components = 1;//mNewTexture->GetDepthBits() / 8; 
    769821 
    770         float *data = new float[texWidth * texHeight * components]; 
     822        float *data = new float[mTexWidth * mTexHeight * components]; 
    771823        //const int texFormat = WGL_TEXTURE_DEPTH_COMPONENT_NV; 
    772824        const int texFormat = GL_DEPTH_COMPONENT; 
     
    780832        const int bpp = components; 
    781833 
    782         ilTexImage(texWidth, texHeight, depth, bpp, IL_LUMINANCE, IL_FLOAT, data); 
     834        ilTexImage(mTexWidth, mTexHeight, depth, bpp, IL_LUMINANCE, IL_FLOAT, data); 
    783835        ilSaveImage((char *const)filename.c_str()); 
    784836 
     
    799851        const int components = 4;//mNewTexture->GetDepthBits() / 8; 
    800852 
    801         unsigned char *data = new unsigned char [texWidth * texHeight * components]; 
     853        unsigned char *data = new unsigned char [mTexWidth * mTexHeight * components]; 
    802854        //const int texFormat = WGL_TEXTURE_DEPTH_COMPONENT_NV; 
    803855        const int texFormat = GL_RGBA; 
     
    810862        const int bpp = components; 
    811863 
    812         ilTexImage(texWidth, texHeight, depth, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data); 
     864        ilTexImage(mTexWidth, mTexHeight, depth, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data); 
    813865        ilSaveImage((char *const)filename.c_str()); 
    814866 
     
    821873 
    822874 
    823 void GlobalLinesRenderer::ApplyDepthPeeling(VssRayContainer &rays, 
    824                                                                                         Beam &beam,  
    825                                                                                         const int samples) 
     875void GlobalLinesRenderer::ApplyDepthPeeling(VssRayContainer &rays) 
    826876{ 
    827877        mNewTexture->BeginCapture(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h

    r1963 r1964  
    2121{ 
    2222public: 
    23         /*GlobalLinesRenderer(RenderTexture *buffer1,  
    24                                                 RenderTexture *buffer2,  
    25                                                 Preprocessor *preprocessor, 
    26                                                 GlRenderer *renderer); 
    27 */ 
     23         
     24        GlobalLinesRenderer(Preprocessor *preprocessor,  
     25                                                GlRenderer *renderer, 
     26                                                const float texHeight, 
     27                                                const float mTexWidth, 
     28                                                const float eps); 
     29 
    2830        GlobalLinesRenderer(Preprocessor *preprocessor, GlRenderer *renderer); 
    2931 
    3032        ~GlobalLinesRenderer(); 
    3133 
    32         void CastGlobalLines(Beam &beam, const int samples); 
     34        /** Casts global lines in the angle specified by alpha and 
     35                beta.  
     36                @returns Computed samples in the container rays 
     37        */ 
     38        void CastGlobalLines(const float alpha,  
     39                                                 const float beta,  
     40                                                 VssRayContainer &rays); 
    3341 
    3442        void InitGl(); 
     
    5159        void GrabDepthBuffer(float *data, RenderTexture *rt); 
    5260        void GrabItemBuffer(unsigned char *data, RenderTexture *rt); 
    53         void ApplyDepthPeeling(VssRayContainer &rays, Beam &beam, const int samples); 
     61        void ApplyDepthPeeling(VssRayContainer &rays); 
    5462        void ExportDepthBuffer(); 
    5563        void ExportItemBuffer(); 
    56         void ProcessDepthBuffer(VssRayContainer &vssRays, const bool oldBufferInitialised, const int pass); 
     64        void ProcessDepthBuffer(VssRayContainer &vssRays,  
     65                                                        const bool oldBufferInitialised,  
     66                                                        const int pass); 
     67 
    5768        void DisplayBuffer(const bool isDepth); 
    5869         
     
    93104                                           Vector3 &eye,  
    94105                                           Vector3 &up,  
    95                                            Vector3 left); 
     106                                           Vector3 &left); 
    96107protected: 
    97108 
    98109        void SwitchRenderTextures(); 
    99110 
    100         void SetupProjection(const Vector3 &viewPoint,  
    101                                                  const Beam &beam); 
    102  
    103          
     111        void InitScene(const float alpha, const float beta); 
    104112 
    105113        Preprocessor *mPreprocessor; 
    106114 
    107115        GlRenderer *mRenderer; 
     116 
     117        int mTexWidth; 
     118        int mTexHeight; 
     119        float mEpsilon; 
    108120}; 
    109121 
  • GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp

    r1883 r1964  
    2929{ 
    3030  if (simpleRay.mType == Ray::GLOBAL_RAY) 
    31         return CastGlobalRay(simpleRay, vssRays, box, pruneInvalidRays); 
     31          return CastGlobalRay(simpleRay, vssRays, box, pruneInvalidRays); 
    3232   
    3333  //cout << "internal ray" << endl; 
     
    8282int 
    8383InternalRayCaster::CastGlobalRay(const SimpleRay &simpleRay, 
    84                                                                                                                                 VssRayContainer &vssRays, 
    85                                                                                                                                 const AxisAlignedBox3 &box, 
    86                                                                                                                                 const bool pruneInvalidRays 
    87                                                                                                                                  ) 
     84                                                                VssRayContainer &vssRays, 
     85                                                                const AxisAlignedBox3 &box, 
     86                                                                const bool pruneInvalidRays 
     87                                                                ) 
    8888{ 
    8989  static Ray ray; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h

    r1952 r1964  
    5959        virtual bool GenerateSample(SimpleRay &ray) = 0; 
    6060 
    61   // true if the strategy keeps pointers to rays and thus they should get deleted 
    62   // outside, in that case the strategy has to use reference counting and deleting the rays 
    63   // by itself if the number of references drops to zero 
    64   virtual bool RequiresRays() { return false; } 
    65  
    66  
    67   virtual void Update(VssRayContainer &vssRays) {} 
    68  
    69   friend bool LowerRatio(const SamplingStrategy *a, const SamplingStrategy *b) { 
    70         return a->mRatio < b->mRatio; 
    71   } 
     61        // true if the strategy keeps pointers to rays and thus they should get deleted 
     62        // outside, in that case the strategy has to use reference counting and deleting the rays 
     63        // by itself if the number of references drops to zero 
     64        virtual bool RequiresRays() { return false; } 
     65 
     66 
     67        virtual void Update(VssRayContainer &vssRays) {} 
     68 
     69        friend bool LowerRatio(const SamplingStrategy *a, const SamplingStrategy *b) { 
     70                return a->mRatio < b->mRatio; 
     71        } 
    7272 
    7373public: 
     
    262262 
    263263 
     264class HwGlobalLinesDistribution: public SamplingStrategy 
     265{ 
     266public: 
     267  
     268  HwGlobalLinesDistribution(Preprocessor &preprocessor): 
     269        SamplingStrategy(preprocessor) { 
     270        //mType = HW_GLOBAL_LINES_DISTRIBUTION; 
     271  } 
     272   
     273private: 
     274 
     275        virtual bool GenerateSample(SimpleRay &ray); 
     276        static HaltonSequence sHalton; 
     277}; 
     278 
    264279/** This strategy generates samples inside of the objects, e.g., 
    265280        for sampling the inside of a colon. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/depth_peeling2d.cg

    r1962 r1964  
    22float3 main(in float4 col : COL0, 
    33            in float3 pos : WPOS, 
     4            uniform float texWidth, 
     5            uniform float stepSize, 
    46            uniform sampler2D depthTex) : COLOR 
    57{ 
    6    float zold = tex2D(depthTex, pos.xy / 256.0); 
     8   float zold = tex2D(depthTex, pos.xy / texWidth); 
    79 
    8    if(pos.z < (zold + 0.00001)) 
     10   if(pos.z < (zold + stepSize)) 
    911      discard; 
    1012   else; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/depth_peelingRect.cg

    r1950 r1964  
    22float3 main(in float4 col : COL0, 
    33            in float3 pos : WPOS, 
     4            uniform float stepSize, 
    45            uniform samplerRect depthTex) : COLOR 
    56{ 
    67   float zold = texRect(depthTex, pos.xy); 
    78 
    8    if(pos.z < (zold + 0.1)) 
     9   if(pos.z < (zold + stepSize)) 
    910      discard; 
    1011   else; 
Note: See TracChangeset for help on using the changeset viewer.