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
00027 namespace lux
00028 {
00029
00030 class SPD {
00031 public:
00032 SPD() {
00033 nSamples = 0;
00034 lambdaMin = lambdaMax = delta = invDelta = 0.;
00035 samples = NULL;
00036 }
00037 virtual ~SPD() { FreeSamples(); }
00038
00039
00040 inline float sample(const float lambda) const {
00041 if (nSamples < 1 || lambda < lambdaMin || lambda > lambdaMax)
00042 return 0.f;
00043
00044
00045 const float x = (lambda - lambdaMin) * invDelta;
00046 const int b0 = Floor2Int(x);
00047 const int b1 = min(b0 + 1, nSamples - 1);
00048 const float dx = x - b0;
00049 return Lerp(dx, samples[b0], samples[b1]);
00050 }
00051
00052 inline void sample(u_int n, const float lambda[], float *p) const {
00053 for (u_int i = 0; i < n; ++i) {
00054 if (nSamples < 1 || lambda[i] < lambdaMin ||
00055 lambda[i] > lambdaMax) {
00056 p[i] = 0.f;
00057 continue;
00058 }
00059
00060
00061 const float x = (lambda[i] - lambdaMin) * invDelta;
00062 const int b0 = Floor2Int(x);
00063 const int b1 = min(b0 + 1, nSamples - 1);
00064 const float dx = x - b0;
00065 p[i] = Lerp(dx, samples[b0], samples[b1]);
00066 }
00067 }
00068
00069 float Y() const ;
00070 XYZColor ToXYZ() const;
00071 void AllocateSamples(int n);
00072 void FreeSamples();
00073 void Normalize();
00074 void Clamp();
00075 void Scale(float s);
00076 void Whitepoint(float temp);
00077
00078 protected:
00079 int nSamples;
00080 float lambdaMin, lambdaMax;
00081 float delta, invDelta;
00082 float *samples;
00083 };
00084
00085 }
00086
00087 #endif // LUX_SPD_H