All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Color.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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 /* 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 #include "gazebo/util/system.hh"
29 
30 namespace gazebo
31 {
32  namespace common
33  {
36 
40  {
42  public: static const Color White;
44  public: static const Color Black;
46  public: static const Color Red;
48  public: static const Color Green;
50  public: static const Color Blue;
52  public: static const Color Yellow;
54  public: static const Color Purple;
55 
58  public: typedef unsigned int RGBA;
59 
62  public: typedef unsigned int BGRA;
63 
66  public: typedef unsigned int ARGB;
67 
70  public: typedef unsigned int ABGR;
71 
73  public: Color();
74 
80  public: Color(float _r, float _g, float _b, float _a = 1.0);
81 
84  public: Color(const Color &_clr);
85 
87  public: virtual ~Color();
88 
90  public: void Reset();
91 
97  public: void Set(float _r = 1, float _g = 1 , float _b = 1, float _a = 1);
98 
101  public: math::Vector3 GetAsHSV() const;
102 
107  public: void SetFromHSV(float _h, float _s, float _v);
108 
111  public: math::Vector3 GetAsYUV() const;
112 
117  public: void SetFromYUV(float _y, float _u, float _v);
118 
122  public: Color &operator =(const Color &_pt);
123 
127  public: float operator[](unsigned int _index);
128 
131  public: RGBA GetAsRGBA() const;
132 
135  public: BGRA GetAsBGRA() const;
136 
139  public: ARGB GetAsARGB() const;
140 
143  public: ABGR GetAsABGR() const;
144 
145 
148  public: void SetFromRGBA(const RGBA _v);
149 
152  public: void SetFromBGRA(const BGRA _v);
153 
156  public: void SetFromARGB(const ARGB _v);
157 
160  public: void SetFromABGR(const ABGR _v);
161 
165  public: Color operator+(const Color &_pt) const;
166 
170  public: Color operator+(const float &_v) const;
171 
175  public: const Color &operator+=(const Color &_pt);
176 
180  public: Color operator-(const Color &_pt) const;
181 
185  public: Color operator-(const float &_v) const;
186 
190  public: const Color &operator-=(const Color &_pt);
191 
195  public: const Color operator/(const Color &_pt) const;
196 
200  public: const Color operator/(const float &_v) const;
201 
205  public: const Color &operator/=(const Color &_pt);
206 
210  public: const Color operator*(const Color &_pt) const;
211 
215  public: const Color operator*(const float &_v) const;
216 
220  public: const Color &operator*=(const Color &_pt);
221 
225  public: bool operator ==(const Color &_pt) const;
226 
230  public: bool operator!=(const Color &_pt) const;
231 
233  private: void Clamp();
234 
239  public: friend std::ostream &operator<< (std::ostream &_out,
240  const Color &_pt)
241  {
242  _out << _pt.r << " " << _pt.g << " " << _pt.b << " " << _pt.a;
243  return _out;
244  }
245 
249  public: friend std::istream &operator>> (std::istream &_in, Color &_pt)
250  {
251  // Skip white spaces
252  _in.setf(std::ios_base::skipws);
253  _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
254  return _in;
255  }
256 
257  // The values
258  public: float r, g, b, a;
259  };
261  }
262 }
263 #endif
float r
Definition: Color.hh:258
static const Color Red
(1, 0, 0)
Definition: Color.hh:46
static const Color White
(1, 1, 1)
Definition: Color.hh:42
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
float a
Definition: Color.hh:258
unsigned int ARGB
Definition: Color.hh:66
unsigned int BGRA
Definition: Color.hh:62
static const Color Blue
(0, 0, 1)
Definition: Color.hh:50
float g
Definition: Color.hh:258
unsigned int RGBA
Definition: Color.hh:58
unsigned int ABGR
Definition: Color.hh:70
static const Color Purple
(1, 0, 1)
Definition: Color.hh:54
static const Color Green
(0, 1, 0)
Definition: Color.hh:48
static const Color Yellow
(1, 1, 0)
Definition: Color.hh:52
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:39
float b
Definition: Color.hh:258
static const Color Black
(0, 0, 0)
Definition: Color.hh:44
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48