00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdafx.h"
00027 #include "samplers/lowdiscrepancy.h"
00028 #include "camera.h"
00029 #include "montecarlo.h"
00030
00031
00032 LDSampler::LDSampler(int xstart, int xend, int ystart, int yend, int ps,
00033 float sopen, float sclose)
00034 : Sampler(xstart, xend, ystart, yend, RoundUpPow2(ps), sopen, sclose) {
00035 xPos = xPixelStart;
00036 yPos = yPixelStart;
00037 if (!IsPowerOf2(ps)) {
00038 Warning("Pixel samples being rounded up to power of 2");
00039 nPixelSamples = RoundUpPow2(ps);
00040 } else
00041 nPixelSamples = ps;
00042 sampleBuf = NULL;
00043 }
00044
00045
00046 LDSampler::~LDSampler() {
00047 delete[] sampleBuf;
00048 }
00049
00050
00051 Sampler *LDSampler::GetSubSampler(int num, int count) {
00052 int x0, x1, y0, y1;
00053 ComputeSubWindow(num, count, &x0, &x1, &y0, &y1);
00054 if (x0 == x1 || y0 == y1) return NULL;
00055 return new LDSampler(x0, x1, y0, y1, nPixelSamples, shutterOpen, shutterClose);
00056 }
00057
00058
00059 int LDSampler::GetMoreSamples(Sample *samples, RNG &rng) {
00060 if (yPos == yPixelEnd) return 0;
00061 if (sampleBuf == NULL)
00062 sampleBuf = new float[LDPixelSampleFloatsNeeded(samples,
00063 nPixelSamples)];
00064 LDPixelSample(xPos, yPos, shutterOpen, shutterClose,
00065 nPixelSamples, samples, sampleBuf, rng);
00066 if (++xPos == xPixelEnd) {
00067 xPos = xPixelStart;
00068 ++yPos;
00069 }
00070 return nPixelSamples;
00071 }
00072
00073
00074 LDSampler *CreateLowDiscrepancySampler(const ParamSet ¶ms, const Film *film,
00075 const Camera *camera) {
00076
00077 int xstart, xend, ystart, yend;
00078 film->GetSampleExtent(&xstart, &xend, &ystart, ¥d);
00079 int nsamp = params.FindOneInt("pixelsamples", 4);
00080 if (PbrtOptions.quickRender) nsamp = 1;
00081 return new LDSampler(xstart, xend, ystart, yend, nsamp,
00082 camera->shutterOpen, camera->shutterClose);
00083 }
00084
00085