Color.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
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 #ifndef _GAZEBO_COLOR_HH_
18 #define _GAZEBO_COLOR_HH_
19 
20 #include <iostream>
21 #include <ignition/math/Vector3.hh>
22 
24 #include "gazebo/math/Vector3.hh"
25 #include "gazebo/util/system.hh"
26 
27 namespace gazebo
28 {
29  namespace common
30  {
33 
36  class GZ_COMMON_VISIBLE Color
37  {
39  public: static const Color White;
41  public: static const Color Black;
43  public: static const Color Red;
45  public: static const Color Green;
47  public: static const Color Blue;
49  public: static const Color Yellow;
51  public: static const Color Magenta;
52 
55  public: typedef unsigned int RGBA;
56 
59  public: typedef unsigned int BGRA;
60 
63  public: typedef unsigned int ARGB;
64 
67  public: typedef unsigned int ABGR;
68 
70  public: Color();
71 
77  public: Color(float _r, float _g, float _b, float _a = 1.0);
78 
81  public: Color(const Color &_clr);
82 
84  public: virtual ~Color();
85 
87  public: void Reset();
88 
94  public: void Set(float _r = 1, float _g = 1 , float _b = 1, float _a = 1);
95 
98  public: ignition::math::Vector3d HSV() const;
99 
104  public: void SetFromHSV(float _h, float _s, float _v);
105 
110  public: math::Vector3 GetAsYUV() const GAZEBO_DEPRECATED(8.0);
111 
114  public: ignition::math::Vector3d YUV() const;
115 
120  public: void SetFromYUV(float _y, float _u, float _v);
121 
125  public: Color &operator =(const Color &_pt);
126 
130  public: float operator[](unsigned int _index);
131 
134  public: RGBA GetAsRGBA() const;
135 
138  public: BGRA GetAsBGRA() const;
139 
142  public: ARGB GetAsARGB() const;
143 
146  public: ABGR GetAsABGR() const;
147 
148 
151  public: void SetFromRGBA(const RGBA _v);
152 
155  public: void SetFromBGRA(const BGRA _v);
156 
159  public: void SetFromARGB(const ARGB _v);
160 
163  public: void SetFromABGR(const ABGR _v);
164 
168  public: Color operator+(const Color &_pt) const;
169 
173  public: Color operator+(const float &_v) const;
174 
178  public: const Color &operator+=(const Color &_pt);
179 
183  public: Color operator-(const Color &_pt) const;
184 
188  public: Color operator-(const float &_v) const;
189 
193  public: const Color &operator-=(const Color &_pt);
194 
198  public: const Color operator/(const Color &_pt) const;
199 
203  public: const Color operator/(const float &_v) const;
204 
208  public: const Color &operator/=(const Color &_pt);
209 
213  public: const Color operator*(const Color &_pt) const;
214 
218  public: const Color operator*(const float &_v) const;
219 
223  public: const Color &operator*=(const Color &_pt);
224 
228  public: bool operator ==(const Color &_pt) const;
229 
233  public: bool operator!=(const Color &_pt) const;
234 
236  private: void Clamp();
237 
242  public: friend std::ostream &operator<< (std::ostream &_out,
243  const Color &_pt)
244  {
245  _out << _pt.r << " " << _pt.g << " " << _pt.b << " " << _pt.a;
246  return _out;
247  }
248 
252  public: friend std::istream &operator>> (std::istream &_in, Color &_pt)
253  {
254  // Skip white spaces
255  _in.setf(std::ios_base::skipws);
256  _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
257  return _in;
258  }
259 
260  // The values
261  public: float r, g, b, a;
262  };
264  }
265 }
266 #endif
static const Color Blue
(0, 0, 1)
Definition: Color.hh:47
float a
Definition: Color.hh:261
float b
Definition: Color.hh:261
static const Color White
(1, 1, 1)
Definition: Color.hh:39
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:44
static const Color Red
(1, 0, 0)
Definition: Color.hh:43
unsigned int RGBA
Definition: Color.hh:55
unsigned int ABGR
Definition: Color.hh:67
unsigned int ARGB
Definition: Color.hh:63
static const Color Green
(0, 1, 0)
Definition: Color.hh:45
float r
Definition: Color.hh:261
GAZEBO_VISIBLE void Set(common::Image &_img, const msgs::Image &_msg)
Convert a msgs::Image to a common::Image.
Defines a color.
Definition: Color.hh:36
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
static const Color Yellow
(1, 1, 0)
Definition: Color.hh:49
static const Color Black
(0, 0, 0)
Definition: Color.hh:41
bool const T & _b
Definition: Helpers.hh:258
static const Color Magenta
(1, 0, 1)
Definition: Color.hh:51
float g
Definition: Color.hh:261
unsigned int BGRA
Definition: Color.hh:59