Ignore:
Timestamp:
05/31/06 10:04:05 (18 years ago)
Author:
mattausch
Message:

fixed bug for histogram
improved samplerenderer
todo: difference detectempty true / false

File:
1 edited

Legend:

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

    r991 r997  
    444444 
    445445void 
     446GlRendererBuffer::EvalQueryWithItemBuffer( 
     447                                                                           //RenderCostSample &sample 
     448                                                                           ) 
     449{ 
     450        // read back the texture 
     451        glReadPixels(0, 0, 
     452                                GetWidth(), GetHeight(), 
     453                                GL_RGBA, 
     454                                GL_UNSIGNED_BYTE, 
     455                                mPixelBuffer); 
     456                 
     457                         
     458        unsigned int *p = mPixelBuffer; 
     459                         
     460        for (int y = 0; y < GetHeight(); y++) 
     461        { 
     462                for (int x = 0; x < GetWidth(); x++, p++)  
     463                { 
     464                        unsigned int id = (*p) & 0xFFFFFF; 
     465 
     466                        if (id != 0xFFFFFF) 
     467                                ++ mObjects[id]->mCounter; 
     468                } 
     469        } 
     470} 
     471 
     472 
     473void 
     474GlRendererBuffer::EvalQueryWithOcclusionQueries( 
     475                                                                           //RenderCostSample &sample 
     476                                                                           ) 
     477{ 
     478        glDepthFunc(GL_LEQUAL); 
     479                 
     480        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
     481        glDepthMask(GL_FALSE); 
     482                 
     483        // now issue queries for all objects 
     484        for (int j = 0; j < mObjects.size(); ++ j)  
     485        { 
     486                for (int q = 0; j + q < mObjects.size() && q < mOcclusionQueries.size(); ++ q)  
     487                { 
     488                        glBeginOcclusionQueryNV(mOcclusionQueries[q]); 
     489                                         
     490                        RenderIntersectable(mObjects[j + q]); 
     491                        glEndOcclusionQueryNV(); 
     492                } 
     493                 
     494                // collect results of the queries 
     495                for (int q = 0; j + q < mObjects.size() && q < mOcclusionQueries.size(); ++ q)  
     496                { 
     497                        unsigned int pixelCount; 
     498                                         
     499                        //-- reenable other state 
     500#if 1 
     501                        do  
     502                        { 
     503                                glGetOcclusionQueryuivNV(mOcclusionQueries[q], 
     504                                                                                GL_PIXEL_COUNT_AVAILABLE_NV, 
     505                                                                                &pixelCount); 
     506                                         
     507                                if (0 && !pixelCount) cout << "W"; 
     508                        }  
     509                        while (!pixelCount); 
     510#endif 
     511 
     512                        glGetOcclusionQueryuivNV(mOcclusionQueries[q], 
     513                                                                        GL_PIXEL_COUNT_NV, 
     514                                                                        &pixelCount); 
     515 
     516                        // if (pixelCount) 
     517                        // cout<<"q="<<mOcclusionQueries[q]<<" pc="<<pixelCount<<" "; 
     518                         
     519                        mObjects[j + q]->mCounter += pixelCount; 
     520                } 
     521 
     522                j += q; 
     523        } 
     524                 
     525        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     526        glDepthMask(GL_TRUE); 
     527} 
     528 
     529 
     530void 
    446531GlRendererBuffer::EvalRenderCostSample( 
    447532                                                                           RenderCostSample &sample 
    448533                                                                           ) 
    449534{ 
    450   mViewCellsManager->GetViewPoint(mViewPoint); 
    451   sample.mPosition = mViewPoint; 
    452  
    453   cout << mViewPoint << endl; 
    454    
    455   // take a render cost sample by rendering a cube 
    456   Vector3 directions[6]; 
    457   directions[0] = Vector3(1,0,0); 
    458   directions[1] = Vector3(0,1,0); 
    459   directions[2] = Vector3(0,0,1); 
    460   directions[3] = Vector3(-1,0,0); 
    461   directions[4] = Vector3(0,-1,0); 
    462   directions[5] = Vector3(0,0,-1); 
    463  
    464   sample.mVisibleObjects = 0; 
    465  
    466   int i, j; 
    467    
    468   // reset object visibility 
    469   for (i=0; i < mObjects.size(); i++) { 
    470         mObjects[i]->mCounter = 0; 
    471   } 
    472   mFrame++; 
    473   for (i=0; i < 6; i++) { 
    474         mViewDirection = directions[i]; 
    475         SetupCamera(); 
    476         glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 
    477         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    478          
    479         glDepthFunc( GL_LESS ); 
    480  
    481         mUseFalseColors = true; 
    482  
    483         RenderScene(); 
    484  
    485         if (1) { 
    486           char filename[256]; 
    487           sprintf(filename, "snap/frame-%04d-%d.png", mFrame, i); 
    488           QImage im = toImage(); 
    489           im.save(filename, "PNG"); 
    490         } 
    491          
    492         bool useItemBuffer = false; 
    493          
    494         if (useItemBuffer) { 
    495           // read back the texture 
    496           glReadPixels(0, 0, 
    497                                    GetWidth(), GetHeight(), 
    498                                    GL_RGBA, 
    499                                    GL_UNSIGNED_BYTE, 
    500                                    mPixelBuffer); 
    501            
    502           int x, y; 
    503           unsigned int *p = mPixelBuffer; 
    504           for (y = 0; y < GetHeight(); y++) 
    505                 for (x = 0; x < GetWidth(); x++, p++) { 
    506                   unsigned int id = (*p) & 0xFFFFFF; 
    507                   if (id != 0xFFFFFF) 
    508                         mObjects[id]->mCounter++; 
     535        // choose a random view point 
     536        mViewCellsManager->GetViewPoint(mViewPoint); 
     537        sample.mPosition = mViewPoint; 
     538        //cout << "viewpoint: " << mViewPoint << endl; 
     539 
     540        // take a render cost sample by rendering a cube 
     541        Vector3 directions[6]; 
     542 
     543        directions[0] = Vector3(1,0,0); 
     544        directions[1] = Vector3(0,1,0); 
     545        directions[2] = Vector3(0,0,1); 
     546        directions[3] = Vector3(-1,0,0); 
     547        directions[4] = Vector3(0,-1,0); 
     548        directions[5] = Vector3(0,0,-1); 
     549 
     550        sample.mVisibleObjects = 0; 
     551 
     552        int i, j; 
     553 
     554        // reset object visibility 
     555        for (i=0; i < mObjects.size(); i++)  
     556        { 
     557                mObjects[i]->mCounter = 0; 
     558        } 
     559 
     560        ++ mFrame; 
     561 
     562        // either use occlusion queries or item buffer 
     563        bool useOcclusionQueries; 
     564        environment->GetBoolValue("RenderSampler.useOcclusionQueries", useOcclusionQueries); 
     565 
     566        //if (useOcclusionQueries) cout << "using occlusion queries" << endl; 
     567        //else cout << "using item buffer" << endl; 
     568         
     569        glCullFace(GL_FRONT); 
     570 
     571        if (mDetectEmptyViewSpace)  
     572        { 
     573                glEnable(GL_CULL_FACE); 
     574                cout << "culling" << endl; 
     575        } 
     576        else 
     577        { 
     578                cout << "not culling" << endl; 
     579                glDisable(GL_CULL_FACE); 
     580        } 
     581 
     582        for (i = 0; i < 6; ++ i)  
     583        { 
     584                mViewDirection = directions[i]; 
     585                SetupCamera(); 
     586 
     587                glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 
     588                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     589                glDepthFunc(GL_LESS); 
     590                mUseFalseColors = true; 
     591 
     592 
     593                // the actual scene rendering 
     594 
     595                RenderScene(); 
     596 
     597 
     598                if (0)  
     599                { 
     600                        char filename[256]; 
     601                        sprintf(filename, "snap/frame-%04d-%d.png", mFrame, i); 
     602                        QImage im = toImage(); 
     603                        im.save(filename, "PNG"); 
    509604                } 
    510            
    511         } else { 
    512          
    513           //      glDepthFunc( GL_LEQUAL ); 
    514           glDepthFunc( GL_LEQUAL ); 
    515            
    516           glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    517           glDepthMask(GL_FALSE); 
    518            
    519           // now issue queries for all objects 
    520           for (j = 0; j < mObjects.size(); j++) { 
    521                 int q; 
    522                 for (q = 0; j + q < mObjects.size() && q < mOcclusionQueries.size(); q++) { 
    523                   glBeginOcclusionQueryNV(mOcclusionQueries[q]); 
    524                   RenderIntersectable(mObjects[j+q]); 
    525                   glEndOcclusionQueryNV(); 
     605          
     606                if (useOcclusionQueries)  
     607                { 
     608                        EvalQueryWithOcclusionQueries(); 
    526609                } 
    527                  
    528                  
    529                 // collect results of the queries 
    530                 for (q = 0; j + q < mObjects.size() && q < mOcclusionQueries.size(); q++) { 
    531                   unsigned int pixelCount; 
    532                   // reenable other state 
    533  
    534 #if 1 
    535                   do { 
    536                         glGetOcclusionQueryuivNV(mOcclusionQueries[q], 
    537                                                                          GL_PIXEL_COUNT_AVAILABLE_NV, 
    538                                                                          &pixelCount); 
    539                         if (!pixelCount) 
    540                           cout<<"W"; 
    541                   } while(!pixelCount); 
    542 #endif 
    543  
    544                   glGetOcclusionQueryuivNV(mOcclusionQueries[q], 
    545                                                                    GL_PIXEL_COUNT_NV, 
    546                                                                    &pixelCount); 
    547                   //            if (pixelCount) 
    548                   //              cout<<"q="<<mOcclusionQueries[q]<<" pc="<<pixelCount<<" "; 
    549                   mObjects[j+q]->mCounter += pixelCount; 
     610                else  
     611                { 
     612                        EvalQueryWithItemBuffer(); 
    550613                } 
    551                 j += q; 
    552           } 
    553            
    554           glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    555           glDepthMask(GL_TRUE); 
    556         } 
    557            
    558          
    559   }   
    560   // now evaluate the statistics over that sample 
    561   // currently only the number of visible objects is taken into account 
    562   sample.Reset(); 
    563   for (j = 0; j < mObjects.size(); j++) { 
    564         if (mObjects[j]->mCounter) { 
    565           sample.mVisibleObjects++; 
    566           sample.mVisiblePixels += mObjects[j]->mCounter; 
    567         } 
    568   } 
    569   cout<<"RS="<<sample.mVisibleObjects<<" "; 
     614        }   
     615 
     616        // now evaluate the statistics over that sample 
     617        // currently only the number of visible objects is taken into account 
     618        sample.Reset(); 
     619 
     620        for (j = 0; j < mObjects.size(); j++)  
     621        { 
     622                if (mObjects[j]->mCounter)  
     623                { 
     624                        ++ sample.mVisibleObjects; 
     625                        sample.mVisiblePixels += mObjects[j]->mCounter; 
     626                } 
     627        } 
     628 
     629        cout << "RS=" << sample.mVisibleObjects << " "; 
    570630} 
    571631 
     
    575635                                                                   vector<RenderCostSample> &samples 
    576636                                                                   ) 
    577 {cout << "here1" << endl; 
     637{ 
    578638  makeCurrent(); 
    579639 
    580640  if (mPixelBuffer == NULL) 
    581         mPixelBuffer = new unsigned int[GetWidth()*GetHeight()]; 
     641          mPixelBuffer = new unsigned int[GetWidth()*GetHeight()]; 
    582642   
    583643  SetupProjection(GetHeight(), GetHeight(), 90.0f); 
     
    589649  int numQ = 500; 
    590650 
    591   cout << "here2988" << endl; 
    592651 
    593652  if (mOcclusionQueries.size() < numQ)  
     
    605664          mOcclusionQueries.resize(numQ); 
    606665         
    607           for (i=0; i < numQ; ++ i) 
     666          for (i = 0; i < numQ; ++ i) 
    608667          { 
    609668                  mOcclusionQueries[i] = queries[i]; 
     
    613672  } 
    614673   
    615   for (i=0; i < n; ++ i) 
     674  for (i = 0; i < n; ++ i) 
    616675  { 
    617           cout << i << " "; 
    618676          EvalRenderCostSample(samples[i]); 
    619677  } 
Note: See TracChangeset for help on using the changeset viewer.