Changeset 1931


Ignore:
Timestamp:
01/02/07 16:12:46 (17 years ago)
Author:
bittner
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
2 added
14 edited

Legend:

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

    r1900 r1931  
    108108        if (!mMixtureDistribution->RequiresRays()) 
    109109          CLEAR_CONTAINER(vssRays); 
     110 
     111        if (renderer) { 
     112          ComputeRenderError(); 
     113        } 
     114         
    110115  } 
    111116   
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r1925 r1931  
    8484  mUseForcedColors = false; 
    8585  mRenderBoxes = false; 
    86   //  mUseGlLists = true; 
    87   mUseGlLists = false; 
     86  mUseGlLists = true; 
     87  //mUseGlLists = false; 
     88 
     89  Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames); 
     90  mPvsErrorBuffer.resize(mPvsStatFrames); 
     91  ClearErrorBuffer(); 
     92   
    8893} 
    8994 
     
    466471GlRenderer(sceneGraph, viewcells, tree)   
    467472{ 
    468   Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames); 
    469   mPvsErrorBuffer.resize(mPvsStatFrames); 
    470   ClearErrorBuffer(); 
    471473   
    472474  mPixelBuffer = NULL; 
     
    572574 
    573575void 
    574 GlRendererBuffer::RandomViewPoint() 
     576GlRenderer::RandomViewPoint() 
    575577{  
    576578  // do not use this function since it could return different viewpoints for 
     
    858860 
    859861void 
    860 GlRendererBuffer::ClearErrorBuffer() 
     862GlRenderer::ClearErrorBuffer() 
    861863{ 
    862864  for (int i=0; i < mPvsStatFrames; i++) { 
     
    869871GlRendererBuffer::EvalPvsStat() 
    870872{ 
    871   mPvsStat.Reset(); 
    872   halton.Reset(); 
    873873 
    874874  MakeCurrent(); 
    875875 
    876   SetupProjection(GetWidth(), GetHeight()); 
    877  
    878   cout<<"mPvsStatFrames="<<mPvsStatFrames<<endl; 
    879    
    880   for (int i=0; i < mPvsStatFrames; i++) { 
    881         float err; 
    882         // set frame id for saving the error buffer 
    883         mFrame = i; 
    884         RandomViewPoint(); 
    885  
    886         // atlanta problematic frames: 325 525 691 1543 
    887 #if 0 
    888         if (mFrame != 325 && 
    889                 mFrame != 525 && 
    890                 mFrame != 691 && 
    891                 mFrame != 1543) 
    892           mPvsErrorBuffer[i] = -1; 
    893         else { 
    894           Debug<<"frame ="<<mFrame<<" vp="<<mViewPoint<<" vd="<<mViewDirection<<endl; 
    895         } 
    896 #endif 
    897          
    898         if (mPvsErrorBuffer[i].mError > 0.0f) { 
    899           int pvsSize; 
    900  
    901  
    902           float error = GetPixelError(pvsSize); 
    903           mPvsErrorBuffer[i].mError = error; 
    904           mPvsErrorBuffer[i].mPvsSize = pvsSize; 
    905  
    906           //      emit UpdatePvsErrorItem(i, 
    907           //                                                      mPvsErrorBuffer[i]); 
    908  
    909           cout<<"("<<i<<","<<mPvsErrorBuffer[i].mError<<")"; 
    910           //      swapBuffers(); 
    911         } 
    912          
    913         err = mPvsErrorBuffer[i].mError; 
    914          
    915         if (err >= 0.0f) { 
    916           if (err > mPvsStat.maxError) 
    917                 mPvsStat.maxError = err; 
    918           mPvsStat.sumError += err; 
    919           mPvsStat.sumPvsSize += mPvsErrorBuffer[i].mPvsSize; 
    920            
    921           if (err == 0.0f) 
    922                 mPvsStat.errorFreeFrames++; 
    923           mPvsStat.frames++; 
    924         } 
    925   } 
    926  
    927   glFinish(); 
     876  GlRenderer::EvalPvsStat(); 
     877   
    928878  DoneCurrent(); 
    929  
    930   cout<<endl<<flush; 
     879   
    931880  //  mRenderingFinished.wakeAll(); 
    932881} 
     
    13631312 
    13641313 
    1365  
    1366  
    1367  
    1368  
    1369  
    1370  
    1371  
    1372  
    1373  
    1374  
    1375 } 
     1314void 
     1315GlRenderer::EvalPvsStat() 
     1316{ 
     1317 
     1318  mPvsStat.Reset(); 
     1319  halton.Reset(); 
     1320 
     1321 
     1322  SetupProjection(GetWidth(), GetHeight()); 
     1323 
     1324  cout<<"mPvsStatFrames="<<mPvsStatFrames<<endl; 
     1325   
     1326  for (int i=0; i < mPvsStatFrames; i++) { 
     1327        float err; 
     1328        // set frame id for saving the error buffer 
     1329        mFrame = i; 
     1330        RandomViewPoint(); 
     1331 
     1332        // atlanta problematic frames: 325 525 691 1543 
     1333#if 0 
     1334        if (mFrame != 325 && 
     1335                mFrame != 525 && 
     1336                mFrame != 691 && 
     1337                mFrame != 1543) 
     1338          mPvsErrorBuffer[i] = -1; 
     1339        else { 
     1340          Debug<<"frame ="<<mFrame<<" vp="<<mViewPoint<<" vd="<<mViewDirection<<endl; 
     1341        } 
     1342#endif 
     1343         
     1344        if (mPvsErrorBuffer[i].mError > 0.0f) { 
     1345          int pvsSize; 
     1346 
     1347 
     1348          float error = GetPixelError(pvsSize); 
     1349          mPvsErrorBuffer[i].mError = error; 
     1350          mPvsErrorBuffer[i].mPvsSize = pvsSize; 
     1351 
     1352          //      emit UpdatePvsErrorItem(i, 
     1353          //                                                      mPvsErrorBuffer[i]); 
     1354 
     1355          cout<<"("<<i<<","<<mPvsErrorBuffer[i].mError<<")"; 
     1356          //      swapBuffers(); 
     1357        } 
     1358         
     1359        err = mPvsErrorBuffer[i].mError; 
     1360         
     1361        if (err >= 0.0f) { 
     1362          if (err > mPvsStat.maxError) 
     1363                mPvsStat.maxError = err; 
     1364          mPvsStat.sumError += err; 
     1365          mPvsStat.sumPvsSize += mPvsErrorBuffer[i].mPvsSize; 
     1366           
     1367          if (err == 0.0f) 
     1368                mPvsStat.errorFreeFrames++; 
     1369          mPvsStat.frames++; 
     1370        } 
     1371  } 
     1372 
     1373  glFinish(); 
     1374  cout<<endl<<flush; 
     1375 
     1376} 
     1377 
     1378 
     1379float 
     1380GlRenderer::GetPixelError(int &pvsSize) 
     1381{ 
     1382  float pErrorPixels = -1.0f; 
     1383   
     1384  glReadBuffer(GL_BACK); 
     1385   
     1386  //  mUseFalseColors = true; 
     1387   
     1388  mUseFalseColors = false; 
     1389  unsigned int pixelCount; 
     1390 
     1391  //static int query = -1; 
     1392  //if (query == -1) 
     1393  //      glGenOcclusionQueriesNV(1, (unsigned int *)&query); 
     1394 
     1395  OcclusionQuery query; 
     1396 
     1397  ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint); 
     1398  if (viewcell == NULL) 
     1399        return 0.0f; 
     1400 
     1401  if (mDetectEmptyViewSpace) { 
     1402        // now check whether any backfacing polygon would pass the depth test 
     1403        SetupCamera(); 
     1404        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     1405        glEnable( GL_CULL_FACE ); 
     1406        glCullFace(GL_BACK); 
     1407 
     1408        cout<<"RS "; 
     1409        RenderScene(); 
     1410         
     1411        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
     1412        glDepthMask(GL_FALSE); 
     1413        glDisable( GL_CULL_FACE ); 
     1414 
     1415        query.BeginQuery(); 
     1416         
     1417        cout<<"RS "; 
     1418        RenderScene(); 
     1419        cout<<"RS3 "; 
     1420         
     1421        query.EndQuery(); 
     1422         
     1423        // at this point, if possible, go and do some other computation 
     1424        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     1425        glDepthMask(GL_TRUE); 
     1426        glEnable( GL_CULL_FACE ); 
     1427         
     1428        // reenable other state 
     1429        pixelCount = query.GetQueryResult(); 
     1430        cout<<"RS4 "; 
     1431         
     1432        if (pixelCount > 0) 
     1433          return -1.0f; // backfacing polygon found -> not a valid viewspace sample 
     1434 
     1435  } else 
     1436        glDisable( GL_CULL_FACE ); 
     1437         
     1438 
     1439  //  ViewCell *viewcell = NULL; 
     1440   
     1441  //  PrVs prvs; 
     1442   
     1443  //  mViewCellsManager->SetMaxFilterSize(0); 
     1444  //  mViewCellsManager->GetPrVS(mViewPoint, prvs, mViewCellsManager->GetFilterWidth()); 
     1445  //  viewcell = prvs.mViewCell; 
     1446   
     1447  ObjectPvs pvs; 
     1448  if (1) { 
     1449        pvs = viewcell->GetPvs(); 
     1450  } else { 
     1451        mViewCellsManager->ApplyFilter2(viewcell, 
     1452                                                                        false, 
     1453                                                                        1.0f, 
     1454                                                                        pvs); 
     1455  } 
     1456   
     1457  SetupCamera(); 
     1458  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     1459  glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); 
     1460   
     1461   
     1462  //    // Render PVS 
     1463  ObjectPvsIterator it = pvs.GetIterator(); 
     1464   
     1465  pvsSize = pvs.GetSize(); 
     1466  Intersectable::NewMail(); 
     1467  for (; it.HasMoreEntries(); ) { 
     1468        ObjectPvsEntry entry = it.Next(); 
     1469        Intersectable *object = entry.mObject; 
     1470        RenderIntersectable(object); 
     1471  } 
     1472   
     1473  //    glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); 
     1474  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     1475   
     1476  mUseFalseColors = true; 
     1477   
     1478  query.BeginQuery(); 
     1479   
     1480  SetupCamera(); 
     1481   
     1482  RenderScene(); 
     1483   
     1484  query.EndQuery(); 
     1485   
     1486   
     1487  // reenable other state 
     1488  pixelCount = query.GetQueryResult(); 
     1489   
     1490   
     1491  pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight()); 
     1492 
     1493#if 0   
     1494  if (mSnapErrorFrames && pErrorPixels > 0.001f) { 
     1495         
     1496        char filename[256]; 
     1497        sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels); 
     1498        QImage im = toImage(); 
     1499        string str = mSnapPrefix + filename; 
     1500        QString qstr(str.c_str()); 
     1501         
     1502        im.save(qstr, "PNG"); 
     1503        if (1) { //0 && mFrame == 1543) { 
     1504          int x,y; 
     1505          int lastIndex = -1; 
     1506          for (y=0; y < im.height(); y++) 
     1507                for (x=0; x < im.width(); x++) { 
     1508                  QRgb p = im.pixel(x,y); 
     1509                  int index = qRed(p) + (qGreen(p)<<8) + (qBlue(p)<<16); 
     1510                  if (qGreen(p) != 255 && index!=0) { 
     1511                        if (index != lastIndex) { 
     1512                          //                            Debug<<"ei="<<index<<" "; 
     1513                          lastIndex = index; 
     1514                        } 
     1515                  } 
     1516                } 
     1517        } 
     1518         
     1519         
     1520        mUseFalseColors = false; 
     1521        glPushAttrib(GL_CURRENT_BIT); 
     1522        glColor3f(0,1,0); 
     1523        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     1524        SetupCamera(); 
     1525        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     1526         
     1527        // Render PVS 
     1528        Intersectable::NewMail(); 
     1529 
     1530        ObjectPvsIterator it = pvs.GetIterator(); 
     1531        for (; it.HasMoreEntries(); ) { 
     1532          ObjectPvsEntry entry = it.Next(); 
     1533          Intersectable *object = entry.mObject; 
     1534          RenderIntersectable(object); 
     1535        } 
     1536         
     1537        im = toImage(); 
     1538        sprintf(filename, "error-frame-%04d-%0.5f-pvs.png", mFrame, pErrorPixels); 
     1539        str = mSnapPrefix + filename; 
     1540        qstr = str.c_str(); 
     1541        im.save(qstr, "PNG"); 
     1542        glPopAttrib(); 
     1543  } 
     1544#endif 
     1545   
     1546  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     1547   
     1548  return pErrorPixels; 
     1549} 
     1550 
     1551 
     1552 
     1553 
     1554 
     1555 
     1556 
     1557} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h

    r1832 r1931  
    104104 
    105105 
     106  virtual void RandomViewPoint(); 
     107 
    106108  void SetupFalseColor(const int id); 
    107109  void RenderIntersectable(Intersectable *); 
     
    139141 
    140142   
    141    
     143  virtual float 
     144  GetPixelError(int &pvsSize); 
     145   
     146  virtual void 
     147  EvalPvsStat(); 
    142148 
    143149  void InitGL(); 
     
    154160  inline void SetSnapPrefix(const string &pref) { mSnapPrefix = pref; } 
    155161 
     162  virtual void ClearErrorBuffer(); 
     163   
     164 
    156165public: 
    157166  int mFrame; 
    158167  bool mWireFrame; 
    159          
     168 
     169  PvsRenderStatistics mPvsStat; 
     170   
     171  int mPvsStatFrames; 
     172  struct PvsErrorEntry { 
     173          PvsErrorEntry() {} 
     174          float mError; 
     175          int mPvsSize; 
     176          Vector3 mPosition; 
     177          Vector3 mDirection; 
     178  }; 
     179 
    160180protected: 
    161181 
    162         PvsCache mPvsCache; 
     182   
     183  vector<PvsErrorEntry> mPvsErrorBuffer; 
     184 
     185  PvsCache mPvsCache; 
    163186 
    164187  vector<OcclusionQuery *> mOcclusionQueries; 
     
    231254  virtual void EvalPvsStat(); 
    232255 
    233   virtual void ClearErrorBuffer(); 
    234    
    235256 
    236257  virtual int GetWidth() const = 0; 
     
    241262   
    242263 
    243   virtual void RandomViewPoint(); 
    244264  virtual void SampleBeamContributions( 
    245265                                                           Intersectable *sourceObject, 
     
    266286  virtual int ComputePvs() const = 0; 
    267287 
    268   virtual float 
    269   GetPixelError(int &pvsSize) = 0; 
    270288   
    271289  virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0; 
    272    
    273   PvsRenderStatistics mPvsStat; 
    274     
    275   int mPvsStatFrames; 
    276   struct PvsErrorEntry { 
    277           PvsErrorEntry() {} 
    278           float mError; 
    279           int mPvsSize; 
    280           Vector3 mPosition; 
    281           Vector3 mDirection; 
    282   }; 
    283    
    284   vector<PvsErrorEntry> mPvsErrorBuffer; 
     290 
     291 
    285292 
    286293   
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r1900 r1931  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: ?t 14. XII 10:54:14 2006 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: út 2. I 10:32:48 2007 
    44# Project:  preprocessor.pro 
    55# Template: app 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1926 r1931  
    12701270} 
    12711271 
    1272 } 
     1272void 
     1273Preprocessor::ComputeRenderError() 
     1274{ 
     1275  // compute rendering error 
     1276         
     1277  if (renderer && renderer->mPvsStatFrames) { 
     1278        //      emit EvalPvsStat(); 
     1279        //      QMutex mutex; 
     1280        //      mutex.lock(); 
     1281        //      renderer->mRenderingFinished.wait(&mutex); 
     1282        //      mutex.unlock(); 
     1283         
     1284        renderer->EvalPvsStat(); 
     1285 
     1286        mStats << 
     1287          "#AvgPvsRenderError\n" <<renderer->mPvsStat.GetAvgError()<<endl<< 
     1288          "#MaxPvsRenderError\n" <<renderer->mPvsStat.GetMaxError()<<endl<< 
     1289          "#ErrorFreeFrames\n" <<renderer->mPvsStat.GetErrorFreeFrames()<<endl<< 
     1290          "#AvgRenderPvs\n" <<renderer->mPvsStat.GetAvgPvs()<<endl; 
     1291  } 
     1292} 
     1293 
     1294} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1926 r1931  
    146146                const bool pruneInvalidRays = true); 
    147147 
     148  /** Compute pixel error of the current PVS solution by sampling given number of viewpoints */ 
     149  virtual void 
     150  ComputeRenderError(); 
     151 
    148152        /** Returns a view cells manager of the given name. 
    149153        */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp

    r1877 r1931  
    102102  OcclusionQuery query; 
    103103 
     104  ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint); 
     105  if (viewcell == NULL) 
     106        return 0.0f; 
     107 
    104108  if (mDetectEmptyViewSpace) { 
    105109        // now check whether any backfacing polygon would pass the depth test 
     
    108112        glEnable( GL_CULL_FACE ); 
    109113        glCullFace(GL_BACK); 
    110          
     114 
     115        cout<<"RS "; 
    111116        RenderScene(); 
    112117         
     
    117122        query.BeginQuery(); 
    118123         
     124        cout<<"RS "; 
    119125        RenderScene(); 
     126        cout<<"RS3 "; 
    120127         
    121128        query.EndQuery(); 
     
    128135        // reenable other state 
    129136        pixelCount = query.GetQueryResult(); 
     137        cout<<"RS4 "; 
    130138         
    131139        if (pixelCount > 0) 
     
    145153   
    146154  ObjectPvs pvs; 
    147   ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint); 
    148          
    149   if (viewcell) { 
     155  if (1) { 
     156        pvs = viewcell->GetPvs(); 
     157  } else { 
    150158        mViewCellsManager->ApplyFilter2(viewcell, 
    151159                                                                        false, 
    152160                                                                        1.0f, 
    153161                                                                        pvs); 
    154          
    155         pvsSize = 0; 
    156         SetupCamera(); 
    157         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    158         glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); 
    159                  
    160            
    161                 //      // Render PVS 
    162                 ObjectPvsIterator it = pvs.GetIterator(); 
    163                  
    164                 pvsSize = pvs.GetSize(); 
    165                 Intersectable::NewMail(); 
    166         for (; it.HasMoreEntries(); ) { 
    167           ObjectPvsEntry entry = it.Next(); 
    168           Intersectable *object = entry.mObject; 
    169           RenderIntersectable(object); 
    170         } 
    171          
    172         //      glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); 
    173         glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    174          
    175          
    176         mUseFalseColors = true; 
    177          
    178         query.BeginQuery(); 
    179          
    180         SetupCamera(); 
    181          
    182         RenderScene(); 
    183          
    184         query.EndQuery(); 
    185          
    186          
    187         unsigned int pixelCount; 
    188         // reenable other state 
    189         pixelCount = query.GetQueryResult(); 
    190          
    191          
    192         pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight()); 
    193   } else 
    194         pErrorPixels = 0.0f; 
     162  } 
     163   
     164  SetupCamera(); 
     165  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     166  glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); 
     167   
     168   
     169  //    // Render PVS 
     170  ObjectPvsIterator it = pvs.GetIterator(); 
     171   
     172  pvsSize = pvs.GetSize(); 
     173  Intersectable::NewMail(); 
     174  for (; it.HasMoreEntries(); ) { 
     175        ObjectPvsEntry entry = it.Next(); 
     176        Intersectable *object = entry.mObject; 
     177        RenderIntersectable(object); 
     178  } 
     179   
     180  //    glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); 
     181  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     182   
     183  mUseFalseColors = true; 
     184   
     185  query.BeginQuery(); 
     186   
     187  SetupCamera(); 
     188   
     189  RenderScene(); 
     190   
     191  query.EndQuery(); 
     192   
     193   
     194  // reenable other state 
     195  pixelCount = query.GetQueryResult(); 
     196   
     197   
     198  pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight()); 
     199 
    195200   
    196201  if (mSnapErrorFrames && pErrorPixels > 0.001f) { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp

    r1926 r1931  
    303303 
    304304 
    305 void 
    306 RssPreprocessor::ComputeRenderError() 
    307 { 
    308   // compute rendering error 
    309          
    310   if (renderer && renderer->mPvsStatFrames) { 
    311         //      emit EvalPvsStat(); 
    312         //      QMutex mutex; 
    313         //      mutex.lock(); 
    314         //      renderer->mRenderingFinished.wait(&mutex); 
    315         //      mutex.unlock(); 
    316          
    317         renderer->EvalPvsStat(); 
    318  
    319         mStats << 
    320           "#AvgPvsRenderError\n" <<renderer->mPvsStat.GetAvgError()<<endl<< 
    321           "#MaxPvsRenderError\n" <<renderer->mPvsStat.GetMaxError()<<endl<< 
    322           "#ErrorFreeFrames\n" <<renderer->mPvsStat.GetErrorFreeFrames()<<endl<< 
    323           "#AvgRenderPvs\n" <<renderer->mPvsStat.GetAvgPvs()<<endl; 
    324   } 
    325 } 
    326305 
    327306void 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h

    r1900 r1931  
    115115 
    116116 
    117   void 
    118   ComputeRenderError(); 
    119117 
    120118  /** Redefininition of the get sample rays method from the preprocessor */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp

    r1906 r1931  
    26292629{ 
    26302630 
    2631   if (1) { 
    2632         float param[5]; 
    2633          
    2634         for (int i=0; i < numberOfRays; i++) { 
    2635           mHalton.GetNext(5, param); 
    2636           GenerateRay(param, rays); 
    2637         } 
    2638  
    2639         return rays.size(); 
    2640   } 
    2641    
    2642   vector<RssTreeLeaf *> leaves; 
    2643  
    2644   Debug<<"Collecting leaves..."<<endl<<flush; 
    2645   CollectLeaves(leaves); 
    2646   Debug<<"done."<<endl<<flush; 
    2647    
    2648    
    2649   if (numberOfLeaves != leaves.size()) { 
    2650         Debug<<"sorting leaves..."<<endl<<flush; 
    2651         sort(leaves.begin(), 
    2652                  leaves.end(), 
    2653                  GreaterContribution); 
    2654         Debug<<"done."<<endl<<flush; 
    2655   } 
    2656                           
    2657    
    2658   Debug<<"Evaluating leaf importance..."<<endl<<flush; 
    2659  
    2660   float sumContrib = 0.0; 
    2661   int i; 
    2662   int k = 0; 
    2663   for (i=0; i < leaves.size() && k < numberOfLeaves; i++) 
    2664         if (ValidLeaf(leaves[i])) { 
    2665           float c = leaves[i]->GetImportance(); 
    2666           sumContrib += c; 
    2667           //            cout<<"ray contrib "<<i<<" : "<<c<<endl; 
    2668           k++; 
    2669         } 
    2670  
    2671   Debug<<"done."<<endl<<flush; 
    2672    
    2673   float avgContrib = sumContrib/numberOfLeaves; 
    2674    
    2675   // always generate at leat n ray per leaf 
    2676   int fixedPerLeaf = 1; 
    2677   // int fixedPerLeaf = 0; 
    2678   int fixed = fixedPerLeaf*(int)leaves.size(); 
    2679  
    2680   // check if the number of fixed is not too big 
    2681  
    2682   if (fixed >= numberOfRays/2) { 
    2683         fixedPerLeaf = 0; 
    2684         fixed = 0; 
    2685   } 
    2686    
    2687   int iGenerated = numberOfRays - fixed; 
    2688   float ratioPerLeaf = iGenerated /(avgContrib*numberOfLeaves); 
    2689    
    2690   k = 0; 
    2691  
    2692   Debug<<"generating leaf rays..."<<endl<<flush; 
    2693  
    2694   for (i=0; i < leaves.size() && k < numberOfLeaves; i++) 
    2695         if (ValidLeaf(leaves[i])) { 
    2696           RssTreeLeaf *leaf = leaves[i]; 
    2697           float c = leaf->GetImportance(); 
    2698            
    2699           int num = fixedPerLeaf + (int)(c*ratioPerLeaf + 0.5f); 
    2700           GenerateLeafRaysSimple(leaf, num, rays); 
    2701  
    2702           k++; 
    2703         } 
    2704  
    2705   Debug<<"done."<<endl<<flush; 
    2706  
    2707   return (int)rays.size(); 
     2631  float param[5]; 
     2632   
     2633  for (int i=0; i < numberOfRays; i++) { 
     2634        mHalton.GetNext(5, param); 
     2635        GenerateRay(param, rays); 
     2636  } 
     2637   
     2638  return rays.size(); 
     2639   
    27082640} 
    27092641 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r1901 r1931  
    528528        float contribution = 
    529529          mPreprocessor.mViewCellsManager->ComputeSampleContribution(*ray, true, false); 
     530 
    530531        mDistributions[i]->mContribution += contribution; 
    531532        mDistributions[i]->mRays ++; 
     
    579580   
    580581  cout<<"ratios: "; 
    581   for (i=0; i < mDistributions.size(); i++) 
    582         cout<<mDistributions[i]->mRatio<<" "; 
     582  float last = 0.0f; 
     583  for (i=0; i < mDistributions.size(); i++) { 
     584        cout<<mDistributions[i]->mRatio-last<<" "; 
     585        last = mDistributions[i]->mRatio; 
     586  } 
    583587  cout<<endl; 
    584588} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1928 r1931  
    3030 
    3131#define USE_RAY_LENGTH_AS_CONTRIBUTION 0 
    32 #define DIST_WEIGHTED_CONTRIBUTION 1 
     32#define DIST_WEIGHTED_CONTRIBUTION 0 
     33#define SUM_RAY_CONTRIBUTIONS 0 
     34#define AVG_RAY_CONTRIBUTIONS 1 
     35#define CONTRIBUTION_RELATIVE_TO_PVS_SIZE 1 
    3336 
    3437namespace GtpVisibilityPreprocessor { 
     
    16931696          } 
    16941697        } 
    1695    
     1698 
    16961699  return sum; 
    16971700} 
     
    21932196        Intersectable *terminationObj = GetIntersectable(ray, true); 
    21942197 
    2195  
     2198         
    21962199        for (; it != viewcells.end(); ++ it)  
    21972200        { 
     
    22012204                {        
    22022205                        // if ray not outside of view space 
    2203                         float contribution; 
    2204  
     2206                        float relContribution = 0.0f; 
     2207                        float absContribution = 0.0f; 
     2208                         
    22052209                        if (terminationObj)  
    22062210                        { 
    22072211                                // todo: maybe not correct for kd node pvs 
    2208                                 bool absContribution =  
    2209                                         viewcell->GetPvs().GetSampleContribution( 
    2210                                                                                                                         terminationObj, 
    2211                                                                                                                         ray.mPdf, 
    2212                                                                                                                         contribution); 
    2213 #if DIST_WEIGHTED_CONTRIBUTION 
    2214                                 // clear the relative contribution 
    2215                                 contribution = 0.0f; 
     2212                          if (viewcell->GetPvs().GetSampleContribution( 
     2213                                                                                                                   terminationObj, 
     2214                                                                                                                   ray.mPdf, 
     2215                                                                                                                   relContribution)) 
     2216                                absContribution = 1.0f; 
     2217                           
     2218                          // $$ clear the relative contribution as it is currently not correct anyway 
     2219                          relContribution = 0.0f; 
     2220 
     2221                          if (absContribution == 1.0f) 
     2222                                { 
     2223                                  ++ ray.mPvsContribution; 
     2224                                  relContribution = 1.0f; 
     2225                                  if (addRays) { 
     2226#if PVS_ADD_DIRTY 
     2227                                        viewcell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf); 
     2228                                        if (viewcell->GetPvs().RequiresResort()) { 
     2229                                          viewcell->GetPvs().SimpleSort(); 
     2230                                        } 
     2231#else 
     2232                                        viewcell->GetPvs().AddSample(terminationObj, ray.mPdf); 
    22162233#endif 
    2217                                 if (absContribution) 
    2218                                 { 
    2219                                         ++ ray.mPvsContribution; 
    2220                                         if (addRays) { 
    2221 #if PVS_ADD_DIRTY 
    2222                                                 viewcell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf); 
    2223                                                 if (viewcell->GetPvs().RequiresResort()) { 
    2224                                                         viewcell->GetPvs().SimpleSort(); 
    2225                                                 } 
    2226 #else 
    2227                                                 viewcell->GetPvs().AddSample(terminationObj, ray.mPdf); 
     2234                                  } 
     2235 
     2236#if CONTRIBUTION_RELATIVE_TO_PVS_SIZE 
     2237                                  relContribution /= viewcell->GetPvs().GetSize(); 
    22282238#endif 
    2229                                         } 
     2239                                   
    22302240#if DIST_WEIGHTED_CONTRIBUTION  
    2231                                         // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
    2232                                         // object-> a new contribution in the proximity of the viewcell has a larger weight! 
    2233                                         contribution = 1.0f/SqrDistance(GetViewCellBox(viewcell).Center(), 
    2234                                                 ray.mTermination); 
     2241                                  // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
     2242                                  // object-> a new contribution in the proximity of the viewcell has a larger weight! 
     2243                                  relContribution /= SqrDistance(GetViewCellBox(viewcell).Center(), 
     2244                                                                                                 ray.mTermination); 
     2245                                   
    22352246#endif 
    22362247                                } 
    2237  
    2238                                 ray.mRelativePvsContribution += contribution; 
     2248#if SUM_RAY_CONTRIBUTIONS || AVG_RAY_CONTRIBUTIONS 
     2249                          ray.mRelativePvsContribution += relContribution; 
     2250#else 
     2251                          // recalculate relative contribution - use max of AbsContribution 
     2252                          if (ray.mRelativePvsContribution < absContribution) 
     2253                                ray.mRelativePvsContribution = absContribution; 
     2254#endif 
    22392255                        } 
    22402256                } 
    22412257        } 
    22422258 
     2259#if AVG_RAY_CONTRIBUTIONS 
     2260        ray.mRelativePvsContribution /= viewcells.size(); 
     2261#endif 
    22432262#if USE_RAY_LENGTH_AS_CONTRIBUTION 
    22442263  float c = 0.0f; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/default.env

    r1900 r1931  
    103103        samplesPerPass 1000000 
    104104        initialSamples 2000000 
    105         vssSamples 20000000 
     105        vssSamples 150000000 
    106106        vssSamplesPerPass 5000000 
    107107        useImportanceSampling true 
     
    195195 
    196196ViewCells { 
     197        useKdPvs true 
    197198        # samples used for view cell construction 
    198199        Construction { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro

    r1891 r1931  
    109109InternalRayCaster.cpp IntelRayCaster.cpp \ 
    110110RayCaster.cpp PreprocessorFactory.cpp GvsPreprocessor.cpp \ 
    111 Trackball.cpp ObjExporter.cpp SubdivisionCandidate.cpp QtGlViewer.cpp \ 
     111Trackball.cpp ObjExporter.cpp SubdivisionCandidate.cpp \ 
    112112Mailable.cpp \ 
    113 CombinedPreprocessor.cpp 
    114  
     113CombinedPreprocessor.cpp QtGlViewer.cpp  
    115114 
    116115SOURCES += BoostPreprocessorThread.cpp  
Note: See TracChangeset for help on using the changeset viewer.