Changeset 1698 for GTP/trunk/Lib/Vis
- Timestamp:
- 10/30/06 12:09:35 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1696 r1698 240 240 bool randomize = false; 241 241 Environment::GetSingleton()->GetBoolValue("VspTree.Construction.randomize", randomize); 242 243 // initialise random generator for heuristics 242 244 if (randomize) 243 Randomize(); // initialise random generator for heuristics 244 245 246 //////////////////////////////////// 245 Randomize(); 246 247 ////////////////////////////// 247 248 //-- termination criteria for autopartition 248 249 … … 251 252 Environment::GetSingleton()->GetIntValue("BvHierarchy.Termination.minObjects", mTermMinObjects); 252 253 Environment::GetSingleton()->GetIntValue("BvHierarchy.Termination.minRays", mTermMinRays); 253 Environment::GetSingleton()->GetFloatValue( "BvHierarchy.Termination.minProbability", mTermMinProbability);254 255 254 Environment::GetSingleton()->GetFloatValue( 255 "BvHierarchy.Termination.minProbability", mTermMinProbability); 256 Environment::GetSingleton()->GetIntValue("BvHierarchy.Termination.missTolerance", mTermMissTolerance); 256 257 257 258 … … 282 283 "BvHierarchy.Construction.renderCostDecreaseWeight", mRenderCostDecreaseWeight); 283 284 284 Environment::GetSingleton()->GetBoolValue("BvHierarchy.Construction.useGlobalSorting", mUseGlobalSorting); 285 Environment::GetSingleton()->GetBoolValue( 286 "BvHierarchy.Construction.useGlobalSorting", mUseGlobalSorting); 287 285 288 Environment::GetSingleton()->GetIntValue("BvHierarchy.minRaysForVisibility", mMinRaysForVisibility); 286 289 287 288 290 mUseBboxAreaForSah = true; 291 289 292 290 293 ///////////// … … 516 519 if (computeSplitPlane) 517 520 { 518 const bool sufficientSamples = splitCandidate.mParentData.mNumRays > mMinRaysForVisibility; 521 const bool sufficientSamples = 522 splitCandidate.mParentData.mNumRays > mMinRaysForVisibility; 519 523 520 524 const bool useVisibiliyBasedHeuristics = 521 525 !mUseSah && 522 (mHierarchyManager->GetViewSpaceSubdivisionType() == HierarchyManager::KD_BASED_VIEWSPACE_SUBDIV) && 526 (mHierarchyManager->GetViewSpaceSubdivisionType() == 527 HierarchyManager::KD_BASED_VIEWSPACE_SUBDIV) && 523 528 sufficientSamples; 524 529 … … 531 536 // cost ratio violated? 532 537 const bool maxCostRatioViolated = mTermMaxCostRatio < ratio; 533 534 538 const int previousMisses = splitCandidate.mParentData.mMaxCostMisses; 535 539 … … 674 678 // objects related stuff 675 679 676 // note: th is number should always accumulate to the total number of objects680 // note: the sum should alwaysbe total number of objects for bvh 677 681 mBvhStats.objectRefs += (int)leaf->mObjects.size(); 678 682 … … 813 817 // go through the lists, count the number of objects left and right 814 818 // and evaluate the following cost funcion: 815 // C = ct_div_ci + (ol + or) /queries819 // C = ct_div_ci + (ol + or) / queries 816 820 PrepareLocalSubdivisionCandidates(tData, axis); 817 821 818 int objectsLeft = 0, objectsRight = (int)tData.mNode->mObjects.size(); 822 const float totalRenderCost = EvalAbsCost(tData.mNode->mObjects); 823 float objectsLeft = 0, objectsRight = totalRenderCost; 819 824 820 825 const AxisAlignedBox3 nodeBbox = tData.mNode->GetBoundingBox(); … … 872 877 Intersectable *obj = (*cit).mObject; 873 878 874 ++ objectsLeft; 875 -- objectsRight; 879 const float renderCost = mViewCellsManager->EvalRenderCost(obj); 880 //const int renderCost = 1; 881 882 objectsLeft += renderCost; 883 objectsRight -= renderCost; 876 884 877 885 const AxisAlignedBox3 obox = obj->GetBox(); … … 919 927 areaLeft = al; 920 928 areaRight = ar; 929 921 930 // objects belong to left side now 922 931 for (; currentPos != (cit + 1); ++ currentPos); … … 936 945 objectsFront.push_back((*cit).mObject); 937 946 938 float oldCost = (float)tData.mNode->mObjects.size();939 947 float newCost = minSum / boxArea; 940 float ratio = newCost / oldCost;948 float ratio = newCost / totalRenderCost; 941 949 942 950 #ifdef _DEBUG … … 1001 1009 ObjectContainer &objectsBack) 1002 1010 { 1003 /////////////////////////////////////////////////////// /////////1004 // go through the lists, count the number of objects left and right1005 // and evaluate the cost funcion1011 /////////////////////////////////////////////////////// 1012 // -- go through the lists, count the number of objects left 1013 //-- and right and evaluate the cost funcion 1006 1014 1007 1015 // prepare the heuristics by setting mailboxes and counters. … … 1011 1019 float volLeft = 0; 1012 1020 float volRight = totalVol; 1013 int nObjectsLeft = 0; 1014 const int nTotalObjects = (int)tData.mNode->mObjects.size(); 1021 1022 const float nTotalObjects = EvalAbsCost(tData.mNode->mObjects); 1023 float nObjectsLeft = 0; 1024 float nObjectsRight = nTotalObjects; 1025 1015 1026 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 1016 1027 … … 1038 1049 //-- traverse through events and find best split plane 1039 1050 1040 SortableEntryContainer::const_iterator cit, cit_end = cit_end = mSubdivisionCandidates->end(); 1051 SortableEntryContainer::const_iterator cit, 1052 cit_end = cit_end = mSubdivisionCandidates->end(); 1041 1053 1042 1054 for (cit = mSubdivisionCandidates->begin(); cit != cit_end; ++ cit) … … 1049 1061 EvalHeuristicsContribution(object, volLeft, volRight); 1050 1062 1051 ++ nObjectsLeft; 1052 const int nObjectsRight = nTotalObjects - nObjectsLeft; 1053 1063 const float rc = mViewCellsManager->EvalRenderCost(object); 1064 1065 nObjectsLeft += rc; 1066 nObjectsRight -= rc; 1067 1054 1068 // the heuristics 1055 1069 const float sum = volLeft * (float)nObjectsLeft + … … 1405 1419 1406 1420 1421 float BvHierarchy::EvalAbsCost(const ObjectContainer &objects) const 1422 { 1423 #if USE_BETTER_RENDERCOST_EST 1424 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1425 1426 for (oit = objects.begin(); oit != oit_end; ++ oit) 1427 { 1428 objRenderCost += mViewCellsManager->GetRendercost(*oit); 1429 } 1430 #else 1431 return (float)objects.size(); 1432 #endif 1433 } 1434 1435 1407 1436 float BvHierarchy::EvalRenderCost(const ObjectContainer &objects) const 1408 1437 { 1409 if (0 && 1410 (mHierarchyManager->GetViewSpaceSubdivisionType() == 1411 HierarchyManager::NO_VIEWSPACE_SUBDIV)) 1412 { 1413 //////////////// 1414 //-- surface area heuristics 1415 1416 if (objects.empty()) 1417 return 0.0f; 1418 1419 const AxisAlignedBox3 box = EvalBoundingBox(objects); 1420 const float area = box.SurfaceArea(); 1421 const float viewSpaceArea = mViewCellsManager->GetViewSpaceBox().SurfaceArea(); 1422 1423 return (float)objects.size() * area / viewSpaceArea; 1424 } 1425 else 1426 { /////////////// 1427 //-- render cost heuristics 1428 1429 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 1430 1431 // probability that view point lies in a view cell which sees this node 1432 const float p = EvalViewCellsVolume(objects) / viewSpaceVol; 1433 1434 return (float)objects.size() * p; 1435 } 1438 /////////////// 1439 //-- render cost heuristics 1440 1441 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 1442 1443 // probability that view point lies in a view cell which sees this node 1444 const float p = EvalViewCellsVolume(objects) / viewSpaceVol; 1445 float objRenderCost = EvalAbsCost(objects); 1446 1447 return objRenderCost * p; 1436 1448 } 1437 1449 … … 1590 1602 int BvHierarchy::CountViewCells(const ObjectContainer &objects) const 1591 1603 { 1592 // no view cells yet1593 if (0 && mHierarchyManager->GetViewSpaceSubdivisionType() ==1594 HierarchyManager::NO_VIEWSPACE_SUBDIV)1595 return 1;1596 1597 1604 int nViewCells = 0; 1598 1599 1605 ViewCell::NewMail(); 1600 1601 1606 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1602 1607 … … 1728 1733 { 1729 1734 // search nodes 1730 std::map<BvhNode *, BvhIntersectable *>::const_iterator it1731 = mBvhIntersectables.find(node);1735 std::map<BvhNode *, BvhIntersectable *>::const_iterator 1736 it = mBvhIntersectables.find(node); 1732 1737 1733 1738 if (it != mBvhIntersectables.end()) … … 1816 1821 void BvHierarchy::Initialise(const ObjectContainer &objects) 1817 1822 { 1823 AxisAlignedBox3 box = EvalBoundingBox(objects); 1824 1818 1825 /////// 1819 1826 //-- create new root 1820 1827 1821 AxisAlignedBox3 box = EvalBoundingBox(objects);1822 1828 BvhLeaf *bvhleaf = new BvhLeaf(box, NULL, (int)objects.size()); 1823 1829 bvhleaf->mObjects = objects; … … 1834 1840 /* 1835 1841 Mesh *BvHierarchy::MergeLeafToMesh() 1836 void BvHierarchy::MergeLeavesToMeshes()1837 1842 { 1838 1843 vector<BvhLeaf *> leaves; … … 1903 1908 bvhLeaf->SetSubdivisionCandidate(oSubdivisionCandidate); 1904 1909 1905 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 1906 mTotalCost = (float)objects.size() * prop / viewSpaceVol; 1910 mTotalCost = EvalRenderCost(objects); 1907 1911 mPvsEntries = CountViewCells(objects); 1908 1912 -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1695 r1698 609 609 ///////////////////////////////// 610 610 611 float EvalAbsCost(const ObjectContainer &objects) const; 612 611 613 protected: 612 614 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1696 r1698 1638 1638 if (!obj) return; 1639 1639 1640 //const float renderCost = mViewCellsManager->SimpleRay &raynderCost(obj); 1641 const int renderCost = 1; 1640 const float renderCost = mViewCellsManager->EvalRenderCost(obj); 1642 1641 1643 1642 // object in no pvs => new … … 1650 1649 // the object belongs to no pvs in this case? 1651 1650 //if (cf == Ray::COINCIDENT) return; 1652 1653 1651 if (cf >= 0) // front pvs 1654 1652 { … … 1689 1687 { 1690 1688 if (!leaf) return; 1691 const int renderCost = countEntries ? 1 : (int)leaf->mObjects.size(); 1689 1690 const float renderCost = countEntries ? 1 : 1691 mHierarchyManager->mBvHierarchy->EvalAbsCost(leaf->mObjects); 1692 1692 1693 1693 // leaf in no pvs => new … … 1727 1727 } 1728 1728 } 1729 1730 1729 1731 1730 … … 1801 1800 // test if this leaf is in valid view space 1802 1801 VspLeaf *leaf = dynamic_cast<VspLeaf *>(node); 1802 1803 1803 if (leaf->TreeValid() && 1804 1804 (!onlyUnmailed || !leaf->Mailed()) &&
Note: See TracChangeset
for help on using the changeset viewer.