00001 #ifndef STRATIFIEDSAMPLEGENERATOR_H
00002 #define STRATIFIEDSAMPLEGENERATOR_H
00003
00004 #include "SampleGenerator.h"
00005
00011 class StratifiedSampleGenerator : public SampleGenerator
00012 {
00013 public:
00014 void samples(int n, float u[], float v[], float weight[]) const
00015 {
00016 int x = static_cast<int>(floorf(sqrtf(n)));
00017 assert(x*x == n);
00018
00019
00020 float size = 1.0/n;
00021 for (int i=0; i < x; i++)
00022 {
00023 for (int j=0; j < x; j++)
00024 {
00025 if (i*x+j >= n)
00026 return;
00027 u[i*x+j] = static_cast<float>(i)/x + frand()*size;
00028 v[i*x+j] = static_cast<float>(j)/x + frand()*size;
00029 weight[i*x+j] = 1.0 / float(n);
00030 }
00031 }
00032 }
00033 };
00034
00035 #endif