1 #ifndef STRATIFIEDSAMPLEGENERATOR_HXX
 2 #define STRATIFIEDSAMPLEGENERATOR_HXX
 3 
 4 #include "SampleGenerator.hxx"
 5 #include "Randomizer.hxx"
 6 
 7 class StratifiedSampleGenerator : public SampleGenerator 
 8 {
 9 private:
10 	Randomizer randomizer;
11 public:
12 	virtual void GetSamples(int n, float *u, float *v, float *weight)
13 	{    
14 		float stdweight = 1.0f / static_cast<float>(n),
15 		      mf        = sqrtf(static_cast<float>(n));
16 		int   m         = static_cast<int>(mf),
17 		      pos;
18 
19 		for (int i = 0; i < m; ++i)
20 			for (int j = 0; j < m; ++j)
21 			{
22 				pos = i * m + j;
23 				u[pos] = (static_cast<float>(i) + randomizer.drand()) / mf;
24 				v[pos] = (static_cast<float>(j) + randomizer.drand()) / mf;
25 				weight[pos] = stdweight;
26 			}
27 	};
28 
29 	virtual ~StratifiedSampleGenerator(){};
30 };
31 
32 #endif


syntax highlighted by Code2HTML, v. 0.9.1