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 "sampler.h"
00028 #include "integrator.h"
00029 #include "volume.h"
00030
00031
00032 Sampler::~Sampler() {
00033 }
00034
00035
00036 Sampler::Sampler(int xstart, int xend, int ystart, int yend, int spp,
00037 float sopen, float sclose)
00038 : xPixelStart(xstart), xPixelEnd(xend), yPixelStart(ystart),
00039 yPixelEnd(yend), samplesPerPixel(spp), shutterOpen(sopen),
00040 shutterClose(sclose) { }
00041 bool Sampler::ReportResults(Sample *samples, const RayDifferential *rays,
00042 const Spectrum *Ls, const Intersection *isects, int count) {
00043 return true;
00044 }
00045
00046
00047 void Sampler::ComputeSubWindow(int num, int count, int *newXStart,
00048 int *newXEnd, int *newYStart, int *newYEnd) const {
00049
00050 int dx = xPixelEnd - xPixelStart, dy = yPixelEnd - yPixelStart;
00051 int nx = count, ny = 1;
00052 while ((nx & 0x1) == 0 && 2 * dx * ny < dy * nx) {
00053 nx >>= 1;
00054 ny <<= 1;
00055 }
00056 Assert(nx * ny == count);
00057
00058
00059 int xo = num % nx, yo = num / nx;
00060 float tx0 = float(xo) / float(nx), tx1 = float(xo+1) / float(nx);
00061 float ty0 = float(yo) / float(ny), ty1 = float(yo+1) / float(ny);
00062 *newXStart = Floor2Int(Lerp(tx0, xPixelStart, xPixelEnd));
00063 *newXEnd = Floor2Int(Lerp(tx1, xPixelStart, xPixelEnd));
00064 *newYStart = Floor2Int(Lerp(ty0, yPixelStart, yPixelEnd));
00065 *newYEnd = Floor2Int(Lerp(ty1, yPixelStart, yPixelEnd));
00066 }
00067
00068
00069
00070
00071 Sample::Sample(Sampler *sampler, SurfaceIntegrator *surf,
00072 VolumeIntegrator *vol, const Scene *scene) {
00073 if (surf) surf->RequestSamples(sampler, this, scene);
00074 if (vol) vol->RequestSamples(sampler, this, scene);
00075 AllocateSampleMemory();
00076 }
00077
00078
00079 void Sample::AllocateSampleMemory() {
00080
00081 int nPtrs = n1D.size() + n2D.size();
00082 if (!nPtrs) {
00083 oneD = twoD = NULL;
00084 return;
00085 }
00086 oneD = AllocAligned<float *>(nPtrs);
00087 twoD = oneD + n1D.size();
00088
00089
00090 int totSamples = 0;
00091 for (uint32_t i = 0; i < n1D.size(); ++i)
00092 totSamples += n1D[i];
00093 for (uint32_t i = 0; i < n2D.size(); ++i)
00094 totSamples += 2 * n2D[i];
00095
00096
00097 float *mem = AllocAligned<float>(totSamples);
00098 for (uint32_t i = 0; i < n1D.size(); ++i) {
00099 oneD[i] = mem;
00100 mem += n1D[i];
00101 }
00102 for (uint32_t i = 0; i < n2D.size(); ++i) {
00103 twoD[i] = mem;
00104 mem += 2 * n2D[i];
00105 }
00106 }
00107
00108
00109 Sample *Sample::Duplicate(int count) const {
00110 Sample *ret = new Sample[count];
00111 for (int i = 0; i < count; ++i) {
00112 ret[i].n1D = n1D;
00113 ret[i].n2D = n2D;
00114 ret[i].AllocateSampleMemory();
00115 }
00116 return ret;
00117 }
00118
00119