Changeset 482
- Timestamp:
- 12/27/05 12:52:25 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r481 r482 146 146 loadFromFile false 147 147 #type kdTree 148 #type vspKdTree148 type vspKdTree 149 149 #type bspTree 150 type vspBspTree150 #type vspBspTree 151 151 152 152 #type sceneDependent … … 166 166 # how much samples are be used for visualization 167 167 samples 90000 168 #colorCode PVS 169 #colorCode MergedLeaves 170 #colorCode MergedTreeDiff 171 colorCode Random 168 172 } 169 173 … … 192 196 Termination { 193 197 maxDepth 40 194 minPvs 5 195 minRays 500198 minPvs 50 199 minRays 300 196 200 minSize 0.1 197 maxCostRatio 0.9198 missTolerance 4199 maxRayContribution 0. 2201 maxCostRatio 1.8 202 missTolerance 2 203 maxRayContribution 0.5 200 204 } 201 205 … … 209 213 # maximal cost for merging a view cell 210 214 PostProcess { 211 maxCostRatio 1.4212 minViewCells 100215 maxCostRatio 0.005 216 minViewCells 300 213 217 maxPvsSize 50000 214 218 } … … 216 220 217 221 Visualization { 218 exportRays true222 exportRays false 219 223 exportGeometry false 220 224 } … … 223 227 VspBspTree { 224 228 Construction { 225 samples 500000229 samples 300000 226 230 epsilon 0.005 227 231 } … … 258 262 minArea 0.0001 259 263 maxRayContribution 0.005 260 maxCostRatio 0. 8264 maxCostRatio 0.9 261 265 missTolerance 2 262 266 #maxAccRayLength 100 263 267 264 maxViewCells 5000268 maxViewCells 1000 265 269 266 270 # used for pvs criterium 267 271 ct_div_ci 0.0 268 272 } 269 273 270 274 Visualization { … … 277 281 PostProcess { 278 282 maxCostRatio 0.005 279 minViewCells 700283 minViewCells 100 280 284 maxPvsSize 500 281 285 } -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp
r469 r482 1771 1771 return true; 1772 1772 } 1773 1774 1775 bool AxisAlignedBox3::GetIntersectionFace(Rectangle3 &face, 1776 const AxisAlignedBox3 &neighbour) const 1777 1778 { 1779 if (EpsilonEqual(mMin[0], neighbour.Max(0))) 1780 { 1781 float maxy = min(mMax.y, neighbour.mMax.y); 1782 float maxz = min(mMax.z, neighbour.mMax.z); 1783 float miny = max(mMin.y, neighbour.mMin.y); 1784 float minz = max(mMin.z, neighbour.mMin.z); 1785 1786 face.mVertices[3].SetValue(mMin.x, miny, minz); 1787 face.mVertices[2].SetValue(mMin.x, maxy, minz); 1788 face.mVertices[1].SetValue(mMin.x, maxy, maxz); 1789 face.mVertices[0].SetValue(mMin.x, miny, maxz); 1790 1791 return true; 1792 } 1793 if (EpsilonEqual(mMax[0], neighbour.Min(0))) 1794 { 1795 float maxy = min(mMax.y, neighbour.mMax.y); 1796 float maxz = min(mMax.z, neighbour.mMax.z); 1797 float miny = max(mMin.y, neighbour.mMin.y); 1798 float minz = max(mMin.z, neighbour.mMin.z); 1799 1800 face.mVertices[0].SetValue(mMax.x, miny, minz); 1801 face.mVertices[1].SetValue(mMax.x, maxy, minz); 1802 face.mVertices[2].SetValue(mMax.x, maxy, maxz); 1803 face.mVertices[3].SetValue(mMax.x, miny, maxz); 1804 1805 return true; 1806 } 1807 if (EpsilonEqual(mMin[1], neighbour.Max(1))) 1808 { 1809 float maxx = min(mMax.x, neighbour.mMax.x); 1810 float maxz = min(mMax.z, neighbour.mMax.z); 1811 float minx = max(mMin.x, neighbour.mMin.x); 1812 float minz = max(mMin.z, neighbour.mMin.z); 1813 1814 face.mVertices[3].SetValue(minx, mMin.y, minz); 1815 face.mVertices[2].SetValue(minx, mMin.y, maxz); 1816 face.mVertices[1].SetValue(maxx, mMin.y, maxz); 1817 face.mVertices[0].SetValue(maxx, mMin.y, minz); 1818 1819 return true; 1820 } 1821 if (EpsilonEqual(mMax[1], neighbour.Min(1))) 1822 { 1823 float maxx = min(mMax.x, neighbour.mMax.x); 1824 float maxz = min(mMax.z, neighbour.mMax.z); 1825 float minx = max(mMin.x, neighbour.mMin.x); 1826 float minz = max(mMin.z, neighbour.mMin.z); 1827 1828 face.mVertices[0].SetValue(minx, mMax.y, minz); 1829 face.mVertices[1].SetValue(minx, mMax.y, maxz); 1830 face.mVertices[2].SetValue(maxx, mMax.y, maxz); 1831 face.mVertices[3].SetValue(maxx, mMax.y, minz); 1832 1833 return true; 1834 } 1835 if (EpsilonEqual(mMin[2], neighbour.Max(2))) 1836 { 1837 float maxx = min(mMax.x, neighbour.mMax.x); 1838 float maxy = min(mMax.y, neighbour.mMax.y); 1839 float minx = max(mMin.x, neighbour.mMin.x); 1840 float miny = max(mMin.y, neighbour.mMin.y); 1841 1842 face.mVertices[3].SetValue(minx, miny, mMin.z); 1843 face.mVertices[2].SetValue(maxx, miny, mMin.z); 1844 face.mVertices[1].SetValue(maxx, maxy, mMin.z); 1845 face.mVertices[0].SetValue(minx, maxy, mMin.z); 1846 1847 return true; 1848 } 1849 if (EpsilonEqual(mMax[2], neighbour.Min(2))) 1850 { 1851 float maxx = min(mMax.x, neighbour.mMax.x); 1852 float maxy = min(mMax.y, neighbour.mMax.y); 1853 float minx = max(mMin.x, neighbour.mMin.x); 1854 float miny = max(mMin.y, neighbour.mMin.y); 1855 1856 face.mVertices[0].SetValue(minx, miny, mMax.z); 1857 face.mVertices[1].SetValue(maxx, miny, mMax.z); 1858 face.mVertices[2].SetValue(maxx, maxy, mMax.z); 1859 face.mVertices[3].SetValue(minx, maxy, mMax.z); 1860 1861 return true; 1862 } 1863 1864 return false; 1865 } 1866 -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h
r459 r482 321 321 float &maxT) const; 322 322 323 /** If the boxes are intersecting on a common face, this function 324 returns the face intersection, false otherwise. 325 326 @param neighbour the neighbouring box intersecting with this box. 327 */ 328 bool GetIntersectionFace(Rectangle3 &face, 329 const AxisAlignedBox3 &neighbour) const; 330 323 331 #define __EXTENT_HACK 324 332 // get the extent of face -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r481 r482 1231 1231 "-view_cells_height=", 1232 1232 "5.0"); 1233 1233 RegisterOption("ViewCells.Visualization.colorCode", 1234 optString, 1235 "-view_cells_visualization.color_code", 1236 "PVS"); 1237 1234 1238 /************************************************************************************/ 1235 1239 /* Render simulation related options */ … … 1621 1625 /************************************************************************************/ 1622 1626 1623 1624 1627 RegisterOption("VspBspTree.Termination.minPolygons", 1625 1626 1627 1628 optInt, 1629 "-vsp_bsp_term_min_polygons=", 1630 "5"); 1628 1631 1629 1632 RegisterOption("VspBspTree.Termination.minPvs", 1630 1631 1632 1633 optInt, 1634 "-vsp_bsp_term_min_pvs=", 1635 "20"); 1633 1636 1634 1637 RegisterOption("VspBspTree.Termination.minArea", 1635 1636 1637 1638 optFloat, 1639 "-vsp_bsp_term_min_area=", 1640 "0.001"); 1638 1641 1639 1642 RegisterOption("VspBspTree.Termination.maxRayContribution", 1640 1641 1642 1643 optFloat, 1644 "-vsp_bsp_term_ray_contribution=", 1645 "0.005"); 1643 1646 1644 1647 RegisterOption("VspBspTree.Termination.minAccRayLenght", 1645 1646 1647 1648 optFloat, 1649 "-vsp_bsp_term_min_acc_ray_length=", 1650 "50"); 1648 1651 1649 1652 RegisterOption("VspBspTree.Termination.minRays", 1650 1651 1652 1653 optInt, 1654 "-vsp_bsp_term_min_rays=", 1655 "-1"); 1653 1656 1654 1657 RegisterOption("VspBspTree.Termination.ct_div_ci", 1655 1656 1657 1658 optFloat, 1659 "-vsp_bsp_term_ct_div_ci=", 1660 "0.0"); 1658 1661 1659 1662 RegisterOption("VspBspTree.Termination.maxDepth", 1660 1661 1662 1663 optInt, 1664 "-vsp_bsp_term_max_depth=", 1665 "100"); 1663 1666 1664 1667 RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio", 1665 1666 1667 1668 optFloat, 1669 "-vsp_bsp_term_axis_aligned_max_cost_ratio=", 1670 "1.5"); 1668 1671 1669 1672 RegisterOption("VspBspTree.Termination.maxViewCells", 1670 1671 1672 1673 optInt, 1674 "-vsp_bsp_term_axis_aligned_max_view_cells=", 1675 "1000"); 1673 1676 1674 1677 RegisterOption("VspBspTree.Termination.maxCostRatio", … … 1716 1719 "-vsp_bsp_visualization.export_splits", 1717 1720 "false"); 1721 1718 1722 RegisterOption("VspBspTree.Visualization.exportRays", 1719 1723 optBool, … … 1726 1730 "false"); 1727 1731 1732 1728 1733 RegisterOption("VspBspTree.Factor.leastRaySplits", optFloat, "-vsp_bsp_factor_least_ray_splits=", "1.0"); 1729 1734 RegisterOption("VspBspTree.Factor.balancedRays", optFloat, "-vsp_bsp_factor_balanced_rays=", "1.0"); -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r466 r482 100 100 ExportBspSplits(const VspBspTree &tree, const bool exportDepth = false) = 0; 101 101 102 virtual void103 ExportBspViewCellPartition(const VspBspTree &tree, const int maxPvs = 0) = 0;104 105 102 virtual void 106 103 ExportPolygons(const PolygonContainer &polys) = 0; 107 108 virtual void109 ExportBspViewCellPartition(const BspTree &tree, const int maxPvs = 0) = 0;110 104 111 105 virtual void … … 118 112 ExportRssTree2(const RssTree &tree, 119 113 const Vector3 direction) = 0; 120 121 virtual bool122 ExportVspKdTreeViewCells(const VspKdTree &tree, const int maxPvs = 0) = 0;123 114 124 115 void SetExportRayDensity(const bool d) { mExportRayDensity = d; } -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
r480 r482 77 77 // probability of view cell 78 78 const float pInVc = mViewCellsManager->GetProbability(vc); 79 // compute render time of PVS times probability that view point is in view cell 80 const float vcCost = pInVc * mViewCellsManager->GetRendercost(vc, mObjRenderCost); 79 // compute render time of PVS times probability 80 // that view point is in view cell 81 const float vcCost = pInVc * 82 mViewCellsManager->GetRendercost(vc, mObjRenderCost); 81 83 82 84 // crossing the border of a view cell is depending on the move speed 83 85 // and the probability that a view cell border is crossed 84 86 loadPvsOverhead += GetCrossVcProbability() * mVcOverhead; 85 //Debug << "vccost: " << vcCost << " p in vc " << pInVc << " cross vc " << GetCrossVcProbability() << endl; 87 88 //Debug << "vccost: " << vcCost << " p in vc " << pInVc 89 //<< " cross vc " << GetCrossVcProbability() << endl; 90 86 91 //-- update statistics 87 92 renderTime += vcCost; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r480 r482 57 57 } 58 58 59 59 60 BspInterior *BspNode::GetParent() 60 61 { … … 62 63 } 63 64 65 64 66 void BspNode::SetParent(BspInterior *parent) 65 67 { 66 68 mParent = parent; 69 } 70 71 72 bool BspNode::IsSibling(BspNode *n) const 73 { 74 return ((this != n) && mParent && 75 (mParent->GetFront() == n) || (mParent->GetBack() == n)); 76 } 77 78 int BspNode::GetDepth() const 79 { 80 int depth = 0; 81 BspNode *p = mParent; 82 83 while (p) 84 { 85 p = p->mParent; 86 ++ depth; 87 } 88 89 return depth; 67 90 } 68 91 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r480 r482 198 198 void SetParent(BspInterior *parent); 199 199 200 200 /** Returns true if this node is a sibling of node n. 201 */ 202 bool IsSibling(BspNode *n) const; 203 204 /** returns depth of the node. 205 */ 206 int GetDepth() const; 201 207 static int sMailId; 202 208 int mMailbox; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r480 r482 21 21 mTotalArea(0.0f) 22 22 { 23 // post processing stuff 24 environment->GetIntValue("ViewCells.PostProcess.minPvsDif", mMinPvsDif); 25 environment->GetIntValue("ViewCells.PostProcess.minPvs", mMinPvs); 26 environment->GetIntValue("ViewCells.PostProcess.maxPvs", mMaxPvs); 23 ParseEnvironment(); 27 24 } 28 25 … … 33 30 mVisualizationSamples(0) 34 31 { 32 ParseEnvironment(); 33 } 34 35 void ViewCellsManager::ParseEnvironment() 36 { 35 37 // post processing stuff 36 38 environment->GetIntValue("ViewCells.PostProcess.minPvsDif", mMinPvsDif); 37 39 environment->GetIntValue("ViewCells.PostProcess.minPvs", mMinPvs); 38 40 environment->GetIntValue("ViewCells.PostProcess.maxPvs", mMaxPvs); 41 42 char buf[50]; 43 44 environment->GetStringValue("ViewCells.Visualization.colorCode", buf); 45 46 if (strcmp(buf, "PVS") == 0) 47 mColorCode = 1; 48 else if (strcmp(buf, "MergedLeaves") == 0) 49 mColorCode = 2; 50 else if (strcmp(buf, "MergedTreeDiff") == 0) 51 mColorCode = 3; 52 else 53 mColorCode = 0; 54 55 Debug << "colorCode: " << mColorCode << endl; 39 56 } 40 57 … … 336 353 } 337 354 355 338 356 void ViewCellsManager::PrintStatistics(ostream &s) const 339 357 { 340 358 s << mViewCellsStats << endl; 359 } 360 361 362 void ViewCellsManager::ExportViewCells(Exporter *exporter) const 363 { 364 ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 365 366 for (it = mViewCells.begin(); it != it_end; ++ it) 367 { 368 ExportColor(exporter, *it); 369 ExportGeometry(exporter, *it); 370 } 341 371 } 342 372 … … 345 375 /* BspViewCellsManager implementation */ 346 376 /**********************************************************************/ 377 347 378 348 379 BspViewCellsManager::BspViewCellsManager(BspTree *bspTree, … … 490 521 //exporter->SetWireframe(); 491 522 exporter->SetFilled(); 492 exporter->ExportBspViewCellPartition(*mBspTree, 493 mViewCellsStats.maxPvs); 523 ExportViewCells(exporter); 494 524 495 525 if (0) … … 593 623 if (exporter) 594 624 { 595 exporter->ExportBspViewCellPartition(*mBspTree, 596 mViewCellsStats.maxPvs); 625 ExportViewCells(exporter); 597 626 delete exporter; 598 627 } … … 635 664 exporter->ExportBspSplits(*mBspTree, true); 636 665 637 // take forced material, else big scenes cannot be viewed666 //NOTE: take forced material, else big scenes cannot be viewed 638 667 m.mDiffuseColor = RgbColor(0, 1, 0); 639 668 exporter->SetForcedMaterial(m); 669 //exporter->ResetForcedMaterial(); 670 640 671 exporter->SetFilled(); 641 642 exporter->ResetForcedMaterial(); 643 672 644 673 // export rays 645 674 if (0) … … 671 700 672 701 environment->GetBoolValue("VspBspTree.Visualization.exportRays", exportRays); 673 environment->GetBoolValue("VspBspTree.Visualization.export Geometry", exportGeometry);702 environment->GetBoolValue("VspBspTree.Visualization.exportRays", exportRays); 674 703 675 704 const int leafOut = 10; … … 866 895 } 867 896 897 898 void BspViewCellsManager::ExportColor(Exporter *exporter, 899 ViewCell *vc) const 900 { 901 if (mColorCode == 0) // Random color 902 { 903 exporter->ResetForcedMaterial(); 904 return; 905 } 906 907 float importance = 0; 908 909 switch (mColorCode) 910 { 911 case 1: // pvs 912 { 913 importance = (float)vc->GetPvs().GetSize() / 914 (float)mViewCellsStats.maxPvs; 915 } 916 break; 917 case 2: // merges 918 { 919 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 920 921 importance = (float)bspVc->mLeaves.size() / 922 (float)mViewCellsStats.maxLeaves; 923 } 924 break; 925 case 3: // merge tree differene 926 { 927 // TODO 928 } 929 break; 930 default: 931 break; 932 } 933 934 Material m; 935 m.mDiffuseColor.b = 1.0f; 936 m.mDiffuseColor.r = importance; 937 m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r; 938 939 exporter->SetForcedMaterial(m); 940 } 941 942 void BspViewCellsManager::ExportGeometry(Exporter *exporter, 943 ViewCell *vc) const 944 { 945 if (vc->GetMesh()) 946 exporter->ExportViewCell(vc); 947 else 948 { 949 PolygonContainer cell; 950 mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(vc), cell); 951 952 exporter->ExportPolygons(cell); 953 } 954 } 868 955 869 956 /**********************************************************************/ … … 1116 1203 1117 1204 1205 void KdViewCellsManager::ExportColor(Exporter *exporter, 1206 ViewCell *vc) const 1207 { 1208 // TODO 1209 } 1210 1211 1212 void KdViewCellsManager::ExportGeometry(Exporter *exporter, 1213 ViewCell *vc) const 1214 { 1215 // TODO 1216 } 1217 1218 1118 1219 int KdViewCellsManager::GetType() const 1119 1220 { … … 1143 1244 /* VspKdViewCellsManager implementation */ 1144 1245 /**********************************************************************/ 1246 1145 1247 1146 1248 VspKdViewCellsManager::VspKdViewCellsManager(VspKdTree *vspKdTree, … … 1192 1294 Debug << mVspKdTree->GetStatistics() << endl; 1193 1295 1194 ResetViewCells();1195 Debug << "\nView cells after construction:\n" << mViewCellsStats << endl;1296 // export leaf building blocks 1297 ExportLeaves(objects, rays); 1196 1298 1197 1299 // finally merge kd leaf building blocks to view cells 1198 1300 const int merged = mVspKdTree->MergeLeaves(); 1301 // evaluale view cell stats 1302 ResetViewCells(); 1303 1304 Debug << "\nView cells after construction:\n" << mViewCellsStats << endl; 1199 1305 1200 1306 // recast rest of rays … … 1221 1327 return 0; 1222 1328 1329 // recalculate stats 1330 EvaluateViewCellsStats(); 1331 1223 1332 return 0; 1224 1333 } 1225 1334 1335 1226 1336 AxisAlignedBox3 VspKdViewCellsManager::GetSceneBbox() const 1227 1337 { 1228 1338 return mVspKdTree->GetBBox(mVspKdTree->GetRoot()); 1339 } 1340 1341 1342 void VspKdViewCellsManager::ExportLeaves(const ObjectContainer &objects, 1343 const VssRayContainer &sampleRays) 1344 { 1345 bool exportRays = false; 1346 bool exportGeometry = false; 1347 1348 environment->GetBoolValue("VspKdTree.Visualization.exportRays", exportRays); 1349 environment->GetBoolValue("VspKdTree.Visualization.exportGeometry", exportGeometry); 1350 1351 if (!ViewCellsConstructed()) 1352 return; 1353 1354 //-- export leaf building blocks 1355 Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d"); 1356 if (!exporter) 1357 return; 1358 1359 //exporter->SetWireframe(); 1360 //exporter->ExportVspKdTree(*mVspKdTree, mVspKdTree->GetStatistics().maxPvsSize); 1361 exporter->ExportVspKdTree(*mVspKdTree); 1362 1363 if (exportGeometry) 1364 exporter->ExportGeometry(objects); 1365 1366 if (exportRays) 1367 { 1368 const float prob = (float)mVisualizationSamples 1369 / ((float)sampleRays.size() + Limits::Small); 1370 1371 exporter->SetWireframe(); 1372 1373 //-- collect uniformly distributed rays 1374 VssRayContainer rays; 1375 1376 for (int i = 0; i < sampleRays.size(); ++ i) 1377 { 1378 if (RandomValue(0,1) < prob) 1379 rays.push_back(sampleRays[i]); 1380 } 1381 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 1382 } 1383 1384 delete exporter; 1229 1385 } 1230 1386 … … 1240 1396 if (!ViewCellsConstructed()) 1241 1397 return; 1242 1243 //-- export tree leaves 1244 if (1) 1245 { 1246 Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d"); 1247 //exporter->SetWireframe(); 1248 //exporter->ExportVspKdTree(*mVspKdTree, mVspKdTree->GetStatistics().maxPvsSize); 1249 exporter->ExportVspKdTree(*mVspKdTree); 1250 1251 if (1) 1252 exporter->ExportGeometry(objects); 1253 1254 if (exportRays) 1255 { 1256 int raysSize = 2000; 1257 float prob = raysSize / (float)sampleRays.size(); 1258 1259 exporter->SetWireframe(); 1260 1261 VssRayContainer rays; 1262 1263 for (int i = 0; i < sampleRays.size(); ++ i) 1398 1399 //-- export single view cells 1400 for (int i = 0; i < 10; ++ i) 1401 { 1402 char s[64]; 1403 sprintf(s, "vsp_viewcell%04d.x3d", i); 1404 Exporter *exporter = Exporter::GetExporter(s); 1405 const int idx = 1406 (int)RandomValue(0.0, (Real)((int)mViewCells.size() - 1)); 1407 1408 VspKdViewCell *vc = dynamic_cast<VspKdViewCell *>(mViewCells[idx]); 1409 1410 //-- export geometry 1411 Material m; 1412 m.mDiffuseColor = RgbColor(0, 1, 1); 1413 1414 exporter->SetForcedMaterial(m); 1415 exporter->SetWireframe(); 1416 1417 ExportGeometry(exporter, vc); 1418 1419 //-- export stored rays 1420 if (exportRays) 1421 { 1422 vector<VspKdLeaf *>::const_iterator it, 1423 it_end = vc->mLeaves.end(); 1424 1425 for (it = vc->mLeaves.begin(); it != it_end; ++ it) 1264 1426 { 1265 if (RandomValue(0,1) < prob) 1266 rays.push_back(sampleRays[i]); 1427 VspKdLeaf *leaf = *it; 1428 AxisAlignedBox3 box = mVspKdTree->GetBBox(leaf); 1429 1430 VssRayContainer vssRays; 1431 leaf->GetRays(vssRays); 1432 1433 VssRayContainer rays; 1434 VssRayContainer::const_iterator it, it_end = vssRays.end(); 1435 1436 for (it = vssRays.begin(); it != it_end; ++ it) 1437 rays.push_back(*it); 1438 1439 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 1267 1440 } 1268 1269 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 1441 } 1442 1443 //-- output PVS of view cell 1444 m.mDiffuseColor = RgbColor(1, 0, 0); 1445 exporter->SetForcedMaterial(m); 1446 1447 ObjectPvsMap::const_iterator it, 1448 it_end = vc->GetPvs().mEntries.end(); 1449 1450 exporter->SetFilled(); 1451 1452 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 1453 { 1454 Intersectable *intersect = (*it).first; 1455 1456 if (!intersect->Mailed()) 1457 { 1458 Material m = RandomMaterial(); 1459 exporter->SetForcedMaterial(m); 1460 1461 exporter->ExportIntersectable(intersect); 1462 intersect->Mail(); 1463 } 1270 1464 } 1271 1465 1272 1466 delete exporter; 1273 }1274 1275 //-- export single leaves1276 if (1)1277 {1278 vector<VspKdLeaf *> leafContainer;1279 mVspKdTree->CollectLeaves(leafContainer);1280 1281 for (int i = 0; i < 10; ++ i)1282 {1283 char s[64];1284 sprintf(s, "vsp_leaves%04d.x3d", i);1285 Exporter *exporter = Exporter::GetExporter(s);1286 1287 // export geometry1288 VspKdLeaf *leaf = leafContainer[(int)RandomValue(0.0, (Real)((int)leafContainer.size() - 1))];1289 AxisAlignedBox3 box = mVspKdTree->GetBBox(leaf);1290 1291 Material m;1292 m.mDiffuseColor = RgbColor(0, 1, 1);1293 exporter->SetForcedMaterial(m);1294 exporter->SetWireframe();1295 exporter->ExportBox(box);1296 1297 //-- export stored rays1298 VssRayContainer vssRays;1299 leaf->GetRays(vssRays);1300 1301 VssRayContainer rays;1302 VssRayContainer::const_iterator it, it_end = vssRays.end();1303 1304 for (it = vssRays.begin(); it != it_end; ++ it)1305 rays.push_back(*it);1306 1307 exporter->ExportRays(rays, RgbColor(1, 0, 0));1308 1309 //-- export stored PVS1310 ObjectContainer pvsObj;1311 leaf->ExtractPvs(pvsObj);1312 1313 exporter->ExportGeometry(pvsObj);1314 1315 delete exporter;1316 }1317 1467 } 1318 1468 1319 1469 //-- export final view cells 1320 1470 Exporter *exporter = Exporter::GetExporter("vspkdtree_merged.x3d"); 1321 exporter->SetWireframe(); 1322 //exporter->ExportVspKdTreeViewCells(*mVspKdTree, vcStats.maxPvs); 1323 exporter->ExportVspKdTreeViewCells(*mVspKdTree); 1324 1325 if (1) 1471 exporter->SetFilled(); 1472 ExportViewCells(exporter); 1473 1474 if (exportGeometry) 1326 1475 { 1327 1476 exporter->SetFilled(); … … 1331 1480 if (exportRays) 1332 1481 { 1333 int raysSize = 2000;1334 float prob = raysSize / (float)sampleRays.size();1482 const float prob = (float)mVisualizationSamples 1483 / ((float)sampleRays.size() + Limits::Small); 1335 1484 1336 1485 exporter->SetWireframe(); … … 1363 1512 1364 1513 1514 void VspKdViewCellsManager::ExportColor(Exporter *exporter, 1515 ViewCell *vc) const 1516 { 1517 if (mColorCode == 0) // Random color 1518 return; 1519 1520 float importance = 0; 1521 1522 switch (mColorCode) 1523 { 1524 case 1: // pvs 1525 { 1526 importance = (float)vc->GetPvs().GetSize() / 1527 (float)mViewCellsStats.maxPvs; 1528 } 1529 break; 1530 case 2: // merges 1531 { 1532 VspKdViewCell *vspKdVc = dynamic_cast<VspKdViewCell *>(vc); 1533 1534 importance = (float)vspKdVc->mLeaves.size() / 1535 (float)mViewCellsStats.maxLeaves; 1536 } 1537 break; 1538 case 3: // merge tree differene 1539 { 1540 //importance = (float)GetMaxTreeDiff(vc) / 1541 // (float)(mVspBspTree->GetStatistics().maxDepth * 2); 1542 } 1543 break; 1544 default: 1545 break; 1546 } 1547 1548 Material m; 1549 m.mDiffuseColor.b = 1.0f; 1550 m.mDiffuseColor.r = importance; 1551 m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r; 1552 //Debug << "importance: " << importance << endl; 1553 exporter->SetForcedMaterial(m); 1554 } 1555 1556 1557 void VspKdViewCellsManager::ExportGeometry(Exporter *exporter, 1558 ViewCell *vc) const 1559 { 1560 VspKdViewCell *kdVc = dynamic_cast<VspKdViewCell *>(vc); 1561 1562 vector<VspKdLeaf *>::const_iterator it, it_end = kdVc->mLeaves.end(); 1563 1564 for (it = kdVc->mLeaves.begin(); it != it_end; ++ it) 1565 { 1566 exporter->ExportBox(mVspKdTree->GetBBox(*it)); 1567 } 1568 } 1569 1365 1570 1366 1571 /**********************************************************************/ 1367 1572 /* VspBspViewCellsManager implementation */ 1368 1573 /**********************************************************************/ 1574 1369 1575 1370 1576 VspBspViewCellsManager::VspBspViewCellsManager(VspBspTree *vspBspTree, … … 1511 1717 //exporter->SetWireframe(); 1512 1718 exporter->SetFilled(); 1513 //exporter->ExportBspViewCellPartition(*mVspBspTree, mViewCellsStats.maxPvs);1514 exporter->ExportBspViewCellPartition(*mVspBspTree);1719 1720 ExportViewCells(exporter); 1515 1721 1516 1722 if (0) … … 1612 1818 if (exporter) 1613 1819 { 1614 //exporter->ExportBspViewCellPartition(*mVspBspTree, mViewCellsStats.maxPvs); 1615 exporter->ExportBspViewCellPartition(*mVspBspTree); 1820 ExportViewCells(exporter); 1616 1821 delete exporter; 1617 1822 } … … 1633 1838 ExportBspPvs(objects); 1634 1839 } 1635 1840 1636 1841 1637 1842 void VspBspViewCellsManager::ExportSplits(const ObjectContainer &objects) 1638 1843 { 1639 1844 Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 1845 1846 bool exportRays = false; 1847 bool exportGeometry = false; 1848 1849 environment->GetBoolValue("VspBspTree.Visualization.exportRays", exportRays); 1850 environment->GetBoolValue("VspBspTree.Visualization.exportGeometry", exportGeometry); 1640 1851 1641 1852 if (exporter) … … 1656 1867 1657 1868 // export rays 1658 if ( 0)1869 if (exportRays) 1659 1870 { 1660 1871 VssRayContainer outRays; … … 1670 1881 } 1671 1882 1672 if ( 0)1883 if (exportGeometry) 1673 1884 exporter->ExportGeometry(objects); 1674 1885 … … 1861 2072 return mVspBspTree->CastLineSegment(origin, termination, viewcells); 1862 2073 } 2074 2075 2076 void VspBspViewCellsManager::ExportColor(Exporter *exporter, 2077 ViewCell *vc) const 2078 { 2079 if (mColorCode == 0) // Random color 2080 return; 2081 2082 float importance = 0; 2083 2084 switch (mColorCode) 2085 { 2086 case 1: // pvs 2087 { 2088 importance = (float)vc->GetPvs().GetSize() / 2089 (float)mViewCellsStats.maxPvs; 2090 } 2091 break; 2092 case 2: // merges 2093 { 2094 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 2095 2096 importance = (float)bspVc->mLeaves.size() / 2097 (float)mViewCellsStats.maxLeaves; 2098 } 2099 break; 2100 case 3: // merge tree differene 2101 { 2102 importance = (float)GetMaxTreeDiff(vc) / 2103 (float)(mVspBspTree->GetStatistics().maxDepth * 2); 2104 } 2105 break; 2106 default: 2107 break; 2108 } 2109 2110 Material m; 2111 m.mDiffuseColor.b = 1.0f; 2112 m.mDiffuseColor.r = importance; 2113 m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r; 2114 //Debug << "importance: " << importance << endl; 2115 exporter->SetForcedMaterial(m); 2116 } 2117 2118 2119 void VspBspViewCellsManager::ExportGeometry(Exporter *exporter, 2120 ViewCell *vc) const 2121 { 2122 if (vc->GetMesh()) 2123 exporter->ExportViewCell(vc); 2124 else 2125 { 2126 PolygonContainer cell; 2127 mVspBspTree-> 2128 ConstructGeometry(dynamic_cast<BspViewCell *>(vc), cell); 2129 2130 exporter->ExportPolygons(cell); 2131 } 2132 } 2133 2134 2135 int VspBspViewCellsManager::GetMaxTreeDiff(ViewCell *vc) const 2136 { 2137 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 2138 2139 int maxDist = 0; 2140 // compute max height difference 2141 for (int i = 0; i < (int)bspVc->mLeaves.size(); ++ i) 2142 for (int j = 0; j < (int)bspVc->mLeaves.size(); ++ j) 2143 { 2144 BspLeaf *leaf = bspVc->mLeaves[i]; 2145 2146 if (i != j) 2147 { 2148 BspLeaf *leaf2 = bspVc->mLeaves[j]; 2149 int dist = mVspBspTree->TreeDistance(leaf, leaf2); 2150 if (dist > maxDist) 2151 maxDist = dist; 2152 } 2153 } 2154 2155 return maxDist; 2156 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r480 r482 24 24 class BspLeaf; 25 25 class ViewCellsStatistics; 26 26 class Exporter; 27 27 struct BspRay; 28 28 … … 214 214 protected: 215 215 216 void ParseEnvironment(); 217 216 218 /** Recollects view cells and resets statistics. 217 219 */ 218 220 void ResetViewCells(); 221 219 222 /** Collects the view cells in the view cell container. 220 223 */ 221 224 virtual void CollectViewCells() = 0; 222 225 223 226 /** Evaluates view cells statistics and stores it in 224 227 mViewCellsStatistics. 225 228 */ 226 229 void EvaluateViewCellsStats(); 227 230 231 232 //-- helper functions for view cell visualization 233 234 /** Exports the view cell partition. 235 */ 236 void ExportViewCells(Exporter *exporter) const; 237 238 /** Sets exporter color. 239 */ 240 virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0; 241 242 /** Exports view cell geometry. 243 */ 244 virtual void ExportGeometry(Exporter *exporter, ViewCell *vc) const = 0; 245 228 246 /// the view cell corresponding to unbounded space 229 247 ViewCell *mUnbounded; … … 247 265 float mTotalAreaValid; 248 266 float mTotalArea; 267 268 // visualization color code 269 int mColorCode; 249 270 250 271 ViewCellsStatistics mViewCellsStats; … … 307 328 void ConstructBspRays(const VssRayContainer &rays, 308 329 const int numSamples); 330 331 void ExportColor(Exporter *exporter, ViewCell *vc) const; 332 void ExportGeometry(Exporter *exporter, ViewCell *vc) const; 333 309 334 /// the BSP tree. 310 335 BspTree *mBspTree; … … 367 392 KdNode *GetNodeForPvs(KdLeaf *leaf); 368 393 394 void ExportColor(Exporter *exporter, ViewCell *vc) const; 395 void ExportGeometry(Exporter *exporter, ViewCell *vc) const; 369 396 370 397 /// the BSP tree. … … 417 444 protected: 418 445 446 void ExportLeaves(const ObjectContainer &objects, 447 const VssRayContainer &sampleRays); 448 419 449 void CollectViewCells(); 450 451 void ExportColor(Exporter *exporter, ViewCell *vc) const; 452 void ExportGeometry(Exporter *exporter, ViewCell *vc) const; 453 420 454 421 455 /// the BSP tree. … … 480 514 void CollectViewCells(); 481 515 516 void ExportColor(Exporter *exporter, ViewCell *vc) const; 517 void ExportGeometry(Exporter *exporter, ViewCell *vc) const; 518 519 /** Returns maximal depth difference of view cell 520 leaves in tree. 521 */ 522 int GetMaxTreeDiff(ViewCell *vc) const; 523 482 524 /// the view space partition BSP tree. 483 525 VspBspTree *mVspBspTree; 484 526 527 /// helper array of rays 485 528 vector<BspRay *> mBspRays; 486 529 487 530 private: 488 531 489 490 532 /** Exports visualization of the BSP splits. 491 533 */ -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r481 r482 19 19 20 20 //-- static members 21 /** Evaluates split plane classification with respect to the plane's 21 /** Evaluates split plane classification with respect to the plane's 22 22 contribution for a minimum number of ray splits. 23 23 */ 24 24 const float VspBspTree::sLeastRaySplitsTable[] = {0, 0, 1, 1, 0}; 25 /** Evaluates split plane classification with respect to the plane's 25 /** Evaluates split plane classification with respect to the plane's 26 26 contribution for balanced rays. 27 27 */ … … 29 29 30 30 31 int VspBspTree::sFrontId = 0; 31 int VspBspTree::sFrontId = 0; 32 32 int VspBspTree::sBackId = 0; 33 33 int VspBspTree::sFrontAndBackId = 0; … … 39 39 /****************************************************************/ 40 40 41 VspBspTree::VspBspTree(): 41 VspBspTree::VspBspTree(): 42 42 mRoot(NULL), 43 43 mPvsUseArea(true), 44 44 mCostNormalizer(Limits::Small), 45 45 mViewCellsManager(NULL), 46 mStoreRays(true) 46 mStoreRays(true), 47 mOnlyDrivingAxis(false) 47 48 { 48 49 mRootCell = new BspViewCell(); … … 54 55 environment->GetIntValue("VspBspTree.Termination.minPvs", mTermMinPvs); 55 56 environment->GetIntValue("VspBspTree.Termination.minRays", mTermMinRays); 56 environment->GetFloatValue("VspBspTree.Termination.minArea", mTermMinArea); 57 environment->GetFloatValue("VspBspTree.Termination.minArea", mTermMinArea); 57 58 environment->GetFloatValue("VspBspTree.Termination.maxRayContribution", mTermMaxRayContribution); 58 59 environment->GetFloatValue("VspBspTree.Termination.minAccRayLenght", mTermMinAccRayLength); … … 65 66 environment->GetFloatValue("VspBspTree.Termination.ct_div_ci", mCtDivCi); 66 67 67 //-- termination criteria for axis aligned split 68 environment->GetFloatValue("VspBspTree.Termination.AxisAligned.ct_div_ci", mAxisAlignedCtDivCi); 68 //-- max cost ratio for early tree termination 69 69 environment->GetFloatValue("VspBspTree.Termination.maxCostRatio", mTermMaxCostRatio); 70 71 environment->GetIntValue("VspBspTree.Termination.AxisAligned.minRays", 72 mTermMinRaysForAxisAligned); 73 70 74 71 //-- partition criteria 75 72 environment->GetIntValue("VspBspTree.maxPolyCandidates", mMaxPolyCandidates); 76 73 environment->GetIntValue("VspBspTree.maxRayCandidates", mMaxRayCandidates); 77 74 environment->GetIntValue("VspBspTree.splitPlaneStrategy", mSplitPlaneStrategy); 78 environment->GetFloatValue("VspBspTree.AxisAligned.splitBorder", mAxisAlignedSplitBorder);79 75 80 76 environment->GetFloatValue("VspBspTree.Construction.epsilon", mEpsilon); … … 100 96 Debug << "max polygon candidates: " << mMaxPolyCandidates << endl; 101 97 Debug << "max plane candidates: " << mMaxRayCandidates << endl; 102 98 103 99 Debug << "Split plane strategy: "; 104 100 if (mSplitPlaneStrategy & RANDOM_POLYGON) … … 125 121 Debug << "pvs"; 126 122 } 127 123 128 124 mSplitCandidates = new vector<SortableEntry>; 129 125 … … 132 128 133 129 134 const BspTreeStatistics &VspBspTree::GetStatistics() const 130 const BspTreeStatistics &VspBspTree::GetStatistics() const 135 131 { 136 132 return mStat; … … 145 141 } 146 142 147 int VspBspTree::AddMeshToPolygons(Mesh *mesh, 148 PolygonContainer &polys, 143 int VspBspTree::AddMeshToPolygons(Mesh *mesh, 144 PolygonContainer &polys, 149 145 MeshInstance *parent) 150 146 { 151 147 FaceContainer::const_iterator fi; 152 148 153 149 // copy the face data to polygons 154 150 for (fi = mesh->mFaces.begin(); fi != mesh->mFaces.end(); ++ fi) 155 151 { 156 152 Polygon3 *poly = new Polygon3((*fi), mesh); 157 153 158 154 if (poly->Valid(mEpsilon)) 159 155 { … … 167 163 } 168 164 169 int VspBspTree::AddToPolygonSoup(const ViewCellContainer &viewCells, 170 PolygonContainer &polys, 165 int VspBspTree::AddToPolygonSoup(const ViewCellContainer &viewCells, 166 PolygonContainer &polys, 171 167 int maxObjects) 172 168 { 173 int limit = (maxObjects > 0) ? 169 int limit = (maxObjects > 0) ? 174 170 Min((int)viewCells.size(), maxObjects) : (int)viewCells.size(); 175 171 176 172 int polysSize = 0; 177 173 … … 181 177 { 182 178 mBox.Include(viewCells[i]->GetBox()); // add to BSP tree aabb 183 polysSize += 184 AddMeshToPolygons(viewCells[i]->GetMesh(), 185 polys, 179 polysSize += 180 AddMeshToPolygons(viewCells[i]->GetMesh(), 181 polys, 186 182 viewCells[i]); 187 183 } … … 191 187 } 192 188 193 int VspBspTree::AddToPolygonSoup(const ObjectContainer &objects, 194 PolygonContainer &polys, 189 int VspBspTree::AddToPolygonSoup(const ObjectContainer &objects, 190 PolygonContainer &polys, 195 191 int maxObjects) 196 192 { 197 int limit = (maxObjects > 0) ? 193 int limit = (maxObjects > 0) ? 198 194 Min((int)objects.size(), maxObjects) : (int)objects.size(); 199 195 200 196 for (int i = 0; i < limit; ++i) 201 197 { … … 216 212 break; 217 213 } 218 214 219 215 if (mesh) // copy the mesh data to polygons 220 216 { … … 231 227 mStat.nodes = 1; 232 228 mBox.Initialize(); // initialise BSP tree bounding box 233 229 234 230 PolygonContainer polys; 235 231 RayInfoContainer *rays = new RayInfoContainer(); … … 247 243 { 248 244 VssRay *ray = *rit; 249 245 250 246 if (ray->mTerminationObject && !ray->mTerminationObject->Mailed()) 251 247 { … … 270 266 { 271 267 VssRay *ray = *rit; 272 268 273 269 float minT, maxT; 274 270 … … 277 273 { 278 274 float len = ray->Length(); 279 280 if (!len) 275 276 if (!len) 281 277 len = Limits::Small; 282 278 283 279 rays->push_back(RayInfo(ray, minT / len, maxT / len)); 284 280 } … … 290 286 cout << "finished" << endl; 291 287 292 Debug << "\nPolygon extraction: " << (int)polys.size() << " polys extracted from " 288 Debug << "\nPolygon extraction: " << (int)polys.size() << " polys extracted from " 293 289 << (int)sampleRays.size() << " rays in " 294 290 << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl << endl; … … 310 306 ConstructGeometry(mRoot, *geom); 311 307 312 VspBspTraversalData tData(mRoot, 313 new PolygonContainer(polys), 308 VspBspTraversalData tData(mRoot, 309 new PolygonContainer(polys), 314 310 0, 315 rays, 316 ComputePvsSize(*rays), 317 geom->GetArea(), 311 rays, 312 ComputePvsSize(*rays), 313 geom->GetArea(), 318 314 geom); 319 315 … … 324 320 325 321 long startTime = GetTime(); 326 322 327 323 while (!tStack.empty()) 328 324 { … … 335 331 336 332 if (r == mRoot) 337 Debug << "VSP BSP tree construction time spent at root: " 333 Debug << "VSP BSP tree construction time spent at root: " 338 334 << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl << endl; 339 335 } … … 346 342 bool VspBspTree::TerminationCriteriaMet(const VspBspTraversalData &data) const 347 343 { 348 return 344 return 349 345 (((int)data.mRays->size() <= mTermMinRays) || 350 346 (data.mPvs <= mTermMinPvs) || … … 355 351 } 356 352 357 BspNode *VspBspTree::Subdivide(VspBspTraversalStack &tStack, 353 BspNode *VspBspTree::Subdivide(VspBspTraversalStack &tStack, 358 354 VspBspTraversalData &tData) 359 355 { … … 363 359 { 364 360 PolygonContainer coincident; 365 361 366 362 VspBspTraversalData tFrontData; 367 363 VspBspTraversalData tBackData; … … 378 374 379 375 // delete old leaf node 380 DEL_PTR(tData.mNode); 381 } 382 } 383 376 DEL_PTR(tData.mNode); 377 } 378 } 379 384 380 //-- terminate traversal and create new view cell 385 381 if (newNode->IsLeaf()) 386 382 { 387 383 BspLeaf *leaf = dynamic_cast<BspLeaf *>(newNode); 388 384 389 385 // create new view cell for this leaf 390 386 BspViewCell *viewCell = new BspViewCell(); 391 387 leaf->SetViewCell(viewCell); 392 388 393 389 if (mStoreRays) 394 390 { … … 404 400 int conSamp = 0, sampCon = 0; 405 401 AddToPvs(leaf, *tData.mRays, conSamp, sampCon); 406 402 407 403 mStat.contributingSamples += conSamp; 408 404 mStat.sampleContributions += sampCon; 409 405 410 406 EvaluateLeafStats(tData); 411 407 } 412 413 408 409 414 410 //-- cleanup 415 411 tData.Clear(); … … 436 432 { 437 433 // terminate branch because of max cost 438 ++ mStat.maxCostNodes; 434 ++ mStat.maxCostNodes; 439 435 return leaf; 440 436 } … … 444 440 445 441 //-- subdivide further 446 BspInterior *interior = new BspInterior(splitPlane); 442 BspInterior *interior = new BspInterior(splitPlane); 447 443 448 444 #ifdef _DEBUG 449 445 Debug << interior << endl; 450 446 #endif 451 447 452 448 //-- the front and back traversal data is filled with the new values 453 449 frontData.mPolygons = new PolygonContainer(); … … 462 458 463 459 // subdivide rays 464 SplitRays(interior->GetPlane(), 465 *tData.mRays, 466 *frontData.mRays, 460 SplitRays(interior->GetPlane(), 461 *tData.mRays, 462 *frontData.mRays, 467 463 *backData.mRays); 468 464 469 465 // subdivide polygons 470 466 mStat.splits += SplitPolygons(interior->GetPlane(), 471 *tData.mPolygons, 472 *frontData.mPolygons, 467 *tData.mPolygons, 468 *frontData.mPolygons, 473 469 *backData.mPolygons, 474 470 coincident); 475 471 476 472 477 473 // how often was max cost ratio missed in this branch? 478 474 frontData.mMaxCostMisses = maxCostMisses; … … 486 482 if (1) 487 483 { 488 tData.mGeometry->SplitGeometry(*frontData.mGeometry, 489 *backData.mGeometry, 484 tData.mGeometry->SplitGeometry(*frontData.mGeometry, 485 *backData.mGeometry, 490 486 interior->GetPlane(), 491 487 mBox, 492 488 mEpsilon); 493 489 494 490 frontData.mArea = frontData.mGeometry->GetArea(); 495 491 backData.mArea = backData.mGeometry->GetArea(); … … 517 513 // and setup child links 518 514 interior->SetupChildLinks(new BspLeaf(interior), new BspLeaf(interior)); 519 515 520 516 frontData.mNode = interior->GetFront(); 521 517 backData.mNode = interior->GetBack(); … … 526 522 527 523 void VspBspTree::AddToPvs(BspLeaf *leaf, 528 const RayInfoContainer &rays, 524 const RayInfoContainer &rays, 529 525 int &sampleContributions, 530 526 int &contributingSamples) … … 542 538 int contribution = 0; 543 539 VssRay *ray = (*it).mRay; 544 540 545 541 if (ray->mTerminationObject) 546 542 contribution += vc->GetPvs().AddSample(ray->mTerminationObject); 547 543 548 544 if (ray->mOriginObject) 549 545 contribution += vc->GetPvs().AddSample(ray->mOriginObject); … … 567 563 requestedSize < (int)(mSplitCandidates->capacity()/10) ) 568 564 { 569 DEL_PTR(mSplitCandidates);565 delete mSplitCandidates; 570 566 mSplitCandidates = new vector<SortableEntry>; 571 567 } … … 578 574 bool positive = (*ri).mRay->HasPosDir(axis); 579 575 mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMin : SortableEntry::ERayMax, 580 (*ri).ExtrapOrigin(axis), ( void *)&*ri));576 (*ri).ExtrapOrigin(axis), (*ri).mRay)); 581 577 582 578 mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMax : SortableEntry::ERayMin, 583 (*ri).ExtrapTermination(axis), ( void *)&*ri));579 (*ri).ExtrapTermination(axis), (*ri).mRay)); 584 580 } 585 581 … … 593 589 float &position) 594 590 { 595 // AxisAlignedBox3 dirBox = GetDirBBox(node);596 591 int raysBack; 597 592 int raysFront; … … 599 594 int pvsFront; 600 595 601 //axis = box.Size().DrivingAxis();602 603 596 SortSplitCandidates(rays, axis); 604 597 … … 630 623 631 624 if (object) 625 { 632 626 if (!object->Mailed()) 633 627 { … … 637 631 else 638 632 ++ object->mCounter; 633 } 639 634 } 640 635 } … … 652 647 { 653 648 ++ rl; 654 ray = (VssRay *) (*ci).data; 649 ray = (VssRay *) (*ci).ray; 650 655 651 Intersectable *object = ray->mTerminationObject; 652 656 653 if (object && !object->Mailed()) 657 654 { … … 664 661 { 665 662 -- rr; 666 667 ray = (VssRay *) (*ci).data; 663 ray = (VssRay *) (*ci).ray; 664 668 665 Intersectable *object = ray->mTerminationObject; 669 666 … … 671 668 { 672 669 if (-- object->mCounter == 0) 673 -- pr;670 -- pr; 674 671 } 675 672 … … 712 709 713 710 714 float VspBspTree::SelectAxisAlignedPlane(Plane3 &plane, 711 float VspBspTree::SelectAxisAlignedPlane(Plane3 &plane, 715 712 const VspBspTraversalData &tData) 716 713 { 717 714 AxisAlignedBox3 box; 718 715 box.Initialize(); 719 716 720 717 // create bounding box of region 721 718 RayInfoContainer::const_iterator ri, ri_end = tData.mRays->end(); … … 731 728 int bestAxis = -1; 732 729 733 bool mOnlyDrivingAxis = false;734 735 730 const int sAxis = box.Size().DrivingAxis(); 736 731 737 732 for (int axis = 0; axis < 3; ++ axis) 738 733 { … … 748 743 else 749 744 { 750 nCostRatio[axis] = 745 nCostRatio[axis] = 751 746 BestCostRatioHeuristics(*tData.mRays, 752 747 box, … … 780 775 781 776 782 bool VspBspTree::SelectPlane(Plane3 &plane, 783 BspLeaf *leaf, 777 bool VspBspTree::SelectPlane(Plane3 &plane, 778 BspLeaf *leaf, 784 779 VspBspTraversalData &data) 785 780 { … … 799 794 //-- choose plane on midpoint of a ray 800 795 const int candidateIdx = (int)RandomValue(0, (Real)((int)data.mRays->size() - 1)); 801 796 802 797 const Vector3 minPt = (*data.mRays)[candidateIdx].ExtrapOrigin(); 803 798 const Vector3 maxPt = (*data.mRays)[candidateIdx].ExtrapTermination(); … … 806 801 807 802 const Vector3 normal = (*data.mRays)[candidateIdx].mRay->GetDir(); 808 803 809 804 plane = Plane3(normal, pt); 810 805 return true; … … 815 810 816 811 // use heuristics to find appropriate plane 817 return SelectPlaneHeuristics(plane, leaf, data); 812 return SelectPlaneHeuristics(plane, leaf, data); 818 813 } 819 814 820 815 821 816 Plane3 VspBspTree::ChooseCandidatePlane(const RayInfoContainer &rays) const 822 { 817 { 823 818 const int candidateIdx = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 824 819 825 820 const Vector3 minPt = rays[candidateIdx].ExtrapOrigin(); 826 821 const Vector3 maxPt = rays[candidateIdx].ExtrapTermination(); … … 834 829 835 830 Plane3 VspBspTree::ChooseCandidatePlane2(const RayInfoContainer &rays) const 836 { 831 { 837 832 Vector3 pt[3]; 838 833 839 834 int idx[3]; 840 835 int cmaxT = 0; … … 845 840 { 846 841 idx[j] = (int)RandomValue(0, (Real)((int)rays.size() * 2 - 1)); 847 842 848 843 if (idx[j] >= (int)rays.size()) 849 844 { 850 845 idx[j] -= (int)rays.size(); 851 846 852 847 chooseMin = (cminT < 2); 853 848 } … … 857 852 RayInfo rayInf = rays[idx[j]]; 858 853 pt[j] = chooseMin ? rayInf.ExtrapOrigin() : rayInf.ExtrapTermination(); 859 } 854 } 860 855 861 856 return Plane3(pt[0], pt[1], pt[2]); … … 863 858 864 859 Plane3 VspBspTree::ChooseCandidatePlane3(const RayInfoContainer &rays) const 865 { 860 { 866 861 Vector3 pt[3]; 867 862 868 863 int idx1 = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 869 864 int idx2 = (int)RandomValue(0, (Real)((int)rays.size() - 1)); … … 881 876 // vector from line 1 to line 2 882 877 const Vector3 vd = ray2.ExtrapOrigin() - ray1.ExtrapOrigin(); 883 878 884 879 // project vector on normal to get distance 885 880 const float dist = DotProd(vd, norm); … … 891 886 } 892 887 893 bool VspBspTree::SelectPlaneHeuristics(Plane3 &bestPlane, 894 BspLeaf *leaf, 888 bool VspBspTree::SelectPlaneHeuristics(Plane3 &bestPlane, 889 BspLeaf *leaf, 895 890 VspBspTraversalData &data) 896 891 { … … 901 896 const int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 902 897 int maxIdx = (int)data.mPolygons->size(); 903 898 904 899 float candidateCost; 905 900 … … 909 904 const int candidateIdx = (int)RandomValue(0, (Real)(-- maxIdx)); 910 905 //Debug << "current Idx: " << maxIdx << " cand idx " << candidateIdx << endl; 911 906 912 907 Polygon3 *poly = (*data.mPolygons)[candidateIdx]; 913 908 914 909 // swap candidate to the end to avoid testing same plane 915 910 std::swap((*data.mPolygons)[maxIdx], (*data.mPolygons)[candidateIdx]); 916 911 917 912 //Polygon3 *poly = (*data.mPolygons)[(int)RandomValue(0, (int)polys.size() - 1)]; 918 913 … … 926 921 } 927 922 } 928 923 929 924 #if 0 930 925 //-- choose candidate planes extracted from rays … … 937 932 if (candidateCost < lowestCost) 938 933 { 939 bestPlane = plane; 934 bestPlane = plane; 940 935 lowestCost = candidateCost; 941 936 } … … 944 939 945 940 // axis aligned splits 946 candidateCost = SelectAxisAlignedPlane(plane, data); 941 candidateCost = SelectAxisAlignedPlane(plane, data); 947 942 948 943 if (candidateCost < lowestCost) 949 944 { 950 bestPlane = plane; 945 bestPlane = plane; 951 946 lowestCost = candidateCost; 952 947 } … … 971 966 } 972 967 973 float VspBspTree::SplitPlaneCost(const Plane3 &candidatePlane, 968 float VspBspTree::SplitPlaneCost(const Plane3 &candidatePlane, 974 969 const VspBspTraversalData &data) const 975 970 { … … 978 973 float sumBalancedRays = 0; 979 974 float sumRaySplits = 0; 980 975 981 976 int frontPvs = 0; 982 977 int backPvs = 0; … … 993 988 // create unique ids for pvs heuristics 994 989 GenerateUniqueIdsForPvs(); 995 990 996 991 if (mPvsUseArea) // use front and back cell areas to approximate volume 997 { 992 { 998 993 // construct child geometry with regard to the candidate split plane 999 994 BspNodeGeometry frontCell; 1000 995 BspNodeGeometry backCell; 1001 1002 data.mGeometry->SplitGeometry(frontCell, 1003 backCell, 996 997 data.mGeometry->SplitGeometry(frontCell, 998 backCell, 1004 999 candidatePlane, 1005 1000 mBox, 1006 1001 mEpsilon); 1007 1002 1008 1003 pFront = frontCell.GetArea(); 1009 1004 pBack = backCell.GetArea(); … … 1012 1007 } 1013 1008 } 1014 1009 1015 1010 int limit; 1016 1011 bool useRand; … … 1041 1036 sumBalancedRays += cf; 1042 1037 } 1043 1038 1044 1039 if (mSplitPlaneStrategy & BALANCED_RAYS) 1045 1040 { … … 1051 1046 { 1052 1047 // in case the ray intersects an object 1053 // assure that we only count the object 1048 // assure that we only count the object 1054 1049 // once for the front and once for the back side of the plane 1055 1050 1056 1051 // add the termination object 1057 1052 AddObjToPvs(ray->mTerminationObject, cf, frontPvs, backPvs); 1058 1053 1059 1054 // add the source object 1060 1055 AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs); 1061 1056 1062 1057 // use number or length of rays to approximate volume 1063 1058 if (!mPvsUseArea) … … 1067 1062 if (pvsUseLen) // use length of rays 1068 1063 len = rayInf.SqrSegmentLength(); 1069 1064 1070 1065 pOverall += len; 1071 1066 … … 1077 1072 { 1078 1073 // use length of rays to approximate volume 1079 if (pvsUseLen) 1074 if (pvsUseLen) 1080 1075 { 1081 float newLen = len * 1082 (rayInf.GetMaxT() - t) / 1076 float newLen = len * 1077 (rayInf.GetMaxT() - t) / 1083 1078 (rayInf.GetMaxT() - rayInf.GetMinT()); 1084 1079 1085 1080 if (candidatePlane.Side(rayInf.ExtrapOrigin()) <= 0) 1086 1081 { … … 1105 1100 1106 1101 const float raysSize = (float)data.mRays->size() + Limits::Small; 1107 1102 1108 1103 if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 1109 1104 cost += mLeastRaySplitsFactor * sumRaySplits / raysSize; … … 1111 1106 if (mSplitPlaneStrategy & BALANCED_RAYS) 1112 1107 cost += mBalancedRaysFactor * fabs(sumBalancedRays) / raysSize; 1113 1108 1114 1109 // pvs criterium 1115 1110 if (mSplitPlaneStrategy & PVS) … … 1120 1115 //cost += mPvsFactor * 0.5 * (frontPvs * pFront + backPvs * pBack) / oldCost; 1121 1116 //Debug << "new cost: " << cost << " over" << frontPvs * pFront + backPvs * pBack << " old cost " << oldCost << endl; 1122 1117 1123 1118 if (0) // give penalty to unbalanced split 1124 if (((pFront * 0.2 + Limits::Small) > pBack) || 1119 if (((pFront * 0.2 + Limits::Small) > pBack) || 1125 1120 (pFront < (pBack * 0.2 + Limits::Small))) 1126 1121 cost += 0.5; … … 1129 1124 #ifdef _DEBUG 1130 1125 Debug << "totalpvs: " << data.mPvs << " ptotal: " << pOverall 1131 << " frontpvs: " << frontPvs << " pFront: " << pFront 1126 << " frontpvs: " << frontPvs << " pFront: " << pFront 1132 1127 << " backpvs: " << backPvs << " pBack: " << pBack << endl << endl; 1133 1128 #endif 1134 1129 1135 1130 // normalize cost by sum of linear factors 1136 1131 return cost / (float)mCostNormalizer; … … 1150 1145 if (cf >= 0) 1151 1146 { 1152 if ((obj->mMailbox != sFrontId) && 1147 if ((obj->mMailbox != sFrontId) && 1153 1148 (obj->mMailbox != sFrontAndBackId)) 1154 1149 { … … 1156 1151 1157 1152 if (obj->mMailbox == sBackId) 1158 obj->mMailbox = sFrontAndBackId; 1153 obj->mMailbox = sFrontAndBackId; 1159 1154 else 1160 obj->mMailbox = sFrontId; 1161 } 1162 } 1163 1155 obj->mMailbox = sFrontId; 1156 } 1157 } 1158 1164 1159 if (cf <= 0) 1165 1160 { … … 1170 1165 1171 1166 if (obj->mMailbox == sFrontId) 1172 obj->mMailbox = sFrontAndBackId; 1167 obj->mMailbox = sFrontAndBackId; 1173 1168 else 1174 obj->mMailbox = sBackId; 1169 obj->mMailbox = sBackId; 1175 1170 } 1176 1171 } … … 1181 1176 stack<BspNode *> nodeStack; 1182 1177 nodeStack.push(mRoot); 1183 1184 while (!nodeStack.empty()) 1178 1179 while (!nodeStack.empty()) 1185 1180 { 1186 1181 BspNode *node = nodeStack.top(); 1187 1182 1188 1183 nodeStack.pop(); 1189 1190 if (node->IsLeaf()) 1191 { 1192 BspLeaf *leaf = (BspLeaf *)node; 1184 1185 if (node->IsLeaf()) 1186 { 1187 BspLeaf *leaf = (BspLeaf *)node; 1193 1188 leaves.push_back(leaf); 1194 } 1195 else 1189 } 1190 else 1196 1191 { 1197 1192 BspInterior *interior = dynamic_cast<BspInterior *>(node); … … 1224 1219 if (data.mDepth < mStat.minDepth) 1225 1220 mStat.minDepth = data.mDepth; 1226 1221 1227 1222 if (data.mDepth >= mTermMaxDepth) 1228 1223 ++ mStat.maxDepthNodes; … … 1236 1231 if (data.GetAvgRayContribution() > mTermMaxRayContribution) 1237 1232 ++ mStat.maxRayContribNodes; 1238 1239 if (data.mArea <= mTermMinArea) 1233 1234 if (data.mArea <= mTermMinArea) 1240 1235 { 1241 1236 //Debug << "area: " << data.mArea / mBox.SurfaceArea() << " min area: " << mTermMinArea / mBox.SurfaceArea() << endl; … … 1250 1245 << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 1251 1246 << "Area: " << data.mArea << " (min: " << mTermMinArea << "), " 1252 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 1247 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 1253 1248 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "=, " 1254 1249 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; … … 1259 1254 { 1260 1255 int hits = 0; 1261 1256 1262 1257 stack<BspRayTraversalData> tStack; 1263 1258 1264 1259 float maxt, mint; 1265 1260 … … 1271 1266 Vector3 entp = ray.Extrap(mint); 1272 1267 Vector3 extp = ray.Extrap(maxt); 1273 1268 1274 1269 BspNode *node = mRoot; 1275 1270 BspNode *farChild = NULL; 1276 1271 1277 1272 while (1) 1278 1273 { 1279 if (!node->IsLeaf()) 1274 if (!node->IsLeaf()) 1280 1275 { 1281 1276 BspInterior *in = dynamic_cast<BspInterior *>(node); … … 1291 1286 if(extSide <= 0) // plane does not split ray => no far child 1292 1287 continue; 1293 1288 1294 1289 farChild = in->GetFront(); // plane splits ray 1295 1290 … … 1301 1296 continue; 1302 1297 1303 farChild = in->GetBack(); // plane splits ray 1298 farChild = in->GetBack(); // plane splits ray 1304 1299 } 1305 1300 else // ray and plane are coincident … … 1318 1313 extp = splitPlane.FindIntersection(ray.GetLoc(), extp, &t); 1319 1314 maxt *= t; 1320 1315 1321 1316 } else // reached leaf => intersection with view cell 1322 1317 { 1323 1318 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 1324 1319 1325 1320 if (!leaf->GetViewCell()->Mailed()) 1326 1321 { … … 1329 1324 ++ hits; 1330 1325 } 1331 1326 1332 1327 //-- fetch the next far child from the stack 1333 1328 if (tStack.empty()) 1334 1329 break; 1335 1330 1336 1331 entp = extp; 1337 1332 mint = maxt; // NOTE: need this? … … 1357 1352 Exporter *exporter = Exporter::GetExporter(filename); 1358 1353 1359 if (exporter) 1354 if (exporter) 1360 1355 { 1361 1356 //exporter->ExportVspBspTree(*this); 1362 1357 return true; 1363 } 1358 } 1364 1359 1365 1360 return false; … … 1373 1368 ViewCell::NewMail(); 1374 1369 1375 while (!nodeStack.empty()) 1370 while (!nodeStack.empty()) 1376 1371 { 1377 1372 BspNode *node = nodeStack.top(); 1378 1373 nodeStack.pop(); 1379 1374 1380 if (node->IsLeaf()) 1375 if (node->IsLeaf()) 1381 1376 { 1382 1377 ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 1383 1378 1384 if (!viewCell->Mailed()) 1379 if (!viewCell->Mailed()) 1385 1380 { 1386 1381 viewCell->Mail(); … … 1388 1383 } 1389 1384 } 1390 else 1385 else 1391 1386 { 1392 1387 BspInterior *interior = dynamic_cast<BspInterior *>(node); … … 1399 1394 1400 1395 1401 BspTreeStatistics &VspBspTree::GetStat()1402 {1403 return mStat;1404 }1405 1406 1407 1396 float VspBspTree::AccumulatedRayLength(const RayInfoContainer &rays) const 1408 1397 { … … 1419 1408 1420 1409 int VspBspTree::SplitRays(const Plane3 &plane, 1421 RayInfoContainer &rays, 1422 RayInfoContainer &frontRays, 1410 RayInfoContainer &rays, 1411 RayInfoContainer &frontRays, 1423 1412 RayInfoContainer &backRays) 1424 1413 { … … 1435 1424 // get classification and receive new t 1436 1425 const int cf = bRay.ComputeRayIntersection(plane, t); 1437 1426 1438 1427 switch (cf) 1439 1428 { … … 1444 1433 frontRays.push_back(bRay); 1445 1434 break; 1446 case 0: 1435 case 0: 1447 1436 //-- split ray 1448 1437 //-- look if start point behind or in front of plane 1449 1438 if (plane.Side(bRay.ExtrapOrigin()) <= 0) 1450 { 1439 { 1451 1440 backRays.push_back(RayInfo(ray, bRay.GetMinT(), t)); 1452 1441 frontRays.push_back(RayInfo(ray, t, bRay.GetMaxT())); … … 1479 1468 // split plane of node itself 1480 1469 n = n->GetParent(); 1481 1470 1482 1471 if (n) 1483 1472 { … … 1494 1483 } 1495 1484 1496 void VspBspTree::ConstructGeometry(BspNode *n, 1485 void VspBspTree::ConstructGeometry(BspNode *n, 1497 1486 BspNodeGeometry &cell) const 1498 1487 { … … 1502 1491 } 1503 1492 1504 void VspBspTree::ConstructGeometry(BspNode *n, 1493 void VspBspTree::ConstructGeometry(BspNode *n, 1505 1494 PolygonContainer &cell) const 1506 1495 { … … 1515 1504 { 1516 1505 Polygon3 *p = GetBoundingBox().CrossSection(halfSpaces[i]); 1517 1506 1518 1507 if (p->Valid(mEpsilon)) 1519 1508 { … … 1527 1516 { 1528 1517 VertexContainer vertices; 1529 1518 1530 1519 for (int j = 0; j < 4; ++ j) 1531 1520 vertices.push_back(mBox.GetFace(i).mVertices[j]); … … 1545 1534 Polygon3 *frontPoly, *backPoly; 1546 1535 1547 const int cf = 1536 const int cf = 1548 1537 candidatePolys[i]->ClassifyPlane(halfSpaces[j], 1549 1538 mEpsilon); 1550 1539 1551 1540 switch (cf) 1552 1541 { … … 1555 1544 backPoly = new Polygon3(); 1556 1545 1557 candidatePolys[i]->Split(halfSpaces[j], 1558 *frontPoly, 1546 candidatePolys[i]->Split(halfSpaces[j], 1547 *frontPoly, 1559 1548 *backPoly, 1560 1549 mEpsilon); … … 1579 1568 } 1580 1569 } 1581 1570 1582 1571 if (candidatePolys[i]) 1583 1572 cell.push_back(candidatePolys[i]); … … 1595 1584 } 1596 1585 1597 int VspBspTree::FindNeighbors(BspNode *n, vector<BspLeaf *> &neighbors, 1586 int VspBspTree::FindNeighbors(BspNode *n, vector<BspLeaf *> &neighbors, 1598 1587 const bool onlyUnmailed) const 1599 1588 { … … 1604 1593 stack<BspNode *> nodeStack; 1605 1594 nodeStack.push(mRoot); 1606 1595 1607 1596 // planes needed to verify that we found neighbor leaf. 1608 1597 vector<Plane3> halfSpaces; 1609 1598 ExtractHalfSpaces(n, halfSpaces); 1610 1599 1611 while (!nodeStack.empty()) 1600 while (!nodeStack.empty()) 1612 1601 { 1613 1602 BspNode *node = nodeStack.top(); … … 1622 1611 PolygonContainer neighborCandidate; 1623 1612 ConstructGeometry(node, neighborCandidate); 1624 1613 1625 1614 bool isAdjacent = true; 1626 1615 for (int i = 0; (i < halfSpaces.size()) && isAdjacent; ++ i) 1627 1616 { 1628 const int cf = 1629 Polygon3::ClassifyPlane(neighborCandidate, 1617 const int cf = 1618 Polygon3::ClassifyPlane(neighborCandidate, 1630 1619 halfSpaces[i], 1631 1620 mEpsilon); … … 1641 1630 } 1642 1631 } 1643 else 1632 else 1644 1633 { 1645 1634 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1646 1647 const int cf = Polygon3::ClassifyPlane(cell, 1648 interior->GetPlane(), 1635 1636 const int cf = Polygon3::ClassifyPlane(cell, 1637 interior->GetPlane(), 1649 1638 mEpsilon); 1650 1639 … … 1654 1643 if (cf == Polygon3::BACK_SIDE) 1655 1644 nodeStack.push(interior->GetBack()); 1656 else 1645 else 1657 1646 { 1658 1647 // random decision … … 1662 1651 } 1663 1652 } 1664 1653 1665 1654 CLEAR_CONTAINER(cell); 1666 1655 return (int)neighbors.size(); … … 1671 1660 stack<BspNode *> nodeStack; 1672 1661 nodeStack.push(mRoot); 1673 1662 1674 1663 int mask = rand(); 1675 1676 while (!nodeStack.empty()) 1664 1665 while (!nodeStack.empty()) 1677 1666 { 1678 1667 BspNode *node = nodeStack.top(); 1679 1668 nodeStack.pop(); 1680 1681 if (node->IsLeaf()) 1669 1670 if (node->IsLeaf()) 1682 1671 { 1683 1672 return dynamic_cast<BspLeaf *>(node); 1684 } 1685 else 1673 } 1674 else 1686 1675 { 1687 1676 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1688 1677 1689 1678 BspNode *next; 1690 1679 1691 1680 PolygonContainer cell; 1692 1681 … … 1701 1690 if (cf == Polygon3::FRONT_SIDE) 1702 1691 next = interior->GetFront(); 1703 else 1692 else 1704 1693 { 1705 1694 // random decision … … 1714 1703 } 1715 1704 } 1716 1705 1717 1706 return NULL; 1718 1707 } … … 1721 1710 { 1722 1711 stack<BspNode *> nodeStack; 1723 1712 1724 1713 nodeStack.push(mRoot); 1725 1714 1726 1715 int mask = rand(); 1727 1728 while (!nodeStack.empty()) 1716 1717 while (!nodeStack.empty()) 1729 1718 { 1730 1719 BspNode *node = nodeStack.top(); 1731 1720 nodeStack.pop(); 1732 1733 if (node->IsLeaf()) 1721 1722 if (node->IsLeaf()) 1734 1723 { 1735 1724 if ( (!onlyUnmailed || !node->Mailed()) ) 1736 1725 return dynamic_cast<BspLeaf *>(node); 1737 1726 } 1738 else 1727 else 1739 1728 { 1740 1729 BspInterior *interior = dynamic_cast<BspInterior *>(node); … … 1749 1738 } 1750 1739 } 1751 1740 1752 1741 return NULL; 1753 1742 } … … 1764 1753 { 1765 1754 VssRay *ray = (*rit).mRay; 1766 1755 1767 1756 if (ray->mOriginObject) 1768 1757 { … … 1797 1786 1798 1787 int VspBspTree::SplitPolygons(const Plane3 &plane, 1799 PolygonContainer &polys, 1800 PolygonContainer &frontPolys, 1801 PolygonContainer &backPolys, 1788 PolygonContainer &polys, 1789 PolygonContainer &frontPolys, 1790 PolygonContainer &backPolys, 1802 1791 PolygonContainer &coincident) const 1803 1792 { … … 1816 1805 case Polygon3::COINCIDENT: 1817 1806 coincident.push_back(poly); 1818 break; 1819 case Polygon3::FRONT_SIDE: 1807 break; 1808 case Polygon3::FRONT_SIDE: 1820 1809 frontPolys.push_back(poly); 1821 1810 break; … … 1844 1833 int hits = 0; 1845 1834 stack<BspRayTraversalData> tStack; 1846 1835 1847 1836 float mint = 0.0f, maxt = 1.0f; 1848 1837 1849 1838 Intersectable::NewMail(); 1850 1839 1851 1840 Vector3 entp = origin; 1852 1841 Vector3 extp = termination; 1853 1842 1854 1843 BspNode *node = mRoot; 1855 1844 BspNode *farChild = NULL; 1856 1857 while (1) 1858 { 1859 if (!node->IsLeaf()) 1845 1846 while (1) 1847 { 1848 if (!node->IsLeaf()) 1860 1849 { 1861 1850 BspInterior *in = dynamic_cast<BspInterior *>(node); 1862 1851 1863 1852 Plane3 splitPlane = in->GetPlane(); 1864 1853 const int entSide = splitPlane.Side(entp); 1865 1854 const int extSide = splitPlane.Side(extp); 1866 1867 if (entSide < 0) 1855 1856 if (entSide < 0) 1868 1857 { 1869 1858 node = in->GetBack(); 1870 1859 1871 1860 if(extSide <= 0) // plane does not split ray => no far child 1872 1861 continue; 1873 1862 1874 1863 farChild = in->GetFront(); // plane splits ray 1875 } else if (entSide > 0) 1864 } else if (entSide > 0) 1876 1865 { 1877 1866 node = in->GetFront(); 1878 1867 1879 1868 if (extSide >= 0) // plane does not split ray => no far child 1880 1869 continue; 1881 1882 farChild = in->GetBack(); // plane splits ray 1870 1871 farChild = in->GetBack(); // plane splits ray 1883 1872 } 1884 1873 else // ray and plane are coincident … … 1889 1878 continue; 1890 1879 } 1891 1880 1892 1881 // push data for far child 1893 1882 tStack.push(BspRayTraversalData(farChild, extp, maxt)); 1894 1883 1895 1884 // find intersection of ray segment with plane 1896 1885 float t; 1897 1886 extp = splitPlane.FindIntersection(origin, extp, &t); 1898 1887 maxt *= t; 1899 1900 } else 1888 1889 } else 1901 1890 { 1902 1891 // reached leaf => intersection with view cell 1903 1892 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 1904 1905 if (!leaf->GetViewCell()->Mailed()) 1893 1894 if (!leaf->GetViewCell()->Mailed()) 1906 1895 { 1907 1896 viewcells.push_back(leaf->GetViewCell()); … … 1909 1898 ++ hits; 1910 1899 } 1911 1900 1912 1901 //-- fetch the next far child from the stack 1913 1902 if (tStack.empty()) 1914 1903 break; 1915 1904 1916 1905 entp = extp; 1917 1906 mint = maxt; // NOTE: need this? 1918 1919 1907 1908 1920 1909 BspRayTraversalData &s = tStack.top(); 1921 1910 1922 1911 node = s.mNode; 1923 1912 extp = s.mExitPoint; 1924 1913 maxt = s.mMaxT; 1925 1914 1926 1915 tStack.pop(); 1927 1916 } … … 1930 1919 } 1931 1920 1921 int VspBspTree::TreeDistance(BspNode *n1, BspNode *n2) 1922 { 1923 std::deque<BspNode *> path1; 1924 BspNode *p1 = n1; 1925 1926 // create path from node 1 to root 1927 while (p1) 1928 { 1929 if (p1 == n2) // second node on path 1930 return (int)path1.size(); 1931 1932 path1.push_front(p1); 1933 p1 = p1->GetParent(); 1934 } 1935 1936 int depth = n2->GetDepth(); 1937 int d = depth; 1938 1939 BspNode *p2 = n2; 1940 1941 // compare with same depth 1942 while (1) 1943 { 1944 if ((d < (int)path1.size()) && (p2 == path1[d])) 1945 return (depth - d) + ((int)path1.size() - 1 - d); 1946 1947 -- d; 1948 p2 = p2->GetParent(); 1949 } 1950 1951 return 0; // never come here 1952 } 1932 1953 1933 1954 BspNode *VspBspTree::CollapseTree(BspNode *node) … … 1952 1973 1953 1974 BspLeaf *leaf = new BspLeaf(interior->GetParent(), vc); 1954 1975 1955 1976 // replace a link from node's parent 1956 1977 if (leaf->GetParent()) … … 2048 2069 2049 2070 int merged = 0; 2071 int mergedSiblings = 0; 2072 int accTreeDist = 0; 2073 int maxTreeDist = 0; 2074 const bool mergeStats = true; 2075 2050 2076 2051 2077 //-- use priority queue to merge leaf pairs 2052 2078 while (!mergeQueue.empty() && (vcSize > mMergeMinViewCells) && 2053 (mergeQueue.top().GetMergeCost() < 2079 (mergeQueue.top().GetMergeCost() < 2054 2080 mMergeMaxCostRatio * BspMergeCandidate::sOverallCost)) 2055 2081 { … … 2066 2092 ViewCell::NewMail(); 2067 2093 MergeViewCells(mc.GetLeaf1(), mc.GetLeaf2()); 2068 2069 ++ merged;2070 2094 -- vcSize; 2071 2095 // increase absolute merge cost 2072 2096 BspMergeCandidate::sOverallCost += mc.GetMergeCost(); 2097 2098 //-- stats 2099 ++ merged; 2100 2101 if (mc.GetLeaf1()->IsSibling(mc.GetLeaf2())) 2102 ++ mergedSiblings; 2103 2104 if (mergeStats) 2105 { 2106 const int dist = TreeDistance(mc.GetLeaf1(), mc.GetLeaf2()); 2107 2108 if (dist > maxTreeDist) 2109 maxTreeDist = dist; 2110 2111 accTreeDist += dist; 2112 } 2073 2113 } 2074 2114 // merge candidate not valid, because one of the leaves was already … … 2088 2128 RepairVcLeafLists(); 2089 2129 2090 //Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl; 2130 Debug << "Merged " << merged << " nodes of " << savedVcSize 2131 << " (merged " << mergedSiblings << " siblings)" << endl; 2132 2133 if (mergeStats) 2134 { 2135 Debug << "maximal tree distance: " << maxTreeDist << endl; 2136 Debug << "Avg tree distance: " << (float)accTreeDist / (float)merged << endl; 2137 } 2091 2138 2092 2139 //TODO: should return sample contributions … … 2097 2144 bool VspBspTree::MergeViewCells(BspLeaf *l1, BspLeaf *l2) 2098 2145 { 2099 //-- change pointer to view cells of all leaves associated 2146 //-- change pointer to view cells of all leaves associated 2100 2147 //-- with the previous view cells 2101 2148 BspViewCell *fVc = l1->GetViewCell(); … … 2184 2231 //-- to new rendering cost (size of merged view cell times pvs size) 2185 2232 const float oldCost = GetLeaf1Cost() + GetLeaf2Cost(); 2186 2233 2187 2234 const float newCost = 2188 2235 (float)vcPvs * (vc1->GetArea() + vc2->GetArea()); -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r481 r482 191 191 enum {FROM_INPUT_VIEW_CELLS, FROM_SCENE_GEOMETRY, FROM_SAMPLES}; 192 192 193 /** Returns statistics.194 */195 BspTreeStatistics &GetStat();196 197 193 /** finds neighbouring leaves of this tree node. 198 194 */ … … 255 251 BspNode *CollapseTree(BspNode *node); 256 252 253 254 /** Returns distance from node 1 to node 2. 255 */ 256 int TreeDistance(BspNode *n1, BspNode *n2); 257 257 258 258 protected: … … 271 271 int type; 272 272 float value; 273 void *data;273 VssRay *ray; 274 274 275 275 SortableEntry() {} 276 SortableEntry(const int t, const float v, void *d):type(t),277 value(v), data(d)276 SortableEntry(const int t, const float v, VssRay *r):type(t), 277 value(v), ray(r) 278 278 { 279 279 } … … 580 580 vector<SortableEntry> *mSplitCandidates; 581 581 582 bool mOnlyDrivingAxis; 583 584 582 585 private: 583 586 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r480 r482 343 343 344 344 345 346 VspKdTree::VspKdTree(): mOnlyDrivingAxis(true) 345 VspKdTree::VspKdTree(): mOnlyDrivingAxis(false) 347 346 { 348 347 environment->GetIntValue("VspKdTree.Termination.maxDepth", mTermMaxDepth); … … 431 430 app << "#N_LEAVES ( Number of leaves )\n" << Leaves() << "\n"; 432 431 433 app << "#N_SPLITS ( Number of splits in axes x y z dx dy dz\n";434 435 for (int i =0; i<7; i++)436 app << splits[i] << " ";432 app << "#N_SPLITS ( Number of splits in axes x y z\n"; 433 434 for (int i = 0; i < 3; ++ i) 435 app << splits[i] << " "; 437 436 app << endl; 438 437 … … 466 465 maxRayContribNodes * 100 / (double)Leaves() << endl; 467 466 467 app << "#N_PMAXRCOSTLEAVES ( Percentage of leaves with maximal cost ratio )\n" << 468 maxCostNodes * 100 / (double)Leaves() << endl; 469 468 470 app << "#N_ADDED_RAYREFS ( Number of dynamically added ray references )\n"<< 469 471 addedRayRefs << endl; … … 476 478 app << "#N_( Maximal PVS size / leaf)\n" 477 479 << maxPvsSize << endl; 480 481 app << "#N_( Average PVS size / leaf)\n" 482 << (double) accPvsSize / (double)Leaves() << endl; 478 483 479 484 app << "#N_CTIME ( Construction time [s] )\n" … … 550 555 //leaf->AddRay(RayInfo(*ri)); 551 556 VssRay *ray = *ri; 552 553 557 float minT, maxT; 554 555 // TODO: not very efficient to implictly cast between rays types ...558 559 // TODO: not very efficient to implictly cast between rays types! 556 560 if (mBox.GetRaySegment(*ray, minT, maxT)) 557 561 { … … 692 696 if (costRatio > mTermMaxCostRatio) 693 697 { 694 Debug << "Too big cost ratio " << costRatio << endl; 695 return -1; 698 //Debug << "Too big cost ratio " << costRatio << endl; 699 ++ leaf->mMaxCostMisses; 700 if (leaf->mMaxCostMisses > mTermMissTolerance) 701 { 702 ++ mStat.maxCostNodes; 703 return -1; 704 } 696 705 } 697 706 … … 721 730 pvsBack = 0; 722 731 723 float newCost;724 725 732 Intersectable::NewMail(3); 726 733 727 734 // eval pvs size 728 int pvsSize = leaf->GetPvsSize();735 const int pvsSize = leaf->GetPvsSize(); 729 736 730 737 // this is the main ray classification loop! … … 748 755 } 749 756 757 //-- only one of these options should be one 758 759 if (0) //-- only pvs 760 { 761 const float sum = float(pvsBack + pvsFront); 762 const float oldCost = (float)pvsSize; 763 764 return sum / oldCost; 765 } 766 767 //-- pvs + probability heuristics 768 float pBack, pFront, pOverall; 769 750 770 if (0) 751 771 { 752 const float sum = float(pvsBack + pvsFront); 753 const float oldCost = (float)pvsSize * 2; 754 755 return sum / oldCost; 756 } 757 else 758 { 759 #if 0 760 float minBox = box.Min(axis); 761 float maxBox = box.Max(axis); 762 763 float sizeBox = maxBox - minBox; 764 #else 765 766 float minBox = AxisAlignedBox3(box.Min(), position).SurfaceArea(); 767 float maxBox = AxisAlignedBox3(position, box.Max()).SurfaceArea(); 768 769 float sizeBox = box.SurfaceArea(); 770 #endif 771 772 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 773 const float sum = pvsBack * (position - minBox) + pvsFront * (maxBox - position); 774 775 newCost = mCtDivCi + sum / sizeBox; 776 777 //Debug << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl; 778 // float oldCost = leaf->mRays.size(); 779 const float oldCost = (float)pvsSize; 780 781 return newCost / oldCost; 782 } 772 // box length substitute for probability 773 const float minBox = box.Min(axis); 774 const float maxBox = box.Max(axis); 775 776 pBack = position - minBox; 777 pFront = maxBox - position; 778 pOverall = maxBox - minBox; 779 } 780 781 if (1) //-- area substitute for probability 782 { 783 784 const bool useMidSplit = true; 785 //const bool useMidSplit = false; 786 787 pOverall = box.SurfaceArea(); 788 789 if (!useMidSplit) 790 { 791 Vector3 pos = box.Max(); pos[axis] = position; 792 pBack = AxisAlignedBox3(box.Min(), pos).SurfaceArea(); 793 794 pos = box.Min(); pos[axis] = position; 795 pFront = AxisAlignedBox3(pos, box.Max()).SurfaceArea(); 796 } 797 else 798 { 799 //-- simplified computation for mid split 800 const int axis2 = (axis + 1) % 3; 801 const int axis3 = (axis + 2) % 3; 802 803 const float faceArea = 804 (box.Max(axis2) - box.Min(axis2)) * 805 (box.Max(axis3) - box.Min(axis3)); 806 807 pBack = pFront = pOverall * 0.5f + faceArea; 808 } 809 } 810 811 //-- ray density substitute for probability 812 if (1) 813 { 814 pBack = (float)raysBack; 815 pFront = (float)raysFront; 816 pOverall = (float)leaf->mRays.size(); 817 } 818 819 //Debug << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl; 820 //Debug << pFront << " " << pBack << " " << pOverall << endl; 821 822 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 823 const float newCost = pvsBack * pBack + pvsFront * pFront; 824 // float oldCost = leaf->mRays.size(); 825 const float oldCost = (float)pvsSize * pOverall; 826 827 return (mCtDivCi + newCost) / oldCost; 783 828 } 784 829 … … 800 845 801 846 //AxisAlignedBox3 sBox = GetBBox(leaf); 802 803 847 const int sAxis = box.Size().DrivingAxis(); 804 848 … … 912 956 { 913 957 ++ rl; 914 ray = ( VssRay *) (*ci).data;958 ray = (*ci).ray; 915 959 Intersectable *object = ray->mTerminationObject; 916 960 if (object && !object->Mailed()) … … 925 969 -- rr; 926 970 927 ray = ( VssRay *) (*ci).data;971 ray = (*ci).ray; 928 972 Intersectable *object = ray->mTerminationObject; 929 973 … … 992 1036 bool positive = (*ri).mRay->HasPosDir(axis); 993 1037 mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMin : SortableEntry::ERayMax, 994 (*ri).ExtrapOrigin(axis), ( void *)&*ri));1038 (*ri).ExtrapOrigin(axis), (*ri).mRay)); 995 1039 996 1040 mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMax : SortableEntry::ERayMin, 997 (*ri).ExtrapTermination(axis), ( void *)&*ri));1041 (*ri).ExtrapTermination(axis), (*ri).mRay)); 998 1042 } 999 1043 … … 1013 1057 mStat.maxRayRefs = (int)leaf->mRays.size(); 1014 1058 1059 mStat.rays += (int)leaf->mRays.size(); 1015 1060 1016 1061 if (data.mDepth >= mTermMaxDepth) … … 1020 1065 ++ mStat.minPvsNodes; 1021 1066 1067 mStat.accPvsSize += leaf->GetPvsSize(); 1068 1022 1069 if ((int)leaf->GetRays().size() < mTermMinRays) 1023 1070 ++ mStat.minRaysNodes; … … 1036 1083 return ((leaf->GetPvsSize() < mTermMinPvs) || 1037 1084 (leaf->mRays.size() < mTermMinRays) || 1038 //(leaf->GetAvgRayContribution() > mTermMaxRayContribution ) ||1085 (leaf->GetAvgRayContribution() > mTermMaxRayContribution ) || 1039 1086 (leaf->mDepth >= mTermMaxDepth) || 1040 1087 (SqrMagnitude(box.Size()) <= mTermMinSize)); … … 1068 1115 // select subdivision axis 1069 1116 const int axis = SelectPlane(leaf, box, position, raysBack, raysFront, pvsBack, pvsFront); 1070 1071 1117 //Debug << "rays back=" << raysBack << " rays front=" << raysFront << " pvs back=" << pvsBack << " pvs front=" << pvsFront << endl; 1072 1118 1073 int maxCostMisses = leaf->GetMaxCostMisses();1074 1075 1119 if (axis == -1) 1076 { 1077 // cost ratio missed 1078 ++ maxCostMisses; 1079 if (maxCostMisses > mTermMissTolerance) 1080 return leaf; 1081 } 1082 1120 return leaf; 1121 1083 1122 mStat.nodes += 2; 1084 //++ mStat.splits[axis];1123 ++ mStat.splits[axis]; 1085 1124 1086 1125 // add the new nodes to the tree … … 1094 1133 frontBBox = box; 1095 1134 1096 VspKdLeaf *back = new VspKdLeaf(node, raysBack, maxCostMisses);1135 VspKdLeaf *back = new VspKdLeaf(node, raysBack, leaf->GetMaxCostMisses()); 1097 1136 back->SetPvsSize(pvsBack); 1098 VspKdLeaf *front = new VspKdLeaf(node, raysFront, maxCostMisses);1137 VspKdLeaf *front = new VspKdLeaf(node, raysFront, leaf->GetMaxCostMisses()); 1099 1138 front->SetPvsSize(pvsFront); 1100 1139 … … 1686 1725 1687 1726 } 1688 else { 1727 else 1728 { 1689 1729 VspKdInterior *in = (VspKdInterior *)node; 1690 // both nodes for directional splits1730 1691 1731 tstack.push(in->GetFront()); 1692 1732 tstack.push(in->GetBack()); … … 1733 1773 VspKdInterior *in = 1734 1774 dynamic_cast<VspKdInterior *>(node); 1735 // both nodes for directional splits1775 1736 1776 tstack.push(in->GetFront()); 1737 1777 tstack.push(in->GetBack()); … … 1767 1807 { 1768 1808 VspKdInterior *in = (VspKdInterior *)node; 1769 // both nodes for directional splits1809 1770 1810 tstack.push(in->GetFront()); 1771 1811 tstack.push(in->GetBack()); … … 1832 1872 } 1833 1873 1874 1834 1875 int VspKdTree::ComputePvsSize(VspKdNode *node, 1835 1876 const RayInfoContainer &globalRays) const … … 1840 1881 1841 1882 RayInfoContainer::const_iterator it, it_end = globalRays.end(); 1883 1884 // TODO 1842 1885 1843 1886 // warning: implicit conversion from VssRay to Ray … … 1847 1890 return pvsSize; 1848 1891 } 1892 1849 1893 1850 1894 void VspKdTree::CollectLeaves(vector<VspKdLeaf *> &leaves) const … … 2065 2109 // set new size of view cell 2066 2110 vc->SetVolume(fVc->GetVolume() + bVc->GetVolume()); 2111 // new area 2112 vc->SetArea(fVc->GetArea() + bVc->GetArea()); 2067 2113 2068 2114 vector<VspKdLeaf *> fLeaves = fVc->mLeaves; … … 2143 2189 int merged = 0; 2144 2190 2145 //Debug << mMinViewCells << " " << mMaxCostRatio << endl;2146 2147 2191 // use priority queue to merge leaves 2148 while (!mergeQueue.empty() && 2149 (vcSize > mMergeMinViewCells) && 2192 while (!mergeQueue.empty() && (vcSize > mMergeMinViewCells) && 2150 2193 (mergeQueue.top().GetMergeCost() < 2151 mMergeMaxCostRatio /MergeCandidate::sOverallCost))2152 { 2153 //Debug << mergeQueue.top().GetMergeCost() << " " << mMaxCostRatio << endl;2194 mMergeMaxCostRatio * MergeCandidate::sOverallCost)) 2195 { 2196 //Debug << "mergecost: " << mergeQueue.top().GetMergeCost() / MergeCandidate::sOverallCost << " " << mMergeMaxCostRatio << endl; 2154 2197 MergeCandidate mc = mergeQueue.top(); 2155 2198 mergeQueue.pop(); … … 2181 2224 2182 2225 // collapse siblings belonging to the same view cell 2183 //CollapseTree(mRoot);2226 CollapseTree(mRoot); 2184 2227 // revalidate leaves 2185 //RepairVcLeafLists();2186 2187 //Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl;2228 RepairVcLeafLists(); 2229 2230 Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl; 2188 2231 2189 2232 //TODO: should return sample contributions … … 2332 2375 } 2333 2376 2377 2334 2378 VspKdLeaf *MergeCandidate::GetLeaf1() 2335 2379 { … … 2337 2381 } 2338 2382 2383 2339 2384 VspKdLeaf *MergeCandidate::GetLeaf2() 2340 2385 { 2341 2386 return mLeaf2; 2342 2387 } 2388 2343 2389 2344 2390 bool MergeCandidate::Valid() const … … 2349 2395 } 2350 2396 2397 2351 2398 float MergeCandidate::GetMergeCost() const 2352 2399 { 2353 2400 return mMergeCost; 2354 2401 } 2402 2355 2403 2356 2404 void MergeCandidate::SetValid() -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
r480 r482 140 140 int maxPvsSize; 141 141 142 // max cost ratio 143 int maxCostNodes; 144 142 145 // number of dynamically added ray refs 143 146 int addedRayRefs; … … 145 148 int removedRayRefs; 146 149 150 /// for average pvs 151 int accPvsSize; 152 147 153 /** Default constructor. 148 154 */ … … 167 173 maxRayContribNodes = 0; 168 174 minSizeNodes = 0; 175 maxCostNodes = 0; 169 176 170 177 maxRayRefs = 0; … … 173 180 initialPvsSize = 0; 174 181 maxPvsSize = 0; 182 accPvsSize = 0; 175 183 } 176 184 … … 236 244 VspKdInterior *mParent; 237 245 238 enum {SPLIT_X = 0, SPLIT_Y, SPLIT_Z , SPLIT_DIRX, SPLIT_DIRY, SPLIT_DIRZ};246 enum {SPLIT_X = 0, SPLIT_Y, SPLIT_Z}; 239 247 240 248 /// splitting axis … … 431 439 int type; 432 440 float value; 433 void *data;441 VssRay *ray; 434 442 435 443 SortableEntry() {} 436 SortableEntry(const int t, const float v, void *d):type(t),437 value(v), data(d)444 SortableEntry(const int t, const float v, VssRay *r): type(t), 445 value(v), ray(r) 438 446 { 439 447 } -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r469 r482 224 224 for (it = viewCells.begin(); it != it_end; ++ it) 225 225 ExportViewCell(*it); 226 }227 228 void229 X3dExporter::ExportBspViewCellPartition(const BspTree &tree, const int maxPvs)230 {231 ViewCellContainer viewCells;232 tree.CollectViewCells(viewCells);233 234 ViewCellContainer::const_iterator it, it_end = viewCells.end();235 236 if (maxPvs > 0)237 mUseForcedMaterial = true;238 239 for (it = viewCells.begin(); it != it_end; ++ it)240 {241 if (maxPvs > 0)242 {243 mForcedMaterial.mDiffuseColor.b = 1.0f;244 float importance = (float)(*it)->GetPvs().GetSize() / (float)maxPvs;245 246 mForcedMaterial.mDiffuseColor.r = importance;247 mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r;248 }249 250 if ((*it)->GetMesh())251 ExportViewCell(*it);252 else253 {254 PolygonContainer cell;255 tree.ConstructGeometry(dynamic_cast<BspViewCell *>(*it), cell);256 257 ExportPolygons(cell);258 }259 }260 226 } 261 227 … … 588 554 589 555 // export view cells 590 ExportBsp ViewCellPartition(tree);556 ExportBspLeaves(tree); 591 557 592 558 return true; … … 664 630 } 665 631 666 bool X3dExporter::ExportVspKdTreeViewCells(const VspKdTree &tree, const int maxPvs)667 {668 ViewCellContainer vc;669 670 //if (maxPvs > 0)671 mUseForcedMaterial = true;672 673 tree.CollectViewCells(vc);674 675 ViewCellContainer::const_iterator it, it_end = vc.end();676 677 for (it = vc.begin(); it != it_end; ++ it)678 {679 VspKdViewCell *viewCell = dynamic_cast<VspKdViewCell *>(*it);680 681 if (maxPvs > 0)682 {683 mForcedMaterial.mDiffuseColor.b = 1.0f;684 685 const float importance = (float)viewCell->GetPvs().GetSize() / (float)maxPvs;686 mForcedMaterial.mDiffuseColor.r = importance;687 mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r;688 }689 else690 mForcedMaterial = RandomMaterial();691 692 ExportVspKdTreeViewCell(tree, *viewCell);693 }694 695 return true;696 }697 698 bool X3dExporter::ExportVspKdTreeViewCell(const VspKdTree &tree, const VspKdViewCell &vc)699 {700 vector<VspKdLeaf *>::const_iterator it, it_end = vc.mLeaves.end();701 702 for (it = vc.mLeaves.begin(); it != it_end; ++ it)703 ExportBox(tree.GetBBox(*it));704 705 return true;706 }707 632 708 633 bool X3dExporter::ExportKdTree(const KdTree &tree) … … 1232 1157 } 1233 1158 1234 void X3dExporter::ExportBspViewCellPartition(const VspBspTree &tree,1235 const int maxPvs)1236 {1237 ViewCellContainer viewCells;1238 tree.CollectViewCells(viewCells);1239 1240 ViewCellContainer::const_iterator it, it_end = viewCells.end();1241 1242 if (maxPvs > 0)1243 mUseForcedMaterial = true;1244 1245 for (it = viewCells.begin(); it != it_end; ++ it)1246 {1247 if (maxPvs > 0)1248 {1249 mForcedMaterial.mDiffuseColor.b = 1.0f;1250 float importance = (float)(*it)->GetPvs().GetSize() / (float)maxPvs;1251 1252 mForcedMaterial.mDiffuseColor.r = importance;1253 mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r;1254 }1255 1256 if ((*it)->GetMesh())1257 ExportViewCell(*it);1258 else1259 {1260 PolygonContainer cell;1261 tree.ConstructGeometry(dynamic_cast<BspViewCell *>(*it), cell);1262 1263 ExportPolygons(cell);1264 }1265 }1266 }1267 1268 1159 1269 1160 bool -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r469 r482 115 115 116 116 virtual void 117 ExportBspViewCellPartition(const BspTree &tree, const int maxPvs = 0);118 119 virtual void120 117 ExportBspLeaves(const BspTree &tree, const int maxPvs = 0); 121 118 … … 123 120 virtual void 124 121 ExportBspSplits(const VspBspTree &tree, const bool exportDepth); 125 126 virtual void127 ExportBspViewCellPartition(const VspBspTree &tree, const int maxPvs = 0);128 129 virtual bool130 ExportVspKdTreeViewCells(const VspKdTree &tree, const int maxPvs = 0);131 122 132 123 protected: … … 151 142 const bool epsilon); 152 143 153 bool ExportVspKdTreeViewCell(const VspKdTree &tree, const VspKdViewCell &vc);154 155 144 156 145 void ExportViewpoint(const Vector3 &point, const Vector3 &direction);
Note: See TracChangeset
for help on using the changeset viewer.