Visual Servoing Platform  version 3.3.1 under development (2020-02-21)
vpColor.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 
119 class VISP_EXPORT vpColor : public vpRGBa
120 {
121 public:
123  typedef enum {
124  id_black = 0,
126  id_white,
128  id_lightGray,
130  id_gray,
132  id_darkGray,
134  id_lightRed,
136  id_red,
138  id_darkRed,
140  id_lightGreen,
142  id_green,
144  id_darkGreen,
146  id_lightBlue,
148  id_blue,
150  id_darkBlue,
152  id_yellow,
154  id_cyan,
156  id_orange,
158  id_purple,
161  id_unknown
167 
168  vpColorIdentifier id;
172  /* Predefined colors. */
173  static const vpColor black;
174  static const vpColor white;
175  static const vpColor lightGray;
176  static const vpColor gray;
177  static const vpColor darkGray;
178  static const vpColor lightRed;
179  static const vpColor red;
180  static const vpColor darkRed;
181  static const vpColor lightGreen;
182  static const vpColor green;
183  static const vpColor darkGreen;
184  static const vpColor lightBlue;
185  static const vpColor blue;
186  static const vpColor darkBlue;
187  static const vpColor yellow;
188  static const vpColor cyan;
189  static const vpColor orange;
190  static const vpColor purple;
191  static const vpColor none;
192 
193  static const unsigned int nbColors;
194  static const vpColor allColors[];
195 
203  inline vpColor() : vpRGBa(), id(id_unknown){}
214  inline vpColor(unsigned char r, unsigned char g, unsigned char b,
216  : vpRGBa(r, g, b), id(cid){}
218  inline virtual ~vpColor(){}
219 
220  friend VISP_EXPORT bool operator==(const vpColor &c1, const vpColor &c2);
221  friend VISP_EXPORT bool operator!=(const vpColor &c1, const vpColor &c2);
233  inline void setColor(unsigned char r, unsigned char g, unsigned char b)
234  {
235  this->R = r;
236  this->G = g;
237  this->B = b;
238  this->A = 0;
239  id = id_unknown;
240  }
241 
248  static inline vpColor getColor(const unsigned int &i) { return vpColor::allColors[i % vpColor::nbColors]; }
249 };
250 
251 // In this file if windows
252 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
253 
254 vpColor const __declspec(selectany) vpColor::black = vpColor(0, 0, 0, id_black);
257 vpColor const __declspec(selectany) vpColor::white = vpColor(255, 255, 255, id_white);
260 vpColor const __declspec(selectany) vpColor::lightGray = vpColor(192, 192, 192, id_lightGray);
262 vpColor const __declspec(selectany) vpColor::gray = vpColor(128, 128, 128, id_gray);
265 vpColor const __declspec(selectany) vpColor::darkGray = vpColor(64, 64, 64, id_darkGray);
268 vpColor const __declspec(selectany) vpColor::lightRed = vpColor(255, 140, 140, id_lightRed);
271 vpColor const __declspec(selectany) vpColor::red = vpColor(255, 0, 0, id_red);
274 vpColor const __declspec(selectany) vpColor::darkRed = vpColor(128, 0, 0, id_darkRed);
277 vpColor const __declspec(selectany) vpColor::lightGreen = vpColor(140, 255, 140, id_lightGreen);
280 vpColor const __declspec(selectany) vpColor::green = vpColor(0, 255, 0, id_green);
283 vpColor const __declspec(selectany) vpColor::darkGreen = vpColor(0, 128, 0, id_darkGreen);
286 vpColor const __declspec(selectany) vpColor::lightBlue = vpColor(140, 140, 255, id_lightBlue);
289 vpColor const __declspec(selectany) vpColor::blue = vpColor(0, 0, 255, id_blue);
292 vpColor const __declspec(selectany) vpColor::darkBlue = vpColor(0, 0, 128, id_darkBlue);
295 vpColor const __declspec(selectany) vpColor::yellow = vpColor(255, 255, 0, id_yellow);
298 vpColor const __declspec(selectany) vpColor::cyan = vpColor(0, 255, 255, id_cyan);
301 vpColor const __declspec(selectany) vpColor::orange = vpColor(255, 165, 0, id_orange);
304 vpColor const __declspec(selectany) vpColor::purple = vpColor(128, 0, 128, id_purple);
306 vpColor const __declspec(selectany) vpColor::none = vpColor(0, 0, 0, id_unknown);
307 
308 const __declspec(selectany) unsigned int vpColor::nbColors = 18;
309 
311 vpColor const __declspec(selectany) vpColor::allColors[vpColor::nbColors] = {vpColor::blue, // 12
312  vpColor::green, // 9
313  vpColor::red, // 6
314  vpColor::cyan, // 15
315  vpColor::purple, // 4
316  vpColor::yellow, // 14
317  vpColor::orange, // 16
318  vpColor::lightBlue, // 11
319  vpColor::lightGreen, // 8
320  vpColor::lightRed, // 5
321  vpColor::darkBlue, // 13
322  vpColor::darkGreen, // 10
323  vpColor::darkRed, // 7
324  vpColor::lightGray, // 2
325  vpColor::gray, // 3
326  vpColor::darkGray, // 4
327  vpColor::black, // 0
328  vpColor::white}; // 17
329 
330 #endif
331 
332 #endif
vpColor()
Definition: vpColor.h:203
void setColor(unsigned char r, unsigned char g, unsigned char b)
Definition: vpColor.h:233
static const vpColor allColors[]
Definition: vpColor.h:194
static const vpColor black
Definition: vpColor.h:173
static const vpColor darkRed
Definition: vpColor.h:180
Class to define colors available for display functionnalities.
Definition: vpColor.h:119
static const vpColor none
Definition: vpColor.h:191
static const vpColor lightGray
Definition: vpColor.h:175
static const vpColor darkBlue
Definition: vpColor.h:186
static const vpColor green
Definition: vpColor.h:182
static const vpColor lightRed
Definition: vpColor.h:178
Definition: vpRGBa.h:66
static const vpColor red
Definition: vpColor.h:179
static const vpColor orange
Definition: vpColor.h:189
vpColorIdentifier id
Definition: vpColor.h:168
bool operator==(const vpRGBa &v)
Definition: vpRGBa.cpp:118
static const vpColor cyan
Definition: vpColor.h:188
static const vpColor lightGreen
Definition: vpColor.h:181
vpColorIdentifier
Definition: vpColor.h:123
static const vpColor gray
Definition: vpColor.h:176
static const vpColor darkGray
Definition: vpColor.h:177
virtual ~vpColor()
Definition: vpColor.h:218
static const vpColor darkGreen
Definition: vpColor.h:183
static vpColor getColor(const unsigned int &i)
Definition: vpColor.h:248
static const vpColor yellow
Definition: vpColor.h:187
static const vpColor lightBlue
Definition: vpColor.h:184
static const vpColor purple
Definition: vpColor.h:190
static const vpColor white
Definition: vpColor.h:174
bool operator!=(const vpRGBa &v)
Definition: vpRGBa.cpp:136
static const unsigned int nbColors
Definition: vpColor.h:193
static const vpColor blue
Definition: vpColor.h:185
vpColor(unsigned char r, unsigned char g, unsigned char b, vpColor::vpColorIdentifier cid=vpColor::id_unknown)
Definition: vpColor.h:214