Visual Servoing Platform  version 3.5.1 under development (2023-03-14)
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 
157 class VISP_EXPORT vpColor : public vpRGBa
158 {
159 public:
161  typedef enum {
162  id_black = 0,
164  id_white,
166  id_lightGray,
168  id_gray,
170  id_darkGray,
172  id_lightRed,
174  id_red,
176  id_darkRed,
178  id_lightGreen,
180  id_green,
182  id_darkGreen,
184  id_lightBlue,
186  id_blue,
188  id_darkBlue,
190  id_yellow,
192  id_cyan,
194  id_orange,
196  id_purple,
199  id_unknown
204  } vpColorIdentifier;
205 
210  /* Predefined colors. */
211  static const vpColor black;
212  static const vpColor white;
213  static const vpColor lightGray;
214  static const vpColor gray;
215  static const vpColor darkGray;
216  static const vpColor lightRed;
217  static const vpColor red;
218  static const vpColor darkRed;
219  static const vpColor lightGreen;
220  static const vpColor green;
221  static const vpColor darkGreen;
222  static const vpColor lightBlue;
223  static const vpColor blue;
224  static const vpColor darkBlue;
225  static const vpColor yellow;
226  static const vpColor cyan;
227  static const vpColor orange;
228  static const vpColor purple;
229  static const vpColor none;
230 
231  static const unsigned int nbColors;
232  static const vpColor allColors[];
233 
241  inline vpColor() : vpRGBa(), id(id_unknown) {}
252  inline vpColor(unsigned char r, unsigned char g, unsigned char b,
254  : vpRGBa(r, g, b), id(cid)
255  {
256  }
268  inline vpColor(unsigned char r, unsigned char g, unsigned char b, unsigned char alpha,
270  : vpRGBa(r, g, b, alpha), id(cid)
271  {
272  }
279  inline vpColor(const vpColor &color, unsigned char alpha) : vpRGBa(color.R, color.G, color.B, alpha), id(color.id) {}
280 
282  inline virtual ~vpColor() {}
283 
284  friend VISP_EXPORT bool operator==(const vpColor &c1, const vpColor &c2);
285  friend VISP_EXPORT bool operator!=(const vpColor &c1, const vpColor &c2);
298  inline void setColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a = vpRGBa::alpha_default)
299  {
300  this->R = r;
301  this->G = g;
302  this->B = b;
303  this->A = a;
304  id = id_unknown;
305  }
306 
313  static inline vpColor getColor(const unsigned int &i) { return vpColor::allColors[i % vpColor::nbColors]; }
314 };
315 
316 // In this file if windows
317 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
319 vpColor const __declspec(selectany) vpColor::black = vpColor(0, 0, 0, id_black);
322 vpColor const __declspec(selectany) vpColor::white = vpColor(255, 255, 255, id_white);
325 vpColor const __declspec(selectany) vpColor::lightGray = vpColor(192, 192, 192, id_lightGray);
327 vpColor const __declspec(selectany) vpColor::gray = vpColor(128, 128, 128, id_gray);
330 vpColor const __declspec(selectany) vpColor::darkGray = vpColor(64, 64, 64, id_darkGray);
333 vpColor const __declspec(selectany) vpColor::lightRed = vpColor(255, 140, 140, id_lightRed);
336 vpColor const __declspec(selectany) vpColor::red = vpColor(255, 0, 0, id_red);
339 vpColor const __declspec(selectany) vpColor::darkRed = vpColor(128, 0, 0, id_darkRed);
342 vpColor const __declspec(selectany) vpColor::lightGreen = vpColor(140, 255, 140, id_lightGreen);
345 vpColor const __declspec(selectany) vpColor::green = vpColor(0, 255, 0, id_green);
348 vpColor const __declspec(selectany) vpColor::darkGreen = vpColor(0, 128, 0, id_darkGreen);
351 vpColor const __declspec(selectany) vpColor::lightBlue = vpColor(140, 140, 255, id_lightBlue);
354 vpColor const __declspec(selectany) vpColor::blue = vpColor(0, 0, 255, id_blue);
357 vpColor const __declspec(selectany) vpColor::darkBlue = vpColor(0, 0, 128, id_darkBlue);
360 vpColor const __declspec(selectany) vpColor::yellow = vpColor(255, 255, 0, id_yellow);
363 vpColor const __declspec(selectany) vpColor::cyan = vpColor(0, 255, 255, id_cyan);
366 vpColor const __declspec(selectany) vpColor::orange = vpColor(255, 165, 0, id_orange);
369 vpColor const __declspec(selectany) vpColor::purple = vpColor(128, 0, 128, id_purple);
371 vpColor const __declspec(selectany) vpColor::none = vpColor(0, 0, 0, id_unknown);
372 
373 const __declspec(selectany) unsigned int vpColor::nbColors = 18;
374 
376 vpColor const __declspec(selectany) vpColor::allColors[vpColor::nbColors] = {vpColor::blue, // 12
377  vpColor::green, // 9
378  vpColor::red, // 6
379  vpColor::cyan, // 15
380  vpColor::purple, // 4
381  vpColor::yellow, // 14
382  vpColor::orange, // 16
383  vpColor::lightBlue, // 11
384  vpColor::lightGreen, // 8
385  vpColor::lightRed, // 5
386  vpColor::darkBlue, // 13
387  vpColor::darkGreen, // 10
388  vpColor::darkRed, // 7
389  vpColor::lightGray, // 2
390  vpColor::gray, // 3
391  vpColor::darkGray, // 4
392  vpColor::black, // 0
393  vpColor::white}; // 17
394 
395 #endif
396 
397 #endif
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:158
static const vpColor white
Definition: vpColor.h:212
vpColorIdentifier id
Definition: vpColor.h:206
vpColor(const vpColor &color, unsigned char alpha)
Definition: vpColor.h:279
static vpColor getColor(const unsigned int &i)
Definition: vpColor.h:313
static const vpColor red
Definition: vpColor.h:217
static const vpColor darkGray
Definition: vpColor.h:215
static const vpColor black
Definition: vpColor.h:211
static const vpColor cyan
Definition: vpColor.h:226
static const vpColor none
Definition: vpColor.h:229
static const vpColor orange
Definition: vpColor.h:227
static const vpColor darkRed
Definition: vpColor.h:218
static const vpColor blue
Definition: vpColor.h:223
static const vpColor lightGray
Definition: vpColor.h:213
static const vpColor lightBlue
Definition: vpColor.h:222
vpColor(unsigned char r, unsigned char g, unsigned char b, unsigned char alpha, vpColor::vpColorIdentifier cid=vpColor::id_unknown)
Definition: vpColor.h:268
vpColor(unsigned char r, unsigned char g, unsigned char b, vpColor::vpColorIdentifier cid=vpColor::id_unknown)
Definition: vpColor.h:252
static const vpColor darkGreen
Definition: vpColor.h:221
static const unsigned int nbColors
Definition: vpColor.h:231
void setColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a=vpRGBa::alpha_default)
Definition: vpColor.h:298
virtual ~vpColor()
Definition: vpColor.h:282
static const vpColor darkBlue
Definition: vpColor.h:224
static const vpColor purple
Definition: vpColor.h:228
static const vpColor lightGreen
Definition: vpColor.h:219
static const vpColor yellow
Definition: vpColor.h:225
static const vpColor allColors[]
Definition: vpColor.h:232
vpColor()
Definition: vpColor.h:241
vpColorIdentifier
Definition: vpColor.h:161
@ id_unknown
Definition: vpColor.h:199
static const vpColor lightRed
Definition: vpColor.h:216
static const vpColor green
Definition: vpColor.h:220
static const vpColor gray
Definition: vpColor.h:214
Definition: vpRGBa.h:67
bool operator!=(const vpRGBa &v)
Definition: vpRGBa.cpp:136
@ alpha_default
Definition: vpRGBa.h:69
bool operator==(const vpRGBa &v)
Definition: vpRGBa.cpp:118