00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _LUXRAYS_SPECTRUM_H
00024 #define _LUXRAYS_SPECTRUM_H
00025
00026 #include <ostream>
00027
00028 namespace luxrays {
00029
00030 class Spectrum {
00031 public:
00032
00033 Spectrum(float _r = 0.f, float _g = 0.f, float _b = 0.f)
00034 : r(_r), g(_g), b(_b) {
00035 }
00036
00037 Spectrum operator+(const Spectrum &v) const {
00038 return Spectrum(r + v.r, g + v.g, b + v.b);
00039 }
00040
00041 Spectrum operator*(const Spectrum &v) const {
00042 return Spectrum(r * v.r, g * v.g, b * v.b);
00043 }
00044
00045 Spectrum & operator*=(const Spectrum &v) {
00046 r *= v.r;
00047 g *= v.g;
00048 b *= v.b;
00049 return *this;
00050 }
00051
00052 Spectrum & operator+=(const Spectrum &v) {
00053 r += v.r;
00054 g += v.g;
00055 b += v.b;
00056 return *this;
00057 }
00058
00059 Spectrum operator-(const Spectrum &v) const {
00060 return Spectrum(r - v.r, g - v.g, b - v.b);
00061 }
00062
00063 Spectrum & operator-=(const Spectrum &v) {
00064 r -= v.r;
00065 g -= v.g;
00066 b -= v.b;
00067 return *this;
00068 }
00069
00070 bool operator==(const Spectrum &v) const {
00071 return r == v.r && g == v.g && b == v.b;
00072 }
00073
00074 Spectrum operator*(float f) const {
00075 return Spectrum(f*r, f*g, f * b);
00076 }
00077
00078 Spectrum & operator*=(float f) {
00079 r *= f;
00080 g *= f;
00081 b *= f;
00082 return *this;
00083 }
00084
00085 Spectrum operator/(float f) const {
00086 float inv = 1.f / f;
00087 return Spectrum(r * inv, g * inv, b * inv);
00088 }
00089
00090 Spectrum & operator/=(float f) {
00091 float inv = 1.f / f;
00092 r *= inv;
00093 g *= inv;
00094 b *= inv;
00095 return *this;
00096 }
00097
00098 Spectrum operator-() const {
00099 return Spectrum(-r, -g, -b);
00100 }
00101
00102 float operator[](int i) const {
00103 return (&r)[i];
00104 }
00105
00106 float &operator[](int i) {
00107 return (&r)[i];
00108 }
00109
00110 float Filter() const {
00111 return Max<float>(r, Max<float>(g, b));
00112 }
00113
00114 bool Black() const {
00115 return (r == 0.f) && (g == 0.f) && (b == 0.f);
00116 }
00117
00118 bool IsNaN() const {
00119 return (isnan(r) || isnan(g) || isnan(b));
00120 }
00121
00122 float r, g, b;
00123 };
00124
00125 inline std::ostream &operator<<(std::ostream &os, const Spectrum &v) {
00126 os << "Spectrum[" << v.r << ", " << v.g << ", " << v.b << "]";
00127 return os;
00128 }
00129
00130 inline Spectrum operator*(float f, const Spectrum &v) {
00131 return v * f;
00132 }
00133
00134 inline Spectrum Exp(const Spectrum &s) {
00135 return Spectrum(expf(s.r), expf(s.g), expf(s.b));
00136 }
00137
00138 }
00139
00140 #endif