00001 /*************************************************************************** 00002 * Copyright (C) 1998-2010 by authors (see AUTHORS.txt ) * 00003 * * 00004 * This file is part of LuxRays. * 00005 * * 00006 * LuxRays 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 * LuxRays 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 * LuxRays website: http://www.luxrender.net * 00020 ***************************************************************************/ 00021 00022 #ifndef _SAMPLEBUFFER_H 00023 #define _SAMPLEBUFFER_H 00024 00025 #include "luxrays/core/pixel/spectrum.h" 00026 00027 namespace luxrays { 00028 00029 typedef struct { 00030 float screenX, screenY; 00031 Spectrum radiance; 00032 } SampleBufferElem; 00033 00034 class SampleBuffer { 00035 public: 00036 SampleBuffer(const size_t bufferSize) : size(bufferSize) { 00037 samples = new SampleBufferElem[size]; 00038 Reset(); 00039 } 00040 virtual ~SampleBuffer() { 00041 delete[] samples; 00042 } 00043 00044 void Reset() { currentFreeSample = 0; }; 00045 bool IsFull() const { return (currentFreeSample >= size); } 00046 00047 void SplatSample(const float scrX, const float scrY, const Spectrum &radiance) { 00048 // Safety check 00049 if (!radiance.IsNaN()) { 00050 SampleBufferElem *s = &samples[currentFreeSample++]; 00051 00052 s->screenX = scrX; 00053 s->screenY = scrY; 00054 s->radiance = radiance; 00055 }/* else { 00056 cerr << "Internal error: NaN in SampleBuffer::SplatSample()" << endl; 00057 }*/ 00058 } 00059 00060 SampleBufferElem *GetSampleBuffer() const { return samples; } 00061 00062 size_t GetSampleCount() const { return currentFreeSample; } 00063 size_t GetSize() const { return size; } 00064 00065 private: 00066 size_t size; 00067 size_t currentFreeSample; 00068 00069 SampleBufferElem *samples; 00070 }; 00071 00072 } 00073 00074 #endif /* _SAMPLEBUFFER_H */
1.6.3