src/StratifiedSampleGenerator.h

Go to the documentation of this file.
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         // create a grid of jittered sample coordinates
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

Generated on Fri Feb 1 00:01:42 2008 for Grayfall by  doxygen 1.5.1