colour.h

Go to the documentation of this file.
00001 /*
00002  *  This file is part of libcxxsupport.
00003  *
00004  *  libcxxsupport is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  libcxxsupport is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with libcxxsupport; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  */
00018 
00019 /*
00020  *  libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik
00021  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00022  *  (DLR).
00023  */
00024 
00025 /*! \file colour.h
00026  *  Simple class for representing colours. Adapted from RAY++ source code.
00027  *
00028  *  Copyright (C) 2015 Max-Planck-Society
00029  *  \author Martin Reinecke
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

Generated on Thu Oct 8 14:48:51 2015 for LevelS C++ support library