- Timestamp:
- 01/18/07 10:25:29 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r1984 r1989 9 9 10 10 11 // $$JB HACK 12 #define KD_PVS_AREA (1e-5f) 11 13 12 14 namespace GtpVisibilityPreprocessor { … … 106 108 delete splitCandidates; 107 109 110 float area = GetBox().SurfaceArea()*KD_PVS_AREA; 111 112 SetPvsTerminationNodes(area); 113 108 114 return true; 109 115 } … … 828 834 void 829 835 KdTree::CollectKdObjects(const AxisAlignedBox3 &box, 830 ObjectContainer &objects, 831 const float maxArea 836 ObjectContainer &objects 832 837 ) 833 838 { … … 839 844 KdNode *node = nodeStack.top(); 840 845 nodeStack.pop(); 841 if (node->IsLeaf() || (GetSurfaceArea(node) <= maxArea) ){846 if (node->IsLeaf() || node->mPvsTermination == 1) { 842 847 Intersectable *object = GetOrCreateKdIntersectable(node); 843 848 if (!object->Mailed()) { … … 1425 1430 } 1426 1431 1432 float area = GetBox().SurfaceArea()*KD_PVS_AREA; 1433 1434 SetPvsTerminationNodes(area); 1435 1427 1436 Debug << mStat << endl; 1428 1437 … … 1444 1453 1445 1454 return node->mIntersectable; 1455 } 1456 1457 1458 void 1459 KdTree::SetPvsTerminationNodes( 1460 const float maxArea) 1461 { 1462 stack<KdNode *> nodeStack; 1463 1464 nodeStack.push(mRoot); 1465 1466 while (!nodeStack.empty()) { 1467 KdNode *node = nodeStack.top(); 1468 nodeStack.pop(); 1469 1470 node->mPvsTermination = 0; 1471 if (node->IsLeaf() || (GetSurfaceArea(node) <= maxArea) ) { 1472 node->mPvsTermination = 1; 1473 // create dummy kd intersectable 1474 Intersectable *object = GetOrCreateKdIntersectable(node); 1475 } else { 1476 KdInterior *interior = (KdInterior *)node; 1477 nodeStack.push(interior->mFront); 1478 nodeStack.push(interior->mBack); 1479 } 1480 } 1481 } 1482 1483 KdNode * 1484 KdTree::GetPvsNode(const Vector3 &point) const 1485 { 1486 KdNode *node = mRoot; 1487 1488 while (node->mPvsTermination == 0 ) { 1489 KdInterior *inter = (KdInterior *)node; 1490 if (point[inter->mAxis] < inter->mPosition) 1491 node = inter->mBack; 1492 else 1493 node = inter->mFront; 1494 } 1495 1496 return node; 1446 1497 } 1447 1498 -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r1974 r1989 133 133 but allows various optimizations of tree traversal algorithms */ 134 134 KdInterior *mParent; 135 int mDepth; 135 short mDepth; 136 short mPvsTermination; 136 137 }; 137 138 … … 344 345 KdIntersectable *GetOrCreateKdIntersectable(KdNode *node); 345 346 347 348 void 349 SetPvsTerminationNodes( 350 const float maxArea); 351 352 KdNode * 353 GetPvsNode(const Vector3 &point) const; 354 355 346 356 void 347 357 CollectKdObjects(const AxisAlignedBox3 &box, 348 ObjectContainer &objects, 349 const float maxArea 358 ObjectContainer &objects 350 359 ); 351 360 -
GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
r1984 r1989 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.2) on: po 15. I 21:59:1920073 # Generated by qmake (2.00a) (Qt 4.1.2) on: st 17. I 15:41:45 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/Ray.h
r1974 r1989 321 321 short mType; 322 322 short mDistribution; 323 // generator Id -> relative to the generating distribution! 324 int mGeneratorId; 323 325 float mPdf; 324 326 -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r1984 r1989 282 282 hitA.mObject, 283 283 mPreprocessor.mPass, 284 simpleRay.mPdf); 284 simpleRay.mPdf 285 ); 285 286 286 287 if (validA) … … 288 289 289 290 vssRay->mDistribution = simpleRay.mDistribution; 291 vssRay->mGeneratorId = simpleRay.mGeneratorId; 292 290 293 vssRays.push_back(vssRay); 291 294 ++ hits; … … 311 314 312 315 vssRay->mDistribution = simpleRay.mDistribution; 316 vssRay->mGeneratorId = simpleRay.mGeneratorId; 313 317 vssRays.push_back(vssRay); 314 318 ++ hits; -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r1986 r1989 6 6 #include "AxisAlignedBox3.h" 7 7 #include "RssTree.h" 8 #include "Vector2.h" 9 #include "RndGauss.h" 8 #include "Mutation.h" 10 9 11 10 namespace GtpVisibilityPreprocessor { 12 13 #define MUTATION_USE_CDF 014 15 11 16 12 //HaltonSequence SamplingStrategy::sHalton; … … 48 44 // tmp changed matt. Q: should one rejected sample 49 45 // terminate the whole method? 50 if (0) 51 { 52 for (; i < number; i++) { 53 if (!GenerateSample(ray)) 54 return i; 55 rays.push_back(ray); 56 } 57 } 58 else 59 { 60 for (; i < number; i++) 61 { 62 int j = 0; 63 bool sampleGenerated = false; 64 65 for (j = 0; !sampleGenerated && (j < maxTries); ++ j) 66 { 67 sampleGenerated = GenerateSample(ray); 68 69 if (sampleGenerated) 70 { 71 ++ samples; 72 rays.push_back(ray); 73 } 74 } 75 } 76 } 77 46 for (; i < number; i++) 47 { 48 int j = 0; 49 bool sampleGenerated = false; 50 51 for (j = 0; !sampleGenerated && (j < maxTries); ++ j) 52 { 53 sampleGenerated = GenerateSample(ray); 54 55 if (sampleGenerated) 56 { 57 ++ samples; 58 rays.push_back(ray); 59 } 60 } 61 } 62 63 78 64 return samples; 79 65 } … … 686 672 } 687 673 688 void689 MutationBasedDistribution::Update(VssRayContainer &vssRays)690 {691 // for (int i=0; i < mRays.size(); i++)692 // cout<<mRays[i].mSamples<<" ";693 // cout<<endl;694 cerr<<"Muattion update..."<<endl;695 cerr<<"rays = "<<mRays.size()<<endl;696 if (mRays.size()) {697 cerr<<"Oversampling factors = "<<698 GetEntry(0).mSamples<<" "<<699 GetEntry(1).mSamples<<" "<<700 GetEntry(2).mSamples<<" "<<701 GetEntry(3).mSamples<<" "<<702 GetEntry(4).mSamples<<" "<<703 GetEntry(5).mSamples<<" ... "<<704 GetEntry(mRays.size()-6).mSamples<<" "<<705 GetEntry(mRays.size()-5).mSamples<<" "<<706 GetEntry(mRays.size()-4).mSamples<<" "<<707 GetEntry(mRays.size()-3).mSamples<<" "<<708 GetEntry(mRays.size()-2).mSamples<<" "<<709 GetEntry(mRays.size()-1).mSamples<<endl;710 }711 int contributingRays = 0;712 for (int i=0; i < vssRays.size(); i++) {713 if (vssRays[i]->mPvsContribution) {714 contributingRays++;715 if (mRays.size() < mMaxRays) {716 VssRay *newRay = new VssRay(*vssRays[i]);717 // add this ray718 newRay->Ref();719 mRays.push_back(RayEntry(newRay));720 } else {721 // unref the old ray722 *mRays[mBufferStart].mRay = *vssRays[i];723 mRays[mBufferStart].mSamples = 0;724 // mRays[mBufferStart] = RayEntry(newRay);725 mBufferStart++;726 if (mBufferStart >= mMaxRays)727 mBufferStart = 0;728 }729 }730 }731 732 float pContributingRays = contributingRays/(float)vssRays.size();733 float importance = 1.0f; //sqr(1.0f/(pContributingRays + 1e-5));734 // set this values for last contributingRays735 int index = mBufferStart - 1;736 737 for (int i=0; i < contributingRays; i++, index--) {738 if (index < 0)739 index = mRays.size()-1;740 mRays[index].mImportance = importance;741 }742 743 #if MUTATION_USE_CDF744 // compute cdf745 mRays[0].mCdf = mRays[0].mImportance/(mRays[0].mSamples+1);746 for (int i=1; i < mRays.size(); i++)747 mRays[i].mCdf = mRays[i-1].mCdf + mRays[i].mImportance/(mRays[i].mSamples+1);748 749 float scale = 1.0f/mRays[i-1].mCdf;750 for (i=0; i < mRays.size(); i++) {751 mRays[i].mCdf *= scale;752 }753 #endif754 755 cout<<"Importance = "<<756 GetEntry(0).mImportance<<" "<<757 GetEntry(mRays.size()-1).mImportance<<endl;758 759 cerr<<"Mutation update done."<<endl;760 }761 762 763 Vector3764 MutationBasedDistribution::ComputeOriginMutation(const VssRay &ray,765 const Vector3 &U,766 const Vector3 &V,767 const Vector2 vr2,768 const float radius769 )770 {771 #if 0772 Vector3 v;773 if (d.DrivingAxis() == 0)774 v = Vector3(0, r[0]-0.5f, r[1]-0.5f);775 else776 if (d.DrivingAxis() == 1)777 v = Vector3(r[0]-0.5f, 0, r[1]-0.5f);778 else779 v = Vector3(r[0]-0.5f, r[1]-0.5f, 0);780 return v*(2*radius);781 #endif782 #if 0783 return (U*(r[0] - 0.5f) + V*(r[1] - 0.5f))*(2*radius);784 #endif785 786 787 // Output random variable788 Vector2 gaussvec2;789 790 // Here we apply transform to gaussian, so 2D bivariate791 // normal distribution792 // float sigma = ComputeSigmaFromRadius(radius);793 float sigma = radius;794 GaussianOn2D(vr2,795 sigma, // input796 gaussvec2); // output797 798 799 // Here we tranform the point correctly to 3D space using base800 // vectors of the 3D space defined by the direction801 Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V;802 803 // cout<<shift<<endl;804 return shift;805 }806 807 Vector3808 MutationBasedDistribution::ComputeTerminationMutation(const VssRay &ray,809 const Vector3 &U,810 const Vector3 &V,811 const Vector2 vr2,812 const float radius813 )814 {815 #if 0816 Vector3 v;817 // mutate the termination818 if (d.DrivingAxis() == 0)819 v = Vector3(0, r[2]-0.5f, r[3]-0.5f);820 else821 if (d.DrivingAxis() == 1)822 v = Vector3(r[2]-0.5f, 0, r[3]-0.5f);823 else824 v = Vector3(r[2]-0.5f, r[3]-0.5f, 0);825 826 // Vector3 nv;827 828 // if (Magnitude(v) > Limits::Small)829 // nv = Normalize(v);830 // else831 // nv = v;832 833 // v = nv*size + v*size;834 835 return v*(4.0f*radius);836 #endif837 #if 0838 return (U*(vr2.xx - 0.5f) + V*(vr2.yy - 0.5f))*(4.0f*radius);839 #endif840 Vector2 gaussvec2;841 #if 1842 float sigma = radius;843 GaussianOn2D(vr2,844 sigma, // input845 gaussvec2); // output846 Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V;847 // cout<<shift<<endl;848 return shift;849 #endif850 #if 0851 // Here we estimate standard deviation (sigma) from radius852 float sigma = 1.1f*ComputeSigmaFromRadius(radius);853 Vector3 vr3(vr2.xx, vr2.yy, RandomValue(0,1));854 PolarGaussianOnDisk(vr3,855 sigma,856 radius, // input857 gaussvec2); // output858 859 // Here we tranform the point correctly to 3D space using base860 // vectors of the 3D space defined by the direction861 Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V;862 863 // cout<<shift<<endl;864 return shift;865 #endif866 }867 868 869 bool870 MutationBasedDistribution::GenerateSample(SimpleRay &sray)871 {872 float rr[5];873 874 if (mRays.size() == 0) {875 // use direction based distribution876 Vector3 origin, direction;877 static HaltonSequence halton;878 879 halton.GetNext(5, rr);880 mPreprocessor.mViewCellsManager->GetViewPoint(origin,881 Vector3(rr[0], rr[1], rr[2]));882 883 884 direction = UniformRandomVector(rr[3], rr[4]);885 886 const float pdf = 1.0f;887 sray = SimpleRay(origin, direction, MUTATION_BASED_DISTRIBUTION, pdf);888 889 return true;890 }891 892 int index;893 894 #if !MUTATION_USE_CDF895 // get tail of the buffer896 index = (mLastIndex+1)%mRays.size();897 if (mRays[index].GetSamplingFactor() >898 mRays[mLastIndex].GetSamplingFactor()) {899 // search back for index where this is valid900 index = (mLastIndex - 1 + mRays.size())%mRays.size();901 for (int i=0; i < mRays.size(); i++) {902 903 // if (mRays[index].mSamples > mRays[mLastIndex].mSamples)904 // break;905 if (mRays[index].GetSamplingFactor() >906 mRays[mLastIndex].GetSamplingFactor() )907 break;908 index = (index - 1 + mRays.size())%mRays.size();909 }910 // go one step back911 index = (index+1)%mRays.size();912 }913 #else914 static HaltonSequence iHalton;915 iHalton.GetNext(1, rr);916 //rr[0] = RandomValue(0,1);917 // use binary search to find index with this cdf918 int l=0, r=mRays.size()-1;919 while(l<r) {920 int i = (l+r)/2;921 if (rr[0] < mRays[i].mCdf )922 r = i;923 else924 l = i+1;925 }926 index = l;927 // if (rr[0] >= mRays[r].mCdf)928 // index = r;929 // else930 // index = l;931 932 933 #endif934 // cout<<index<<" "<<rr[0]<<" "<<mRays[index].mCdf<<" "<<mRays[(index+1)%mRays.size()].mCdf<<endl;935 936 VssRay *ray = mRays[index].mRay;937 mRays[index].mSamples++;938 mLastIndex = index;939 940 mRays[index].mHalton.GetNext(4, rr);941 942 // mutate the origin943 Vector3 d = ray->GetDir();944 945 946 AxisAlignedBox3 box = ray->mTerminationObject->GetBox();947 float objectRadius = 0.5f*Magnitude(box.Diagonal());948 // cout<<objectRadius<<endl;949 if (objectRadius < Limits::Small)950 return false;951 952 // Compute right handed coordinate system from direction953 Vector3 U, V;954 Vector3 nd = Normalize(d);955 nd.RightHandedBase(U, V);956 957 Vector3 origin = ray->mOrigin;958 Vector3 termination = ray->mTermination; //box.Center(); //ray->mTermination; //box.Center();959 960 float radiusExtension = 1.0f;961 // + mRays[index].mSamples/50.0f;962 963 // origin += ComputeOriginMutation(*ray, U, V, Vector2(r[0], r[1]), 0.5f*mOriginMutationSize*radiusExtension);964 origin += ComputeOriginMutation(*ray, U, V,965 Vector2(rr[0], rr[1]),966 objectRadius*radiusExtension);967 termination += ComputeTerminationMutation(*ray, U, V,968 Vector2(rr[2], rr[3]),969 objectRadius*radiusExtension);970 971 Vector3 direction = termination - origin;972 973 if (Magnitude(direction) < Limits::Small)974 return false;975 976 // shift the origin a little bit977 origin += direction*0.5f;978 979 direction.Normalize();980 981 // $$ jb the pdf is yet not correct for all sampling methods!982 const float pdf = 1.0f;983 984 sray = SimpleRay(origin, direction, MUTATION_BASED_DISTRIBUTION, pdf);985 return true;986 }987 988 MutationBasedDistribution::MutationBasedDistribution(Preprocessor &preprocessor989 ) :990 SamplingStrategy(preprocessor)991 {992 mType = MUTATION_BASED_DISTRIBUTION;993 mBufferStart = 0;994 mMaxRays = 500000;995 mRays.reserve(mMaxRays);996 mOriginMutationSize = 10.0f;997 mLastIndex = 0;998 // mOriginMutationSize = Magnitude(preprocessor.mViewCellsManager->999 // GetViewSpaceBox().Diagonal())*1e-3;1000 1001 }1002 674 1003 675 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r1983 r1989 225 225 }; 226 226 227 class MutationBasedDistribution: public SamplingStrategy228 {229 public:230 MutationBasedDistribution(Preprocessor &preprocessor);231 virtual void Update(VssRayContainer &vssRays);232 233 virtual bool RequiresRays() { return true; }234 235 private:236 virtual bool GenerateSample(SimpleRay &ray);237 238 struct RayEntry {239 // halton sequence for generatin gmutations of this ray240 VssRay *mRay;241 int mSamples;242 HaltonSequence mHalton;243 float mImportance;244 float mCdf;245 246 float GetSamplingFactor() const { return mSamples/mImportance; }247 RayEntry() {}248 RayEntry(VssRay *r):mRay(r), mSamples(0), mHalton(), mImportance(1.0f) {}249 };250 251 252 Vector3253 ComputeOriginMutation(const VssRay &ray,254 const Vector3 &U,255 const Vector3 &V,256 const Vector2 vr2,257 const float radius258 );259 260 Vector3261 ComputeTerminationMutation(const VssRay &ray,262 const Vector3 &U,263 const Vector3 &V,264 const Vector2 vr2,265 const float radius266 );267 268 RayEntry &GetEntry(const int index) {269 return mRays[(mBufferStart+index)%mRays.size()];270 }271 272 vector<RayEntry> mRays;273 int mMaxRays;274 float mOriginMutationSize;275 int mBufferStart;276 int mLastIndex;277 };278 227 279 228 class GlobalLinesDistribution: public SamplingStrategy -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1983 r1989 26 26 27 27 28 // $$JB HACK29 #define KD_PVS_AREA (1e-5f)30 28 31 29 #define USE_RAY_LENGTH_AS_CONTRIBUTION 0 … … 330 328 if (mUseKdPvs) 331 329 { 332 float area = GetPreprocessor()->mKdTree->GetBox().SurfaceArea()*KD_PVS_AREA; 333 KdNode *node = GetPreprocessor()->mKdTree->GetNode(isTermination ? 334 ray.mTermination : ray.mOrigin, 335 area); 336 return GetPreprocessor()->mKdTree->GetOrCreateKdIntersectable(node); 330 KdNode *node = GetPreprocessor()->mKdTree->GetPvsNode(isTermination ? 331 ray.mTermination : ray.mOrigin); 332 return GetPreprocessor()->mKdTree->GetOrCreateKdIntersectable(node); 337 333 } 338 334 else 339 {335 { 340 336 return isTermination ? ray.mTerminationObject : ray.mOriginObject; 341 }337 } 342 338 } 343 339 … … 3061 3057 // $$ warning collect objects takes only unmailed ones! 3062 3058 if (mUseKdPvsAfterFiltering) { 3063 float area = GetPreprocessor()->mKdTree->GetBox().SurfaceArea()*KD_PVS_AREA; 3064 GetPreprocessor()->mKdTree->CollectKdObjects(box, objects, area); 3059 GetPreprocessor()->mKdTree->CollectKdObjects(box, objects); 3065 3060 } else 3066 3061 CollectObjects(box, objects); -
GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h
r1966 r1989 32 32 33 33 // Id of the generating SimpleRay 34 int mGenerat ingRayId;34 int mGeneratorId; 35 35 36 36 static int mailID; -
GTP/trunk/Lib/Vis/Preprocessing/src/default.env
r1983 r1989 172 172 maxCostRatio 0.98 173 173 ct_div_ci 0.5 174 maxNodes 200000174 maxNodes 50000 175 175 #500000 176 176 } -
GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro
r1983 r1989 112 112 Mailable.cpp \ 113 113 CombinedPreprocessor.cpp Vector2.cpp GlobalLinesRenderer.cpp \ 114 RenderTexture.cpp 114 RenderTexture.cpp Mutation.cpp 115 115 116 116 SOURCES += BoostPreprocessorThread.cpp -
GTP/trunk/Lib/Vis/Preprocessing/src/run
r1986 r1989 1 1 #!/bin/sh 2 2 3 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish- -preprocessor_use_gl_renderer+ -preprocessor_evaluate_filter- -preprocessor_ray_cast_method= 0"3 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish- -preprocessor_use_gl_renderer+ -preprocessor_evaluate_filter- -preprocessor_ray_cast_method=1" 4 4 5 #SCENE=../data/Pompeii/PompeiiTen.obj6 #VIEWCELLS=../data/Pompeii/pompeii_big-seq-viewcells.xml.gz5 SCENE=../data/Pompeii/PompeiiTen.obj 6 VIEWCELLS=../data/Pompeii/pompeii_big-seq-viewcells.xml.gz 7 7 8 8 #SCENE=../data/artificial/room_with_sphere.obj 9 9 #VIEWCELLS=../data/artificial/simpleHoleViewCell.x3d 10 10 11 SCENE=../data/soda/soda5.dat12 VIEWCELLS=../data/soda/soda5-viewcells.xml11 #SCENE=../data/soda/soda5.dat 12 #VIEWCELLS=../data/soda/soda5-viewcells.xml 13 13 14 14 $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
Note: See TracChangeset
for help on using the changeset viewer.