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 // bestcandidate.cpp* 00027 #include "bestcandidate.h" 00028 #include "vegas.h" 00029 // Lux (copy) constructor 00030 BestCandidateSampler* BestCandidateSampler::clone() const 00031 { 00032 return new BestCandidateSampler(*this); 00033 } 00034 // BestCandidateSampler Method Definitions 00035 BestCandidateSampler:: 00036 BestCandidateSampler(int xstart, int xend, 00037 int ystart, int yend, 00038 int pixelSamples) 00039 : Sampler(xstart, xend, ystart, yend, pixelSamples) { 00040 tableWidth = 00041 (float)SQRT_SAMPLE_TABLE_SIZE / sqrtf(pixelSamples); 00042 xTableCorner = float(xPixelStart) - tableWidth; 00043 yTableCorner = float(yPixelStart); 00044 tableOffset = SAMPLE_TABLE_SIZE; 00045 // _BestCandidateSampler_ constructor implementation 00046 oneDSamples = twoDSamples = NULL; 00047 strat2D = NULL; 00048 } 00049 00050 #include "sampledata.h" 00051 bool BestCandidateSampler::GetNextSample(Sample *sample, u_int *use_pos) { 00052 again: 00053 if (tableOffset == SAMPLE_TABLE_SIZE) { 00054 // TODO implement progressive mode - radiance 00055 // Advance to next best-candidate sample table position 00056 tableOffset = 0; 00057 xTableCorner += tableWidth; 00058 if (xTableCorner >= xPixelEnd) { 00059 xTableCorner = float(xPixelStart); 00060 yTableCorner += tableWidth; 00061 if (yTableCorner >= yPixelEnd) 00062 return false; 00063 } 00064 if (!oneDSamples) { 00065 // Initialize sample tables and precompute _strat2D_ values 00066 oneDSamples = new float *[sample->n1D.size()]; 00067 for (u_int i = 0; i < sample->n1D.size(); ++i) { 00068 oneDSamples[i] = (sample->n1D[i] == 1) ? 00069 new float[SAMPLE_TABLE_SIZE] : NULL; 00070 } 00071 twoDSamples = new float *[sample->n2D.size()]; 00072 strat2D = new int[sample->n2D.size()]; 00073 for (u_int i = 0; i < sample->n2D.size(); ++i) { 00074 twoDSamples[i] = (sample->n2D[i] == 1) ? 00075 new float[2 * SAMPLE_TABLE_SIZE] : NULL; 00076 strat2D[i] = 00077 Ceil2Int(sqrtf((float)sample->n2D[i] - .5f)); 00078 } 00079 } 00080 // Update sample shifts 00081 for (int i = 0; i < 3; ++i) 00082 sampleOffsets[i] = lux::random::floatValue(); 00083 // Generate _SAMPLE\_TABLE\_SIZE_-sized tables for single samples 00084 for (u_int i = 0; i < sample->n1D.size(); ++i) 00085 if (sample->n1D[i] == 1) 00086 LDShuffleScrambled1D(SAMPLE_TABLE_SIZE, 1, 00087 oneDSamples[i]); 00088 for (u_int i = 0; i < sample->n2D.size(); ++i) 00089 if (sample->n2D[i] == 1) 00090 LDShuffleScrambled2D(SAMPLE_TABLE_SIZE, 1, 00091 twoDSamples[i]); 00092 } 00093 // Compute raster sample from table 00094 #define WRAP(x) ((x) > 1 ? ((x)-1) : (x)) 00095 sample->imageX = xTableCorner + tableWidth * 00096 sampleTable[tableOffset][0]; 00097 sample->imageY = yTableCorner + tableWidth * 00098 sampleTable[tableOffset][1]; 00099 sample->time = WRAP(sampleOffsets[0] + 00100 sampleTable[tableOffset][2]); 00101 sample->lensU = WRAP(sampleOffsets[1] + 00102 sampleTable[tableOffset][3]); 00103 sample->lensV = WRAP(sampleOffsets[2] + 00104 sampleTable[tableOffset][4]); 00105 // Check sample against crop window, goto _again_ if outside 00106 if (sample->imageX < xPixelStart || 00107 sample->imageX >= xPixelEnd || 00108 sample->imageY < yPixelStart || 00109 sample->imageY >= yPixelEnd) { 00110 ++tableOffset; 00111 goto again; 00112 } 00113 // Compute integrator samples for best-candidate sample 00114 for (u_int i = 0; i < sample->n1D.size(); ++i) { 00115 if (sample->n1D[i] == 1) 00116 sample->oneD[i][0] = oneDSamples[i][tableOffset]; 00117 else 00118 StratifiedSample1D(sample->oneD[i], sample->n1D[i]); 00119 } 00120 for (u_int i = 0; i < sample->n2D.size(); ++i) { 00121 if (sample->n2D[i] == 1) { 00122 sample->twoD[i][0] = twoDSamples[i][2*tableOffset]; 00123 sample->twoD[i][1] = twoDSamples[i][2*tableOffset+1]; 00124 } 00125 else { 00126 StratifiedSample2D(sample->twoD[i], 00127 strat2D[i], 00128 strat2D[i]); 00129 } 00130 } 00131 ++tableOffset; 00132 return true; 00133 } 00134 Sampler* BestCandidateSampler::CreateSampler(const ParamSet ¶ms, const Film *film) { 00135 // Initialize common sampler parameters 00136 int xstart, xend, ystart, yend; 00137 film->GetSampleExtent(&xstart, &xend, &ystart, ¥d); 00138 int nsamp = params.FindOneInt("pixelsamples", 4); 00139 return new BestCandidateSampler(xstart, xend, ystart, yend, nsamp); 00140 } 00141 */