Changeset 1345 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 09/12/06 19:30:31 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1344 r1345 262 262 263 263 264 BvhInterior *BvHierarchy::SubdivideNode(const ObjectContainer &frontObjects, 265 const ObjectContainer &backObjects, 266 const BvhTraversalData &tData, 264 BvhInterior *BvHierarchy::SubdivideNode(const BvhSubdivisionCandidate &sc, 267 265 BvhTraversalData &frontData, 268 266 BvhTraversalData &backData) 269 267 { 268 const BvhTraversalData &tData = sc.mParentData; 270 269 BvhLeaf *leaf = tData.mNode; 271 272 // two new leaves 273 mBvhStats.nodes += 2; 270 mBvhStats.nodes += 2; // we have two new leaves 274 271 275 272 // add the new nodes to the tree … … 281 278 frontData.mDepth = backData.mDepth = tData.mDepth + 1; 282 279 283 frontData.mBoundingBox = ComputeBoundingBox(frontObjects, &tData.mBoundingBox); 284 backData.mBoundingBox = ComputeBoundingBox(backObjects, &tData.mBoundingBox); 285 286 ///////////// 280 frontData.mBoundingBox = ComputeBoundingBox(sc.mFrontObjects, &tData.mBoundingBox); 281 backData.mBoundingBox = ComputeBoundingBox(sc.mBackObjects, &tData.mBoundingBox); 282 283 284 //////////////////////////////// 287 285 //-- create front and back leaf 288 286 289 287 BvhLeaf *back = 290 new BvhLeaf(backData.mBoundingBox, node, (int) backObjects.size());288 new BvhLeaf(backData.mBoundingBox, node, (int)sc.mBackObjects.size()); 291 289 BvhLeaf *front = 292 new BvhLeaf(frontData.mBoundingBox, node, (int) frontObjects.size());290 new BvhLeaf(frontData.mBoundingBox, node, (int)sc.mFrontObjects.size()); 293 291 294 292 BvhInterior *parent = leaf->GetParent(); 295 296 293 297 294 // replace a link from node's parent … … 301 298 node->SetParent(parent); 302 299 } 303 else // n ewroot300 else // no parent => this node is the root 304 301 { 305 302 mRoot = node; … … 311 308 ++ mBvhStats.splits; 312 309 313 314 310 //////////////////////////////////// 311 //-- fill traversal data 315 312 316 313 frontData.mNode = front; 317 314 backData.mNode = back; 318 315 319 back->mObjects = backObjects;320 front->mObjects = frontObjects;316 back->mObjects = sc.mBackObjects; 317 front->mObjects = sc.mFrontObjects; 321 318 322 319 AssociateObjectsWithLeaf(back); 323 320 AssociateObjectsWithLeaf(front); 324 321 325 // compute probability, i.e., volume of seen view cells 326 frontData.mProbability = EvalViewCellsVolume(frontObjects); 327 backData.mProbability = EvalViewCellsVolume(backObjects); 328 322 // compute probability of this node being visible, 323 // i.e., volume of the view cells that can see this node 324 frontData.mProbability = EvalViewCellsVolume(sc.mFrontObjects); 325 backData.mProbability = EvalViewCellsVolume(sc.mBackObjects); 326 327 // how often was max cost ratio missed in this branch? 328 frontData.mMaxCostMisses = sc.mMaxCostMisses; 329 backData.mMaxCostMisses = sc.mMaxCostMisses; 330 331 // assign positions of the iterators 332 #if 0 333 frontData.mObjectsStart = sc.mFrontObjectsStart; 334 frontData.mObjectsEnd = sc.mFrontObjectsEnd; 335 336 backData.mObjectsStart = sc.mBackObjectsStart; 337 backData.mObjectsEnd = sc.mBackObjectsEnd; 338 #endif 339 // return the new interior node 329 340 return node; 330 341 } … … 339 350 BvhTraversalData &tData = sc->mParentData; 340 351 341 BvhNode * newNode = tData.mNode;352 BvhNode *currentNode = tData.mNode; 342 353 343 354 if (!LocalTerminationCriteriaMet(tData) && !globalCriteriaMet) 344 355 { 356 ////////////////////////////////////////// 345 357 //-- continue subdivision 346 358 … … 349 361 350 362 // create new interior node and two leaf node 351 newNode = SubdivideNode(sc->mFrontObjects, 352 sc->mBackObjects, 353 tData, 354 tFrontData, 355 tBackData); 356 357 const int maxCostMisses = sc->mMaxCostMisses; 358 359 // how often was max cost ratio missed in this branch? 360 tFrontData.mMaxCostMisses = maxCostMisses; 361 tBackData.mMaxCostMisses = maxCostMisses; 362 363 currentNode = SubdivideNode( 364 *sc, 365 tFrontData, 366 tBackData); 367 363 368 // decrease the weighted average cost of the subdivisoin 364 369 mTotalCost -= sc->GetRenderCostDecrease(); … … 367 372 if (1) PrintSubdivisionStats(*sc); 368 373 374 375 ///////////////////////////////////////// 369 376 //-- push the new split candidates on the queue 370 377 … … 386 393 tQueue.Push(frontCandidate); 387 394 tQueue.Push(backCandidate); 388 389 // delete old leaf node 390 //DEL_PTR(tData.mNode); 391 } 392 393 //-- terminate traversal 394 395 if (newNode->IsLeaf()) 396 { 395 } 396 397 ///////////////////////////////// 398 //-- node is a leaf => terminate traversal 399 400 if (currentNode->IsLeaf()) 401 { 402 ////////////////////////////////////// 397 403 //-- store additional info 398 399 404 EvaluateLeafStats(tData); 400 405 … … 402 407 if (mStoreRays) 403 408 { 404 BvhLeaf *leaf = dynamic_cast<BvhLeaf *>( newNode);409 BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(currentNode); 405 410 CollectRays(leaf->mObjects, leaf->mVssRays); 406 411 } 407 412 408 // detach subdivision candidate: this leaf is no candidate for 409 // splitting anymore 413 ////////////////////////////////////// 414 415 // this leaf is no candidate for splitting anymore 416 // => detach subdivision candidate 410 417 tData.mNode->SetSubdivisionCandidate(NULL); 411 // detach node so it won't get deleted418 // detach node so we don't delete it with the traversal data 412 419 tData.mNode = NULL; 413 420 } 414 421 415 return newNode;422 return currentNode; 416 423 } 417 424 … … 561 568 ObjectContainer &objectsBack) 562 569 { 563 SortSubdivisionCandidates(tData , axis);570 SortSubdivisionCandidates(tData.mNode->mObjects, &mSubdivisionCandidates, axis); 564 571 565 572 vector<SortableEntry>::const_iterator cit, cit_end = mSubdivisionCandidates->end(); … … 596 603 ObjectContainer &objectsBack) 597 604 { 598 SortSubdivisionCandidates(tData , axis);605 SortSubdivisionCandidates(tData.mNode->mObjects, &mSubdivisionCandidates, axis); 599 606 600 607 // go through the lists, count the number of objects left and right … … 846 853 847 854 848 void BvHierarchy::SortSubdivisionCandidates(const BvhTraversalData &tData, 855 void BvHierarchy::SortSubdivisionCandidates(const ObjectContainer &objects, 856 vector<SortableEntry> **subdivisionCandidates, 849 857 const int axis) 850 858 { 851 mSubdivisionCandidates->clear(); 852 853 //RayInfoContainer *rays = tData.mRays; 854 BvhLeaf *leaf = tData.mNode; 859 (*subdivisionCandidates)->clear(); 855 860 856 861 // compute requested size 857 const int requestedSize = (int) leaf->mObjects.size() * 2;862 const int requestedSize = (int)objects.size() * 2; 858 863 859 864 // creates a sorted split candidates array 860 if ( mSubdivisionCandidates->capacity() > 500000 &&861 requestedSize < (int)( mSubdivisionCandidates->capacity() / 10) )862 { 863 delete mSubdivisionCandidates;864 mSubdivisionCandidates = new vector<SortableEntry>;865 } 866 867 mSubdivisionCandidates->reserve(requestedSize);865 if ((*subdivisionCandidates)->capacity() > 500000 && 866 requestedSize < (int)((*subdivisionCandidates)->capacity() / 10) ) 867 { 868 delete *subdivisionCandidates; 869 *subdivisionCandidates = new vector<SortableEntry>; 870 } 871 872 (*subdivisionCandidates)->reserve(requestedSize); 868 873 869 874 //-- insert object queries … … 872 877 //-- there is no ray associated with these events!! 873 878 874 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();875 876 for (oit = leaf->mObjects.begin(); oit < oit_end; ++ oit)879 ObjectContainer::const_iterator oit, oit_end = objects.end(); 880 881 for (oit = objects.begin(); oit < oit_end; ++ oit) 877 882 { 878 883 Intersectable *obj = *oit; … … 882 887 const float midPt = (box.Min(axis) + box.Max(axis)) * 0.5f; 883 888 884 mSubdivisionCandidates->push_back(SortableEntry(object, midPt));885 } 886 887 stable_sort( mSubdivisionCandidates->begin(), mSubdivisionCandidates->end());889 (*subdivisionCandidates)->push_back(SortableEntry(object, midPt)); 890 } 891 892 stable_sort((*subdivisionCandidates)->begin(), (*subdivisionCandidates)->end()); 888 893 } 889 894 … … 901 906 902 907 // sort so we can use a sweep from right to left 903 SortSubdivisionCandidates(tData , axis);908 SortSubdivisionCandidates(tData.mNode->mObjects, &mSubdivisionCandidates, axis); 904 909 905 910 // collect and mark the view cells as belonging to front pvs … … 1464 1469 mBvhStats.nodes = 1; 1465 1470 1471 for (int i = 0; i < 3; ++ i) 1472 { 1473 mGlobalSubdivisionCandidates[i] = new vector<SortableEntry>(); 1474 SortSubdivisionCandidates(objects, &mGlobalSubdivisionCandidates[i], i); 1475 } 1476 1466 1477 // note matt: we assume that we have objects sorted by their id 1467 1478 -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1323 r1345 283 283 public: 284 284 285 struct SortableEntry; 286 typedef vector<SortableEntry> SortableEntryContainer; 287 285 288 /** Additional data which is passed down the BSP tree during traversal. 286 289 */ … … 294 297 mProbability(0.0), 295 298 mMaxCostMisses(0), 296 mPriority(0),297 299 mAxis(0) 300 //mObjectsStart(0), 301 //mObjectsEnd(0) 298 302 {} 299 303 … … 307 311 mProbability(v), 308 312 mMaxCostMisses(0), 309 mPriority(0),310 313 mAxis(0) 314 //mObjectsStart(0) 315 //mObjectsEnd(0) 311 316 {} 312 313 314 /** Returns cost of the traversal data.315 */316 float GetCost() const317 {318 return mPriority;319 }320 317 321 318 /// deletes contents and sets them to NULL … … 337 334 /// current axis 338 335 int mAxis; 339 /// current priority 340 float mPriority; 341 342 343 friend bool operator<(const BvhTraversalData &a, const BvhTraversalData &b) 344 { 345 return a.GetCost() < b.GetCost(); 346 } 336 /// start of objects 337 SortableEntryContainer::const_iterator mObjectsStart; 338 /// end of objects 339 SortableEntryContainer::const_iterator mObjectsEnd; 347 340 }; 348 341 … … 544 537 } 545 538 }; 546 539 547 540 /** Evaluate balanced object partition. 548 541 */ … … 586 579 587 580 /** Subdivides leaf. 588 @param leaf the leaf to be subdivided581 @param sc the subdivisionCandidate holding all necessary data for subdivision 589 582 590 @param polys the polygons to be split 591 @param frontPolys returns the polygons in front of the split plane 592 @param backPolys returns the polygons in the back of the split plane 593 594 @param rays the polygons to be filtered 595 @param frontRays returns the polygons in front of the split plane 596 @param backRays returns the polygons in the back of the split plane 597 598 @returns the root of the subdivision 583 @param frontData returns the traversal data for the front node 584 @param backData returns the traversal data for the back node 585 586 @returns the new interior node = the of the subdivision 599 587 */ 600 588 BvhInterior *SubdivideNode( 601 const ObjectContainer &frontObjects, 602 const ObjectContainer &backObjects, 603 const BvhTraversalData &tData, 589 const BvhSubdivisionCandidate &sc, 604 590 BvhTraversalData &frontData, 605 591 BvhTraversalData &backData); … … 636 622 @param axis the current split axis 637 623 */ 638 void SortSubdivisionCandidates( 639 const BvhTraversalData &data, 624 static void SortSubdivisionCandidates( 625 const ObjectContainer &objects, 626 vector<SortableEntry> **subdivisionCandidates, 640 627 const int axis); 641 628 … … 724 711 protected: 725 712 713 /// pre-sorted subdivision candidtes for all three directions. 714 vector<SortableEntry> *mGlobalSubdivisionCandidates[3]; 715 726 716 /// pointer to the hierarchy of view cells 727 717 ViewCellsTree *mViewCellsTree;
Note: See TracChangeset
for help on using the changeset viewer.