Visual Servoing Platform  version 3.1.0
vpColor.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Color definition.
33  *
34  * Authors:
35  * Eric Marchand
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
40 #ifndef vpColor_hh
41 #define vpColor_hh
42 
43 #include <visp3/core/vpConfig.h>
44 #include <visp3/core/vpRGBa.h>
45 
120 class VISP_EXPORT vpColor : public vpRGBa
121 {
122 public:
124  typedef enum {
125  id_black = 0,
127  id_white,
129  id_lightGray,
131  id_gray,
133  id_darkGray,
135  id_lightRed,
137  id_red,
139  id_darkRed,
141  id_lightGreen,
143  id_green,
145  id_darkGreen,
147  id_lightBlue,
149  id_blue,
151  id_darkBlue,
153  id_yellow,
155  id_cyan,
157  id_orange,
159  id_purple,
162  id_unknown
168 
169  vpColorIdentifier id;
173  /* Predefined colors. */
174  static const vpColor black;
175  static const vpColor white;
176  static const vpColor lightGray;
177  static const vpColor gray;
178  static const vpColor darkGray;
179  static const vpColor lightRed;
180  static const vpColor red;
181  static const vpColor darkRed;
182  static const vpColor lightGreen;
183  static const vpColor green;
184  static const vpColor darkGreen;
185  static const vpColor lightBlue;
186  static const vpColor blue;
187  static const vpColor darkBlue;
188  static const vpColor yellow;
189  static const vpColor cyan;
190  static const vpColor orange;
191  static const vpColor purple;
192  static const vpColor none;
193 
194  static const unsigned int nbColors;
195  static const vpColor allColors[];
196 
204  inline vpColor() : vpRGBa(), id(id_unknown){};
215  inline vpColor(unsigned char r, unsigned char g, unsigned char b,
217  : vpRGBa(r, g, b), id(cid){};
219  inline virtual ~vpColor(){};
220 
221  friend VISP_EXPORT bool operator==(const vpColor &c1, const vpColor &c2);
222  friend VISP_EXPORT bool operator!=(const vpColor &c1, const vpColor &c2);
234  inline void setColor(unsigned char r, unsigned char g, unsigned char b)
235  {
236  this->R = r;
237  this->G = g;
238  this->B = b;
239  this->A = 0;
240  id = id_unknown;
241  };
242 
249  static inline vpColor getColor(const unsigned int &i) { return vpColor::allColors[i % vpColor::nbColors]; };
250 };
251 
252 // In this file if windows
253 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
254 
255 vpColor const __declspec(selectany) vpColor::black = vpColor(0, 0, 0, id_black);
258 vpColor const __declspec(selectany) vpColor::white = vpColor(255, 255, 255, id_white);
261 vpColor const __declspec(selectany) vpColor::lightGray = vpColor(192, 192, 192, id_lightGray);
263 vpColor const __declspec(selectany) vpColor::gray = vpColor(128, 128, 128, id_gray);
266 vpColor const __declspec(selectany) vpColor::darkGray = vpColor(64, 64, 64, id_darkGray);
269 vpColor const __declspec(selectany) vpColor::lightRed = vpColor(255, 140, 140, id_lightRed);
272 vpColor const __declspec(selectany) vpColor::red = vpColor(255, 0, 0, id_red);
275 vpColor const __declspec(selectany) vpColor::darkRed = vpColor(128, 0, 0, id_darkRed);
278 vpColor const __declspec(selectany) vpColor::lightGreen = vpColor(140, 255, 140, id_lightGreen);
281 vpColor const __declspec(selectany) vpColor::green = vpColor(0, 255, 0, id_green);
284 vpColor const __declspec(selectany) vpColor::darkGreen = vpColor(0, 128, 0, id_darkGreen);
287 vpColor const __declspec(selectany) vpColor::lightBlue = vpColor(140, 140, 255, id_lightBlue);
290 vpColor const __declspec(selectany) vpColor::blue = vpColor(0, 0, 255, id_blue);
293 vpColor const __declspec(selectany) vpColor::darkBlue = vpColor(0, 0, 128, id_darkBlue);
296 vpColor const __declspec(selectany) vpColor::yellow = vpColor(255, 255, 0, id_yellow);
299 vpColor const __declspec(selectany) vpColor::cyan = vpColor(0, 255, 255, id_cyan);
302 vpColor const __declspec(selectany) vpColor::orange = vpColor(255, 165, 0, id_orange);
305 vpColor const __declspec(selectany) vpColor::purple = vpColor(128, 0, 128, id_purple);
307 vpColor const __declspec(selectany) vpColor::none = vpColor(0, 0, 0, id_unknown);
308 
309 const __declspec(selectany) unsigned int vpColor::nbColors = 18;
310 
312 vpColor const __declspec(selectany) vpColor::allColors[vpColor::nbColors] = {vpColor::blue, // 12
313  vpColor::green, // 9
314  vpColor::red, // 6
315  vpColor::cyan, // 15
316  vpColor::purple, // 4
317  vpColor::yellow, // 14
318  vpColor::orange, // 16
319  vpColor::lightBlue, // 11
320  vpColor::lightGreen, // 8
321  vpColor::lightRed, // 5
322  vpColor::darkBlue, // 13
323  vpColor::darkGreen, // 10
324  vpColor::darkRed, // 7
325  vpColor::lightGray, // 2
326  vpColor::gray, // 3
327  vpColor::darkGray, // 4
328  vpColor::black, // 0
329  vpColor::white}; // 17
330 
331 #endif
332 
333 #endif
vpColor()
Definition: vpColor.h:204
void setColor(unsigned char r, unsigned char g, unsigned char b)
Definition: vpColor.h:234
static const vpColor allColors[]
Definition: vpColor.h:195
static const vpColor black
Definition: vpColor.h:174
static const vpColor darkRed
Definition: vpColor.h:181
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
static const vpColor none
Definition: vpColor.h:192
static const vpColor lightGray
Definition: vpColor.h:176
static const vpColor darkBlue
Definition: vpColor.h:187
static const vpColor green
Definition: vpColor.h:183
static const vpColor lightRed
Definition: vpColor.h:179
Definition: vpRGBa.h:66
static const vpColor red
Definition: vpColor.h:180
static const vpColor orange
Definition: vpColor.h:190
vpColorIdentifier id
Definition: vpColor.h:169
bool operator==(const vpRGBa &v)
Definition: vpRGBa.cpp:118
static const vpColor cyan
Definition: vpColor.h:189
static const vpColor lightGreen
Definition: vpColor.h:182
vpColorIdentifier
Definition: vpColor.h:124
static const vpColor gray
Definition: vpColor.h:177
static const vpColor darkGray
Definition: vpColor.h:178
virtual ~vpColor()
Definition: vpColor.h:219
static const vpColor darkGreen
Definition: vpColor.h:184
static vpColor getColor(const unsigned int &i)
Definition: vpColor.h:249
static const vpColor yellow
Definition: vpColor.h:188
static const vpColor lightBlue
Definition: vpColor.h:185
static const vpColor purple
Definition: vpColor.h:191
static const vpColor white
Definition: vpColor.h:175
bool operator!=(const vpRGBa &v)
Definition: vpRGBa.cpp:136
static const unsigned int nbColors
Definition: vpColor.h:194
static const vpColor blue
Definition: vpColor.h:186
vpColor(unsigned char r, unsigned char g, unsigned char b, vpColor::vpColorIdentifier cid=vpColor::id_unknown)
Definition: vpColor.h:215