Ignore:
Timestamp:
07/09/07 09:58:07 (17 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface
Files:
3 edited

Legend:

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

    r2530 r2538  
    1515#include "QtPreprocessorThread.h" 
    1616#include "Material.h" 
     17#include "IntersectableWrapper.h" 
     18 
    1719 
    1820#define USE_CG 1 
     
    109111   
    110112  ObjectPvs pvs; 
    111   if (1) { 
    112         pvs = viewcell->GetPvs(); 
    113   } else { 
    114         mViewCellsManager->ApplyFilter2(viewcell, 
    115                                                                         false, 
    116                                                                         1.0f, 
    117                                                                         pvs); 
    118   } 
     113   
     114  if (1)  
     115          pvs = viewcell->GetPvs(); 
     116  else  
     117          mViewCellsManager->ApplyFilter2(viewcell,     false, 1.0f, pvs); 
    119118   
    120119  //  cout<<"pvs size"<<pvs.GetSize()<<endl<<flush; 
     
    128127  glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);  
    129128   
    130   //    // Render PVS 
     129  // Render PVS 
    131130  ObjectPvsIterator it = pvs.GetIterator(); 
    132131   
     
    349348 
    350349 
    351  
    352 void 
    353 QtGlRendererWidget::RenderPvs() 
    354 { 
     350bool QtGlRendererWidget::PvsChanged(ViewCell *viewCell) const 
     351{ 
     352        if (viewCell != mPvsCache.mViewCell) 
     353                return true; 
     354 
     355        if (viewCell->GetPvs().GetSize() != mPvsCache.mUnfilteredPvsSize) 
     356                return true; 
     357 
     358        return false; 
     359} 
     360 
     361 
     362void QtGlRendererWidget::_RenderPvs() 
     363{ 
     364        mUseFalseColors = false; 
     365 
     366        int offset = mObjects.size() * 3; 
     367        char *arrayPtr = mUseVbos ? NULL : (char *)mData; 
    355368         
    356   Intersectable::NewMail(); 
    357  
    358   ViewCell *viewcell = NULL; 
    359  
    360   if (mDetectEmptyViewSpace)  
    361         glEnable( GL_CULL_FACE ); 
    362   else 
    363         glDisable( GL_CULL_FACE ); 
    364    
    365   viewcell = mViewCellsManager->GetViewCell(mViewPoint, true); 
    366    
    367   if (viewcell) { 
    368         // copy the pvs so that it can be filtered... 
    369          
    370         //      mPvsCache.mPvs; 
    371          
    372         if (mPvsCache.mViewCell != viewcell) { 
    373           mPvsCache.Reset(); 
    374           mPvsCache.mViewCell = viewcell; 
    375            
    376           if (mUseSpatialFilter) { 
    377                 // 9.11. 2006 -> experiment with new spatial filter 
     369        glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr); 
     370        glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3)); 
     371        glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices); 
     372} 
     373 
     374 
     375void QtGlRendererWidget::_UpdatePvsIndices() 
     376{ 
     377        mIndexBufferSize = 0; 
     378        KdNode::NewMail(); 
     379 
     380        mPvsSize = mPvsCache.mPvs.GetSize(); 
     381 
     382        ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 
     383 
     384        for (; it.HasMoreEntries(); )  
     385        { 
     386                Intersectable *obj = it.Next(); 
     387                KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem(); 
     388                _UpdatePvsIndices(node); 
     389        } 
     390} 
     391 
     392 
     393void QtGlRendererWidget::_UpdatePvsIndices(KdNode *node) 
     394{ 
     395        if (node->Mailed()) 
     396                return; 
     397 
     398        node->Mail(); 
     399 
     400        if (!node->IsLeaf())  
     401        { 
     402                KdInterior *in = static_cast<KdInterior *>(node); 
     403                 
     404                _UpdatePvsIndices(in->mBack); 
     405                _UpdatePvsIndices(in->mFront); 
     406        }  
     407        else  
     408        { 
     409                KdLeaf *leaf = static_cast<KdLeaf *>(node); 
     410 
     411                leaf->mIndexBufferStart = mIndexBufferSize; 
     412 
     413                for (size_t i = 0; i < leaf->mObjects.size(); ++ i) 
     414                { 
     415                        TriangleIntersectable *obj =  
     416                                static_cast<TriangleIntersectable *>(leaf->mObjects[i]); 
     417 
     418                        // check if already rendered 
     419                        if (!obj->Mailed()) 
     420                        { 
     421                                obj->Mail(); 
     422 
     423                                mIndices[mIndexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0; 
     424                                mIndices[mIndexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1; 
     425                                mIndices[mIndexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2; 
     426 
     427                                mIndexBufferSize += 3; 
     428                        } 
     429                } 
     430 
     431                leaf->mIndexBufferSize = mIndexBufferSize - leaf->mIndexBufferStart; 
     432        } 
     433} 
     434 
     435 
     436void QtGlRendererWidget::RenderPvs() 
     437{ 
     438        if (mUseVbos)  
     439                glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 
     440 
     441        EnableDrawArrays(); 
     442 
     443        Intersectable::NewMail(); 
     444        ViewCell *viewcell = NULL; 
     445 
     446        if (mDetectEmptyViewSpace)  
     447                glEnable(GL_CULL_FACE); 
     448        else 
     449                glDisable(GL_CULL_FACE); 
     450 
     451        viewcell = mViewCellsManager->GetViewCell(mViewPoint, true); 
     452 
     453        if (viewcell)  
     454        { 
     455                // copy the pvs so that it can be filtered... 
     456                if (PvsChanged(viewcell))  
     457                { 
     458                        mPvsCache.Reset(); 
     459                        mPvsCache.mViewCell = viewcell; 
     460                        mPvsCache.mUnfilteredPvsSize = viewcell->GetPvs().GetSize(); 
     461 
     462                        if (mUseSpatialFilter)  
     463                        { 
     464                                // 9.11. 2006 -> experiment with new spatial filter 
    378465#if 0 
    379                 mViewCellsManager->ApplySpatialFilter(mKdTree, 
    380                                                                                           mSpatialFilterSize* 
    381                                                                                           Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 
    382                                                                                           mPvsCache.mPvs); 
     466                                mViewCellsManager->ApplySpatialFilter(mKdTree, 
     467                                        mSpatialFilterSize* 
     468                                        Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 
     469                                        mPvsCache.mPvs); 
    383470#else 
    384                 // mSpatialFilter size is in range 0.001 - 0.1 
    385                 mViewCellsManager->ApplyFilter2(viewcell, 
    386                                                                                 mUseFilter, 
    387                                                                                 100*mSpatialFilterSize, 
    388                                                                                 mPvsCache.mPvs, 
    389                                                                                 &mPvsCache.filteredBoxes 
    390                                                                                 ); 
     471                                //cout<<"updating filter" << endl; 
     472                                // mSpatialFilter size is in range 0.001 - 0.1 
     473                                mViewCellsManager->ApplyFilter2(viewcell, 
     474                                        mUseFilter, 
     475                                        100 * mSpatialFilterSize, 
     476                                        mPvsCache.mPvs, 
     477                                        &mPvsCache.filteredBoxes 
     478                                        ); 
    391479#endif 
    392           } else 
    393                 mPvsCache.mPvs = viewcell->GetPvs(); 
    394            
    395           emit PvsUpdated(); 
     480                        }  
     481                        else 
     482                        { 
     483                                mPvsCache.mPvs = viewcell->GetPvs(); 
     484                        } 
     485 
     486                        /// update the indices for rendering 
     487                        _UpdatePvsIndices(); 
     488 
     489                        emit PvsUpdated(); 
     490                } 
     491 
     492                Intersectable::NewMail(); 
     493                PvsData pvsData; 
     494 
     495                // Render PVS 
     496                if (mUseSpatialFilter && mRenderBoxes)  
     497                { 
     498                        for (int i=0; i < mPvsCache.filteredBoxes.size(); i++) 
     499                                RenderBox(mPvsCache.filteredBoxes[i]); 
     500                }  
     501                else  
     502                { 
     503                        if (!mRenderVisibilityEstimates) 
     504                        { 
     505                                _RenderPvs(); 
     506                        } 
     507                        else 
     508                        { 
     509                                ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 
     510 
     511                                mPvsSize = mPvsCache.mPvs.GetSize(); 
     512                                for (; it.HasMoreEntries(); )  
     513                                { 
     514                                        Intersectable *object = it.Next(pvsData); 
     515 
     516                                        //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 
     517                                        // glColor3f(visibility, 0.0f, 0.0f); 
     518                                        //cerr << "sumpdf: " << pvsData.mSumPdf << endl; 
     519                                        RgbColor color = RainbowColorMapping(mTransferFunction*log10(pvsData.mSumPdf + 1)); 
     520                                        glColor3f(color.r, color.g, color.b); 
     521 
     522                                        mUseForcedColors = true; 
     523                                        RenderIntersectable(object); 
     524                                        mUseForcedColors = false; 
     525                                } 
     526                        } 
     527                } 
     528 
     529                if (mRenderFilter)  
     530                { 
     531                        mWireFrame = true; 
     532                        RenderIntersectable(viewcell); 
     533                        glPushMatrix(); 
     534                        glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z); 
     535                        glScalef(5.0f,5.0f,5.0f); 
     536                        glPushAttrib(GL_CURRENT_BIT); 
     537                        glColor3f(1.0f, 0.0f, 0.0f); 
     538                        //        gluSphere((::GLUquadric *)mSphere, 
     539                        //                              1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6); 
     540                        glPopAttrib(); 
     541                        glPopMatrix(); 
     542                        mWireFrame = false; 
     543                } 
     544        }  
     545        else  
     546        { 
     547                /*ObjectContainer::const_iterator oi = mObjects.begin(); 
     548                for (; oi != mObjects.end(); oi++) 
     549                        RenderIntersectable(*oi);*/ 
     550                RenderScene(); 
    396551        } 
    397552 
    398         Intersectable::NewMail(); 
    399  
    400         PvsData pvsData; 
    401  
    402         // Render PVS 
    403         if (mUseSpatialFilter && mRenderBoxes) { 
    404           for (int i=0; i < mPvsCache.filteredBoxes.size(); i++) 
    405                 RenderBox(mPvsCache.filteredBoxes[i]); 
    406         } else { 
    407           ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 
    408            
    409           mPvsSize = mPvsCache.mPvs.GetSize(); 
    410           for (; it.HasMoreEntries(); ) { 
    411                 Intersectable *object = it.Next(pvsData); 
    412                  
    413                 if (mRenderVisibilityEstimates) { 
    414                   //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 
    415                   //              glColor3f(visibility, 0.0f, 0.0f); 
    416                         //cerr << "sumpdf: " << pvsData.mSumPdf << endl; 
    417                   RgbColor color = RainbowColorMapping(mTransferFunction*log10(pvsData.mSumPdf + 1)); 
    418                   glColor3f(color.r, color.g, color.b); 
    419                    
    420                   mUseForcedColors = true; 
    421                   RenderIntersectable(object); 
    422                   mUseForcedColors = false; 
    423                 } else { 
    424                   mUseForcedColors = false; 
    425                   RenderIntersectable(object); 
    426                 } 
    427           } 
    428         } 
    429          
    430         if (mRenderFilter) { 
    431           mWireFrame = true; 
    432           RenderIntersectable(viewcell); 
    433           glPushMatrix(); 
    434           glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z); 
    435           glScalef(5.0f,5.0f,5.0f); 
    436           glPushAttrib(GL_CURRENT_BIT); 
    437           glColor3f(1.0f, 0.0f, 0.0f); 
    438           //      gluSphere((::GLUquadric *)mSphere, 
    439           //                            1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6); 
    440           glPopAttrib(); 
    441           glPopMatrix(); 
    442           mWireFrame = false; 
    443         } 
    444   } else { 
    445         ObjectContainer::const_iterator oi = mObjects.begin(); 
    446         for (; oi != mObjects.end(); oi++) 
    447           RenderIntersectable(*oi); 
    448   } 
     553        //DisableDrawArrays(); 
     554        //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 
    449555} 
    450556 
     
    466572  glColor3f(0.0f, 0.8f, 0.2f); 
    467573 
    468   //    // Render PVS 
     574  // Render PVS 
    469575  RenderPvs(); 
    470576   
    471577  glEnable(GL_STENCIL_TEST);  
    472578   
    473   //  mUseFalseColors = true; 
     579  //mUseFalseColors = true; 
    474580   
    475581  glDisable(GL_LIGHTING); 
     
    501607  int pixelCount = query->GetQueryResult(); 
    502608  pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight()); 
    503   cout<<"error pixels="<<pixelCount<<endl; 
     609  if (0) cout<<"error pixels="<<pixelCount<<endl; 
    504610 
    505611  mRenderError = pErrorPixels; 
     
    509615 
    510616 
    511 void 
    512 QtGlRendererWidget::mousePressEvent(QMouseEvent *e) 
     617void QtGlRendererWidget::timerEvent(QTimerEvent *event)  
     618{ 
     619        //std::cout << "Timer ID:" << event->timerId(); 
     620        update(); 
     621} 
     622 
     623 
     624void QtGlRendererWidget::mousePressEvent(QMouseEvent *e) 
    513625{ 
    514626  int x = e->pos().x(); 
     
    523635QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e) 
    524636{ 
    525   float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3; 
    526   float TURN_SENSITIVITY=0.1f; 
    527   float TILT_SENSITIVITY=32.0 ; 
    528   float TURN_ANGLE= M_PI/36.0 ; 
    529  
    530   int x = e->pos().x(); 
    531   int y = e->pos().y(); 
    532  
    533   int diffx = -(mousePoint.x - x); 
    534   int diffy = -(mousePoint.y - y); 
    535    
    536   if (e->modifiers() & Qt::ControlModifier) { 
    537         mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0; 
    538         mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0; 
    539   } else { 
    540         mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY); 
    541         float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY; 
    542         float angle = atan2(mViewDirection.x, mViewDirection.z); 
    543         mViewDirection.x = sin(angle+adiff); 
    544         mViewDirection.z = cos(angle+adiff); 
    545   } 
    546    
    547   mousePoint.x = x; 
    548   mousePoint.y = y; 
    549    
    550   updateGL(); 
     637        float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3; 
     638        float TURN_SENSITIVITY=0.1f; 
     639        float TILT_SENSITIVITY=32.0 ; 
     640        float TURN_ANGLE= M_PI/36.0 ; 
     641 
     642        int x = e->pos().x(); 
     643        int y = e->pos().y(); 
     644 
     645        int diffx = -(mousePoint.x - x); 
     646        int diffy = -(mousePoint.y - y); 
     647 
     648        if (e->modifiers() & Qt::ControlModifier)  
     649        { 
     650                mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0; 
     651                mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0; 
     652        }  
     653        else  
     654        { 
     655                mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY); 
     656                float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY; 
     657                float angle = atan2(mViewDirection.x, mViewDirection.z); 
     658                mViewDirection.x = sin(angle + adiff); 
     659                mViewDirection.z = cos(angle + adiff); 
     660        } 
     661 
     662        mousePoint.x = x; 
     663        mousePoint.y = y; 
     664 
     665        updateGL(); 
    551666} 
    552667 
     
    554669QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *) 
    555670{ 
    556  
    557  
    558671} 
    559672 
     
    584697  RenderInfo(); 
    585698 
    586   mFrame++; 
     699  mFrame ++; 
    587700   
    588701} 
     
    707820  mRenderVisibilityEstimates = false; 
    708821  mTransferFunction = 0.2f; 
     822  mIndexBufferSize = 0; 
     823    
     824  const int delay = 500; // half a second 
     825  timerId = startTimer(delay); 
    709826 
    710827  bool tmp; 
     
    825942          currentCost = costFunction[currentPos]; 
    826943#if 1    
    827         cout<<"costFunction.size()="<<costFunction.size()<<endl; 
     944        cout<<"costFunction.size()="<<(int)costFunction.size()<<endl; 
    828945        cout<<"CP="<<currentPos<<endl; 
    829946        cout<<"MC="<<maxCost<<endl; 
     
    9131030  int vc = 0; 
    9141031  if (mViewCellsManager) 
    915         vc = mViewCellsManager->GetViewCells().size(); 
     1032        vc = (int)mViewCellsManager->GetViewCells().size(); 
    9161033 
    9171034  int filter = 0; 
     
    10701187 
    10711188 
    1072  
    1073  
    1074 /***********************************************************************/ 
    1075 /*                     QtGlDebuggerWidget implementation                                   */ 
    1076 /***********************************************************************/ 
     1189/*********************************************************************/ 
     1190/*                   QtGlDebuggerWidget implementation               */ 
     1191/*********************************************************************/ 
    10771192 
    10781193 
     
    10941209         DEL_PTR(mRenderBuffer); 
    10951210} 
    1096  
    10971211 
    10981212 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h

    r1997 r2538  
    148148  float mTransferFunction; 
    149149 
     150  unsigned int mIndexBufferSize; 
    150151   
    151152  QtRendererControlWidget *mControlWidget; 
     
    177178  void resizeGL(int w, int h); 
    178179  void paintGL(); 
    179   void timerEvent(QTimerEvent *) { 
    180           update(); 
    181   } 
    182  
     180  void timerEvent(QTimerEvent *event); 
    183181  void mousePressEvent(QMouseEvent *); 
    184182  void mouseReleaseEvent(QMouseEvent *); 
    185183  void mouseMoveEvent(QMouseEvent *); 
    186184 
    187   void keyPressEvent ( QKeyEvent * e ) ; 
    188  
    189   void 
    190   RenderPvs(); 
    191  
    192   float 
    193   RenderErrors(); 
    194   void 
    195   RenderInfo(); 
     185  void keyPressEvent(QKeyEvent * e); 
     186 
     187  void RenderPvs(); 
     188 
     189  float RenderErrors(); 
     190  void RenderInfo(); 
    196191 
    197192  virtual int GetWidth() const { return width(); } 
     
    211206        show(); 
    212207  } 
     208 
     209  bool PvsChanged(ViewCell *viewcell) const; 
     210 
    213211 
    214212 public slots: 
     
    306304        updateGL(); 
    307305  } 
     306 
     307  void _RenderPvs(); 
     308 
     309  void _UpdatePvsIndices(); 
     310  void _UpdatePvsIndices(KdNode *node); 
    308311 
    309312  signals: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp

    r1997 r2538  
    100100QtGlViewer::paintGL() 
    101101{ 
    102   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    103   glLoadIdentity(); 
     102        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     103        glLoadIdentity(); 
    104104 
    105   float m[4][4]; 
     105        float m[4][4]; 
    106106 
    107   glLoadIdentity(); 
    108   gluLookAt(0.0, 0.0, 1.0,  /* eye is at (0,0,30) */ 
    109                                                 0.0, 0.0, 0.0,      /* center is at (0,0,0) */ 
    110                                                 0.0, 1.0, 0.);      /* up is in positive Y direction */ 
    111    
    112   build_rotmatrix(m, manipulatorLastQuat); 
    113   glMultMatrixf(&m[0][0]); 
     107        glLoadIdentity(); 
     108        gluLookAt(0.0, 0.0, 1.0,  /* eye is at (0,0,30) */ 
     109                0.0, 0.0, 0.0,      /* center is at (0,0,0) */ 
     110                0.0, 1.0, 0.);      /* up is in positive Y direction */ 
    114111 
    115   float s = scale*20.0f/Magnitude(mRenderer->mSceneGraph->GetBox().Diagonal()); 
    116   glScalef(s, s, s); 
    117    
    118   Vector3 t = -mRenderer->mSceneGraph->GetBox().Center(); 
    119   glTranslatef(t.x, t.y, t.z); 
     112        build_rotmatrix(m, manipulatorLastQuat); 
     113        glMultMatrixf(&m[0][0]); 
     114 
     115        float s = scale*20.0f/Magnitude(mRenderer->mSceneGraph->GetBox().Diagonal()); 
     116        glScalef(s, s, s); 
     117 
     118        Vector3 t = -mRenderer->mSceneGraph->GetBox().Center(); 
     119        glTranslatef(t.x, t.y, t.z); 
    120120 
    121121        RenderScene(); 
Note: See TracChangeset for help on using the changeset viewer.