- Timestamp:
- 01/05/07 16:29:54 (18 years ago)
- 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 79 79 totalVssRays += (int)vssRays.size(); 80 80 81 mMixtureDistribution->ComputeContributions(vssRays); 82 81 83 if (mExportRays) { 82 84 Debug<<"Exporting rays..."<<endl<<flush; 83 85 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 84 92 sprintf(filename, "rss-rays-i%04d.x3d", mPass); 85 93 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 91 95 Debug<<"done."<<endl<<flush; 92 96 } 93 97 94 mMixtureDistribution-> ComputeContributions(vssRays);95 98 mMixtureDistribution->UpdateDistributions(vssRays); 99 96 100 if (i - lastEvaluation >= mSamplesPerEvaluation) { 97 101 mViewCellsManager->PrintPvsStatistics(mStats); … … 114 118 115 119 } 116 120 121 EvalViewCellHistogram(); 122 117 123 return true; 118 124 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1934 r1942 1742 1742 RegisterOption("Preprocessor.loadMeshes", 1743 1743 optBool, 1744 "preprocessor_load_meshes =",1744 "preprocessor_load_meshes", 1745 1745 "true"); 1746 1746 1747 1747 RegisterOption("Preprocessor.evaluateFilter", 1748 1748 optBool, 1749 "preprocessor_evaluate_filter =",1749 "preprocessor_evaluate_filter", 1750 1750 "false"); 1751 1751 1752 1752 RegisterOption("Preprocessor.delayVisibilityComputation", 1753 1753 optBool, 1754 "preprocessor_delay_computation =",1754 "preprocessor_delay_computation", 1755 1755 "true"); 1756 1756 … … 1762 1762 RegisterOption("Preprocessor.useGlRenderer", 1763 1763 optBool, 1764 "preprocessor_use_gl_renderer =",1764 "preprocessor_use_gl_renderer", 1765 1765 "false"); 1766 1766 1767 1767 RegisterOption("Preprocessor.useGlDebugger", 1768 1768 optBool, 1769 "preprocessor_use_gl_debugger =",1769 "preprocessor_use_gl_debugger", 1770 1770 "false"); 1771 1771 1772 1772 RegisterOption("Preprocessor.detectEmptyViewSpace", 1773 1773 optBool, 1774 "preprocessor_detect_empty_viewspace =",1774 "preprocessor_detect_empty_viewspace", 1775 1775 "false"); 1776 1776 1777 1777 RegisterOption("Preprocessor.quitOnFinish", 1778 1778 optBool, 1779 "preprocessor_quit_on_finish =",1779 "preprocessor_quit_on_finish", 1780 1780 "true"); 1781 1781 1782 1782 RegisterOption("Preprocessor.computeVisibility", 1783 1783 optBool, 1784 "preprocessor_compute_visibility =",1784 "preprocessor_compute_visibility", 1785 1785 "true"); 1786 1786 1787 1787 RegisterOption("Preprocessor.exportVisibility", 1788 1788 optBool, 1789 "preprocessor_export_visibility =",1789 "preprocessor_export_visibility", 1790 1790 "true"); 1791 1791 … … 1797 1797 RegisterOption("Preprocessor.applyVisibilityFilter", 1798 1798 optBool, 1799 "preprocessor_apply_filter =",1799 "preprocessor_apply_filter", 1800 1800 "false"); 1801 1801 1802 1802 RegisterOption("Preprocessor.applyVisibilitySpatialFilter", 1803 1803 optBool, 1804 "preprocessor_apply_spatial_filter =",1804 "preprocessor_apply_spatial_filter", 1805 1805 "false"); 1806 1806 -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r1941 r1942 66 66 // mViewCellsManager->GetViewPoint(mViewPoint); 67 67 68 mViewPoint = mSceneGraph->GetBox().Center(); 68 viewCellsManager->GetViewPoint(mViewPoint); 69 //mSceneGraph->GetBox().Center(); 69 70 mViewDirection = Vector3(0,0,1); 70 71 -
GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
r1867 r1942 2 2 #include "VssRay.h" 3 3 #include "Preprocessor.h" 4 #include "SceneGraph.h" 4 5 5 6 #ifdef GTP_INTERNAL … … 125 126 float backward_dist[16]; 126 127 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(); 130 131 131 132 for (i=0; i < num; i++) { -
GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
r1931 r1942 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.2) on: út 2. I 10:32:4820073 # Generated by qmake (2.00a) (Qt 4.1.2) on: pá 5. I 16:16:49 2007 4 4 # Project: preprocessor.pro 5 5 # Template: app -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1932 r1942 31 31 32 32 33 33 34 /** Namespace for the external visibility preprocessor 34 35 … … 230 231 231 232 GlRendererBuffer *renderer; 232 233 233 234 234 235 protected: 235 236 -
GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorFactory.cpp
r1891 r1942 49 49 } 50 50 51 51 52 return NULL; 52 53 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r1925 r1942 615 615 // sample not found yet => search further in the unsorted part 616 616 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()) 622 621 found = true; 623 622 } … … 653 652 } 654 653 else 655 {654 { 656 655 PvsEntry<T, S> entry(sample, pdf); 657 656 mEntries.insert(it, entry); 658 657 ++ mLastSorted; 659 658 return pdf; 660 }659 } 661 660 } 662 661 … … 706 705 707 706 vector<PvsEntry<T, S> >::iterator it; 708 constbool entryFound = Find(sample, it);707 bool entryFound = Find(sample, it); 709 708 710 709 if (entryFound) { -
GTP/trunk/Lib/Vis/Preprocessing/src/QtGlViewer.h
r1936 r1942 12 12 class QtGlViewer : public QGLWidget 13 13 { 14 15 //Q_OBJECT 14 Q_OBJECT 16 15 17 16 friend class QtGlRendererWidget; -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
r1940 r1942 10 10 #include "KdTree.h" 11 11 #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 12 21 #include <Cg/cg.h> 13 22 #include <Cg/cgGL.h> 23 #endif 14 24 15 25 #include <QVBoxLayout> … … 17 27 namespace GtpVisibilityPreprocessor { 18 28 29 30 19 31 class ViewCellsManager; 20 32 21 33 static CGcontext sCgContext = NULL; 22 34 static CGprogram sCgFragmentProgram = NULL; 23 static CGprogram sCgDepthPeelingProgram = NULL;24 35 static CGprofile sCgFragmentProfile; 25 36 26 static GLuint frontDepthMap; 27 static GLuint backDepthMap; 28 29 const int depthMapSize = 512; 37 38 //static vector<OcclusionQuery *> sQueries; 30 39 31 40 QtGlRendererWidget *rendererWidget = NULL; … … 38 47 } 39 48 40 49 #if USE_CG 41 50 static void handleCgError() 42 51 { … … 44 53 exit(1); 45 54 } 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 57 void 58 QtGlRendererBuffer::MakeCurrent() 156 59 { 157 60 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 63 void 64 QtGlRendererBuffer::DoneCurrent() 65 { 186 66 doneCurrent(); 187 188 } 189 190 67 } 68 191 69 192 70 QtGlRendererBuffer::QtGlRendererBuffer(const int w, … … 196 74 KdTree *tree): 197 75 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(); 207 80 InitGL(); 208 doneCurrent(); 209 210 } 81 DoneCurrent(); 82 } 83 84 211 85 212 86 float 213 87 QtGlRendererBuffer::GetPixelError(int &pvsSize) 214 88 { 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; 336 221 } 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 } 626 223 } 627 224 } 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); 651 242 } 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 257 int 258 QtGlRendererBuffer::ComputePvs(ObjectContainer &objects, 259 ObjectContainer &pvs) const 887 260 { 888 261 int pvsSize = 0; … … 924 297 } 925 298 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 308 void 309 QtGlRendererWidget::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); 935 315 glMatrixMode(GL_PROJECTION); 936 316 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())); 938 318 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 941 331 942 332 void 943 333 QtGlRendererWidget::RenderPvs() 944 334 { 945 SetupCamera(); 946 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);947 335 336 Intersectable::NewMail(); 337 948 338 ViewCell *viewcell = NULL; 949 339 950 340 PrVs prvs; 951 341 952 if ( !mUseFilter) {342 if (1 || !mUseFilter) { 953 343 viewcell = mViewCellsManager->GetViewCell(mViewPoint, true); 954 344 } 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 965 359 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); 1006 429 } 1007 430 } … … 1016 439 mUseFalseColors = true; 1017 440 1018 SetupCamera();1019 441 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1020 442 … … 1154 576 int x = e->pos().x(); 1155 577 int y = e->pos().y(); 578 579 int diffx = -(mousePoint.x - x); 580 int diffy = -(mousePoint.y - y); 1156 581 1157 582 if (e->modifiers() & Qt::ControlModifier) { … … 1182 607 QtGlRendererWidget::resizeGL(int w, int h) 1183 608 { 1184 Setup Projection(w, h);609 SetupCameraProjection(w, h); 1185 610 updateGL(); 1186 611 } … … 1191 616 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1192 617 1193 1194 if (!mRenderViewCells) { 1195 if (mRenderErrors) 618 if (1) { 619 SetupCameraProjection(width(), height()); 620 SetupCamera(); 621 622 if (mRenderErrors) { 1196 623 RenderErrors(); 1197 else624 } else { 1198 625 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(); 1209 631 1210 632 mFrame++; 633 1211 634 } 1212 635 … … 1250 673 } 1251 674 675 1252 676 void 1253 677 QtGlRendererWidget::keyPressEvent ( QKeyEvent * e ) … … 1256 680 case Qt::Key_T: 1257 681 mTopView = !mTopView; 1258 Setup Projection(width(), height());682 SetupCameraProjection(width(), height()); 1259 683 updateGL(); 1260 684 break; … … 1277 701 1278 702 1279 QtGlRendererWidget::QtGlRendererWidget(SceneGraph *sceneGraph, 1280 ViewCellsManager *viewcells, 1281 KdTree *tree, 1282 QWidget * parent, 1283 const QGLWidget * shareWidget, 1284 Qt::WFlags f 1285 ) 703 QtGlRendererWidget::QtGlRendererWidget( 704 SceneGraph *sceneGraph, 705 ViewCellsManager *viewcells, 706 KdTree *tree, 707 QWidget * parent, 708 const QGLWidget * shareWidget, 709 Qt::WFlags f 710 ) 1286 711 : 1287 712 GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f) 1288 713 { 714 mPreprocessorThread = NULL; 1289 715 mTopView = false; 1290 716 mRenderViewCells = false; … … 1293 719 mCutScene = false; 1294 720 mRenderErrors = false; 721 mRenderBoxes = false; 1295 722 mRenderFilter = true; 723 mRenderVisibilityEstimates = false; 724 mTransferFunction = 0.2f; 1296 725 1297 726 bool tmp; … … 1302 731 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", 1303 732 tmp ); 1304 1305 733 mUseSpatialFilter = tmp; 1306 734 … … 1310 738 mPvsSize = 0; 1311 739 mRenderError = 0.0f; 740 mShowRays = false; 741 1312 742 mControlWidget = new QtRendererControlWidget(NULL); 1313 743 1314 744 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 1315 755 connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); 1316 756 connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int))); … … 1326 766 connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool))); 1327 767 connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool))); 768 connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool))); 1328 769 connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool))); 770 connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)), 771 this, SLOT(SetRenderVisibilityEstimates(bool))); 1329 772 connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool))); 1330 773 connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)), 1331 774 this, SLOT(SetUseSpatialFilter(bool))); 1332 775 1333 776 connect(mControlWidget, 777 SIGNAL(SetShowRays(bool)), 778 this, 779 SLOT(SetShowRays(bool))); 780 781 resize(1000, 500); 1334 782 mControlWidget->show(); 1335 783 } 1336 784 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) { 785 void 786 QtGlRendererWidget::UpdateAllPvs() 787 { 788 // $$ does not work so far:( 789 mViewCellsManager->UpdatePvsForEvaluation(); 790 // mViewCellsManager->FinalizeViewCells(false); 791 } 792 793 void 794 QtGlRendererWidget::ComputeVisibility() 795 { 796 cerr<<"Compute Visibility called!\n"<<endl; 797 if (!mPreprocessorThread->isRunning()) 798 mPreprocessorThread->RunThread(); 799 } 800 801 void 802 QtGlRendererWidget::StopComputation() 803 { 804 cerr<<"stop computation called!\n"<<endl; 805 mViewCellsManager->GetPreprocessor()->mStopComputation = true; 806 } 807 808 void 809 QtGlRendererWidget::SetRandomViewPoint() 810 { 811 cerr<<"stop computation called!\n"<<endl; 812 mViewCellsManager->GetViewPoint(mViewPoint); 813 updateGL(); 814 } 815 816 void 817 QtGlRendererWidget::RenderRenderCost() 818 { 1370 819 static vector<float> costFunction; 1371 820 static float maxCost = -1; … … 1377 826 for (int i=0; i < costFunction.size(); i++) { 1378 827 // 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(); 1379 830 if (costFunction[i] > maxCost) 1380 831 maxCost = costFunction[i]; … … 1389 840 if (currentPos < costFunction.size()) 1390 841 currentCost = costFunction[currentPos]; 1391 #if 0842 #if 1 1392 843 cout<<"costFunction.size()="<<costFunction.size()<<endl; 1393 844 cout<<"CP="<<currentPos<<endl; … … 1396 847 #endif 1397 848 if (costFunction.size()) { 849 float scaley = 1.0f/log10(maxCost); 850 float scalex = 1.0f/(float)costFunction.size(); 851 1398 852 glDisable(GL_DEPTH_TEST); 1399 853 // init ortographic projection 1400 854 glMatrixMode(GL_PROJECTION); 855 1401 856 glPushMatrix(); 1402 857 … … 1414 869 1415 870 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; 1418 873 glVertex3f(x,y,0.0f); 1419 874 } … … 1422 877 glColor3f(1.0f,0,0); 1423 878 glBegin(GL_LINES); 1424 float x = currentPos /(float)costFunction.size();879 float x = currentPos*scalex; 1425 880 glVertex3f(x,0.0,0.0f); 1426 881 glVertex3f(x,1.0f,0.0f); … … 1437 892 1438 893 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; 1441 896 glVertex3f(x,0.0,0.0f); 1442 897 glVertex3f(x,1.0f,0.0f); 1443 898 } 1444 899 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); 1449 907 } 1450 908 … … 1459 917 1460 918 } 1461 } 919 920 921 922 } 923 924 void 925 QtGlRendererWidget::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 1462 962 } 1463 963 … … 1466 966 QtGlRendererWidget::SetViewCellGranularity(int number) 1467 967 { 1468 if (mViewCellsManager) 968 if (mViewCellsManager) { 1469 969 // mViewCellsManager->SetMaxFilterSize(number); 1470 970 mViewCellsManager->CollectViewCells(number); 1471 971 972 // $$ does not work so far:( 973 // mViewCellsManager->UpdatePvsForEvaluation(); 974 // mViewCellsManager->FinalizeViewCells(false); 975 } 1472 976 updateGL(); 1473 977 } … … 1478 982 if (mViewCellsManager) 1479 983 mViewCellsManager->SetMaxFilterSize(number); 984 mPvsCache.Reset(); 1480 985 updateGL(); 1481 986 } … … 1485 990 { 1486 991 mSpatialFilterSize = 1e-3*number; 992 mPvsCache.Reset(); 1487 993 updateGL(); 1488 994 } … … 1513 1019 QtGlRendererWidget::RenderViewCells() 1514 1020 { 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); 1531 1067 } 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 1568 1078 } 1569 1079 … … 1573 1083 1574 1084 /***********************************************************************/ 1575 /* QtGlDebuggerWidget implementation */1085 /* QtGlDebuggerWidget implementation */ 1576 1086 /***********************************************************************/ 1577 1087 … … 1612 1122 QLabel *label = new QLabel("Granularity"); 1613 1123 vbox->layout()->addWidget(label); 1614 1124 1615 1125 QSlider *slider = new QSlider(Qt::Horizontal, vbox); 1616 1126 vl->addWidget(slider); … … 1620 1130 slider->setValue(200); 1621 1131 1132 1622 1133 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int))); 1623 1134 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 1624 1155 label = new QLabel("Filter size"); 1625 1156 vbox->layout()->addWidget(label); … … 1659 1190 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool))); 1660 1191 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 1661 1197 cb = new QCheckBox("Show render cost", hbox); 1662 1198 hlayout->addWidget(cb); 1663 1199 cb->setChecked(false); 1664 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShow RenderCost(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); 1667 1203 hlayout->addWidget(cb); 1668 1204 cb->setChecked(false); 1669 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShow PvsSizes(bool)));1205 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool))); 1670 1206 1671 1207 vbox->resize(800,100); … … 1678 1214 vbox->setLayout(vl); 1679 1215 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))); 1680 1222 1681 1223 … … 1689 1231 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int))); 1690 1232 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 1691 1250 cb = new QCheckBox("Render errors", vbox); 1692 1251 vbox->layout()->addWidget(cb); … … 1694 1253 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool))); 1695 1254 1255 1256 bool tmp; 1257 1696 1258 cb = new QCheckBox("Use filter", vbox); 1697 1259 vbox->layout()->addWidget(cb); 1698 cb->setChecked(true); 1260 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp ); 1261 cb->setChecked(tmp); 1699 1262 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool))); 1700 1263 1264 1701 1265 cb = new QCheckBox("Use spatial filter", vbox); 1702 1266 vbox->layout()->addWidget(cb); 1703 cb->setChecked(true); 1267 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", 1268 tmp ); 1269 cb->setChecked(tmp); 1704 1270 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool))); 1705 1271 … … 1710 1276 1711 1277 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)));1721 1278 1722 1279 … … 1735 1292 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool))); 1736 1293 1294 1295 1737 1296 vbox = new QGroupBox("PVS Errors", this); 1738 1297 layout()->addWidget(vbox); 1739 1298 1740 1299 vl = new QVBoxLayout; 1741 1300 vbox->setLayout(vl); 1742 1301 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); 1752 1303 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 1755 1335 setWindowTitle("Preprocessor Control Widget"); 1756 1336 adjustSize(); … … 1758 1338 1759 1339 1340 1341 1760 1342 void 1761 1343 QtRendererControlWidget::FocusNextPvsErrorFrame(void) … … 1767 1349 void 1768 1350 QtRendererControlWidget::UpdatePvsErrorItem(int row, 1769 1351 GlRendererBuffer::PvsErrorEntry &pvsErrorEntry) 1770 1352 { 1771 1353 -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
r1940 r1942 4 4 #include <QtOpenGL> 5 5 #include <QWaitCondition> 6 7 //#include <QGLPixelBuffer> 6 8 7 9 #include "Vector3.h" … … 11 13 #include "GlRenderer.h" 12 14 #include "Beam.h" 13 15 #include "QtPreprocessorThread.h" 14 16 class QWidget; 17 //class QtPreprocessorThread; 15 18 16 19 namespace GtpVisibilityPreprocessor { … … 29 32 class TransformedMeshInstance; 30 33 34 31 35 struct VssRayContainer; 32 36 struct PvsRenderStatistics; … … 34 38 35 39 36 class __declspec(dllexport) QtGlRendererBuffer: public QObject, public QGLPixelBuffer, public GlRendererBuffer40 class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer 37 41 { 38 42 Q_OBJECT 39 40 43 public: 41 44 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 68 public: 69 signals: 70 void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &); 71 }; 72 73 74 class QtRendererControlWidget : public QWidget 121 75 { 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 77 public: 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 119 class QtGlRendererWidget : public QGLWidget, public GlRendererWidget 159 120 { 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 122 public: 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(); 300 308 }; 301 309 … … 305 313 Q_OBJECT 306 314 public: 307 308 309 310 311 312 313 314 315 316 317 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; 325 333 326 334 private: 327 328 GLuint dynamicTexture; 329 int timerId; 335 GLuint dynamicTexture; 336 int timerId; 330 337 }; 331 338 -
GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h
r1883 r1942 93 93 mType = _type; 94 94 depth = 0; 95 95 Init(); 96 96 } 97 97 // dummy constructor … … 239 239 240 240 Vector3 GetInvDir() const { return invDir; } 241 241 242 // precompute some values that are necessary 243 void Precompute(); 244 242 245 private: 243 246 Vector3 loc, dir; // Describes ray origin and vector … … 271 274 void Init(); 272 275 273 // precompute some values that are necessary274 void Precompute();275 276 276 277 friend class AxisAlignedBox3; -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r1932 r1942 3 3 #include "Ray.h" 4 4 #include "Preprocessor.h" 5 #include "ViewCellsManager.h" 5 6 6 7 … … 10 11 #define DEBUG_RAYCAST 0 11 12 12 #define EXACT_BOX_CLIPPING 113 #define EXACT_BOX_CLIPPING 0 13 14 14 15 RayCaster::RayCaster(const Preprocessor &preprocessor): … … 38 39 } 39 40 41 bool 42 RayCaster::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 } 40 72 41 73 /** Checks if ray is valid, (e.g., not in empty view space or outside the view space) … … 140 172 // degenerate rays checked by geometrical constraint... 141 173 // !pruneInvalidRays || (hitA.mObject != hitB.mObject); 174 142 175 143 176 #if DEBUG_RAYCAST 144 177 Debug<<"PR2"<<flush; 145 178 #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, 150 190 hitA.mPoint, 151 191 hitB.mObject, … … 167 207 #endif 168 208 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) 179 220 vssRay->mFlags |= VssRay::Valid; 180 221 … … 183 224 ++ hits; 184 225 //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 191 232 return hits; 192 233 } -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
r1932 r1942 98 98 const AxisAlignedBox3 &box, 99 99 Intersection &hit); 100 101 bool 102 ClipToViewSpaceBox(const Vector3 &origin, 103 const Vector3 &termination, 104 Vector3 &clippedOrigin, 105 Vector3 &clippedTermination); 100 106 101 107 const Preprocessor &mPreprocessor; -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
r1931 r1942 2299 2299 { 2300 2300 Vector3 origin = sbox.GetPoint(Vector3(params[0], params[1], params[2])); 2301 2302 2301 Vector3 dirVector = sDirBBox.GetPoint(Vector3(params[3], params[4], 0.0f)); 2303 2304 2302 Vector3 direction = VssRay::GetInvDirParam(dirVector.x, dirVector.y); 2305 2303 … … 2308 2306 float minT, maxT; 2309 2307 2310 float boxSize = Magnitude(sbox.Size());2311 2308 // compute interection of the ray with the box 2312 2309 #if 1 2313 2310 if (sbox.ComputeMinMaxT(origin, direction, &minT, &maxT) && minT < maxT) 2314 dist = (maxT + 0.0f*boxSize);2311 dist = (maxT + Limits::Small); 2315 2312 #else 2313 float boxSize = Magnitude(sbox.Size()); 2316 2314 dist = 0.5f*boxSize; 2317 2315 #endif 2318 2316 2319 2317 origin += direction*dist; 2320 2318 2321 2319 //Debug<<"dir vector.x="<<dirVector.x<<"direction'.x="<<atan2(direction.x, direction.y)<<endl; 2322 2320 rays.push_back(SimpleRay(origin, … … 2765 2763 sumContributions += c1; 2766 2764 if (c1 > maxContribution) 2767 2765 maxContribution = c1; 2768 2766 2769 2767 //$$ 20.7. changed to sqr to pronouce higher contribution so that … … 2806 2804 pow(((weightAbsContributions*sumContributions + 2807 2805 (1.0f - weightAbsContributions)*sumRelContributions)/sumWeights), 1.0f); 2808 #else 12806 #else 2809 2807 leaf->mImportance = 2810 2808 (weightAbsContributions*maxContribution + -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r1931 r1942 527 527 528 528 float contribution = 529 mPreprocessor.mViewCellsManager->ComputeSampleContribution(*ray, true, false); 529 mPreprocessor.mViewCellsManager->ComputeSampleContribution(*ray, 530 true, 531 false); 530 532 531 533 mDistributions[i]->mContribution += contribution; … … 536 538 } 537 539 540 541 UpdateRatios(); 542 } 543 544 void 545 MixtureDistribution::UpdateDistributions(VssRayContainer &vssRays) 546 { 538 547 // 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++) { 540 549 mDistributions[i]->Update(vssRays); 541 550 } 542 543 544 UpdateRatios(); 545 } 546 551 } 552 547 553 void 548 554 MixtureDistribution::UpdateRatios() -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r1901 r1942 269 269 void ComputeContributions(VssRayContainer &vssRays); 270 270 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 271 276 void 272 277 UpdateRatios(); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1935 r1942 31 31 #define USE_RAY_LENGTH_AS_CONTRIBUTION 0 32 32 #define DIST_WEIGHTED_CONTRIBUTION 0 33 #define SUM_RAY_CONTRIBUTIONS 034 #define AVG_RAY_CONTRIBUTIONS 135 #define CONTRIBUTION_RELATIVE_TO_PVS_SIZE 133 #define SUM_RAY_CONTRIBUTIONS 1 34 #define AVG_RAY_CONTRIBUTIONS 0 35 #define CONTRIBUTION_RELATIVE_TO_PVS_SIZE 0 36 36 #define PVS_ADD_DIRTY 1 37 37 … … 1996 1996 stat.avgFilterRadius = 0; 1997 1997 stat.avgFilterRatio = 0; 1998 stat.avgRelPvsIncrease = 0.0f; 1999 stat.devRelPvsIncrease = 0.0f; 1998 2000 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++) 2000 2014 { 2001 2015 ViewCell *viewcell = *it; … … 2010 2024 stat.avgPvs += pvsCost; 2011 2025 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 2014 2035 2015 2036 … … 2040 2061 } 2041 2062 } 2063 2064 2042 2065 2043 2066 if (stat.viewcells) { … … 2046 2069 stat.avgFilterContribution/=stat.viewcells; 2047 2070 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); 2049 2080 } 2081 2050 2082 } 2051 2083 … … 2063 2095 s<<"#MAX_PVS\n"<<pvsStat.maxPvs<<endl; 2064 2096 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; 2065 2099 } 2066 2100 … … 2178 2212 const bool addRays) 2179 2213 { 2180 2214 // check if we are outside of view space 2181 2215 if (!obj || !viewCell->GetValid()) 2182 2216 return; 2183 2217 2184 2218 // if ray not outside of view space 2185 2219 float relContribution = 0.0f; 2186 2220 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 2209 2251 #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 2214 2257 #endif 2215 }2216 2258 } 2259 2217 2260 #if SUM_RAY_CONTRIBUTIONS || AVG_RAY_CONTRIBUTIONS 2218 ray.mRelativePvsContribution += relContribution;2261 ray.mRelativePvsContribution += relContribution; 2219 2262 #else 2220 // recalculate relative contribution - use max of AbsContribution2221 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; 2223 2266 #endif 2267 } 2268 2224 2269 } 2225 2270 … … 2243 2288 float tmin = 0, tmax = 1.0; 2244 2289 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 } 2247 2294 2248 2295 Vector3 origin = hray.Extrap(tmin); … … 2254 2301 CastLineSegment(origin, termination, viewCells); 2255 2302 2303 2256 2304 if (storeViewCells) 2257 2305 { 2258 2259 2260 2306 // copy viewcells memory efficiently 2307 ray.mViewCells.reserve(viewCells.size()); 2308 ray.mViewCells = viewCells; 2261 2309 } 2262 2310 … … 2280 2328 #if USE_RAY_LENGTH_AS_CONTRIBUTION 2281 2329 float c = 0.0f; 2282 if ( obj)2283 2330 if (terminationObj) 2331 c = ray.Length(); 2284 2332 ray.mRelativePvsContribution = ray.mPvsContribution = c; 2285 2333 return c; 2286 2334 #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; 2289 2337 #endif 2290 2338 } … … 2897 2945 sqrt((float)objectSamples); 2898 2946 2899 // cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl;2947 // cout<<"os="<<objectSamples<<" lr="<<localRadius<<" gr="<<globalRadius<<endl; 2900 2948 2901 2949 // now compute the filter size -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1932 r1942 81 81 { 82 82 public: 83 struct PvsStatistics 83 84 struct PerViewCellStat { 85 float pvsSize; 86 float relPvsIncrease; 87 }; 88 89 struct PvsStatistics 84 90 { 85 91 float minPvs; … … 90 96 float avgFilterRadius; 91 97 float avgFilterRatio; 98 float avgRelPvsIncrease; 99 float devRelPvsIncrease; 92 100 int viewcells; 93 94 101 }; 95 102 96 103 /// view cell container types 97 104 enum {BSP, KD, VSP_KD, VSP_BSP, VSP_OSP}; … … 789 796 /// if view cells geometry should be used from other sources 790 797 bool mUsePredefinedViewCells; 798 799 800 vector<PerViewCellStat> mPerViewCellStat; 801 791 802 }; 792 803 -
GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.cpp
r1932 r1942 357 357 { 358 358 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 371 367 return (int)selected.size(); 372 368 } -
GTP/trunk/Lib/Vis/Preprocessing/src/default.env
r1931 r1942 43 43 useGlDebugger false 44 44 # 0 = INTERNAL 1 = MLRT 45 46 45 rayCastMethod 1 47 46 … … 62 61 applyVisibilitySpatialFilter false 63 62 visibilityFilterWidth 0.01 64 exportVisibility false63 exportVisibility true 65 64 visibilityFile visibility.xml 66 65 loadMeshes false … … 98 97 99 98 # 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 101 102 # distributions object_direction 102 103 103 104 samplesPerPass 1000000 104 105 initialSamples 2000000 105 vssSamples 150000000106 vssSamples 20000000 106 107 vssSamplesPerPass 5000000 107 108 useImportanceSampling true … … 132 133 # splitType heuristic 133 134 134 minRays 50135 minRays 200 135 136 minSize 0.001 136 137 maxCostRatio 1.0 -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r1940 r1942 28 28 #include "ObjExporter.h" 29 29 #include "SceneGraph.h" 30 #include "GlobalLinesRenderer.h"30 //#include "GlobalLinesRenderer.h" 31 31 32 32 #include "ViewCellsManager.h" -
GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro
r1931 r1942 25 25 unix:INCLUDEPATH += ../support/src/xerces-c-src_2_7_0/include 26 26 27 INCLUDEPATH += ../src $$NONGTP/Xerces/xerces/include $$NONGTP/Zlib/include $$NONGTP/Boost $$NONGTP/Devil/include27 INCLUDEPATH += ../src ../src/QtInterface $$NONGTP/Xerces/xerces/include $$NONGTP/Zlib/include $$NONGTP/Boost $$NONGTP/Devil/include 28 28 29 29 win32:LIBPATH += GL $$NONGTP/Xerces/xerces/lib $$NONGTP/Devil/lib \ … … 87 87 # Input 88 88 HEADERS += Halton.h VssRay.h VssPreprocessor.h RssTree.h GlRenderer.h \ 89 PreprocessorThread.h Preprocessor.h Beam.h QtGlViewer.h89 PreprocessorThread.h Preprocessor.h Beam.h 90 90 91 91 … … 111 111 Trackball.cpp ObjExporter.cpp SubdivisionCandidate.cpp \ 112 112 Mailable.cpp \ 113 CombinedPreprocessor.cpp QtGlViewer.cpp113 CombinedPreprocessor.cpp 114 114 115 115 SOURCES += BoostPreprocessorThread.cpp 116 116 117 117 CONFIG(qt) { 118 HEADERS += QtPreprocessorThread.h QtGlRenderer.h 119 SOURCES += OcclusionQuery.cpp QtPreprocessorThread.cpp QtGlRenderer.cpp 118 HEADERS += QtPreprocessorThread.h QtInterface/QtGlRenderer.h \ 119 QtInterface/QtGlViewer.h 120 SOURCES += OcclusionQuery.cpp QtPreprocessorThread.cpp \ 121 QtInterface/QtGlRenderer.cpp QtInterface/QtGlViewer.cpp 120 122 } else { 121 123 SOURCES += BoostPreprocessorThread.cpp -
GTP/trunk/Lib/Vis/Preprocessing/src/run_test2
r1900 r1942 2 2 3 3 #COMMAND="./release/preprocessor.exe -preprocessor_quit_on_finish+" 4 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter -"4 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter+" 5 5 6 6 #SCENE="../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d" … … 65 65 66 66 $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 70 75 71 76
Note: See TracChangeset
for help on using the changeset viewer.