Color.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 
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 Purple;
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 
100  public: math::Vector3 GetAsHSV() const GAZEBO_DEPRECATED(6.0);
101 
104  public: ignition::math::Vector3d HSV() const;
105 
110  public: void SetFromHSV(float _h, float _s, float _v);
111 
116  public: math::Vector3 GetAsYUV() const;
117 
120  public: ignition::math::Vector3d YUV() const;
121 
126  public: void SetFromYUV(float _y, float _u, float _v);
127 
131  public: Color &operator =(const Color &_pt);
132 
136  public: float operator[](unsigned int _index);
137 
140  public: RGBA GetAsRGBA() const;
141 
144  public: BGRA GetAsBGRA() const;
145 
148  public: ARGB GetAsARGB() const;
149 
152  public: ABGR GetAsABGR() const;
153 
154 
157  public: void SetFromRGBA(const RGBA _v);
158 
161  public: void SetFromBGRA(const BGRA _v);
162 
165  public: void SetFromARGB(const ARGB _v);
166 
169  public: void SetFromABGR(const ABGR _v);
170 
174  public: Color operator+(const Color &_pt) const;
175 
179  public: Color operator+(const float &_v) const;
180 
184  public: const Color &operator+=(const Color &_pt);
185 
189  public: Color operator-(const Color &_pt) const;
190 
194  public: Color operator-(const float &_v) const;
195 
199  public: const Color &operator-=(const Color &_pt);
200 
204  public: const Color operator/(const Color &_pt) const;
205 
209  public: const Color operator/(const float &_v) const;
210 
214  public: const Color &operator/=(const Color &_pt);
215 
219  public: const Color operator*(const Color &_pt) const;
220 
224  public: const Color operator*(const float &_v) const;
225 
229  public: const Color &operator*=(const Color &_pt);
230 
234  public: bool operator ==(const Color &_pt) const;
235 
239  public: bool operator!=(const Color &_pt) const;
240 
242  private: void Clamp();
243 
248  public: friend std::ostream &operator<< (std::ostream &_out,
249  const Color &_pt)
250  {
251  _out << _pt.r << " " << _pt.g << " " << _pt.b << " " << _pt.a;
252  return _out;
253  }
254 
258  public: friend std::istream &operator>> (std::istream &_in, Color &_pt)
259  {
260  // Skip white spaces
261  _in.setf(std::ios_base::skipws);
262  _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
263  return _in;
264  }
265 
266  // The values
267  public: float r, g, b, a;
268  };
270  }
271 }
272 #endif
float r
Definition: Color.hh:267
static const Color Red
(1, 0, 0)
Definition: Color.hh:43
static const Color White
(1, 1, 1)
Definition: Color.hh:39
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
float a
Definition: Color.hh:267
unsigned int ARGB
Definition: Color.hh:63
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:47
unsigned int BGRA
Definition: Color.hh:59
#define GZ_COMMON_VISIBLE
Definition: system.hh:91
static const Color Blue
(0, 0, 1)
Definition: Color.hh:47
float g
Definition: Color.hh:267
unsigned int RGBA
Definition: Color.hh:55
unsigned int ABGR
Definition: Color.hh:67
static const Color Purple
(1, 0, 1)
Definition: Color.hh:51
static const Color Green
(0, 1, 0)
Definition: Color.hh:45
static const Color Yellow
(1, 1, 0)
Definition: Color.hh:49
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
float b
Definition: Color.hh:267
static const Color Black
(0, 0, 0)
Definition: Color.hh:41