Changeset 1958


Ignore:
Timestamp:
01/08/07 18:40:01 (17 years ago)
Author:
mattausch
Message:

debug version of global lines renderer

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

Legend:

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

    r1954 r1958  
    106106{ 
    107107        //globalLinesRenderer->DrawGeometry(); 
    108         globalLinesRenderer->CastGlobalLines(Beam(), 0); 
     108        //globalLinesRenderer->CastGlobalLines(Beam(), 0); 
     109        globalLinesRenderer->DisplayBuffer(); 
    109110        PrintGLerror("display"); 
    110111 
     
    124125        { 
    125126        case '2': 
    126                 ++ globalLinesRenderer->mMaxDepth; 
    127                 cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl; 
    128                 return; 
     127                { 
     128                        VssRayContainer rays; 
     129 
     130                        ++ globalLinesRenderer->mMaxDepth; 
     131                        globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0); 
     132 
     133                        cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl; 
     134                        return; 
     135                } 
    129136        case '1': 
    130                 -- globalLinesRenderer->mMaxDepth; 
    131                 cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl; 
    132                 return; 
     137                { 
     138                        VssRayContainer rays; 
     139 
     140                        -- globalLinesRenderer->mMaxDepth; 
     141                        cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl; 
     142                         
     143                        globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0); 
     144                        return; 
     145                } 
    133146        case '3': 
    134                 //globalLinesRenderer->ApplyDepthPeeling(Beam(), 0); 
    135                 globalLinesRenderer->GrabDepthBuffer(globalLinesRenderer->mNewDepthBuffer, globalLinesRenderer->mNewTexture); 
     147                { 
     148                        //globalLinesRenderer->ApplyDepthPeeling(Beam(), 0); 
     149                        globalLinesRenderer->ExportDepthBuffer(); 
     150                        return; 
     151                } 
     152        case '4': 
     153                { 
     154                        VssRayContainer rays; 
     155 
     156                        globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0); 
     157                        return; 
     158                } 
    136159        default: 
    137160                return; 
     
    162185 
    163186 
     187void GlobalLinesRenderer::DisplayBuffer() 
     188{ 
     189        //mNewTexture->Bind(); 
     190        mNewTexture->BindDepth(); 
     191        mNewTexture->EnableTextureTarget(); 
     192         
     193        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     194         
     195        if (mNewTexture->IsRectangleTexture()) 
     196        { 
     197                glBegin(GL_QUADS); 
     198                glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 
     199                glTexCoord2f(mNewTexture->GetWidth(), 0); glVertex3f( 1, -1, -0.5f); 
     200                glTexCoord2f(mNewTexture->GetWidth(), mNewTexture->GetHeight()); glVertex3f( 1,  1, -0.5f); 
     201                glTexCoord2f(0, mNewTexture->GetHeight()); glVertex3f(-1, 1, -0.5f); 
     202                glEnd(); 
     203        } 
     204        else 
     205        { 
     206                glBegin(GL_QUADS); 
     207                glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 
     208                glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f); 
     209                glTexCoord2f(1, 1); glVertex3f( 1,  1, -0.5f); 
     210                glTexCoord2f(0, 1); glVertex3f(-1,  1, -0.5f); 
     211                glEnd(); 
     212        }   
     213 
     214        mNewTexture->DisableTextureTarget(); 
     215        PrintGLerror("displaytexture"); 
     216} 
     217 
     218 
    164219GlobalLinesRenderer::~GlobalLinesRenderer() 
    165220{ 
     
    168223        if (sCgContext) 
    169224                cgDestroyContext(sCgContext); 
     225 
     226        // init the receiving buffers 
     227        delete mNewDepthBuffer; 
     228        delete mOldDepthBuffer; 
     229         
     230        delete mNewItemBuffer; 
     231        delete mOldItemBuffer; 
    170232} 
    171233 
     
    173235void GlobalLinesRenderer::CastGlobalLines(Beam &beam, const int samples) 
    174236{ 
     237        VssRayContainer rays; 
     238 
    175239        // bind pixel shader implementing the front depth buffer functionality 
    176         ApplyDepthPeeling(beam, samples); 
     240        ApplyDepthPeeling(rays, beam, samples); 
    177241} 
    178242 
     
    192256        {  
    193257                //glLoadIdentity(); 
    194                          
    195                 //mRenderer->mUseFalseColors = true; 
    196258                ObjectContainer::const_iterator oit, oit_end = mPreprocessor->mObjects.end(); 
    197259 
     
    215277 
    216278 
     279void GlobalLinesRenderer::ComputeLookAt(const float alpha,  
     280                                                                                const float beta, 
     281                                                                                Vector3 &eye,  
     282                                                                                Vector3 &up,  
     283                                                                                Vector3 left) 
     284{ 
     285        //float x = cos(alpha); 
     286        //float y = sin(alpha); 
     287        eye.x = sin(alpha) * cos(beta); 
     288        eye.y = sin(alpha) * sin(beta); 
     289        eye.z = cos(beta); 
     290 
     291        eye.RightHandedBase(up, left); 
     292} 
     293 
     294 
    217295void GlobalLinesRenderer::InitGl() 
    218296{ 
     
    241319        glLoadIdentity(); 
    242320 
    243         // init the receiving buffers 
     321        // initialise the receiving buffers 
    244322        mNewDepthBuffer = new float[texWidth * texHeight]; 
    245323        mOldDepthBuffer = new float[texWidth * texHeight]; 
    246324         
     325        for (int i = 0; i < texWidth * texHeight; ++ i) 
     326        { 
     327                mNewDepthBuffer[i] = 1; 
     328                mOldDepthBuffer[i] = 1; 
     329        } 
     330 
    247331        mNewItemBuffer = new int[texWidth * texHeight *4]; 
    248332        mOldItemBuffer = new int[texWidth * texHeight *4]; 
    249333         
     334        for (int i = 0; i < texWidth * texHeight * 4; ++ i) 
     335        { 
     336                mNewItemBuffer[i] = 0; 
     337                mOldItemBuffer[i] = 0; 
     338        } 
     339 
    250340        AxisAlignedBox3 bbox = globalLinesRenderer->mPreprocessor->mKdTree->GetBox(); 
    251341         
    252         Vector3 midPoint = bbox.Center(); 
     342        mViewPoint = bbox.Center(); 
    253343         
    254344        const float sceneSize = Magnitude(bbox.Diagonal()); 
    255         Vector3 viewPoint = midPoint + Vector3(0.5 * sceneSize, 0, 0); 
    256          
    257         cout << "mid point: " << midPoint << endl; 
     345        Vector3 viewPoint = mViewPoint + Vector3(0.5 * sceneSize, 0, 0); 
     346         
     347        cout << "mid point: " << mViewPoint << endl; 
    258348        cout << "view point: " << viewPoint << endl; 
    259349        cout << "scene: " << bbox << endl; 
     350 
     351        mEyeVec = Normalize(viewPoint - mViewPoint); 
     352        mEyeVec.RightHandedBase(mUpVec, mLeftVec); 
    260353 
    261354        /*gluLookAt(viewPoint.x, viewPoint.y, viewPoint.z,  
     
    331424                SetFrustum(sceneSize, sceneSize, 1, sceneSize); 
    332425 
    333                 glClearColor(0.1, 0.7, 0.2, 1); 
     426                // for item buffer: white means no color 
     427                glClearColor(1, 1, 1, 1); 
    334428                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    335429 
     
    343437                glLoadIdentity(); 
    344438                gluLookAt(viewPoint.x, viewPoint.y, viewPoint.z,  
    345                                   midPoint.x, midPoint.y, midPoint.z,  
     439                                  mViewPoint.x, mViewPoint.y, mViewPoint.z,  
    346440                                  0, 1, 0); 
    347441 
     
    350444        mNewTexture->EndCapture(); 
    351445 
    352         // setup the rendering context for the RenderTexture 
     446        // setup the rendering context for the other depth buffer 
    353447        mOldTexture->BeginCapture(); 
    354448        { 
    355                 glClearColor(0.1, 0.7, 0.2, 1); 
     449                // for item buffer: white means no color 
     450                glClearColor(1, 1, 1, 1); 
    356451        
    357452                //Reshape(texWidth, texHeight); 
     
    369464                 
    370465                gluLookAt(viewPoint.x, viewPoint.y, viewPoint.z,  
    371                                   midPoint.x, midPoint.y, midPoint.z,  
     466                                  mViewPoint.x, mViewPoint.y, mViewPoint.z,  
    372467                                  0, 1, 0); 
    373468 
     
    406501 
    407502                        float newDummy2 = x - texWidth / 2; 
    408                         float newDummy3 = y -  texHeight / 2; 
     503                        float newDummy3 = y - texHeight / 2; 
    409504 
    410505                        float oldDummy2 = newDummy2; 
    411506                        float oldDummy3 = newDummy3; 
    412507 
    413                         const Vector3 newPt = newDepth * mEyeVec + newDummy1 * mLeftVec + newDummy2 * mUpVec; 
    414                         const Vector3 oldPt = oldDepth * mEyeVec + oldDummy1 * mLeftVec + oldDummy2 * mUpVec; 
    415  
    416                         Intersectable *termObj1 = GetObject(mNewItemBuffer[index]); 
    417                         Intersectable *termObj2 = GetObject(mOldItemBuffer[index]); 
    418  
     508                        const Vector3 newPt = mViewPoint + newDepth * mEyeVec + newDummy1 * mLeftVec + newDummy2 * mUpVec; 
     509                        const Vector3 oldPt = mViewPoint + oldDepth * mEyeVec + oldDummy1 * mLeftVec + oldDummy2 * mUpVec; 
     510 
     511                        //cout << "viewpoint: " << mViewPoint << " new: " << newPt << " old: " << newPt << endl; 
     512                         
     513                        int r = mNewItemBuffer[index]; 
     514                        int g = mNewItemBuffer[index + 1]; 
     515                        int b = mNewItemBuffer[index + 2]; 
     516                         
     517                        Intersectable *termObj1 = NULL; 
     518                        Intersectable *termObj2 = NULL; 
     519 
     520                        // 3 times 255 means no valid object 
     521                        if (!((r == 255) && (g == 255) && (b == 255))) 
     522                        { 
     523                                const int id = mRenderer->GetId(r, g, b); 
     524                                cout << id << " "; 
     525                                //termObj1 = mPreprocessor->GetObjectById(id); 
     526                        } 
     527 
     528                        /*r = mOldItemBuffer[index]; 
     529                        g = mOldItemBuffer[index + 1]; 
     530                        b = mOldItemBuffer[index + 2]; 
     531 
     532                        if (!((r == 255) && (g == 255) && (b == 255))) 
     533                                Intersectable *termObj2 = mPreprocessor->GetObjectById(mRenderer->GetId(r, g, b)); 
     534*/ 
    419535                        // create rays in both directions 
    420                         vssRays.push_back(new VssRay(oldPt, newPt, NULL, termObj1)); 
    421                         vssRays.push_back(new VssRay(newPt, oldPt, NULL, termObj2)); 
     536                        //vssRays.push_back(new VssRay(oldPt, newPt, NULL, termObj1)); 
     537                        //vssRays.push_back(new VssRay(newPt, oldPt, NULL, termObj2)); 
    422538                } 
    423539        } 
     
    446562void GlobalLinesRenderer::GrabItemBuffer(int *data, RenderTexture *rt) 
    447563{ 
    448         rt->BindDepth(); 
     564        rt->Bind(); 
    449565        rt->EnableTextureTarget(); 
    450         cout << "depth: " << mNewTexture->GetDepthBits() << endl; 
    451  
    452         const int texFormat = GL_DEPTH_COMPONENT; 
     566        //cout << "depth: " << mNewTexture->GetDepthBits() << endl; 
     567 
     568        const int texFormat = GL_RGBA; 
    453569        glGetTexImage(mNewTexture->GetTextureTarget(), 0, texFormat, GL_FLOAT, data); 
    454570 
    455571        mNewTexture->DisableTextureTarget(); 
    456572} 
     573 
    457574 
    458575void GlobalLinesRenderer::ExportDepthBuffer() 
     
    493610 
    494611 
    495 void GlobalLinesRenderer::ApplyDepthPeeling(Beam &beam, const int samples) 
     612/* 
     613void GlobalLinesRenderer::ExportItemBuffer() 
     614{ 
     615        mNewTexture->BindDepth(); 
     616        mNewTexture->EnableTextureTarget(); 
     617        cout << "depth: " << mNewTexture->GetDepthBits() << endl; 
     618 
     619        const bool components = 1;//mNewTexture->GetDepthBits() / 8; 
     620 
     621        float *data = new float[texWidth * texHeight * components]; 
     622        //const int texFormat = WGL_TEXTURE_DEPTH_COMPONENT_NV; 
     623        const int texFormat = GL_DEPTH_COMPONENT; 
     624        //const int texFormat = GL_RGBA; 
     625        glGetTexImage(mNewTexture->GetTextureTarget(), 0, texFormat, GL_FLOAT, data); 
     626 
     627        string filename("depth.tga"); 
     628        ilRegisterType(IL_FLOAT); 
     629 
     630        const int depth = 1; 
     631        const int bpp = components; 
     632 
     633        ilTexImage(texWidth, texHeight, depth, bpp, IL_LUMINANCE, IL_FLOAT, data); 
     634        ilSaveImage((char *const)filename.c_str()); 
     635 
     636        cout << "finished" << endl; 
     637        delete data; 
     638        cout << "data deleted" << endl; 
     639        mNewTexture->DisableTextureTarget(); 
     640        PrintGLerror("grab texture"); 
     641} 
     642*/ 
     643 
     644 
     645void GlobalLinesRenderer::ApplyDepthPeeling(VssRayContainer &rays, 
     646                                                                                        Beam &beam,  
     647                                                                                        const int samples) 
    496648{ 
    497649        mNewTexture->BeginCapture(); 
     
    504656         
    505657        PrintGLerror("firstpass"); 
    506  
    507658        if (mNewTexture->IsRectangleTexture()) cout << "rect" << endl; 
     659 
     660        // process the buffers for the first layer 
     661        ProcessDepthBuffer(rays); 
    508662 
    509663        for(int i = 0; i < mMaxDepth; ++ i)  
     
    520674 
    521675                        cgGLBindProgram(sCgDepthPeelingProgram); 
    522                 //      cgGLBindProgram(sCgPassThroughProgram); 
    523676                        cgGLEnableProfile(sCgFragmentProfile); 
    524677                        cgGLSetTextureParameter(sTextureParam, mOldTexture->GetDepthTextureID()); 
     
    532685                        cgGLDisableTextureParameter(sTextureParam); 
    533686                        cgGLDisableProfile(sCgFragmentProfile); 
     687 
     688                        // process the buffers for following layer 
     689                        ProcessDepthBuffer(rays); 
     690 
    534691                } 
    535692                mNewTexture->EndCapture(); 
     
    537694 
    538695        PrintGLerror("endpeeling"); 
    539  
    540         //mNewTexture->Bind(); 
    541         mNewTexture->BindDepth(); 
    542         mNewTexture->EnableTextureTarget(); 
    543          
    544         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    545          
    546         if (mNewTexture->IsRectangleTexture()) 
    547         { 
    548                 glBegin(GL_QUADS); 
    549                 glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 
    550                 glTexCoord2f(mNewTexture->GetWidth(), 0); glVertex3f( 1, -1, -0.5f); 
    551                 glTexCoord2f(mNewTexture->GetWidth(), mNewTexture->GetHeight()); glVertex3f( 1,  1, -0.5f); 
    552                 glTexCoord2f(0, mNewTexture->GetHeight()); glVertex3f(-1, 1, -0.5f); 
    553                 glEnd(); 
    554         } 
    555         else 
    556         { 
    557                 glBegin(GL_QUADS); 
    558                 glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 
    559                 glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f); 
    560                 glTexCoord2f(1, 1); glVertex3f( 1,  1, -0.5f); 
    561                 glTexCoord2f(0, 1); glVertex3f(-1,  1, -0.5f); 
    562                 glEnd(); 
    563         }   
    564  
    565         mNewTexture->DisableTextureTarget(); 
    566         PrintGLerror("displaytexture"); 
    567 } 
    568  
    569  
    570 } 
     696} 
     697 
     698 
     699} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h

    r1954 r1958  
    5151void GrabDepthBuffer(float *data, RenderTexture *rt); 
    5252void GrabItemBuffer(int *data, RenderTexture *rt); 
    53 void ApplyDepthPeeling(Beam &beam, const int samples); 
     53void ApplyDepthPeeling(VssRayContainer &rays, Beam &beam, const int samples); 
    5454void ExportDepthBuffer(); 
    5555void ProcessDepthBuffer(VssRayContainer &vssRays); 
     56void DisplayBuffer(); 
    5657 
    5758        int mMaxDepth; 
     
    6263        float mNear; 
    6364 
     65        Vector3 mViewPoint; 
     66 
    6467        float *mNewDepthBuffer; 
    6568        float *mOldDepthBuffer; 
     
    6871RenderTexture *mNewTexture; 
    6972        RenderTexture *mOldTexture; 
     73 
     74        void ComputeLookAt(const float alpha,  
     75                                           const float beta, 
     76                                           Vector3 &eye,  
     77                                           Vector3 &up,  
     78                                           Vector3 left); 
    7079protected: 
    71  
    72         void ProcessDepthBuffer(); 
    7380 
    7481        void SwitchRenderTextures(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1940 r1958  
    12941294} 
    12951295 
    1296 } 
     1296 
     1297Intersectable *Preprocessor::GetObjectById(const int id) 
     1298{ 
     1299#if 0 
     1300        // create a dummy mesh instance to be able to use stl 
     1301        MeshInstance object(NULL); 
     1302        object.SetId(id); 
     1303 
     1304        ObjectContainer::const_iterator oit = 
     1305                lower_bound(mObjects.begin(), mObjects.end(), &object, ilt); 
     1306                                 
     1307        // objects sorted by id 
     1308        if ((oit != mObjects.end()) && ((*oit)->GetId() == object.GetId())) 
     1309        { 
     1310                return (*oit); 
     1311        } 
     1312        else 
     1313        { 
     1314                return NULL; 
     1315        } 
     1316#else 
     1317        return mObjects[id]; 
     1318#endif 
     1319} 
     1320 
     1321} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1942 r1958  
    147147                                                  const bool pruneInvalidRays = true); 
    148148 
    149   /** Compute pixel error of the current PVS solution by sampling given number of viewpoints */ 
    150   virtual void 
    151   ComputeRenderError(); 
     149        /** Compute pixel error of the current PVS solution by sampling given number of viewpoints */ 
     150        virtual void ComputeRenderError(); 
    152151 
    153152        /** Returns a view cells manager of the given name. 
     
    172171        PreprocessorThread *GetThread() const; 
    173172 
     173         
     174        Intersectable *GetObjectById(const int id); 
    174175 
    175176 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj

    r1949 r1958  
    717717                        </File> 
    718718                        <File 
    719                                 RelativePath=".\QtPreprocessorThread.cpp"> 
    720                         </File> 
    721                         <File 
    722                                 RelativePath=".\QtPreprocessorThread.h"> 
    723                         </File> 
    724                         <File 
    725719                                RelativePath="..\src\Ray.cpp"> 
    726720                        </File> 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp

    r1344 r1958  
    181181} 
    182182 
     183 
    183184} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h

    r1328 r1958  
    5353        void SetRoot(SceneGraphNode *sgNnode); 
    5454 
     55 
    5556protected: 
    5657 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.h

    r1883 r1958  
    184184  // Viewer is the coordinates of viewer location, UpL is the vector. 
    185185  friend void ViewVectors(const Vector3 &DirAt, const Vector3 &Viewer, 
    186                           const Vector3 &UpL, Vector3 &ViewV, 
    187                           Vector3 &ViewU, Vector3 &ViewN ); 
     186                                                  const Vector3 &UpL, Vector3 &ViewV, 
     187                                                  Vector3 &ViewU, Vector3 &ViewN ); 
    188188 
    189189  // Given the intersection point `P', you have available normal `N' 
     
    262262 
    263263 
     264inline void 
     265Vector3::RightHandedBase(Vector3& U, Vector3& V) const 
     266{ 
     267        // HACK 
     268        V = ArbitraryNormal(*this); 
     269        U = CrossProd(V, *this); 
     270} 
     271 
     272 
    264273inline Vector3 
    265274ToGlobalFrame(const Vector3 &loc, 
Note: See TracChangeset for help on using the changeset viewer.