Changeset 1297 for GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
- Timestamp:
- 08/30/06 04:39:53 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1294 r1297 26 26 static float debugVol = 0; 27 27 28 int BvhNode::sMailId = 2147483647;28 int BvhNode::sMailId = 10000;//2147483647; 29 29 int BvhNode::sReservedMailboxes = 1; 30 30 … … 44 44 /***************************************************************/ 45 45 46 BvhNode::BvhNode(): mParent(NULL) 46 BvhNode::BvhNode(): mParent(NULL), mMailbox(0) 47 47 { 48 48 } 49 49 50 50 BvhNode::BvhNode(const AxisAlignedBox3 &bbox): 51 mParent(NULL), mBoundingBox(bbox) 51 mParent(NULL), mBoundingBox(bbox), mMailbox(0) 52 52 { 53 53 } … … 55 55 56 56 BvhNode::BvhNode(const AxisAlignedBox3 &bbox, BvhInterior *parent): 57 mBoundingBox(bbox), mParent(parent) 57 mBoundingBox(bbox), mParent(parent), mMailbox(0) 58 58 { 59 59 } … … 217 217 218 218 //-- factors for bsp tree split plane heuristics 219 Environment::GetSingleton()->GetFloatValue("BvHierarchy.Termination.ct_div_ci", mCtDivCi);220 221 //-- partition criteria222 Environment::GetSingleton()->GetFloatValue("BvHierarchy.Construction.epsilon", mEpsilon);223 219 224 220 // if only the driving axis is used for axis aligned split … … 227 223 Environment::GetSingleton()->GetBoolValue("BvHierarchy.useCostHeuristics", mUseCostHeuristics); 228 224 229 230 225 char subdivisionStatsLog[100]; 231 226 Environment::GetSingleton()->GetStringValue("BvHierarchy.subdivisionStats", subdivisionStatsLog); 232 227 mSubdivisionStats.open(subdivisionStatsLog); 233 228 234 Environment::GetSingleton()->GetFloatValue("BvHierarchy.Construction.splitBorder", mSplitBorder);235 229 Environment::GetSingleton()->GetFloatValue( 236 230 "BvHierarchy.Construction.renderCostDecreaseWeight", mRenderCostDecreaseWeight); … … 240 234 241 235 Debug << "******* Bvh hierarchy options ******** " << endl; 242 243 236 Debug << "max depth: " << mTermMaxDepth << endl; 244 237 Debug << "min probabiliy: " << mTermMinProbability<< endl; … … 247 240 Debug << "miss tolerance: " << mTermMissTolerance << endl; 248 241 Debug << "max leaves: " << mTermMaxLeaves << endl; 249 250 242 Debug << "randomize: " << randomize << endl; 251 252 243 Debug << "min global cost ratio: " << mTermMinGlobalCostRatio << endl; 253 244 Debug << "global cost miss tolerance: " << mTermGlobalCostMissTolerance << endl; … … 387 378 EvalSubdivisionCandidate(*frontCandidate); 388 379 EvalSubdivisionCandidate(*backCandidate); 380 381 // cross reference 382 tFrontData.mNode->SetSubdivisionCandidate(frontCandidate); 383 tBackData.mNode->SetSubdivisionCandidate(backCandidate); 389 384 390 385 tQueue.Push(frontCandidate); … … 397 392 398 393 //-- terminate traversal 399 if (newNode->IsLeaf()) 400 { 394 if (newNode->IsLeaf()) 395 { 396 //-- store additional info 401 397 EvaluateLeafStats(tData); 402 398 403 const bool mStoreRays= true; 404 405 //-- store additional info 399 const bool mStoreRays = true; 406 400 if (mStoreRays) 407 401 { … … 429 423 430 424 // cost ratio violated? 431 const bool maxCostRatioViolated = ratio < mTermMaxCostRatio;425 const bool maxCostRatioViolated = mTermMaxCostRatio < ratio; 432 426 433 427 splitCandidate.mMaxCostMisses = maxCostRatioViolated ? 434 splitCandidate.mParentData.mMaxCostMisses :435 splitCandidate.mParentData.mMaxCostMisses + 1;428 splitCandidate.mParentData.mMaxCostMisses + 1 : 429 splitCandidate.mParentData.mMaxCostMisses; 436 430 437 431 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); … … 451 445 splitCandidate.SetRenderCostDecrease(renderCostDecr); 452 446 453 #if 1447 #if 0 454 448 const float priority = (float)-splitCandidate.mParentData.mDepth; 455 449 #else … … 520 514 521 515 516 #if 0 522 517 float BvHierarchy::EvalLocalObjectPartition(const BvhTraversalData &tData, 523 518 const int axis, … … 535 530 { 536 531 Intersectable *obj = *oit; 537 AxisAlignedBox3 box = obj->GetBox();532 const AxisAlignedBox3 box = obj->GetBox(); 538 533 539 534 const float objMid = (box.Max(axis) + box.Min(axis)) * 0.5f; … … 553 548 return ratio; 554 549 } 550 551 #else 552 553 float BvHierarchy::EvalLocalObjectPartition(const BvhTraversalData &tData, 554 const int axis, 555 ObjectContainer &objectsFront, 556 ObjectContainer &objectsBack) 557 { 558 SortSubdivisionCandidates(tData, axis); 559 560 vector<SortableEntry>::const_iterator cit, cit_end = mSubdivisionCandidates->end(); 561 562 int i = 0; 563 const int border = (int)tData.mNode->mObjects.size() / 2; 564 565 for (cit = mSubdivisionCandidates->begin(); cit != cit_end; ++ cit, ++ i) 566 { 567 Intersectable *obj = (*cit).mObject; 568 569 // object mailed => belongs to back objects 570 if (i < border) 571 objectsBack.push_back(obj); 572 else 573 objectsFront.push_back(obj); 574 } 575 576 const float oldRenderCost = tData.mProbability * (float)tData.mNode->mObjects.size(); 577 const float newRenderCost = 578 EvalRenderCost(tData, objectsFront, objectsBack); 579 580 const float ratio = newRenderCost / oldRenderCost; 581 return ratio; 582 } 583 #endif 555 584 556 585 … … 719 748 // mail view cells on the left side 720 749 ViewCell::NewMail(); 721 722 750 // mail the objects on the left side 723 751 Intersectable::NewMail(); … … 762 790 // => add volume to left node 763 791 volLeft += vol; 764 //volRight -= vol;765 792 } 766 793 … … 815 842 { 816 843 if (mUseCostHeuristics) 817 { 844 {cout << "h"; 818 845 //-- partition objects using heuristics 819 846 nCostRatio[axis] = … … 825 852 } 826 853 else 827 { 854 {cout << "m"; 828 855 nCostRatio[axis] = 829 856 EvalLocalObjectPartition( … … 1072 1099 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 1073 1100 1101 Debug << "collecting " << (int)viewCells.size() << " dirty candidates" << endl; 1074 1102 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 1075 1103 { 1076 1104 VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 1077 1078 1105 VspLeaf *leaf = vc->mLeaf; 1106 SubdivisionCandidate *candidate = leaf->GetSubdivisionCandidate(); 1107 1079 1108 dirtyList.push_back(leaf->GetSubdivisionCandidate()); 1080 1109 } … … 1108 1137 { 1109 1138 // rather use the simple version 1110 if (object->mBvhLeaf) 1111 { 1112 return object->mBvhLeaf; 1113 } 1114 1139 if (!object) return NULL; 1140 return object->mBvhLeaf; 1141 1115 1142 /////////////////////////////////////// 1116 1143 // start from root of tree 1144 1117 1145 if (node == NULL) 1118 {1119 1146 node = mRoot; 1120 } 1121 1147 1122 1148 vector<BvhLeaf *> leaves; 1123 1149 … … 1182 1208 1183 1209 1184 /*1185 int BvHierarchy::UpdateViewCellsPvs(BvhLeaf *leaf,1186 const RayInfoContainer &rays) const1187 1188 {1189 MailablePvsData::NewMail();1190 1191 ViewCellContainer touchedViewCells;1192 CollectTouchedViewCells(rays, touchedViewCells);1193 1194 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();1195 1196 for (oit = leaf->mObjects.begin(); oit < oit_end; ++ oit)1197 {1198 Intersectable *obj = *oit;1199 ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end();1200 1201 // traverse through view cells and classify them according1202 // to them being seen from to back / front / front and back node1203 for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit)1204 {1205 ViewCell *vc = *vit;1206 float contri;1207 AddViewCellToObjectPvs(obj, vc, contri, true);1208 }1209 }1210 1211 return 0;1212 }1213 1214 1215 int BvHierarchy::RemoveParentViewCellsPvs(BvhLeaf *leaf,1216 const RayInfoContainer &rays1217 ) const1218 1219 {1220 MailablePvsData::NewMail();1221 1222 ViewCellContainer touchedViewCells;1223 CollectTouchedViewCells(rays, touchedViewCells);1224 1225 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();1226 1227 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit)1228 {1229 Intersectable *obj = *oit;1230 1231 // traverse through view cells and classify them according1232 // to them being seen from to back / front / front and back node1233 ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end();1234 1235 for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit)1236 {1237 ViewCell *vc = *vit;1238 1239 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc);1240 1241 if (vdata && !vdata->Mailed())1242 {1243 vdata->Mail();1244 obj->mViewCellPvs.RemoveSample(vc, 1);1245 }1246 }1247 }1248 1249 return 0;1250 }1251 */1252 1253 1210 bool BvHierarchy::Export(OUT_STREAM &stream) 1254 1211 {
Note: See TracChangeset
for help on using the changeset viewer.