Changeset 1963


Ignore:
Timestamp:
01/10/07 13:28:42 (17 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
2 edited

Legend:

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

    r1962 r1963  
    66#include "GlRenderer.h" 
    77#include "Exporter.h" 
     8#include "ViewCellsManager.h" 
     9 
    810 
    911// the devil library 
     
    392394         
    393395        const float sceneSize = Magnitude(bbox.Diagonal()); 
    394         mViewPoint = midPoint + Vector3(0.5 * sceneSize, 0, 0); 
     396        mViewPoint = midPoint + Vector3(0.5 * sceneSize, 0, 0.5 * sceneSize); 
    395397         
    396398        cout << "mid point: " << midPoint << endl; 
     
    399401 
    400402        mNear = 1; 
    401         mFar = sceneSize; 
     403        mFar = sceneSize * 2; 
    402404        mWidth = sceneSize; 
    403405 
     
    580582 
    581583void GlobalLinesRenderer::ProcessDepthBuffer(VssRayContainer &vssRays,  
    582                                                                                          const bool oldBufferInitialised) 
     584                                                                                         const bool oldBufferInitialised, 
     585                                                                                         const int pass) 
    583586{ 
    584587        GrabDepthBuffer(mNewDepthBuffer, mNewTexture); 
     
    603606        } 
    604607 
    605         cout << "vp: " << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl; 
     608        //cout << "vp: " << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl; 
    606609 
    607610        for (int y = 0; y < texHeight; ++ y) 
     
    625628                                                                                                                 false); 
    626629 
     630                        if (!termObj1 && !termObj2) // we do not create a ray 
     631                                continue; 
     632 
     633                        Vector3 clippedOldPt, clippedNewPt; 
     634 
     635                        ClipToViewSpaceBox(oldPt, newPt, clippedOldPt, clippedNewPt); 
     636                        //clippedOldPt = oldPt; 
     637                        //clippedNewPt = newPt; 
     638 
    627639                        // create rays in both directions 
    628640                        if (termObj1) 
    629641                        { 
    630                                 vssRays.push_back(new VssRay(oldPt, newPt, NULL, termObj1)); 
     642                                vssRays.push_back(new VssRay(clippedOldPt, clippedNewPt, NULL, termObj1, pass)); 
    631643                                //cout << "new pt: " << newPt << endl; 
    632644                        } 
     
    634646                        if (termObj2) 
    635647                        { 
    636                                 vssRays.push_back(new VssRay(newPt, oldPt, NULL, termObj2)); 
     648                                vssRays.push_back(new VssRay(clippedNewPt, clippedOldPt, NULL, termObj2, pass)); 
    637649                                //cout << "old pt: " << oldPt << endl; 
    638650                        } 
     
    642654 
    643655 
     656bool GlobalLinesRenderer::ClipToViewSpaceBox(const Vector3 &origin, 
     657                                                                                         const Vector3 &termination, 
     658                                                                                         Vector3 &clippedOrigin, 
     659                                                                                         Vector3 &clippedTermination) 
     660{ 
     661        Ray ray(origin, termination - origin, Ray::LINE_SEGMENT);        
     662        ray.Precompute(); 
     663         
     664        float tmin, tmax; 
     665         
     666        //const AxisAlignedBox3 bbox = mPreprocessor->mViewCellsManager->GetViewSpaceBox(); 
     667        // hack 
     668        const AxisAlignedBox3 bbox = mPreprocessor->mKdTree->GetBox(); 
     669 
     670        if ((!bbox.ComputeMinMaxT(ray, &tmin, &tmax)) || 
     671                tmin>=tmax) 
     672        { 
     673                return false; 
     674        } 
     675         
     676        if (tmin >= 1.0f || tmax <=0.0f) 
     677                return false; 
     678 
     679        if (tmin > 0.0f) 
     680                clippedOrigin = ray.Extrap(tmin); 
     681        else 
     682                clippedOrigin = origin; 
     683 
     684        if (tmax < 1.0f) 
     685                clippedTermination = ray.Extrap(tmax); 
     686        else 
     687                clippedTermination = termination; 
     688 
     689        return true; 
     690} 
     691 
     692 
    644693void GlobalLinesRenderer::Run() 
    645694{ 
    646695        glutMainLoop(); 
    647 } 
    648  
    649  
    650 void SetupFalseColor(const unsigned int id,  
    651                                          unsigned char &r, 
    652                                          unsigned char &g, 
    653                                          unsigned char &b 
    654                                          ) 
    655 { 
    656         // swap bits of the color 
    657         r = id & 255; 
    658         g = (id >> 8) & 255; 
    659         b = (id >> 16) & 255; 
    660696} 
    661697 
     
    673709 
    674710        VssRayContainer::const_iterator vit, vit_end = vssRays.end(); 
     711        VssRayContainer outRays; 
     712 
     713        Intersectable::NewMail(); 
    675714 
    676715        for (vit = vssRays.begin(); vit != vit_end; ++ vit) 
    677716        { 
    678717                VssRay *ray = *vit; 
    679                 Intersectable *obj = (*vit)->mTerminationObject;         
    680                 exporter->ExportIntersectable(obj); 
     718                Intersectable *obj = (*vit)->mTerminationObject; 
     719 
     720                if (!obj->Mailed()) 
     721                { 
     722                        obj->Mail(); 
     723                        exporter->ExportIntersectable(obj); 
     724                } 
     725 
     726                if (ray->mPass == 4) 
     727                        outRays.push_back(ray); 
    681728        }        
    682729 
    683         exporter->ExportRays(vssRays); 
     730        exporter->ExportRays(outRays); 
    684731 
    685732        delete exporter; 
     
    691738        rt->BindDepth(); 
    692739        rt->EnableTextureTarget(); 
    693         cout << "depth: " << mNewTexture->GetDepthBits() << endl; 
     740        //cout << "depth: " << mNewTexture->GetDepthBits() << endl; 
    694741 
    695742        const int texFormat = GL_DEPTH_COMPONENT; 
     
    727774        glGetTexImage(mNewTexture->GetTextureTarget(), 0, texFormat, GL_FLOAT, data); 
    728775 
    729         /*for (int i = texWidth * 123; i < texWidth * 124; ++ i) 
    730         { 
    731                 cout << data[i] << " "; 
    732         } 
    733         cout << "Saving image " << texWidth << " " << texHeight << endl; 
    734 */ 
    735776        string filename("depth.tga"); 
    736777        ilRegisterType(IL_FLOAT); 
     
    749790} 
    750791 
    751 /* 
     792 
    752793void GlobalLinesRenderer::ExportItemBuffer() 
    753794{ 
     
    758799        const int components = 4;//mNewTexture->GetDepthBits() / 8; 
    759800 
    760         float *data = new float[texWidth * texHeight * components*8]; 
     801        unsigned char *data = new unsigned char [texWidth * texHeight * components]; 
     802        //const int texFormat = WGL_TEXTURE_DEPTH_COMPONENT_NV; 
    761803        const int texFormat = GL_RGBA; 
    762         glGetTexImage(mNewTexture->GetTextureTarget(), 0, texFormat, GL_FLOAT, data); 
    763  
    764         string filename("items.tga"); 
    765         ilRegisterType(IL_FLOAT); 
     804        glGetTexImage(mNewTexture->GetTextureTarget(), 0, texFormat, GL_UNSIGNED_BYTE, data); 
     805 
     806        string filename("items.jpg"); 
     807        ilRegisterType(IL_UNSIGNED_BYTE); 
    766808 
    767809        const int depth = 1; 
    768810        const int bpp = components; 
    769811 
    770         cout << "saving items to file " << endl; 
    771  
    772         ilTexImage(16, 16, depth, bpp, IL_RGBA, IL_FLOAT, data); 
     812        ilTexImage(texWidth, texHeight, depth, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data); 
    773813        ilSaveImage((char *const)filename.c_str()); 
    774814 
     
    779819        PrintGLerror("grab texture"); 
    780820} 
    781 */ 
    782 void GlobalLinesRenderer::ExportItemBuffer() 
    783 { 
    784         mNewTexture->Bind(); 
    785         mNewTexture->EnableTextureTarget(); 
    786         cout << "depth: " << mNewTexture->GetDepthBits() << endl; 
    787  
    788         const int components = 4;//mNewTexture->GetDepthBits() / 8; 
    789  
    790         unsigned char *data = new unsigned char [texWidth * texHeight * components]; 
    791         //const int texFormat = WGL_TEXTURE_DEPTH_COMPONENT_NV; 
    792         const int texFormat = GL_RGBA; 
    793         glGetTexImage(mNewTexture->GetTextureTarget(), 0, texFormat, GL_UNSIGNED_BYTE, data); 
    794  
    795         string filename("items.jpg"); 
    796         ilRegisterType(IL_UNSIGNED_BYTE); 
    797  
    798         const int depth = 1; 
    799         const int bpp = components; 
    800  
    801         ilTexImage(texWidth, texHeight, depth, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data); 
    802         ilSaveImage((char *const)filename.c_str()); 
    803  
    804         cout << "finished" << endl; 
    805         delete data; 
    806         cout << "data deleted" << endl; 
    807         mNewTexture->DisableTextureTarget(); 
    808         PrintGLerror("grab texture"); 
    809 } 
    810821 
    811822 
     
    826837 
    827838        // process the buffers for the first layer 
    828         ProcessDepthBuffer(rays, false); 
    829  
    830         for(int i = 0; i < mMaxDepth; ++ i)  
     839        ProcessDepthBuffer(rays, false, 0); 
     840 
     841        for(int i = 1; i < mMaxDepth; ++ i)  
    831842        { 
    832843                // Peel another layer 
     
    836847                mNewTexture->BeginCapture(); 
    837848                { 
    838                         //if (mNewTexture->IsDoubleBuffered())  
    839                         //      glDrawBuffer(GL_BACK); 
    840  
    841849                        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);          
    842850 
     
    846854                        cgGLEnableTextureParameter(sTextureParam); 
    847855 
    848                         //glutSolidTorus(0.25, 1, 32, 64); 
    849856                        DrawGeometry(); 
    850857                         
    851                         glPopMatrix(); 
    852  
    853858                        cgGLDisableTextureParameter(sTextureParam); 
    854859                        cgGLDisableProfile(sCgFragmentProfile); 
     
    856861                mNewTexture->EndCapture(); 
    857862 
    858                 CLEAR_CONTAINER(rays); 
    859863                // process the buffers for following layer 
    860                 ProcessDepthBuffer(rays, true); 
     864                ProcessDepthBuffer(rays, true, i); 
    861865        } 
    862866 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h

    r1960 r1963  
    5454        void ExportDepthBuffer(); 
    5555        void ExportItemBuffer(); 
    56         void ProcessDepthBuffer(VssRayContainer &vssRays, const bool oldBufferInitialised); 
     56        void ProcessDepthBuffer(VssRayContainer &vssRays, const bool oldBufferInitialised, const int pass); 
    5757        void DisplayBuffer(const bool isDepth); 
    5858         
     59        bool ClipToViewSpaceBox(const Vector3 &origin, 
     60                                                        const Vector3 &termination, 
     61                                                        Vector3 &clippedOrigin, 
     62                                                        Vector3 &clippedTermination); 
     63 
    5964        Intersectable *ExtractSamplePoint(float *depthBuffer, 
    6065                                                                          unsigned char *itemBuffer, 
Note: See TracChangeset for help on using the changeset viewer.