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/util/system.hh"
25 
26 namespace gazebo
27 {
28  namespace common
29  {
32 
35  class GZ_COMMON_VISIBLE Color
36  {
38  public: static const Color White;
40  public: static const Color Black;
42  public: static const Color Red;
44  public: static const Color Green;
46  public: static const Color Blue;
48  public: static const Color Yellow;
50  public: static const Color Magenta;
51 
54  public: typedef unsigned int RGBA;
55 
58  public: typedef unsigned int BGRA;
59 
62  public: typedef unsigned int ARGB;
63 
66  public: typedef unsigned int ABGR;
67 
69  public: Color();
70 
76  public: Color(float _r, float _g, float _b, float _a = 1.0);
77 
80  public: Color(const Color &_clr);
81 
83  public: virtual ~Color();
84 
86  public: void Reset();
87 
93  public: void Set(float _r = 1, float _g = 1 , float _b = 1, float _a = 1);
94 
97  public: ignition::math::Vector3d HSV() const;
98 
103  public: void SetFromHSV(float _h, float _s, float _v);
104 
107  public: ignition::math::Vector3d YUV() const;
108 
113  public: void SetFromYUV(float _y, float _u, float _v);
114 
118  public: Color &operator =(const Color &_pt);
119 
123  public: float operator[](unsigned int _index);
124 
127  public: RGBA GetAsRGBA() const;
128 
131  public: BGRA GetAsBGRA() const;
132 
135  public: ARGB GetAsARGB() const;
136 
139  public: ABGR GetAsABGR() const;
140 
141 
144  public: void SetFromRGBA(const RGBA _v);
145 
148  public: void SetFromBGRA(const BGRA _v);
149 
152  public: void SetFromARGB(const ARGB _v);
153 
156  public: void SetFromABGR(const ABGR _v);
157 
161  public: Color operator+(const Color &_pt) const;
162 
166  public: Color operator+(const float &_v) const;
167 
171  public: const Color &operator+=(const Color &_pt);
172 
176  public: Color operator-(const Color &_pt) const;
177 
181  public: Color operator-(const float &_v) const;
182 
186  public: const Color &operator-=(const Color &_pt);
187 
191  public: const Color operator/(const Color &_pt) const;
192 
196  public: const Color operator/(const float &_v) const;
197 
201  public: const Color &operator/=(const Color &_pt);
202 
206  public: const Color operator*(const Color &_pt) const;
207 
211  public: const Color operator*(const float &_v) const;
212 
216  public: const Color &operator*=(const Color &_pt);
217 
221  public: bool operator ==(const Color &_pt) const;
222 
226  public: bool operator!=(const Color &_pt) const;
227 
229  private: void Clamp();
230 
235  public: friend std::ostream &operator<< (std::ostream &_out,
236  const Color &_pt)
237  {
238  _out << _pt.r << " " << _pt.g << " " << _pt.b << " " << _pt.a;
239  return _out;
240  }
241 
245  public: friend std::istream &operator>> (std::istream &_in, Color &_pt)
246  {
247  // Skip white spaces
248  _in.setf(std::ios_base::skipws);
249  _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
250  return _in;
251  }
252 
253  // The values
254  public: float r, g, b, a;
255  };
257  }
258 }
259 #endif
static const Color Blue
(0, 0, 1)
Definition: Color.hh:46
float a
Definition: Color.hh:254
float b
Definition: Color.hh:254
static const Color White
(1, 1, 1)
Definition: Color.hh:38
Forward declarations for the common classes.
Definition: Animation.hh:33
static const Color Red
(1, 0, 0)
Definition: Color.hh:42
unsigned int RGBA
Definition: Color.hh:54
unsigned int ABGR
Definition: Color.hh:66
unsigned int ARGB
Definition: Color.hh:62
static const Color Green
(0, 1, 0)
Definition: Color.hh:44
float r
Definition: Color.hh:254
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:35
static const Color Yellow
(1, 1, 0)
Definition: Color.hh:48
static const Color Black
(0, 0, 0)
Definition: Color.hh:40
bool const T & _b
Definition: Helpers.hh:258
static const Color Magenta
(1, 0, 1)
Definition: Color.hh:50
float g
Definition: Color.hh:254
unsigned int BGRA
Definition: Color.hh:58