Changeset 2726 for GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
- Timestamp:
- 05/30/08 02:37:07 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r2698 r2726 54 54 55 55 int 56 SamplingStrategy::GenerateSamples(const int number, 57 SimpleRayContainer &rays) 56 SamplingStrategy::GenerateSamples(int number, 57 SimpleRayContainer &rays, 58 int &invalidSamples) 58 59 { 59 60 SimpleRay ray; 60 int samples = 0; 61 int i = 0; 62 const int maxTries = 20; 61 int oldSamples = (int)rays.size(); 62 63 static const int maxTries = 20; 64 63 65 // tmp changed matt. Q: should one rejected sample 64 66 // terminate the whole method? 65 for ( ; i < number; i++)67 for (int i = 0; i < number; ++ i) 66 68 { 67 int j = 0; 68 bool sampleGenerated = false; 69 70 for (j = 0; !sampleGenerated && (j < maxTries); ++ j) 69 for (int j = 0; j < maxTries; ++ j) 71 70 { 72 sampleGenerated = GenerateSample(ray); 73 74 if (sampleGenerated) 71 if (GenerateSample(ray)) 75 72 { 76 ++ samples;77 73 rays.push_back(ray); 78 //cout << "d " << ray.mDirection << " ";74 break; 79 75 } 76 cerr<<"x"; 77 ++ invalidSamples; 80 78 } 81 79 } 82 80 83 return samples;81 return (int)rays.size() - oldSamples; 84 82 } 85 83 … … 722 720 723 721 int 724 MixtureDistribution::GenerateSamples(const int number, 725 SimpleRayContainer &rays) 722 MixtureDistribution::GenerateSamples(int number, 723 SimpleRayContainer &rays, 724 int &invalidSamples) 726 725 { 727 726 for (int i=0; i < mDistributions.size(); i++) 728 727 mDistributions[i]->mGeneratedRays = 0; 729 728 730 return SamplingStrategy::GenerateSamples(number, rays );729 return SamplingStrategy::GenerateSamples(number, rays, invalidSamples); 731 730 } 732 731 … … 804 803 bool ViewCellBasedDistribution::GenerateSample(SimpleRay &ray) 805 804 { 806 Vector3 origin, direction;807 808 Vector3 point;809 Vector3 normal;810 811 float r[2];812 //for (int i=0; i < 2; i++)813 // r[i] = RandomValue(0, 1);814 815 805 sHalton.GetNext(2, r); 816 817 806 direction = UniformRandomVector(r[0], r[1]); 807 808 #if 0 818 809 const float c = Magnitude(direction); 819 810 811 if (!((c < 1.00001f) && (c > 0.999999f))) 812 cerr << "len wrong" << endl; 820 813 if (c <= Limits::Small) 821 814 return false; 822 815 823 816 direction *= 1.0f / c; 817 #endif 824 818 825 819 // get point on view cell surface 826 if ( 0)820 if (1) 827 821 { 828 822 //mViewCell->GetRandomEdgePoint(origin, normal); 829 mViewCell->GetRandomSurfacePoint(origin, normal);823 origin = mViewCell->GetBox().GetRandomSurfacePoint(); 830 824 831 825 // move a little bit back to avoid piercing through walls 832 826 // that bound the view cell 833 if (0)origin -= 0.01f * normal;827 //origin -= 0.01f * normal; 834 828 } 835 829 else 836 830 origin = mViewCell->GetBox().GetUniformRandomSurfacePoint(); 837 831 838 //direction = point - origin; 839 840 // $$ jb the pdf is yet not correct for all sampling methods! 841 const float pdf = 1.0f; 832 static const float pdf = 1.0f; 842 833 843 834 ray = SimpleRay(origin, direction, VIEWCELL_BASED_DISTRIBUTION, pdf);
Note: See TracChangeset
for help on using the changeset viewer.