Changeset 1323 for GTP/trunk/Lib/Vis
- Timestamp:
- 09/05/06 09:51:56 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1314 r1323 580 580 581 581 const float oldProp = EvalViewCellsVolume(tData.mNode->mObjects); 582 //const float oldProp2 = tData.mProbability; Debug << "here65 " << oldProp - oldProp2 << endl;582 //const float oldProp2 = tData.mProbability; 583 583 584 584 const float oldRenderCost = oldProp * (float)tData.mNode->mObjects.size(); … … 591 591 592 592 593 float BvHierarchy::EvalLocalCostHeuristics(const BvhTraversalData &tData, 594 const int axis, 595 ObjectContainer &objectsFront, 596 ObjectContainer &objectsBack) 597 { 598 // prepare the heuristics by setting mailboxes and counters. 599 const float totalVol = PrepareHeuristics(tData, axis); 600 593 float BvHierarchy::EvalSah(const BvhTraversalData &tData, 594 const int axis, 595 ObjectContainer &objectsFront, 596 ObjectContainer &objectsBack) 597 { 598 SortSubdivisionCandidates(tData, axis); 599 601 600 // go through the lists, count the number of objects left and right 602 // and evaluate the cost funcion 603 604 // local helper variables 605 float volLeft = 0; 606 float volRight = totalVol; 607 608 int nObjectsLeft = 0; 609 610 const int nTotalObjects = (int)tData.mNode->mObjects.size(); 611 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 601 // and evaluate the following cost funcion: 602 // C = ct_div_ci + (ol + or)/queries 603 int objectsLeft = 0, objectsRight = (int)tData.mNode->mObjects.size(); 604 605 AxisAlignedBox3 box = tData.mNode->GetBoundingBox(); 606 607 float minBox = box.Min(axis); 608 float maxBox = box.Max(axis); 609 float boxArea = box.SurfaceArea(); 610 611 float minSum = 1e20f; 612 613 vector<float> bordersRight; 614 bordersRight.resize(mSubdivisionCandidates->size()); 615 616 float minBorder = maxBox; 617 float maxBorder = minBox; 612 618 613 619 vector<SortableEntry>::const_iterator currentPos = 614 620 mSubdivisionCandidates->begin(); 615 621 616 ///////////////////////////////// 617 // the parameters for the current optimum 618 619 float volBack = volLeft; 620 float volFront = volRight; 621 float newRenderCost = nTotalObjects * totalVol; 622 623 #ifdef _DEBUG 624 const int leaves = mBvhStats.Leaves(); 625 const bool printStats = ((axis == 0) && (leaves > 0) && (leaves < 90)); 626 627 ofstream sumStats; 628 ofstream vollStats; 629 ofstream volrStats; 630 631 if (printStats) 622 vector<SortableEntry>::reverse_iterator rcit = 623 mSubdivisionCandidates->rbegin(), rcit_end = mSubdivisionCandidates->rend(); 624 625 vector<float>::reverse_iterator rbit = bordersRight.rbegin(); 626 627 for (; rcit != rcit_end; ++ rcit, ++ rbit) 628 { 629 Intersectable *obj = (*rcit).mObject; 630 const AxisAlignedBox3 box = obj->GetBox(); 631 632 if (box.Min() < minBorder) 633 minBorder = box.Min(axis); 634 635 (*rbit) = minBorder; 636 } 637 638 vector<float>::const_iterator bit = bordersRight.begin(); 639 640 vector<SortableEntry>::const_iterator cit, cit_end = mSubdivisionCandidates->end(); 641 for (cit = mSubdivisionCandidates->begin(); cit != cit_end; ++ cit, ++ bit) 642 { 643 Intersectable *obj = (*cit).mObject; 644 645 ++ objectsLeft; 646 -- objectsRight; 647 648 AxisAlignedBox3 lbox = box; 649 AxisAlignedBox3 rbox = box; 650 651 const AxisAlignedBox3 obox = obj->GetBox(); 652 653 if (obox.Max(axis) > maxBorder) 654 maxBorder = obox.Max(axis); 655 656 lbox.SetMax(axis, maxBorder); 657 rbox.SetMin(axis, *bit); 658 659 const float sum = objectsLeft * lbox.SurfaceArea() + objectsRight * rbox.SurfaceArea(); 660 661 // cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 662 // cout<<"cost= "<<sum<<endl; 663 664 if (sum < minSum) 665 { 666 minSum = sum; 667 // objects belongs to left side now 668 for (; currentPos != (cit + 1); ++ currentPos); 669 } 670 } 671 672 //-- assign object to front and back volume 673 674 // belongs to back bv 675 for (cit = mSubdivisionCandidates->begin(); cit != currentPos; ++ cit) 676 objectsBack.push_back((*cit).mObject); 677 678 // belongs to front bv 679 for (cit = currentPos; cit != cit_end; ++ cit) 680 objectsFront.push_back((*cit).mObject); 681 682 float oldCost = (float)tData.mNode->mObjects.size(); 683 float newCost = minSum / boxArea; 684 float ratio = newCost / oldCost; 685 686 #if 0 687 cout<<"===================="<<endl; 688 cout<<"costRatio="<<ratio<<" pos="<<position<<" t="<<(position - minBox)/(maxBox - minBox) 689 <<"\t o=("<<objectsBack<<","<<objectsFront<<")"<<endl; 690 #endif 691 return ratio; 692 } 693 694 695 static bool PrepareOutput(const int axis, 696 const int leaves, 697 ofstream &sumStats, 698 ofstream &vollStats, 699 ofstream &volrStats) 700 { 701 if ((axis == 0) && (leaves > 0) && (leaves < 90)) 632 702 { 633 703 char str[64]; … … 639 709 volrStats.open(str); 640 710 } 711 712 return sumStats.is_open() && vollStats.is_open() && volrStats.is_open(); 713 } 714 715 716 static void PrintHeuristics(const int objectsRight, 717 const float sum, 718 const float volLeft, 719 const float volRight, 720 const float viewSpaceVol, 721 ofstream &sumStats, 722 ofstream &vollStats, 723 ofstream &volrStats) 724 { 725 sumStats 726 << "#Position\n" << objectsRight << endl 727 << "#Sum\n" << sum / viewSpaceVol << endl 728 << "#Vol\n" << (volLeft + volRight) / viewSpaceVol << endl; 729 730 vollStats 731 << "#Position\n" << objectsRight << endl 732 << "#Vol\n" << volLeft / viewSpaceVol << endl; 733 734 volrStats 735 << "#Position\n" << objectsRight << endl 736 << "#Vol\n" << volRight / viewSpaceVol << endl; 737 } 738 739 740 float BvHierarchy::EvalLocalCostHeuristics(const BvhTraversalData &tData, 741 const int axis, 742 ObjectContainer &objectsFront, 743 ObjectContainer &objectsBack) 744 { 745 // prepare the heuristics by setting mailboxes and counters. 746 const float totalVol = PrepareHeuristics(tData, axis); 747 748 // go through the lists, count the number of objects left and right 749 // and evaluate the cost funcion 750 751 // local helper variables 752 float volLeft = 0; 753 float volRight = totalVol; 754 755 int nObjectsLeft = 0; 756 757 const int nTotalObjects = (int)tData.mNode->mObjects.size(); 758 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 759 760 vector<SortableEntry>::const_iterator currentPos = 761 mSubdivisionCandidates->begin(); 762 763 ///////////////////////////////// 764 // the parameters for the current optimum 765 766 float volBack = volLeft; 767 float volFront = volRight; 768 float newRenderCost = nTotalObjects * totalVol; 769 770 #ifdef _DEBUG 771 ofstream sumStats; 772 ofstream vollStats; 773 ofstream volrStats; 774 775 const bool printStats = 776 PrepareOutput(axis, mBvhStats.Leaves(), sumStats, vollStats, volrStats); 777 641 778 #endif 642 779 … … 666 803 667 804 #ifdef _DEBUG 668 669 805 if (printStats) 670 { 671 sumStats 672 << "#Position\n" << nObjectsRight << endl 673 << "#Sum\n" << sum / viewSpaceVol << endl 674 << "#Vol\n" << (volLeft + volRight) / viewSpaceVol << endl; 675 676 vollStats 677 << "#Position\n" << nObjectsRight << endl 678 << "#Vol\n" << volLeft / viewSpaceVol << endl; 679 680 volrStats 681 << "#Position\n" << nObjectsRight << endl 682 << "#Vol\n" << volRight / viewSpaceVol << endl; 683 } 806 PrintHeuristics(nObjectsRight, sum, volLeft, volRight, viewSpaceVol, 807 sumStats, vollStats, volrStats); 684 808 #endif 685 809 … … 705 829 for (cit = currentPos; cit != cit_end; ++ cit) 706 830 objectsFront.push_back((*cit).mObject); 707 708 tData.mNode->mObjects.end();709 831 710 832 const float oldRenderCost = (float)nTotalObjects * totalVol + Limits::Small; … … 775 897 float BvHierarchy::PrepareHeuristics(const BvhTraversalData &tData, const int axis) 776 898 { 777 //-- sort so we can use a sweep from right to left 899 BvhLeaf *leaf = tData.mNode; 900 float vol = 0; 901 902 // sort so we can use a sweep from right to left 778 903 SortSubdivisionCandidates(tData, axis); 779 780 float vol = 0;781 BvhLeaf *leaf = tData.mNode;782 904 783 905 // collect and mark the view cells as belonging to front pvs 784 906 ViewCellContainer viewCells; 785 907 CollectViewCells(tData.mNode->mObjects, viewCells, true); 786 787 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 788 908 909 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 789 910 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 790 911 { … … 792 913 } 793 914 915 // mail the objects on the left side 916 Intersectable::NewMail(); 794 917 // mail view cells on the left side 795 918 ViewCell::NewMail(); 796 // mail the objects on the left side 797 Intersectable::NewMail(); 798 919 799 920 return vol; 800 921 } … … 808 929 // collect all view cells associated with this objects 809 930 // (also multiple times, if they are pierced by several rays) 810 811 931 ViewCellContainer viewCells; 812 813 932 const bool useMailboxing = false; 933 814 934 CollectViewCells(obj, viewCells, useMailboxing); 815 816 935 817 936 /// classify view cells and compute volume contri accordingly -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1315 r1323 553 553 ObjectContainer &objectsBack); 554 554 555 float EvalSah( 556 const BvhTraversalData &tData, 557 const int axis, 558 ObjectContainer &objectsFront, 559 ObjectContainer &objectsBack); 560 555 561 /** Computes priority of the traversal data and stores it in tData. 556 562 */ -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1315 r1323 46 46 mOspTree = new OspTree(); 47 47 mOspTree->mVspTree = mVspTree; 48 //mOspTree->mHierarchyManager = this;48 49 49 Debug << "creating osp tree" << endl; 50 50 break; … … 52 52 mBvHierarchy = new BvHierarchy(); 53 53 mBvHierarchy->mVspTree = mVspTree; 54 //mBvHierarchy->mHierarchyManager = this;54 55 55 Debug << "creating bv hierachy" << endl; 56 56 break; … … 74 74 mOspTree->mVspTree = mVspTree; 75 75 76 //mOspTree->mHierarchyManager = this;77 76 Debug << "creating osp tree" << endl; 78 77 … … 216 215 cout << "Constructing view space / object space tree ... \n"; 217 216 217 // use objects for evaluating vsp tree construction in the first levels 218 // of the subdivision 219 mSavedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType; 220 mObjectSpaceSubdivisionType = NO_OBJ_SUBDIV; 221 222 // start with view space subdivison: prepare vsp tree for traversal 223 PrepareViewSpaceSubdivision(sampleRays, objects, forcedViewSpace); 224 225 // start object space subdivision immediately? 226 if (StartObjectSpaceSubdivision()) 227 { 228 mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 229 PrepareObjectSpaceSubdivision(sampleRays, objects); 230 } 231 218 232 // process object space candidates 219 233 RunConstruction(sampleRays, objects, forcedViewSpace); … … 328 342 const bool ospDepthReached = 329 343 (mMinDepthForObjectSpaceSubdivion <= mVspTree->mVspStats.maxDepth); 330 const bool stillNotOsp = (mObjectSpaceSubdivisionType == NO_OBJ_SUBDIV);331 344 332 return stillNotOsp && (mTQueue.Empty() || ((mConstructionType == 1) && ospDepthReached)); 345 return !ObjectSpaceSubdivisionConstructed() && 346 (mTQueue.Empty() || ((mConstructionType == INTERLEAVED) && ospDepthReached)); 333 347 } 334 348 … … 340 354 mHierarchyStats.nodes = 0; 341 355 mGlobalCostMisses = 0; 342 343 // use objects for evaluating vsp tree construction in the first levels344 // of the subdivision345 const int savedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType;346 mObjectSpaceSubdivisionType = NO_OBJ_SUBDIV;347 348 // start with view space subdivison: prepare vsp tree for traversal349 PrepareViewSpaceSubdivision(sampleRays, objects, forcedViewSpace);350 351 // start object space subdivision immediately?352 if (StartObjectSpaceSubdivision())353 {cout << "here1155 ";354 mObjectSpaceSubdivisionType = savedObjectSpaceSubdivisionType;355 PrepareObjectSpaceSubdivision(sampleRays, objects);356 }357 356 358 357 int i = 0; … … 389 388 if (StartObjectSpaceSubdivision()) 390 389 { 391 mObjectSpaceSubdivisionType = savedObjectSpaceSubdivisionType;390 mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 392 391 393 392 cout << "starting object space subdivision at maximal view space subdivison depth " << mVspTree->mVspStats.maxDepth << " (" << mMinDepthForObjectSpaceSubdivion << ") " << endl; … … 401 400 DEL_PTR(mCurrentCandidate); 402 401 } 403 404 mObjectSpaceSubdivisionType = savedObjectSpaceSubdivisionType;402 403 mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 405 404 } 406 405 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1314 r1323 265 265 protected: 266 266 267 enum {SEQUENTIAL, INTERLEAVED}; 267 268 int mObjectSpaceSubdivisionType; 269 /// the original osp type 270 int mSavedObjectSpaceSubdivisionType; 271 268 272 int mConstructionType; 269 273
Note: See TracChangeset
for help on using the changeset viewer.