00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LUX_SPD_H
00024 #define LUX_SPD_H
00025
00026 #include "lux.h"
00027 #include "spectrum.h"
00028
00029 namespace lux
00030 {
00031
00032 class SPD {
00033 public:
00034 SPD() {
00035 nSamples = 0;
00036 lambdaMin = lambdaMax = delta = invDelta = 0.;
00037 }
00038 ~SPD() {}
00039
00040
00041 inline float sample(const float lambda) const {
00042 if (nSamples < 1 || lambda < lambdaMin || lambda > lambdaMax)
00043 return 0.f;
00044
00045
00046 const float x = (lambda - lambdaMin) * invDelta;
00047 const int b0 = Floor2Int(x);
00048 const int b1 = min(b0 + 1, nSamples - 1);
00049 const float dx = x - b0;
00050 return Lerp(dx, samples[b0], samples[b1]);
00051 }
00052
00053 inline void sample(u_int n, const float lambda[], float *p) const {
00054 for (u_int i = 0; i < n; ++i) {
00055 if (nSamples < 1 || lambda[i] < lambdaMin || lambda[i] > lambdaMax)
00056 p[i] = 0.f;
00057
00058
00059 const float x = (lambda[i] - lambdaMin) * invDelta;
00060 const int b0 = Floor2Int(x);
00061 const int b1 = min(b0 + 1, nSamples - 1);
00062 const float dx = x - b0;
00063 p[i] = Lerp(dx, samples[b0], samples[b1]);
00064 }
00065 }
00066
00067 void AllocateSamples(int n);
00068 void Normalize();
00069 void Clamp();
00070 void Scale(float s);
00071
00072 protected:
00073 int nSamples;
00074 float lambdaMin, lambdaMax;
00075 float delta, invDelta;
00076 float *samples;
00077
00078 };
00079
00080 }
00081
00082 #endif // LUX_SPD_H