Changeset 997 for GTP/trunk/Lib/Vis
- Timestamp:
- 05/31/06 10:04:05 (19 years ago)
- Location:
- GTP/trunk/Lib/Vis
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/scripts/TestPreprocessor.vcproj
r991 r997 80 80 <Tool 81 81 Name="VCLinkerTool" 82 AdditionalDependencies="xerces-c_2.lib zdll.lib zziplib.lib devil.lib qtmain.lib QtGui d4.lib Qt3Support4.lib QAxContainer.lib glut32.lib OpenGL32.Lib glu32.lib cg.lib cgGL.lib Preprocessor.lib QtCore4.lib QtOpenGL4.lib"82 AdditionalDependencies="xerces-c_2.lib zdll.lib zziplib.lib devil.lib qtmain.lib QtGui4.lib Qt3Support4.lib QAxContainer.lib glut32.lib OpenGL32.Lib glu32.lib cg.lib cgGL.lib Preprocessor.lib QtCore4.lib QtOpenGL4.lib" 83 83 OutputFile="$(OutDir)/Preprocessor.exe" 84 84 LinkIncremental="1" -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r991 r997 1168 1168 "1000"); 1169 1169 1170 RegisterOption("VssPreprocessor.initialSamples", 1170 RegisterOption("RenderSampler.useOcclusionQueries", 1171 optBool, 1172 "render_sampler_use_occlusion_queries=", 1173 "true"); 1174 1175 RegisterOption("VssPreprocessor.initialSamples", 1171 1176 optInt, 1172 1177 "initial_samples=", … … 1247 1252 "false"); 1248 1253 1249 RegisterOption("ViewCells.Evaluation.histo Passes",1250 optInt, 1251 "view_cells_evaluation_histo_ passes=",1254 RegisterOption("ViewCells.Evaluation.histoStepSize", 1255 optInt, 1256 "view_cells_evaluation_histo_step_size=", 1252 1257 "5000"); 1253 1258 … … 1645 1650 "pvsRenderErrorSamples=", 1646 1651 "10000"); 1647 1648 1652 1649 1653 RegisterOption("Preprocessor.useGlRenderer", … … 1674 1678 RegisterOption("Preprocessor.exportVisibility", 1675 1679 optBool, 1676 "preprocessor_export_visibility ",1680 "preprocessor_export_visibility=", 1677 1681 "true"); 1678 1682 … … 1684 1688 RegisterOption("Preprocessor.applyVisibilityFilter", 1685 1689 optBool, 1686 "preprocessor_apply_filter ",1690 "preprocessor_apply_filter=", 1687 1691 "true"); 1688 1692 1689 1693 RegisterOption("Preprocessor.applyVisibilitySpatialFilter", 1690 1694 optBool, 1691 "preprocessor_apply_spatial_filter ",1695 "preprocessor_apply_spatial_filter=", 1692 1696 "true"); 1693 1697 … … 1719 1723 RegisterOption("VspKdTree.Termination.maxDepth", 1720 1724 optInt, 1721 "vsp_term_maxdepth=", "30"); 1725 "vsp_term_maxdepth=", 1726 "30"); 1722 1727 1723 1728 RegisterOption("VspKdTree.Termination.minPvs", … … 1858 1863 1859 1864 RegisterOption("VssTree.queryPosWeight", optFloat, "qposweight=", "0.0"); 1860 RegisterOption("VssTree.useRefDirSplits", optBool, "refdir ", "false");1865 RegisterOption("VssTree.useRefDirSplits", optBool, "refdir=", "false"); 1861 1866 RegisterOption("VssTree.refDirAngle", optFloat, "refangle=", "10"); 1862 1867 RegisterOption("VssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1"); … … 1890 1895 RegisterOption("RssPreprocessor.useImportanceSampling", 1891 1896 optBool, 1892 "rss_use_importance ",1897 "rss_use_importance=", 1893 1898 "true"); 1894 1899 1895 1900 RegisterOption("RssPreprocessor.objectBasedSampling", 1896 1901 optBool, 1897 "rss_object_based_sampling ",1902 "rss_object_based_sampling=", 1898 1903 "true"); 1899 1904 1900 1905 RegisterOption("RssPreprocessor.directionalSampling", 1901 1906 optBool, 1902 "rss_directional_sampling ",1907 "rss_directional_sampling=", 1903 1908 "false"); 1904 1909 … … 1911 1916 RegisterOption("RssTree.epsilon", optFloat, "kd_eps=", "1e-6"); 1912 1917 RegisterOption("RssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0"); 1913 RegisterOption("RssTree.randomize", optBool, "randomize ", "false");1918 RegisterOption("RssTree.randomize", optBool, "randomize=", "false"); 1914 1919 RegisterOption("RssTree.splitType", optString, "split=", "queries"); 1915 1920 RegisterOption("RssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false"); … … 1931 1936 RegisterOption("RssTree.minCollapseDepth", optInt, "colldepth=", "4"); 1932 1937 1933 RegisterOption("RssTree.interleaveDirSplits", optBool, "interleavedirsplits ", "true");1938 RegisterOption("RssTree.interleaveDirSplits", optBool, "interleavedirsplits=", "true"); 1934 1939 RegisterOption("RssTree.dirSplitDepth", optInt, "dirsplidepth=", "10"); 1935 RegisterOption("RssTree.importanceBasedCost", optBool, "importance_based_cost ", "true");1940 RegisterOption("RssTree.importanceBasedCost", optBool, "importance_based_cost=", "true"); 1936 1941 RegisterOption("RssTree.maxRays", optInt, "rss_max_rays=", "2000000"); 1937 1942 1938 1943 RegisterOption("RssTree.perObjectTree", optBool, "rss_per_object_tree", "false"); 1939 1944 1940 RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs ", "false");1941 RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree ", "false");1942 RegisterOption("RssPreprocessor.Export.rays", optBool, "rss_export_rays ", "false");1945 RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs=", "false"); 1946 RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree=", "false"); 1947 RegisterOption("RssPreprocessor.Export.rays", optBool, "rss_export_rays=", "false"); 1943 1948 RegisterOption("RssPreprocessor.Export.numRays", optInt, "rss_export_num_rays=", "5000"); 1944 RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells ", "false");1949 RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells=", "false"); 1945 1950 RegisterOption("RssPreprocessor.updateSubdivision", 1946 1951 optBool, 1947 "rss_update_subdivision ",1952 "rss_update_subdivision=", 1948 1953 "false"); 1949 1954 … … 1971 1976 RegisterOption("VspBspTree.Termination.minGlobalCostRatio", 1972 1977 optFloat, 1973 "vsp_bsp_term_min_global_cost_ratio ",1978 "vsp_bsp_term_min_global_cost_ratio=", 1974 1979 "0.0001"); 1975 1980 … … 1981 1986 RegisterOption("VspBspTree.Termination.globalCostMissTolerance", 1982 1987 optInt, 1983 "vsp_bsp_term_global_cost_miss_tolerance ",1988 "vsp_bsp_term_global_cost_miss_tolerance=", 1984 1989 "4"); 1985 1990 … … 2050 2055 2051 2056 RegisterOption("VspBspTree.Termination.missTolerance", 2052 optInt, 2053 "vsp_bsp_term_miss_tolerance=", 2054 "4"); 2057 optInt, 2058 "vsp_bsp_term_miss_tolerance=", 2059 "4"); 2060 2055 2061 RegisterOption("VspBspTree.splitPlaneStrategy", 2056 2062 optString, -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r991 r997 444 444 445 445 void 446 GlRendererBuffer::EvalQueryWithItemBuffer( 447 //RenderCostSample &sample 448 ) 449 { 450 // read back the texture 451 glReadPixels(0, 0, 452 GetWidth(), GetHeight(), 453 GL_RGBA, 454 GL_UNSIGNED_BYTE, 455 mPixelBuffer); 456 457 458 unsigned int *p = mPixelBuffer; 459 460 for (int y = 0; y < GetHeight(); y++) 461 { 462 for (int x = 0; x < GetWidth(); x++, p++) 463 { 464 unsigned int id = (*p) & 0xFFFFFF; 465 466 if (id != 0xFFFFFF) 467 ++ mObjects[id]->mCounter; 468 } 469 } 470 } 471 472 473 void 474 GlRendererBuffer::EvalQueryWithOcclusionQueries( 475 //RenderCostSample &sample 476 ) 477 { 478 glDepthFunc(GL_LEQUAL); 479 480 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 481 glDepthMask(GL_FALSE); 482 483 // now issue queries for all objects 484 for (int j = 0; j < mObjects.size(); ++ j) 485 { 486 for (int q = 0; j + q < mObjects.size() && q < mOcclusionQueries.size(); ++ q) 487 { 488 glBeginOcclusionQueryNV(mOcclusionQueries[q]); 489 490 RenderIntersectable(mObjects[j + q]); 491 glEndOcclusionQueryNV(); 492 } 493 494 // collect results of the queries 495 for (int q = 0; j + q < mObjects.size() && q < mOcclusionQueries.size(); ++ q) 496 { 497 unsigned int pixelCount; 498 499 //-- reenable other state 500 #if 1 501 do 502 { 503 glGetOcclusionQueryuivNV(mOcclusionQueries[q], 504 GL_PIXEL_COUNT_AVAILABLE_NV, 505 &pixelCount); 506 507 if (0 && !pixelCount) cout << "W"; 508 } 509 while (!pixelCount); 510 #endif 511 512 glGetOcclusionQueryuivNV(mOcclusionQueries[q], 513 GL_PIXEL_COUNT_NV, 514 &pixelCount); 515 516 // if (pixelCount) 517 // cout<<"q="<<mOcclusionQueries[q]<<" pc="<<pixelCount<<" "; 518 519 mObjects[j + q]->mCounter += pixelCount; 520 } 521 522 j += q; 523 } 524 525 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 526 glDepthMask(GL_TRUE); 527 } 528 529 530 void 446 531 GlRendererBuffer::EvalRenderCostSample( 447 532 RenderCostSample &sample 448 533 ) 449 534 { 450 mViewCellsManager->GetViewPoint(mViewPoint); 451 sample.mPosition = mViewPoint; 452 453 cout << mViewPoint << endl; 454 455 // take a render cost sample by rendering a cube 456 Vector3 directions[6]; 457 directions[0] = Vector3(1,0,0); 458 directions[1] = Vector3(0,1,0); 459 directions[2] = Vector3(0,0,1); 460 directions[3] = Vector3(-1,0,0); 461 directions[4] = Vector3(0,-1,0); 462 directions[5] = Vector3(0,0,-1); 463 464 sample.mVisibleObjects = 0; 465 466 int i, j; 467 468 // reset object visibility 469 for (i=0; i < mObjects.size(); i++) { 470 mObjects[i]->mCounter = 0; 471 } 472 mFrame++; 473 for (i=0; i < 6; i++) { 474 mViewDirection = directions[i]; 475 SetupCamera(); 476 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 477 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 478 479 glDepthFunc( GL_LESS ); 480 481 mUseFalseColors = true; 482 483 RenderScene(); 484 485 if (1) { 486 char filename[256]; 487 sprintf(filename, "snap/frame-%04d-%d.png", mFrame, i); 488 QImage im = toImage(); 489 im.save(filename, "PNG"); 490 } 491 492 bool useItemBuffer = false; 493 494 if (useItemBuffer) { 495 // read back the texture 496 glReadPixels(0, 0, 497 GetWidth(), GetHeight(), 498 GL_RGBA, 499 GL_UNSIGNED_BYTE, 500 mPixelBuffer); 501 502 int x, y; 503 unsigned int *p = mPixelBuffer; 504 for (y = 0; y < GetHeight(); y++) 505 for (x = 0; x < GetWidth(); x++, p++) { 506 unsigned int id = (*p) & 0xFFFFFF; 507 if (id != 0xFFFFFF) 508 mObjects[id]->mCounter++; 535 // choose a random view point 536 mViewCellsManager->GetViewPoint(mViewPoint); 537 sample.mPosition = mViewPoint; 538 //cout << "viewpoint: " << mViewPoint << endl; 539 540 // take a render cost sample by rendering a cube 541 Vector3 directions[6]; 542 543 directions[0] = Vector3(1,0,0); 544 directions[1] = Vector3(0,1,0); 545 directions[2] = Vector3(0,0,1); 546 directions[3] = Vector3(-1,0,0); 547 directions[4] = Vector3(0,-1,0); 548 directions[5] = Vector3(0,0,-1); 549 550 sample.mVisibleObjects = 0; 551 552 int i, j; 553 554 // reset object visibility 555 for (i=0; i < mObjects.size(); i++) 556 { 557 mObjects[i]->mCounter = 0; 558 } 559 560 ++ mFrame; 561 562 // either use occlusion queries or item buffer 563 bool useOcclusionQueries; 564 environment->GetBoolValue("RenderSampler.useOcclusionQueries", useOcclusionQueries); 565 566 //if (useOcclusionQueries) cout << "using occlusion queries" << endl; 567 //else cout << "using item buffer" << endl; 568 569 glCullFace(GL_FRONT); 570 571 if (mDetectEmptyViewSpace) 572 { 573 glEnable(GL_CULL_FACE); 574 cout << "culling" << endl; 575 } 576 else 577 { 578 cout << "not culling" << endl; 579 glDisable(GL_CULL_FACE); 580 } 581 582 for (i = 0; i < 6; ++ i) 583 { 584 mViewDirection = directions[i]; 585 SetupCamera(); 586 587 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 588 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 589 glDepthFunc(GL_LESS); 590 mUseFalseColors = true; 591 592 593 // the actual scene rendering 594 595 RenderScene(); 596 597 598 if (0) 599 { 600 char filename[256]; 601 sprintf(filename, "snap/frame-%04d-%d.png", mFrame, i); 602 QImage im = toImage(); 603 im.save(filename, "PNG"); 509 604 } 510 511 } else { 512 513 // glDepthFunc( GL_LEQUAL ); 514 glDepthFunc( GL_LEQUAL ); 515 516 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 517 glDepthMask(GL_FALSE); 518 519 // now issue queries for all objects 520 for (j = 0; j < mObjects.size(); j++) { 521 int q; 522 for (q = 0; j + q < mObjects.size() && q < mOcclusionQueries.size(); q++) { 523 glBeginOcclusionQueryNV(mOcclusionQueries[q]); 524 RenderIntersectable(mObjects[j+q]); 525 glEndOcclusionQueryNV(); 605 606 if (useOcclusionQueries) 607 { 608 EvalQueryWithOcclusionQueries(); 526 609 } 527 528 529 // collect results of the queries 530 for (q = 0; j + q < mObjects.size() && q < mOcclusionQueries.size(); q++) { 531 unsigned int pixelCount; 532 // reenable other state 533 534 #if 1 535 do { 536 glGetOcclusionQueryuivNV(mOcclusionQueries[q], 537 GL_PIXEL_COUNT_AVAILABLE_NV, 538 &pixelCount); 539 if (!pixelCount) 540 cout<<"W"; 541 } while(!pixelCount); 542 #endif 543 544 glGetOcclusionQueryuivNV(mOcclusionQueries[q], 545 GL_PIXEL_COUNT_NV, 546 &pixelCount); 547 // if (pixelCount) 548 // cout<<"q="<<mOcclusionQueries[q]<<" pc="<<pixelCount<<" "; 549 mObjects[j+q]->mCounter += pixelCount; 610 else 611 { 612 EvalQueryWithItemBuffer(); 550 613 } 551 j += q; 552 } 553 554 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 555 glDepthMask(GL_TRUE); 556 } 557 558 559 } 560 // now evaluate the statistics over that sample 561 // currently only the number of visible objects is taken into account 562 sample.Reset(); 563 for (j = 0; j < mObjects.size(); j++) { 564 if (mObjects[j]->mCounter) { 565 sample.mVisibleObjects++; 566 sample.mVisiblePixels += mObjects[j]->mCounter; 567 } 568 } 569 cout<<"RS="<<sample.mVisibleObjects<<" "; 614 } 615 616 // now evaluate the statistics over that sample 617 // currently only the number of visible objects is taken into account 618 sample.Reset(); 619 620 for (j = 0; j < mObjects.size(); j++) 621 { 622 if (mObjects[j]->mCounter) 623 { 624 ++ sample.mVisibleObjects; 625 sample.mVisiblePixels += mObjects[j]->mCounter; 626 } 627 } 628 629 cout << "RS=" << sample.mVisibleObjects << " "; 570 630 } 571 631 … … 575 635 vector<RenderCostSample> &samples 576 636 ) 577 { cout << "here1" << endl;637 { 578 638 makeCurrent(); 579 639 580 640 if (mPixelBuffer == NULL) 581 mPixelBuffer = new unsigned int[GetWidth()*GetHeight()];641 mPixelBuffer = new unsigned int[GetWidth()*GetHeight()]; 582 642 583 643 SetupProjection(GetHeight(), GetHeight(), 90.0f); … … 589 649 int numQ = 500; 590 650 591 cout << "here2988" << endl;592 651 593 652 if (mOcclusionQueries.size() < numQ) … … 605 664 mOcclusionQueries.resize(numQ); 606 665 607 for (i =0; i < numQ; ++ i)666 for (i = 0; i < numQ; ++ i) 608 667 { 609 668 mOcclusionQueries[i] = queries[i]; … … 613 672 } 614 673 615 for (i =0; i < n; ++ i)674 for (i = 0; i < n; ++ i) 616 675 { 617 cout << i << " ";618 676 EvalRenderCostSample(samples[i]); 619 677 } -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
r991 r997 223 223 vector<PvsErrorEntry> mPvsErrorBuffer; 224 224 225 225 226 private: 226 227 unsigned int *mPixelBuffer; … … 232 233 233 234 Intersectable *sourceObject); 235 236 void EvalQueryWithItemBuffer(); 237 void EvalQueryWithOcclusionQueries(); 234 238 235 239 public: -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r991 r997 275 275 276 276 if (mApplyVisibilityFilter || mApplyVisibilitySpatialFilter) { 277 cout<<"Applying visibility filter ...";278 cout<<"filyter width = " <<mVisibilityFilterWidth<<endl;277 cout<<"Applying visibility filter ..."; 278 cout<<"filyter width = " << mVisibilityFilterWidth << endl; 279 279 280 280 mViewCellsManager->ApplyFilter(mKdTree, 281 281 mApplyVisibilityFilter ? mVisibilityFilterWidth : -1.0f, 282 282 mApplyVisibilitySpatialFilter ? mVisibilityFilterWidth : -1.0f); 283 cout <<"done.";283 cout << "done." << endl; 284 284 } 285 285 … … 354 354 355 355 if (mLoadViewCells) 356 { 356 { 357 357 environment->GetStringValue("ViewCells.filename", buf); 358 358 mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects, environment, true); … … 363 363 char viewCellsStr[64]; 364 364 environment->GetStringValue("ViewCells.type", viewCellsStr); 365 365 366 mViewCellsManager = CreateViewCellsManager(viewCellsStr); 366 367 } 367 368 369 //-- parameters for render heuristics evaluation 368 370 float objRenderCost = 0, vcOverhead = 0, moveSpeed = 0; 369 371 … … 377 379 mViewCellsManager->SetRenderer(mRenderSimulator); 378 380 381 // default view space is the extent of the scene 382 mViewCellsManager->SetViewSpaceBox(mSceneGraph->GetBox()); 379 383 380 384 if (mUseGlRenderer || mUseGlDebugger) -
GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp
r991 r997 30 30 31 31 if (renderer) 32 { cout << "here18 " << mSamples << endl;32 { 33 33 renderer->SampleRenderCost(mSamples, samples); 34 34 } … … 37 37 38 38 39 //-- Evaluate properties39 //-- Evaluate results 40 40 41 41 … … 46 46 vector<int> histogram(intervals); 47 47 48 int i; 49 50 /// initialise histogram 51 for (i = 0; i < intervals; ++ i) 48 // initialise histogram 49 for (int i = 0; i < intervals; ++ i) 52 50 { 53 51 histogram[i] = 0; 54 52 } 55 53 56 57 58 for (i = 0; i < mSamples; ++ i) 54 // store maximal pvs 55 for (int i = 0; i < mSamples; ++ i) 59 56 { 60 57 if (samples[i].mVisibleObjects > maxPvs) … … 67 64 68 65 // sometimes need need to unifiy maximum pvs to compare with other method's histograms 69 // => choose histoMaxPvs accordingly (higher than all pvsss) 66 // => choose histoMaxPvs accordingly (higher than all pvss) ( but smaller than highest possible pvs?) 67 70 68 const int maxVal = max(histoMaxVal, maxPvs); 71 72 for (i = 0; i < mSamples; ++ i) 69 //const int maxVal = min(max(histoMaxVal, maxPvs), mObjects.size()); 70 71 for (int i = 0; i < mSamples; ++ i) 73 72 { 74 73 const int bin = (samples[i].mVisibleObjects * intervals) / maxVal; 74 //const int bin = samples[i].mVisibleObjects; 75 75 76 76 ++ histogram[bin]; … … 85 85 86 86 87 88 87 Debug << "****************************************" << endl; 89 88 Debug << "From point queries: " << endl; 90 89 91 for (i = 0; i < intervals; ++ i)90 for (int i = 0; i < intervals; ++ i) 92 91 { 93 92 outstream << "#Pass\n" << i << endl; 94 outstream << "#Pvs\n" << histogram[i] << endl; 93 outstream << "#Pvs\n" << (float)(i * maxVal) / (float)intervals << endl; 94 95 // HACK: #point samples substitute for volume 96 outstream << "#VolumeDif\n" << (float)histogram[i] / (float)mSamples << endl; 95 97 //cout << histogram[i] << endl; 96 98 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r971 r997 1661 1661 int pvsSize = 0; 1662 1662 1663 if (vc->IsLeaf())1664 {1665 pvsSize = vc->GetPvs().GetSize();1666 }1667 1668 1669 1663 Intersectable::NewMail(); 1670 1664 1671 1665 ////////////////////////// 1666 // for interiors, pvs can be stored using different methods 1667 1672 1668 switch (mViewCellsStorage) 1673 1669 { 1674 1670 case PVS_IN_LEAVES: //-- store pvs only in leaves 1675 1671 { 1672 // pvs is always stored directly in leaves 1673 if (vc->IsLeaf()) 1674 { 1675 pvsSize = vc->GetPvs().GetSize(); 1676 break; 1677 } 1678 1679 // the stored pvs size is the valid pvs size => just return scalar 1676 1680 if (vc->mPvsSizeValid) 1677 1681 { … … 1680 1684 } 1681 1685 1682 //-- if no valid pvs size stored as a scalar => compute new pvs size1686 //-- if no valid pvs size stored as a scalar => compute new pvs size 1683 1687 ViewCellContainer leaves; 1684 1688 CollectLeaves(vc, leaves); … … 1711 1715 { 1712 1716 //////////////////////// 1713 //-- compressed pvs1717 //-- compressed pvs 1714 1718 1715 1719 if (vc->mPvsSizeValid) 1720 { 1716 1721 return vc->mPvsSize; 1717 1718 // if no pvs size stored: compute 1719 int pvsSize = 0; 1720 ViewCell *root = vc; 1721 1722 // also add pvs from this view cell to root 1723 while (root->GetParent()) 1724 { 1725 root = root->GetParent(); 1726 pvsSize += CountDiffPvs(root); 1727 } 1728 1729 stack<ViewCell *> tstack; 1730 tstack.push(vc); 1731 1732 while (!tstack.empty()) 1733 { 1734 vc = tstack.top(); 1735 tstack.pop(); 1736 1737 pvsSize += CountDiffPvs(vc); 1738 1739 if (!vc->IsLeaf()) 1740 { 1741 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1742 1743 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1744 1745 for (it = interior->mChildren.begin(); it != it_end; ++ it) 1722 } 1723 1724 // if no pvs size stored, compute new one 1725 int pvsSize = 0; 1726 ViewCell *root = vc; 1727 1728 // also add pvs from this view cell to root 1729 while (root->GetParent()) 1746 1730 { 1747 tstack.push(*it); 1748 } 1749 } 1750 } 1731 root = root->GetParent(); 1732 pvsSize += CountDiffPvs(root); 1733 } 1734 1735 stack<ViewCell *> tstack; 1736 tstack.push(vc); 1737 1738 while (!tstack.empty()) 1739 { 1740 vc = tstack.top(); 1741 tstack.pop(); 1742 1743 pvsSize += CountDiffPvs(vc); 1744 1745 if (!vc->IsLeaf()) 1746 { 1747 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1748 1749 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1750 1751 for (it = interior->mChildren.begin(); it != it_end; ++ it) 1752 { 1753 tstack.push(*it); 1754 } 1755 } 1756 } 1751 1757 break; 1752 1758 } 1753 1759 case PVS_IN_INTERIORS: 1754 default:Debug << "in interiors: " << vc->mPvsSize << " $$ " << vc->GetPvs().GetSize() << endl; 1760 default: 1761 Debug << "in interiors: " << vc->mPvsSize << " $$ " << vc->GetPvs().GetSize() << endl; 1755 1762 pvsSize = vc->GetPvs().GetSize(); 1756 1763 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r971 r997 193 193 static bool SmallerPvs(const ViewCell *a, const ViewCell *b) 194 194 { 195 return a->GetPvs().GetSize() < b->GetPvs().GetSize(); 196 } 197 198 static bool SmallerRenderCost(const ViewCell *a, const ViewCell *b) 199 { 200 return a->GetRenderCost() < b->GetRenderCost(); 201 } 202 203 static bool LargerRenderCost(const ViewCell *a, const ViewCell *b) 204 { 205 return a->GetRenderCost() > b->GetRenderCost(); 206 } 195 // HACK: take scalar value because pvs may not have been stored properly 196 #if 1 197 return a->mPvsSize < b->mPvsSize; 198 #else 199 return a->GetPvs().GetSize() < b->GetPvs().GetSize(); 200 #endif 201 } 202 203 static bool SmallerRenderCost(const ViewCell *a, const ViewCell *b) 204 { 205 return a->GetRenderCost() < b->GetRenderCost(); 206 } 207 208 static bool LargerRenderCost(const ViewCell *a, const ViewCell *b) 209 { 210 return a->GetRenderCost() > b->GetRenderCost(); 211 } 207 212 208 213 void SetMergeCost(const float mergeCost); 214 209 215 float GetMergeCost() const; 210 static void NewMail(const int reserve = 1) { 216 217 static void NewMail(const int reserve = 1) 218 { 211 219 sMailId += sReservedMailboxes; 212 220 sReservedMailboxes = reserve; 213 221 } 222 214 223 void Mail() { mMailbox = sMailId; } 215 224 bool Mailed() const { return mMailbox == sMailId; } … … 309 318 310 319 311 /// points to the currently active view cell. 320 /** points to the currently active view cell. This is the 321 view cell representing the current brach. 322 */ 312 323 ViewCell *mActiveViewCell; 313 324 }; … … 349 360 350 361 public: 362 /** View cells tree constructor taking a view cell mnanager and 363 an environment as parameters. 364 */ 351 365 ViewCellsTree(ViewCellsManager *vcm, Environment *env); 352 366 ~ViewCellsTree(); … … 372 386 373 387 /** Assign colors to the viewcells so that they can be renderered interactively without 374 color flickering.375 388 color flickering. 389 */ 376 390 void AssignRandomColors(); 377 391 378 /** Updates view cell stats for this particular view cell 392 /** Updates view cell stats for this particular view cell. 379 393 */ 380 394 void UpdateViewCellsStats(ViewCell *vc, ViewCellsStatistics &vcStat); 381 395 382 396 383 /** Get costs resulting from each merge step. */ 397 /** Get costs resulting from each merge step. 398 */ 384 399 void GetCostFunction(vector<float> &costFunction); 385 400 … … 465 480 466 481 467 ////////////////////////////////////////////////////////////// 468 // merge related stuff //469 ////////////////////////////////////////////////////////////// 482 ///////////////////////////////////////////////////////////////// 483 // merge related stuff // 484 ///////////////////////////////////////////////////////////////// 470 485 471 486 /** Computes render cost of the merged pvs. … … 525 540 const int numNewViewCells); 526 541 527 /** merge queue must be reset after some time because expected value542 /** Merge queue must be reset after some time because expected value 528 543 may not be valid. 529 544 */ … … 535 550 int UpdateActiveViewCells(ViewCellContainer &viewCells); 536 551 552 /** Helper function pullling pvs as high up in the tree as possible. 553 */ 537 554 void PullUpVisibility(ViewCellInterior *interior); 538 555 556 /** Compress pvs of view cell and children. 557 */ 539 558 void CompressViewCellsPvs(ViewCell *root); 540 559 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r991 r997 568 568 Debug << "histogram min rc: " << minRenderCost << " max rc: " << maxRenderCost << endl; 569 569 570 571 const int intervals = min(20, (int)viewCells.size()); 572 570 int histoIntervals; 571 mEnvironment->GetIntValue("Preprocessor.histogram.intervals", histoIntervals); 572 const int intervals = min(histoIntervals, (int)viewCells.size()); 573 574 int histoMaxVal; 575 mEnvironment->GetIntValue("Preprocessor.histogram.maxValue", histoMaxVal); 576 maxRenderCost = max(histoMaxVal, maxRenderCost); 577 578 573 579 const float range = maxRenderCost - minRenderCost; 574 580 const float stepSize = range / (float)intervals; … … 580 586 //const float totalVol = mViewCellsTree->GetRoot()->GetVolume(); 581 587 582 //float vol = 0;583 //int smallerCost = 0;584 588 int j = 0; 585 589 int i = 0; … … 677 681 const ObjectContainer &objects) 678 682 { 683 if (!ViewCellsConstructed()) 684 return false; 685 679 686 cout << "exporting view cells to xml ... "; 680 687 681 688 #if ZIPPED_VIEWCELLS 682 689 ogzstream stream(filename.c_str()); 683 cout << "!!!!!!!!!!!!!!!!!!!!!!" << endl;684 690 #else 685 691 std::ofstream stream(filename.c_str()); … … 755 761 mViewCellsTree->CollectBestViewCellSet(viewCells, nViewCells); 756 762 757 int maxPvs Size, minPvsSize;758 759 // sort by render cost763 int maxPvs, maxVal, minVal; 764 765 // sort by pvs size 760 766 sort(viewCells.begin(), viewCells.end(), ViewCell::SmallerPvs); 761 767 762 minPvsSize = viewCells.front()->GetPvs().GetSize(); 763 maxPvsSize = viewCells.back()->GetPvs().GetSize(); 764 minPvsSize = 0; 768 //Debug << "********************" << endl; 769 //for (int i = 0; i < viewCells.size(); ++ i) 770 // Debug << "pvs: " << mViewCellsTree->GetPvsSize(viewCells[i]) << " "; 771 //Debug << "\n"; 772 maxPvs = mViewCellsTree->GetPvsSize(viewCells.back()); 773 minVal = 0; 774 765 775 // hack: normalize pvs size 766 maxPvsSize = 1200; 767 minPvsSize = 0; 768 maxPvsSize = 1200; 769 770 Debug << "histogram minpvssize: " << minPvsSize << " maxpvssize: " << maxPvsSize << endl; 771 772 773 const int intervals = min(20, (int)viewCells.size()); 774 const int range = maxPvsSize - minPvsSize; 776 int histoMaxVal; 777 mEnvironment->GetIntValue("Preprocessor.histogram.maxValue", histoMaxVal); 778 maxVal = max(histoMaxVal, maxPvs); 779 780 Debug << "histogram minpvssize: " << minVal << " maxpvssize: " << maxVal << " real maxpvs " << maxPvs << endl; 781 782 int histoIntervals; 783 mEnvironment->GetIntValue("Preprocessor.histogram.intervals", histoIntervals); 784 const int intervals = min(histoIntervals, (int)viewCells.size()); 785 786 const int range = maxVal - minVal; 775 787 int stepSize = range / intervals; 776 788 777 789 // set step size to avoid endless loop 778 790 if (!stepSize) stepSize = 1; 779 791 780 792 Debug << "stepsize: " << stepSize << endl; 781 cout << "stepsize: " << stepSize << endl;793 782 794 783 795 const float totalRenderCost = mViewCellsTree->GetRoot()->GetRenderCost(); 784 796 const float totalVol = GetViewSpaceBox().GetVolume(); 785 797 786 int currentPvs Size = minPvsSize;//(int)ceil(minRenderCost);787 788 //float vol = 0;798 int currentPvs = minVal;//(int)ceil(minRenderCost); 799 800 789 801 int i = 0; 790 802 int j = 0; … … 795 807 ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end(); 796 808 797 while (1)809 for (int j = 0; j < intervals; ++ j) 798 810 { 799 811 float volDif = 0; 800 812 int smallerDif = 0; 801 813 802 while ((i < (int)viewCells.size()) && (viewCells[i]->GetPvs().GetSize() < currentPvsSize)) 814 while ((i < (int)viewCells.size()) && 815 (mViewCellsTree->GetPvsSize(viewCells[i]) < currentPvs)) 803 816 { 804 817 volDif += viewCells[i]->GetVolume(); 805 818 volSum += viewCells[i]->GetVolume(); 819 806 820 ++ i; 807 821 ++ smallerDif; … … 809 823 } 810 824 811 //if (i < (int)viewCells.size()) 812 // Debug << "new pvs size increase: " << viewCells[i]->GetPvs().GetSize() << " " << currentPvsSize << endl; 813 814 if ((i >= (int)viewCells.size()) || (currentPvsSize >= maxPvsSize)) 815 break; 816 825 if (0 && (i < (int)viewCells.size())) 826 Debug << "new pvs size increase: " << mViewCellsTree->GetPvsSize(viewCells[i]) << " " << currentPvs << endl; 827 817 828 const float volRatioDif = volDif / totalVol; 818 829 const float volRatioSum = volSum / totalVol; 819 830 820 outstream << "#Pass\n" << j ++<< endl;821 outstream << "#Pvs\n" << currentPvs Size<< endl;831 outstream << "#Pass\n" << j << endl; 832 outstream << "#Pvs\n" << currentPvs << endl; 822 833 outstream << "#ViewCellsDif\n" << smallerDif << endl; 823 834 outstream << "#ViewCellsSum\n" << smallerSum << endl; 824 835 outstream << "#VolumeDif\n" << volRatioDif << endl << endl; 825 836 outstream << "#VolumeSum\n" << volRatioSum << endl << endl; 826 827 // increase current pvs size 828 currentPvsSize += stepSize; 837 838 //if ((i >= (int)viewCells.size()) || (currentPvs >= maxPvs)) break; 839 840 //-- increase current pvs size to define next interval 841 currentPvs += stepSize; 829 842 } 830 843 … … 856 869 857 870 858 /*ViewCellContainer leaves;859 mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);860 */861 871 cout << "reseting pvs ... "; 862 872 … … 922 932 } 923 933 934 935 //-- histogram 936 937 924 938 bool useHisto; 925 int histo Passes;939 int histoStepSize; 926 940 927 941 mEnvironment->GetBoolValue("ViewCells.Evaluation.histogram", useHisto); 928 mEnvironment->GetIntValue("ViewCells.Evaluation.histoPasses", histoPasses); 929 942 mEnvironment->GetIntValue("ViewCells.Evaluation.histoStepSize", histoStepSize); 943 944 Debug << "here21 " << histoStepSize << endl; 930 945 const int numLeaves = mViewCellsTree->GetNumInitialViewCells(mViewCellsTree->GetRoot()); 931 946 932 //Debug << "number of leaves: " << numLeaves << endl;933 //cout << "number of leaves: " << numLeaves << endl;934 947 935 948 if (useHisto) … … 937 950 // evaluate view cells in a histogram 938 951 char s[64]; 952 953 for (int pass = histoStepSize; pass <= numLeaves; pass += histoStepSize) 954 { 955 string filename; 956 957 cout << "computing histogram for " << pass << " view cells" << endl; 939 958 #if 0 940 for (int passes = 1; passes <= histoPasses; ++ passes)941 {942 int n = numLeaves * passes / histoPasses;943 944 cout << "computing histogram for " << n << " view cells" << endl;945 946 //-- evaluate histogram for render cost947 sprintf(s, "-%09d-histo.log", n);948 string filename = string(statsPrefix) + string(s);949 950 EvalViewCellHistogram(filename, n);951 952 //////////////////////////////////////////953 // --evaluate histogram for pvs size954 955 cout << "computing pvs histogram for " << n << " view cells" << endl;956 957 sprintf(s, "-%09d-histo-pvs.log", n);958 filename = string(statsPrefix) + string(s);959 960 EvalViewCellHistogramForPvsSize(filename, n);961 }962 #else963 for (int pass = histoPasses; pass <= numLeaves; pass += histoPasses)964 {965 cout << "computing histogram for " << pass << " view cells" << endl;966 967 959 //-- evaluate histogram for render cost 968 960 sprintf(s, "-%09d-histo.log", pass); 969 stringfilename = string(statsPrefix) + string(s);961 filename = string(statsPrefix) + string(s); 970 962 971 963 EvalViewCellHistogram(filename, pass); 972 964 965 #endif 973 966 ////////////////////////////////////////// 974 967 //-- evaluate histogram for pvs size … … 981 974 EvalViewCellHistogramForPvsSize(filename, pass); 982 975 } 983 #endif984 976 } 985 977 … … 1250 1242 ) 1251 1243 { 1252 sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 1253 1254 int start = mViewCells.size()*minValid; 1255 int end = mViewCells.size()*maxValid; 1256 1257 for (int i=0; i < mViewCells.size(); i++) 1258 { 1259 mViewCells[i]->SetValid(i >= start && i <= end); 1260 1261 } 1244 sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 1245 1246 int start = mViewCells.size()*minValid; 1247 int end = mViewCells.size()*maxValid; 1248 1249 for (int i = 0; i < mViewCells.size(); ++ i) 1250 { 1251 mViewCells[i]->SetValid(i >= start && i <= end); 1252 } 1262 1253 } 1263 1254 … … 1293 1284 { 1294 1285 viewPoint = mViewSpaceBox.GetRandomPoint(); 1295 1296 1286 return true; 1297 1287 } … … 2537 2527 Debug << "\nOutput view cells: " << endl; 2538 2528 2539 // sort view cells to getlargest view cells2529 // sort view cells in order to find the largest view cells 2540 2530 if (0) 2541 2531 stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); … … 4289 4279 } 4290 4280 } 4281 4291 4282 Debug << "failed to find valid view point, taking " << viewPoint << endl; 4292 4283 return false; … … 4709 4700 int numSamples; 4710 4701 4711 environment->GetIntValue("RenderSampler.samples", numSamples);4702 mEnvironment->GetIntValue("RenderSampler.samples", numSamples); 4712 4703 cout << "samples" << numSamples << endl; 4713 4704 … … 5022 5013 // center + Vector3(viewSpaceFilterSize/2)); 5023 5014 5015 if (!ViewCellsConstructed()) 5016 return; 5017 5024 5018 if (viewSpaceFilterSize >=0.0f) { 5025 5019 … … 5067 5061 ) 5068 5062 { 5063 5064 if (!ViewCellsConstructed()) 5065 return; 5069 5066 5070 5067 ViewCellContainer::const_iterator it, it_end = mViewCells.end(); -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r991 r997 28 28 int 29 29 main(int argc, char **argv) 30 { QApplication *app = new QApplication(argc, argv);30 { 31 31 32 cout << "here222237" << endl; 33 //Now just call this function at the start of your program and if you're 34 //compiling in debug mode (F5), any leaks will be displayed in the Output 35 //window when the program shuts down. If you're not in debug mode this will 36 //be ignored. Use it as you will! 37 //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() { 32 //Now just call this function at the start of your program and if you're 33 //compiling in debug mode (F5), any leaks will be displayed in the Output 34 //window when the program shuts down. If you're not in debug mode this will 35 //be ignored. Use it as you will! 36 //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() { 38 37 _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); 39 38 _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE); 40 39 _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 41 cout << "here3" << endl; 42 Debug.open("debug.log"); cout << "here2" << endl;40 41 Debug.open("debug.log"); 43 42 environment = new Environment; 44 cout << "here122223" << endl; cout.flush();43 45 44 environment->Parse(argc, argv, USE_EXE_PATH); 46 45 MeshKdTree::ParseEnvironment(); 47 cout << "here222283" << endl; 46 48 47 char buff[128]; 49 48 environment->GetStringValue("Preprocessor.type", buff); … … 51 50 52 51 Preprocessor *p; 53 cout << "here22223" << endl; 52 54 53 if (preprocessorType == "vss") 55 { cout << "here223" << endl;56 p = new VssPreprocessor();54 { 55 p = new VssPreprocessor(); 57 56 } 58 57 else … … 68 67 if (preprocessorType == "render") 69 68 { 70 cout << "here23" << endl; 71 p = new RenderSampler(); 69 p = new RenderSampler(); 72 70 } 73 71 else { … … 78 76 79 77 80 //QApplication *app = NULL;78 QApplication *app = NULL; 81 79 82 80 if (p->mUseGlRenderer || p->mUseGlDebugger) { 83 cout << "here1111" << endl;81 84 82 // create a qt application first (must be created before any opengl widget... 85 //app = new QApplication(argc, argv);86 cout << "here1112" << endl;83 app = new QApplication(argc, argv); 84 87 85 if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) { 88 cout << "here1133" << endl;cout.flush();89 86 QMessageBox::information(0, "OpenGL pbuffers", 90 87 "This system does not support OpenGL/pbuffers.", … … 92 89 return -1; 93 90 } 94 cout << "here1119" << endl;95 91 } 96 cout << "here1123" << endl;92 97 93 preprocessor = p; 98 94 … … 103 99 p->BuildKdTree(); 104 100 p->KdTreeStatistics(cout); 105 cout << "here1199" << endl;101 106 102 // parse view cells related options 107 103 p->PrepareViewCells(); 108 104 109 cout << "here1117" << endl; 105 110 106 // create a preprocessor thread 111 107 PreprocessorThread *pt = new PreprocessorThread(p, app); … … 116 112 p->Export(filename + "-kdtree.x3d", false, true, false); 117 113 } 118 cout << "here1118" << endl; 114 119 115 if (p->mUseGlRenderer) { 120 cout << "here1114" << endl;116 121 117 rendererWidget = new GlRendererWidget(p->mSceneGraph, p->mViewCellsManager, p->mKdTree); 122 118 // renderer->resize(640, 480); 123 cout << "here1115" << endl;119 124 120 rendererWidget->resize(640, 480); 125 121 rendererWidget->show(); 126 cout << "here1113" << endl;122 127 123 if (p->GetRenderer()) { 128 124
Note: See TracChangeset
for help on using the changeset viewer.