Changeset 1308 for GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
- Timestamp:
- 08/31/06 17:58:27 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1305 r1308 36 36 HierarchyManager::HierarchyManager(VspTree *vspTree, 37 37 const int objectSpaceSubdivisionType): 38 mObjectSpaceSubdivis onType(objectSpaceSubdivisionType),38 mObjectSpaceSubdivisionType(objectSpaceSubdivisionType), 39 39 mVspTree(vspTree), 40 40 mOspTree(NULL), 41 41 mBvHierarchy(NULL) 42 42 { 43 switch(mObjectSpaceSubdivis onType)43 switch(mObjectSpaceSubdivisionType) 44 44 { 45 45 case KD_BASED_OBJ_SUBDIV: … … 67 67 68 68 HierarchyManager::HierarchyManager(VspTree *vspTree, KdTree *kdTree): 69 mObjectSpaceSubdivis onType(KD_BASED_OBJ_SUBDIV),69 mObjectSpaceSubdivisionType(KD_BASED_OBJ_SUBDIV), 70 70 mVspTree(vspTree), 71 71 mBvHierarchy(NULL) … … 102 102 "Hierarchy.Construction.type", mConstructionType); 103 103 104 mMinDepthForObjectSpaceSubdivion = -1; 105 104 106 Debug << "******** Hierachy Manager Parameters ***********" << endl; 105 107 Debug << "max leaves: " << mTermMaxLeaves << endl; … … 143 145 144 146 145 void HierarchyManager::PrepareConstruction(const VssRayContainer &sampleRays,146 const ObjectContainer &objects,147 AxisAlignedBox3 *forcedViewSpace,148 RayInfoContainer &viewSpaceRays,149 RayInfoContainer &objectSpaceRays)150 {151 mHierarchyStats.Reset();152 mHierarchyStats.Start();153 154 switch (mObjectSpaceSubdivisonType)155 {156 case KD_BASED_OBJ_SUBDIV:157 {158 SubdivisionCandidate *vsc =159 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, viewSpaceRays);160 mTQueue.Push(vsc);161 162 SubdivisionCandidate *osc;163 osc = mOspTree->PrepareConstruction(sampleRays, objects, objectSpaceRays);164 mTQueue.Push(osc);165 break;166 }167 case BV_BASED_OBJ_SUBDIV:168 {169 mBvHierarchy->CreateRoot(objects);170 171 SubdivisionCandidate *vsc =172 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, viewSpaceRays);173 mTQueue.Push(vsc);174 175 SubdivisionCandidate *osc;176 osc = mBvHierarchy->PrepareConstruction(sampleRays, objects);177 mTQueue.Push(osc);178 break;179 }180 default:181 break;182 }183 184 mTotalCost = (float)objects.size();185 Debug << "setting total cost to " << mTotalCost << endl;186 }187 188 189 147 void HierarchyManager::EvalSubdivisionStats(const SubdivisionCandidate &tData) 190 148 { 191 149 const float costDecr = tData.GetRenderCostDecrease(); 192 150 193 switch (mObjectSpaceSubdivis onType)151 switch (mObjectSpaceSubdivisionType) 194 152 { 195 153 case KD_BASED_OBJ_SUBDIV: … … 219 177 const float totalRenderCost) 220 178 { 221 mSubdivisionStats 179 mSubdivisionStats 222 180 << "#Splits\n" << splits << endl 223 181 << "#RenderCostDecrease\n" << renderCostDecr << endl … … 241 199 AxisAlignedBox3 *forcedViewSpace) 242 200 { 243 switch (mConstructionType) 244 { 245 case 0: 246 ConstructSequential(sampleRays, objects, forcedViewSpace); 247 break; 248 case 1: 249 ConstructInterleaved(sampleRays, objects, forcedViewSpace); 250 break; 251 default: 252 break; 253 } 254 } 255 256 257 void HierarchyManager::ConstructInterleaved(const VssRayContainer &sampleRays, 258 const ObjectContainer &objects, 259 AxisAlignedBox3 *forcedViewSpace) 260 { 261 RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 201 262 202 RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 263 203 264 // prepare vsp and osp trees for traversal 265 PrepareConstruction(sampleRays, 266 objects, 267 forcedViewSpace, 268 *viewSpaceRays, 269 *objectSpaceRays); 270 204 mHierarchyStats.Reset(); 205 mHierarchyStats.Start(); 206 207 // start with view space subdivison: prepare vsp tree for traversal 208 SubdivisionCandidate *vsc = 209 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays); 210 mTQueue.Push(vsc); 211 212 mTotalCost = (float)objects.size(); 213 Debug << "setting total cost to " << mTotalCost << endl; 214 215 const long startTime = GetTime(); 271 216 cout << "Constructing view space / object space tree ... \n"; 272 const long startTime = GetTime();273 217 274 const bool repairQueue = true;275 //const bool repairQueue = false;276 277 218 // process object space candidates 278 RunConstruction(repairQueue); 219 RunConstruction(); 220 279 221 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 280 281 222 mVspTree->mVspStats.Stop(); 282 223 } 283 224 284 225 285 void HierarchyManager::ConstructBvHierarchy(const VssRayContainer &sampleRays, 286 const ObjectContainer &objects) 287 288 { 289 Debug << "\n$$$$$$$$$ bv hierarchy construction $$$$$$$$$$\n" << endl; 226 void HierarchyManager::PrepareObjectSpaceSubdivision(const VssRayContainer &sampleRays, 227 const ObjectContainer &objects) 228 { 229 if (mObjectSpaceSubdivisionType == KD_BASED_OBJ_SUBDIV) 230 { 231 PrepareOspTree(sampleRays, objects); 232 } 233 else if (mObjectSpaceSubdivisionType == BV_BASED_OBJ_SUBDIV) 234 { 235 PrepareBvHierarchy(sampleRays, objects); 236 } 237 } 238 239 240 void HierarchyManager::PrepareBvHierarchy(const VssRayContainer &sampleRays, 241 const ObjectContainer &objects) 242 243 { 290 244 cout << "starting bv hierarchy construction ... " << endl; 291 245 … … 298 252 mTotalCost = mBvHierarchy->mTotalCost; 299 253 Debug << "reseting cost, new total cost: " << mTotalCost << endl; 300 254 301 255 mTQueue.Push(sc); 302 303 mBvHierarchy->mBvhStats.Reset(); 304 mBvHierarchy->mBvhStats.Start(); 305 306 const long startTime = GetTime(); 307 308 const bool repairQueue = false; 309 // process object space candidates 310 RunConstruction(repairQueue); 311 312 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 313 mBvHierarchy->mBvhStats.Stop(); 314 } 315 316 317 void HierarchyManager::ConstructOspTree(const VssRayContainer &sampleRays, 318 const ObjectContainer &objects) 319 256 } 257 258 259 void HierarchyManager::PrepareOspTree(const VssRayContainer &sampleRays, 260 const ObjectContainer &objects) 320 261 { 321 262 RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 322 263 323 Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl;324 264 cout << "starting osp tree construction ... " << endl; 325 265 … … 335 275 336 276 mTQueue.Push(osc); 337 338 mOspTree->mOspStats.Reset(); 339 mOspTree->mOspStats.Start(); 340 341 const long startTime = GetTime(); 342 343 const bool repairQueue = false; 344 // process object space candidates 345 RunConstruction(repairQueue); 346 347 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 348 mOspTree->mOspStats.Stop(); 349 350 ////////////////////////// 351 // matt: only for debugging purpose 352 353 const float rc = mOspTree->EvalRenderCost(sampleRays); 354 Debug << "My render cost evalulation: " << rc << endl; 355 } 356 277 } 357 278 358 279 … … 371 292 else 372 293 { 373 if (mObjectSpaceSubdivis onType == KD_BASED_OBJ_SUBDIV)294 if (mObjectSpaceSubdivisionType == KD_BASED_OBJ_SUBDIV) 374 295 { 375 296 KdNode *n = mOspTree->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); … … 378 299 return false; 379 300 } 380 else if (mObjectSpaceSubdivis onType == BV_BASED_OBJ_SUBDIV)301 else if (mObjectSpaceSubdivisionType == BV_BASED_OBJ_SUBDIV) 381 302 { 382 303 BvhNode *n = mBvHierarchy->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); … … 386 307 } 387 308 } 388 389 309 return true;//!globalTerminationCriteriaMet; 390 310 } 391 311 392 312 393 void HierarchyManager::RunConstruction(const bool repair) 313 bool HierarchyManager::StartObjectSpaceSubdivision() const 314 { 315 const bool constructAfterViewSpace = (mConstructionType == 1) && mTQueue.Empty(); 316 317 return 318 NO_OBJ_SUBDIV && 319 ((mMinDepthForObjectSpaceSubdivion < 0/*mVspTree->mVspStats.mMaxDepth*/) || constructAfterViewSpace); 320 } 321 322 323 void HierarchyManager::RunConstruction() 394 324 { 395 325 mHierarchyStats.nodes = 0; 396 326 mGlobalCostMisses = 0; 397 327 398 while (!FinishedConstruction()) 399 { 328 // use objects for evaluating vsp tree construction 329 const int savedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType; 330 mObjectSpaceSubdivisionType = NO_OBJ_SUBDIV; 331 332 //const bool repairQueue = false; 333 const bool repairQueue = true; 334 335 do 336 { 337 // use objects for evaluating vsp tree construction until a certain depth 338 if (StartObjectSpaceSubdivision()) 339 { 340 mObjectSpaceSubdivisionType = savedObjectSpaceSubdivisionType; 341 //PrepareObjectSpaceSubdivision(); 342 } 343 400 344 mCurrentCandidate = NextSubdivisionCandidate(); 401 345 mTotalCost -= mCurrentCandidate->GetRenderCostDecrease(); … … 420 364 // reevaluate candidates affected by the split for view space splits, 421 365 // this would be object space splits and other way round 422 if (repair) RepairQueue(); 423 } 424 366 if (repairQueue) RepairQueue(); 367 } 425 368 DEL_PTR(mCurrentCandidate); 426 369 } 370 while (!FinishedConstruction()); 371 372 mObjectSpaceSubdivisionType = savedObjectSpaceSubdivisionType; 427 373 } 428 374 … … 436 382 void HierarchyManager::CollectObjectSpaceDirtyList(SubdivisionCandidateContainer &dirtyList) 437 383 { 438 switch (mObjectSpaceSubdivis onType)384 switch (mObjectSpaceSubdivisionType) 439 385 { 440 386 case KD_BASED_OBJ_SUBDIV: … … 485 431 void HierarchyManager::RepairQueue() 486 432 { 487 // TODO488 433 // for each update of the view space partition: 489 434 // the candidates from object space partition which … … 535 480 { 536 481 // the type of the view cells hierarchy 537 switch (mObjectSpaceSubdivis onType)482 switch (mObjectSpaceSubdivisionType) 538 483 { 539 484 case KD_BASED_OBJ_SUBDIV: … … 559 504 if (!obj) return false; 560 505 561 switch (mObjectSpaceSubdivis onType)506 switch (mObjectSpaceSubdivisionType) 562 507 { 563 508 case NO_OBJ_SUBDIV: … … 583 528 void HierarchyManager::PrintObjectSpaceHierarchyStatistics(ofstream &stream) const 584 529 { 585 switch (mObjectSpaceSubdivis onType)530 switch (mObjectSpaceSubdivisionType) 586 531 { 587 532 case KD_BASED_OBJ_SUBDIV: … … 604 549 const ObjectContainer &objects) const 605 550 { 606 switch (mObjectSpaceSubdivis onType)551 switch (mObjectSpaceSubdivisionType) 607 552 { 608 553 case KD_BASED_OBJ_SUBDIV: … … 640 585 641 586 642 void HierarchyManager::ConstructSequential(const VssRayContainer &sampleRays, 643 const ObjectContainer &objects, 644 AxisAlignedBox3 *forcedViewSpace) 645 { 646 // rays clipped in view space and in object space 647 RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 648 649 650 ///////////////////////////////////////////////////////////// 651 // view space space partition 652 ///////////////////////////////////////////////////////////// 653 654 655 // use objects for evaluating vsp tree construction 656 const int savedobjectSpaceSubdivisionType = mObjectSpaceSubdivisonType; 657 mObjectSpaceSubdivisonType = NO_OBJ_SUBDIV; 658 659 SubdivisionCandidate *vsc = 660 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays); 661 662 // add to subdivision candidate to split candidate queue 663 mTQueue.Push(vsc); 664 665 long startTime = GetTime(); 666 cout << "starting vsp construction ... " << endl; 667 668 mVspTree->mVspStats.Reset(); 669 mVspTree->mVspStats.Start(); 670 671 // all objects can be seen from everywhere 672 mTotalCost = (float)dynamic_cast<VspTree::VspSubdivisionCandidate *>(vsc)->mParentData.mPvs; 673 674 const bool repairQueue = false; 675 // process view space candidates 676 RunConstruction(repairQueue); 677 678 cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 679 mVspTree->mVspStats.Stop(); 680 681 // reset subdivision type 682 mObjectSpaceSubdivisonType = savedobjectSpaceSubdivisionType; 683 684 685 ///////////////////////////////////////////////////////////// 686 // object space partition 687 ///////////////////////////////////////////////////////////// 688 689 switch (mObjectSpaceSubdivisonType) 690 { 691 case KD_BASED_OBJ_SUBDIV: 692 { 693 ConstructOspTree(sampleRays, objects); 694 break; 695 } 696 case BV_BASED_OBJ_SUBDIV: 697 { 698 ConstructBvHierarchy(sampleRays, objects); 699 break; 700 } 701 default: 702 break; 703 } 704 } 705 706 707 } 587 }
Note: See TracChangeset
for help on using the changeset viewer.