Ignore:
Timestamp:
02/08/06 20:32:42 (18 years ago)
Author:
bittner
Message:

slider support for viewcells

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp

    r599 r608  
    1313#include <Cg/cgGL.h> 
    1414 
     15#include <QVBoxLayout> 
     16 
    1517static CGcontext sCgContext = NULL; 
    1618static CGprogram sCgFragmentProgram = NULL; 
     
    4345  mViewPoint = mSceneGraph->GetBox().Center(); 
    4446  mViewDirection = Vector3(0,0,1); 
     47 
    4548  //  timerId = startTimer(10); 
    4649  // debug coords for atlanta 
    47   mViewPoint = Vector3(3473, 6.778, -1699); 
    48   mViewDirection = Vector3(-0.2432, 0, 0.97); 
     50  //  mViewPoint = Vector3(3473, 6.778, -1699); 
     51  //  mViewDirection = Vector3(-0.2432, 0, 0.97); 
    4952   
    5053  mFrame = 0; 
     
    205208{ 
    206209  QString s; 
    207   s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)", 
     210  int vc = 0; 
     211  if (mViewCellsManager) 
     212        vc = mViewCellsManager->GetViewCells().size(); 
     213  s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f) viewcells:%04d", 
    208214                        mFrame, 
    209215                        mViewPoint.x, 
     
    212218                        mViewDirection.x, 
    213219                        mViewDirection.y, 
    214                         mViewDirection.z 
    215  
     220                        mViewDirection.z, 
     221                        vc 
    216222                        ); 
    217223  renderText(0,20,s); 
     
    433439 
    434440 
     441void 
     442GlRendererWidget::SetupProjection(const int w, const int h) 
     443{ 
     444  if (!mTopView) 
     445        GlRenderer::SetupProjection(w, h); 
     446  else { 
     447        glViewport(0, 0, w, h); 
     448        glMatrixMode(GL_PROJECTION); 
     449        glLoadIdentity(); 
     450        gluPerspective(50.0, 1.0, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal())); 
     451        glMatrixMode(GL_MODELVIEW); 
     452  } 
     453} 
     454 
    435455float 
    436456GlRendererWidget::RenderErrors() 
     
    444464  SetupCamera(); 
    445465  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    446  
    447  
     466   
     467  double eq[4]; 
     468  eq[0] = mSceneCutPlane.mNormal.x; 
     469  eq[1] = mSceneCutPlane.mNormal.y; 
     470  eq[2] = mSceneCutPlane.mNormal.z; 
     471  eq[3] = mSceneCutPlane.mD; 
     472   
     473  if (mCutScene) { 
     474        glClipPlane(GL_CLIP_PLANE0, eq); 
     475    glEnable(GL_CLIP_PLANE0); 
     476  } 
     477   
    448478  if (mDetectEmptyViewSpace)  
    449479        glEnable( GL_CULL_FACE ); 
     
    553583  } 
    554584 
     585  glDisable(GL_CLIP_PLANE0); 
     586 
    555587  return pErrorPixels; 
    556588} 
     
    697729GlRendererWidget::paintGL() 
    698730{ 
    699   if (mRenderViewCells) 
     731  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     732 
     733   
     734  RenderErrors(); 
     735  RenderInfo(); 
     736 
     737    if (mRenderViewCells)  
    700738        RenderViewCells(); 
    701   else { 
    702         RenderErrors(); 
    703         RenderInfo(); 
    704   } 
    705    
     739 
    706740  mFrame++; 
    707741} 
     
    714748        GlRenderer::SetupCamera(); 
    715749  else { 
    716         float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05; 
    717         Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x, 
    718                                                                                         -1, 
    719                                                                                         mViewDirection.y); 
    720          
    721         Vector3 target = mViewPoint + dist*mViewDirection; 
    722         Vector3 up(0,1,0); 
    723          
    724         glLoadIdentity(); 
    725         gluLookAt(pos.x, pos.y, pos.z, 
    726                           target.x, target.y, target.z, 
    727                           up.x, up.y, up.z); 
     750        if (0) { 
     751          float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05; 
     752          Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x, 
     753                                                                                          -1, 
     754                                                                                          mViewDirection.y); 
     755           
     756          Vector3 target = mViewPoint + dist*mViewDirection; 
     757          Vector3 up(0,1,0); 
     758           
     759          glLoadIdentity(); 
     760          gluLookAt(pos.x, pos.y, pos.z, 
     761                                target.x, target.y, target.z, 
     762                                up.x, up.y, up.z); 
     763        } else { 
     764          float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*mTopDistance; 
     765          Vector3 pos = mViewPoint  + dist*Vector3(0, 
     766                                                                                           1, 
     767                                                                                           0); 
     768           
     769          Vector3 target = mViewPoint; 
     770          Vector3 up(mViewDirection.x, 0, mViewDirection.z); 
     771           
     772          glLoadIdentity(); 
     773          gluLookAt(pos.x, pos.y, pos.z, 
     774                                target.x, target.y, target.z, 
     775                                up.x, up.y, up.z); 
     776           
     777        } 
    728778  } 
    729779 
     
    736786  case Qt::Key_T: 
    737787        mTopView = !mTopView; 
     788        SetupProjection(width(), height()); 
    738789        updateGL(); 
    739790        break; 
     
    746797        break; 
    747798  } 
    748    
     799} 
     800 
     801   
     802RendererControlWidget::RendererControlWidget(QWidget * parent, Qt::WFlags f): 
     803  QWidget(parent, f) 
     804{ 
     805 
     806  QVBoxLayout *vl = new QVBoxLayout; 
     807  setLayout(vl); 
     808   
     809  QWidget *vbox = new QGroupBox("ViewCells", this); 
     810  layout()->addWidget(vbox); 
     811   
     812  vl = new QVBoxLayout; 
     813  vbox->setLayout(vl); 
     814   
     815  QSlider *slider = new QSlider(Qt::Horizontal, vbox); 
     816  vl->addWidget(slider); 
     817  slider->show(); 
     818  slider->setRange(1, 10000); 
     819  slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 
     820  slider->setValue(500); 
     821 
     822  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int))); 
     823 
     824 
     825 
     826  QWidget *hbox = new QWidget(vbox); 
     827  vl->addWidget(hbox); 
     828  QHBoxLayout *hlayout = new QHBoxLayout; 
     829  hbox->setLayout(hlayout); 
     830   
     831  QCheckBox *cb = new QCheckBox("Show viewcells", hbox); 
     832  hlayout->addWidget(cb); 
     833  cb->setChecked(false); 
     834  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool))); 
     835 
     836  vbox->resize(800,100); 
     837 
     838   
     839  vbox = new QGroupBox("Rendering", this); 
     840  layout()->addWidget(vbox); 
     841   
     842  vl = new QVBoxLayout; 
     843  vbox->setLayout(vl); 
     844   
     845  slider = new QSlider(Qt::Horizontal, vbox); 
     846  vbox->layout()->addWidget(slider); 
     847  slider->show(); 
     848  slider->setRange(0, 1000); 
     849  slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 
     850  slider->setValue(1000); 
     851 
     852  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int))); 
     853 
     854 
     855  cb = new QCheckBox("Cut view cells", vbox); 
     856  vbox->layout()->addWidget(cb); 
     857  cb->setChecked(false); 
     858  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool))); 
     859 
     860  cb = new QCheckBox("Cut scene", vbox); 
     861  vbox->layout()->addWidget(cb); 
     862  cb->setChecked(false); 
     863  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool))); 
     864 
     865   
     866  slider = new QSlider(Qt::Horizontal, vbox); 
     867  vbox->layout()->addWidget(slider); 
     868  slider->show(); 
     869  slider->setRange(1, 1000); 
     870  slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 
     871  slider->setValue(500); 
     872   
     873  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int))); 
     874 
     875  cb = new QCheckBox("Top View", vbox); 
     876  vbox->layout()->addWidget(cb); 
     877  cb->setChecked(false); 
     878  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool))); 
     879   
     880 
     881  adjustSize(); 
    749882} 
    750883 
     
    761894  mTopView = false; 
    762895  mRenderViewCells = false; 
    763  
    764   QSlider *slider = new QSlider(this); 
    765   slider->show(); 
    766   slider->setRange(1, 10000); 
    767  
    768   connect(slider, SIGNAL(valueChanged(int)), this, SLOT(SetViewcellGranularity(int))); 
    769 } 
    770  
    771 void 
    772 GlRendererWidget::SetViewcellGranularity(int number) 
     896  mTopDistance = 1.0f; 
     897  mCutViewCells = false; 
     898  mCutScene = false; 
     899   
     900  RendererControlWidget *cw = new RendererControlWidget(NULL); 
     901  connect(cw, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int))); 
     902  connect(cw, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); 
     903  connect(cw, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int))); 
     904  connect(cw, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool))); 
     905  connect(cw, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool))); 
     906  connect(cw, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool))); 
     907  connect(cw, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool))); 
     908   
     909  cw->show(); 
     910} 
     911 
     912void 
     913GlRendererWidget::SetViewCellGranularity(int number) 
    773914{ 
    774915  mViewCellsManager->CollectViewCells(number); 
     
    777918 
    778919void 
     920GlRendererWidget::SetSceneCut(int number) 
     921{ 
     922  // assume the cut plane can only be aligned with xz plane 
     923  // shift it along y according to number, which is percentage of the bounding 
     924  // box position 
     925  if (mViewCellsManager) { 
     926        AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 
     927        Vector3 p = box.Min() + (number/1000.0f)*box.Max(); 
     928        mSceneCutPlane.mNormal = Vector3(0,-1,0); 
     929        mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p); 
     930        updateGL(); 
     931  } 
     932} 
     933 
     934void 
     935GlRendererWidget::SetTopDistance(int number) 
     936{ 
     937  mTopDistance = number/1000.0f; 
     938  updateGL(); 
     939} 
     940 
     941void 
    779942GlRendererWidget::RenderViewCells() 
    780943{ 
     
    782945 
    783946  SetupCamera(); 
    784   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    785  
     947  glEnable(GL_CULL_FACE); 
     948  glCullFace(GL_FRONT); 
     949  double eq[4]; 
     950  eq[0] = mSceneCutPlane.mNormal.x; 
     951  eq[1] = mSceneCutPlane.mNormal.y; 
     952  eq[2] = mSceneCutPlane.mNormal.z; 
     953  eq[3] = mSceneCutPlane.mD; 
     954 
     955  if (mCutViewCells) { 
     956        glClipPlane(GL_CLIP_PLANE0, eq); 
     957        glEnable(GL_CLIP_PLANE0); 
     958  } 
     959   
    786960  int i; 
    787961  ViewCellContainer &viewcells = mViewCellsManager->GetViewCells(); 
    788962  for (i=0; i < viewcells.size(); i++) { 
    789963        ViewCell *vc = viewcells[i]; 
    790         Mesh *m = vc->GetMesh(); 
    791         float r = RandomValue(0.5, 1.0); 
    792         float g = RandomValue(0.5, 1.0); 
    793         float b = RandomValue(0.5, 1.0); 
    794  
    795         glColor3f(r, g, b); 
    796         //SetupMaterial(m->mMaterial); 
    797  
     964        //      Mesh *m = vc->GetMesh(); 
     965        RgbColor c = vc->GetColor(); 
     966        glColor3f(c.r, c.g, c.b); 
    798967        RenderViewCell(vc); 
    799968  } 
     969 
     970  glDisable(GL_CLIP_PLANE0); 
    800971 
    801972} 
Note: See TracChangeset for help on using the changeset viewer.