color.hpp
Go to the documentation of this file.
00001 /*
00002 **    TP 4ETI CPE Lyon
00003 **    Copyright (C) 2012 Damien Rohmer
00004 **
00005 **    This program is free software: you can redistribute it and/or modify
00006 **    it under the terms of the GNU General Public License as published by
00007 **    the Free Software Foundation, either version 3 of the License, or
00008 **    (at your option) any later version.
00009 **
00010 **   This program is distributed in the hope that it will be useful,
00011 **    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 **    GNU General Public License for more details.
00014 **
00015 **    You should have received a copy of the GNU General Public License
00016 **    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 
00021 #ifndef COLOR_HPP
00022 #define COLOR_HPP
00023 
00024 #include <exception_cpe.hpp>
00025 
00026 #include <iostream>
00027 #include <vector>
00028 
00029 
00030 namespace cpe
00031 {
00033     class color
00034     {
00035     public:
00036 
00037 
00038         // ********************************************* //
00039         // ********************************************* //
00040         //  CONSTRUCTORS
00041         // ********************************************* //
00042         // ********************************************* //
00043 
00045         color();
00047         color(const int& gray);
00049         color(const int& r,const int& g,const int& b);
00050 
00051         // ********************************************* //
00052         // ********************************************* //
00053         //  ACCESS COLOR VALUE
00054         // ********************************************* //
00055         // ********************************************* //
00056 
00058         void set(const int& r,const int& g,const int& b);
00059 
00060 
00062         const int& r() const;
00064         int& r();
00066         const int& g() const;
00068         int& g();
00070         const int& b() const;
00072         int& b();
00073 
00074         // ********************************************* //
00075         // ********************************************* //
00076         //  COLOR INTERPOLATION
00077         // ********************************************* //
00078         // ********************************************* //
00079 
00083         static color interpolate_linear(const color& c1,const color& c2,const double& alpha);
00089         static color interpolate_linear(const std::vector<color>& v_color,const std::vector<double>& weights);
00090 
00092         color clamped() const;
00093 
00094 
00095         // ********************************************* //
00096         // ********************************************* //
00097         //  MATH OPERATOR
00098         // ********************************************* //
00099         // ********************************************* //
00100 
00102         friend color operator+(const color& c0,const color& c1);
00104         color& operator+=(const color& c);
00105 
00107         friend color operator*(const double& alpha,const color& c);
00109         friend color operator*(const color& c,const double& alpha);
00111         color& operator*=(const double& alpha);
00112 
00113 
00114 
00115         // ********************************************* //
00116         // ********************************************* //
00117         //  I/O
00118         // ********************************************* //
00119         // ********************************************* //
00120 
00122         friend std::ostream& operator<<(std::ostream& stream,const color& c);
00123 
00124 
00125     private:
00126 
00127         // ********************************************* //
00128         // ********************************************* //
00129         //  INTERNAL STORAGE
00130         // ********************************************* //
00131         // ********************************************* //
00132 
00134         int internal_r;
00136         int internal_g;
00138         int internal_b;
00139 
00140     };
00141 
00143     class exception_color: public exception_cpe
00144     {
00145     public:
00147         exception_color():exception_cpe(){}
00149         exception_color(const std::string& msg,const std::string& file,const std::string& caller,const int& line):exception_cpe(msg,file,caller,line){}
00150     };
00151 }
00152 
00153 #endif