Ignore:
Timestamp:
01/07/08 02:23:52 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2572 r2576  
     1#include "glInterface.h" 
     2#include "QtGlRenderer.h" 
    13#include "Mesh.h" 
    2 #include "glInterface.h" 
    34#include "OcclusionQuery.h" 
    4 #include "QtGlRenderer.h" 
    55#include "ViewCellsManager.h" 
    66#include "SceneGraph.h" 
     
    12451245#endif 
    12461246 
    1247 void 
    1248 QtGlRendererWidget::RenderViewCells() 
     1247 
     1248 
     1249void QtGlRendererWidget::ComputeMaxValues(const ViewCellContainer &viewCells, 
     1250                                                                                  int &maxPvs,  
     1251                                                                                  int &maxPiercingRays,  
     1252                                                                                  float &maxRelativeRays,  
     1253                                                                                  float &maxRcCost) 
     1254{ 
     1255        maxPvs = -1; 
     1256        maxPiercingRays = 1; // not zero for savety 
     1257        maxRelativeRays = Limits::Small; // not zero for savety 
     1258        maxRcCost = Limits::Small; 
     1259 
     1260        for (size_t i = 0; i < viewCells.size(); ++ i)  
     1261        { 
     1262                ViewCell *vc = viewCells[i]; 
     1263 
     1264                if (mShowPvsSizes) // pvs size 
     1265                { 
     1266                        //const int p = vc->GetPvs().CountObjectsInPvs(); 
     1267                        const int p = vc->GetPvs().GetSize(); 
     1268                        if (p > maxPvs) 
     1269                                maxPvs = p; 
     1270                } 
     1271                else if (mShowPiercingRays) // relative number of rays 
     1272                { 
     1273                        const int piercingRays = vc->GetNumPiercingRays(); 
     1274 
     1275                        if (piercingRays > maxPiercingRays) 
     1276                                maxPiercingRays = piercingRays; 
     1277                }  
     1278                else if (mShowWeightedRays) 
     1279                { 
     1280                        const int piercingRays = vc->GetNumPiercingRays(); 
     1281 
     1282                        const float relativeArea =  
     1283                                vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea(); 
     1284 
     1285                        if ((float)piercingRays / relativeArea > maxRelativeRays) 
     1286                                maxRelativeRays = (float)piercingRays / relativeArea; 
     1287                } 
     1288                else if (mShowWeightedCost) 
     1289                { 
     1290                        const float rcCost = ComputeRenderCost(vc); 
     1291                        mViewCellsManager->UpdateScalarPvsCost(vc, rcCost); 
     1292 
     1293                        if (rcCost > maxRcCost) 
     1294                                maxRcCost = rcCost; 
     1295                } 
     1296        } 
     1297} 
     1298 
     1299 
     1300void QtGlRendererWidget::RenderViewCells() 
    12491301{ 
    12501302        mUseFalseColors = true; 
     
    12721324        ViewCellContainer &viewcells = mViewCellsManager->GetViewCells(); 
    12731325         
    1274         int maxPvs = -1; 
    1275         int maxPiercingRays = 1; // not zero for savety 
    1276         float maxRelativeRays = Limits::Small; // not zero for savety 
    1277         float maxRcCost = Limits::Small; 
    1278  
    1279         for (i = 0; i < viewcells.size(); ++ i)  
    1280         { 
    1281                 ViewCell *vc = viewcells[i]; 
    1282  
    1283                 if (mShowPvsSizes) // pvs size 
    1284                 { 
    1285                         //const int p = vc->GetPvs().CountObjectsInPvs(); 
    1286                         const int p = vc->GetPvs().GetSize(); 
    1287                         if (p > maxPvs) 
    1288                                 maxPvs = p; 
    1289                 } 
    1290                 else if (mShowPiercingRays) // relative number of rays 
    1291                 { 
    1292                         const int piercingRays = vc->GetNumPiercingRays(); 
    1293  
    1294                         if (piercingRays > maxPiercingRays) 
    1295                                 maxPiercingRays = piercingRays; 
    1296                 }  
    1297                 else if (mShowWeightedRays) 
    1298                 { 
    1299                         const int piercingRays = vc->GetNumPiercingRays(); 
    1300  
    1301                         const float relativeArea =  
    1302                                 vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea(); 
    1303  
    1304                         if ((float)piercingRays / relativeArea > maxRelativeRays) 
    1305                                 maxRelativeRays = (float)piercingRays / relativeArea; 
    1306                 } 
    1307                 else if (mShowWeightedCost) 
    1308                 { 
    1309                         const float rcCost = ComputeRenderCost(vc); 
    1310                         mViewCellsManager->UpdateScalarPvsCost(vc, rcCost); 
    1311  
    1312                         if (rcCost > maxRcCost) 
    1313                                 maxRcCost = rcCost; 
    1314                 } 
    1315         } 
     1326        int maxPvs, maxPiercingRays; 
     1327        float maxRelativeRays, maxRcCost; 
     1328 
     1329        ComputeMaxValues(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost); 
     1330 
    13161331 
    13171332        if (!mShowPvsSizes && !mShowPiercingRays && !mShowWeightedRays && !mShowWeightedCost) 
     
    13381353        else 
    13391354        { 
    1340                 //glDisable(GL_CULL_FACE); 
    1341                 //glCullFace(GL_BACK); 
    1342  
     1355                // transparency  
    13431356                if (!mUseTransparency) 
    13441357                { 
     
    13651378                } 
    13661379 
    1367                 for (i = 0; i < viewcells.size(); ++ i)  
    1368                 { 
    1369                         RgbColor c; 
    1370             ViewCell *vc = viewcells[i]; 
    1371                          
    1372                         float importance; 
    1373  
    1374                         if (mShowPiercingRays) 
    1375                         { 
    1376                                 importance = mTransferFunction * 
    1377                                         ((float)vc->GetNumPiercingRays() / (float)maxPiercingRays); 
    1378                         } 
    1379                         else if (mShowWeightedRays) // relative number of rays 
    1380                         { 
    1381                                 float relativeArea = vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea(); 
    1382  
    1383                                 if (relativeArea < Limits::Small) 
    1384                                         relativeArea = Limits::Small; 
    1385  
    1386                                 importance = mTransferFunction * ((float)vc->GetNumPiercingRays() / relativeArea) / maxRelativeRays; 
    1387                         } 
    1388                         else if (mShowPvsSizes) // pvs size 
    1389                         { 
    1390                                 importance = mTransferFunction * 
    1391                                         ((float)vc->GetPvs().GetSize() / (float)maxPvs); 
    1392                         } // weighted render cost 
    1393                         else if (mShowWeightedCost) 
    1394                         { 
    1395                                 const float rcCost = mTransferFunction * ComputeRenderCost(vc); 
    1396                                 importance = rcCost / maxRcCost; 
    1397                         } 
    1398  
    1399                         // c = RgbColor(importance, 1.0f - importance, 0.0f); 
    1400                         c = RainbowColorMapping(importance); 
    1401  
    1402                         glColor4f(c.r, c.g, c.b, 1.0f - mTransparency); 
    1403  
    1404                         if (!mHideByCost || (mHidingCost < importance))  
    1405                         { 
    1406                                 RenderViewCell(vc); 
    1407                         } 
    1408                 } 
     1380                ViewCellInfoContainer *infos1 = mCurrentInfos[mCurrentSamples]; 
     1381                ViewCellInfoContainer *infos2 = mCompareInfos[mCurrentSamples]; 
     1382 
     1383                if (mAssignImportanceByRelativeValue) 
     1384                        AssignImportanceByRelativeValue(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost); 
     1385                else 
     1386                        AssignColorByComparison(viewcells, *infos1, *infos2); 
    14091387 
    14101388                glEnable(GL_DEPTH_TEST);         
     
    14231401 
    14241402 
    1425  
    1426 /*********************************************************************/ 
    1427 /*                   QtGlDebuggerWidget implementation               */ 
    1428 /*********************************************************************/ 
    1429  
    1430  
    1431 QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent) 
    1432 : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf) 
    1433 { 
    1434         // create the pbuffer 
    1435         //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this); 
    1436         timerId = startTimer(20); 
    1437         setWindowTitle(("OpenGL pbuffers")); 
    1438 } 
    1439  
    1440  
    1441 QtGlDebuggerWidget::~QtGlDebuggerWidget() 
    1442 { 
    1443         mRenderBuffer->releaseFromDynamicTexture(); 
    1444         glDeleteTextures(1, &dynamicTexture); 
    1445  
    1446         DEL_PTR(mRenderBuffer); 
    1447 } 
    1448  
    1449  
     1403void QtGlRendererWidget::AssignImportanceByRelativeValue(const ViewCellContainer &viewCells, 
     1404                                                                                                                 int &maxPvs,  
     1405                                                                                                                 int &maxPiercingRays,  
     1406                                                                                                                 float &maxRelativeRays,  
     1407                                                                                                                 float &maxRcCost) 
     1408{ 
     1409        for (size_t i = 0; i < viewCells.size(); ++ i)  
     1410        { 
     1411                RgbColor c; 
     1412                ViewCell *vc = viewCells[i]; 
     1413 
     1414                float importance; 
     1415 
     1416                if (mShowPiercingRays) 
     1417                { 
     1418                        importance = mTransferFunction * 
     1419                                ((float)vc->GetNumPiercingRays() / (float)maxPiercingRays); 
     1420                } 
     1421                else if (mShowWeightedRays) // relative number of rays 
     1422                { 
     1423                        float relativeArea = vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea(); 
     1424 
     1425                        if (relativeArea < Limits::Small) 
     1426                                relativeArea = Limits::Small; 
     1427 
     1428                        importance = mTransferFunction * ((float)vc->GetNumPiercingRays() / relativeArea) / maxRelativeRays; 
     1429                } 
     1430                else if (mShowPvsSizes) // pvs size 
     1431                { 
     1432                        importance = mTransferFunction * 
     1433                                ((float)vc->GetPvs().GetSize() / (float)maxPvs); 
     1434                } // weighted render cost 
     1435                else if (mShowWeightedCost) 
     1436                { 
     1437                        const float rcCost = mTransferFunction * ComputeRenderCost(vc); 
     1438                        importance = rcCost / maxRcCost; 
     1439                } 
     1440 
     1441                // c = RgbColor(importance, 1.0f - importance, 0.0f); 
     1442                c = RainbowColorMapping(importance); 
     1443 
     1444                glColor4f(c.r, c.g, c.b, 1.0f - mTransparency); 
     1445 
     1446                if (!mHideByCost || (mHidingCost < importance))  
     1447                { 
     1448                        RenderViewCell(vc); 
     1449                } 
     1450        } 
     1451} 
     1452 
     1453 
     1454void QtGlRendererWidget::AssignColorByComparison(const ViewCellContainer &viewcells, 
     1455                                                                                                 const ViewCellInfoContainer &infos1,  
     1456                                                                                                 const ViewCellInfoContainer &infos2) 
     1457{ 
     1458 
     1459        const float maxRatio = 2; 
     1460        const float minRatio = 0.5; 
     1461 
     1462        const float scale = 1.0f / (maxRatio - minRatio); 
     1463 
     1464        for (size_t i = 0; i < viewcells.size(); ++ i)  
     1465        { 
     1466                RgbColor c; 
     1467                ViewCell *vc = viewcells[i]; 
     1468 
     1469                ViewCellInfo vc1Info = infos1[i]; 
     1470                ViewCellInfo vc2Info = infos2[i]; 
     1471 
     1472                const float vcRatio = vc1Info.mPiercingRays / vc2Info.mPiercingRays + Limits::Small; 
     1473 
     1474                const float importance = (vcRatio - minRatio) * scale; 
     1475 
     1476                // c = RgbColor(importance, 1.0f - importance, 0.0f); 
     1477                c = RainbowColorMapping(importance); 
     1478 
     1479                glColor4f(c.r, c.g, c.b, 1.0f); 
     1480 
     1481                if (1)//!mHideByCost || (mHidingCost < importance))  
     1482                { 
     1483                        RenderViewCell(vc); 
     1484                } 
     1485        } 
     1486} 
     1487 
     1488 
     1489 
     1490/**********************************************************************/ 
     1491/*              QtRendererControlWidget implementation                */ 
     1492/**********************************************************************/ 
     1493 
     1494#if 1 
    14501495QGroupBox *QtRendererControlWidget::CreateVisualizationPanel(QWidget *parent) 
    14511496{ 
     
    15271572} 
    15281573 
     1574 
    15291575QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f): 
    15301576QWidget(parent, f) 
     
    18431889void 
    18441890QtRendererControlWidget::FocusNextPvsErrorFrame(void) 
    1845 { 
    1846  
    1847  
    1848 } 
     1891{} 
    18491892 
    18501893void 
     
    18651908 
    18661909 
     1910 
     1911#endif 
     1912 
     1913 
     1914/*********************************************************************/ 
     1915/*                   QtGlDebuggerWidget implementation               */ 
     1916/*********************************************************************/ 
     1917 
     1918 
     1919QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent) 
     1920: QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf) 
     1921{ 
     1922        // create the pbuffer 
     1923        //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this); 
     1924        timerId = startTimer(20); 
     1925        setWindowTitle(("OpenGL pbuffers")); 
     1926} 
     1927 
     1928 
     1929QtGlDebuggerWidget::~QtGlDebuggerWidget() 
     1930{ 
     1931        mRenderBuffer->releaseFromDynamicTexture(); 
     1932        glDeleteTextures(1, &dynamicTexture); 
     1933 
     1934        DEL_PTR(mRenderBuffer); 
     1935} 
     1936 
     1937 
    18671938void QtGlDebuggerWidget::initializeGL() 
    18681939{ 
     
    19452016} 
    19462017 
     2018 
    19472019void QtGlDebuggerWidget::initCommon() 
    19482020{ 
     
    19542026 
    19552027 
    1956  
    1957 } 
     2028} 
Note: See TracChangeset for help on using the changeset viewer.