Changeset 1379 for GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
- Timestamp:
- 09/15/06 17:33:22 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1370 r1379 290 290 BvhTraversalData &backData) 291 291 { 292 mBvhStats.nodes += 2; // we have two new leaves293 294 292 const BvhTraversalData &tData = sc.mParentData; 295 293 BvhLeaf *leaf = tData.mNode; 296 294 AxisAlignedBox3 parentBox = leaf->GetBoundingBox(); 295 296 // update stats 297 mBvhStats.nodes += 2; // we have two new leaves 298 299 if (tData.mDepth > mBvhStats.maxDepth) 300 { 301 mBvhStats.maxDepth = tData.mDepth; 302 } 297 303 298 304 // add the new nodes to the tree … … 471 477 splitCandidate.mParentData.mMaxCostMisses; 472 478 473 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume();474 479 const float oldProp = EvalViewCellsVolume(leaf->mObjects); 475 476 const float oldRenderCost = oldProp * (float)leaf->mObjects.size() / viewSpaceVol; 477 480 const float oldRenderCost = EvalRenderCost(leaf->mObjects); 481 478 482 // compute global decrease in render cost 479 float newRenderCost = EvalRenderCost(splitCandidate.mParentData, 480 splitCandidate.mFrontObjects, 481 splitCandidate.mBackObjects); 482 483 newRenderCost /= viewSpaceVol; 483 const float newRenderCost = 484 EvalRenderCost(splitCandidate.mFrontObjects) + 485 EvalRenderCost(splitCandidate.mBackObjects); 486 484 487 const float renderCostDecr = oldRenderCost - newRenderCost; 485 488 486 //Debug << "\nbvh render cost decr: " << renderCostDecr << endl; 489 #ifdef _DEBUG 490 Debug << "old render cost: " << oldRenderCost << endl; 491 Debug << "new render cost: " << newRenderCost << endl; 492 Debug << "render cost decrease: " << renderCostDecr << endl; 493 #endif 487 494 splitCandidate.SetRenderCostDecrease(renderCostDecr); 488 495 489 #if 0 490 const float priority = (float)-splitCandidate.mParentData.mDepth; 491 #else 496 #if 1 492 497 // take render cost of node into account 493 498 // otherwise danger of being stuck in a local minimum!! 494 499 const float factor = mRenderCostDecreaseWeight; 495 500 const float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost; 501 #else 502 const float priority = (float)-splitCandidate.mParentData.mDepth; 496 503 #endif 497 504 … … 540 547 // depth related stuff 541 548 542 if (data.mDepth > mBvhStats.maxDepth)543 {544 mBvhStats.maxDepth = data.mDepth;545 }546 547 549 if (data.mDepth < mBvhStats.minDepth) 548 550 { … … 640 642 } 641 643 642 const float oldProp = EvalViewCellsVolume(tData.mNode->mObjects); 643 //const float oldProp = tData.mProbability; 644 645 const float oldRenderCost = oldProb * (float)tData.mNode->mObjects.size(); 644 const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects); 646 645 const float newRenderCost = 647 EvalRenderCost( tData, objectsFront,objectsBack);646 EvalRenderCost(objectsFront) * EvalRenderCost(objectsBack); 648 647 649 648 const float ratio = newRenderCost / oldRenderCost; … … 672 671 // object mailed => belongs to back objects 673 672 if (i < border) 673 { 674 674 objectsBack.push_back(obj); 675 } 675 676 else 677 { 676 678 objectsFront.push_back(obj); 677 } 678 679 const float oldProp = EvalViewCellsVolume(tData.mNode->mObjects); 680 //const float oldProp = tData.mProbability; 681 682 const float oldRenderCost = oldProp * (float)tData.mNode->mObjects.size(); 683 const float newRenderCost = EvalRenderCost(tData, objectsFront, objectsBack); 679 } 680 } 681 682 const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects); 683 const float newRenderCost = EvalRenderCost(objectsFront) + EvalRenderCost(objectsBack); 684 684 685 685 const float ratio = newRenderCost / oldRenderCost; … … 694 694 ObjectContainer &objectsBack) 695 695 { 696 PrepareLocalSubdivisionCandidates(tData, axis);697 698 696 // go through the lists, count the number of objects left and right 699 697 // and evaluate the following cost funcion: 700 698 // C = ct_div_ci + (ol + or)/queries 699 PrepareLocalSubdivisionCandidates(tData, axis); 700 701 701 int objectsLeft = 0, objectsRight = (int)tData.mNode->mObjects.size(); 702 702 … … 709 709 float minSum = 1e20f; 710 710 711 float minBorder = maxBox; 712 float maxBorder = minBox; 713 float areaLeft = 0, areaRight = 0; 714 715 SortableEntryContainer::const_iterator currentPos = 716 mSubdivisionCandidates->begin(); 717 718 719 // we keep track of both borders of the bounding boxes => 720 // store the events in descending order 711 721 vector<float> bordersRight; 712 722 bordersRight.resize(mSubdivisionCandidates->size()); 713 723 714 float minBorder = maxBox;715 float maxBorder = minBox;716 717 SortableEntryContainer::const_iterator currentPos =718 mSubdivisionCandidates->begin();719 720 724 SortableEntryContainer::reverse_iterator rcit = 721 725 mSubdivisionCandidates->rbegin(), rcit_end = mSubdivisionCandidates->rend(); 722 726 723 727 vector<float>::reverse_iterator rbit = bordersRight.rbegin(); 724 728 … … 728 732 const AxisAlignedBox3 box = obj->GetBox(); 729 733 730 if (box.Min() < minBorder) 734 if (box.Min(axis) < minBorder) 735 { 731 736 minBorder = box.Min(axis); 732 737 } 738 733 739 (*rbit) = minBorder; 734 740 } 735 741 736 742 vector<float>::const_iterator bit = bordersRight.begin(); 737 cout << "here42" << endl;738 743 SortableEntryContainer::const_iterator cit, cit_end = mSubdivisionCandidates->end(); 744 739 745 for (cit = mSubdivisionCandidates->begin(); cit != cit_end; ++ cit, ++ bit) 740 746 { … … 749 755 const AxisAlignedBox3 obox = obj->GetBox(); 750 756 757 // the borders of the bounding boxes have changed 751 758 if (obox.Max(axis) > maxBorder) 759 { 752 760 maxBorder = obox.Max(axis); 753 761 } 762 763 minBorder = (*bit); 764 754 765 lbox.SetMax(axis, maxBorder); 755 rbox.SetMin(axis, *bit); 756 757 const float sum = objectsLeft * lbox.SurfaceArea() + objectsRight * rbox.SurfaceArea(); 766 rbox.SetMin(axis, minBorder); 767 768 const float al = lbox.SurfaceArea(); 769 const float ar = rbox.SurfaceArea(); 770 771 const float sum = objectsLeft * al + objectsRight * ar; 758 772 759 cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=("773 /*cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=(" 760 774 << lbox.SurfaceArea() << "," << rbox.SurfaceArea() << ")" << endl; 775 cout << "minborder: " << minBorder << " maxborder: " << maxBorder << endl; 761 776 cout << "cost= " << sum << endl; 762 777 */ 763 778 if (sum < minSum) 764 779 { 765 minSum = sum; 780 minSum = sum; 781 areaLeft = al; 782 areaRight = ar; 766 783 // objects belong to left side now 767 784 for (; currentPos != (cit + 1); ++ currentPos); 768 785 } 769 786 } 787 770 788 771 789 //////////////////////////////////////////// … … 784 802 float ratio = newCost / oldCost; 785 803 786 #if 0787 cout<<"===================="<<endl; 788 cout<<"costRatio="<<ratio<<" pos="<<position<<" t="<<(position - minBox)/(maxBox - minBox) 789 <<"\t o=("<<objectsBack<<","<<objectsFront<<")"<<endl;804 #ifdef _DEBUG 805 cout << "\n\nobjects=(" << objectsBack.size() << "," << objectsFront.size() << " of " << tData.mNode->mObjects.size() << ")\t area=(" 806 << areaLeft << "," << areaRight << ")" << endl; 807 cout << "cost= " << minSum << endl; 790 808 #endif 791 809 return ratio; … … 855 873 int nObjectsLeft = 0; 856 874 const int nTotalObjects = (int)tData.mNode->mObjects.size(); 857 const float viewSpaceVol = m VspTree->GetBoundingBox().GetVolume();875 const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume(); 858 876 859 877 SortableEntryContainer::const_iterator backObjectsStart = mSubdivisionCandidates->begin(); … … 1128 1146 //-- use surface area heuristic because view cells not constructed yet 1129 1147 nCostRatio[axis] = 1130 Eval LocalCostHeuristics(1131 1132 1133 1134 1148 EvalSah( 1149 tData, 1150 axis, 1151 nFrontObjects[axis], 1152 nBackObjects[axis]); 1135 1153 } 1136 1154 } … … 1138 1156 { 1139 1157 //-- split objects using some simple criteria 1140 1141 1158 nCostRatio[axis] = 1142 1159 EvalLocalObjectPartition( … … 1245 1262 1246 1263 1247 float BvHierarchy::EvalRenderCost(const BvhTraversalData &tData, 1248 const ObjectContainer &objectsFront, 1249 const ObjectContainer &objectsBack) const 1250 { 1251 // probability that view point lies in a view cell which sees this node 1252 const float pFront = EvalViewCellsVolume(objectsFront); 1253 const float pBack = EvalViewCellsVolume(objectsBack); 1254 1255 //-- pvs rendering heuristics 1256 const float newRenderCost = (int)objectsFront.size() * pFront + (int)objectsBack.size() * pBack; 1257 1258 #ifdef _DEBUG 1259 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 1260 Debug << "\nbvh render cost\n" 1261 << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << endl 1262 << "new rc: " << newRenderCost / viewSpaceVol << endl; 1263 #endif 1264 return newRenderCost; 1264 float BvHierarchy::EvalRenderCost(const ObjectContainer &objects) const 1265 { 1266 if (mHierarchyManager->GetViewSpaceSubdivisionType() == HierarchyManager::NO_VIEWSPACE_SUBDIV) 1267 { 1268 if (objects.empty()) 1269 return 0.0f; 1270 1271 ///////////////////////////// 1272 //-- surface area heuristics 1273 1274 const AxisAlignedBox3 box = ComputeBoundingBox(objects); 1275 const float area = box.SurfaceArea(); 1276 1277 return (float)objects.size() * area; 1278 } 1279 else 1280 { ///////////////////////////// 1281 //-- render cost heuristics 1282 1283 const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume(); 1284 // probability that view point lies in a view cell which sees this node 1285 const float p = EvalViewCellsVolume(objects) / viewSpaceVol; 1286 1287 return (float)objects.size() * p; 1288 } 1265 1289 } 1266 1290 1267 1291 1268 1292 AxisAlignedBox3 BvHierarchy::ComputeBoundingBox(const ObjectContainer &objects, 1269 const AxisAlignedBox3 *parentBox) 1293 const AxisAlignedBox3 *parentBox) const 1270 1294 { 1271 1295 if (parentBox && objects.empty()) … … 1325 1349 const bool setCounter) const 1326 1350 { 1351 // no view cells yet 1352 if (mHierarchyManager->GetViewSpaceSubdivisionType() == 1353 HierarchyManager::NO_VIEWSPACE_SUBDIV) 1354 return; 1355 1327 1356 ViewCell::NewMail(); 1328 1357 ObjectContainer::const_iterator oit, oit_end = objects.end(); … … 1348 1377 ViewCellContainer tmpViewCells; 1349 1378 1350 m VspTree->GetViewCells(*ray, tmpViewCells);1379 mHierarchyManager->mVspTree->GetViewCells(*ray, tmpViewCells); 1351 1380 1352 1381 ViewCellContainer::const_iterator vit, vit_end = tmpViewCells.end(); … … 1645 1674 bvhleaf->SetSubdivisionCandidate(oSubdivisionCandidate); 1646 1675 1647 const float viewSpaceVol = m VspTree->GetBoundingBox().GetVolume();1676 const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume(); 1648 1677 mTotalCost = (float)objects.size() * prop / viewSpaceVol; 1649 1678
Note: See TracChangeset
for help on using the changeset viewer.