colour.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef PLANCK_COLOUR_H
00033 #define PLANCK_COLOUR_H
00034
00035 #include <iostream>
00036
00037 template<typename T> class RGB_tuple
00038 {
00039 public:
00040 T r, g, b;
00041
00042 RGB_tuple () {}
00043 RGB_tuple (T rv, T gv, T bv)
00044 : r (rv), g (gv), b (bv) {}
00045 template<typename T2> explicit RGB_tuple (const RGB_tuple<T2> &orig)
00046 : r(orig.r), g(orig.g), b(orig.b) {}
00047
00048 const RGB_tuple &operator= (const RGB_tuple &Col2)
00049 { r=Col2.r; g=Col2.g; b=Col2.b; return *this; }
00050 const RGB_tuple &operator+= (const RGB_tuple &Col2)
00051 { r+=Col2.r; g+=Col2.g; b+=Col2.b; return *this; }
00052 const RGB_tuple &operator*= (T fac)
00053 { r*=fac; g*=fac; b*=fac; return *this; }
00054 RGB_tuple operator+ (const RGB_tuple &Col2) const
00055 { return RGB_tuple (r+Col2.r, g+Col2.g, b+Col2.b); }
00056 RGB_tuple operator- (const RGB_tuple &Col2) const
00057 { return RGB_tuple (r-Col2.r, g-Col2.g, b-Col2.b); }
00058 template<typename T2> RGB_tuple operator* (T2 factor) const
00059 { return RGB_tuple (r*factor, g*factor, b*factor); }
00060 template<typename T2> friend inline RGB_tuple operator* (T2 factor,
00061 const RGB_tuple &Col)
00062 { return RGB_tuple (Col.r*factor, Col.g*factor, Col.b*factor); }
00063
00064 void Set (T r2, T g2, T b2)
00065 { r=r2; g=g2; b=b2; }
00066
00067 friend std::ostream &operator<< (std::ostream &os, const RGB_tuple &c)
00068 {
00069 os << "(" << c.r << ", " << c.g << ", " << c.b << ")";
00070 return os;
00071 }
00072 };
00073
00074 typedef RGB_tuple<float> Colour;
00075
00076 #endif