Changeset 1713 for GTP/trunk/Lib/Vis
- Timestamp:
- 11/06/06 18:48:22 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1709 r1713 822 822 #endif 823 823 824 #if 1 824 825 825 826 float BvHierarchy::EvalSah(const BvhTraversalData &tData, … … 930 931 const bool noValidSplit = ((objectsLeft <= Limits::Small) || (objectsRight <= Limits::Small)); 931 932 933 const float sum = noValidSplit ? 1e25 : objectsLeft * al + objectsRight * ar; 934 935 /*cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=(" 936 << lbox.SurfaceArea() << "," << rbox.SurfaceArea() << ")" << endl; 937 cout << "minborder: " << minBorder << " maxborder: " << maxBorder << endl; 938 cout << "cost= " << sum << endl; 939 */ 940 941 if (sum < minSum) 942 { //cout <<" sum: " << sum; 943 minSum = sum; 944 areaLeft = al; 945 areaRight = ar; 946 947 // objects belong to left side now 948 for (; currentPos != (cit + 1); ++ currentPos); 949 } 950 } 951 952 //////////////////////////////////////////// 953 //-- assign object to front and back volume 954 955 // belongs to back bv 956 for (cit = mSubdivisionCandidates->begin(); cit != currentPos; ++ cit) 957 objectsBack.push_back((*cit).mObject); 958 959 // belongs to front bv 960 for (cit = currentPos; cit != cit_end; ++ cit) 961 objectsFront.push_back((*cit).mObject); 962 963 float newCost = minSum / boxArea; 964 float ratio = newCost / totalRenderCost; 965 966 #ifdef _DEBUG 967 cout << "\n\nobjects=(" << (int)objectsBack.size() << "," << (int)objectsFront.size() << " of " 968 << (int)tData.mNode->mObjects.size() << ")\t area=(" 969 << areaLeft << ", " << areaRight << ", " << boxArea << ")" << endl 970 << "cost= " << newCost << " oldCost=" << totalRenderCost / boxArea << endl; 971 #endif 972 973 return ratio; 974 } 975 #else 976 977 float BvHierarchy::EvalSah(const BvhTraversalData &tData, 978 const int axis, 979 ObjectContainer &objectsFront, 980 ObjectContainer &objectsBack) 981 { 982 // go through the lists, count the number of objects left and right 983 // and evaluate the following cost funcion: 984 // C = ct_div_ci + (ol + or) / queries 985 PrepareLocalSubdivisionCandidates(tData, axis); 986 987 const float totalRenderCost = EvalAbsCost(tData.mNode->mObjects); 988 float objectsLeft = 0, objectsRight = totalRenderCost; 989 990 const AxisAlignedBox3 nodeBbox = tData.mNode->GetBoundingBox(); 991 992 const float minBox = nodeBbox.Min(axis); 993 const float maxBox = nodeBbox.Max(axis); 994 const float boxArea = nodeBbox.SurfaceArea(); 995 996 float minSum = 1e20f; 997 998 Vector3 minBorder = nodeBbox.Max(); 999 Vector3 maxBorder = nodeBbox.Min(); 1000 1001 float areaLeft = 0, areaRight = 0; 1002 1003 SortableEntryContainer::const_iterator currentPos = 1004 mSubdivisionCandidates->begin(); 1005 1006 vector<Vector3> bordersRight; 1007 1008 if (mUseBboxAreaForSah) 1009 { 1010 // we keep track of both borders of the bounding boxes => 1011 // store the events in descending order 1012 bordersRight.resize(mSubdivisionCandidates->size()); 1013 1014 SortableEntryContainer::reverse_iterator rcit = 1015 mSubdivisionCandidates->rbegin(), rcit_end = mSubdivisionCandidates->rend(); 1016 1017 vector<Vector3>::reverse_iterator rbit = bordersRight.rbegin(); 1018 1019 for (; rcit != rcit_end; ++ rcit, ++ rbit) 1020 { 1021 Intersectable *obj = (*rcit).mObject; 1022 const AxisAlignedBox3 obox = obj->GetBox(); 1023 1024 for (int i = 0; i < 3; ++ i) 1025 { 1026 if (obox.Min(i) < minBorder[i]) 1027 { 1028 minBorder[i] = obox.Min(i); 1029 } 1030 } 1031 1032 (*rbit) = minBorder; 1033 } 1034 } 1035 1036 // temporary surface areas 1037 float al = 0; 1038 float ar = boxArea; 1039 1040 vector<Vector3>::const_iterator bit = bordersRight.begin(); 1041 SortableEntryContainer::const_iterator cit, cit_end = mSubdivisionCandidates->end(); 1042 1043 for (cit = mSubdivisionCandidates->begin(); cit != cit_end; ++ cit, ++ bit) 1044 { 1045 Intersectable *obj = (*cit).mObject; 1046 1047 const float renderCost = mViewCellsManager->EvalRenderCost(obj); 1048 1049 objectsLeft += renderCost; 1050 objectsRight -= renderCost; 1051 1052 const AxisAlignedBox3 obox = obj->GetBox(); 1053 1054 if (mUseBboxAreaForSah) 1055 { 1056 AxisAlignedBox3 lbox = nodeBbox; 1057 AxisAlignedBox3 rbox = nodeBbox; 1058 1059 // the borders of the bounding boxes have changed 1060 for (int i = 0; i < 3; ++ i) 1061 { 1062 if (obox.Max(i) > maxBorder[i]) 1063 { 1064 maxBorder[i] = obox.Max(i); 1065 } 1066 } 1067 1068 minBorder = (*bit); 1069 1070 lbox.SetMax(maxBorder); 1071 rbox.SetMin(minBorder); 1072 1073 al = lbox.SurfaceArea(); 1074 ar = rbox.SurfaceArea(); 1075 } 1076 else 1077 { 1078 // just add up areas of the objects itself 1079 // (as we are not sampling volumetric visibility, 1080 // this should provide better heuristics 1081 const float area = obj->GetArea();//obox.SurfaceArea(); 1082 1083 al += area; 1084 ar -= area; 1085 } 1086 1087 const bool noValidSplit = ((objectsLeft <= Limits::Small) || (objectsRight <= Limits::Small)); 932 1088 const float sum = noValidSplit ? 1e25 : objectsLeft * al + objectsRight * ar; 933 1089 … … 971 1127 #endif 972 1128 973 return ratio; 974 } 975 1129 return ratio; 1130 } 1131 1132 #endif 976 1133 977 1134 static bool PrepareOutput(const int axis, … … 1480 1637 // probability that view point lies in a view cell which sees this node 1481 1638 const float p = EvalViewCellsVolume(objects) / viewSpaceVol; 1482 float objRenderCost = EvalAbsCost(objects);1639 const float objRenderCost = EvalAbsCost(objects); 1483 1640 1484 1641 return objRenderCost * p; … … 2161 2318 // sets the pointers to the currently active view cells 2162 2319 CollectLeaves(node, leaves); 2163 2164 vector<BvhLeaf *>::const_iterator bit, bit_end = leaves.end(); 2165 2166 for (bit = leaves.begin(); bit != bit_end; ++ bit) 2167 { 2168 (*bit)->SetActiveNode(node); 2320 vector<BvhLeaf *>::const_iterator lit, lit_end = leaves.end(); 2321 2322 for (lit = leaves.begin(); lit != lit_end; ++ lit) 2323 { 2324 (*lit)->SetActiveNode(node); 2169 2325 } 2170 2326 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1695 r1713 1427 1427 "0"); 1428 1428 1429 RegisterOption("ViewCells.Evaluation.stepSize", 1430 optInt, 1431 "view_cells_evaluation_step_size=", 1432 "100"); 1433 1429 1434 RegisterOption("ViewCells.maxPvsRatio", 1430 1435 optFloat, -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1710 r1713 1747 1747 HierarchyNodeWrapper *nodeWrapper = tqueue.top(); 1748 1748 tqueue.pop(); 1749 1749 //cout << "priority: " << nodeWrapper->GetMergeCost() << endl; 1750 1750 // save the view cells if it is a leaf or if enough view cells have already been traversed 1751 1751 // because of the priority queue, this will be the optimal set of v … … 1755 1755 ) 1756 1756 { 1757 if (nodeWrapper->Type() == HierarchyNodeWrapper::V SP_NODE)1757 if (nodeWrapper->Type() == HierarchyNodeWrapper::VIEW_CELL) 1758 1758 { 1759 //cout << "1"; 1759 1760 ViewCellWrapper *viewCellWrapper = dynamic_cast<ViewCellWrapper *>(nodeWrapper); 1760 1761 viewCells.push_back(viewCellWrapper->mViewCell); … … 1762 1763 else 1763 1764 { 1765 //cout << "0"; 1764 1766 BvhNodeWrapper *bvhNodeWrapper = dynamic_cast<BvhNodeWrapper *>(nodeWrapper); 1765 1767 bvhNodes.push_back(bvhNodeWrapper->mNode); … … 1776 1778 1777 1779 1778 boolHierarchyManager::ExtractStatistics(const int maxSplits,1779 1780 1781 1782 1780 int HierarchyManager::ExtractStatistics(const int maxSplits, 1781 const float maxMemoryCost, 1782 float &renderCost, 1783 float &memory, 1784 int &pvsEntries) 1783 1785 { 1784 1786 ViewCellContainer viewCells; … … 1787 1789 // collect best set of view cells for this #splits 1788 1790 CollectBestSet(maxSplits, maxMemoryCost, viewCells, bvhNodes); 1789 1791 //cout << "here5 " << bvhNodes.size() << endl; 1790 1792 vector<BvhNode *>::const_iterator bit, bit_end = bvhNodes.end(); 1791 1793 1794 // set new nodes to be active 1792 1795 for (bit = bvhNodes.begin(); bit != bit_end; ++ bit) 1793 1796 { … … 1797 1800 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 1798 1801 1799 int numEntries = 0; 1800 float pvsCost = 0.0f; 1801 1802 pvsEntries = 0; 1803 renderCost = 0.0f; 1804 1805 //BvhNode::NewMail(); 1806 //int dummy = 0; 1802 1807 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 1803 1808 { 1809 float rc = 0; 1804 1810 ViewCell *vc = *vit; 1805 1811 ObjectPvs pvs; 1806 1812 mVspTree->mViewCellsTree->GetPvs(vc, pvs); 1807 1813 //dummy+=pvs.GetSize(); 1808 1814 BvhNode::NewMail(); 1809 1815 … … 1814 1820 { 1815 1821 BvhIntersectable *intersect = dynamic_cast<BvhIntersectable *>((*oit).first); 1822 1816 1823 BvhLeaf *leaf = intersect->GetItem(); 1817 1824 BvhNode *activeNode = leaf->GetActiveNode(); … … 1821 1828 activeNode->Mail(); 1822 1829 1823 ++ numEntries; 1824 pvsCost += mBvHierarchy->EvalAbsCost(leaf->mObjects); 1830 ObjectContainer objects; 1831 activeNode->CollectObjects(objects); 1832 1833 ++ pvsEntries; 1834 rc += mBvHierarchy->EvalAbsCost(objects); 1835 //cout << " pvs: " << mBvHierarchy->EvalAbsCost(leaf->mObjects); 1825 1836 } 1826 1837 } 1827 } 1828 1829 return ((int)(viewCells.size() + bvhNodes.size()) < mHierarchyStats.Leaves()); 1838 1839 rc *= vc->GetVolume(); 1840 renderCost += rc; 1841 } 1842 1843 renderCost /= mVspTree->mViewCellsManager->GetViewSpaceBox().GetVolume(); 1844 1845 memory = pvsEntries * ObjectPvs::GetEntrySize(); 1846 //cout << "viewCells: " << (int)viewCells.size() << " nodes: " << (int)bvhNodes.size() << " rc: " << renderCost << " entries: " << pvsEntries << endl; 1847 1848 return viewCells.size() + bvhNodes.size(); 1830 1849 } 1831 1850 … … 1984 2003 1985 2004 void HierarchyManager::EvaluateSubdivision2(ofstream &splitsStats, 1986 ofstream &memStats, 1987 const int splitsStepSize, 1988 const float memStepSize) 2005 const int splitsStepSize) 1989 2006 { 1990 2007 int splits = 0; 1991 float mem = 15;1992 2008 1993 2009 float renderCost; … … 1997 2013 while (1) 1998 2014 { 1999 if (!ExtractStatistics(splits, 99999.0, renderCost, memory, pvsEntries)) 2015 const int numSplits = ExtractStatistics(splits, 99999.0, renderCost, memory, pvsEntries); 2016 2017 UpdateStats(splitsStats, numSplits, renderCost, pvsEntries, memory, 0); 2018 splits += splitsStepSize; 2019 2020 if (numSplits == mHierarchyStats.Leaves()) 2000 2021 break; 2001 2002 UpdateStats(splitsStats, splits, renderCost, pvsEntries, memory, 0); 2003 2004 splits += splitsStepSize; 2005 } 2006 2007 while (1) 2008 { 2009 if (!ExtractStatistics(99999999, mem, renderCost, memory, pvsEntries)) 2010 break; 2011 2012 UpdateStats(splitsStats, splits, renderCost, pvsEntries, memory, 0); 2013 2014 mem += memStepSize; 2015 } 2016 2017 } 2018 2019 } 2022 } 2023 } 2024 2025 } -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1710 r1713 241 241 242 242 void EvaluateSubdivision2(ofstream &splitsStats, 243 ofstream &memStats, 244 const int splitsStepSize, 245 const float memStepSize); 243 const int splitsStepSize); 246 244 247 245 … … 461 459 vector<BvhNode *> &bvhNodes); 462 460 463 boolExtractStatistics(const int maxSplits,464 465 466 467 461 int ExtractStatistics(const int maxSplits, 462 const float maxMemoryCost, 463 float &renderCost, 464 float &memory, 465 int &pvsEntries); 468 466 469 467 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1701 r1713 313 313 ObjectContainer::const_iterator oit, oit_end = objects.end(); 314 314 315 //AxisAlignedBox3 bbox = mSceneGraph->GetBox(); bbox.Enlarge(30.0);315 AxisAlignedBox3 bbox = mSceneGraph->GetBox(); bbox.Enlarge(30.0); 316 316 for (oit = objects.begin(); oit != oit_end; ++ oit) 317 317 { … … 321 321 { 322 322 Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem(); 323 324 323 //if (bbox.IsInside(tri.mVertices[0]) && bbox.IsInside(tri.mVertices[1]) && bbox.IsInside(tri.mVertices[2])) 325 324 //{ 326 samplesOut << "v " << tri.mVertices[0].x << " " << tri.mVertices[0].y << " " << tri.mVertices[0].z << endl;327 samplesOut << "v " << tri.mVertices[1].x << " " << tri.mVertices[1].y << " " << tri.mVertices[1].z << endl;328 samplesOut << "v " << tri.mVertices[2].x << " " << tri.mVertices[2].y << " " << tri.mVertices[2].z << endl;325 samplesOut << "v " << tri.mVertices[0].x << " " << tri.mVertices[0].y << " " << tri.mVertices[0].z << endl; 326 samplesOut << "v " << tri.mVertices[1].x << " " << tri.mVertices[1].y << " " << tri.mVertices[1].z << endl; 327 samplesOut << "v " << tri.mVertices[2].x << " " << tri.mVertices[2].y << " " << tri.mVertices[2].z << endl; 329 328 //} 330 329 } … … 337 336 // write faces 338 337 int i = 1; 339 for (oit = objects.begin(); oit != oit_end; ++ oit , i += 3)338 for (oit = objects.begin(); oit != oit_end; ++ oit) 340 339 { 341 340 Intersectable *obj = *oit; 342 341 if (obj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 343 342 { 344 Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem(); 345 samplesOut << "f " << i << " " << i + 1 << " " << i + 2 << endl; 343 //Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem(); 344 //if (bbox.IsInside(tri.mVertices[0]) && bbox.IsInside(tri.mVertices[1]) && bbox.IsInside(tri.mVertices[2])) 345 //{ 346 Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem(); 347 samplesOut << "f " << i << " " << i + 1 << " " << i + 2 << endl; 348 i += 3; 349 //} 346 350 } 347 351 else … … 484 488 } 485 489 490 // temporare hack 486 491 //if (!strstr(filename.c_str(), "plane")) mSceneGraph->GetRoot()->UpdateBox(); 487 492 … … 507 512 mObjects.reserve(intersectables); 508 513 mSceneGraph->CollectObjects(&mObjects); 514 515 // temp hack 516 //ExportObj("cropped_vienna.obj", mObjects); 517 509 518 mSceneGraph->GetRoot()->UpdateBox(); 510 519 511 520 cout << "finished loading" << endl; 521 522 512 523 if (0) 513 524 { … … 1141 1152 pertub.y = RandomValue(0.0f, pertubDir); 1142 1153 pertub.z = RandomValue(0.0f, pertubDir); 1154 1143 1155 const Vector3 newDir = mainRay.mDirection + pertub; 1144 1156 //const Vector3 newDir = mainRay.mDirection; … … 1147 1159 pertub.y = RandomValue(0.0f, pertubOrigin); 1148 1160 pertub.z = RandomValue(0.0f, pertubOrigin); 1161 1149 1162 const Vector3 newOrigin = mainRay.mOrigin + pertub; 1150 1163 //const Vector3 newOrigin = mainRay.mOrigin; … … 1159 1172 void Preprocessor::SetupRay(Ray &ray, 1160 1173 const Vector3 &point, 1161 const Vector3 &direction 1162 ) const 1174 const Vector3 &direction) const 1163 1175 { 1164 1176 ray.Clear(); 1165 1177 // do not store anything else then intersections at the ray 1166 ray.Init(point, direction, Ray::LOCAL_RAY); 1167 1168 } 1169 1170 1171 } 1178 ray.Init(point, direction, Ray::LOCAL_RAY); 1179 } 1180 1181 1182 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1709 r1713 1707 1707 } 1708 1708 1709 1709 //////////////// 1710 1710 //-- pvs is not stored with the interiors => reconstruct 1711 1711 Intersectable::NewMail(); 1712 1712 1713 int pvsSize = 0;1714 1713 ViewCell *root = vc; 1715 1714 … … 1736 1735 { 1737 1736 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1738 1739 1737 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1740 1738 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1710 r1713 3384 3384 3385 3385 // evaluate merge cost for priority traversal 3386 const float mergeCost = 1.0f /(float)root->mTimeStamp;3386 const float mergeCost = -(float)root->mTimeStamp; 3387 3387 vcRoot->SetMergeCost(mergeCost); 3388 3388 … … 3428 3428 3429 3429 // evaluate merge cost for priority traversal 3430 float mergeCost = 1.0f /(float)root->mTimeStamp;3430 const float mergeCost = -(float)root->mTimeStamp; 3431 3431 viewCellInterior->SetMergeCost(mergeCost); 3432 3432 … … 5048 5048 5049 5049 // evaluate merge cost for priority traversal 5050 float mergeCost = 1.0f /(float)root->mTimeStamp;5050 const float mergeCost = -(float)root->mTimeStamp; 5051 5051 viewCellInterior->SetMergeCost(mergeCost); 5052 5052 … … 5747 5747 int numSamples; 5748 5748 int castSamples = 0; 5749 int splitsStepSize; 5750 5749 5751 char str[64]; 5750 5752 5751 5753 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesPerPass", samplesPerPass); 5752 5754 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samples", numSamples); 5755 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.stepSize", splitsStepSize); 5753 5756 5754 5757 char statsPrefix[100]; … … 5782 5785 cout << "Evaluating view cell partition ... " << endl; 5783 5786 5784 VssRayContainer evaluationSamples;5785 5786 5787 while (castSamples < numSamples) 5787 5788 { 5789 VssRayContainer evaluationSamples; 5790 5788 5791 /////////////// 5789 5792 //-- we have to use uniform sampling strategy for construction rays … … 5822 5825 //-- output stats 5823 5826 5824 const int splitsStepSize = 500; 5825 const float memStepSize = 1.0f; 5826 5827 sprintf(str, "-splits-%09d-eval.log", castSamples); 5827 sprintf(str, "-%09d-eval.log", castSamples); 5828 5828 const string splitsFilename = string(statsPrefix) + string(str); 5829 5830 sprintf(str, "-mem-%09d-eval.log", castSamples);5831 const string memFilename = string(statsPrefix) + string(str);5832 5829 5833 5830 ofstream splitsStr(splitsFilename.c_str()); 5834 ofstream memStr(memFilename.c_str()); 5835 5836 mHierarchyManager->EvaluateSubdivision2(splitsStr, memStr, splitsStepSize, memStepSize); 5831 mHierarchyManager->EvaluateSubdivision2(splitsStr, splitsStepSize); 5837 5832 5838 5833 timeDiff = TimeDiff(startTime, GetTime()); 5839 5834 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 5840 Debug << "statisti s compted in " << timeDiff * 1e-3 << " secs" << endl;5835 Debug << "statistics computed in " << timeDiff * 1e-3 << " secs" << endl; 5841 5836 5842 5837 disposeRays(evaluationSamples, NULL); -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r1703 r1713 244 244 } 245 245 } 246 // Exporter *exporter= Exporter::GetExporter("test1.wrl"); 247 // AxisAlignedBox3 bbox = preprocessor->mKdTree->GetBox(); 248 // bbox.Scale(Vector3(1, 1, 0.5)); 249 //exporter->ExportGeometry(preprocessor->mObjects);cout<<"here2"<<endl; 250 246 if (0){ 247 Exporter *exporter= Exporter::GetExporter("test1.wrl"); 248 AxisAlignedBox3 bbox = preprocessor->mKdTree->GetBox(); 249 bbox.Scale(Vector3(0.5, 1, 0.5)); 250 exporter->SetWireframe(); 251 exporter->ExportBox(preprocessor->mKdTree->GetBox()); 252 exporter->ExportBox(bbox); 253 exporter->SetFilled(); 254 exporter->ExportGeometry(preprocessor->mObjects, true, &bbox); 255 delete exporter; 256 } 257 258 251 259 // parse view cells related options 252 260 if (!preprocessor->PrepareViewCells())
Note: See TracChangeset
for help on using the changeset viewer.