spectrum.h
#ifndef CMU462_SPECTRUM_H
#define CMU462_SPECTRUM_H
#include "CMU462.h"
#include "color.h"
namespace CMU462 {
class Spectrum {
public:
double r;
double g;
double b;
Spectrum(double r = 0, double g = 0, double b = 0) : r(r), g(g), b(b) {}
Spectrum(const uint8_t *arr);
// operators //
inline Spectrum operator+(const Spectrum &rhs) const {
return Spectrum(r + rhs.r, g + rhs.g, b + rhs.b);
}
inline Spectrum &operator+=(const Spectrum &rhs) {
r += rhs.r;
g += rhs.g;
b += rhs.b;
return *this;
}
inline Spectrum operator*(const Spectrum &rhs) const {
return Spectrum(r * rhs.r, g * rhs.g, b * rhs.b);
}
inline Spectrum &operator*=(const Spectrum &rhs) {
r *= rhs.r;
g *= rhs.g;
b *= rhs.b;
return *this;
}
inline Spectrum operator*(double s) const {
return Spectrum(r * s, g * s, b * s);
}
inline Spectrum &operator*=(double s) {
r *= s;
g *= s;
b *= s;
return *this;
}
inline bool operator==(const Spectrum &rhs) const {
return r == rhs.r && g == rhs.g && b == rhs.b;
}
inline bool operator!=(const Spectrum &rhs) const {
return !operator==(rhs);
}
inline Color toColor() const { return Color(r, g, b, 1); }
static Spectrum fromColor(const Color &c) {
return Spectrum(c.a * c.r, c.a * c.g, c.a * c.b);
}
}; // class Spectrum
// Commutable scalar multiplication
inline Spectrum operator*(double s, const Spectrum &c) { return c * s; }
// Prints components
std::ostream &operator<<(std::ostream &os, const Spectrum &c);
} // namespace CMU462
#endif // CMU462_SPECTRUM_H
CMU462::Spectrum::b
double b
intensity of blue spectrum
Definition: spectrum.h:19
CMU462
Definition: CMU462.h:8
CMU462::Spectrum
Encodes radiance & irradiance values by the intensity of each visible spectrum.
Definition: spectrum.h:15
CMU462::Spectrum::Spectrum
Spectrum(double r=0, double g=0, double b=0)
Parameterized Constructor.
Definition: spectrum.h:28
CMU462::Spectrum::g
double g
intensity of green spectrum
Definition: spectrum.h:18
CMU462::Spectrum::r
double r
intensity of red spectrum
Definition: spectrum.h:17