All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Color.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Nate Koenig
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 /* Desc: Color class
18  * Author: Nate Koenig
19  * Date: 08 May 2009
20  */
21 
22 #ifndef GAZEBO_COLOR_HH
23 #define GAZEBO_COLOR_HH
24 
25 #include <iostream>
27 #include "gazebo/math/Vector3.hh"
28 
29 namespace gazebo
30 {
31  namespace common
32  {
35 
38  class Color
39  {
41  public: static const Color White;
43  public: static const Color Black;
45  public: static const Color Red;
47  public: static const Color Green;
49  public: static const Color Blue;
51  public: static const Color Yellow;
53  public: static const Color Purple;
54 
57  public: typedef unsigned int RGBA;
58 
61  public: typedef unsigned int BGRA;
62 
65  public: typedef unsigned int ARGB;
66 
69  public: typedef unsigned int ABGR;
70 
72  public: Color();
73 
79  public: Color(float _r, float _g, float _b, float _a = 1.0);
80 
83  public: Color(const Color &_clr);
84 
86  public: virtual ~Color();
87 
89  public: void Reset();
90 
96  public: void Set(float _r = 1, float _g = 1 , float _b = 1, float _a = 1);
97 
100  public: math::Vector3 GetAsHSV() const;
101 
106  public: void SetFromHSV(float _h, float _s, float _v);
107 
110  public: math::Vector3 GetAsYUV() const;
111 
116  public: void SetFromYUV(float _y, float _u, float _v);
117 
121  public: Color &operator =(const Color &_pt);
122 
126  public: float operator[](unsigned int _index);
127 
130  public: RGBA GetAsRGBA() const;
131 
134  public: BGRA GetAsBGRA() const;
135 
138  public: ARGB GetAsARGB() const;
139 
142  public: ABGR GetAsABGR() const;
143 
144 
147  public: void SetFromRGBA(const RGBA _v);
148 
151  public: void SetFromBGRA(const BGRA _v);
152 
155  public: void SetFromARGB(const ARGB _v);
156 
159  public: void SetFromABGR(const ABGR _v);
160 
164  public: Color operator+(const Color &_pt) const;
165 
169  public: Color operator+(const float &_v) const;
170 
174  public: const Color &operator+=(const Color &_pt);
175 
179  public: Color operator-(const Color &_pt) const;
180 
184  public: Color operator-(const float &_v) const;
185 
189  public: const Color &operator-=(const Color &_pt);
190 
194  public: const Color operator/(const Color &_pt) const;
195 
199  public: const Color operator/(const float &_v) const;
200 
204  public: const Color &operator/=(const Color &_pt);
205 
209  public: const Color operator*(const Color &_pt) const;
210 
214  public: const Color operator*(const float &_v) const;
215 
219  public: const Color &operator*=(const Color &_pt);
220 
224  public: bool operator ==(const Color &_pt) const;
225 
229  public: bool operator!=(const Color &_pt) const;
230 
232  private: void Clamp();
233 
238  public: friend std::ostream &operator<< (std::ostream &_out,
239  const Color &_pt)
240  {
241  _out << _pt.r << " " << _pt.g << " " << _pt.b << " " << _pt.a;
242  return _out;
243  }
244 
248  public: friend std::istream &operator>> (std::istream &_in, Color &_pt)
249  {
250  // Skip white spaces
251  _in.setf(std::ios_base::skipws);
252  _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
253  return _in;
254  }
255 
256  // The values
257  public: float r, g, b, a;
258  };
260  }
261 }
262 #endif