Changeset 1718 for GTP/trunk/Lib/Vis
- Timestamp:
- 11/07/06 13:56:58 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1717 r1718 838 838 839 839 const AxisAlignedBox3 nodeBbox = tData.mNode->GetBoundingBox(); 840 841 const float minBox = nodeBbox.Min(axis);842 const float maxBox = nodeBbox.Max(axis);843 840 const float boxArea = nodeBbox.SurfaceArea(); 844 841 845 842 float minSum = 1e20f; 846 843 847 float minBorder = maxBox;848 float maxBorder = minBox;844 float minBorder = nodeBbox.Max(axis); 845 float maxBorder = nodeBbox.Min(axis); 849 846 float areaLeft = 0, areaRight = 0; 850 847 … … 854 851 vector<float> bordersRight; 855 852 856 if (mUseBboxAreaForSah) 857 { 858 // we keep track of both borders of the bounding boxes => 859 // store the events in descending order 860 861 bordersRight.resize(mSubdivisionCandidates->size()); 862 863 SortableEntryContainer::reverse_iterator rcit = 864 mSubdivisionCandidates->rbegin(), rcit_end = 865 mSubdivisionCandidates->rend(); 866 867 vector<float>::reverse_iterator rbit = bordersRight.rbegin(); 868 869 for (; rcit != rcit_end; ++ rcit, ++ rbit) 870 { 871 Intersectable *obj = (*rcit).mObject; 872 const AxisAlignedBox3 obox = obj->GetBox(); 873 874 if (obox.Min(axis) < minBorder) 875 { 876 minBorder = obox.Min(axis); 877 } 878 879 (*rbit) = minBorder; 880 } 853 // we keep track of both borders of the bounding boxes => 854 // store the events in descending order 855 856 bordersRight.resize(mSubdivisionCandidates->size()); 857 858 SortableEntryContainer::reverse_iterator rcit = 859 mSubdivisionCandidates->rbegin(), rcit_end = 860 mSubdivisionCandidates->rend(); 861 862 vector<float>::reverse_iterator rbit = bordersRight.rbegin(); 863 864 for (; rcit != rcit_end; ++ rcit, ++ rbit) 865 { 866 Intersectable *obj = (*rcit).mObject; 867 const AxisAlignedBox3 obox = obj->GetBox(); 868 869 if (obox.Min(axis) < minBorder) 870 { 871 minBorder = obox.Min(axis); 872 } 873 874 (*rbit) = minBorder; 881 875 } 882 876 … … 899 893 const AxisAlignedBox3 obox = obj->GetBox(); 900 894 901 if (mUseBboxAreaForSah) 902 { 903 AxisAlignedBox3 lbox = nodeBbox; 904 AxisAlignedBox3 rbox = nodeBbox; 905 906 // the borders of the bounding boxes have changed 907 if (obox.Max(axis) > maxBorder) 908 { 909 maxBorder = obox.Max(axis); 910 } 911 912 minBorder = (*bit); 913 914 lbox.SetMax(axis, maxBorder); 915 rbox.SetMin(axis, minBorder); 916 917 al = lbox.SurfaceArea(); 918 ar = rbox.SurfaceArea(); 919 } 920 else 921 { 922 // just add up areas of the objects itself 923 // As we are not sampling volumetric visibility, 924 // this should provide better heuristics 925 const float area = obj->GetArea();//obox.SurfaceArea(); 926 927 al += area; 928 ar -= area; 929 } 895 // the borders of the bounding boxes have changed 896 if (obox.Max(axis) > maxBorder) 897 { 898 maxBorder = obox.Max(axis); 899 } 900 901 minBorder = (*bit); 902 903 AxisAlignedBox3 lbox = nodeBbox; 904 AxisAlignedBox3 rbox = nodeBbox; 905 906 lbox.SetMax(axis, maxBorder); 907 rbox.SetMin(axis, minBorder); 908 909 al = lbox.SurfaceArea(); 910 ar = rbox.SurfaceArea(); 930 911 931 912 const bool noValidSplit = ((objectsLeft <= Limits::Small) || (objectsRight <= Limits::Small)); 932 933 913 const float sum = noValidSplit ? 1e25 : objectsLeft * al + objectsRight * ar; 934 914 … … 1054 1034 AxisAlignedBox3 rbox = nodeBbox; 1055 1035 1056 // the borders of the bounding boxeshave changed1036 // the borders of the left bounding box have changed 1057 1037 for (int i = 0; i < 3; ++ i) 1058 1038 { … … 2386 2366 2387 2367 2388 } 2368 void BvHierarchy::CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects) 2369 { 2370 stack<BvhNode *> nodeStack; 2371 2372 nodeStack.push(mRoot); 2373 2374 while (!nodeStack.empty()) 2375 { 2376 BvhNode *node = nodeStack.top(); 2377 2378 nodeStack.pop(); 2379 2380 if (node->IsLeaf()) 2381 { 2382 BvhLeaf *leaf = (BvhLeaf *)node; 2383 2384 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 2385 2386 for (oit = leaf->mObjects.begin(); oit != oit_end; ++oit) 2387 { 2388 Intersectable *object = *oit; 2389 if (Overlap(box, object->GetBox())) 2390 { 2391 object->Mail(); 2392 objects.push_back(object); 2393 } 2394 } 2395 } 2396 else 2397 { 2398 BvhInterior *interior = (BvhInterior *)node; 2399 2400 if (Overlap(box, interior->GetBoundingBox())) 2401 nodeStack.push(interior->GetFront()); 2402 2403 if (Overlap(box, interior->GetBoundingBox())) 2404 nodeStack.push(interior->GetBack()); 2405 } 2406 } 2407 } 2408 2409 } -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1707 r1718 613 613 static float EvalAbsCost(const ObjectContainer &objects); 614 614 615 void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects); 615 616 616 617 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1715 r1718 1607 1607 const int entriesInPvs, 1608 1608 const float memoryCost, 1609 const bool vsp) 1609 const int viewSpaceSplits, 1610 const int objectSpaceSplits) 1610 1611 { 1611 1612 stats << "#Pass\n" << 0 << endl … … 1614 1615 << "#TotalEntriesInPvs\n" << entriesInPvs << endl 1615 1616 << "#Memory\n" << memoryCost << endl 1616 << "#Vsp\n" << (vsp ? 1 : 0) << endl 1617 << "#ViewSpaceSplits\n" << viewSpaceSplits << endl 1618 << "#ObjectSpaceSplits\n" << objectSpaceSplits << endl 1619 << "#VspOspRatio\n" << (float)viewSpaceSplits / (float)objectSpaceSplits << endl 1617 1620 << endl; 1618 1621 } … … 1782 1785 float &renderCost, 1783 1786 float &memory, 1784 int &pvsEntries) 1787 int &pvsEntries, 1788 int &viewSpaceSplits, 1789 int &objectSpaceSplits) 1785 1790 { 1786 1791 ViewCellContainer viewCells; … … 1844 1849 1845 1850 memory = pvsEntries * ObjectPvs::GetEntrySize(); 1851 1852 viewSpaceSplits = (int)viewCells.size(); 1853 objectSpaceSplits = (int)bvhNodes.size(); 1854 1846 1855 //cout << "viewCells: " << (int)viewCells.size() << " nodes: " << (int)bvhNodes.size() << " rc: " << renderCost << " entries: " << pvsEntries << endl; 1847 1856 … … 1857 1866 int entriesInPvs = 1; 1858 1867 int steps = 0; 1868 int viewSpaceSplits = 0; 1869 int objectSpaceSplits = 0; 1859 1870 1860 1871 cout << "exporting vsposp stats ... " << endl; … … 1864 1875 //-- first view cell 1865 1876 1866 UpdateStats(stats, 2, totalRenderCost, entriesInPvs, memoryCost, true);1877 UpdateStats(stats, 2, totalRenderCost, entriesInPvs, memoryCost, viewSpaceSplits, objectSpaceSplits); 1867 1878 1868 1879 //-- go through tree in the order of render cost decrease … … 1907 1918 entriesInPvs += entriesIncr; 1908 1919 // if (rcDecr <= 0) 1909 if (nextCandidate->Type() == SubdivisionCandidate::VIEW_SPACE) 1920 if (nextCandidate->Type() == SubdivisionCandidate::VIEW_SPACE) 1921 { 1922 ++ viewSpaceSplits; 1910 1923 cout << "v";//cout << "vsp t: " << timeStamp << " rc: " << rcDecr << " pvs: " << entriesIncr << endl; 1924 } 1911 1925 else 1926 { 1927 ++ objectSpaceSplits; 1912 1928 cout << "o";//"osp t: " << timeStamp << " rc: " << rcDecr << " pvs: " << entriesIncr << endl; 1929 } 1913 1930 1914 1931 ++ steps; … … 1916 1933 if ((steps % 500) == 499) 1917 1934 cout << steps << " steps taken" << endl; 1935 1918 1936 const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize(); 1919 UpdateStats(stats, steps, totalRenderCost, entriesInPvs, memoryCost, false);1937 UpdateStats(stats, steps, totalRenderCost, entriesInPvs, memoryCost, viewSpaceSplits, objectSpaceSplits); 1920 1938 } 1921 1939 … … 2010 2028 float memory; 2011 2029 int pvsEntries; 2030 int viewSpaceSplits; 2031 int objectSpaceSplits; 2012 2032 2013 2033 while (1) 2014 2034 { 2015 const int numSplits = ExtractStatistics(splits, 99999.0, renderCost, memory, pvsEntries); 2035 const int numSplits = ExtractStatistics(splits, 2036 99999.0, 2037 renderCost, 2038 memory, 2039 pvsEntries, 2040 viewSpaceSplits, 2041 objectSpaceSplits); 2016 2042 2017 UpdateStats(splitsStats, numSplits, renderCost, pvsEntries, memory, 0); 2043 UpdateStats(splitsStats, 2044 numSplits, 2045 renderCost, 2046 pvsEntries, 2047 memory, 2048 viewSpaceSplits, 2049 objectSpaceSplits); 2050 2018 2051 splits += splitsStepSize; 2019 2052 … … 2023 2056 } 2024 2057 2025 } 2058 2059 void HierarchyManager::CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects) 2060 { 2061 } 2062 2063 } -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1713 r1718 244 244 245 245 246 void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects); 247 246 248 float mInitialRenderCost; 247 249 … … 463 465 float &renderCost, 464 466 float &memory, 465 int &pvsEntries); 467 int &pvsEntries, 468 int &viewSpaceSplits, 469 int &objectSpaceSplits); 466 470 467 471 -
GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
r1708 r1718 206 206 Name="VCLinkerTool" 207 207 AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib RTScene.lib RTWorld.lib QtCore4.lib qtmain.lib QtOpenGL4.lib Qt3Support4.lib QtTest4.lib QtGui4.lib QtGlRenderer.lib" 208 OutputFile="../bin/release/Preprocessor .exe"208 OutputFile="../bin/release/Preprocessor2.exe" 209 209 LinkIncremental="1" 210 210 AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release;"$(QTDIR)\lib";.\QtGlRenderer\Release" -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1717 r1718 2628 2628 2629 2629 2630 void 2631 ViewCellsManager::UpdatePvsForEvaluation() 2632 { 2633 ObjectPvs objPvs; 2634 UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), objPvs); 2630 void ViewCellsManager::UpdatePvsForEvaluation() 2631 { 2632 ObjectPvs objPvs; 2633 UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), objPvs); 2635 2634 } 2636 2635 … … 5725 5724 5726 5725 #if 1 5727 #if TEST_EVALUATION5728 void VspOspViewCellsManager::EvalViewCellPartition()5729 {5730 const int castSamples = (int)storedRays.size();5731 char s[64];5732 char statsPrefix[100];5733 5734 Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.statsPrefix", statsPrefix);5735 5736 Debug << "view cell stats prefix: " << statsPrefix << endl;5737 5738 // should directional sampling be used?5739 const bool dirSamples = (mEvaluationSamplingType == SamplingStrategy::DIRECTION_BASED_DISTRIBUTION);5740 5741 cout << "reseting pvs ... ";5742 const bool startFromZero = true;5743 5744 if (startFromZero)5745 {5746 // reset pvs and start over from zero5747 mViewCellsTree->ResetPvs();5748 }5749 else5750 {5751 // statistics before casting more samples5752 cout << "compute new statistics ... ";5753 sprintf(s, "-%09d-eval.log", castSamples);5754 string fName = string(statsPrefix) + string(s);5755 5756 mViewCellsTree->ExportStats(fName);5757 cout << "finished" << endl;5758 }5759 cout << "finished" << endl;5760 5761 cout << "Evaluating view cell partition ... " << endl;5762 5763 VssRayContainer evaluationSamples = storedRays;5764 const int samplingType = mEvaluationSamplingType;5765 5766 cout << "computing sample contributions of " << (int)evaluationSamples.size() << " samples ... ";5767 5768 ComputeSampleContributions(evaluationSamples, true, false);5769 5770 cout << "finished" << endl;5771 5772 cout << "compute new statistics ... ";5773 5774 // propagate pvs or pvs size information5775 ObjectPvs pvs;5776 UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs);5777 5778 5779 /////////////////////5780 // $§temporary matt: test render cost5781 5782 sprintf(s, "-%09d-eval.log", castSamples);5783 string fileName = string(statsPrefix) + string(s);5784 5785 ViewCellContainer leaves;5786 5787 mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);5788 float rc = 0;5789 5790 ViewCellContainer::const_iterator vit, vit_end = leaves.end();5791 5792 for (vit = leaves.begin(); vit != vit_end; ++ vit)5793 {5794 ViewCell *vc = *vit;5795 const float pvsCost = vc->GetPvs().EvalPvsCost();5796 const float vol = vc->GetVolume();5797 rc += pvsCost * vol;5798 }5799 5800 Debug << "\nrendercost hack: " << rc / mViewSpaceBox.GetVolume() << endl;5801 mViewCellsTree->ExportStats(fileName);5802 cout << "finished" << endl;5803 5804 disposeRays(evaluationSamples, NULL);5805 }5806 5807 #else5808 5726 5809 5727 void VspOspViewCellsManager::EvalViewCellPartition() … … 5812 5730 int numSamples; 5813 5731 int castSamples = 0; 5732 int oldSamples = 0; 5733 int samplesForStats; 5734 char statsPrefix[100]; 5735 char suffix[100]; 5814 5736 int splitsStepSize; 5815 5737 5816 char str[64]; 5817 5738 5818 5739 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesPerPass", samplesPerPass); 5740 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesForStats", samplesForStats); 5819 5741 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samples", numSamples); 5742 Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.statsPrefix", statsPrefix); 5820 5743 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.stepSize", splitsStepSize); 5821 5822 char statsPrefix[100]; 5823 Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.statsPrefix", statsPrefix); 5824 5744 5745 Debug << "step size: " << splitsStepSize << endl; 5825 5746 Debug << "view cell evaluation samples per pass: " << samplesPerPass << endl; 5826 5747 Debug << "view cell evaluation samples: " << numSamples << endl; 5827 5748 Debug << "view cell stats prefix: " << statsPrefix << endl; 5828 Debug << "step size: " << splitsStepSize << endl; 5749 5750 // should directional sampling be used? 5751 bool dirSamples = 5752 (mEvaluationSamplingType == SamplingStrategy::DIRECTION_BASED_DISTRIBUTION); 5829 5753 5830 5754 cout << "reseting pvs ... "; 5831 5755 5832 const bool startFromZero = true;5833 5834 5756 // reset pvs and start over from zero 5835 if (startFromZero) 5836 { 5837 mViewCellsTree->ResetPvs(); 5838 } 5839 else // start from current sampless 5840 { 5841 // statistics before casting more samples 5842 cout << "compute new statistics ... "; 5843 sprintf(str, "-%09d-eval.log", castSamples); 5844 string fName = string(statsPrefix) + string(str); 5845 5846 mViewCellsTree->ExportStats(fName); 5847 cout << "finished" << endl; 5848 } 5849 5757 mViewCellsTree->ResetPvs(); 5758 5850 5759 cout << "finished" << endl; 5851 5760 cout << "Evaluating view cell partition ... " << endl; … … 5853 5762 while (castSamples < numSamples) 5854 5763 { 5855 VssRayContainer evaluationSamples;5856 5857 5764 /////////////// 5858 5765 //-- we have to use uniform sampling strategy for construction rays 5859 5766 5860 //VssRayContainer evaluationSamples;5767 VssRayContainer evaluationSamples; 5861 5768 const int samplingType = mEvaluationSamplingType; 5862 5769 … … 5871 5778 5872 5779 Real timeDiff = TimeDiff(startTime, GetTime()); 5873 Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl; 5874 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 5875 5780 5781 cout << "finished in " << timeDiff * 1e-3f << " secs" << endl; 5876 5782 cout << "computing sample contributions of " << (int)evaluationSamples.size() << " samples ... "; 5783 5784 Debug << "finished in " << timeDiff * 1e-3f << " secs" << endl; 5877 5785 Debug << "computing sample contributions of " << (int)evaluationSamples.size() << " samples ... "; 5878 5786 … … 5885 5793 Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl; 5886 5794 5887 startTime = GetTime(); 5888 cout << "compute new statistics ... " << endl; 5889 5890 /////////// 5891 //-- output stats 5892 5893 sprintf(str, "-%09d-eval.log", castSamples); 5894 const string splitsFilename = string(statsPrefix) + string(str); 5895 5896 ofstream splitsStr(splitsFilename.c_str()); 5897 mHierarchyManager->EvaluateSubdivision2(splitsStr, splitsStepSize); 5898 5899 timeDiff = TimeDiff(startTime, GetTime()); 5900 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 5901 Debug << "statistics computed in " << timeDiff * 1e-3 << " secs" << endl; 5902 5795 if ((castSamples >= samplesForStats + oldSamples) || (castSamples >= numSamples)) 5796 { 5797 oldSamples += samplesForStats; 5798 5799 /////////// 5800 //-- output stats 5801 5802 sprintf(suffix, "-%09d-eval.log", castSamples); 5803 const string filename = string(statsPrefix) + string(suffix); 5804 5805 startTime = GetTime(); 5806 cout << "compute new statistics ... " << endl; 5807 5808 ofstream ofstr(filename.c_str()); 5809 mHierarchyManager->EvaluateSubdivision2(ofstr, splitsStepSize); 5810 5811 timeDiff = TimeDiff(startTime, GetTime()); 5812 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 5813 Debug << "statistics computed in " << timeDiff * 1e-3 << " secs" << endl; 5814 5815 // only for debugging purpose 5816 if (1) 5817 { 5818 ViewCellContainer viewCells; 5819 mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), viewCells); 5820 5821 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 5822 int pvsSize = 0; 5823 5824 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 5825 { 5826 pvsSize += (*vit)->GetPvs().GetSize(); 5827 } 5828 5829 cout << "debug entries: " << pvsSize << ", memcost: " << (float)pvsSize * ObjectPvs::GetEntrySize() << endl; 5830 } 5831 } 5832 5903 5833 disposeRays(evaluationSamples, NULL); 5904 5834 } 5835 5905 5836 } 5906 5837 #endif 5907 #endif 5908 } 5838 }
Note: See TracChangeset
for help on using the changeset viewer.