00001 /* 00002 * lib-spamod : Visualisation des objets en discret. 00003 * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC 00004 * http://www.sic.sp2mi.univ-poitiers.fr/ 00005 * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS, 00006 * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/ 00007 * 00008 * This file is part of lib-spamod 00009 * 00010 * This program is free software: you can redistribute it and/or modify 00011 * it under the terms of the GNU Lesser General Public License as published by 00012 * the Free Software Foundation, either version 3 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public License 00021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 /****************************************************************************** 00025 * Fichier : Color.h * 00026 * Auteur : DEXET Martine * 00027 *----------------------------------------------------------------------------* 00028 * Ce fichier contient la spécification de la classe Color. Cette classe * 00029 * permet de représenter une couleur à l'aide de trois nombres à virgule * 00030 * flottante correspondants aux trois composantes R, G et B d'une couleur. * 00031 * * 00032 *****************************************************************************/ 00033 00034 00035 #ifndef COLOR_H 00036 #define COLOR_H 00037 00038 00039 00040 /****************************************************************************** 00041 * Classe Color * 00042 *****************************************************************************/ 00043 00044 class Color { 00045 00046 public: 00047 00048 // Constructeurs. 00049 Color(); 00050 Color(float cr, float cg, float cb); 00051 Color(const Color & C); 00052 00053 // Méthodes permettant la lecture des composantes R, G et B. 00054 float Get_R() const; 00055 float Get_G() const; 00056 float Get_B() const; 00057 00058 // Méthodes permettant l'écriture des composantes R, G et B. 00059 void Set_R(float val); 00060 void Set_G(float val); 00061 void Set_B(float val); 00062 void Set_RGB(float vx, float vy, float vz); 00063 00064 // Opérateur de transfert << et >>. 00065 friend std::ostream & operator<<(std::ostream & s,Color const & v); 00066 friend Color& operator >> (std::istream& s, Color & i); 00067 00068 00069 private: 00070 00071 // Variables représentant les composantes R, G et B d'une couleur. 00072 float r,g,b; 00073 00074 }; 00075 00076 /****************************************************************************** 00077 * Fichier : Color.inl * 00078 * Auteur : DEXET Martine * 00079 *----------------------------------------------------------------------------* 00080 * Ce fichier contient l'implémentation des méthodes de la classe Color * 00081 * * 00082 *****************************************************************************/ 00083 00084 00085 // Constructeurs. 00086 inline 00087 Color::Color() 00088 { 00089 r = g = b = 0.0; 00090 } 00091 00092 inline 00093 Color::Color(const Color & C) 00094 { 00095 r = C.r; 00096 g = C.g; 00097 b = C.b; 00098 } 00099 00100 inline 00101 Color::Color(float cr, float cg, float cb) 00102 { 00103 r = cr; 00104 g = cg; 00105 b = cb; 00106 } 00107 00108 00109 // Méthodes permettant la lecture des composantes R, G et B. 00110 inline 00111 float Color::Get_R() const 00112 { 00113 return r; 00114 } 00115 00116 inline 00117 float Color::Get_G() const 00118 { 00119 return g; 00120 } 00121 00122 inline 00123 float Color::Get_B() const 00124 { 00125 return b; 00126 } 00127 00128 00129 // Méthodes permettant l'écriture des composantes R, G et B. 00130 inline 00131 void Color::Set_R(float val) 00132 { 00133 r = val; 00134 } 00135 00136 inline 00137 void Color::Set_G(float val) 00138 { 00139 g = val; 00140 } 00141 00142 inline 00143 void Color::Set_B(float val) 00144 { 00145 b = val; 00146 } 00147 00148 inline 00149 void Color::Set_RGB(float vr, float vg, float vb) 00150 { 00151 r = vr; 00152 g = vg; 00153 b = vb; 00154 } 00155 00156 00157 // Opérateur de transfert << et >>. 00158 inline 00159 std::ostream & operator<<(std::ostream & s,Color const & v) 00160 { 00161 s << v.Get_R() << " " << v.Get_G() << " " << v.Get_B() << std::endl; 00162 return s; 00163 } 00164 00165 00166 inline 00167 Color& operator >> (std::istream& s, Color & i) 00168 { 00169 float alpha, b, c; 00170 00171 s >> alpha >> b >> c; 00172 00173 i.Set_R(alpha); 00174 i.Set_G(b); 00175 i.Set_R(c); 00176 00177 return i; 00178 } 00179 00180 #endif