00001 /*************************************************************************** 00002 * Copyright (C) 1998-2007 by authors (see AUTHORS.txt ) * 00003 * * 00004 * This file is part of Lux Renderer. * 00005 * * 00006 * Lux Renderer is free software; you can redistribute it and/or modify * 00007 * it under the terms of the GNU General Public License as published by * 00008 * the Free Software Foundation; either version 3 of the License, or * 00009 * (at your option) any later version. * 00010 * * 00011 * Lux Renderer is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00018 * * 00019 * This project is based on PBRT ; see http://www.pbrt.org * 00020 * Lux Renderer website : http://www.luxrender.org * 00021 ***************************************************************************/ 00022 00023 // NOTE - Radiance - currently disabled due to reimplementation of pixelsampling, will fix 00024 00025 /* 00026 // stratified.cpp* 00027 #include "stratified.h" 00028 #include "vegas.h" 00029 // Lux (copy) constructor 00030 StratifiedSampler* StratifiedSampler::clone() const 00031 { 00032 return new StratifiedSampler(*this); 00033 } 00034 // StratifiedSampler Method Definitions 00035 StratifiedSampler::StratifiedSampler(int xstart, int xend, 00036 int ystart, int yend, int xs, int ys, bool jitter, string pixelsampler) 00037 : Sampler(xstart, xend, ystart, yend, xs * ys) { 00038 jitterSamples = jitter; 00039 xPos = xPixelStart; 00040 yPos = yPixelStart; 00041 xPixelSamples = xs; 00042 yPixelSamples = ys; 00043 00044 fs_progressive = prog; 00045 00046 // Allocate storage for a pixel's worth of stratified samples 00047 imageSamples = (float *)AllocAligned(5 * xPixelSamples * 00048 yPixelSamples * sizeof(float)); 00049 lensSamples = 00050 imageSamples + 2 * xPixelSamples * yPixelSamples; 00051 timeSamples = 00052 lensSamples + 2 * xPixelSamples * yPixelSamples; 00053 // Generate stratified camera samples for (_xPos_,_yPos_) 00054 StratifiedSample2D(imageSamples, 00055 xPixelSamples, yPixelSamples, 00056 jitterSamples); 00057 StratifiedSample2D(lensSamples, 00058 xPixelSamples, yPixelSamples, 00059 jitterSamples); 00060 StratifiedSample1D(timeSamples, xPixelSamples*yPixelSamples, 00061 jitterSamples); 00062 // Shift stratified image samples to pixel coordinates 00063 for (int o = 0; 00064 o < 2 * xPixelSamples * yPixelSamples; 00065 o += 2) { 00066 imageSamples[o] += xPos; 00067 imageSamples[o+1] += yPos; 00068 } 00069 // Decorrelate sample dimensions 00070 Shuffle(lensSamples, xPixelSamples*yPixelSamples, 2); 00071 Shuffle(timeSamples, xPixelSamples*yPixelSamples, 1); 00072 samplePos = 0; 00073 } 00074 00075 bool StratifiedSampler::GetNextSample(Sample *sample, u_int *use_pos) { 00076 // Compute new set of samples if needed for next pixel 00077 if (samplePos == xPixelSamples * yPixelSamples) { 00078 if(fs_progressive) { 00079 // Progressive film sampling (random) 00080 xPos = xPixelStart + 00081 Ceil2Int( lux::random::floatValue() * xPixelEnd ); 00082 yPos = yPixelStart + 00083 Ceil2Int( lux::random::floatValue() * yPixelEnd ); 00084 } else { 00085 // Linear/finite film sampling 00086 // Advance to next pixel for stratified sampling 00087 if (++xPos == xPixelEnd) { 00088 xPos = xPixelStart; 00089 ++yPos; 00090 } 00091 if (yPos == yPixelEnd) 00092 return false; 00093 } 00094 // Generate stratified camera samples for (_xPos_,_yPos_) 00095 StratifiedSample2D(imageSamples, 00096 xPixelSamples, yPixelSamples, 00097 jitterSamples); 00098 StratifiedSample2D(lensSamples, 00099 xPixelSamples, yPixelSamples, 00100 jitterSamples); 00101 StratifiedSample1D(timeSamples, xPixelSamples*yPixelSamples, 00102 jitterSamples); 00103 // Shift stratified image samples to pixel coordinates 00104 for (int o = 0; 00105 o < 2 * xPixelSamples * yPixelSamples; 00106 o += 2) { 00107 imageSamples[o] += xPos; 00108 imageSamples[o+1] += yPos; 00109 } 00110 // Decorrelate sample dimensions 00111 Shuffle(lensSamples, xPixelSamples*yPixelSamples, 2); 00112 Shuffle(timeSamples, xPixelSamples*yPixelSamples, 1); 00113 samplePos = 0; 00114 } 00115 // Return next _StratifiedSampler_ sample point 00116 sample->imageX = imageSamples[2*samplePos]; 00117 sample->imageY = imageSamples[2*samplePos+1]; 00118 sample->lensU = lensSamples[2*samplePos]; 00119 sample->lensV = lensSamples[2*samplePos+1]; 00120 sample->time = timeSamples[samplePos]; 00121 // Generate stratified samples for integrators 00122 for (u_int i = 0; i < sample->n1D.size(); ++i) 00123 LatinHypercube(sample->oneD[i], sample->n1D[i], 1); 00124 for (u_int i = 0; i < sample->n2D.size(); ++i) 00125 LatinHypercube(sample->twoD[i], sample->n2D[i], 2); 00126 ++samplePos; 00127 return true; 00128 } 00129 Sampler* StratifiedSampler::CreateSampler(const ParamSet ¶ms, const Film *film) { 00130 bool jitter = params.FindOneBool("jitter", true); 00131 // Initialize common sampler parameters 00132 int xstart, xend, ystart, yend; 00133 film->GetSampleExtent(&xstart, &xend, &ystart, ¥d); 00134 int xsamp = params.FindOneInt("xsamples", 2); 00135 int ysamp = params.FindOneInt("ysamples", 2); 00136 bool prog = params.FindOneBool("progressive", false); 00137 return new StratifiedSampler(xstart, xend, ystart, yend, xsamp, ysamp, 00138 jitter, prog); 00139 } 00140 */