Ignore:
Timestamp:
04/11/06 15:33:37 (18 years ago)
Author:
bittner
Message:

visualization of the render cost and pvs sizes for viewcells

File:
1 edited

Legend:

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

    r713 r746  
    5454  mWireFrame = false; 
    5555  environment->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace); 
    56   mSnapErrorFrames = false; 
    57   mSnapPrefix = ""; 
    58  
     56  mSnapErrorFrames = true; 
     57  mSnapPrefix = "snap/"; 
     58  mUseForcedColors = false; 
    5959} 
    6060 
     
    162162  int i = 0; 
    163163 
    164   if (!mUseFalseColors) 
     164  if (!mUseFalseColors && !mUseForcedColors) 
    165165        SetupMaterial(mesh->mMaterial); 
    166166   
     
    202202        wglGetProcAddress("glGetOcclusionQueryuivNV"); 
    203203 
    204         glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 
    205  
     204 
     205 
     206#if 0 
     207  GLfloat mat_ambient[]   = {  0.5, 0.5, 0.5, 1.0  }; 
     208  /*  mat_specular and mat_shininess are NOT default values     */ 
     209  GLfloat mat_diffuse[]   = {  1.0, 1.0, 1.0, 1.0  }; 
     210  GLfloat mat_specular[]  = {  0.3, 0.3, 0.3, 1.0  }; 
     211  GLfloat mat_shininess[] = {  1.0  }; 
     212   
     213  GLfloat light_ambient[]  = {  0.2, 0.2, 0.2, 1.0  }; 
     214  GLfloat light_diffuse[]  = {  0.4, 0.4, 0.4, 1.0  }; 
     215  GLfloat light_specular[] = {  0.3, 0.3, 0.3, 1.0  }; 
     216   
     217  GLfloat lmodel_ambient[] = {  0.3, 0.3, 0.3, 1.0  }; 
     218   
     219   
     220  // default Material 
     221  glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); 
     222  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); 
     223  glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 
     224  glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); 
     225 
     226  // a light 
     227  glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); 
     228  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); 
     229  glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); 
     230   
     231  glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); 
     232  glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); 
     233  glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); 
     234   
     235  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); 
     236   
     237  glEnable(GL_LIGHTING); 
     238  glEnable(GL_LIGHT0); 
     239  glEnable(GL_LIGHT1); 
     240   
     241   
     242  // set position of the light 
     243  GLfloat infinite_light[] = {  1.0, 0.8, 1.0, 0.0  }; 
     244  glLightfv (GL_LIGHT0, GL_POSITION, infinite_light); 
     245   
     246  // set position of the light2 
     247  GLfloat infinite_light2[] = {  -0.3, 1.5, 1.0, 0.0  }; 
     248  glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2); 
     249   
     250  glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 
     251  //   glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR); 
     252  glEnable(GL_COLOR_MATERIAL); 
     253   
     254  glShadeModel( GL_FLAT ); 
     255   
     256  glDepthFunc( GL_LESS ); 
     257  glEnable( GL_DEPTH_TEST ); 
     258#endif 
     259 
     260  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); 
     261 
     262  glEnable( GL_NORMALIZE ); 
     263   
     264  glClearColor(0.0f, 0.0f, 1.0f, 1.0f); 
    206265} 
    207266 
     
    213272  if (mViewCellsManager) 
    214273        vc = mViewCellsManager->GetViewCells().size(); 
    215   s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f) viewcells:%04d", 
     274  int filter = 0; 
     275  if (mViewCellsManager) 
     276        filter = mViewCellsManager->GetMaxFilterSize(); 
     277 
     278  s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f) viewcells:%04d filter:%04d pvs:%04d error:%5.5f\%", 
    216279                        mFrame, 
    217280                        mViewPoint.x, 
     
    221284                        mViewDirection.y, 
    222285                        mViewDirection.z, 
    223                         vc 
     286                        vc, 
     287 
     288                        filter, 
     289                        mPvsSize, 
     290                        mRenderError*100.0f 
    224291                        ); 
     292   
     293  glColor3f(0.0f,0.0f,0.0f); 
    225294  renderText(0,20,s); 
     295   
     296  if (mShowRenderCost) { 
     297        static vector<float> costFunction; 
     298        static float maxCost = -1; 
     299        if (costFunction.size()==0) { 
     300          ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree(); 
     301          if (tree) { 
     302                tree->GetCostFunction(costFunction); 
     303                maxCost = -1; 
     304                for (int i=0;  i < costFunction.size(); i++) { 
     305                  //              cout<<i<<":"<<costFunction[i]<<" "; 
     306                  if (costFunction[i] > maxCost) 
     307                        maxCost = costFunction[i]; 
     308                } 
     309          } 
     310        } 
     311 
     312         
     313        int currentPos = mViewCellsManager->GetViewCells().size(); 
     314        float currentCost=-1; 
     315 
     316        if (currentPos < costFunction.size()) 
     317          currentCost = costFunction[currentPos]; 
     318#if 0    
     319        cout<<"costFunction.size()="<<costFunction.size()<<endl; 
     320        cout<<"CP="<<currentPos<<endl; 
     321        cout<<"MC="<<maxCost<<endl; 
     322        cout<<"CC="<<currentCost<<endl; 
     323#endif 
     324        if (costFunction.size()) { 
     325          glDisable(GL_DEPTH_TEST); 
     326          // init ortographic projection 
     327          glMatrixMode(GL_PROJECTION); 
     328          glPushMatrix(); 
     329           
     330          glLoadIdentity(); 
     331          gluOrtho2D(0, 1.0f, 0, 1.0f); 
     332           
     333          glTranslatef(0.1f, 0.1f, 0.0f); 
     334          glScalef(0.8f, 0.8f, 1.0f); 
     335          glMatrixMode(GL_MODELVIEW); 
     336          glLoadIdentity(); 
     337           
     338          glColor3f(1.0f,0,0); 
     339          glBegin(GL_LINE_STRIP); 
     340          //      glVertex3f(0,0,0); 
     341           
     342          for (int i=0;  i < costFunction.size(); i++) { 
     343                float x =  i/(float)costFunction.size(); 
     344                float y = costFunction[i]/(maxCost*0.5f); 
     345                glVertex3f(x,y,0.0f); 
     346          } 
     347          glEnd(); 
     348           
     349          glColor3f(1.0f,0,0); 
     350          glBegin(GL_LINES); 
     351          float x =  currentPos/(float)costFunction.size(); 
     352          glVertex3f(x,0.0,0.0f); 
     353          glVertex3f(x,1.0f,0.0f); 
     354          glEnd(); 
     355           
     356          glColor3f(0.0f,0,0); 
     357          // show a grid 
     358          glBegin(GL_LINE_LOOP); 
     359          glVertex3f(0,0,0.0f); 
     360          glVertex3f(1,0,0.0f); 
     361          glVertex3f(1,1,0.0f); 
     362          glVertex3f(0,1,0.0f); 
     363          glEnd(); 
     364 
     365          glBegin(GL_LINES); 
     366          for (int i=0;  i < 50000 && i < costFunction.size(); i+=10000) { 
     367                float x =  i/(float)costFunction.size(); 
     368                glVertex3f(x,0.0,0.0f); 
     369                glVertex3f(x,1.0f,0.0f); 
     370          } 
     371 
     372          for (int i=0;  i < maxCost; i+=100) { 
     373                float y = i/(maxCost*0.5f); 
     374                glVertex3f(0,y,0.0f); 
     375                glVertex3f(1,y,0.0f); 
     376          } 
     377 
     378          glEnd(); 
     379 
     380           
     381          // restore the projection matrix 
     382          glMatrixMode(GL_PROJECTION); 
     383          glPopMatrix(); 
     384          glMatrixMode(GL_MODELVIEW); 
     385          glEnable(GL_DEPTH_TEST); 
     386 
     387        } 
     388  } 
    226389} 
    227390 
     
    365528 
    366529        glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); 
    367  
     530         
    368531        // Render PVS 
    369532        std::map<Intersectable *, 
     
    467630} 
    468631 
     632void 
     633GlRendererWidget::RenderPvs() 
     634{ 
     635  SetupCamera(); 
     636  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     637   
     638  ViewCell *viewcell; 
     639  //  viewcell = mViewCellsManager->GetViewCell(mViewPoint); 
     640 
     641  PrVs prvs; 
     642  //  mViewCellsManager->SetMaxFilterSize(1); 
     643  mViewCellsManager->GetPrVS(mViewPoint, prvs); 
     644  viewcell = prvs.mViewCell; 
     645   
     646  if (viewcell) { 
     647        ObjectPvs &pvs = viewcell->GetPvs(); 
     648 
     649        // read back the texture 
     650        std::map<Intersectable *, 
     651          PvsData<Intersectable *>, 
     652          LtSample<Intersectable *> >::const_iterator it = pvs.mEntries.begin(); 
     653 
     654        mPvsSize = pvs.mEntries.size(); 
     655           
     656        for (; it != pvs.mEntries.end(); ++ it) { 
     657          Intersectable *object = (*it).first; 
     658          float visibility = log10((*it).second.mSumPdf + 1)/5.0f; 
     659          glColor3f(visibility, 0.0f, 0.0f); 
     660          mUseForcedColors = true; 
     661          RenderIntersectable(object); 
     662          mUseForcedColors = false; 
     663        } 
     664 
     665        if (mRenderFilter) { 
     666          mWireFrame = true; 
     667          RenderIntersectable(viewcell); 
     668          mWireFrame = false; 
     669        } 
     670        mViewCellsManager->DeleteLocalMergeTree(viewcell); 
     671  } else { 
     672        ObjectContainer::const_iterator oi = mObjects.begin(); 
     673        for (; oi != mObjects.end(); oi++) 
     674          RenderIntersectable(*oi); 
     675  } 
     676} 
     677 
    469678float 
    470679GlRendererWidget::RenderErrors() 
     
    520729          PvsData<Intersectable *>, 
    521730          LtSample<Intersectable *> >::const_iterator it = viewcell->GetPvs().mEntries.begin(); 
    522          
     731 
     732        mPvsSize = viewcell->GetPvs().mEntries.size(); 
     733 
    523734        for (; it != viewcell->GetPvs().mEntries.end(); ++ it) { 
    524735          Intersectable *object = (*it).first; 
     
    540751                  diff.setPixel(x, y, qRgba(255,128,128,255)); 
    541752                  errorPixels++; 
    542                    
    543753                } 
    544754        pErrorPixels = ((float)errorPixels)/(im1.height()*im1.width()); 
     
    556766  // now render im1 
    557767  if (viewcell) { 
    558         if (1 || mTopView) { 
     768        if (0 && mTopView) { 
    559769          mWireFrame = true; 
    560770          RenderIntersectable(viewcell); 
     
    608818        mViewCellsManager->DeleteLocalMergeTree(viewcell); 
    609819 
     820  mRenderError = pErrorPixels; 
    610821  return pErrorPixels; 
    611822} 
     
    673884          mPvsErrorBuffer[i].mPvsSize = pvsSize; 
    674885 
     886          emit UpdatePvsErrorItem(i, 
     887                                                          mPvsErrorBuffer[i]); 
     888           
    675889          cout<<"("<<i<<","<<mPvsErrorBuffer[i].mError<<")"; 
    676890          //      swapBuffers(); 
     
    762976   
    763977  if (!mRenderViewCells) { 
    764         RenderErrors(); 
     978        if (mRenderErrors) 
     979          RenderErrors(); 
     980        else 
     981          RenderPvs(); 
    765982        RenderInfo(); 
    766983  } else { 
    767984        RenderViewCells(); 
    768  
     985         
    769986        mWireFrame = true; 
    770987        RenderScene(); 
    771988        mWireFrame = false; 
     989         
    772990        RenderInfo(); 
    773991  } 
     
    8541072  vl->addWidget(slider); 
    8551073  slider->show(); 
    856   slider->setRange(1, 200); 
     1074  slider->setRange(1, 10000); 
    8571075  slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 
    8581076  slider->setValue(200); 
     
    8841102  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool))); 
    8851103 
     1104  cb = new QCheckBox("Show render cost", hbox); 
     1105  hlayout->addWidget(cb); 
     1106  cb->setChecked(false); 
     1107  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool))); 
     1108 
     1109  cb = new QCheckBox("Show pvs sizes", hbox); 
     1110  hlayout->addWidget(cb); 
     1111  cb->setChecked(false); 
     1112  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool))); 
     1113 
    8861114  vbox->resize(800,100); 
    8871115 
     
    8921120  vl = new QVBoxLayout; 
    8931121  vbox->setLayout(vl); 
    894    
     1122 
     1123 
     1124 
    8951125  slider = new QSlider(Qt::Horizontal, vbox); 
    8961126  vbox->layout()->addWidget(slider); 
     
    9021132  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int))); 
    9031133 
     1134  cb = new QCheckBox("Render errors", vbox); 
     1135  vbox->layout()->addWidget(cb); 
     1136  cb->setChecked(true); 
     1137  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool))); 
     1138 
     1139  cb = new QCheckBox("Render filter", vbox); 
     1140  vbox->layout()->addWidget(cb); 
     1141  cb->setChecked(true); 
     1142  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool))); 
    9041143 
    9051144  cb = new QCheckBox("Cut view cells", vbox); 
     
    9221161   
    9231162  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int))); 
    924  
    925  
    926  
    9271163   
    9281164  cb = new QCheckBox("Top View", vbox); 
     
    9301166  cb->setChecked(false); 
    9311167  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool))); 
    932    
     1168 
     1169  vbox = new QGroupBox("PVS Errors", this); 
     1170  layout()->addWidget(vbox); 
     1171 
     1172  vl = new QVBoxLayout; 
     1173  vbox->setLayout(vl); 
     1174 
     1175  mPvsErrorWidget = new QListWidget(vbox); 
     1176  vbox->layout()->addWidget(mPvsErrorWidget); 
     1177   
     1178  connect(mPvsErrorWidget, 
     1179                  SIGNAL(doubleClicked(const QModelIndex &)), 
     1180                  this, 
     1181                  SLOT(PvsErrorClicked(const QModelIndex &))); 
     1182   
     1183  QPushButton *button = new QPushButton("Next Error Frame", vbox); 
     1184  vbox->layout()->addWidget(button); 
     1185  connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void))); 
     1186 
    9331187  setWindowTitle("Preprocessor Control Widget"); 
    9341188  adjustSize(); 
     1189} 
     1190 
     1191 
     1192 
     1193void 
     1194RendererControlWidget::FocusNextPvsErrorFrame(void) 
     1195{ 
     1196   
     1197   
     1198} 
     1199 
     1200void 
     1201RendererControlWidget::UpdatePvsErrorItem(int row, 
     1202                                                                                  GlRendererBuffer::PvsErrorEntry &pvsErrorEntry) 
     1203{ 
     1204 
     1205  QListWidgetItem *i = mPvsErrorWidget->item(row); 
     1206  QString s; 
     1207  s.sprintf("%5.5f", pvsErrorEntry.mError); 
     1208  if (i) { 
     1209        i->setText(s); 
     1210  } else { 
     1211        new QListWidgetItem(s, mPvsErrorWidget); 
     1212  } 
     1213  mPvsErrorWidget->update(); 
    9351214} 
    9361215 
     
    9501229  mCutViewCells = false; 
    9511230  mCutScene = false; 
    952    
    953   RendererControlWidget *cw = new RendererControlWidget(NULL); 
    954   connect(cw, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int))); 
    955   connect(cw, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); 
    956   connect(cw, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int))); 
    957  
    958   //connect(cw, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetMaxFilterSize(int))); 
    959   //  connect(cw, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int))); 
    960   //connect(cw, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetViewCellGranularity(int))); 
    961  
    962   connect(cw, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool))); 
    963   connect(cw, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool))); 
    964   connect(cw, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool))); 
    965   connect(cw, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool))); 
    966    
    967   cw->show(); 
     1231  mRenderErrors = true; 
     1232  mRenderFilter = true; 
     1233  mShowRenderCost = false; 
     1234  mShowPvsSizes = false; 
     1235 
     1236  mPvsSize = 0; 
     1237  mRenderError = 0.0f; 
     1238  mControlWidget = new RendererControlWidget(NULL); 
     1239   
     1240  connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int))); 
     1241  connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); 
     1242  connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int))); 
     1243 
     1244  connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int))); 
     1245 
     1246  connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool))); 
     1247  connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool))); 
     1248  connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool))); 
     1249  connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool))); 
     1250  connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool))); 
     1251  connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool))); 
     1252  connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool))); 
     1253  connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool))); 
     1254 
     1255   
     1256  mControlWidget->show(); 
    9681257} 
    9691258 
     
    9721261{ 
    9731262  if (mViewCellsManager)  
    974         mViewCellsManager->SetMaxFilterSize(number); 
    975   //  mViewCellsManager->CollectViewCells(number); 
     1263        //      mViewCellsManager->SetMaxFilterSize(number); 
     1264    mViewCellsManager->CollectViewCells(number); 
    9761265  updateGL(); 
    9771266} 
     
    10291318  int i; 
    10301319  ViewCellContainer &viewcells = mViewCellsManager->GetViewCells(); 
     1320  int maxPvs = -1; 
     1321  for (i=0; i < viewcells.size(); i++) { 
     1322        ViewCell *vc = viewcells[i]; 
     1323        int p = vc->GetPvs().GetSize(); 
     1324        if (p > maxPvs) 
     1325          maxPvs = p; 
     1326  } 
     1327 
     1328 
    10311329  for (i=0; i < viewcells.size(); i++) { 
    10321330        ViewCell *vc = viewcells[i]; 
    10331331        //      Mesh *m = vc->GetMesh(); 
    1034         RgbColor c = vc->GetColor(); 
     1332 
     1333 
     1334        RgbColor c; 
     1335 
     1336        if (!mShowPvsSizes)  
     1337          c = vc->GetColor(); 
     1338        else { 
     1339          float importance = (float)vc->GetPvs().GetSize() / (float)maxPvs; 
     1340          c = RgbColor(importance, 1.0f - importance, 0.0f); 
     1341        } 
    10351342        glColor3f(c.r, c.g, c.b); 
     1343         
    10361344        RenderViewCell(vc); 
    10371345  } 
Note: See TracChangeset for help on using the changeset viewer.