Changeset 1942


Ignore:
Timestamp:
01/05/07 16:29:54 (17 years ago)
Author:
bittner
Message:

tmp commit

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
24 edited
1 moved

Legend:

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

    r1931 r1942  
    7979        totalVssRays += (int)vssRays.size(); 
    8080 
     81        mMixtureDistribution->ComputeContributions(vssRays); 
     82 
    8183        if (mExportRays) { 
    8284          Debug<<"Exporting rays..."<<endl<<flush; 
    8385          char filename[256]; 
     86 
     87          VssRayContainer contributingRays; 
     88          vssRays.GetContributingRays(contributingRays, 0); 
     89          sprintf(filename, "rss-crays-%04d.x3d", mPass); 
     90          ExportRays(filename, contributingRays, mExportNumRays); 
     91 
    8492          sprintf(filename, "rss-rays-i%04d.x3d", mPass); 
    8593          ExportRays(filename, vssRays, mExportNumRays); 
    86            
    87           //      VssRayContainer contributingRays; 
    88           //      vssRays.GetContributingRays(contributingRays, 0); 
    89           //      sprintf(filename, "rss-crays-%04d.x3d", mPass); 
    90           //      ExportRays(filename, contributingRays, mExportNumRays); 
     94 
    9195          Debug<<"done."<<endl<<flush; 
    9296        } 
    9397 
    94         mMixtureDistribution->ComputeContributions(vssRays); 
    95  
     98        mMixtureDistribution->UpdateDistributions(vssRays); 
     99         
    96100        if (i - lastEvaluation >= mSamplesPerEvaluation) { 
    97101          mViewCellsManager->PrintPvsStatistics(mStats); 
     
    114118         
    115119  } 
    116    
     120 
     121  EvalViewCellHistogram(); 
     122 
    117123  return true; 
    118124} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1934 r1942  
    17421742        RegisterOption("Preprocessor.loadMeshes", 
    17431743                                        optBool, 
    1744                                         "preprocessor_load_meshes=", 
     1744                                        "preprocessor_load_meshes", 
    17451745                                        "true"); 
    17461746 
    17471747        RegisterOption("Preprocessor.evaluateFilter", 
    17481748                                   optBool, 
    1749                                    "preprocessor_evaluate_filter=", 
     1749                                   "preprocessor_evaluate_filter", 
    17501750                                   "false"); 
    17511751 
    17521752        RegisterOption("Preprocessor.delayVisibilityComputation", 
    17531753                                   optBool, 
    1754                                    "preprocessor_delay_computation=", 
     1754                                   "preprocessor_delay_computation", 
    17551755                                   "true"); 
    17561756 
     
    17621762        RegisterOption("Preprocessor.useGlRenderer", 
    17631763                                        optBool, 
    1764                                         "preprocessor_use_gl_renderer=", 
     1764                                        "preprocessor_use_gl_renderer", 
    17651765                                        "false"); 
    17661766 
    17671767        RegisterOption("Preprocessor.useGlDebugger", 
    17681768                                        optBool, 
    1769                                         "preprocessor_use_gl_debugger=", 
     1769                                        "preprocessor_use_gl_debugger", 
    17701770                                        "false"); 
    17711771 
    17721772        RegisterOption("Preprocessor.detectEmptyViewSpace", 
    17731773                                   optBool, 
    1774                                    "preprocessor_detect_empty_viewspace=", 
     1774                                   "preprocessor_detect_empty_viewspace", 
    17751775                                   "false"); 
    17761776         
    17771777        RegisterOption("Preprocessor.quitOnFinish", 
    17781778                                   optBool, 
    1779                                    "preprocessor_quit_on_finish=", 
     1779                                   "preprocessor_quit_on_finish", 
    17801780                                   "true"); 
    17811781 
    17821782        RegisterOption("Preprocessor.computeVisibility", 
    17831783                                   optBool, 
    1784                                    "preprocessor_compute_visibility=", 
     1784                                   "preprocessor_compute_visibility", 
    17851785                                   "true"); 
    17861786 
    17871787        RegisterOption("Preprocessor.exportVisibility", 
    17881788                                   optBool, 
    1789                                    "preprocessor_export_visibility=", 
     1789                                   "preprocessor_export_visibility", 
    17901790                                   "true"); 
    17911791 
     
    17971797        RegisterOption("Preprocessor.applyVisibilityFilter", 
    17981798                                   optBool, 
    1799                                    "preprocessor_apply_filter=", 
     1799                                   "preprocessor_apply_filter", 
    18001800                                   "false"); 
    18011801         
    18021802        RegisterOption("Preprocessor.applyVisibilitySpatialFilter", 
    18031803                                   optBool, 
    1804                                    "preprocessor_apply_spatial_filter=", 
     1804                                   "preprocessor_apply_spatial_filter", 
    18051805                                   "false"); 
    18061806 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r1941 r1942  
    6666  //  mViewCellsManager->GetViewPoint(mViewPoint); 
    6767 
    68   mViewPoint = mSceneGraph->GetBox().Center(); 
     68  viewCellsManager->GetViewPoint(mViewPoint); 
     69        //mSceneGraph->GetBox().Center(); 
    6970  mViewDirection = Vector3(0,0,1); 
    7071 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp

    r1867 r1942  
    22#include "VssRay.h" 
    33#include "Preprocessor.h" 
     4#include "SceneGraph.h" 
    45 
    56#ifdef GTP_INTERNAL 
     
    125126        float backward_dist[16]; 
    126127 
    127  
    128         Vector3 min = sbox.Min(); 
    129         Vector3 max = sbox.Max(); 
     128         
     129        Vector3 min = mPreprocessor.mSceneGraph->GetBox().Min(); 
     130        Vector3 max = mPreprocessor.mSceneGraph->GetBox().Max(); 
    130131 
    131132        for (i=0; i < num; i++) { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r1931 r1942  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: út 2. I 10:32:48 2007 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: pá 5. I 16:16:49 2007 
    44# Project:  preprocessor.pro 
    55# Template: app 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1932 r1942  
    3131 
    3232 
     33 
    3334/** Namespace for the external visibility preprocessor 
    3435 
     
    230231 
    231232        GlRendererBuffer *renderer; 
    232  
    233  
     233   
     234   
    234235protected: 
    235236 
  • GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorFactory.cpp

    r1891 r1942  
    4949        } 
    5050 
     51 
    5152        return NULL; 
    5253} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r1925 r1942  
    615615  // sample not found yet => search further in the unsorted part 
    616616  if (!found && checkDirty) { 
    617         vector<PvsEntry<T, S> >::const_iterator dit, dit_end = mEntries.end(); 
    618          
    619         for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit) ; 
    620          
    621         if (dit != dit_end) 
     617         
     618        for (it = sorted_end; (it != mEntries.end()) && ((*it).mObject != sample); ++ it) ; 
     619         
     620        if (it != mEntries.end()) 
    622621          found = true; 
    623622  } 
     
    653652        } 
    654653        else  
    655         { 
     654          { 
    656655                PvsEntry<T, S> entry(sample, pdf); 
    657656                mEntries.insert(it, entry); 
    658657                ++ mLastSorted; 
    659658                return pdf; 
    660         } 
     659          } 
    661660} 
    662661 
     
    706705 
    707706        vector<PvsEntry<T, S> >::iterator it; 
    708         const bool entryFound = Find(sample, it); 
     707        bool entryFound = Find(sample, it); 
    709708 
    710709        if (entryFound) { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtGlViewer.h

    r1936 r1942  
    1212class QtGlViewer : public QGLWidget 
    1313{ 
    14          
    15         //Q_OBJECT 
     14  Q_OBJECT 
    1615 
    1716        friend class QtGlRendererWidget; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp

    r1940 r1942  
    1010#include "KdTree.h" 
    1111#include "Environment.h" 
     12#include "RssPreprocessor.h" 
     13#include "RssTree.h" 
     14#include "Trackball.h" 
     15#include "QtPreprocessorThread.h" 
     16 
     17#define USE_CG 1 
     18 
     19 
     20#if USE_CG 
    1221#include <Cg/cg.h> 
    1322#include <Cg/cgGL.h> 
     23#endif 
    1424 
    1525#include <QVBoxLayout> 
     
    1727namespace GtpVisibilityPreprocessor { 
    1828 
     29 
     30   
    1931class ViewCellsManager; 
    2032 
    2133static CGcontext sCgContext = NULL; 
    2234static CGprogram sCgFragmentProgram = NULL; 
    23 static CGprogram sCgDepthPeelingProgram = NULL; 
    2435static CGprofile sCgFragmentProfile; 
    2536 
    26 static GLuint frontDepthMap; 
    27 static GLuint backDepthMap; 
    28  
    29 const int depthMapSize = 512; 
     37 
     38//static vector<OcclusionQuery *> sQueries; 
    3039 
    3140QtGlRendererWidget *rendererWidget = NULL; 
     
    3847} 
    3948 
    40  
     49#if USE_CG 
    4150static void handleCgError()  
    4251{ 
     
    4453    exit(1); 
    4554} 
    46  
    47 void 
    48 QtGlRendererBuffer::EvalRenderCostSample(RenderCostSample &sample, 
    49                                                                                  const bool useOcclusionQueries, 
    50                                                                                  const int threshold 
    51                                                                                  ) 
    52 { 
    53         // choose a random view point 
    54         mViewCellsManager->GetViewPoint(mViewPoint); 
    55         sample.mPosition = mViewPoint; 
    56  
    57         // take a render cost sample by rendering a cube 
    58         Vector3 directions[6]; 
    59  
    60         directions[0] = Vector3(1,0,0); 
    61         directions[1] = Vector3(0,1,0); 
    62         directions[2] = Vector3(0,0,1); 
    63         directions[3] = Vector3(-1,0,0); 
    64         directions[4] = Vector3(0,-1,0); 
    65         directions[5] = Vector3(0,0,-1); 
    66  
    67         sample.mVisibleObjects = 0; 
    68  
    69         // reset object counters 
    70         ObjectContainer::const_iterator it, it_end = mObjects.end(); 
    71  
    72         for (it = mObjects.begin(); it != it_end; ++ it)  
    73         { 
    74                 (*it)->mCounter = 0; 
    75         } 
    76  
    77         ++ mFrame; 
    78  
    79         //glCullFace(GL_FRONT); 
    80         glCullFace(GL_BACK); 
    81         glDisable(GL_CULL_FACE); 
    82          
    83  
    84         // query all 6 directions for a full point sample 
    85         for (int i = 0; i < 6; ++ i)  
    86         { 
    87                 mViewDirection = directions[i]; 
    88                 SetupCamera(); 
    89  
    90                 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 
    91                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    92                 //glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);      glDepthMask(GL_TRUE); 
    93                 glDepthFunc(GL_LESS); 
    94  
    95                 mUseFalseColors = true; 
    96  
    97                 // the actual scene rendering fills the depth (for occlusion queries) 
    98                 // and the frame buffer (for item buffer) 
    99                 RenderScene(); 
    100  
    101  
    102                 if (0)  
    103                 { 
    104                         char filename[256]; 
    105                         sprintf(filename, "snap/frame-%04d-%d.png", mFrame, i); 
    106                         QImage im = toImage(); 
    107                         im.save(filename, "PNG"); 
    108                 } 
    109           
    110                 // evaluate the sample 
    111                 if (useOcclusionQueries)  
    112                 { 
    113                         EvalQueryWithOcclusionQueries(); 
    114                 } 
    115                 else  
    116                 { 
    117                         EvalQueryWithItemBuffer(); 
    118                 } 
    119         }   
    120  
    121         // now evaluate the statistics over that sample 
    122         // currently only the number of visible objects is taken into account 
    123         sample.Reset(); 
    124  
    125         for (it = mObjects.begin(); it != it_end; ++ it)  
    126         { 
    127                 Intersectable *obj = *it; 
    128                 if (obj->mCounter >= threshold)  
    129                 { 
    130                         ++ sample.mVisibleObjects; 
    131                         sample.mVisiblePixels += obj->mCounter; 
    132                 } 
    133         } 
    134  
    135         //cout << "RS=" << sample.mVisibleObjects << " "; 
    136 } 
    137  
    138  
    139 QtGlRendererBuffer::~QtGlRendererBuffer() 
    140 { 
    141         if (sCgFragmentProgram) 
    142                 cgDestroyProgram(sCgFragmentProgram); 
    143         if (sCgDepthPeelingProgram) 
    144                 cgDestroyProgram(sCgDepthPeelingProgram); 
    145         if (sCgContext) 
    146                 cgDestroyContext(sCgContext); 
    147 } 
    148  
    149  
    150 void 
    151 QtGlRendererBuffer::SampleRenderCost(const int numSamples, 
    152                                                                          vector<RenderCostSample> &samples, 
    153                                                                          const bool useOcclusionQueries, 
    154                                                                          const int threshold 
    155                                                                          ) 
     55#endif 
     56 
     57void 
     58QtGlRendererBuffer::MakeCurrent() 
    15659{ 
    15760  makeCurrent(); 
    158  
    159   if (mPixelBuffer == NULL) 
    160           mPixelBuffer = new unsigned int[GetWidth()*GetHeight()]; 
    161    
    162   // using 90 degree projection to capture 360 view with 6 samples 
    163   SetupProjection(GetHeight(), GetHeight(), 90.0f); 
    164  
    165   //samples.resize(numSamples); 
    166   halton.Reset(); 
    167    
    168   // the number of queries queried in batch mode 
    169   const int numQ = 500; 
    170  
    171   //const int numQ = (int)mObjects.size(); 
    172   if (useOcclusionQueries) 
    173   { 
    174           cout << "\ngenerating " << numQ << " queries ... "; 
    175           OcclusionQuery::GenQueries(mOcclusionQueries, numQ); 
    176           cout << "finished" << endl; 
    177   } 
    178  
    179   // sampling queries  
    180   for (int i = 0; i < numSamples; ++ i) 
    181   { 
    182           cout << "."; 
    183           EvalRenderCostSample(samples[i], useOcclusionQueries, threshold); 
    184   } 
    185  
     61} 
     62 
     63void 
     64QtGlRendererBuffer::DoneCurrent() 
     65{ 
    18666  doneCurrent(); 
    187  
    188 } 
    189    
    190  
     67} 
     68   
    19169 
    19270QtGlRendererBuffer::QtGlRendererBuffer(const int w, 
     
    19674                                                                           KdTree *tree): 
    19775  QGLPixelBuffer(QSize(w, h)), 
    198 GlRendererBuffer(sceneGraph, viewcells, tree) { 
    199   
    200   Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames); 
    201   mPvsErrorBuffer.resize(mPvsStatFrames); 
    202   ClearErrorBuffer(); 
    203  
    204   mPixelBuffer = NULL; 
    205    
    206   makeCurrent(); 
     76  //QGLWidget(NULL, w, h), 
     77  GlRendererBuffer(sceneGraph, viewcells, tree) 
     78{ 
     79  MakeCurrent(); 
    20780  InitGL(); 
    208   doneCurrent(); 
    209    
    210 } 
     81  DoneCurrent(); 
     82} 
     83 
     84 
    21185 
    21286float 
    21387QtGlRendererBuffer::GetPixelError(int &pvsSize) 
    21488{ 
    215         float pErrorPixels = -1.0f; 
    216  
    217         glReadBuffer(GL_BACK); 
    218  
    219         mUseFalseColors = false; 
    220         unsigned int pixelCount; 
    221  
    222         OcclusionQuery query; 
    223  
    224         if (mDetectEmptyViewSpace)  
    225         { 
    226                 // now check whether any backfacing polygon would pass the depth test 
    227                 SetupCamera(); 
    228                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    229                 glEnable( GL_CULL_FACE ); 
    230  
    231                 RenderScene(); 
    232  
    233                 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    234                 glDepthMask(GL_FALSE); 
    235                 glDisable( GL_CULL_FACE ); 
    236  
    237  
    238                 query.BeginQuery(); 
    239  
    240                 RenderScene(); 
    241  
    242                 query.EndQuery(); 
    243  
    244                 // at this point, if possible, go and do some other computation 
    245                 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    246                 glDepthMask(GL_TRUE); 
    247                 glEnable( GL_CULL_FACE ); 
    248  
    249                 // reenable other state 
    250                 pixelCount = query.GetQueryResult(); 
    251  
    252                 if (pixelCount > 0) 
    253                         return -1.0f; // backfacing polygon found -> not a valid viewspace sample 
    254         }  
    255         else 
    256         { 
    257                 glDisable( GL_CULL_FACE ); 
    258         } 
    259  
    260         ViewCell *viewcell = NULL; 
    261  
    262         PrVs prvs; 
    263  
    264         mViewCellsManager->SetMaxFilterSize(0); 
    265         mViewCellsManager->GetPrVS(mViewPoint, prvs, mViewCellsManager->GetFilterWidth()); 
    266         viewcell = prvs.mViewCell; 
    267  
    268         // ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint); 
    269         pvsSize = 0; 
    270         if (viewcell)  
    271         { 
    272                 SetupCamera(); 
    273                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    274  
    275                 glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); 
    276  
    277                 // Render PVS 
    278                 ObjectPvsIterator pit = viewcell->GetPvs().GetIterator(); 
    279  
    280                 while (pit.HasMoreEntries()) 
    281                 {                
    282                         const ObjectPvsEntry &entry = pit.Next(); 
    283                         Intersectable *obj = entry.mObject; 
    284  
    285                         RenderIntersectable(obj); 
    286                 } 
    287  
    288                 // glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); 
    289                 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    290                 mUseFalseColors = true; 
    291  
    292                 query.BeginQuery(); 
    293  
    294                 SetupCamera(); 
    295  
    296                 RenderScene(); 
    297  
    298                 query.EndQuery(); 
    299  
    300                 unsigned int pixelCount; 
    301                 // reenable other state 
    302                 pixelCount = query.GetQueryResult(); 
    303  
    304                 pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight()); 
    305                 if (mSnapErrorFrames && pErrorPixels > 0.01)  
    306                 { 
    307             char filename[256]; 
    308  
    309                         sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels); 
    310                         QImage im = toImage(); 
    311                         string str = mSnapPrefix + filename; 
    312                         QString qstr(str.c_str()); 
    313  
    314                         im.save(qstr, "PNG"); 
    315                         if (1)  
    316                         { 
    317                                 int x,y; 
    318                                 int lastIndex = -1; 
    319                                 for (y=0; y < im.height(); y++) 
    320                                 { 
    321                                         for (x=0; x < im.width(); x++)  
    322                                         { 
    323                                                 QRgb p = im.pixel(x,y); 
    324  
    325                                                 int index = qRed(p) + (qGreen(p)<<8) + (qBlue(p)<<16); 
    326                                                  
    327                                                 if (qGreen(p) != 255 && index!=0)  
    328                                                 { 
    329                                                         if (index != lastIndex)  
    330                                                         { 
    331                                                                 lastIndex = index; 
    332                                                         } 
    333                                                 } 
    334                                         } 
    335                                 } 
     89  float pErrorPixels = -1.0f; 
     90   
     91  glReadBuffer(GL_BACK); 
     92   
     93  //  mUseFalseColors = true; 
     94   
     95  mUseFalseColors = false; 
     96  unsigned int pixelCount; 
     97 
     98  //static int query = -1; 
     99  //if (query == -1) 
     100  //      glGenOcclusionQueriesNV(1, (unsigned int *)&query); 
     101 
     102  OcclusionQuery query; 
     103 
     104  ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint); 
     105  if (viewcell == NULL) 
     106        return 0.0f; 
     107 
     108  if (mDetectEmptyViewSpace) { 
     109        // now check whether any backfacing polygon would pass the depth test 
     110        SetupCamera(); 
     111        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     112        glEnable( GL_CULL_FACE ); 
     113        glCullFace(GL_BACK); 
     114 
     115        cout<<"RS "; 
     116        RenderScene(); 
     117         
     118        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
     119        glDepthMask(GL_FALSE); 
     120        glDisable( GL_CULL_FACE ); 
     121 
     122        query.BeginQuery(); 
     123         
     124        cout<<"RS "; 
     125        RenderScene(); 
     126        cout<<"RS3 "; 
     127         
     128        query.EndQuery(); 
     129         
     130        // at this point, if possible, go and do some other computation 
     131        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     132        glDepthMask(GL_TRUE); 
     133        glEnable( GL_CULL_FACE ); 
     134         
     135        // reenable other state 
     136        pixelCount = query.GetQueryResult(); 
     137        cout<<"RS4 "; 
     138         
     139        if (pixelCount > 0) 
     140          return -1.0f; // backfacing polygon found -> not a valid viewspace sample 
     141 
     142  } else 
     143        glDisable( GL_CULL_FACE ); 
     144         
     145 
     146  //  ViewCell *viewcell = NULL; 
     147   
     148  //  PrVs prvs; 
     149   
     150  //  mViewCellsManager->SetMaxFilterSize(0); 
     151  //  mViewCellsManager->GetPrVS(mViewPoint, prvs, mViewCellsManager->GetFilterWidth()); 
     152  //  viewcell = prvs.mViewCell; 
     153   
     154  ObjectPvs pvs; 
     155  if (1) { 
     156        pvs = viewcell->GetPvs(); 
     157  } else { 
     158        mViewCellsManager->ApplyFilter2(viewcell, 
     159                                                                        false, 
     160                                                                        1.0f, 
     161                                                                        pvs); 
     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 
     200   
     201  if (mSnapErrorFrames && pErrorPixels > 0.001f) { 
     202         
     203        char filename[256]; 
     204        sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels); 
     205        QImage im = toImage(); 
     206        string str = mSnapPrefix + filename; 
     207        QString qstr(str.c_str()); 
     208         
     209        im.save(qstr, "PNG"); 
     210        if (1) { //0 && mFrame == 1543) { 
     211          int x,y; 
     212          int lastIndex = -1; 
     213          for (y=0; y < im.height(); y++) 
     214                for (x=0; x < im.width(); x++) { 
     215                  QRgb p = im.pixel(x,y); 
     216                  int index = qRed(p) + (qGreen(p)<<8) + (qBlue(p)<<16); 
     217                  if (qGreen(p) != 255 && index!=0) { 
     218                        if (index != lastIndex) { 
     219                          //                            Debug<<"ei="<<index<<" "; 
     220                          lastIndex = index; 
    336221                        } 
    337  
    338                         mUseFalseColors = false; 
    339                         glPushAttrib(GL_CURRENT_BIT); 
    340                         glColor3f(0,1,0); 
    341                         glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    342                         SetupCamera(); 
    343                         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    344  
    345                         // Render PVS 
    346                         ObjectPvsIterator pit = viewcell->GetPvs().GetIterator(); 
    347  
    348                         while (pit.HasMoreEntries()) 
    349                         {                
    350                                 const ObjectPvsEntry &entry = pit.Next(); 
    351                                 Intersectable *obj = entry.mObject; 
    352  
    353                                 RenderIntersectable(obj); 
    354                         } 
    355  
    356                         im = toImage(); 
    357                         sprintf(filename, "error-frame-%04d-%0.5f-pvs.png", mFrame, pErrorPixels); 
    358                         str = mSnapPrefix + filename; 
    359                         qstr = str.c_str(); 
    360                         im.save(qstr, "PNG"); 
    361                         glPopAttrib(); 
    362                 } 
    363                 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    364         } 
    365  
    366         if (viewcell && mViewCellsManager->GetMaxFilterSize() > 0) 
    367                 mViewCellsManager->DeleteLocalMergeTree(viewcell); 
    368  
    369         return pErrorPixels; 
    370 } 
    371  
    372  
    373 void 
    374 QtGlRendererBuffer::ClearErrorBuffer() 
    375 { 
    376   for (int i=0; i < mPvsStatFrames; i++) { 
    377         mPvsErrorBuffer[i].mError = 1.0f; 
    378   } 
    379 } 
    380  
    381  
    382 void 
    383 QtGlRendererBuffer::EvalPvsStat() 
    384 { 
    385   mPvsStat.Reset(); 
    386   halton.Reset(); 
    387  
    388   makeCurrent(); 
    389  
    390  
    391   SetupProjection(GetWidth(), GetHeight()); 
    392  
    393    
    394   for (int i=0; i < mPvsStatFrames; i++) { 
    395         float err; 
    396         // set frame id for saving the error buffer 
    397         mFrame = i; 
    398         RandomViewPoint(); 
    399  
    400         // atlanta problematic frames: 325 525 691 1543 
    401 #if 0 
    402         if (mFrame != 325 && 
    403                 mFrame != 525 && 
    404                 mFrame != 691 && 
    405                 mFrame != 1543) 
    406           mPvsErrorBuffer[i] = -1; 
    407         else { 
    408           Debug<<"frame ="<<mFrame<<" vp="<<mViewPoint<<" vd="<<mViewDirection<<endl; 
    409         } 
    410 #endif 
    411         if (mPvsErrorBuffer[i].mError > 0.0f) { 
    412           int pvsSize; 
    413  
    414  
    415           float error = GetPixelError(pvsSize); 
    416           mPvsErrorBuffer[i].mError = error; 
    417           mPvsErrorBuffer[i].mPvsSize = pvsSize; 
    418  
    419           emit UpdatePvsErrorItem(i, 
    420                                                           mPvsErrorBuffer[i]); 
    421            
    422           cout<<"("<<i<<","<<mPvsErrorBuffer[i].mError<<")"; 
    423           //      swapBuffers(); 
    424         } 
    425          
    426         err = mPvsErrorBuffer[i].mError; 
    427          
    428         if (err >= 0.0f) { 
    429           if (err > mPvsStat.maxError) 
    430                 mPvsStat.maxError = err; 
    431           mPvsStat.sumError += err; 
    432           mPvsStat.sumPvsSize += mPvsErrorBuffer[i].mPvsSize; 
    433            
    434           if (err == 0.0f) 
    435                 mPvsStat.errorFreeFrames++; 
    436           mPvsStat.frames++; 
    437         } 
    438   } 
    439  
    440   glFinish(); 
    441   doneCurrent(); 
    442  
    443   cout<<endl<<flush; 
    444   //  mRenderingFinished.wakeAll(); 
    445 } 
    446  
    447  
    448  
    449  
    450  
    451  
    452  
    453 void QtGlRendererBuffer::SampleBeamContributions(Intersectable *sourceObject, 
    454                                                                                            Beam &beam, 
    455                                                                                            const int desiredSamples, 
    456                                                                                            BeamSampleStatistics &stat) 
    457 { 
    458         // TODO: should be moved out of here (not to be done every time) 
    459         // only back faces are interesting for the depth pass 
    460         glShadeModel(GL_FLAT); 
    461         glDisable(GL_LIGHTING); 
    462  
    463         // needed to kill the fragments for the front buffer 
    464         glEnable(GL_ALPHA_TEST); 
    465         glAlphaFunc(GL_GREATER, 0); 
    466  
    467         // assumes that the beam is constructed and contains kd-tree nodes 
    468         // and viewcells which it intersects 
    469    
    470    
    471         // Get the number of viewpoints to be sampled 
    472         // Now it is a sqrt but in general a wiser decision could be made. 
    473         // The less viewpoints the better for rendering performance, since less passes 
    474         // over the beam is needed. 
    475         // The viewpoints could actually be generated outside of the bounding box which 
    476         // would distribute the 'efective viewpoints' of the object surface and thus 
    477         // with a few viewpoints better sample the viewpoint space.... 
    478  
    479         //TODO: comment in 
    480         //int viewPointSamples = sqrt((float)desiredSamples); 
    481         int viewPointSamples = max(desiredSamples / (GetWidth() * GetHeight()), 1); 
    482          
    483         // the number of direction samples per pass is given by the number of viewpoints 
    484         int directionalSamples = desiredSamples / viewPointSamples; 
    485          
    486         Debug << "directional samples: " << directionalSamples << endl; 
    487         for (int i = 0; i < viewPointSamples; ++ i)  
    488         { 
    489                 Vector3 viewPoint = beam.mBox.GetRandomPoint(); 
    490                  
    491                 // perhaps the viewpoint should be shifted back a little bit so that it always lies 
    492                 // inside the source object 
    493                 // 'ideally' the viewpoints would be distributed on the soureObject surface, but this 
    494         // would require more complicated sampling (perhaps hierarchical rejection sampling of 
    495                 // the object surface is an option here - only the mesh faces which are inside the box 
    496                 // are considered as candidates)  
    497                  
    498                 SampleViewpointContributions(sourceObject, 
    499                                                                          viewPoint, 
    500                                                                          beam, 
    501                                                                          directionalSamples, 
    502                                                                          stat); 
    503         } 
    504  
    505  
    506         // note: 
    507         // this routine would be called only if the number of desired samples is sufficiently 
    508         // large - for other rss tree cells the cpu based sampling is perhaps more efficient 
    509         // distributing the work between cpu and gpu would also allow us to place more sophisticated 
    510         // sample distributions (silhouette ones) using the cpu and the jittered once on the GPU 
    511         // in order that thios scheme is working well the gpu render buffer should run in a separate 
    512         // thread than the cpu sampler, which would not be such a big problem.... 
    513  
    514         // disable alpha test again 
    515         glDisable(GL_ALPHA_TEST); 
    516 } 
    517  
    518  
    519  
    520 void QtGlRendererBuffer::SampleViewpointContributions(Intersectable *sourceObject, 
    521                                                                                                           const Vector3 viewPoint, 
    522                                                                                                           Beam &beam, 
    523                                                                                                           const int samples, 
    524                                                                                                           BeamSampleStatistics &stat) 
    525 { 
    526     // 1. setup the view port to match the desired samples 
    527         glViewport(0, 0, samples, samples); 
    528  
    529         // 2. setup the projection matrix and view matrix to match the viewpoint + beam.mDirBox 
    530         SetupProjectionForViewPoint(viewPoint, beam, sourceObject); 
    531  
    532  
    533         // 3. reset z-buffer to 0 and render the source object for the beam 
    534         //    with glCullFace(Enabled) and glFrontFace(GL_CW) 
    535         //    save result to the front depth map 
    536         //    the front depth map holds ray origins 
    537  
    538  
    539         // front depth buffer must be initialised to 0 
    540         float clearDepth; 
    541          
    542         glGetFloatv(GL_DEPTH_CLEAR_VALUE, &clearDepth); 
    543         glClearDepth(0.0f); 
    544         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 
    545  
    546  
    547         //glFrontFace(GL_CW); 
    548         glEnable(GL_CULL_FACE); 
    549         glCullFace(GL_FRONT); 
    550         glColorMask(0, 0, 0, 0); 
    551          
    552  
    553         // stencil is increased where the source object is located 
    554         glEnable(GL_STENCIL_TEST);       
    555         glStencilFunc(GL_ALWAYS, 0x1, 0x1); 
    556         glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); 
    557  
    558  
    559 #if 0 
    560         static int glSourceObjList = -1;          
    561         if (glSourceObjList != -1)  
    562         { 
    563                 glSourceObjList = glGenLists(1); 
    564                 glNewList(glSourceObjList, GL_COMPILE); 
    565  
    566                 RenderIntersectable(sourceObject); 
    567          
    568                 glEndList(); 
    569         } 
    570         glCallList(glSourceObjList); 
    571  
    572 #else 
    573         RenderIntersectable(sourceObject); 
    574  
    575 #endif   
    576  
    577          // copy contents of the front depth buffer into depth texture 
    578         glBindTexture(GL_TEXTURE_2D, frontDepthMap);     
    579         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, depthMapSize, depthMapSize); 
    580  
    581  
    582         // reset clear function 
    583         glClearDepth(clearDepth); 
    584  
    585          
    586          
    587         // 4. set up the termination depth buffer (= standard depth buffer) 
    588         //    only rays which have non-zero entry in the origin buffer are valid since 
    589         //    they realy start on the object surface (this is tagged by setting a 
    590         //    stencil buffer bit at step 3). 
    591          
    592         glStencilFunc(GL_EQUAL, 0x1, 0x1); 
    593         glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); 
    594  
    595         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    596         glDepthMask(1); 
    597  
    598         glEnable(GL_DEPTH_TEST); 
    599                  
    600         glEnable(GL_CULL_FACE); 
    601         glCullFace(GL_BACK); 
    602  
    603         // setup front depth buffer 
    604         glEnable(GL_TEXTURE_2D); 
    605          
    606         // bind pixel shader implementing the front depth buffer functionality 
    607         cgGLBindProgram(sCgFragmentProgram); 
    608         cgGLEnableProfile(sCgFragmentProfile); 
    609  
    610  
    611         // 5. render all objects inside the beam  
    612         //    we can use id based false color to read them back for gaining the pvs 
    613  
    614         glColorMask(1, 1, 1, 1); 
    615  
    616          
    617         // if objects not stored in beam => extract objects 
    618         if (beam.mFlags & !Beam::STORE_OBJECTS) 
    619         { 
    620                 vector<KdNode *>::const_iterator it, it_end = beam.mKdNodes.end(); 
    621  
    622                 Intersectable::NewMail(); 
    623                 for (it = beam.mKdNodes.begin(); it != it_end; ++ it) 
    624                 { 
    625                         mKdTree->CollectObjects(*it, beam.mObjects); 
     222                  } 
    626223                } 
    627224        } 
    628  
    629  
    630         //    (objects can be compiled to a gl list now so that subsequent rendering for 
    631         //    this beam is fast - the same hold for step 3) 
    632         //    Afterwards we have two depth buffers defining the ray origin and termination 
    633          
    634  
    635 #if 0 
    636         static int glObjList = -1;  
    637         if (glObjList != -1)  
    638         { 
    639                 glObjList = glGenLists(1); 
    640                 glNewList(glObjList, GL_COMPILE); 
    641          
    642                 ObjectContainer::const_iterator it, it_end = beam.mObjects.end(); 
    643                 for (it = beam.mObjects.begin(); it != it_end; ++ it) 
    644                 { 
    645                         // render all objects except the source object 
    646                         if (*it != sourceObject) 
    647                                 RenderIntersectable(*it); 
    648                 } 
    649                  
    650                 glEndList(); 
     225         
     226         
     227        mUseFalseColors = false; 
     228        glPushAttrib(GL_CURRENT_BIT); 
     229        glColor3f(0,1,0); 
     230        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     231        SetupCamera(); 
     232        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     233         
     234        // Render PVS 
     235        Intersectable::NewMail(); 
     236 
     237        ObjectPvsIterator it = pvs.GetIterator(); 
     238        for (; it.HasMoreEntries(); ) { 
     239          ObjectPvsEntry entry = it.Next(); 
     240          Intersectable *object = entry.mObject; 
     241          RenderIntersectable(object); 
    651242        } 
    652  
    653         glCallList(glObjList); 
    654 #else 
    655         ObjectContainer::const_iterator it, it_end = beam.mObjects.end(); 
    656         for (it = beam.mObjects.begin(); it != it_end; ++ it) 
    657         {        
    658                 // render all objects except the source object 
    659                 if (*it != sourceObject) 
    660                         RenderIntersectable(*it); 
    661         } 
    662 #endif 
    663          
    664     
    665  
    666         // 6. Use occlusion queries for all viewcell meshes associated with the beam -> 
    667         //     a fragment passes if the corresponding stencil fragment is set and its depth is 
    668         //     between origin and termination buffer 
    669  
    670         // create new queries if necessary 
    671         OcclusionQuery::GenQueries(mOcclusionQueries, (int)beam.mViewCells.size()); 
    672  
    673         // check whether any backfacing polygon would pass the depth test? 
    674         // matt: should check both back /front facing because of dual depth buffer 
    675         // and danger of cutting the near plane with front facing polys. 
    676          
    677         glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    678         glDepthMask(GL_FALSE); 
    679         glDisable(GL_CULL_FACE); 
    680  
    681    
    682         ViewCellContainer::const_iterator vit, vit_end = beam.mViewCells.end(); 
    683  
    684         int queryIdx = 0; 
    685  
    686         for (vit = beam.mViewCells.begin(); vit != vit_end; ++ vit) 
    687         { 
    688                 mOcclusionQueries[queryIdx ++]->BeginQuery(); 
    689  
    690                 RenderIntersectable(*vit); 
    691                  
    692                 mOcclusionQueries[queryIdx]->EndQuery(); 
    693  
    694                 ++ queryIdx; 
    695         } 
    696  
    697         // at this point, if possible, go and do some other computation 
    698          
    699         // 7. The number of visible pixels is the number of sample rays which see the source 
    700         //    object from the corresponding viewcell -> remember these values for later update 
    701         //   of the viewcell pvs - or update immediately? 
    702  
    703         queryIdx = 0; 
    704  
    705         for (vit = beam.mViewCells.begin(); vit != vit_end; ++ vit) 
    706         { 
    707                 // fetch queries 
    708                 unsigned int pixelCount = mOcclusionQueries[queryIdx ++]->GetQueryResult(); 
    709  
    710                 if (pixelCount) 
    711                         Debug << "view cell " << (*vit)->GetId() << " visible pixels: " << pixelCount << endl; 
    712         } 
    713          
    714  
    715         // 8. Copmpute rendering statistics 
    716         // In general it is not neccessary to remember to extract all the rays cast. I hope it 
    717         // would be sufficient to gain only the intergral statistics about the new contributions 
    718         // and so the rss tree would actually store no new rays (only the initial ones) 
    719         // the subdivision of the tree would only be driven by the statistics (the glrender could 
    720         // evaluate the contribution entropy for example) 
    721         // However might be an option to extract/store only those the rays which made a contribution 
    722         // (new viewcell has been discovered) or relative contribution greater than a threshold ...  
    723  
    724         ObjectContainer pvsObj; 
    725         stat.pvsSize = ComputePvs(beam.mObjects, pvsObj); 
    726          
    727         // to gain ray source and termination 
    728         // copy contents of ray termination buffer into depth texture 
    729         // and compare with ray source buffer 
    730 #if 0 
    731         VssRayContainer rays; 
    732  
    733         glBindTexture(GL_TEXTURE_2D, backDepthMap);      
    734         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, depthMapSize, depthMapSize); 
    735  
    736         ComputeRays(Intersectable *sourceObj, rays); 
    737  
    738 #endif 
    739  
    740         //////// 
    741         //-- cleanup 
    742  
    743         // reset gl state 
    744         glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    745         glDepthMask(GL_TRUE); 
    746         glEnable(GL_CULL_FACE); 
    747         glDisable(GL_STENCIL_TEST); 
    748         cgGLDisableProfile(sCgFragmentProfile); 
    749         glDisable(GL_TEXTURE_2D); 
    750  
    751         // remove objects from beam 
    752         if (beam.mFlags & !Beam::STORE_OBJECTS) 
    753                 beam.mObjects.clear(); 
    754 } 
    755  
    756  
    757 void QtGlRendererBuffer::SetupProjectionForViewPoint(const Vector3 &viewPoint,  
    758                                                                                                    const Beam &beam,  
    759                                                                                                    Intersectable *sourceObject) 
    760 { 
    761         float left, right, bottom, top, znear, zfar; 
    762  
    763         beam.ComputePerspectiveFrustum(left, right, bottom, top, znear, zfar, 
    764                                                                    mSceneGraph->GetBox()); 
    765  
    766         //Debug << left << " " << right << " " << bottom << " " << top << " " << znear << " " << zfar << endl; 
    767         glMatrixMode(GL_PROJECTION); 
    768         glLoadIdentity(); 
    769         glFrustum(left, right, bottom, top, znear, zfar); 
    770         //glFrustum(-1, 1, -1, 1, 1, 20000); 
    771  
    772     const Vector3 center = viewPoint + beam.GetMainDirection() * (zfar - znear) * 0.3f; 
    773         const Vector3 up =  
    774                 Normalize(CrossProd(beam.mPlanes[0].mNormal, beam.mPlanes[4].mNormal)); 
    775  
    776 #ifdef _DEBUG 
    777         Debug << "view point: " << viewPoint << endl; 
    778         Debug << "eye: " << center << endl; 
    779         Debug << "up: " << up << endl; 
    780 #endif 
    781  
    782         glMatrixMode(GL_MODELVIEW); 
    783         glLoadIdentity(); 
    784         gluLookAt(viewPoint.x, viewPoint.y, viewPoint.z,  
    785                           center.x, center.y, center.z,                    
    786                           up.x, up.y, up.z); 
    787 }                
    788  
    789  
    790 void QtGlRendererBuffer::InitGL() 
    791 { 
    792         makeCurrent();  
    793         GlRenderer::InitGL(); 
    794  
    795 #if 1 
    796         // initialise dual depth buffer textures 
    797         glGenTextures(1, &frontDepthMap); 
    798         glBindTexture(GL_TEXTURE_2D, frontDepthMap); 
    799          
    800         glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, depthMapSize,  
    801                 depthMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); 
    802         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    803         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    804         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 
    805         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 
    806  
    807         glGenTextures(1, &backDepthMap); 
    808         glBindTexture(GL_TEXTURE_2D, backDepthMap); 
    809          
    810         glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, depthMapSize,  
    811                 depthMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); 
    812         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    813         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    814         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 
    815         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 
    816  
    817         // cg initialization 
    818         cgSetErrorCallback(handleCgError); 
    819         sCgContext = cgCreateContext(); 
    820          
    821         if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1)) 
    822                 sCgFragmentProfile = CG_PROFILE_ARBFP1; 
    823         else  
    824         { 
    825           // try FP30 
    826           if (cgGLIsProfileSupported(CG_PROFILE_FP30)) 
    827             sCgFragmentProfile = CG_PROFILE_FP30; 
    828           else  
    829           { 
    830                   Debug << "Neither arbfp1 or fp30 fragment profiles supported on this system" << endl; 
    831                   exit(1); 
    832           } 
    833   } 
    834  
    835  
    836  sCgFragmentProgram = cgCreateProgramFromFile(sCgContext, 
    837                                                                                            CG_SOURCE, "../src/dual_depth.cg", 
    838                                                                                            sCgFragmentProfile, 
    839                                                                                            NULL,  
    840                                                                                            NULL); 
    841  
    842   if (!cgIsProgramCompiled(sCgFragmentProgram)) 
    843           cgCompileProgram(sCgFragmentProgram); 
    844  
    845   cgGLLoadProgram(sCgFragmentProgram); 
    846   cgGLBindProgram(sCgFragmentProgram); 
    847  
    848   Debug << "---- PROGRAM BEGIN ----\n" << 
    849           cgGetProgramString(sCgFragmentProgram, CG_COMPILED_PROGRAM) << "---- PROGRAM END ----\n"; 
    850  
    851  
    852   sCgDepthPeelingProgram =  
    853           cgCreateProgramFromFile(sCgContext, 
    854                                                           CG_SOURCE,  
    855                                                           "../src/depth_peeling.cg", 
    856                                                           sCgFragmentProfile, 
    857                                                           NULL,  
    858                                                           NULL); 
    859  
    860   if (!cgIsProgramCompiled(sCgDepthPeelingProgram)) 
    861           cgCompileProgram(sCgDepthPeelingProgram); 
    862  
    863   cgGLLoadProgram(sCgDepthPeelingProgram); 
    864   cgGLBindProgram(sCgDepthPeelingProgram); 
    865  
    866   Debug << "---- PROGRAM BEGIN ----\n"  
    867             << cgGetProgramString(sCgDepthPeelingProgram, CG_COMPILED_PROGRAM)  
    868                 << "---- PROGRAM END ----\n"; 
    869  
    870 #endif 
    871   doneCurrent(); 
    872 } 
    873  
    874  
    875 void QtGlRendererBuffer::ComputeRays(Intersectable *sourceObj, VssRayContainer &rays) 
    876 { 
    877         for (int i = 0; i < depthMapSize * depthMapSize; ++ i) 
    878         { 
    879                 //todo glGetTexImage() 
    880         } 
    881 } 
    882  
    883  
    884  
    885 int QtGlRendererBuffer::ComputePvs(ObjectContainer &objects,  
    886                                                                    ObjectContainer &pvs) const 
     243         
     244        im = toImage(); 
     245        sprintf(filename, "error-frame-%04d-%0.5f-pvs.png", mFrame, pErrorPixels); 
     246        str = mSnapPrefix + filename; 
     247        qstr = str.c_str(); 
     248        im.save(qstr, "PNG"); 
     249        glPopAttrib(); 
     250  } 
     251   
     252  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     253   
     254  return pErrorPixels; 
     255} 
     256 
     257int 
     258QtGlRendererBuffer::ComputePvs(ObjectContainer &objects,  
     259                                                           ObjectContainer &pvs) const 
    887260{ 
    888261        int pvsSize = 0; 
     
    924297} 
    925298 
    926  
    927  
    928 void 
    929 QtGlRendererWidget::SetupProjection(const int w, const int h, const float angle) 
    930 { 
    931   if (!mTopView) 
    932         GlRenderer::SetupProjection(w, h, angle); 
    933   else { 
    934         glViewport(0, 0, w, h); 
     299/////////////////////////////////////////////////////////////// 
     300/////////////////////////////////////////////////////////////// 
     301/////////////////////////////////////////////////////////////// 
     302/////////////////////////////////////////////////////////////// 
     303 
     304 
     305 
     306 
     307 
     308void 
     309QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle) 
     310{ 
     311  if (!mTopView) { 
     312        int ww = w; 
     313        int hh = h; 
     314        glViewport(0, 0, ww, hh); 
    935315        glMatrixMode(GL_PROJECTION); 
    936316        glLoadIdentity(); 
    937         gluPerspective(50.0, 1.0, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal())); 
     317        gluPerspective(angle, ww/(float)hh, 0.1, 2.0*Magnitude(mSceneGraph->GetBox().Diagonal())); 
    938318        glMatrixMode(GL_MODELVIEW); 
    939   } 
    940 } 
     319  } else { 
     320        int ww = w; 
     321        int hh = h; 
     322        glViewport(0, 0, ww, hh); 
     323        glMatrixMode(GL_PROJECTION); 
     324        glLoadIdentity(); 
     325        gluPerspective(50.0, ww/(float)hh, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal())); 
     326        glMatrixMode(GL_MODELVIEW); 
     327  } 
     328} 
     329 
     330 
    941331 
    942332void 
    943333QtGlRendererWidget::RenderPvs() 
    944334{ 
    945   SetupCamera(); 
    946   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    947    
     335         
     336  Intersectable::NewMail(); 
     337 
    948338  ViewCell *viewcell = NULL; 
    949339 
    950340  PrVs prvs; 
    951341   
    952   if (!mUseFilter) { 
     342  if (1 || !mUseFilter) { 
    953343        viewcell = mViewCellsManager->GetViewCell(mViewPoint, true); 
    954344  } else { 
    955           //  mViewCellsManager->SetMaxFilterSize(1); 
    956           mViewCellsManager->GetPrVS(mViewPoint, prvs, mViewCellsManager->GetFilterWidth()); 
    957           viewcell = prvs.mViewCell; 
    958   } 
    959  
    960   if (viewcell)  
    961   { 
    962           // copy the pvs so that it can be filtered... 
    963           ObjectPvs pvs = viewcell->GetPvs(); 
    964  
     345        //  mViewCellsManager->SetMaxFilterSize(1); 
     346        mViewCellsManager->GetPrVS(mViewPoint, prvs, mViewCellsManager->GetFilterWidth()); 
     347        viewcell = prvs.mViewCell; 
     348  } 
     349   
     350  if (viewcell) { 
     351        // copy the pvs so that it can be filtered... 
     352         
     353        //      mPvsCache.mPvs; 
     354         
     355        if (mPvsCache.mViewCell != viewcell) { 
     356          mPvsCache.Reset(); 
     357          mPvsCache.mViewCell = viewcell; 
     358           
    965359          if (mUseSpatialFilter) { 
    966                   mViewCellsManager->ApplySpatialFilter(mKdTree, 
    967                           mSpatialFilterSize* 
    968                           Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 
    969                           pvs); 
    970           } 
    971  
    972           // read back the texture 
    973           mPvsSize = pvs.GetSize(); 
    974  
    975           ObjectPvsIterator pit = pvs.GetIterator(); 
    976  
    977           while (pit.HasMoreEntries()) 
    978           {              
    979                   const ObjectPvsEntry &entry = pit.Next(); 
    980                   Intersectable *obj = entry.mObject; 
    981  
    982                   float visibility = log10(entry.mData.mSumPdf + 1) / 5.0f; 
    983                   glColor3f(visibility, 0.0f, 0.0f); 
    984                   mUseForcedColors = true; 
    985                   RenderIntersectable(obj); 
    986                   mUseForcedColors = false; 
    987           } 
    988  
    989           if (mRenderFilter)  
    990           { 
    991                   mWireFrame = true; 
    992                   RenderIntersectable(viewcell); 
    993                   mWireFrame = false; 
    994           } 
    995  
    996           if (mUseFilter) 
    997           { 
    998                   mViewCellsManager->DeleteLocalMergeTree(viewcell); 
    999           } 
    1000   }  
    1001   else  
    1002   { 
    1003           ObjectContainer::const_iterator oi = mObjects.begin(); 
    1004           for (; oi != mObjects.end(); oi++) 
    1005                   RenderIntersectable(*oi); 
     360                // 9.11. 2006 -> experiment with new spatial filter 
     361#if 0 
     362                mViewCellsManager->ApplySpatialFilter(mKdTree, 
     363                                                                                          mSpatialFilterSize* 
     364                                                                                          Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 
     365                                                                                          mPvsCache.mPvs); 
     366#else 
     367                // mSpatialFilter size is in range 0.001 - 0.1 
     368                mViewCellsManager->ApplyFilter2(viewcell, 
     369                                                                                mUseFilter, 
     370                                                                                100*mSpatialFilterSize, 
     371                                                                                mPvsCache.mPvs, 
     372                                                                                &mPvsCache.filteredBoxes 
     373                                                                                ); 
     374#endif 
     375          } else 
     376                mPvsCache.mPvs = viewcell->GetPvs(); 
     377           
     378          emit PvsUpdated(); 
     379        } 
     380 
     381        // Render PVS 
     382        if (mUseSpatialFilter && mRenderBoxes) { 
     383                for (int i=0; i < mPvsCache.filteredBoxes.size(); i++) 
     384                        RenderBox(mPvsCache.filteredBoxes[i]); 
     385        } else { 
     386                ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 
     387                 
     388                mPvsSize = mPvsCache.mPvs.GetSize(); 
     389                for (; it.HasMoreEntries(); ) { 
     390                        ObjectPvsEntry entry = it.Next(); 
     391                        Intersectable *object = entry.mObject; 
     392                         
     393                        if (mRenderVisibilityEstimates) { 
     394                                 
     395                                float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 
     396                                glColor3f(visibility, 0.0f, 0.0f); 
     397                                mUseForcedColors = true; 
     398                                RenderIntersectable(object); 
     399                                mUseForcedColors = false; 
     400                        } else { 
     401                                mUseForcedColors = false; 
     402                                RenderIntersectable(object); 
     403                        } 
     404                } 
     405        } 
     406 
     407        if (mRenderFilter) { 
     408          mWireFrame = true; 
     409          RenderIntersectable(viewcell); 
     410          glPushMatrix(); 
     411          glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z); 
     412          glScalef(5.0f,5.0f,5.0f); 
     413          glPushAttrib(GL_CURRENT_BIT); 
     414          glColor3f(1.0f, 0.0f, 0.0f); 
     415          gluSphere((::GLUquadric *)mSphere, 
     416                                                        1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6); 
     417          glPopAttrib(); 
     418          glPopMatrix(); 
     419          mWireFrame = false; 
     420        } 
     421         
     422        if (0 && mUseFilter) 
     423          mViewCellsManager->DeleteLocalMergeTree(viewcell); 
     424 
     425  } else { 
     426                ObjectContainer::const_iterator oi = mObjects.begin(); 
     427                for (; oi != mObjects.end(); oi++) 
     428                        RenderIntersectable(*oi); 
    1006429  } 
    1007430} 
     
    1016439  mUseFalseColors = true; 
    1017440 
    1018   SetupCamera(); 
    1019441  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    1020442   
     
    1154576  int x = e->pos().x(); 
    1155577  int y = e->pos().y(); 
     578 
     579  int diffx = -(mousePoint.x - x); 
     580  int diffy = -(mousePoint.y - y); 
    1156581   
    1157582  if (e->modifiers() & Qt::ControlModifier) { 
     
    1182607QtGlRendererWidget::resizeGL(int w, int h) 
    1183608{ 
    1184   SetupProjection(w, h); 
     609  SetupCameraProjection(w, h); 
    1185610  updateGL(); 
    1186611} 
     
    1191616  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    1192617 
    1193    
    1194   if (!mRenderViewCells) { 
    1195         if (mRenderErrors) 
     618  if (1) { 
     619        SetupCameraProjection(width(), height()); 
     620        SetupCamera(); 
     621         
     622        if (mRenderErrors) { 
    1196623          RenderErrors(); 
    1197         else 
     624        } else { 
    1198625          RenderPvs(); 
    1199         RenderInfo(); 
    1200   } else { 
    1201         RenderViewCells(); 
    1202          
    1203         mWireFrame = true; 
    1204         RenderScene(); 
    1205         mWireFrame = false; 
    1206          
    1207         RenderInfo(); 
    1208   } 
     626        } 
     627         
     628  } 
     629 
     630  RenderInfo(); 
    1209631 
    1210632  mFrame++; 
     633   
    1211634} 
    1212635 
     
    1250673} 
    1251674 
     675 
    1252676void 
    1253677QtGlRendererWidget::keyPressEvent ( QKeyEvent * e ) 
     
    1256680  case Qt::Key_T: 
    1257681        mTopView = !mTopView; 
    1258         SetupProjection(width(), height()); 
     682        SetupCameraProjection(width(), height()); 
    1259683        updateGL(); 
    1260684        break; 
     
    1277701   
    1278702 
    1279 QtGlRendererWidget::QtGlRendererWidget(SceneGraph *sceneGraph, 
    1280                                                                    ViewCellsManager *viewcells, 
    1281                                                                    KdTree *tree, 
    1282                                                                    QWidget * parent, 
    1283                                                                    const QGLWidget * shareWidget, 
    1284                                                                    Qt::WFlags f 
    1285                                                                    ) 
     703QtGlRendererWidget::QtGlRendererWidget( 
     704                                                                           SceneGraph *sceneGraph, 
     705                                                                           ViewCellsManager *viewcells, 
     706                                                                           KdTree *tree, 
     707                                                                           QWidget * parent, 
     708                                                                           const QGLWidget * shareWidget, 
     709                                                                           Qt::WFlags f 
     710                                                                           ) 
    1286711  : 
    1287712  GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f) 
    1288713{ 
     714  mPreprocessorThread = NULL; 
    1289715  mTopView = false; 
    1290716  mRenderViewCells = false; 
     
    1293719  mCutScene = false; 
    1294720  mRenderErrors = false; 
     721  mRenderBoxes = false; 
    1295722  mRenderFilter = true; 
     723  mRenderVisibilityEstimates = false; 
     724  mTransferFunction = 0.2f; 
    1296725 
    1297726  bool tmp; 
     
    1302731  Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", 
    1303732                                                        tmp ); 
    1304  
    1305733  mUseSpatialFilter = tmp; 
    1306734 
     
    1310738  mPvsSize = 0; 
    1311739  mRenderError = 0.0f; 
     740  mShowRays = false; 
     741   
    1312742  mControlWidget = new QtRendererControlWidget(NULL); 
    1313743   
    1314744  connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int))); 
     745  connect(mControlWidget, 
     746                  SIGNAL(SetTransferFunction(int)), 
     747                  this, 
     748                  SLOT(SetTransferFunction(int))); 
     749  connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs())); 
     750  connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility())); 
     751  connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation())); 
     752  connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this, 
     753                  SLOT(SetRandomViewPoint())); 
     754 
    1315755  connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); 
    1316756  connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int))); 
     
    1326766  connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool))); 
    1327767  connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool))); 
     768  connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool))); 
    1328769  connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool))); 
     770  connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)), 
     771                  this, SLOT(SetRenderVisibilityEstimates(bool))); 
    1329772  connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool))); 
    1330773  connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)), 
    1331774                  this, SLOT(SetUseSpatialFilter(bool))); 
    1332775 
    1333    
     776  connect(mControlWidget, 
     777                  SIGNAL(SetShowRays(bool)), 
     778                  this, 
     779                  SLOT(SetShowRays(bool))); 
     780 
     781  resize(1000, 500); 
    1334782  mControlWidget->show(); 
    1335783} 
    1336784 
    1337  
    1338 void 
    1339 QtGlRendererWidget::RenderInfo() 
    1340 { 
    1341   QString s; 
    1342   int vc = 0; 
    1343    
    1344   if (mViewCellsManager) 
    1345           vc = (int)mViewCellsManager->GetViewCells().size(); 
    1346  
    1347   int filter = 0; 
    1348   if (mViewCellsManager) 
    1349         filter = mViewCellsManager->GetMaxFilterSize(); 
    1350  
    1351   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 %", 
    1352                         mFrame, 
    1353                         mViewPoint.x, 
    1354                         mViewPoint.y, 
    1355                         mViewPoint.z, 
    1356                         mViewDirection.x, 
    1357                         mViewDirection.y, 
    1358                         mViewDirection.z, 
    1359                         vc, 
    1360  
    1361                         filter, 
    1362                         mPvsSize, 
    1363                         mRenderError*100.0f 
    1364                         ); 
    1365    
    1366   glColor3f(0.0f,0.0f,0.0f); 
    1367   renderText(0,20,s); 
    1368    
    1369   if (mShowRenderCost) { 
     785void 
     786QtGlRendererWidget::UpdateAllPvs() 
     787{ 
     788  // $$ does not work so far:( 
     789  mViewCellsManager->UpdatePvsForEvaluation(); 
     790  //    mViewCellsManager->FinalizeViewCells(false); 
     791} 
     792 
     793void 
     794QtGlRendererWidget::ComputeVisibility() 
     795{ 
     796  cerr<<"Compute Visibility called!\n"<<endl; 
     797  if (!mPreprocessorThread->isRunning()) 
     798        mPreprocessorThread->RunThread(); 
     799} 
     800 
     801void 
     802QtGlRendererWidget::StopComputation() 
     803{ 
     804  cerr<<"stop computation called!\n"<<endl; 
     805  mViewCellsManager->GetPreprocessor()->mStopComputation = true; 
     806} 
     807 
     808void 
     809QtGlRendererWidget::SetRandomViewPoint() 
     810{ 
     811  cerr<<"stop computation called!\n"<<endl; 
     812  mViewCellsManager->GetViewPoint(mViewPoint); 
     813  updateGL(); 
     814} 
     815 
     816void 
     817QtGlRendererWidget::RenderRenderCost() 
     818{ 
    1370819        static vector<float> costFunction; 
    1371820        static float maxCost = -1; 
     
    1377826                for (int i=0;  i < costFunction.size(); i++) { 
    1378827                  //              cout<<i<<":"<<costFunction[i]<<" "; 
     828                  // update cost function to an absolute value based on the total geometry count 
     829                  costFunction[i]*=mSceneGraph->GetRoot()->mGeometry.size(); 
    1379830                  if (costFunction[i] > maxCost) 
    1380831                        maxCost = costFunction[i]; 
     
    1389840        if (currentPos < costFunction.size()) 
    1390841          currentCost = costFunction[currentPos]; 
    1391 #if 0    
     842#if 1    
    1392843        cout<<"costFunction.size()="<<costFunction.size()<<endl; 
    1393844        cout<<"CP="<<currentPos<<endl; 
     
    1396847#endif 
    1397848        if (costFunction.size()) { 
     849          float scaley = 1.0f/log10(maxCost); 
     850          float scalex = 1.0f/(float)costFunction.size(); 
     851 
    1398852          glDisable(GL_DEPTH_TEST); 
    1399853          // init ortographic projection 
    1400854          glMatrixMode(GL_PROJECTION); 
     855           
    1401856          glPushMatrix(); 
    1402857           
     
    1414869           
    1415870          for (int i=0;  i < costFunction.size(); i++) { 
    1416                 float x =  i/(float)costFunction.size(); 
    1417                 float y = costFunction[i]/(maxCost*0.5f); 
     871                float x =  i*scalex; 
     872                float y = log10(costFunction[i])*scaley; 
    1418873                glVertex3f(x,y,0.0f); 
    1419874          } 
     
    1422877          glColor3f(1.0f,0,0); 
    1423878          glBegin(GL_LINES); 
    1424           float x =  currentPos/(float)costFunction.size(); 
     879          float x =  currentPos*scalex; 
    1425880          glVertex3f(x,0.0,0.0f); 
    1426881          glVertex3f(x,1.0f,0.0f); 
     
    1437892 
    1438893          glBegin(GL_LINES); 
    1439           for (int i=0;  i < 50000 && i < costFunction.size(); i+=10000) { 
    1440                 float x =  i/(float)costFunction.size(); 
     894          for (int i=0;  i < costFunction.size(); i += 1000) { 
     895                float x =  i*scalex; 
    1441896                glVertex3f(x,0.0,0.0f); 
    1442897                glVertex3f(x,1.0f,0.0f); 
    1443898          } 
    1444899 
    1445           for (int i=0;  i < maxCost; i+=100) { 
    1446                 float y = i/(maxCost*0.5f); 
    1447                 glVertex3f(0,y,0.0f); 
    1448                 glVertex3f(1,y,0.0f); 
     900          for (int i=0;  pow(10.0f, i) < maxCost; i+=1) { 
     901                float y = i*scaley; 
     902                //              QString s; 
     903                //              s.sprintf("%d", (int)pow(10,i)); 
     904                //              renderText(width()/2+5, y*height(), s); 
     905                glVertex3f(0.0f, y, 0.0f); 
     906                glVertex3f(1.0f, y, 0.0f); 
    1449907          } 
    1450908 
     
    1459917 
    1460918        } 
    1461   } 
     919   
     920 
     921 
     922} 
     923 
     924void 
     925QtGlRendererWidget::RenderInfo() 
     926{ 
     927   
     928  QString s; 
     929  int vc = 0; 
     930  if (mViewCellsManager) 
     931        vc = mViewCellsManager->GetViewCells().size(); 
     932  int filter = 0; 
     933  if (mViewCellsManager) 
     934        filter = mViewCellsManager->GetMaxFilterSize(); 
     935 
     936  glColor3f(1.0f,1.0f,1.0f); 
     937 
     938  s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)", 
     939                        mFrame, 
     940                        mViewPoint.x, 
     941                        mViewPoint.y, 
     942                        mViewPoint.z, 
     943                        mViewDirection.x, 
     944                        mViewDirection.y, 
     945                        mViewDirection.z 
     946                        ); 
     947 
     948  renderText(20,20,s); 
     949 
     950  s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f\%", 
     951                        vc, 
     952                        filter, 
     953                        mPvsSize, 
     954                        mRenderError*100.0f); 
     955 
     956 
     957  renderText(20,40,s); 
     958 
     959   
     960 
     961   
    1462962} 
    1463963 
     
    1466966QtGlRendererWidget::SetViewCellGranularity(int number) 
    1467967{ 
    1468   if (mViewCellsManager)  
     968  if (mViewCellsManager) { 
    1469969        //      mViewCellsManager->SetMaxFilterSize(number); 
    1470970    mViewCellsManager->CollectViewCells(number); 
    1471971 
     972        // $$ does not work so far:( 
     973        //      mViewCellsManager->UpdatePvsForEvaluation(); 
     974        //      mViewCellsManager->FinalizeViewCells(false); 
     975  } 
    1472976  updateGL(); 
    1473977} 
     
    1478982  if (mViewCellsManager)  
    1479983        mViewCellsManager->SetMaxFilterSize(number); 
     984  mPvsCache.Reset(); 
    1480985  updateGL(); 
    1481986} 
     
    1485990{ 
    1486991  mSpatialFilterSize = 1e-3*number; 
     992  mPvsCache.Reset(); 
    1487993  updateGL(); 
    1488994} 
     
    15131019QtGlRendererWidget::RenderViewCells() 
    15141020{ 
    1515         mUseFalseColors = true; 
    1516  
    1517         SetupCamera(); 
    1518         glEnable(GL_CULL_FACE); 
    1519         //glDisable(GL_CULL_FACE); 
    1520         glCullFace(GL_FRONT); 
    1521         double eq[4]; 
    1522         eq[0] = mSceneCutPlane.mNormal.x; 
    1523         eq[1] = mSceneCutPlane.mNormal.y; 
    1524         eq[2] = mSceneCutPlane.mNormal.z; 
    1525         eq[3] = mSceneCutPlane.mD; 
    1526  
    1527         if (mCutViewCells)  
    1528         { 
    1529                 glClipPlane(GL_CLIP_PLANE0, eq); 
    1530                 glEnable(GL_CLIP_PLANE0); 
     1021  mUseFalseColors = true; 
     1022 
     1023  glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT); 
     1024   
     1025  glEnable(GL_CULL_FACE); 
     1026  //glDisable(GL_CULL_FACE); 
     1027  glCullFace(GL_FRONT); 
     1028  double eq[4]; 
     1029  eq[0] = mSceneCutPlane.mNormal.x; 
     1030  eq[1] = mSceneCutPlane.mNormal.y; 
     1031  eq[2] = mSceneCutPlane.mNormal.z; 
     1032  eq[3] = mSceneCutPlane.mD; 
     1033 
     1034  if (mCutViewCells) { 
     1035        glClipPlane(GL_CLIP_PLANE0, eq); 
     1036        glEnable(GL_CLIP_PLANE0); 
     1037  } 
     1038   
     1039  int i; 
     1040  ViewCellContainer &viewcells = mViewCellsManager->GetViewCells(); 
     1041  int maxPvs = -1; 
     1042  for (i=0; i < viewcells.size(); i++)  
     1043  { 
     1044        ViewCell *vc = viewcells[i]; 
     1045 
     1046        //const int p = vc->GetPvs().CountObjectsInPvs(); 
     1047        const int p = vc->GetPvs().GetSize(); 
     1048        if (p > maxPvs) 
     1049          maxPvs = p; 
     1050  } 
     1051 
     1052 
     1053  for (i=0; i < viewcells.size(); i++) { 
     1054        ViewCell *vc = viewcells[i]; 
     1055        //      Mesh *m = vc->GetMesh(); 
     1056 
     1057 
     1058        RgbColor c; 
     1059 
     1060        if (!mShowPvsSizes) { 
     1061          mWireFrame = true; 
     1062          c = vc->GetColor(); 
     1063        } else { 
     1064          //      const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().CountObjectsInPvs() / (float)maxPvs); 
     1065          const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().GetSize() / (float)maxPvs); 
     1066          c = RgbColor(importance, 1.0f - importance, 0.0f); 
    15311067        } 
    1532  
    1533         //int i; 
    1534         ViewCellContainer &viewCells = mViewCellsManager->GetViewCells(); 
    1535         float maxPvs = -1; 
    1536         ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    1537  
    1538         for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    1539         { 
    1540                 ViewCell *vc = *vit; 
    1541                 const float p = vc->GetPvs().EvalPvsCost(); 
    1542                 if (p > maxPvs) 
    1543                         maxPvs = p; 
    1544         } 
    1545  
    1546         for (vit = viewCells.begin(); vit != vit_end; ++ vit)  
    1547         { 
    1548                 ViewCell *vc = *vit; 
    1549  
    1550                 RgbColor c; 
    1551  
    1552                 if (!mShowPvsSizes)  
    1553                 { 
    1554                         c = vc->GetColor(); 
    1555                 } 
    1556                 else  
    1557                 { 
    1558                         const float importance = (float)vc->GetPvs().EvalPvsCost() / (float)maxPvs; 
    1559                         c = RgbColor(importance, 1.0f - importance, 0.0f); 
    1560                 } 
    1561  
    1562                 glColor3f(c.r, c.g, c.b); 
    1563  
    1564                 RenderViewCell(vc); 
    1565         } 
    1566  
    1567         glDisable(GL_CLIP_PLANE0); 
     1068        glColor3f(c.r, c.g, c.b); 
     1069         
     1070        RenderViewCell(vc); 
     1071  } 
     1072 
     1073  mUseFalseColors = false; 
     1074  mWireFrame = false; 
     1075 
     1076  glPopAttrib(); 
     1077   
    15681078} 
    15691079 
     
    15731083 
    15741084/***********************************************************************/ 
    1575 /*                     QtGlDebuggerWidget implementation                           */ 
     1085/*                     QtGlDebuggerWidget implementation                                   */ 
    15761086/***********************************************************************/ 
    15771087 
     
    16121122  QLabel *label = new QLabel("Granularity"); 
    16131123  vbox->layout()->addWidget(label); 
    1614  
     1124   
    16151125  QSlider *slider = new QSlider(Qt::Horizontal, vbox); 
    16161126  vl->addWidget(slider); 
     
    16201130  slider->setValue(200); 
    16211131 
     1132   
    16221133  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int))); 
    16231134 
     1135  label = new QLabel("Transfer function"); 
     1136  vbox->layout()->addWidget(label); 
     1137   
     1138  slider = new QSlider(Qt::Horizontal, vbox); 
     1139  vl->addWidget(slider); 
     1140  slider->show(); 
     1141  slider->setRange(1, 1000); 
     1142  slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 
     1143  slider->setValue(100); 
     1144 
     1145   
     1146  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int))); 
     1147 
     1148  { 
     1149        QPushButton *button = new QPushButton("Update all PVSs", vbox); 
     1150        vbox->layout()->addWidget(button); 
     1151        connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs())); 
     1152  } 
     1153   
     1154   
    16241155  label = new QLabel("Filter size"); 
    16251156  vbox->layout()->addWidget(label); 
     
    16591190  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool))); 
    16601191 
     1192  cb = new QCheckBox("Render cost curve", hbox); 
     1193  hlayout->addWidget(cb); 
     1194  cb->setChecked(false); 
     1195  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool))); 
     1196 
    16611197  cb = new QCheckBox("Show render cost", hbox); 
    16621198  hlayout->addWidget(cb); 
    16631199  cb->setChecked(false); 
    1664   connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool))); 
    1665  
    1666   cb = new QCheckBox("Show pvs sizes", hbox); 
     1200  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool))); 
     1201 
     1202  cb = new QCheckBox("Show rays", hbox); 
    16671203  hlayout->addWidget(cb); 
    16681204  cb->setChecked(false); 
    1669   connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool))); 
     1205  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool))); 
    16701206 
    16711207  vbox->resize(800,100); 
     
    16781214  vbox->setLayout(vl); 
    16791215 
     1216 
     1217 
     1218  cb = new QCheckBox("Cut view cells", vbox); 
     1219  vbox->layout()->addWidget(cb); 
     1220  cb->setChecked(false); 
     1221  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool))); 
    16801222 
    16811223 
     
    16891231  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int))); 
    16901232 
     1233 
     1234  cb = new QCheckBox("Cut scene", vbox); 
     1235  vbox->layout()->addWidget(cb); 
     1236  cb->setChecked(false); 
     1237  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool))); 
     1238 
     1239  cb = new QCheckBox("Render boxes", vbox); 
     1240  vbox->layout()->addWidget(cb); 
     1241  cb->setChecked(false); 
     1242  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool))); 
     1243 
     1244  cb = new QCheckBox("Render visibility estimates", vbox); 
     1245  vbox->layout()->addWidget(cb); 
     1246  cb->setChecked(false); 
     1247  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool))); 
     1248 
     1249   
    16911250  cb = new QCheckBox("Render errors", vbox); 
    16921251  vbox->layout()->addWidget(cb); 
     
    16941253  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool))); 
    16951254 
     1255   
     1256  bool tmp; 
     1257 
    16961258  cb = new QCheckBox("Use filter", vbox); 
    16971259  vbox->layout()->addWidget(cb); 
    1698   cb->setChecked(true); 
     1260  Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp ); 
     1261  cb->setChecked(tmp); 
    16991262  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool))); 
    17001263 
     1264   
    17011265  cb = new QCheckBox("Use spatial filter", vbox); 
    17021266  vbox->layout()->addWidget(cb); 
    1703   cb->setChecked(true); 
     1267  Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", 
     1268                                                                                        tmp ); 
     1269  cb->setChecked(tmp); 
    17041270  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool))); 
    17051271 
     
    17101276 
    17111277 
    1712   cb = new QCheckBox("Cut view cells", vbox); 
    1713   vbox->layout()->addWidget(cb); 
    1714   cb->setChecked(false); 
    1715   connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool))); 
    1716  
    1717   cb = new QCheckBox("Cut scene", vbox); 
    1718   vbox->layout()->addWidget(cb); 
    1719   cb->setChecked(false); 
    1720   connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool))); 
    17211278 
    17221279   
     
    17351292  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool))); 
    17361293 
     1294 
     1295 
    17371296  vbox = new QGroupBox("PVS Errors", this); 
    17381297  layout()->addWidget(vbox); 
    1739  
     1298   
    17401299  vl = new QVBoxLayout; 
    17411300  vbox->setLayout(vl); 
    17421301 
    1743   mPvsErrorWidget = new QListWidget(vbox); 
    1744   vbox->layout()->addWidget(mPvsErrorWidget); 
    1745    
    1746   connect(mPvsErrorWidget, 
    1747                   SIGNAL(doubleClicked(const QModelIndex &)), 
    1748                   this, 
    1749                   SLOT(PvsErrorClicked(const QModelIndex &))); 
    1750    
    1751   QPushButton *button = new QPushButton("Next Error Frame", vbox); 
     1302  QPushButton *button = new QPushButton("Compute Visibility", vbox); 
    17521303  vbox->layout()->addWidget(button); 
    1753   connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void))); 
    1754  
     1304  connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility())); 
     1305 
     1306  button = new QPushButton("Stop Computation", vbox); 
     1307  vbox->layout()->addWidget(button); 
     1308  connect(button, SIGNAL(clicked()), SLOT(StopComputation())); 
     1309 
     1310  button = new QPushButton("Set Random View Point", vbox); 
     1311  vbox->layout()->addWidget(button); 
     1312  connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint())); 
     1313 
     1314 
     1315  if (0) { 
     1316        vbox = new QGroupBox("PVS Errors", this); 
     1317        layout()->addWidget(vbox); 
     1318         
     1319        vl = new QVBoxLayout; 
     1320        vbox->setLayout(vl); 
     1321         
     1322        mPvsErrorWidget = new QListWidget(vbox); 
     1323        vbox->layout()->addWidget(mPvsErrorWidget); 
     1324         
     1325        connect(mPvsErrorWidget, 
     1326                        SIGNAL(doubleClicked(const QModelIndex &)), 
     1327                        this, 
     1328                        SLOT(PvsErrorClicked(const QModelIndex &))); 
     1329         
     1330        QPushButton *button = new QPushButton("Next Error Frame", vbox); 
     1331        vbox->layout()->addWidget(button); 
     1332        connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void))); 
     1333  } 
     1334   
    17551335  setWindowTitle("Preprocessor Control Widget"); 
    17561336  adjustSize(); 
     
    17581338 
    17591339 
     1340 
     1341 
    17601342void 
    17611343QtRendererControlWidget::FocusNextPvsErrorFrame(void) 
     
    17671349void 
    17681350QtRendererControlWidget::UpdatePvsErrorItem(int row, 
    1769                                                                                         GlRendererBuffer::PvsErrorEntry &pvsErrorEntry) 
     1351                                                                                  GlRendererBuffer::PvsErrorEntry &pvsErrorEntry) 
    17701352{ 
    17711353 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h

    r1940 r1942  
    44#include <QtOpenGL> 
    55#include <QWaitCondition> 
     6 
     7//#include <QGLPixelBuffer> 
    68 
    79#include "Vector3.h" 
     
    1113#include "GlRenderer.h" 
    1214#include "Beam.h" 
    13  
     15#include "QtPreprocessorThread.h" 
    1416class QWidget; 
     17//class QtPreprocessorThread; 
    1518 
    1619namespace GtpVisibilityPreprocessor { 
     
    2932class TransformedMeshInstance; 
    3033 
     34 
    3135struct VssRayContainer; 
    3236struct PvsRenderStatistics;  
     
    3438 
    3539 
    36 class __declspec(dllexport) QtGlRendererBuffer: public QObject, public QGLPixelBuffer, public GlRendererBuffer 
     40class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer 
    3741{ 
    3842        Q_OBJECT 
    39  
    4043public: 
    4144        QtGlRendererBuffer(const int w, 
    42                                            const int h, 
    43                                            SceneGraph *sceneGraph, 
    44                                            ViewCellsManager *viewcells, 
    45                                            KdTree *tree); 
    46  
    47         ~QtGlRendererBuffer(); 
    48  
    49         /** Evaluates render cost of a point sample. 
    50         @param sample the render cost sample to be evaluated 
    51         @param useOcclusionQueries if occlusion queries should be used or item buffer 
    52         @param threshold number of pixels / samples from where an object is considered visible. 
    53         */ 
    54         void EvalRenderCostSample(RenderCostSample &sample, 
    55                 const bool useOcclusionQueries, 
    56                 const int threshold); 
    57  
    58         /** Evaluates render cost of a number of point samples. The point samples 
    59         are distributed uniformly over the defined view space. 
    60  
    61         @param numSamples the number of point samples taken 
    62         @param samples stores the taken point samples in a container 
    63         @param useOcclusionQueries if occlusion queries should be used or item buffer 
    64         @param threshold number of pixels / samples from where an object is considered visible. 
    65         */ 
    66         void SampleRenderCost(const int numSamples,  
    67                 vector<RenderCostSample> &samples, 
    68                 const bool useOcclusionQueries, 
    69                 const int threshold = 0); 
    70  
    71         void 
    72                 EvalPvsStat(); 
    73  
    74         void 
    75                 ClearErrorBuffer(); 
    76  
    77         virtual int GetWidth() const { return width(); } 
    78         virtual int GetHeight() const { return height(); } 
    79  
    80         void SampleBeamContributions( 
    81                         Intersectable *sourceObject, 
    82                         Beam &beam, 
    83                         const int samples, 
    84                         BeamSampleStatistics &stat 
    85                 ); 
    86  
    87         void 
    88                 SampleViewpointContributions( 
    89                         Intersectable *sourceObject, 
    90                         const Vector3 viewPoint, 
    91                         Beam &beam, 
    92                         const int desiredSamples, 
    93                         BeamSampleStatistics &stat 
    94                 ); 
    95  
    96         void InitGL(); 
    97  
    98         /** Computes rays from information gained with hw sampling 
    99         */ 
    100         void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays); 
    101  
    102         float GetPixelError(int &pvsSize); 
    103  
    104         int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const; 
    105  
    106  
    107 private: 
    108  
    109         void SetupProjectionForViewPoint(const Vector3 &viewPoint,  
    110                                                                          const Beam &beam,  
    111                                                                          Intersectable *sourceObject); 
    112  
    113  
    114 public: 
    115 signals: 
    116         void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &); 
    117 }; 
    118  
    119  
    120 class __declspec(dllexport) QtRendererControlWidget : public QWidget 
     45                const int h, 
     46                SceneGraph *sceneGraph, 
     47                ViewCellsManager *viewcells, 
     48                KdTree *tree); 
     49 
     50  ~QtGlRendererBuffer() {} 
     51 
     52  virtual void MakeCurrent(); 
     53  virtual void DoneCurrent(); 
     54 
     55  virtual int GetWidth() const { return width(); } 
     56  virtual int GetHeight() const { return height(); } 
     57 
     58  int ComputePvs() const { return 0; } 
     59   
     60  float 
     61  GetPixelError(int &pvsSize); 
     62   
     63  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const; 
     64      
     65   
     66   
     67   
     68public: 
     69  signals: 
     70  void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &); 
     71}; 
     72 
     73 
     74class QtRendererControlWidget : public QWidget 
    12175{ 
    122         Q_OBJECT 
    123 public: 
    124  
    125         QListWidget *mPvsErrorWidget; 
    126  
    127         QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0); 
    128  
    129 public slots: 
    130  
    131         void FocusNextPvsErrorFrame(); 
    132         void UpdatePvsErrorItem(int i, 
    133                 GlRendererBuffer::PvsErrorEntry &); 
    134  
    135 signals: 
    136  
    137         void SetViewCellGranularity(int); 
    138         void SetSceneCut(int); 
    139         void SetTopDistance(int); 
    140         void SetVisibilityFilterSize(int); 
    141         void SetSpatialFilterSize(int); 
    142  
    143         void SetRenderFilter(bool); 
    144         void SetUseFilter(bool); 
    145         void SetUseSpatialFilter(bool); 
    146         void SetRenderErrors(bool); 
    147         void SetShowViewCells(bool); 
    148         void SetShowRenderCost(bool); 
    149         void SetShowPvsSizes(bool); 
    150         void SetTopView(bool); 
    151         void SetCutViewCells(bool); 
    152         void SetCutScene(bool); 
    153  
    154  
    155 }; 
    156  
    157  
    158 class __declspec(dllexport) QtGlRendererWidget : public QGLWidget, public GlRendererWidget 
     76  Q_OBJECT 
     77public: 
     78 
     79  QListWidget *mPvsErrorWidget; 
     80 
     81  QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0); 
     82 
     83  public slots: 
     84 
     85  void FocusNextPvsErrorFrame(); 
     86  void UpdatePvsErrorItem(int i, 
     87                                                  GlRendererBuffer::PvsErrorEntry &); 
     88 
     89  signals: 
     90 
     91  void ComputeVisibility(); 
     92  void StopComputation(); 
     93  void SetRandomViewPoint(); 
     94  void UpdateAllPvs(); 
     95  void SetViewCellGranularity(int); 
     96  void SetTransferFunction(int); 
     97  void SetSceneCut(int); 
     98  void SetTopDistance(int); 
     99  void SetVisibilityFilterSize(int); 
     100  void SetSpatialFilterSize(int); 
     101 
     102  void SetShowRays(bool); 
     103  void SetRenderFilter(bool); 
     104  void SetRenderVisibilityEstimates(bool); 
     105  void SetUseFilter(bool); 
     106  void SetUseSpatialFilter(bool); 
     107  void SetRenderErrors(bool); 
     108  void SetRenderBoxes(bool); 
     109  void SetShowViewCells(bool); 
     110  void SetShowRenderCost(bool); 
     111  void SetShowPvsSizes(bool); 
     112  void SetTopView(bool); 
     113  void SetCutViewCells(bool); 
     114  void SetCutScene(bool); 
     115 
     116}; 
     117 
     118 
     119class QtGlRendererWidget : public QGLWidget, public GlRendererWidget 
    159120{ 
    160         Q_OBJECT 
    161 public: 
    162  
    163         // point of the last mouse click used for movement in the scene 
    164         Vector3 mousePoint; 
    165  
    166         bool mTopView; 
    167         bool mRenderViewCells; 
    168         bool mCutViewCells; 
    169         bool mCutScene; 
    170         bool mRenderErrors; 
    171         bool mRenderFilter; 
    172         bool mUseFilter; 
    173         bool mUseSpatialFilter; 
    174         bool mShowRenderCost; 
    175  
    176         bool mShowPvsSizes; 
    177         float mSpatialFilterSize; 
    178  
    179         Plane3 mSceneCutPlane; 
    180         float mTopDistance; 
    181  
    182         // some statistics 
    183         int mPvsSize; 
    184         float mRenderError; 
    185  
    186         QtRendererControlWidget *mControlWidget; 
    187  
    188         QtGlRendererWidget(SceneGraph *sceneGraph, 
    189                 ViewCellsManager *viewcells, 
    190                 KdTree *tree, 
    191                 QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0 
    192                 ); 
    193  
    194         QtGlRendererWidget() {}; 
    195  
    196         virtual void SetupCamera(); 
    197  
    198         void initializeGL() { 
    199                 InitGL(); 
    200         } 
    201         void resizeGL(int w, int h); 
    202         void paintGL(); 
    203         void timerEvent(QTimerEvent *) { 
    204                 update(); 
    205         } 
    206  
    207         void mousePressEvent(QMouseEvent *); 
    208         void mouseReleaseEvent(QMouseEvent *); 
    209         void mouseMoveEvent(QMouseEvent *); 
    210  
    211         void keyPressEvent ( QKeyEvent * e ) ; 
    212  
    213         void 
    214                 RenderPvs(); 
    215  
    216         float 
    217                 RenderErrors(); 
    218         void 
    219                 RenderInfo(); 
    220  
    221         virtual int GetWidth() const { return width(); } 
    222         virtual int GetHeight() const { return height(); } 
    223  
    224         virtual void 
    225                 SetupProjection(const int w, const int h, const float angle = 70.0f); 
    226  
    227         void 
    228                 RenderViewCells(); 
    229  
    230 public slots: 
    231  
    232         void SetRenderErrors(bool b) { 
    233                 mRenderErrors = b; 
    234                 updateGL(); 
    235         } 
    236  
    237         void SetRenderFilter(bool b) { 
    238                 mRenderFilter = b; 
    239                 updateGL(); 
    240         } 
    241  
    242         void SetUseFilter(bool b) { 
    243                 mUseFilter = b; 
    244                 updateGL(); 
    245         } 
    246  
    247         void SetUseSpatialFilter(bool b) { 
    248                 mUseSpatialFilter = b; 
    249                 updateGL(); 
    250         } 
    251  
    252  
    253         void 
    254                 SetViewCellGranularity(int number); 
    255  
    256         void 
    257                 SetVisibilityFilterSize(int number); 
    258  
    259         void 
    260                 SetSpatialFilterSize(int number); 
    261  
    262         void 
    263                 SetSceneCut(int cut); 
    264  
    265         void 
    266                 SetTopDistance(int dist); 
    267  
    268         void SetShowViewCells(bool b) { 
    269                 mRenderViewCells = b; 
    270                 updateGL(); 
    271         } 
    272  
    273         void SetShowRenderCost(bool b) { 
    274                 mShowRenderCost = b; 
    275                 updateGL(); 
    276         } 
    277  
    278         void SetShowPvsSizes(bool b) { 
    279                 mShowPvsSizes = b; 
    280                 updateGL(); 
    281         } 
    282  
    283         void SetTopView(bool b) { 
    284                 mTopView = b; 
    285                 updateGL(); 
    286         } 
    287  
    288         void SetCutViewCells(bool b) { 
    289                 mCutViewCells = b; 
    290                 updateGL(); 
    291         } 
    292         void SetCutScene(bool b) { 
    293                 mCutScene = b; 
    294                 updateGL(); 
    295         } 
    296  
    297         // matt: dummy function, must be provided by bittner 
    298         void RenderRenderCost() {} 
    299  
     121  Q_OBJECT 
     122public: 
     123 
     124  // point of the last mouse click used for movement in the scene 
     125  Vector3 mousePoint; 
     126 
     127  bool mTopView; 
     128  bool mRenderViewCells; 
     129  bool mCutViewCells; 
     130  bool mCutScene; 
     131  bool mRenderErrors; 
     132  bool mRenderFilter; 
     133  bool mRenderVisibilityEstimates; 
     134  bool mUseFilter; 
     135  bool mUseSpatialFilter; 
     136  bool mShowRenderCost; 
     137  bool mShowRays; 
     138 
     139  bool mShowPvsSizes; 
     140  float mSpatialFilterSize; 
     141   
     142  Plane3 mSceneCutPlane; 
     143  float mTopDistance; 
     144 
     145  // some statistics 
     146  int mPvsSize; 
     147  float mRenderError; 
     148  float mTransferFunction; 
     149 
     150   
     151  QtRendererControlWidget *mControlWidget; 
     152 
     153  QtPreprocessorThread *mPreprocessorThread; 
     154   
     155  QtGlRendererWidget(SceneGraph *sceneGraph, 
     156                                         ViewCellsManager *viewcells, 
     157                                         KdTree *tree, 
     158                                         QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0 
     159                                         ); 
     160   
     161  QtGlRendererWidget() {}; 
     162 
     163  void SetThread(QtPreprocessorThread *t) { 
     164        mPreprocessorThread = t; 
     165  } 
     166  void 
     167  RenderRenderCost(); 
     168 
     169  virtual void SetupCamera(); 
     170 
     171  void initializeGL() { 
     172        InitGL(); 
     173  } 
     174  void resizeGL(int w, int h); 
     175  void paintGL(); 
     176  void timerEvent(QTimerEvent *) { 
     177          update(); 
     178  } 
     179 
     180  void mousePressEvent(QMouseEvent *); 
     181  void mouseReleaseEvent(QMouseEvent *); 
     182  void mouseMoveEvent(QMouseEvent *); 
     183 
     184  void keyPressEvent ( QKeyEvent * e ) ; 
     185 
     186  void 
     187  RenderPvs(); 
     188 
     189  float 
     190  RenderErrors(); 
     191  void 
     192  RenderInfo(); 
     193 
     194  virtual int GetWidth() const { return width(); } 
     195  virtual int GetHeight() const { return height(); } 
     196 
     197  // virtual void 
     198  //  SetupProjection(const int w, const int h, const float angle = 70.0f); 
     199 
     200  virtual void 
     201  SetupCameraProjection(const int w, const int h, const float angle = 70.0f); 
     202 
     203  void 
     204  RenderViewCells(); 
     205 
     206 
     207  virtual void Show() { 
     208        show(); 
     209  } 
     210 
     211 public slots: 
     212 
     213 void UpdateAllPvs(); 
     214  void ComputeVisibility(); 
     215  void StopComputation(); 
     216  void SetRandomViewPoint(); 
     217 
     218 void SetRenderErrors(bool b) { 
     219   mRenderErrors = b; 
     220   updateGL(); 
     221 } 
     222 
     223  void SetRenderBoxes(bool b) { 
     224        mRenderBoxes = b; 
     225        updateGL(); 
     226  } 
     227 
     228 void SetRenderFilter(bool b) { 
     229   mRenderFilter = b; 
     230   updateGL(); 
     231 } 
     232 
     233  void SetRenderVisibilityEstimates(bool b) { 
     234        mRenderVisibilityEstimates = b; 
     235   updateGL(); 
     236 } 
     237 
     238  void SetUseFilter(bool b) { 
     239   mUseFilter = b; 
     240   mPvsCache.Reset(); 
     241   updateGL(); 
     242 } 
     243 
     244  void SetUseSpatialFilter(bool b) { 
     245        mUseSpatialFilter = b; 
     246        mPvsCache.Reset(); 
     247        updateGL(); 
     248  } 
     249 
     250   
     251  void 
     252  SetViewCellGranularity(int number); 
     253 
     254  void 
     255  SetTransferFunction(int number) { 
     256        mTransferFunction = number/1000.0f; 
     257        updateGL(); 
     258  } 
     259 
     260  void 
     261  SetVisibilityFilterSize(int number); 
     262 
     263  void 
     264  SetSpatialFilterSize(int number); 
     265   
     266  void 
     267  SetSceneCut(int cut); 
     268   
     269  void 
     270  SetTopDistance(int dist); 
     271   
     272  void SetShowViewCells(bool b) { 
     273        mRenderViewCells = b; 
     274        updateGL(); 
     275  } 
     276 
     277  void SetShowRays(bool b) { 
     278        mShowRays = b; 
     279        updateGL(); 
     280  } 
     281 
     282  void SetShowRenderCost(bool b) { 
     283        mShowRenderCost = b; 
     284        updateGL(); 
     285  } 
     286 
     287  void SetShowPvsSizes(bool b) { 
     288        mShowPvsSizes = b; 
     289        updateGL(); 
     290  } 
     291 
     292  void SetTopView(bool b) { 
     293        mTopView = b; 
     294        updateGL(); 
     295  } 
     296 
     297  void SetCutViewCells(bool b) { 
     298        mCutViewCells = b; 
     299        updateGL(); 
     300  } 
     301  void SetCutScene(bool b) { 
     302        mCutScene = b; 
     303        updateGL(); 
     304  } 
     305 
     306  signals: 
     307  void PvsUpdated(); 
    300308}; 
    301309 
     
    305313        Q_OBJECT 
    306314public: 
    307         QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL); 
    308         ~QtGlDebuggerWidget(); 
    309         void initializeGL(); 
    310         void resizeGL(int w, int h); 
    311         void paintGL(); 
    312         void timerEvent(QTimerEvent *) { update(); } 
    313         void mousePressEvent(QMouseEvent *) { killTimer(timerId); } 
    314         void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); } 
    315  
    316         void initCommon(); 
    317         void initPbuffer(); 
    318  
    319  
    320         QtGlRendererBuffer *mRenderBuffer; 
    321  
    322         Beam mBeam; 
    323         int mSamples; 
    324         Intersectable *mSourceObject; 
     315    QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL); 
     316    ~QtGlDebuggerWidget(); 
     317    void initializeGL(); 
     318    void resizeGL(int w, int h); 
     319    void paintGL(); 
     320    void timerEvent(QTimerEvent *) { update(); } 
     321    void mousePressEvent(QMouseEvent *) { killTimer(timerId); } 
     322    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); } 
     323 
     324    void initCommon(); 
     325    void initPbuffer(); 
     326 
     327   
     328         QtGlRendererBuffer *mRenderBuffer; 
     329 
     330         Beam mBeam; 
     331         int mSamples; 
     332         Intersectable *mSourceObject; 
    325333 
    326334private: 
    327  
    328         GLuint dynamicTexture; 
    329         int timerId; 
     335    GLuint dynamicTexture; 
     336    int timerId; 
    330337}; 
    331338 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h

    r1883 r1942  
    9393    mType = _type; 
    9494    depth = 0; 
    95                 Init(); 
     95        Init(); 
    9696  } 
    9797  // dummy constructor 
     
    239239 
    240240  Vector3 GetInvDir() const { return invDir; } 
    241    
     241 
     242  // precompute some values that are necessary 
     243  void Precompute(); 
     244 
    242245private: 
    243246  Vector3 loc, dir;             // Describes ray origin and vector 
     
    271274  void Init(); 
    272275 
    273   // precompute some values that are necessary 
    274   void Precompute(); 
    275276 
    276277  friend class AxisAlignedBox3; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp

    r1932 r1942  
    33#include "Ray.h" 
    44#include "Preprocessor.h" 
     5#include "ViewCellsManager.h" 
    56 
    67 
     
    1011#define DEBUG_RAYCAST 0 
    1112 
    12 #define EXACT_BOX_CLIPPING 1 
     13#define EXACT_BOX_CLIPPING 0 
    1314 
    1415RayCaster::RayCaster(const Preprocessor &preprocessor): 
     
    3839} 
    3940 
     41bool 
     42RayCaster::ClipToViewSpaceBox(const Vector3 &origin, 
     43                                                          const Vector3 &termination, 
     44                                                          Vector3 &clippedOrigin, 
     45                                                          Vector3 &clippedTermination) 
     46{ 
     47  Ray ray(origin, termination - origin, Ray::LINE_SEGMENT);      
     48  ray.Precompute(); 
     49   
     50  float tmin, tmax; 
     51  if ((!mPreprocessor.mViewCellsManager-> 
     52           GetViewSpaceBox().ComputeMinMaxT(ray, &tmin, &tmax)) || 
     53          tmin>=tmax 
     54          ) 
     55        return false; 
     56 
     57  if (tmin >= 1.0f || tmax <=0.0f) 
     58        return false; 
     59   
     60  if (tmin > 0.0f) 
     61        clippedOrigin = ray.Extrap(tmin); 
     62  else 
     63        clippedOrigin = origin; 
     64   
     65  if (tmax < 1.0f) 
     66        clippedTermination = ray.Extrap(tmax); 
     67  else 
     68        clippedTermination = termination; 
     69   
     70  return true; 
     71} 
    4072 
    4173/** Checks if ray is valid, (e.g., not in empty view space or outside the view space) 
     
    140172        // degenerate rays checked by geometrical constraint... 
    141173        //      !pruneInvalidRays || (hitA.mObject != hitB.mObject); 
     174 
    142175         
    143176#if DEBUG_RAYCAST 
    144177        Debug<<"PR2"<<flush; 
    145178#endif 
    146  
    147         if (!pruneInvalidRays || hitA.mObject)  
    148         { 
    149                 VssRay *vssRay = new VssRay(hitB.mPoint, 
     179        const bool validSample = true; 
     180        if (validSample) { 
     181          Vector3 clipA, clipB; 
     182          if (!ClipToViewSpaceBox(hitA.mPoint, 
     183                                                          hitB.mPoint, 
     184                                                          clipA, 
     185                                                          clipB)) 
     186                return 0; 
     187          if (!pruneInvalidRays || hitA.mObject) { 
     188                VssRay *vssRay = new VssRay( 
     189                                                                        clipB, 
    150190                                                                        hitA.mPoint, 
    151191                                                                        hitB.mObject, 
     
    167207#endif 
    168208 
    169         if (castDoubleRay && (!pruneInvalidRays || hitB.mObject)) 
    170         { 
    171                 VssRay *vssRay = new VssRay(hitA.mPoint, 
    172                                                                         hitB.mPoint, 
    173                                                                         hitA.mObject, 
    174                                                                         hitB.mObject, 
    175                                                                         mPreprocessor.mPass, 
    176                                                                         simpleRay.mPdf); 
    177  
    178                 if (validB) 
     209          if (castDoubleRay && (!pruneInvalidRays || hitB.mObject)) 
     210                { 
     211                  VssRay *vssRay = new VssRay( 
     212                                                                          clipA, 
     213                                                                          hitB.mPoint, 
     214                                                                          hitA.mObject, 
     215                                                                          hitB.mObject, 
     216                                                                          mPreprocessor.mPass, 
     217                                                                          simpleRay.mPdf 
     218                                                                          ); 
     219                  if (validB) 
    179220                        vssRay->mFlags |= VssRay::Valid; 
    180221 
     
    183224                ++ hits; 
    184225                //cout << "vssray 2: " << *vssRay << endl; 
    185         } 
    186          
    187 #if DEBUG_RAYCAST 
    188         Debug<<"PR4"<<flush; 
    189 #endif 
    190  
     226                } 
     227#if DEBUG_RAYCAST 
     228          Debug<<"PR4"<<flush; 
     229#endif 
     230        } 
     231         
    191232        return hits; 
    192233} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h

    r1932 r1942  
    9898                                 const AxisAlignedBox3 &box, 
    9999                                         Intersection &hit); 
     100 
     101  bool 
     102  ClipToViewSpaceBox(const Vector3 &origin, 
     103                                         const Vector3 &termination, 
     104                                         Vector3 &clippedOrigin, 
     105                                         Vector3 &clippedTermination); 
    100106         
    101107        const Preprocessor &mPreprocessor; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp

    r1931 r1942  
    22992299{ 
    23002300  Vector3 origin = sbox.GetPoint(Vector3(params[0], params[1], params[2])); 
    2301  
    23022301  Vector3 dirVector = sDirBBox.GetPoint(Vector3(params[3], params[4], 0.0f)); 
    2303  
    23042302  Vector3 direction = VssRay::GetInvDirParam(dirVector.x, dirVector.y); 
    23052303   
     
    23082306  float minT, maxT; 
    23092307   
    2310   float boxSize = Magnitude(sbox.Size()); 
    23112308  // compute interection of the ray with the box 
    23122309#if 1 
    23132310  if (sbox.ComputeMinMaxT(origin, direction, &minT, &maxT) && minT < maxT) 
    2314         dist = (maxT + 0.0f*boxSize); 
     2311        dist = (maxT + Limits::Small); 
    23152312#else 
     2313  float boxSize = Magnitude(sbox.Size()); 
    23162314  dist = 0.5f*boxSize; 
    23172315#endif 
    23182316   
    23192317  origin += direction*dist; 
    2320  
     2318   
    23212319  //Debug<<"dir vector.x="<<dirVector.x<<"direction'.x="<<atan2(direction.x, direction.y)<<endl; 
    23222320  rays.push_back(SimpleRay(origin, 
     
    27652763          sumContributions += c1; 
    27662764          if (c1 > maxContribution) 
    2767                         maxContribution = c1; 
     2765                maxContribution = c1; 
    27682766           
    27692767          //$$ 20.7. changed to sqr to pronouce higher contribution so that 
     
    28062804                pow(((weightAbsContributions*sumContributions + 
    28072805                          (1.0f - weightAbsContributions)*sumRelContributions)/sumWeights), 1.0f); 
    2808 #else 1 
     2806#else  
    28092807          leaf->mImportance = 
    28102808                (weightAbsContributions*maxContribution + 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r1931 r1942  
    527527  
    528528        float contribution = 
    529           mPreprocessor.mViewCellsManager->ComputeSampleContribution(*ray, true, false); 
     529          mPreprocessor.mViewCellsManager->ComputeSampleContribution(*ray, 
     530                                                                                                                                 true, 
     531                                                                                                                                 false); 
    530532 
    531533        mDistributions[i]->mContribution += contribution; 
     
    536538  } 
    537539 
     540   
     541  UpdateRatios(); 
     542} 
     543 
     544void 
     545MixtureDistribution::UpdateDistributions(VssRayContainer &vssRays) 
     546{ 
    538547  // now update the distributions with all the rays 
    539   for (i=0; i < mDistributions.size(); i++) { 
     548  for (int i=0; i < mDistributions.size(); i++) { 
    540549        mDistributions[i]->Update(vssRays); 
    541550  } 
    542    
    543    
    544   UpdateRatios(); 
    545 } 
    546  
     551} 
     552   
    547553void 
    548554MixtureDistribution::UpdateRatios() 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h

    r1901 r1942  
    269269  void ComputeContributions(VssRayContainer &vssRays); 
    270270 
     271  // update distributions with new rays 
     272  // warning: some rays can get deleted (if maintained internally by the 
     273  // particular distribution)! 
     274  void UpdateDistributions(VssRayContainer &vssRays); 
     275 
    271276  void 
    272277  UpdateRatios(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1935 r1942  
    3131#define USE_RAY_LENGTH_AS_CONTRIBUTION 0 
    3232#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 
     33#define SUM_RAY_CONTRIBUTIONS 1 
     34#define AVG_RAY_CONTRIBUTIONS 0 
     35#define CONTRIBUTION_RELATIVE_TO_PVS_SIZE 0 
    3636#define PVS_ADD_DIRTY 1 
    3737 
     
    19961996  stat.avgFilterRadius = 0; 
    19971997  stat.avgFilterRatio = 0; 
     1998  stat.avgRelPvsIncrease = 0.0f; 
     1999  stat.devRelPvsIncrease = 0.0f; 
    19982000   
    1999   for (; it != mViewCells.end(); ++ it)  
     2001  if (mPerViewCellStat.size() != mViewCells.size()) { 
     2002        // reset the pvs size array after the first call to this routine 
     2003        mPerViewCellStat.resize(mViewCells.size()); 
     2004        for (int i=0; i < mPerViewCellStat.size(); i++) { 
     2005          mPerViewCellStat[i].pvsSize = 0.0f; 
     2006          mPerViewCellStat[i].relPvsIncrease = 0.0f; 
     2007        } 
     2008  } 
     2009  int i; 
     2010  bool evaluateFilter; 
     2011  Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluateFilter", evaluateFilter); 
     2012 
     2013  for (i=0; it != mViewCells.end(); ++ it, i++)  
    20002014        { 
    20012015          ViewCell *viewcell = *it; 
     
    20102024                stat.avgPvs += pvsCost; 
    20112025 
    2012                 bool evaluateFilter; 
    2013                 Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluateFilter", evaluateFilter); 
     2026 
     2027                if (mPerViewCellStat[i].pvsSize > 0.0f) 
     2028                  mPerViewCellStat[i].relPvsIncrease = (pvsCost - mPerViewCellStat[i].pvsSize)/mPerViewCellStat[i].pvsSize; 
     2029                 
     2030                stat.avgRelPvsIncrease += mPerViewCellStat[i].relPvsIncrease; 
     2031                 
     2032                // update the pvs size 
     2033                mPerViewCellStat[i].pvsSize = pvsCost; 
     2034                 
    20142035                 
    20152036                 
     
    20402061          } 
    20412062        } 
     2063 
     2064   
    20422065   
    20432066  if (stat.viewcells) { 
     
    20462069        stat.avgFilterContribution/=stat.viewcells; 
    20472070        stat.avgFilterRadius/=stat.viewcells; 
    2048         stat.avgFilterRatio/=stat.viewcells; 
     2071        stat.avgFilterRatio/=stat.viewcells;  
     2072        stat.avgRelPvsIncrease/=stat.viewcells; 
     2073 
     2074        // evaluate std deviation of relPvsIncrease 
     2075        float sum=0.0f; 
     2076        for (i=0; i < stat.viewcells; i++) { 
     2077          sum += sqr(mPerViewCellStat[i].relPvsIncrease - stat.avgRelPvsIncrease); 
     2078        } 
     2079        stat.devRelPvsIncrease = sqrt(sum/stat.viewcells); 
    20492080  } 
     2081   
    20502082} 
    20512083 
     
    20632095  s<<"#MAX_PVS\n"<<pvsStat.maxPvs<<endl; 
    20642096  s<<"#MIN_PVS\n"<<pvsStat.minPvs<<endl; 
     2097  s<<"#AVG_REL_PVS_INCREASE\n"<<pvsStat.avgRelPvsIncrease<<endl; 
     2098  s<<"#DEV_REL_PVS_INCREASE\n"<<pvsStat.devRelPvsIncrease<<endl; 
    20652099} 
    20662100 
     
    21782212                                                                                                   const bool addRays) 
    21792213{ 
    2180         // check if we are outside of view space 
     2214  // check if we are outside of view space 
    21812215        if (!obj || !viewCell->GetValid()) 
    21822216                return; 
    2183  
     2217         
    21842218        // if ray not outside of view space 
    21852219        float relContribution = 0.0f; 
    21862220        float absContribution = 0.0f; 
    2187  
    2188         // todo: maybe not correct for kd node pvs 
    2189         if (viewCell->GetPvs().GetSampleContribution(obj, 
    2190                                                                                                  ray.mPdf, 
    2191                                                                                                  relContribution)) 
    2192         { 
    2193                 absContribution = 1.0f; 
    2194         } 
    2195          
    2196         // $$ clear the relative contribution as it is currently not correct anyway 
    2197         relContribution = 0.0f; 
    2198  
    2199         if (absContribution == 1.0f) 
    2200         { 
    2201                 ++ ray.mPvsContribution; 
    2202                 relContribution = 1.0f; 
    2203  
    2204                 if (addRays)  
    2205                 { 
    2206                         AddSampleToPvs(viewCell->GetPvs(), obj, ray.mPdf); 
    2207                 } 
    2208  
     2221         
     2222        if (obj)  
     2223          { 
     2224                // todo: maybe not correct for kd node pvs 
     2225                if (addRays) { 
     2226                  float pdf = viewCell->GetPvs().AddSampleDirtyCheck(obj, ray.mPdf); 
     2227                  if (pdf == ray.mPdf) { 
     2228                        absContribution = 1.0f; 
     2229                        if (viewCell->GetPvs().RequiresResort())  
     2230                          viewCell->GetPvs().SimpleSort(); 
     2231                  } 
     2232                          } else { 
     2233                                if (viewCell->GetPvs().GetSampleContribution( 
     2234                                                                                                                         obj, 
     2235                                                                                                                         ray.mPdf, 
     2236                                                                                                                         relContribution)) 
     2237                                  absContribution = 1.0f; 
     2238                          } 
     2239                // $$ clear the relative contribution as it is currently not correct anyway 
     2240                relContribution = 0.0f; 
     2241                 
     2242                if (absContribution == 1.0f) { 
     2243                  ++ ray.mPvsContribution; 
     2244                  relContribution = 1.0f; 
     2245                   
     2246                   
     2247#if CONTRIBUTION_RELATIVE_TO_PVS_SIZE 
     2248                  relContribution /= viewcell->GetPvs().GetSize(); 
     2249#endif 
     2250                   
    22092251#if DIST_WEIGHTED_CONTRIBUTION  
    2210                 // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
    2211                 // object-> a new contribution in the proximity of the viewcell has a larger weight! 
    2212                 relContribution /= SqrDistance(GetViewCellBox(viewcell).Center(), pt); 
    2213                                    
     2252                  // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
     2253                  // object-> a new contribution in the proximity of the viewcell has a larger weight! 
     2254                  relContribution /= SqrDistance(GetViewCellBox(viewcell).Center(), 
     2255                                                                                 ray.mTermination); 
     2256                   
    22142257#endif 
    2215         } 
    2216  
     2258                } 
     2259                 
    22172260#if SUM_RAY_CONTRIBUTIONS || AVG_RAY_CONTRIBUTIONS 
    2218         ray.mRelativePvsContribution += relContribution; 
     2261                ray.mRelativePvsContribution += relContribution; 
    22192262#else 
    2220         // recalculate relative contribution - use max of AbsContribution 
    2221         if (ray.mRelativePvsContribution < absContribution) 
    2222                 ray.mRelativePvsContribution = absContribution; 
     2263                // recalculate relative contribution - use max of Rel Contribution 
     2264                if (ray.mRelativePvsContribution < relContribution) 
     2265                  ray.mRelativePvsContribution = relContribution; 
    22232266#endif 
     2267          } 
     2268         
    22242269} 
    22252270 
     
    22432288        float tmin = 0, tmax = 1.0; 
    22442289 
    2245         if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
    2246                 return 0; 
     2290        if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) { 
     2291          //      cerr<<"ray outside view space box\n"; 
     2292          return 0; 
     2293        } 
    22472294 
    22482295        Vector3 origin = hray.Extrap(tmin); 
     
    22542301        CastLineSegment(origin, termination, viewCells); 
    22552302 
     2303         
    22562304        if (storeViewCells) 
    22572305        {        
    2258                 // copy viewcells memory efficiently 
    2259                 ray.mViewCells.reserve(viewCells.size()); 
    2260                 ray.mViewCells = viewCells; 
     2306          // copy viewcells memory efficiently 
     2307          ray.mViewCells.reserve(viewCells.size()); 
     2308          ray.mViewCells = viewCells; 
    22612309        } 
    22622310 
     
    22802328#if USE_RAY_LENGTH_AS_CONTRIBUTION 
    22812329        float c = 0.0f; 
    2282         if (obj)  
    2283                 c = ray.Length(); 
     2330        if (terminationObj)  
     2331          c = ray.Length(); 
    22842332        ray.mRelativePvsContribution = ray.mPvsContribution = c; 
    22852333        return c; 
    22862334#else 
    2287         return ABS_CONTRIBUTION_WEIGHT * ray.mPvsContribution + 
    2288                 (1.0f - ABS_CONTRIBUTION_WEIGHT) * ray.mRelativePvsContribution; 
     2335        return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 
     2336          (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 
    22892337#endif 
    22902338} 
     
    28972945                sqrt((float)objectSamples); 
    28982946           
    2899           //    cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
     2947          //      cout<<"os="<<objectSamples<<" lr="<<localRadius<<" gr="<<globalRadius<<endl; 
    29002948           
    29012949          // now compute the filter size 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1932 r1942  
    8181{ 
    8282public: 
    83         struct PvsStatistics  
     83 
     84  struct PerViewCellStat { 
     85        float pvsSize; 
     86        float relPvsIncrease; 
     87  }; 
     88   
     89  struct PvsStatistics  
    8490        { 
    8591          float minPvs; 
     
    9096          float avgFilterRadius; 
    9197          float avgFilterRatio; 
     98          float avgRelPvsIncrease; 
     99          float devRelPvsIncrease; 
    92100          int viewcells; 
    93            
    94101        }; 
    95  
     102   
    96103        /// view cell container types 
    97104        enum {BSP, KD, VSP_KD, VSP_BSP, VSP_OSP}; 
     
    789796        /// if view cells geometry should be used from other sources 
    790797        bool mUsePredefinedViewCells; 
     798 
     799   
     800  vector<PerViewCellStat> mPerViewCellStat; 
     801 
    791802}; 
    792803 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.cpp

    r1932 r1942  
    357357{ 
    358358  VssRayContainer::const_iterator it = begin(); 
    359  
    360   // ofstream s("contrib.log"); 
    361  
    362   for (; it != end(); it++)  
    363   { 
    364           VssRay *ray = *it; 
    365  
    366           // s<<"(pass="<<ray->mPass<<", c="<<ray->mPvsContribution<<")"<<endl; 
    367           if (ray->mPass >= minPass && ray->mPvsContribution > 0) 
    368                   selected.push_back(ray); 
    369   } 
    370  
     359  //  ofstream s("contrib.log"); 
     360  for (; it != end(); it++) { 
     361        VssRay *ray = *it; 
     362        //      cout<<"(pass="<<ray->mPass<<", c="<<ray->mPvsContribution<<")"<<endl; 
     363        if (ray->mPass >= minPass && ray->mPvsContribution > 0) 
     364          selected.push_back(ray); 
     365  } 
     366   
    371367  return (int)selected.size(); 
    372368} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/default.env

    r1931 r1942  
    4343        useGlDebugger false 
    4444# 0 = INTERNAL          1 = MLRT 
    45  
    4645        rayCastMethod 1 
    4746         
     
    6261        applyVisibilitySpatialFilter false 
    6362        visibilityFilterWidth   0.01 
    64         exportVisibility false 
     63        exportVisibility true 
    6564        visibilityFile visibility.xml 
    6665        loadMeshes false 
     
    9897 
    9998#       distributions rss+spatial+object_direction 
    100         distributions rss+object_direction+spatial+object+direction 
     99#       distributions rss+object_direction+spatial+object+direction 
     100        distributions object_direction+spatial+object+direction 
     101#       distributions rss+object_direction 
    101102#       distributions object_direction 
    102103 
    103104        samplesPerPass 1000000 
    104105        initialSamples 2000000 
    105         vssSamples 150000000 
     106        vssSamples 20000000 
    106107        vssSamplesPerPass 5000000 
    107108        useImportanceSampling true 
     
    132133#       splitType heuristic 
    133134 
    134         minRays         50 
     135        minRays         200 
    135136        minSize         0.001 
    136137        maxCostRatio 1.0 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1940 r1942  
    2828#include "ObjExporter.h" 
    2929#include "SceneGraph.h" 
    30 #include "GlobalLinesRenderer.h" 
     30//#include "GlobalLinesRenderer.h" 
    3131 
    3232#include "ViewCellsManager.h" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro

    r1931 r1942  
    2525unix:INCLUDEPATH += ../support/src/xerces-c-src_2_7_0/include 
    2626 
    27 INCLUDEPATH += ../src $$NONGTP/Xerces/xerces/include  $$NONGTP/Zlib/include $$NONGTP/Boost $$NONGTP/Devil/include 
     27INCLUDEPATH += ../src ../src/QtInterface $$NONGTP/Xerces/xerces/include  $$NONGTP/Zlib/include $$NONGTP/Boost $$NONGTP/Devil/include 
    2828 
    2929win32:LIBPATH += GL $$NONGTP/Xerces/xerces/lib $$NONGTP/Devil/lib \ 
     
    8787# Input 
    8888HEADERS += Halton.h VssRay.h VssPreprocessor.h RssTree.h GlRenderer.h \ 
    89 PreprocessorThread.h Preprocessor.h Beam.h QtGlViewer.h 
     89PreprocessorThread.h Preprocessor.h Beam.h  
    9090 
    9191 
     
    111111Trackball.cpp ObjExporter.cpp SubdivisionCandidate.cpp \ 
    112112Mailable.cpp \ 
    113 CombinedPreprocessor.cpp QtGlViewer.cpp  
     113CombinedPreprocessor.cpp  
    114114 
    115115SOURCES += BoostPreprocessorThread.cpp  
    116116 
    117117CONFIG(qt) { 
    118 HEADERS += QtPreprocessorThread.h QtGlRenderer.h 
    119 SOURCES += OcclusionQuery.cpp QtPreprocessorThread.cpp QtGlRenderer.cpp 
     118HEADERS += QtPreprocessorThread.h QtInterface/QtGlRenderer.h \ 
     119QtInterface/QtGlViewer.h 
     120SOURCES += OcclusionQuery.cpp QtPreprocessorThread.cpp \ 
     121QtInterface/QtGlRenderer.cpp QtInterface/QtGlViewer.cpp  
    120122} else { 
    121123SOURCES += BoostPreprocessorThread.cpp  
  • GTP/trunk/Lib/Vis/Preprocessing/src/run_test2

    r1900 r1942  
    22 
    33#COMMAND="./release/preprocessor.exe -preprocessor_quit_on_finish+" 
    4 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter-" 
     4COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter+" 
    55 
    66#SCENE="../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d" 
     
    6565 
    6666$COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 
    67 -rss_distributions=object_direction+spatial+object+direction -view_cells_filter_max_size=1 \ 
    68 -preprocessor_stats=$PREFIX-i-mixed-b1-n225678.log \ 
    69 -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n225678.hlog 
     67-rss_distributions=rss+object_direction+spatial+object+direction -view_cells_filter_max_size=1 \ 
     68-preprocessor_stats=$PREFIX-i-mixed-b1-n4.log \ 
     69-preprocessor_histogram_file=$PREFIX-i-mixed-b1-n4.hlog 
     70 
     71# $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 
     72# -rss_distributions=rss+object_direction+spatial+object+direction -view_cells_filter_max_size=1 \ 
     73# -preprocessor_stats=$PREFIX-i-mixed-b1-n2.log \ 
     74# -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n2.hlog 
    7075 
    7176 
Note: See TracChangeset for help on using the changeset viewer.