00001 /* 00002 File: Spectrum.h 00003 00004 Function: Provides classes for manipulating spectra 00005 00006 Author: Andrew Willmott 00007 00008 Copyright: (c) 1999-2000, Andrew Willmott 00009 */ 00010 00011 #ifndef __Spectrum__ 00012 #define __Spectrum__ 00013 00014 #include "Geometry.h" 00015 #include "Image.h" 00016 00017 class Spectrum : public Vecf 00018 { 00019 public: 00020 00021 Spectrum() : Vecf(kComponents) 00022 { MakeZero(); }; 00023 Spectrum(const Vecf &v) : Vecf(v) 00024 { Assert(Elts() == kComponents, "bad spectrum"); }; 00025 Spectrum(Float k) : Vecf(kComponents) 00026 { MakeBlock(k); }; 00027 00028 Colour ToCIE_XYZ(); 00029 00030 static Int GetNumComponents() 00031 { return(kComponents); }; 00032 00033 static const Int kComponents; // number of (constant) basis functions 00034 static const Float kStart; // start of spectrum 00035 static const Float kEnd; // end of spectrum 00036 }; 00037 00038 class SpectralCurve 00039 { 00040 public: 00041 virtual ~SpectralCurve(); 00042 00043 operator Spectrum(); 00044 00045 virtual Float Sample(Float lambda) const = 0; 00046 // sample curve at wavelength lambda 00047 virtual Float Integral(Float lambda) const; 00048 // return integral of curve from 0 to lambda 00049 virtual Float MaxCmpt() const; 00050 00051 Void MakeImage(Image &image, ClrReal maxAmplitude = -1.0); 00052 // Plot the spectrum into image. 00053 Colour ToCIE_XYZ(); 00054 // map the spectrum to the CIE XYZ colour system 00055 }; 00056 00057 class RegularSpectralCurve : public SpectralCurve 00058 { 00059 public: 00060 RegularSpectralCurve(Float *sdata, Int start, Int end, Int divisions); 00061 ~RegularSpectralCurve(); 00062 00063 Float Sample(Float lambda) const; 00064 // Float Integral(Float lambda) const; 00065 00066 protected: 00067 Float *data; 00068 Float *accumData; 00069 Int waveDivs; 00070 Float waveStart, waveEnd, waveDelta; 00071 }; 00072 00073 class IrregularSpectralCurve : public SpectralCurve 00074 { 00075 public: 00076 IrregularSpectralCurve(); 00077 IrregularSpectralCurve(Float *amps, Float *wavs, Int divs); 00078 ~IrregularSpectralCurve(); 00079 00080 Float Sample(Float lambda) const; 00081 // Float Integral(Float lambda) const; 00082 00083 IrregularSpectralCurve 00084 &ReadSDFile(FileName filename); 00085 00086 protected: 00087 Float *amplitudes; 00088 Float *accumAmplitudes; 00089 Float *wavelengths; 00090 Int divisions; 00091 }; 00092 00093 // --- CIE colour matching functions ------------------------------------ 00094 00095 extern RegularSpectralCurve kCIE_xbar; 00096 extern RegularSpectralCurve kCIE_ybar; 00097 extern RegularSpectralCurve kCIE_zbar; 00098 00099 // --- useful utilities -------------------------------------------------- 00100 00101 Colour WavelengthToXYZ(ClrReal lambda); 00102 00103 class ChromaticitySpectrum : public SpectralCurve 00104 { 00105 public: 00106 ChromaticitySpectrum(ClrReal x, ClrReal y); 00107 00108 Float Sample(Float lambda) const; 00109 00110 protected: 00111 ClrReal M1, M2; 00112 }; 00113 00114 class BlackBodySpectrum : public SpectralCurve 00115 { 00116 public: 00117 BlackBodySpectrum(Float temperature); 00118 00119 Float Sample(Float lambda) const; 00120 00121 protected: 00122 Float temp; 00123 }; 00124 00125 Void DrawChromaticityImage(Image &image); 00126 00127 #endif