- Timestamp:
- 01/14/07 19:59:25 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1968 r1974 1597 1597 "false"); 1598 1598 1599 RegisterOption("ViewCells.useKdPvsAfterFiltering", 1600 optBool, 1601 "view_cells_use_kd_pvs_after_filtering", 1602 "false"); 1603 1599 1604 1600 1605 -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r1867 r1974 826 826 } 827 827 828 void 829 KdTree::CollectKdObjects(const AxisAlignedBox3 &box, 830 ObjectContainer &objects, 831 const float maxArea 832 ) 833 { 834 stack<KdNode *> nodeStack; 835 836 nodeStack.push(mRoot); 837 838 while (!nodeStack.empty()) { 839 KdNode *node = nodeStack.top(); 840 nodeStack.pop(); 841 if (node->IsLeaf() || (GetSurfaceArea(node) <= maxArea) ) { 842 Intersectable *object = GetOrCreateKdIntersectable(node); 843 if (!object->Mailed()) { 844 object->Mail(); 845 objects.push_back(object); 846 } 847 } else { 848 KdInterior *interior = (KdInterior *)node; 849 850 if ( box.Max()[interior->mAxis] > interior->mPosition ) 851 nodeStack.push(interior->mFront); 852 853 if (box.Min()[interior->mAxis] < interior->mPosition) 854 nodeStack.push(interior->mBack); 855 } 856 } 857 } 828 858 829 859 void -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r1761 r1974 345 345 346 346 void 347 CollectKdObjects(const AxisAlignedBox3 &box, 348 ObjectContainer &objects, 349 const float maxArea 350 ); 351 352 void 347 353 CollectObjects(KdNode *n, ObjectContainer &objects); 348 354 -
GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
r1967 r1974 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.2) on: st 10. I 21:33:1420073 # Generated by qmake (2.00a) (Qt 4.1.2) on: ne 14. I 01:57:15 2007 4 4 # Project: preprocessor.pro 5 5 # Template: app … … 63 63 $(MAKE) -f $(MAKEFILE).Debug uninstall 64 64 65 Makefile: preprocessor.pro C:/Qt/4.1.2/mkspecs/win32-msvc .net\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \65 Makefile: preprocessor.pro C:/Qt/4.1.2/mkspecs/win32-msvc2005\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 66 66 C:\Qt\4.1.2\mkspecs\features\qt_config.prf \ 67 67 C:\Qt\4.1.2\mkspecs\features\exclusive_builds.prf \ -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1972 r1974 1149 1149 ) 1150 1150 { 1151 const long t1 = GetTime(); 1152 1151 1152 1153 const long t1 = GetTime(); 1154 1155 #if 0 1156 mRayCaster->SortRays(rays); 1157 cout<<"Rays sorted in "<<TimeDiff(t1, GetTime())<<" s."<<endl; 1158 #endif 1159 1153 1160 SimpleRayContainer::const_iterator rit, rit_end = rays.end(); 1154 1161 -
GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h
r1969 r1974 339 339 // mId = sSimpleRayId++; 340 340 } 341 342 float GetParam(const int axis) const { 343 if (axis < 3) 344 return mOrigin[axis]; 345 else 346 return mDirection[axis-3]; 347 } 341 348 342 349 Vector3 Extrap(const float t) const { -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r1966 r1974 120 120 } 121 121 122 void 123 RayCaster::SortRays(SimpleRayContainer &rays) 124 { 125 _SortRays(rays, 0, rays.size()-1, 0); 126 } 127 128 void 129 RayCaster::_SortRays(SimpleRayContainer &rays, 130 const int l, 131 const int r, 132 const int axis) 133 { 134 // pick-up a pivot 135 int i=l,j=r; 136 float x = rays[(l+r)/2].GetParam(axis); 137 do { 138 while(rays[i].GetParam(axis) < x) 139 i++; 140 while(x < rays[j].GetParam(axis)) 141 j--; 142 143 if (i <= j) { 144 swap(rays[i], rays[j]); 145 i++; 146 j--; 147 } 148 } while (i<=j); 149 150 if (l + 16 < j ) 151 _SortRays(rays, l, j, (axis+1)%6); 152 153 if (i + 16 < r) 154 _SortRays(rays, i, r, (axis+1)%6); 155 } 156 157 122 158 123 159 int -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
r1972 r1974 60 60 const bool pruneInvalidRays = true 61 61 ) = 0; 62 63 64 virtual void 65 SortRays(SimpleRayContainer &rays); 66 62 67 63 68 64 69 protected: 65 struct Intersection 70 void 71 _SortRays(SimpleRayContainer &rays, 72 const int l, 73 const int r, 74 const int axis); 75 76 struct Intersection 66 77 { 67 78 Intersection(): mObject(NULL), mFaceId(0) -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r1968 r1974 6 6 #include "AxisAlignedBox3.h" 7 7 #include "RssTree.h" 8 #include "Vector2.h" 9 #include "RndGauss.h" 8 10 9 11 namespace GtpVisibilityPreprocessor { … … 566 568 } 567 569 568 #define RAY_CAST_TIME 0. 9f569 #define VIEWCELL_CAST_TIME 0. 1f570 #define RAY_CAST_TIME 0.7f 571 #define VIEWCELL_CAST_TIME 0.3f 570 572 571 573 void … … 589 591 } 590 592 591 592 593 593 if (sum == 0.0f) 594 594 sum = Limits::Small; 595 595 596 596 const float minratio = 0.01f; 597 float threshold = minratio*sum; 598 599 // recaluate the sum 597 598 for (i=0; i < mDistributions.size(); i++) { 599 mDistributions[i]->mRatio /= sum; 600 if (mDistributions[i]->mRatio < minratio) 601 mDistributions[i]->mRatio = minratio; 602 } 603 604 // recaluate the sum after clip 600 605 sum = 0.0f; 601 for (i=0; i < mDistributions.size(); i++) { 602 if (mDistributions[i]->mRatio < threshold) { 603 mDistributions[i]->mRatio = threshold; 604 } 606 for (i=0; i < mDistributions.size(); i++) 605 607 sum += mDistributions[i]->mRatio; 606 } 607 608 mDistributions[0]->mRatio /= sum;608 609 for (i=0; i < mDistributions.size(); i++) 610 mDistributions[i]->mRatio /= sum; 609 611 610 612 for (i=1; i < mDistributions.size(); i++) { 611 float r = mDistributions[i]->mRatio / sum; 612 mDistributions[i]->mRatio = mDistributions[i-1]->mRatio + r; 613 } 614 613 mDistributions[i]->mRatio = mDistributions[i-1]->mRatio + mDistributions[i]->mRatio; 614 } 615 615 616 616 cout<<"ratios: "; … … 692 692 cerr<<"Muattion update..."<<endl; 693 693 cerr<<"rays = "<<mRays.size()<<endl; 694 if (mRays.size()) 695 cerr<<"Oversampling factor = "<<mRays[0].mSamples<<endl; 694 if (mRays.size()) { 695 cerr<<"Oversampling factors = "<< 696 GetEntry(0).mSamples<<" "<< 697 GetEntry(1).mSamples<<" "<< 698 GetEntry(2).mSamples<<" "<< 699 GetEntry(3).mSamples<<" "<< 700 GetEntry(4).mSamples<<" "<< 701 GetEntry(5).mSamples<<" ... "<< 702 GetEntry(mRays.size()-6).mSamples<<" "<< 703 GetEntry(mRays.size()-5).mSamples<<" "<< 704 GetEntry(mRays.size()-4).mSamples<<" "<< 705 GetEntry(mRays.size()-3).mSamples<<" "<< 706 GetEntry(mRays.size()-2).mSamples<<" "<< 707 GetEntry(mRays.size()-1).mSamples<<endl; 708 } 709 int contributingRays = 0; 696 710 for (int i=0; i < vssRays.size(); i++) { 697 711 if (vssRays[i]->mPvsContribution) { 712 contributingRays++; 698 713 if (mRays.size() < mMaxRays) { 699 714 VssRay *newRay = new VssRay(*vssRays[i]); … … 712 727 } 713 728 } 729 730 float pContributingRays = contributingRays/(float)vssRays.size(); 731 float importance = 1.0f/(pContributingRays + 1e-5); 732 // set this values for last contributingRays 733 int index = mBufferStart - 1; 734 int i; 735 for (i=0; i < contributingRays; i++, index--) { 736 if (index < 0) 737 index = mRays.size()-1; 738 mRays[index].mImportance = importance; 739 } 740 741 742 // compute cdf 743 mRays[0].mCdf = mRays[0].mImportance/(mRays[0].mSamples+1); 744 for (i=1; i < mRays.size(); i++) 745 mRays[i].mCdf = mRays[i-1].mCdf + mRays[i].mImportance/(mRays[i].mSamples+1); 746 747 float scale = 1.0f/mRays[i-1].mCdf; 748 for (i=0; i < mRays.size(); i++) { 749 mRays[i].mCdf *= scale; 750 } 751 752 cout<<"Importance = "<< 753 GetEntry(0).mImportance<<" "<< 754 GetEntry(mRays.size()-1).mImportance<<endl; 755 714 756 cerr<<"Mutation update done."<<endl; 715 716 } 717 718 bool 719 MutationBasedDistribution::GenerateSample(SimpleRay &sray) 720 { 721 float r[5]; 722 723 if (mRays.size() == 0) { 724 // use direction based distribution 725 Vector3 origin, direction; 726 static HaltonSequence halton; 727 728 halton.GetNext(5, r); 729 mPreprocessor.mViewCellsManager->GetViewPoint(origin, 730 Vector3(r[0], r[1], r[2])); 731 732 733 direction = UniformRandomVector(r[3], r[4]); 734 735 const float pdf = 1.0f; 736 sray = SimpleRay(origin, direction, MUTATION_BASED_DISTRIBUTION, pdf); 737 738 return true; 739 } 740 741 // int index = (int) (r[0]*mRays.size()); 742 // if (index >= mRays.size()) { 743 // cerr<<"mutation: index out of bounds\n"; 744 // exit(1); 745 // } 746 747 // get tail of the buffer 748 int index = (mLastIndex+1)%mRays.size(); 749 if (mRays[index].mSamples > mRays[mLastIndex].mSamples) { 750 // search back for index where this is valid 751 index = (mLastIndex - 1 + mRays.size())%mRays.size(); 752 for (int i=0; i < mRays.size(); i++) { 753 if (mRays[index].mSamples > mRays[mLastIndex].mSamples) 754 break; 755 index = (index - 1 + mRays.size())%mRays.size(); 756 } 757 // go one step back 758 index = (index+1)%mRays.size(); 759 } 760 761 VssRay *ray = mRays[index].mRay; 762 mRays[index].mSamples++; 763 mLastIndex = index; 764 765 mRays[index].mHalton.GetNext(4, r); 766 757 } 758 759 760 Vector3 761 MutationBasedDistribution::ComputeOriginMutation(const VssRay &ray, 762 const Vector3 &U, 763 const Vector3 &V, 764 const Vector2 vr2, 765 const float radius 766 ) 767 { 768 #if 0 767 769 Vector3 v; 768 // mutate the origin769 Vector3 d = ray->GetDir();770 770 if (d.DrivingAxis() == 0) 771 771 v = Vector3(0, r[0]-0.5f, r[1]-0.5f); … … 775 775 else 776 776 v = Vector3(r[0]-0.5f, r[1]-0.5f, 0); 777 778 v=v*mOriginMutationSize; 779 780 Vector3 origin = ray->mOrigin + v; 781 777 return v*(2*radius); 778 #endif 779 #if 0 780 return (U*(r[0] - 0.5f) + V*(r[1] - 0.5f))*(2*radius); 781 #endif 782 783 784 // Output random variable 785 Vector2 gaussvec2; 786 787 // Here we apply transform to gaussian, so 2D bivariate 788 // normal distribution 789 // float sigma = ComputeSigmaFromRadius(radius); 790 float sigma = radius; 791 GaussianOn2D(vr2, 792 sigma, // input 793 gaussvec2); // output 794 795 796 // Here we tranform the point correctly to 3D space using base 797 // vectors of the 3D space defined by the direction 798 Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V; 799 800 // cout<<shift<<endl; 801 return shift; 802 } 803 804 Vector3 805 MutationBasedDistribution::ComputeTerminationMutation(const VssRay &ray, 806 const Vector3 &U, 807 const Vector3 &V, 808 const Vector2 vr2, 809 const float radius 810 ) 811 { 812 #if 0 813 Vector3 v; 782 814 // mutate the termination 783 815 if (d.DrivingAxis() == 0) … … 788 820 else 789 821 v = Vector3(r[2]-0.5f, r[3]-0.5f, 0); 822 823 // Vector3 nv; 824 825 // if (Magnitude(v) > Limits::Small) 826 // nv = Normalize(v); 827 // else 828 // nv = v; 829 830 // v = nv*size + v*size; 831 832 return v*(4.0f*radius); 833 #endif 834 #if 0 835 return (U*(vr2.xx - 0.5f) + V*(vr2.yy - 0.5f))*(4.0f*radius); 836 #endif 837 Vector2 gaussvec2; 838 #if 1 839 float sigma = radius; 840 GaussianOn2D(vr2, 841 sigma, // input 842 gaussvec2); // output 843 Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V; 844 // cout<<shift<<endl; 845 return shift; 846 #endif 847 #if 0 848 // Here we estimate standard deviation (sigma) from radius 849 float sigma = 1.1f*ComputeSigmaFromRadius(radius); 850 Vector3 vr3(vr2.xx, vr2.yy, RandomValue(0,1)); 851 PolarGaussianOnDisk(vr3, 852 sigma, 853 radius, // input 854 gaussvec2); // output 855 856 // Here we tranform the point correctly to 3D space using base 857 // vectors of the 3D space defined by the direction 858 Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V; 859 860 // cout<<shift<<endl; 861 return shift; 862 #endif 863 } 864 865 866 bool 867 MutationBasedDistribution::GenerateSample(SimpleRay &sray) 868 { 869 float rr[5]; 870 871 if (mRays.size() == 0) { 872 // use direction based distribution 873 Vector3 origin, direction; 874 static HaltonSequence halton; 875 876 halton.GetNext(5, rr); 877 mPreprocessor.mViewCellsManager->GetViewPoint(origin, 878 Vector3(rr[0], rr[1], rr[2])); 879 880 881 direction = UniformRandomVector(rr[3], rr[4]); 882 883 const float pdf = 1.0f; 884 sray = SimpleRay(origin, direction, MUTATION_BASED_DISTRIBUTION, pdf); 885 886 return true; 887 } 888 889 int index; 890 #if 1 891 // get tail of the buffer 892 index = (mLastIndex+1)%mRays.size(); 893 if (mRays[index].GetSamplingFactor() > 894 mRays[mLastIndex].GetSamplingFactor()) { 895 // search back for index where this is valid 896 index = (mLastIndex - 1 + mRays.size())%mRays.size(); 897 for (int i=0; i < mRays.size(); i++) { 898 899 // if (mRays[index].mSamples > mRays[mLastIndex].mSamples) 900 // break; 901 if (mRays[index].GetSamplingFactor() > 902 mRays[mLastIndex].GetSamplingFactor() ) 903 break; 904 index = (index - 1 + mRays.size())%mRays.size(); 905 } 906 // go one step back 907 index = (index+1)%mRays.size(); 908 } 909 #else 910 static HaltonSequence iHalton; 911 iHalton.GetNext(1, rr); 912 //rr[0] = RandomValue(0,1); 913 // use binary search to find index with this cdf 914 int l=0, r=mRays.size()-1; 915 while(l<r) { 916 int i = (l+r)/2; 917 if (rr[0] < mRays[i].mCdf ) 918 r = i; 919 else 920 l = i+1; 921 } 922 index = l; 923 // if (rr[0] >= mRays[r].mCdf) 924 // index = r; 925 // else 926 // index = l; 927 928 929 #endif 930 // cout<<index<<" "<<rr[0]<<" "<<mRays[index].mCdf<<" "<<mRays[(index+1)%mRays.size()].mCdf<<endl; 931 932 VssRay *ray = mRays[index].mRay; 933 mRays[index].mSamples++; 934 mLastIndex = index; 935 936 mRays[index].mHalton.GetNext(4, rr); 937 938 // mutate the origin 939 Vector3 d = ray->GetDir(); 940 790 941 791 942 AxisAlignedBox3 box = ray->mTerminationObject->GetBox(); 792 float size = 2.0f*Magnitude(box.Diagonal()); 793 if (size < Limits::Small) 943 float objectRadius = 0.5f*Magnitude(box.Diagonal()); 944 // cout<<objectRadius<<endl; 945 if (objectRadius < Limits::Small) 794 946 return false; 795 947 796 // Vector3 nv; 797 798 // if (Magnitude(v) > Limits::Small) 799 // nv = Normalize(v); 800 // else 801 // nv = v; 802 803 // v = nv*size + v*size; 804 805 v = v*size; 806 807 // Vector3 termination = ray->mTermination + v; 808 Vector3 termination = box.Center() + v; 948 // Compute right handed coordinate system from direction 949 Vector3 U, V; 950 Vector3 nd = Normalize(d); 951 nd.RightHandedBase(U, V); 952 953 Vector3 origin = ray->mOrigin; 954 Vector3 termination = ray->mTermination; //box.Center(); //ray->mTermination; //box.Center(); 955 956 float radiusExtension = 1.0f; 957 // + mRays[index].mSamples/50.0f; 958 959 // origin += ComputeOriginMutation(*ray, U, V, Vector2(r[0], r[1]), 0.5f*mOriginMutationSize*radiusExtension); 960 origin += ComputeOriginMutation(*ray, U, V, 961 Vector2(rr[0], rr[1]), 962 objectRadius*radiusExtension); 963 termination += ComputeTerminationMutation(*ray, U, V, 964 Vector2(rr[2], rr[3]), 965 objectRadius*radiusExtension); 809 966 810 967 Vector3 direction = termination - origin; 811 968 812 969 if (Magnitude(direction) < Limits::Small) 813 970 return false; 814 971 815 972 // shift the origin a little bit 816 973 origin += direction*0.5f; -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r1968 r1974 6 6 7 7 #include "Halton.h" 8 9 8 namespace GtpVisibilityPreprocessor { 10 9 11 class VssRay; 10 class Vector2; 11 class Vector3; 12 class VssRay; 12 13 class Preprocessor; 13 14 struct SimpleRay; 14 15 class SimpleRayContainer; 16 15 17 struct VssRayContainer; 16 18 … … 238 240 int mSamples; 239 241 HaltonSequence mHalton; 240 242 float mImportance; 243 float mCdf; 244 245 float GetSamplingFactor() const { return mSamples/mImportance; } 241 246 RayEntry() {} 242 RayEntry(VssRay *r):mRay(r), mSamples(0), mHalton() {}247 RayEntry(VssRay *r):mRay(r), mSamples(0), mHalton(), mImportance(1.0f) {} 243 248 }; 249 250 251 Vector3 252 ComputeOriginMutation(const VssRay &ray, 253 const Vector3 &U, 254 const Vector3 &V, 255 const Vector2 vr2, 256 const float radius 257 ); 258 259 Vector3 260 ComputeTerminationMutation(const VssRay &ray, 261 const Vector3 &U, 262 const Vector3 &V, 263 const Vector2 vr2, 264 const float radius 265 ); 266 267 RayEntry &GetEntry(const int index) { 268 return mRays[(mBufferStart+index)%mRays.size()]; 269 } 244 270 245 271 vector<RayEntry> mRays; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1972 r1974 667 667 668 668 669 670 671 ViewCellsManager *ViewCellsManager::LoadViewCells(const string &filename, 672 ObjectContainer *objects, 673 bool finalizeViewCells, 674 BoundingBoxConverter *bconverter) 675 676 { 677 ViewCellsParser parser; 678 ViewCellsManager *vm = NULL; 679 680 const long startTime = GetTime(); 681 bool success = parser.ParseViewCellsFile(filename, &vm, objects, bconverter); 682 683 cout<<"viewcells parsed "<<endl<<flush; 684 685 if (success) 686 { 687 //vm->ResetViewCells(); 688 //hack 689 vm->mViewCells.clear(); 690 ViewCellContainer leaves; 691 vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves); 692 693 ViewCellContainer::const_iterator it, it_end = leaves.end(); 694 695 for (it = leaves.begin(); it != it_end; ++ it) 696 { 697 vm->mViewCells.push_back(*it); 698 } 699 vm->mViewCellsFinished = true; 700 vm->mMaxPvsSize = (int)objects->size(); 701 702 if (finalizeViewCells) 703 { 704 // create the meshes and compute volumes 705 vm->FinalizeViewCells(true); 706 // vm->mViewCellsTree->AssignRandomColors(); 707 } 708 709 Debug << (int)vm->mViewCells.size() << " view cells loaded in " 710 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 711 } 712 else 713 { 714 Debug << "Error: loading view cells failed!" << endl; 715 DEL_PTR(vm); 716 } 717 718 return vm; 719 } 720 721 722 bool VspBspViewCellsManager::ExportViewCells(const string filename, 723 const bool exportPvs, 724 const ObjectContainer &objects) 725 { 726 if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 727 { 728 return false; 729 } 730 731 cout << "exporting view cells to xml ... "; 732 733 OUT_STREAM stream(filename.c_str()); 734 735 // for output we need unique ids for each view cell 736 CreateUniqueViewCellIds(); 737 738 stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl; 739 stream << "<VisibilitySolution>" << endl; 740 741 if (exportPvs) 742 { 743 //-- export bounding boxes 744 stream << "<BoundingBoxes>" << endl; 745 746 if (mUseKdPvs) 747 { 748 vector<KdIntersectable *>::iterator kit, kit_end = GetPreprocessor()->mKdTree->mKdIntersectables.end(); 749 750 int id = 0; 751 for (kit = GetPreprocessor()->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 752 { 753 Intersectable *obj = *kit; 754 const AxisAlignedBox3 box = obj->GetBox(); 755 756 obj->SetId(id); 757 758 stream << "<BoundingBox" << " id=\"" << id << "\"" 759 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 760 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 761 } 762 } 763 else 764 { 765 ObjectContainer::const_iterator oit, oit_end = objects.end(); 766 767 for (oit = objects.begin(); oit != oit_end; ++ oit) 768 { 769 const AxisAlignedBox3 box = (*oit)->GetBox(); 770 771 //////////// 772 //-- the bounding boxes 773 774 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 775 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 776 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 777 } 778 } 779 780 stream << "</BoundingBoxes>" << endl; 781 } 782 783 784 ///////////// 785 //-- export the view cells and the pvs 786 787 const int numViewCells = mCurrentViewCellsStats.viewCells; 788 stream << "<ViewCells number=\"" << numViewCells << "\" >" << endl; 789 790 mViewCellsTree->Export(stream, exportPvs); 791 792 stream << "</ViewCells>" << endl; 793 794 795 ////////// 796 //-- export the view space hierarchy 797 798 stream << "<ViewSpaceHierarchy type=\"bsp\"" 799 << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\"" 800 << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\">" << endl; 801 802 mVspBspTree->Export(stream); 803 stream << "</ViewSpaceHierarchy>" << endl; 804 805 stream << "</VisibilitySolution>" << endl; 806 807 stream.close(); 808 cout << "finished" << endl; 809 810 return true; 811 } 812 669 813 void ViewCellsManager::EvalViewCellHistogram(const string filename, 670 814 const int nViewCells) … … 757 901 outstream.close(); 758 902 } 759 760 761 ViewCellsManager *ViewCellsManager::LoadViewCells(const string &filename,762 ObjectContainer *objects,763 bool finalizeViewCells,764 BoundingBoxConverter *bconverter)765 766 {767 ViewCellsParser parser;768 ViewCellsManager *vm = NULL;769 770 const long startTime = GetTime();771 bool success = parser.ParseViewCellsFile(filename, &vm, objects, bconverter);772 773 cout<<"viewcells parsed "<<endl<<flush;774 775 if (success)776 {777 //vm->ResetViewCells();778 //hack779 vm->mViewCells.clear();780 ViewCellContainer leaves;781 vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves);782 783 ViewCellContainer::const_iterator it, it_end = leaves.end();784 785 for (it = leaves.begin(); it != it_end; ++ it)786 {787 vm->mViewCells.push_back(*it);788 }789 vm->mViewCellsFinished = true;790 vm->mMaxPvsSize = (int)objects->size();791 792 if (finalizeViewCells)793 {794 // create the meshes and compute volumes795 vm->FinalizeViewCells(true);796 // vm->mViewCellsTree->AssignRandomColors();797 }798 799 Debug << (int)vm->mViewCells.size() << " view cells loaded in "800 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;801 }802 else803 {804 Debug << "Error: loading view cells failed!" << endl;805 DEL_PTR(vm);806 }807 808 return vm;809 }810 811 812 bool VspBspViewCellsManager::ExportViewCells(const string filename,813 const bool exportPvs,814 const ObjectContainer &objects)815 {816 if (!ViewCellsConstructed() || !ViewCellsTreeConstructed())817 {818 return false;819 }820 821 cout << "exporting view cells to xml ... ";822 823 OUT_STREAM stream(filename.c_str());824 825 // for output we need unique ids for each view cell826 CreateUniqueViewCellIds();827 828 stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl;829 stream << "<VisibilitySolution>" << endl;830 831 if (exportPvs)832 {833 //-- export bounding boxes834 stream << "<BoundingBoxes>" << endl;835 836 if (mUseKdPvs)837 {838 vector<KdIntersectable *>::iterator kit, kit_end = GetPreprocessor()->mKdTree->mKdIntersectables.end();839 840 int id = 0;841 for (kit = GetPreprocessor()->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id)842 {843 Intersectable *obj = *kit;844 const AxisAlignedBox3 box = obj->GetBox();845 846 obj->SetId(id);847 848 stream << "<BoundingBox" << " id=\"" << id << "\""849 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\""850 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl;851 }852 }853 else854 {855 ObjectContainer::const_iterator oit, oit_end = objects.end();856 857 for (oit = objects.begin(); oit != oit_end; ++ oit)858 {859 const AxisAlignedBox3 box = (*oit)->GetBox();860 861 ////////////862 //-- the bounding boxes863 864 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\""865 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\""866 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl;867 }868 }869 870 stream << "</BoundingBoxes>" << endl;871 }872 873 874 /////////////875 //-- export the view cells and the pvs876 877 const int numViewCells = mCurrentViewCellsStats.viewCells;878 stream << "<ViewCells number=\"" << numViewCells << "\" >" << endl;879 880 mViewCellsTree->Export(stream, exportPvs);881 882 stream << "</ViewCells>" << endl;883 884 885 //////////886 //-- export the view space hierarchy887 888 stream << "<ViewSpaceHierarchy type=\"bsp\""889 << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\""890 << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\">" << endl;891 892 mVspBspTree->Export(stream);893 stream << "</ViewSpaceHierarchy>" << endl;894 895 stream << "</VisibilitySolution>" << endl;896 897 stream.close();898 cout << "finished" << endl;899 900 return true;901 }902 903 903 904 904 void ViewCellsManager::EvalViewCellHistogramForPvsSize(const string filename, … … 1269 1269 filename = string(statsPrefix) + string(s); 1270 1270 1271 EvalViewCellHistogramForPvsSize(filename, pass); 1271 EvalViewCellHistogram(filename, pass); 1272 // EvalViewCellHistogramForPvsSize(filename, pass); 1272 1273 } 1273 1274 } … … 1992 1993 stat.maxPvs = 0; 1993 1994 stat.avgPvs = 0.0f; 1995 stat.avgPvsEntries = 0.0f; 1994 1996 stat.avgFilteredPvs = 0.0f; 1997 stat.avgFilteredPvsEntries = 0.0f; 1995 1998 stat.avgFilterContribution = 0.0f; 1996 1999 stat.avgFilterRadius = 0; … … 2016 2019 if (viewcell->GetValid()) { 2017 2020 const float pvsCost = mViewCellsTree->GetPvsCost(viewcell); 2018 2021 2019 2022 if (pvsCost < stat.minPvs) 2020 2023 stat.minPvs = pvsCost; … … 2024 2027 stat.avgPvs += pvsCost; 2025 2028 2029 const float pvsEntries = mViewCellsTree->GetPvsEntries(viewcell); 2030 stat.avgPvsEntries += pvsEntries; 2031 2026 2032 2027 2033 if (mPerViewCellStat[i].pvsSize > 0.0f) … … 2037 2043 if (evaluateFilter) { 2038 2044 ObjectPvs filteredPvs; 2045 2039 2046 PvsFilterStatistics fstat = ApplyFilter2(viewcell, 2040 2047 false, … … 2043 2050 2044 2051 float filteredCost = filteredPvs.EvalPvsCost(); 2052 2045 2053 stat.avgFilteredPvs += filteredCost; 2054 stat.avgFilteredPvsEntries += filteredPvs.GetSize(); 2055 2046 2056 stat.avgFilterContribution += filteredCost - pvsCost; 2047 2057 … … 2066 2076 if (stat.viewcells) { 2067 2077 stat.avgPvs/=stat.viewcells; 2078 stat.avgPvsEntries/=stat.viewcells; 2068 2079 stat.avgFilteredPvs/=stat.viewcells; 2069 2080 stat.avgFilterContribution/=stat.viewcells; … … 2089 2100 GetPvsStatistics(pvsStat); 2090 2101 s<<"#AVG_PVS\n"<<pvsStat.avgPvs<<endl; 2102 s<<"#AVG_ENTRIES_PVS\n"<<pvsStat.avgPvsEntries<<endl; 2091 2103 s<<"#AVG_FILTERED_PVS\n"<<pvsStat.avgFilteredPvs<<endl; 2104 s<<"#AVG_FILTERED_ENTRIES_PVS\n"<<pvsStat.avgFilteredPvsEntries<<endl; 2092 2105 s<<"#AVG_FILTER_CONTRIBUTION\n"<<pvsStat.avgFilterContribution<<endl; 2093 2106 s<<"#AVG_FILTER_RADIUS\n"<<pvsStat.avgFilterRadius<<endl; … … 2991 3004 objects.clear(); 2992 3005 // $$ warning collect objects takes only unmailed ones! 2993 CollectObjects(box, objects); 3006 if (mUseKdPvsAfterFiltering) { 3007 float area = GetPreprocessor()->mKdTree->GetBox().SurfaceArea()*KD_PVS_AREA; 3008 GetPreprocessor()->mKdTree->CollectKdObjects(box, objects, area); 3009 } else 3010 CollectObjects(box, objects); 3011 2994 3012 // cout<<"collected objects="<<objects.size()<<endl; 2995 3013 ObjectContainer::const_iterator noi = objects.begin(); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1942 r1974 92 92 float maxPvs; 93 93 float avgPvs; 94 float avgPvsEntries; 95 94 96 float avgFilteredPvs; 97 float avgFilteredPvsEntries; 98 95 99 float avgFilterContribution; 96 100 float avgFilterRadius; … … 775 779 776 780 bool mUseKdPvs; 781 bool mUseKdPvsAfterFiltering; 777 782 778 783 MixtureDistribution *mMixtureDistribution; -
GTP/trunk/Lib/Vis/Preprocessing/src/default.env
r1967 r1974 36 36 } 37 37 38 38 39 Preprocessor { 39 totalSamples 1000000040 totalSamples 250000000 40 41 samplesPerPass 1000000 41 42 # initialSamples 2000000 … … 50 51 rayCastMethod 1 51 52 52 type sampling53 # type sampling 53 54 # type vss 54 55 # type rss 55 #type combined56 type combined 56 57 # type render 57 58 detectEmptyViewSpace true … … 196 197 ViewCells { 197 198 useKdPvs true 199 useKdPvsAfterFiltering true 198 200 # samples used for view cell construction 199 201 Construction { -
GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro
r1952 r1974 111 111 Trackball.cpp ObjExporter.cpp SubdivisionCandidate.cpp \ 112 112 Mailable.cpp \ 113 CombinedPreprocessor.cpp 113 CombinedPreprocessor.cpp Vector2.cpp 114 114 115 115 SOURCES += BoostPreprocessorThread.cpp -
GTP/trunk/Lib/Vis/Preprocessing/src/run_test2
r1966 r1974 29 29 VIEWCELLS=../data/vienna/vienna_cropped-gradient-viewcells.xml.gz 30 30 31 PREFIX=../work/plots/osp 2-1e531 PREFIX=../work/plots/osp-1e5 32 32 33 33 #SCENE=../data/atlanta/atlanta2.x3d … … 36 36 37 37 38 $COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \39 -preprocessor_visibility_file=$PREFIX-r-reference.xml \40 -view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-r-reference.log \41 -preprocessor_histogram_file=$PREFIX-r-reference.hlog38 # $COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 39 # -preprocessor_visibility_file=$PREFIX-r-reference.xml \ 40 # -view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-r-reference.log \ 41 # -preprocessor_histogram_file=$PREFIX-r-reference.hlog 42 42 43 43 # $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 44 # -rss_distributions=direction -view_cells_filter_max_size=1 \45 # -preprocessor_visibility_file=$PREFIX-r-reference-global.xml \46 # -preprocessor_stats=$PREFIX-r-reference-global.log \47 # -preprocessor_histogram_file=$PREFIX-r-reference-global.hlog44 # -rss_distributions=direction -view_cells_filter_max_size=1 \ 45 # -preprocessor_visibility_file=$PREFIX-r-reference-global.xml \ 46 # -preprocessor_stats=$PREFIX-r-reference-global.log \ 47 # -preprocessor_histogram_file=$PREFIX-r-reference-global.hlog 48 48 49 # $COMMAND-scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \50 #-rss_distributions=mutation+object_direction+spatial -view_cells_filter_max_size=1 \51 # -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4c.xml \52 # -preprocessor_stats=$PREFIX-i-mixed-b1-n4c.log \53 # -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n4c.hlog49 $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 50 -rss_distributions=mutation+object_direction+spatial -view_cells_filter_max_size=1 \ 51 -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4e.xml \ 52 -preprocessor_stats=$PREFIX-i-mixed-b1-n4e.log \ 53 -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n4e.hlog 54 54 55 55 # $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
Note: See TracChangeset
for help on using the changeset viewer.