- Timestamp:
- 11/17/05 18:47:53 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj
r410 r420 237 237 </File> 238 238 <File 239 RelativePath="..\src\RayInfo.cpp"> 240 </File> 241 <File 242 RelativePath="..\src\RayInfo.h"> 243 </File> 244 <File 239 245 RelativePath="..\src\Rectangle3.cpp"> 240 246 </File> -
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r419 r420 73 73 74 74 height 5.0 75 maxViewCells 076 75 77 76 … … 133 132 #splitPlaneStrategy 130 134 133 135 splitPlaneStrategy 1 024136 137 maxPolyCandidates 50138 maxRayCandidates 50134 splitPlaneStrategy 12 135 136 maxPolyCandidates 70 137 maxRayCandidates 100 139 138 140 139 Termination { 141 140 # parameters used for autopartition 142 maxRays 100141 maxRays 200 143 142 maxPolygons -1 144 143 maxDepth 40 -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
r419 r420 66 66 // surface area substitute for probability 67 67 PolygonContainer geom; 68 68 float overallarea = 0; 69 69 for (it = viewCells.begin(); it != it_end; ++ it) 70 70 { … … 72 72 mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom); 73 73 const float area = Polygon3::GetArea(geom); 74 if (area < 0.0001) 75 Debug << "warning, area: " << area << endl; 74 76 CLEAR_CONTAINER(geom); 75 77 … … 92 94 // crossing the border of a view cell is also depending on the move speed 93 95 loadPvsOverhead += pCrossVc * mVcOverhead; 94 96 overallarea+=area; 95 97 pInVcTotal += pInVc; 96 98 } 97 99 Debug << "overall area: " << overallarea << endl; 98 100 99 101 renderTime /= pInVcTotal; … … 103 105 mStat.avgRenderTime = renderTime + loadPvsOverhead; 104 106 107 mStat.maxCost /= pInVcTotal; 108 mStat.minCost /= pInVcTotal; 109 105 110 mStat.Stop(); 106 111 … … 183 188 mStat.avgRtWithoutOverhead = renderTime; 184 189 mStat.avgRenderTime = renderTime + loadPvsOverhead; 185 mStat.maxCost /= pCrossVcTotal; 186 mStat.minCost /= pCrossVcTotal; 190 191 mStat.maxCost /= pInVcTotal; 192 mStat.minCost /= pInVcTotal; 187 193 188 194 mStat.Stop(); -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r419 r420 61 61 ObjectContainer objects; 62 62 63 switch ( BspTree::sConstructionMethod)63 switch (mBspTree->mConstructionMethod) 64 64 { 65 65 case BspTree::FROM_INPUT_VIEW_CELLS: … … 181 181 } 182 182 183 if (ViewCell::sHierarchy == ViewCell::BSP)183 switch(ViewCell::sHierarchy) 184 184 { 185 // cast ray to BSP tree to get intersection with view cells 186 if (mBspTree) 187 { 188 mBspTree->CastRay(ray); 189 190 if (object) 191 sampleContributions += AddObjectSamples(object, ray); 192 193 if (!ray.intersections.empty()) // second intersection found 194 { 195 sampleContributions += 196 AddObjectSamples(ray.intersections[0].mObject, ray); 197 } 198 } 199 } 200 else { 201 if (ray.kdLeaves.size()) { 185 case ViewCell::BSP: 186 187 //-- cast ray to BSP tree to get intersection with view cells 188 if (!mBspTree) 189 break; 190 191 mBspTree->CastRay(ray); 192 193 if (object) 194 sampleContributions += AddObjectSamples(object, ray); 195 196 if (!ray.intersections.empty()) // second intersection found 197 { 198 sampleContributions += 199 AddObjectSamples(ray.intersections[0].mObject, ray); 200 } 201 break; 202 case ViewCell::KD: 203 if (ray.kdLeaves.size()) 204 { 202 205 Intersectable *terminator = 203 206 ray.intersections.size() ? ray.intersections[0].mObject: NULL; 204 207 205 208 sampleContributions += AddNodeSamples(ray, 206 object, 207 terminator); 208 } 209 } 210 209 object, 210 terminator); 211 } 212 break; 213 case ViewCell::VSP: 214 // TODO: 215 break; 216 default: 217 Debug << "Should never come here" << endl; 218 break; 219 } 220 211 221 return sampleContributions; 212 222 } … … 573 583 if (exporter) 574 584 { 585 exporter->SetWireframe(); 575 586 exporter->ExportBspLeaves(*mBspTree, stat.maxPvs); 576 587 //exporter->ExportBspViewCellPartition(*mBspTree, 0); 588 589 if (1) // export scene geometry 590 { 591 Material m;//= RandomMaterial(); 592 m.mDiffuseColor = RgbColor(0, 1, 0); 593 exporter->SetForcedMaterial(m); 594 exporter->SetWireframe(); 595 596 for (int j = 0; j < objects.size(); ++ j) 597 exporter->ExportIntersectable(objects[j]); 598 } 599 577 600 delete exporter; 578 601 } … … 756 779 if (!mBspTree) 757 780 { 758 if ((BspTree:: sConstructionMethod == BspTree::FROM_RAYS) &&781 if ((BspTree::mConstructionMethod == BspTree::FROM_RAYS) && 759 782 ((int)mSampleRays.size() < mBspConstructionSamples)) 760 783 { … … 866 889 outRays.push_back(mSampleRays[i]); 867 890 } 868 if (BspTree:: sConstructionMethod == BspTree::FROM_RAYS)891 if (BspTree::mConstructionMethod == BspTree::FROM_RAYS) 869 892 { 870 893 // export rays -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r418 r420 14 14 #include "Plane3.h" 15 15 16 int BspTree::sMaxPolyCandidates = 10;17 int BspTree::sMaxRayCandidates = 10;18 int BspTree::sSplitPlaneStrategy = BALANCED_POLYS;19 int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS;20 21 22 int BspTree::sTermMaxPolygons = 10;23 int BspTree::sTermMinPvs = 20;24 int BspTree::sTermMaxDepth = 20;25 float BspTree::sTermMinArea = 0.001f;26 int BspTree::sTermMaxPolysForAxisAligned = 50;27 int BspTree::sTermMaxObjectsForAxisAligned = 50;28 int BspTree::sTermMaxRaysForAxisAligned = -1;29 int BspTree::sTermMaxRays = -1;30 float BspTree::sTermMaxRayContribution = 0.05f;31 float BspTree::sTermMaxAccRayLength = 50;32 33 34 int BspTree::sMinPvsDif = 10;35 int BspTree::sMinPvs = 10;36 int BspTree::sMaxPvs = 500;37 38 float BspTree::sCt_div_ci = 1.0f;39 float BspTree::sSplitBorder = 1.0f;40 float BspTree::sMaxCostRatio = 0.9f;41 42 //-- factors for bsp tree split plane heuristics43 44 float BspTree::sLeastSplitsFactor = 1.0f;45 float BspTree::sBalancedPolysFactor = 1.0f;46 float BspTree::sBalancedViewCellsFactor = 1.0f;47 48 // NOTE: very important criterium for 2.5d scenes49 float BspTree::sVerticalSplitsFactor = 1.0f;50 float BspTree::sLargestPolyAreaFactor = 1.0f;51 float BspTree::sBlockedRaysFactor = 1.0f;52 float BspTree::sLeastRaySplitsFactor = 1.0f;53 float BspTree::sBalancedRaysFactor = 1.0f;54 float BspTree::sPvsFactor = 1.0f;55 56 bool BspTree::sStoreLeavesWithRays = false;57 16 int BspNode::mailID = 1; 58 17 … … 74 33 */ 75 34 float BspTree::sBalancedRaysTable[] = {1, -1, 0, 0, 0}; 76 77 bool BspTree::sPvsUseArea = true;78 35 79 36 /****************************************************************/ … … 271 228 void BspLeaf::AddToPvs(const BoundedRayContainer &rays, 272 229 int &sampleContributions, 273 int &contributingSamples) 230 int &contributingSamples, 231 bool storeLeavesWithRays) 274 232 { 275 233 sampleContributions = 0; … … 296 254 } 297 255 298 if ( BspTree::sStoreLeavesWithRays)256 if (storeLeavesWithRays) 299 257 // warning: intersections not ordered 300 258 ray->bspIntersections.push_back(Ray::BspIntersection((*it)->mMinT, this)); … … 308 266 309 267 BspTree::BspTree(BspViewCell *viewCell): 310 mRootCell(viewCell), mRoot(NULL), mGenerateViewCells(false), 311 mStorePiercingRays(true) 312 { 268 mRootCell(viewCell), 269 mRoot(NULL), 270 mGenerateViewCells(false), 271 //-- factors for bsp tree split plane heuristics 272 mVerticalSplitsFactor(1.0f), 273 mLargestPolyAreaFactor(1.0f), 274 mBlockedRaysFactor(1.0f), 275 mLeastRaySplitsFactor(1.0f), 276 mBalancedRaysFactor(1.0f), 277 mPvsFactor(1.0f), 278 mLeastSplitsFactor(1.0f), 279 mBalancedPolysFactor(1.0f), 280 mBalancedViewCellsFactor(1.0f), 281 //------------------------------------ 282 mStoreLeavesWithRays(false), 283 mPvsUseArea(true) 284 { 285 ParseEnvironment(); 313 286 Randomize(); // initialise random generator for heuristics 314 287 } … … 593 566 { 594 567 //store rays if needed for heuristics 595 if ( sSplitPlaneStrategy & BLOCKED_RAYS)568 if (mSplitPlaneStrategy & BLOCKED_RAYS) 596 569 (*it).second->mPiercingRays.push_back(ray); 597 570 } … … 602 575 polys->push_back(poly); 603 576 604 if ( sSplitPlaneStrategy & BLOCKED_RAYS)577 if (mSplitPlaneStrategy & BLOCKED_RAYS) 605 578 poly->mPiercingRays.push_back(ray); 606 579 … … 664 637 } 665 638 666 inlinebool BspTree::TerminationCriteriaMet(const BspTraversalData &data) const639 bool BspTree::TerminationCriteriaMet(const BspTraversalData &data) const 667 640 { 668 641 return 669 (((int)data.mPolygons->size() <= sTermMaxPolygons) || 670 ((int)data.mRays->size() <= sTermMaxRays) || 671 (data.mPvs <= sTermMinPvs) || 672 (data.mArea <= sTermMinArea) || 673 (data.mDepth >= sTermMaxDepth) || 674 (((float)data.mPvs / (float)data.mRays->size()) < sTermMaxRayContribution)); 642 (((int)data.mPolygons->size() <= mTermMaxPolygons) || 643 ((int)data.mRays->size() <= mTermMaxRays) || 644 (data.mPvs <= mTermMinPvs) || 645 (data.mArea <= mTermMinArea) || 646 (data.mDepth >= mTermMaxDepth) || 647 (((float)data.mPvs / ((float)data.mRays->size() + Limits::Small)) < 648 mTermMaxRayContribution)); 675 649 } 676 650 … … 926 900 float boxArea = box.SurfaceArea(); 927 901 928 float minBand = minBox + sSplitBorder * (maxBox - minBox);929 float maxBand = minBox + (1.0f - sSplitBorder) * (maxBox - minBox);902 float minBand = minBox + mSplitBorder * (maxBox - minBox); 903 float maxBand = minBox + (1.0f - mSplitBorder) * (maxBox - minBox); 930 904 931 905 float minSum = 1e20f; … … 968 942 969 943 float oldCost = (float)polys.size(); 970 float newCost = sCt_div_ci + minSum / boxArea;944 float newCost = mCt_div_ci + minSum / boxArea; 971 945 float ratio = newCost / oldCost; 972 946 … … 1008 982 } 1009 983 1010 if (costRatio >= sMaxCostRatio)984 if (costRatio >= mMaxCostRatio) 1011 985 return false; 1012 986 … … 1037 1011 } 1038 1012 1039 if (( sSplitPlaneStrategy & AXIS_ALIGNED) &&1040 ((int)data.mPolygons->size() > sTermMaxPolysForAxisAligned) &&1041 ((int)data.mRays->size() > sTermMaxRaysForAxisAligned) &&1042 (( sTermMaxObjectsForAxisAligned < 0) ||1043 (Polygon3::ParentObjectsSize(*data.mPolygons) > sTermMaxObjectsForAxisAligned)))1013 if ((mSplitPlaneStrategy & AXIS_ALIGNED) && 1014 ((int)data.mPolygons->size() > mTermMaxPolysForAxisAligned) && 1015 ((int)data.mRays->size() > mTermMaxRaysForAxisAligned) && 1016 ((mTermMaxObjectsForAxisAligned < 0) || 1017 (Polygon3::ParentObjectsSize(*data.mPolygons) > mTermMaxObjectsForAxisAligned))) 1044 1018 { 1045 1019 Plane3 plane; … … 1049 1023 1050 1024 // simplest strategy: just take next polygon 1051 if ( sSplitPlaneStrategy & RANDOM_POLYGON)1025 if (mSplitPlaneStrategy & RANDOM_POLYGON) 1052 1026 { 1053 1027 if (!data.mPolygons->empty()) … … 1086 1060 Plane3 plane; 1087 1061 1088 int limit = Min((int)data.mPolygons->size(), sMaxPolyCandidates);1062 int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 1089 1063 1090 1064 int candidateIdx = limit; … … 1116 1090 const BoundedRayContainer *rays = data.mRays; 1117 1091 1118 for (int i = 0; i < sMaxRayCandidates / 2; ++ i)1092 for (int i = 0; i < mMaxRayCandidates / 2; ++ i) 1119 1093 { 1120 1094 candidateIdx = Random((int)rays->size()); … … 1143 1117 1144 1118 //Debug << "lowest: " << lowestCost << endl; 1145 1146 for (int i = 0; i < sMaxRayCandidates / 2; ++ i) 1119 for (int i = 0; i < mMaxRayCandidates / 2; ++ i) 1147 1120 { 1148 1121 Vector3 pt[3]; … … 1228 1201 const int classification = (*it)->ClassifyPlane(candidatePlane); 1229 1202 1230 if ( sSplitPlaneStrategy & BALANCED_POLYS)1203 if (mSplitPlaneStrategy & BALANCED_POLYS) 1231 1204 sumBalancedPolys += sBalancedPolysTable[classification]; 1232 1205 1233 if ( sSplitPlaneStrategy & LEAST_SPLITS)1206 if (mSplitPlaneStrategy & LEAST_SPLITS) 1234 1207 sumSplits += sLeastPolySplitsTable[classification]; 1235 1208 1236 if ( sSplitPlaneStrategy & LARGEST_POLY_AREA)1209 if (mSplitPlaneStrategy & LARGEST_POLY_AREA) 1237 1210 { 1238 1211 if (classification == Polygon3::COINCIDENT) … … 1241 1214 } 1242 1215 1243 if ( sSplitPlaneStrategy & BLOCKED_RAYS)1216 if (mSplitPlaneStrategy & BLOCKED_RAYS) 1244 1217 { 1245 1218 const float blockedRays = (float)(*it)->mPiercingRays.size(); … … 1252 1225 1253 1226 // assign view cells to back or front according to classificaion 1254 if ( sSplitPlaneStrategy & BALANCED_VIEW_CELLS)1227 if (mSplitPlaneStrategy & BALANCED_VIEW_CELLS) 1255 1228 { 1256 1229 MeshInstance *viewCell = (*it)->mParent; … … 1291 1264 } 1292 1265 1266 const float polysSize = (float)polys.size() + Limits::Small; 1267 1293 1268 // all values should be approx. between 0 and 1 so they can be combined 1294 1269 // and scaled with the factors according to their importance 1295 if ( (sSplitPlaneStrategy & BALANCED_POLYS) && (!polys.empty()))1296 val += sBalancedPolysFactor * fabs(sumBalancedPolys) / (float)polys.size();1297 1298 if ( (sSplitPlaneStrategy & LEAST_SPLITS) && (!polys.empty()))1299 val += sLeastSplitsFactor * sumSplits / (float)polys.size();1300 1301 if ( sSplitPlaneStrategy & LARGEST_POLY_AREA)1270 if (mSplitPlaneStrategy & BALANCED_POLYS) 1271 val += sBalancedPolysFactor * fabs(sumBalancedPolys) / polysSize; 1272 1273 if (mSplitPlaneStrategy & LEAST_SPLITS) 1274 val += sLeastSplitsFactor * sumSplits / polysSize; 1275 1276 if (mSplitPlaneStrategy & LARGEST_POLY_AREA) 1302 1277 // HACK: polys.size should be total area so scaling is between 0 and 1 1303 1278 val += sLargestPolyAreaFactor * (float)polys.size() / sumPolyArea; 1304 1279 1305 if ( sSplitPlaneStrategy & BLOCKED_RAYS)1280 if (mSplitPlaneStrategy & BLOCKED_RAYS) 1306 1281 if (totalBlockedRays != 0) 1307 1282 val += sBlockedRaysFactor * (totalBlockedRays - sumBlockedRays) / totalBlockedRays; 1308 1283 1309 if ( sSplitPlaneStrategy & BALANCED_VIEW_CELLS)1310 if (totalViewCells != 0)1311 val += sBalancedViewCellsFactor * fabs(sumBalancedViewCells) / (float)totalViewCells;1284 if (mSplitPlaneStrategy & BALANCED_VIEW_CELLS) 1285 val += sBalancedViewCellsFactor * fabs(sumBalancedViewCells) / 1286 ((float)totalViewCells + Limits::Small); 1312 1287 1313 1288 return val; … … 1360 1335 float pBack = 0; 1361 1336 1362 if ( sSplitPlaneStrategy & PVS)1337 if (mSplitPlaneStrategy & PVS) 1363 1338 { 1364 1339 // create three unique ids for pvs heuristics … … 1367 1342 Intersectable::NewMail(); frontAndBackId = ViewCell::sMailId; 1368 1343 1369 if ( sPvsUseArea) // use front and back cell areas to approximate volume1344 if (mPvsUseArea) // use front and back cell areas to approximate volume 1370 1345 { 1371 1346 // construct child geometry with regard to the candidate split plane … … 1395 1370 ray->ClassifyPlane(candidatePlane, minT, maxT, entP, extP); 1396 1371 1397 if ( sSplitPlaneStrategy & LEAST_RAY_SPLITS)1372 if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 1398 1373 { 1399 1374 sumBalancedRays += sBalancedRaysTable[cf]; 1400 1375 } 1401 1376 1402 if ( sSplitPlaneStrategy & BALANCED_RAYS)1377 if (mSplitPlaneStrategy & BALANCED_RAYS) 1403 1378 { 1404 1379 sumRaySplits += sLeastRaySplitsTable[cf]; 1405 1380 } 1406 1381 1407 if ( sSplitPlaneStrategy & PVS)1382 if (mSplitPlaneStrategy & PVS) 1408 1383 { 1409 1384 if (!ray->intersections.empty()) … … 1423 1398 } 1424 1399 1425 if (! sPvsUseArea) // use front and back cell areas to approximate volume1400 if (!mPvsUseArea) // use front and back cell areas to approximate volume 1426 1401 { 1427 1402 float len = Distance(entP, extP); … … 1475 1450 } 1476 1451 1477 if ((sSplitPlaneStrategy & LEAST_RAY_SPLITS) && !rays.empty()) 1478 val += sLeastRaySplitsFactor * sumRaySplits / (float)rays.size(); 1479 1480 if ((sSplitPlaneStrategy & BALANCED_RAYS) && !rays.empty()) 1481 val += sBalancedRaysFactor * fabs(sumBalancedRays) / (float)rays.size(); 1482 1483 if ((sSplitPlaneStrategy & PVS) && area && pvs) 1484 { 1485 val += sPvsFactor * (frontPvs * pFront + (backPvs * pBack)) / 1486 (pOverall * (float)pvs * 2); 1452 const float raysSize = (float)rays.size() + Limits::Small; 1453 if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 1454 val += sLeastRaySplitsFactor * sumRaySplits / raysSize; 1455 1456 if (mSplitPlaneStrategy & BALANCED_RAYS) 1457 val += sBalancedRaysFactor * fabs(sumBalancedRays) / raysSize; 1458 1459 float denom = pOverall * (float)pvs * 2.0f + Limits::Small; 1460 if ((mSplitPlaneStrategy & PVS) && area && pvs) 1461 { 1462 val += sPvsFactor * (frontPvs * pFront + (backPvs * pBack)) / denom; 1487 1463 1488 1464 // give penalty to unbalanced split … … 1557 1533 float val = 0; 1558 1534 1559 if ( sSplitPlaneStrategy & VERTICAL_AXIS)1535 if (mSplitPlaneStrategy & VERTICAL_AXIS) 1560 1536 { 1561 1537 Vector3 tinyAxis(0,0,0); tinyAxis[mBox.Size().TinyAxis()] = 1.0f; … … 1567 1543 1568 1544 // the following criteria loop over all polygons to find the cost value 1569 if (( sSplitPlaneStrategy & BALANCED_POLYS) ||1570 ( sSplitPlaneStrategy & LEAST_SPLITS) ||1571 ( sSplitPlaneStrategy & LARGEST_POLY_AREA) ||1572 ( sSplitPlaneStrategy & BALANCED_VIEW_CELLS) ||1573 ( sSplitPlaneStrategy & BLOCKED_RAYS))1545 if ((mSplitPlaneStrategy & BALANCED_POLYS) || 1546 (mSplitPlaneStrategy & LEAST_SPLITS) || 1547 (mSplitPlaneStrategy & LARGEST_POLY_AREA) || 1548 (mSplitPlaneStrategy & BALANCED_VIEW_CELLS) || 1549 (mSplitPlaneStrategy & BLOCKED_RAYS)) 1574 1550 { 1575 1551 val += SplitPlaneCost(candidatePlane, *data.mPolygons); … … 1577 1553 1578 1554 // the following criteria loop over all rays to find the cost value 1579 if (( sSplitPlaneStrategy & BALANCED_RAYS) ||1580 ( sSplitPlaneStrategy & LEAST_RAY_SPLITS) ||1581 ( sSplitPlaneStrategy & PVS))1555 if ((mSplitPlaneStrategy & BALANCED_RAYS) || 1556 (mSplitPlaneStrategy & LEAST_RAY_SPLITS) || 1557 (mSplitPlaneStrategy & PVS)) 1582 1558 { 1583 1559 val += SplitPlaneCost(candidatePlane, *data.mRays, data.mPvs, … … 1592 1568 { 1593 1569 //-- parse bsp cell tree construction method 1594 char constructionMethodStr[60];1570 /*char constructionMethodStr[60]; 1595 1571 1596 1572 environment->GetStringValue("BspTree.Construction.input", constructionMethodStr); 1597 1573 1598 sConstructionMethod = FROM_INPUT_VIEW_CELLS;1574 mConstructionMethod = FROM_INPUT_VIEW_CELLS; 1599 1575 1600 1576 if (strcmp(constructionMethodStr, "fromViewCells") == 0) 1601 sConstructionMethod = FROM_INPUT_VIEW_CELLS;1577 mConstructionMethod = FROM_INPUT_VIEW_CELLS; 1602 1578 else if (strcmp(constructionMethodStr, "fromSceneGeometry") == 0) 1603 sConstructionMethod = FROM_SCENE_GEOMETRY;1579 mConstructionMethod = FROM_SCENE_GEOMETRY; 1604 1580 else if (strcmp(constructionMethodStr, "fromRays") == 0) 1605 sConstructionMethod = FROM_RAYS;1581 mConstructionMethod = FROM_RAYS; 1606 1582 else 1607 1583 { … … 1611 1587 1612 1588 Debug << "Construction method: " << constructionMethodStr << endl; 1613 1589 */ 1614 1590 //-- termination criteria for autopartition 1615 environment->GetIntValue("BspTree.Termination.maxDepth", sTermMaxDepth);1616 environment->GetIntValue("BspTree.Termination.minPvs", sTermMinPvs);1617 environment->GetIntValue("BspTree.Termination.maxPolygons", sTermMaxPolygons);1618 environment->GetIntValue("BspTree.Termination.maxRays", sTermMaxRays);1619 environment->GetFloatValue("BspTree.Termination.minArea", sTermMinArea);1620 environment->GetFloatValue("BspTree.Termination.maxRayContribution", sTermMaxRayContribution);1621 environment->GetFloatValue("BspTree.Termination.maxAccRayLenght", sTermMaxAccRayLength);1591 environment->GetIntValue("BspTree.Termination.maxDepth", mTermMaxDepth); 1592 environment->GetIntValue("BspTree.Termination.minPvs", mTermMinPvs); 1593 environment->GetIntValue("BspTree.Termination.maxPolygons", mTermMaxPolygons); 1594 environment->GetIntValue("BspTree.Termination.maxRays", mTermMaxRays); 1595 environment->GetFloatValue("BspTree.Termination.minArea", mTermMinArea); 1596 environment->GetFloatValue("BspTree.Termination.maxRayContribution", mTermMaxRayContribution); 1597 environment->GetFloatValue("BspTree.Termination.maxAccRayLenght", mTermMaxAccRayLength); 1622 1598 1623 1599 //-- termination criteria for axis aligned split 1624 environment->GetFloatValue("BspTree.Termination.AxisAligned.ct_div_ci", sCt_div_ci);1625 environment->GetFloatValue("BspTree.Termination.AxisAligned.maxCostRatio", sMaxCostRatio);1600 environment->GetFloatValue("BspTree.Termination.AxisAligned.ct_div_ci", mCt_div_ci); 1601 environment->GetFloatValue("BspTree.Termination.AxisAligned.maxCostRatio", mMaxCostRatio); 1626 1602 environment->GetIntValue("BspTree.Termination.AxisAligned.maxPolys", 1627 sTermMaxPolysForAxisAligned);1603 mTermMaxPolysForAxisAligned); 1628 1604 environment->GetIntValue("BspTree.Termination.AxisAligned.maxRays", 1629 sTermMaxRaysForAxisAligned);1605 mTermMaxRaysForAxisAligned); 1630 1606 environment->GetIntValue("BspTree.Termination.AxisAligned.maxObjects", 1631 sTermMaxObjectsForAxisAligned);1607 mTermMaxObjectsForAxisAligned); 1632 1608 //-- partition criteria 1633 environment->GetIntValue("BspTree.maxPolyCandidates", sMaxPolyCandidates);1634 environment->GetIntValue("BspTree.maxRayCandidates", sMaxRayCandidates);1635 environment->GetIntValue("BspTree.splitPlaneStrategy", sSplitPlaneStrategy);1636 environment->GetFloatValue("BspTree.AxisAligned.splitBorder", sSplitBorder);1609 environment->GetIntValue("BspTree.maxPolyCandidates", mMaxPolyCandidates); 1610 environment->GetIntValue("BspTree.maxRayCandidates", mMaxRayCandidates); 1611 environment->GetIntValue("BspTree.splitPlaneStrategy", mSplitPlaneStrategy); 1612 environment->GetFloatValue("BspTree.AxisAligned.splitBorder", mSplitBorder); 1637 1613 1638 1614 environment->GetFloatValue("BspTree.Construction.sideTolerance", Vector3::sDistTolerance); … … 1640 1616 1641 1617 // post processing stuff 1642 environment->GetIntValue("ViewCells.PostProcessing.minPvsDif", sMinPvsDif);1643 environment->GetIntValue("ViewCells.PostProcessing.minPvs", sMinPvs);1644 environment->GetIntValue("ViewCells.PostProcessing.maxPvs", sMaxPvs);1645 1646 Debug << "BSP max depth: " << sTermMaxDepth << endl;1647 Debug << "BSP min PVS: " << sTermMinPvs << endl;1648 Debug << "BSP min area: " << sTermMinArea << endl;1649 Debug << "BSP max polys: " << sTermMaxPolygons << endl;1650 Debug << "BSP max rays: " << sTermMaxRays << endl;1651 Debug << "BSP max polygon candidates: " << sMaxPolyCandidates << endl;1652 Debug << "BSP max plane candidates: " << sMaxRayCandidates << endl;1618 environment->GetIntValue("ViewCells.PostProcessing.minPvsDif", mMinPvsDif); 1619 environment->GetIntValue("ViewCells.PostProcessing.minPvs", mMinPvs); 1620 environment->GetIntValue("ViewCells.PostProcessing.maxPvs", mMaxPvs); 1621 1622 Debug << "BSP max depth: " << mTermMaxDepth << endl; 1623 Debug << "BSP min PVS: " << mTermMinPvs << endl; 1624 Debug << "BSP min area: " << mTermMinArea << endl; 1625 Debug << "BSP max polys: " << mTermMaxPolygons << endl; 1626 Debug << "BSP max rays: " << mTermMaxRays << endl; 1627 Debug << "BSP max polygon candidates: " << mMaxPolyCandidates << endl; 1628 Debug << "BSP max plane candidates: " << mMaxRayCandidates << endl; 1653 1629 1654 1630 Debug << "Split plane strategy: "; 1655 if ( sSplitPlaneStrategy & RANDOM_POLYGON)1631 if (mSplitPlaneStrategy & RANDOM_POLYGON) 1656 1632 Debug << "random polygon "; 1657 if ( sSplitPlaneStrategy & AXIS_ALIGNED)1633 if (mSplitPlaneStrategy & AXIS_ALIGNED) 1658 1634 Debug << "axis aligned "; 1659 if ( sSplitPlaneStrategy & LEAST_SPLITS)1635 if (mSplitPlaneStrategy & LEAST_SPLITS) 1660 1636 Debug << "least splits "; 1661 if ( sSplitPlaneStrategy & BALANCED_POLYS)1637 if (mSplitPlaneStrategy & BALANCED_POLYS) 1662 1638 Debug << "balanced polygons "; 1663 if ( sSplitPlaneStrategy & BALANCED_VIEW_CELLS)1639 if (mSplitPlaneStrategy & BALANCED_VIEW_CELLS) 1664 1640 Debug << "balanced view cells "; 1665 if ( sSplitPlaneStrategy & LARGEST_POLY_AREA)1641 if (mSplitPlaneStrategy & LARGEST_POLY_AREA) 1666 1642 Debug << "largest polygon area "; 1667 if ( sSplitPlaneStrategy & VERTICAL_AXIS)1643 if (mSplitPlaneStrategy & VERTICAL_AXIS) 1668 1644 Debug << "vertical axis "; 1669 if ( sSplitPlaneStrategy & BLOCKED_RAYS)1645 if (mSplitPlaneStrategy & BLOCKED_RAYS) 1670 1646 Debug << "blocked rays "; 1671 if ( sSplitPlaneStrategy & LEAST_RAY_SPLITS)1647 if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 1672 1648 Debug << "least ray splits "; 1673 if ( sSplitPlaneStrategy & BALANCED_RAYS)1649 if (mSplitPlaneStrategy & BALANCED_RAYS) 1674 1650 Debug << "balanced rays "; 1675 if ( sSplitPlaneStrategy & PVS)1651 if (mSplitPlaneStrategy & PVS) 1676 1652 Debug << "pvs"; 1677 1653 Debug << endl; … … 1719 1695 BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode); 1720 1696 1721 if (data.mDepth >= sTermMaxDepth)1697 if (data.mDepth >= mTermMaxDepth) 1722 1698 ++ mStat.maxDepthNodes; 1723 1699 … … 1734 1710 #ifdef _DEBUG 1735 1711 Debug << "BSP stats: " 1736 << "Depth: " << data.mDepth << " (max: " << sTermMaxDepth << "), "1737 << "PVS: " << data.mPvs << " (min: " << sTermMinPvs << "), "1738 << "Area: " << data.mArea << " (min: " << sTermMinArea << "), "1739 << "#polygons: " << (int)data.mPolygons->size() << " (max: " << sTermMaxPolygons << "), "1740 << "#rays: " << (int)data.mRays->size() << " (max: " << sTermMaxRays << "), "1712 << "Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), " 1713 << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 1714 << "Area: " << data.mArea << " (min: " << mTermMinArea << "), " 1715 << "#polygons: " << (int)data.mPolygons->size() << " (max: " << mTermMaxPolygons << "), " 1716 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMaxRays << "), " 1741 1717 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "=, " 1742 1718 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; … … 1795 1771 } 1796 1772 else // ray and plane are coincident 1797 // WHAT TO DO IN THIS CASE ?1798 1773 { 1799 break; 1800 //node = in->GetFront(); 1801 //continue; 1774 // WHAT TO DO IN THIS CASE ? 1775 //break; 1776 node = in->GetFront(); 1777 continue; 1802 1778 } 1803 1779 … … 1990 1966 int fdiff = fvc->GetPvs().Diff(bvc->GetPvs()); 1991 1967 1992 if (fvc->GetPvs().GetSize() + fdiff < sMaxPvs)1993 { 1994 if ((fvc->GetPvs().GetSize() < sMinPvs) ||1995 (bvc->GetPvs().GetSize() < sMinPvs) ||1996 ((fdiff < sMinPvsDif) && (bvc->GetPvs().Diff(fvc->GetPvs()) < sMinPvsDif)))1968 if (fvc->GetPvs().GetSize() + fdiff < mMaxPvs) 1969 { 1970 if ((fvc->GetPvs().GetSize() < mMinPvs) || 1971 (bvc->GetPvs().GetSize() < mMinPvs) || 1972 ((fdiff < mMinPvsDif) && (bvc->GetPvs().Diff(fvc->GetPvs()) < mMinPvsDif))) 1997 1973 { 1998 1974 return true; … … 2055 2031 { 2056 2032 case Ray::COINCIDENT: // TODO: should really discard ray? 2057 //frontRays.push_back(bRay);2058 DEL_PTR(bRay);2033 frontRays.push_back(bRay); 2034 //DEL_PTR(bRay); 2059 2035 break; 2060 2036 case Ray::BACK: -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r419 r420 316 316 */ 317 317 void AddToPvs(const BoundedRayContainer &rays, int &sampleContributions, 318 int &contributingSamples );318 int &contributingSamples, bool storeLeavesWithRays = false); 319 319 320 320 protected: … … 495 495 void EvaluateViewCellsStats(BspViewCellsStatistics &stat) const; 496 496 497 /// BSP tree construction method 498 int mConstructionMethod; 499 497 500 protected: 498 501 … … 733 736 int ComputePvsSize(const BoundedRayContainer &rays) const; 734 737 735 bool TerminationCriteriaMet(const BspTraversalData &data) const;738 inline bool TerminationCriteriaMet(const BspTraversalData &data) const; 736 739 737 740 float AccumulatedRayLength(BoundedRayContainer &rays) const; … … 766 769 bool mGenerateViewCells; 767 770 768 /// if rays should be stored that are piercing this view cell 769 bool mStorePiercingRays; 770 771 public: 772 /** Parses the environment and stores the global BSP tree parameters 773 */ 774 static void ParseEnvironment(); 771 /** Parses the environment and stores the global BSP tree parameters 772 */ 773 void ParseEnvironment(); 775 774 776 775 /// maximal number of polygons before subdivision termination 777 static int sTermMaxPolygons;776 int mTermMaxPolygons; 778 777 /// maximal number of rays before subdivision termination 779 static int sTermMaxRays;778 int mTermMaxRays; 780 779 /// maximal possible depth 781 static int sTermMaxDepth;780 int mTermMaxDepth; 782 781 /// mininum area 783 static float sTermMinArea;782 float mTermMinArea; 784 783 /// mininum PVS 785 static int sTermMinPvs;784 int mTermMinPvs; 786 785 /// strategy to get the best split plane 787 static int sSplitPlaneStrategy;786 int mSplitPlaneStrategy; 788 787 /// number of candidates evaluated for the next split plane 789 static int sMaxPolyCandidates;790 static int sMaxRayCandidates;791 /// BSP tree construction method792 static int sConstructionMethod;788 int mMaxPolyCandidates; 789 /// number of candidates for split planes evaluated using the rays 790 int mMaxRayCandidates; 791 793 792 /// maximal number of polygons for axis aligned split 794 static int sTermMaxPolysForAxisAligned;793 int mTermMaxPolysForAxisAligned; 795 794 /// maximal number of rays for axis aligned split 796 static int sTermMaxRaysForAxisAligned;795 int mTermMaxRaysForAxisAligned; 797 796 /// maximal number of objects for axis aligned split 798 static int sTermMaxObjectsForAxisAligned; 799 800 static float sTermMaxRayContribution; 801 static float sTermMaxAccRayLength; 802 803 static bool sStoreLeavesWithRays; 797 int mTermMaxObjectsForAxisAligned; 798 /// maximal contribution per ray 799 float mTermMaxRayContribution; 800 /// maximal accumulated ray length 801 float mTermMaxAccRayLength; 802 803 bool mStoreLeavesWithRays; 804 804 805 805 /// axis aligned split criteria 806 static float sCt_div_ci;807 static float sSplitBorder;808 static float sMaxCostRatio;806 float mCt_div_ci; 807 float mSplitBorder; 808 float mMaxCostRatio; 809 809 810 810 // factors guiding the split plane heuristics 811 static float sLeastSplitsFactor; 812 static float sBalancedPolysFactor; 813 static float sBalancedViewCellsFactor; 814 static float sVerticalSplitsFactor; 815 static float sLargestPolyAreaFactor; 816 static float sBlockedRaysFactor; 817 static float sLeastRaySplitsFactor; 818 static float sBalancedRaysFactor; 819 static float sPvsFactor; 820 821 //-- thresholds used for view cells are merging 822 static int sMinPvsDif; 823 static int sMinPvs; 824 static int sMaxPvs; 825 static bool sPvsUseArea; 811 float sLeastSplitsFactor; 812 float sBalancedPolysFactor; 813 float sBalancedViewCellsFactor; 814 float sVerticalSplitsFactor; 815 float sLargestPolyAreaFactor; 816 float sBlockedRaysFactor; 817 float sLeastRaySplitsFactor; 818 float sBalancedRaysFactor; 819 float sPvsFactor; 820 821 //-- thresholds used for view cells merge 822 int mMinPvsDif; 823 int mMinPvs; 824 int mMaxPvs; 825 /// if area or accumulated ray lenght should be used for PVS heuristics 826 bool mPvsUseArea; 826 827 827 828 private: -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r419 r420 24 24 #include "Intersectable.h" 25 25 #include "Ray.h" 26 #include "RayInfo.h" 26 27 27 28 // Static variables … … 34 35 float VspKdTree::sTermMaxRayContribution = 0.1f; 35 36 36 37 37 /// Adds object to the pvs of the front and back node 38 38 inline void AddObject2Pvs(Intersectable *object, 39 39 const int side, … … 71 71 72 72 /**************************************************************/ 73 /* class VspKdTreeNode implementation */ 74 /**************************************************************/ 75 76 // Inline constructor 77 VspKdTreeNode::VspKdTreeNode(VspKdTreeInterior *p): 78 mParent(p), mAxis(-1), mDepth(p ? p->mDepth + 1 : 0) 79 {} 80 81 VspKdTreeNode::~VspKdTreeNode() 82 {}; 83 84 inline VspKdTreeInterior *VspKdTreeNode::GetParent() const 85 { 86 return mParent; 87 } 88 89 inline void VspKdTreeNode::SetParent(VspKdTreeInterior *p) 90 { 91 mParent = p; 92 } 93 94 bool VspKdTreeNode::IsLeaf() const 95 { 96 return mAxis == -1; 97 } 98 99 int VspKdTreeNode::GetAccessTime() 100 { 101 return 0x7FFFFFF; 102 } 103 104 /**************************************************************/ 73 105 /* VspKdTreeInterior implementation */ 74 106 /**************************************************************/ … … 88 120 mBack = b; 89 121 mFront = f; 90 b->mParent = f->mParent = this; 122 b->SetParent(this); 123 f->SetParent(this); 91 124 } 92 125 … … 140 173 } 141 174 142 /**************************************************/ 143 /* class VspKdTree implementation */ 144 /**************************************************/ 175 176 /*********************************************************/ 177 /* class VspKdTreeLeaf implementation */ 178 /*********************************************************/ 179 VspKdTreeLeaf::VspKdTreeLeaf(VspKdTreeInterior *p, const int nRays): 180 VspKdTreeNode(p), mRays(), mPvsSize(0), mValidPvs(false) 181 { 182 mRays.reserve(nRays); 183 } 184 185 VspKdTreeLeaf::~VspKdTreeLeaf() 186 {} 187 188 int VspKdTreeLeaf::Type() const 189 { 190 return ELeaf; 191 } 192 193 void VspKdTreeLeaf::Print(ostream &s) const 194 { 195 s << endl << "L: r = " << (int)mRays.size() << endl; 196 }; 197 198 void VspKdTreeLeaf::AddRay(const RayInfo &data) 199 { 200 mValidPvs = false; 201 mRays.push_back(data); 202 data.mRay->Ref(); 203 } 204 205 int VspKdTreeLeaf::GetPvsSize() const 206 { 207 return mPvsSize; 208 } 209 210 void VspKdTreeLeaf::SetPvsSize(const int s) 211 { 212 mPvsSize = s; 213 } 214 215 void VspKdTreeLeaf::Mail() 216 { 217 mMailbox = mailID; 218 } 219 220 void VspKdTreeLeaf::NewMail() 221 { 222 ++ mailID; 223 } 224 225 bool VspKdTreeLeaf::Mailed() const 226 { 227 return mMailbox == mailID; 228 } 229 230 bool VspKdTreeLeaf::Mailed(const int mail) 231 { 232 return mMailbox >= mailID + mail; 233 } 234 235 float VspKdTreeLeaf::GetAvgRayContribution() const 236 { 237 return GetPvsSize() / ((float)mRays.size() + Limits::Small); 238 } 239 240 float VspKdTreeLeaf::GetSqrRayContribution() const 241 { 242 return sqr(GetAvgRayContribution()); 243 } 244 245 /*********************************************************/ 246 /* class VspKdTree implementation */ 247 /*********************************************************/ 248 249 145 250 void VspKdTree::ParseEnvironment() 146 251 { … … 271 376 Intersectable::NewMail(); 272 377 int pvsSize = 0; 273 for( VspKdTreeNode::RayInfoContainer::iterator ri = rays.begin();274 ri != rays.end(); ++ ri)378 for(RayInfoContainer::iterator ri = mRays.begin(); 379 ri != mRays.end(); ++ ri) 275 380 { 276 381 if ((*ri).mRay->IsActive()) … … 323 428 for (VssRayContainer::const_iterator ri = rays.begin(); ri != rays.end(); ++ ri) 324 429 { 325 leaf->AddRay( VspKdTreeNode::RayInfo(*ri));430 leaf->AddRay(RayInfo(*ri)); 326 431 327 432 mBox.Include((*ri)->GetOrigin()); … … 334 439 cout << "Bbox = " << mBox << endl; 335 440 336 mStat.rays = (int)leaf-> rays.size();441 mStat.rays = (int)leaf->mRays.size(); 337 442 leaf->UpdatePvsSize(); 338 443 … … 467 572 cout<< 468 573 "pvs="<<leaf->mPvsSize<< 469 " rays="<<leaf-> rays.size()<<574 " rays="<<leaf->mRays.size()<< 470 575 " rc="<<leaf->GetAvgRayContribution()<< 471 576 " axis="<<axis<<endl; … … 502 607 503 608 // this is the main ray classification loop! 504 for( VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin();505 ri != leaf-> rays.end(); ri++)609 for(RayInfoContainer::iterator ri = leaf->mRays.begin(); 610 ri != leaf->mRays.end(); ri++) 506 611 { 507 612 if (!(*ri).mRay->IsActive()) … … 533 638 534 639 // cout<<axis<<" "<<pvsSize<<" "<<pvsBack<<" "<<pvsFront<<endl; 535 // float oldCost = leaf-> rays.size();640 // float oldCost = leaf->mRays.size(); 536 641 float oldCost = (float)pvsSize; 537 642 … … 616 721 // C = ct_div_ci + (ql*rl + qr*rr)/queries 617 722 618 int rl =0, rr = (int)leaf->rays.size();619 int pl =0, pr = leaf->GetPvsSize();723 int rl = 0, rr = (int)leaf->mRays.size(); 724 int pl = 0, pr = leaf->GetPvsSize(); 620 725 float minBox = box.Min(axis); 621 726 float maxBox = box.Max(axis); … … 630 735 Intersectable::NewMail(); 631 736 // set all object as belonging to the fron pvs 632 for( VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin();633 ri != leaf-> rays.end(); ++ ri)737 for(RayInfoContainer::iterator ri = leaf->mRays.begin(); 738 ri != leaf->mRays.end(); ++ ri) 634 739 { 635 740 if ((*ri).mRay->IsActive()) … … 724 829 splitCandidates->clear(); 725 830 726 int requestedSize = 2 * (int)(node-> rays.size());831 int requestedSize = 2 * (int)(node->mRays.size()); 727 832 // creates a sorted split candidates array 728 833 if (splitCandidates->capacity() > 500000 && … … 736 841 737 842 // insert all queries 738 for( VspKdTreeNode::RayInfoContainer::const_iterator ri = node->rays.begin();739 ri < node-> rays.end(); ++ ri)843 for(RayInfoContainer::const_iterator ri = node->mRays.begin(); 844 ri < node->mRays.end(); ++ ri) 740 845 { 741 846 bool positive = (*ri).mRay->HasPosDir(axis); … … 759 864 ++ mStat.maxDepthNodes; 760 865 761 // if ( (int)(leaf-> rays.size()) < termMinCost)866 // if ( (int)(leaf->mRays.size()) < termMinCost) 762 867 // stat.minCostNodes++; 763 868 if (leaf->GetPvsSize() < sTermMinPvs) … … 773 878 ++ mStat.minSizeNodes; 774 879 775 // if ((int)(leaf-> rays.size()) > stat.maxRayRefs)776 // mStat.maxRayRefs = (int)leaf-> rays.size();880 // if ((int)(leaf->mRays.size()) > stat.maxRayRefs) 881 // mStat.maxRayRefs = (int)leaf->mRays.size(); 777 882 } 778 883 … … 784 889 AxisAlignedBox3 &frontBBox) 785 890 { 786 if ( (leaf->GetPvsSize() < sTermMinPvs) || (leaf-> rays.size() < sTermMinRays) ||891 if ( (leaf->GetPvsSize() < sTermMinPvs) || (leaf->mRays.size() < sTermMinRays) || 787 892 // (leaf->GetAvgRayContribution() > termMaxRayContribution ) || 788 893 (leaf->mDepth >= sTermMaxDepth) || SqrMagnitude(box.Size()) <= sTermMinSize ) … … 791 896 #if 0 792 897 if (leaf->mDepth >= termMaxDepth) { 793 cout<<"Warning: max depth reached depth="<<(int)leaf->mDepth<<" rays="<<leaf-> rays.size()<<endl;898 cout<<"Warning: max depth reached depth="<<(int)leaf->mDepth<<" rays="<<leaf->mRays.size()<<endl; 794 899 cout<<"Bbox: "<<GetBBox(leaf)<<" dirbbox:"<<GetDirBBox(leaf)<<endl; 795 900 } … … 846 951 frontBBox.SetMin(axis, position); 847 952 848 for( VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin();849 ri != leaf-> rays.end(); ri++)953 for(RayInfoContainer::iterator ri = leaf->mRays.begin(); 954 ri != leaf->mRays.end(); ++ ri) 850 955 { 851 956 if ((*ri).mRay->IsActive()) … … 861 966 if ((*ri).mRay->HasPosDir(axis)) 862 967 { 863 back->AddRay( VspKdTreeNode::RayInfo((*ri).mRay,864 865 866 front->AddRay( VspKdTreeNode::RayInfo((*ri).mRay,867 868 968 back->AddRay(RayInfo((*ri).mRay, 969 (*ri).mMinT, 970 (*ri).mRay->mT)); 971 front->AddRay(RayInfo((*ri).mRay, 972 (*ri).mRay->mT, 973 (*ri).mMaxT)); 869 974 } 870 975 else 871 976 { 872 back->AddRay( VspKdTreeNode::RayInfo((*ri).mRay,873 874 875 front->AddRay( VspKdTreeNode::RayInfo((*ri).mRay,876 877 977 back->AddRay(RayInfo((*ri).mRay, 978 (*ri).mRay->mT, 979 (*ri).mMaxT)); 980 front->AddRay(RayInfo((*ri).mRay, 981 (*ri).mMinT, 982 (*ri).mRay->mT)); 878 983 } 879 984 } … … 891 996 // rays front/back 892 997 893 for (VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin();894 ri != leaf-> rays.end(); ++ ri)998 for (RayInfoContainer::iterator ri = leaf->mRays.begin(); 999 ri != leaf->mRays.end(); ++ ri) 895 1000 { 896 1001 if ((*ri).mRay->IsActive()) … … 916 1021 917 1022 // update stats 918 mStat.rayRefs -= (int)leaf-> rays.size();1023 mStat.rayRefs -= (int)leaf->mRays.size(); 919 1024 mStat.rayRefs += raysBack + raysFront; 920 1025 921 delete leaf; 1026 DEL_PTR(leaf); 1027 922 1028 return node; 923 1029 } … … 929 1035 // find a node in the tree which subtree will be collapsed 930 1036 int maxAccessTime = time - accessTimeThreshold; 931 int released ;1037 int released = 0; 932 1038 933 1039 tstack.push(mRoot); … … 947 1053 break; 948 1054 } 949 if (in->GetBack()->GetAccessTime() < 1055 if (in->GetBack()->GetAccessTime() < in->GetFront()->GetAccessTime()) 950 1056 { 951 1057 tstack.push(in->GetFront()); … … 984 1090 985 1091 // check if we should perform a dynamic subdivision of the leaf 986 if (// leaf-> rays.size() > (unsigned)termMinCost &&1092 if (// leaf->mRays.size() > (unsigned)termMinCost && 987 1093 (leaf->GetPvsSize() >= sTermMinPvs) && 988 1094 (SqrMagnitude(leafBBox.Size()) > sizeThreshold) ) … … 1042 1148 stack<RayTraversalData> tstack; 1043 1149 1044 tstack.push(RayTraversalData(mRoot, VspKdTreeNode::RayInfo(ray)));1150 tstack.push(RayTraversalData(mRoot, RayInfo(ray))); 1045 1151 1046 1152 RayTraversalData data; … … 1056 1162 // split the set of rays in two groups intersecting the 1057 1163 // two subtrees 1058 1059 1164 TraverseInternalNode(data, tstack); 1060 1165 } … … 1074 1179 if (removeAllScheduledRays) 1075 1180 { 1076 int tail = (int)leaf-> rays.size() - 1;1077 1078 for (int i=0; i < (int)(leaf-> rays.size()); ++ i)1181 int tail = (int)leaf->mRays.size() - 1; 1182 1183 for (int i=0; i < (int)(leaf->mRays.size()); ++ i) 1079 1184 { 1080 if (leaf-> rays[i].mRay->ScheduledForRemoval())1185 if (leaf->mRays[i].mRay->ScheduledForRemoval()) 1081 1186 { 1082 1187 // find a ray to replace it with 1083 while (tail >= i && leaf-> rays[tail].mRay->ScheduledForRemoval())1188 while (tail >= i && leaf->mRays[tail].mRay->ScheduledForRemoval()) 1084 1189 { 1085 1190 ++ mStat.removedRayRefs; 1086 leaf-> rays[tail].mRay->Unref();1087 leaf-> rays.pop_back();1191 leaf->mRays[tail].mRay->Unref(); 1192 leaf->mRays.pop_back(); 1088 1193 1089 1194 -- tail; … … 1095 1200 ++ mStat.removedRayRefs; 1096 1201 1097 leaf-> rays[i].mRay->Unref();1098 leaf-> rays[i] = leaf->rays[tail];1099 leaf-> rays.pop_back();1202 leaf->mRays[i].mRay->Unref(); 1203 leaf->mRays[i] = leaf->mRays[tail]; 1204 leaf->mRays.pop_back(); 1100 1205 -- tail; 1101 1206 } … … 1105 1210 1106 1211 if (!removeAllScheduledRays) 1107 for (int i=0; i < (int)leaf-> rays.size(); i++)1212 for (int i=0; i < (int)leaf->mRays.size(); i++) 1108 1213 { 1109 if (leaf-> rays[i].mRay == ray)1214 if (leaf->mRays[i].mRay == ray) 1110 1215 { 1111 1216 ++ mStat.removedRayRefs; 1112 1217 ray->Unref(); 1113 leaf-> rays[i] = leaf->rays[leaf->rays.size() - 1];1114 leaf-> rays.pop_back();1218 leaf->mRays[i] = leaf->mRays[leaf->mRays.size() - 1]; 1219 leaf->mRays.pop_back(); 1115 1220 // check this ray again 1116 1221 break; … … 1132 1237 stack<RayTraversalData> tstack; 1133 1238 1134 tstack.push(RayTraversalData(mRoot, VspKdTreeNode::RayInfo(ray)));1239 tstack.push(RayTraversalData(mRoot, RayInfo(ray))); 1135 1240 1136 1241 RayTraversalData data; … … 1148 1253 { 1149 1254 // remove the ray from the leaf 1150 // find the ray in the leaf and swap it with the last ray ...1151 VspKdTreeLeaf *leaf = (VspKdTreeLeaf *)data.mNode;1255 // find the ray in the leaf and swap it with the last ray 1256 VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(data.mNode); 1152 1257 leaf->AddRay(data.mRayData); 1153 1258 ++ mStat.addedRayRefs; … … 1171 1276 { 1172 1277 tstack.push(RayTraversalData(in->GetBack(), 1173 VspKdTreeNode::RayInfo(data.mRayData.mRay, data.mRayData.mMinT, 1174 data.mRayData.mRay->mT))); 1278 RayInfo(data.mRayData.mRay, data.mRayData.mMinT, data.mRayData.mRay->mT))); 1175 1279 1176 1280 tstack.push(RayTraversalData(in->GetFront(), 1177 VspKdTreeNode::RayInfo(data.mRayData.mRay, data.mRayData.mRay->mT, 1178 data.mRayData.mMaxT))); 1281 RayInfo(data.mRayData.mRay, data.mRayData.mRay->mT, data.mRayData.mMaxT))); 1179 1282 1180 1283 } … … 1182 1285 { 1183 1286 tstack.push(RayTraversalData(in->GetBack(), 1184 VspKdTreeNode::RayInfo(data.mRayData.mRay,1185 1186 1287 RayInfo(data.mRayData.mRay, 1288 data.mRayData.mRay->mT, 1289 data.mRayData.mMaxT))); 1187 1290 tstack.push(RayTraversalData(in->GetFront(), 1188 VspKdTreeNode::RayInfo(data.mRayData.mRay,1189 1190 1291 RayInfo(data.mRayData.mRay, 1292 data.mRayData.mMinT, 1293 data.mRayData.mRay->mT))); 1191 1294 } 1192 1295 } … … 1219 1322 1220 1323 #if DEBUG_COLLAPSE 1221 cout <<"Collapsing subtree"<<endl;1222 cout <<"acessTime="<<sroot->GetAccessTime()<<endl;1223 cout <<"depth="<<(int)sroot->depth<<endl;1324 cout << "Collapsing subtree" << endl; 1325 cout << "acessTime=" << sroot->GetAccessTime() << endl; 1326 cout << "depth=" << (int)sroot->depth << endl; 1224 1327 #endif 1225 1328 … … 1240 1343 VspKdTreeLeaf *leaf = (VspKdTreeLeaf *) node; 1241 1344 1242 for( VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin();1243 ri != leaf-> rays.end(); ++ ri)1345 for(RayInfoContainer::iterator ri = leaf->mRays.begin(); 1346 ri != leaf->mRays.end(); ++ ri) 1244 1347 { 1245 1348 ++ totalRayCount; … … 1278 1381 VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(node); 1279 1382 1280 for( VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin();1281 ri != leaf-> rays.end(); ++ ri)1383 for(RayInfoContainer::iterator ri = leaf->mRays.begin(); 1384 ri != leaf->mRays.end(); ++ ri) 1282 1385 { 1283 1386 // unref this ray from the old node … … 1305 1408 1306 1409 // delete the node and all its children 1307 delete sroot;1308 1309 // for(VspKdTreeNode::SRayContainer::iterator ri = new Leaf->rays.begin();1310 // ri != new Leaf->rays.end(); ++ ri)1410 DEL_PTR(sroot); 1411 1412 // for(VspKdTreeNode::SRayContainer::iterator ri = newleaf->mRays.begin(); 1413 // ri != newleaf->mRays.end(); ++ ri) 1311 1414 // (*ri).ray->UnMail(2); 1312 1415 … … 1347 1450 { 1348 1451 VspKdTreeLeaf *leaf = (VspKdTreeLeaf *)node; 1349 for ( VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin();1350 ri != leaf->rays.end(); ++ ri)1452 for (RayInfoContainer::iterator ri = leaf->mRays.begin(); 1453 ri != leaf->mRays.end(); ++ ri) 1351 1454 { 1352 1455 if ((*ri).mRay->IsActive()) … … 1548 1651 return mStat; 1549 1652 } 1653 1654 void VspKdTree::AddRays(VssRayContainer &add) 1655 { 1656 VssRayContainer remove; 1657 UpdateRays(remove, add); 1658 } 1659 1660 // return memory usage in MB 1661 float VspKdTree::GetMemUsage() const 1662 { 1663 return 1664 (sizeof(VspKdTree) + 1665 mStat.Leaves() * sizeof(VspKdTreeLeaf) + 1666 mStat.Interior() * sizeof(VspKdTreeInterior) + 1667 mStat.rayRefs * sizeof(RayInfo)) / (1024.0f * 1024.0f); 1668 } 1669 1670 float VspKdTree::GetRayMemUsage() const 1671 { 1672 return mStat.rays * (sizeof(VssRay))/(1024.0f * 1024.0f); 1673 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
r419 r420 31 31 #include "Ray.h" 32 32 33 // -------------------------------------------------------------- 34 // Static statistics for kd-tree search 35 // -------------------------------------------------------------- 33 #include "RayInfo.h" 34 35 36 /** 37 Static statistics for vsp kd-tree search 38 */ 36 39 class VspKdStatistics: public StatisticsBase 37 40 { 38 41 public: 39 40 41 42 43 44 42 // total number of nodes 43 int nodes; 44 // number of splits along each of the axes 45 int splits[7]; 46 // totals number of rays 47 int rays; 45 48 // initial size of the pvs 46 49 int initialPvsSize; 47 50 // total number of query domains 48 49 50 51 int queryDomains; 52 // total number of ray references 53 int rayRefs; 51 54 52 55 // max depth nodes 53 54 55 56 56 int maxDepthNodes; 57 // max depth nodes 58 int minPvsNodes; 59 int minRaysNodes; 57 60 // max ray contribution nodes 58 61 int maxRayContribNodes; 59 62 // max depth nodes 60 int minSizeNodes; 61 62 // max number of rays per node 63 int maxRayRefs; 64 // number of dynamically added ray refs 65 int addedRayRefs; 66 // number of dynamically removed ray refs 67 int removedRayRefs; 68 69 // Constructor 70 VspKdStatistics() 71 { 72 Reset(); 73 } 74 75 int Nodes() const {return nodes;} 76 int Interior() const { return nodes/2; } 77 int Leaves() const { return (nodes/2) + 1; } 78 79 void Reset() 80 { 81 nodes = 0; 82 for (int i=0; i<7; i++) 83 splits[i] = 0; 84 rays = queryDomains = 0; 85 rayRefs = 0; 86 maxDepthNodes = 0; 87 minPvsNodes = 0; 88 minRaysNodes = 0; 89 maxRayRefs = 0; 90 addedRayRefs = removedRayRefs = 0; 91 initialPvsSize = 0; 92 maxRayContribNodes = 0; 93 minSizeNodes = 0; 94 } 95 96 void 97 Print(ostream &app) const; 98 99 friend ostream &operator<<(ostream &s, const VspKdStatistics &stat) { 100 stat.Print(s); 101 return s; 102 } 103 63 int minSizeNodes; 64 65 // max number of rays per node 66 int maxRayRefs; 67 // number of dynamically added ray refs 68 int addedRayRefs; 69 // number of dynamically removed ray refs 70 int removedRayRefs; 71 72 /** Default constructor. 73 */ 74 VspKdStatistics() { Reset(); } 75 int Nodes() const { return nodes; } 76 int Interior() const { return nodes / 2; } 77 int Leaves() const { return (nodes / 2) + 1; } 78 79 void Reset() 80 { 81 nodes = 0; 82 83 for (int i=0; i<7; i++) 84 splits[i] = 0; 85 86 rays = queryDomains = 0; 87 rayRefs = 0; 88 maxDepthNodes = 0; 89 minPvsNodes = 0; 90 minRaysNodes = 0; 91 maxRayRefs = 0; 92 addedRayRefs = removedRayRefs = 0; 93 initialPvsSize = 0; 94 maxRayContribNodes = 0; 95 minSizeNodes = 0; 96 } 97 98 void Print(ostream &app) const; 99 friend ostream &operator<<(ostream &s, const VspKdStatistics &stat) 100 { 101 stat.Print(s); 102 return s; 103 } 104 104 }; 105 105 … … 108 108 109 109 110 // -------------------------------------------------------------- 111 // KD-tree node - abstract class 112 // -------------------------------------------------------------- 110 /** Abstract superclass of Vsp-Kd-Tree nodes. 111 */ 113 112 class VspKdTreeNode 114 113 { … … 118 117 #define USE_FIXEDPOINT_T 1 119 118 120 struct RayInfo 121 { 122 // pointer to the actual ray 123 VssRay *mRay; 124 125 // endpoints - do we need them? 126 #if USE_FIXEDPOINT_T 127 short mMinT, mMaxT; 128 #else 129 float mMinT, mMaxT; 130 #endif 131 132 RayInfo():mRay(NULL) {} 133 134 RayInfo(VssRay *r):mRay(r), mMinT(0), 135 #if USE_FIXEDPOINT_T 136 #define FIXEDPOINT_ONE 0x7FFE 137 // mMaxT(0xFFFF) 138 mMaxT(FIXEDPOINT_ONE) 139 #else 140 mMaxT(1.0f) 141 #endif 142 {} 143 144 RayInfo(VssRay *r, 145 const float _min, 146 const float _max 147 ):mRay(r) 148 { 149 SetMinT(_min); 150 SetMaxT(_max); 151 } 152 153 RayInfo(VssRay *r, 154 const short _min, 155 const float _max):mRay(r), mMinT(_min) 156 { 157 SetMaxT(_max); 158 } 159 160 RayInfo(VssRay *r, 161 const float _min, 162 const short _max): 163 mRay(r), mMaxT(_max) 164 { 165 SetMinT(_min); 166 } 167 168 friend bool operator<(const RayInfo &a, const RayInfo &b) { 169 return a.mRay < b.mRay; 170 } 171 172 173 float ExtrapOrigin(const int axis) const { 174 return mRay->GetOrigin(axis) + GetMinT()*mRay->GetDir(axis); 175 } 176 177 float ExtrapTermination(const int axis) const { 178 return mRay->GetOrigin(axis) + GetMaxT()*mRay->GetDir(axis); 179 } 180 181 #if USE_FIXEDPOINT_T 182 float GetMinT () const { return mMinT/(float)(FIXEDPOINT_ONE); } 183 float GetMaxT () const { return mMaxT/(float)(FIXEDPOINT_ONE); } 184 185 void SetMinT (const float t) { 186 mMinT = (short) (t*(float)(FIXEDPOINT_ONE)); 187 } 188 189 void SetMaxT (const float t) { 190 mMaxT = (short) (t*(float)(FIXEDPOINT_ONE)); 191 mMaxT++; 192 // if (mMaxT!=0xFFFF) 193 // mMaxT++; 194 } 195 #else 196 float GetMinT () const { return mMinT; } 197 float GetMaxT () const { return mMaxT; } 198 199 void SetMinT (const float t) { mMinT = t; } 200 void SetMaxT (const float t) { mMaxT = t; } 201 #endif 202 203 204 int ComputeRayIntersection(const int axis, const float position, float &t) const 205 { 206 // intersect the ray with the plane 207 float denom = mRay->GetDir(axis); 208 209 if (fabs(denom) < 1e-20) 210 //if (denom == 0.0f) 211 return (mRay->GetOrigin(axis) > position) ? 1 : -1; 212 213 t = (position - mRay->GetOrigin(axis))/denom; 214 215 if (t < GetMinT()) 216 return (denom > 0) ? 1 : -1; 217 218 if (t > GetMaxT()) 219 return (denom > 0) ? -1 : 1; 220 221 return 0; 222 } 223 224 225 }; 226 227 228 typedef vector<RayInfo> RayInfoContainer; 229 230 enum {EInterior, ELeaf}; 231 232 ///////////////////////////////// 233 // The actual data goes here 234 235 // link to the parent 236 VspKdTreeInterior *mParent; 237 238 enum {SPLIT_X=0, SPLIT_Y, SPLIT_Z, SPLIT_DIRX, SPLIT_DIRY, SPLIT_DIRZ}; 239 240 // splitting axis 241 char mAxis; 242 243 // depth 244 unsigned char mDepth; 245 246 // short depth; 247 // 248 ///////////////////////////////// 249 250 inline VspKdTreeNode(VspKdTreeInterior *p); 251 252 253 virtual ~VspKdTreeNode() {}; 254 virtual int Type() const = 0; 255 256 257 bool IsLeaf() const { return mAxis == -1; } 258 259 virtual void Print(ostream &s) const = 0; 260 261 virtual int GetAccessTime() 262 { 263 return 0x7FFFFFF; 264 } 265 266 267 119 enum {EInterior, ELeaf}; 120 121 /** Constructs new interior node from the parent node. 122 */ 123 inline VspKdTreeNode(VspKdTreeInterior *p); 124 125 /** Destroys this node and the subtree. 126 */ 127 virtual ~VspKdTreeNode(); 128 129 /** Type of the node (Einterior or ELeaf) 130 */ 131 virtual int Type() const = 0; 132 133 /** Returns true if this node is a leaf. 134 */ 135 bool IsLeaf() const; 136 137 /** Prints node stats. 138 */ 139 virtual void Print(ostream &s) const = 0; 140 141 /** Returns time needed to access this node. 142 */ 143 virtual int GetAccessTime(); // NOTE: don't really know how it is used! 144 145 /** Returns parent node. 146 */ 147 VspKdTreeInterior *GetParent() const; 148 /** Sets parent node. 149 */ 150 void SetParent(VspKdTreeInterior *p); 151 152 protected: 153 ///////////////////////////////// 154 // The actual data goes here 155 156 /// link to the parent 157 VspKdTreeInterior *mParent; 158 159 enum {SPLIT_X = 0, SPLIT_Y, SPLIT_Z, SPLIT_DIRX, SPLIT_DIRY, SPLIT_DIRZ}; 160 161 /// splitting axis 162 char mAxis; 163 164 /// depth 165 unsigned char mDepth; 268 166 }; 269 167 … … 276 174 friend class VspKdTree; 277 175 176 /** Constructs new interior node from parent node. 177 */ 278 178 VspKdTreeInterior(VspKdTreeInterior *p); 279 179 … … 286 186 virtual void Print(ostream &s) const; 287 187 188 /** Returns back child. 189 */ 288 190 inline VspKdTreeNode *GetBack() const; 191 /** Returns front child. 192 */ 289 193 inline VspKdTreeNode *GetFront() const; 290 194 291 195 protected: 292 196 197 /** Sets pointers to back child and front child. 198 */ 293 199 void SetupChildLinks(VspKdTreeNode *b, VspKdTreeNode *f); 294 200 201 /** Replaces the pointer to oldChild with a pointer to newChild. 202 */ 295 203 void ReplaceChildLink(VspKdTreeNode *oldChild, VspKdTreeNode *newChild); 296 204 205 /** Computes intersection of the ray with the node boundaries. 206 */ 297 207 int ComputeRayIntersection(const RayInfo &rayData, float &t); 298 208 … … 321 231 friend class VspKdTree; 322 232 233 /** Constructs leaf from parent node. 234 @param p the parent node 235 @param nRays preallocates memory to store this number of rays 236 */ 237 VspKdTreeLeaf(VspKdTreeInterior *p, const int nRays); 238 239 virtual ~VspKdTreeLeaf(); 240 241 virtual int Type() const; 242 243 virtual void Print(ostream &s) const; 244 245 /** Adds a ray to the leaf ray container. 246 */ 247 void AddRay(const RayInfo &data); 248 /** Returns size of the leaf PVS as induced by the rays 249 @note returns precomputed PVS size, which may not be valid 250 anymore. Run UpdatePvsSize to get a valid PVS. 251 */ 252 int GetPvsSize() const; 253 void SetPvsSize(const int s); 254 255 /** If PVS is not valid, this function recomputes the leaf 256 PVS as induced by the rays. 257 */ 258 void UpdatePvsSize(); 259 260 void Mail(); 261 262 bool Mailed() const; 263 264 bool Mailed(const int mail); 265 266 /** Returns average contribution of a ray to the PVS 267 */ 268 inline float GetAvgRayContribution() const; 269 /** Returns square of average contribution of a ray. 270 */ 271 inline float GetSqrRayContribution() const; 272 273 static void NewMail(); 274 323 275 static int mailID; 324 int mailbox; 325 326 RayInfoContainer rays; 276 277 protected: 278 279 int mMailbox; 280 281 RayInfoContainer mRays; 327 282 bool mValidPvs; 328 283 329 VspKdTreeLeaf(VspKdTreeInterior *p, const int nRays):330 VspKdTreeNode(p), rays(), mPvsSize(0), mValidPvs(false)331 {332 rays.reserve(nRays);333 }334 335 virtual ~VspKdTreeLeaf() { }336 337 virtual int Type() const338 {339 return ELeaf;340 }341 342 virtual void Print(ostream &s) const343 {344 s << endl << "L: r = " << (int)rays.size() << endl;345 };346 347 void AddRay(const RayInfo &data)348 {349 mValidPvs = false;350 rays.push_back(data);351 data.mRay->Ref();352 }353 354 int GetPvsSize() const355 {356 return mPvsSize;357 }358 void SetPvsSize(const int s)359 {360 mPvsSize = s;361 }362 363 void UpdatePvsSize();364 365 void Mail()366 {367 mailbox = mailID;368 }369 370 static void NewMail()371 {372 ++ mailID;373 }374 375 bool Mailed() const376 {377 return mailbox == mailID;378 }379 380 bool Mailed(const int mail)381 {382 return mailbox >= mailID + mail;383 }384 385 float GetAvgRayContribution() const386 {387 return GetPvsSize()/((float)rays.size() + Limits::Small);388 }389 390 float GetSqrRayContribution() const391 {392 return sqr(GetPvsSize()/((float)rays.size() + Limits::Small));393 }394 284 private: 395 285 int mPvsSize; 396 286 }; 397 398 // Inline functions399 inline VspKdTreeNode::VspKdTreeNode(VspKdTreeInterior *p):400 mParent(p), mAxis(-1), mDepth(p ? p->mDepth + 1 : 0)401 {}402 287 403 288 … … 501 386 }; 502 387 503 / / simplified data for ray traversal only...504 388 /** Simplified data for ray traversal only. 389 */ 505 390 struct RayTraversalData 506 391 { 507 VspKdTreeNode::RayInfo mRayData;392 RayInfo mRayData; 508 393 VspKdTreeNode *mNode; 509 394 510 395 RayTraversalData() {} 511 396 512 RayTraversalData(VspKdTreeNode *n, const VspKdTreeNode::RayInfo &data):397 RayTraversalData(VspKdTreeNode *n, const RayInfo &data): 513 398 mRayData(data), mNode(n) {} 514 399 }; … … 521 406 virtual void Construct(VssRayContainer &rays, 522 407 AxisAlignedBox3 *forcedBoundingBox = NULL); 523 524 // incemental construction 408 409 /** Returns bounding box of the specified node. 410 */ 411 AxisAlignedBox3 GetBBox(VspKdTreeNode *node) const; 412 413 const VspKdStatistics &GetStatistics() const; 414 415 /** Get the root of the tree. 416 */ 417 VspKdTreeNode *GetRoot() const; 418 419 /** Returns average PVS size in tree. 420 */ 421 float GetAvgPvsSize(); 422 423 /** Parses the environment and stores the global VspKd tree parameters 424 */ 425 static void ParseEnvironment(); 426 427 ///////////////////////////// 428 // Construction parameters 429 430 /// max depth of the tree 431 static int sTermMaxDepth; 432 433 /// minimal ratio of the volume of the cell and the query volume 434 static float sTermMinSize; 435 436 /// minimal pvs per node to still get subdivided 437 static int sTermMinPvs; 438 439 /// minimal ray number per node to still get subdivided 440 static int sTermMinRays; 441 442 /// maximal cost ration to subdivide a node 443 static float sTermMaxCostRatio; 444 445 /// maximal contribution per ray to subdivide the node 446 static float sTermMaxRayContribution; 447 448 /** Returns memory usage in MB. 449 */ 450 float GetMemUsage() const; 451 452 float GetRayMemUsage() const; 453 454 protected: 455 // incremental construction 525 456 virtual void UpdateRays(VssRayContainer &remove, VssRayContainer &add); 526 457 527 virtual void AddRays(VssRayContainer &add) 528 { 529 VssRayContainer remove; 530 UpdateRays(remove, add); 531 } 458 virtual void AddRays(VssRayContainer &add); 532 459 533 460 VspKdTreeNode *Locate(const Vector3 &v); … … 549 476 550 477 void SortSplitCandidates(VspKdTreeLeaf *node, 551 const int axis); 552 553 554 // return memory usage in MB 555 float GetMemUsage() const 556 { 557 return 558 (sizeof(VspKdTree) + 559 mStat.Leaves() * sizeof(VspKdTreeLeaf) + 560 mStat.Interior() * sizeof(VspKdTreeInterior) + 561 mStat.rayRefs * sizeof(VspKdTreeNode::RayInfo)) / (1024.0f*1024.0f); 562 } 563 564 float GetRayMemUsage() const 565 { 566 return mStat.rays * (sizeof(VssRay))/(1024.0f * 1024.0f); 567 } 478 const int axis); 568 479 569 480 float BestCostRatioHeuristic(VspKdTreeLeaf *node, … … 591 502 int &pvsFront); 592 503 593 AxisAlignedBox3 GetBBox(VspKdTreeNode *node) const;594 504 595 505 VspKdTreeNode * SubdivideLeaf(VspKdTreeLeaf *leaf, … … 619 529 SimpleRayContainer &rays); 620 530 621 float GetAvgPvsSize();622 623 /** Get the root of the tree.624 */625 VspKdTreeNode *GetRoot() const;626 627 531 int CollapseSubtree(VspKdTreeNode *sroot, const int time); 628 629 const VspKdStatistics &GetStatistics() const;630 532 631 533 int ReleaseMemory(const int time); 632 633 /** Parses the environment and stores the global BSP tree parameters634 */635 static void ParseEnvironment();636 637 /////////////////////////////638 // Construction parameters639 640 // max depth of the tree641 static int sTermMaxDepth;642 643 // minimal ratio of the volume of the cell and the query volume644 static float sTermMinSize;645 646 // minimal pvs per node to still get subdivided647 static int sTermMinPvs;648 649 // minimal ray number per node to still get subdivided650 static int sTermMinRays;651 652 // maximal cost ration to subdivide a node653 static float sTermMaxCostRatio;654 655 // maximal contribution per ray to subdivide the node656 static float sTermMaxRayContribution;657 534 658 535 protected: -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r419 r420 23 23 environment->Parse(argc, argv, USE_EXE_PATH); 24 24 MeshKdTree::ParseEnvironment(); 25 BspTree::ParseEnvironment();25 26 26 VspKdTree::ParseEnvironment(); 27 27 … … 63 63 // a certain number of rays collected 64 64 if (ViewCell::sHierarchy == ViewCell::BSP && 65 !(BspTree:: sConstructionMethod == BspTree::FROM_RAYS))65 !(BspTree::mConstructionMethod == BspTree::FROM_RAYS)) 66 66 { 67 if (BspTree:: sConstructionMethod == BspTree::FROM_INPUT_VIEW_CELLS)67 if (BspTree::mConstructionMethod == BspTree::FROM_INPUT_VIEW_CELLS) 68 68 { 69 69 // view cells input file name
Note: See TracChangeset
for help on using the changeset viewer.