CMU462 Library  1.0
15-462/15-662: Computer Graphics (Fall 2015)
spectrum.h
1 #ifndef CMU462_SPECTRUM_H
2 #define CMU462_SPECTRUM_H
3 
4 #include "CMU462.h"
5 #include "color.h"
6 
7 namespace CMU462 {
8 
15 class Spectrum {
16  public:
17  double r;
18  double g;
19  double b;
20 
28  Spectrum(double r = 0, double g = 0, double b = 0) : r(r), g(g), b(b) {}
29 
35  Spectrum(const uint8_t *arr);
36 
37  // operators //
38 
39  inline Spectrum operator+(const Spectrum &rhs) const {
40  return Spectrum(r + rhs.r, g + rhs.g, b + rhs.b);
41  }
42 
43  inline Spectrum &operator+=(const Spectrum &rhs) {
44  r += rhs.r;
45  g += rhs.g;
46  b += rhs.b;
47  return *this;
48  }
49 
50  inline Spectrum operator*(const Spectrum &rhs) const {
51  return Spectrum(r * rhs.r, g * rhs.g, b * rhs.b);
52  }
53 
54  inline Spectrum &operator*=(const Spectrum &rhs) {
55  r *= rhs.r;
56  g *= rhs.g;
57  b *= rhs.b;
58  return *this;
59  }
60 
61  inline Spectrum operator*(double s) const {
62  return Spectrum(r * s, g * s, b * s);
63  }
64 
65  inline Spectrum &operator*=(double s) {
66  r *= s;
67  g *= s;
68  b *= s;
69  return *this;
70  }
71 
72  inline bool operator==(const Spectrum &rhs) const {
73  return r == rhs.r && g == rhs.g && b == rhs.b;
74  }
75 
76  inline bool operator!=(const Spectrum &rhs) const {
77  return !operator==(rhs);
78  }
79 
80  inline Color toColor() const { return Color(r, g, b, 1); }
81 
82  static Spectrum fromColor(const Color &c) {
83  return Spectrum(c.a * c.r, c.a * c.g, c.a * c.b);
84  }
85 
86 }; // class Spectrum
87 
88 // Commutable scalar multiplication
89 inline Spectrum operator*(double s, const Spectrum &c) { return c * s; }
90 
91 // Prints components
92 std::ostream &operator<<(std::ostream &os, const Spectrum &c);
93 
94 } // namespace CMU462
95 
96 #endif // CMU462_SPECTRUM_H
double b
intensity of blue spectrum
Definition: spectrum.h:19
Definition: CMU462.h:8
Encodes radiance & irradiance values by the intensity of each visible spectrum.
Definition: spectrum.h:15
Spectrum(double r=0, double g=0, double b=0)
Parameterized Constructor.
Definition: spectrum.h:28
double g
intensity of green spectrum
Definition: spectrum.h:18
double r
intensity of red spectrum
Definition: spectrum.h:17