Visual Servoing Platform  version 3.6.1 under development (2024-03-18)
vpColor.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Color definition.
32  */
33 
34 #ifndef vpColor_hh
35 #define vpColor_hh
36 
37 #include <visp3/core/vpConfig.h>
38 #include <visp3/core/vpRGBa.h>
39 
151 class VISP_EXPORT vpColor : public vpRGBa
152 {
153 public:
155  typedef enum {
156  id_black = 0,
158  id_white,
160  id_lightGray,
162  id_gray,
164  id_darkGray,
166  id_lightRed,
168  id_red,
170  id_darkRed,
172  id_lightGreen,
174  id_green,
176  id_darkGreen,
178  id_lightBlue,
180  id_blue,
182  id_darkBlue,
184  id_yellow,
186  id_cyan,
188  id_orange,
190  id_purple,
193  id_unknown
198  } vpColorIdentifier;
199 
204  /* Predefined colors. */
205  static const vpColor black;
206  static const vpColor white;
207  static const vpColor lightGray;
208  static const vpColor gray;
209  static const vpColor darkGray;
210  static const vpColor lightRed;
211  static const vpColor red;
212  static const vpColor darkRed;
213  static const vpColor lightGreen;
214  static const vpColor green;
215  static const vpColor darkGreen;
216  static const vpColor lightBlue;
217  static const vpColor blue;
218  static const vpColor darkBlue;
219  static const vpColor yellow;
220  static const vpColor cyan;
221  static const vpColor orange;
222  static const vpColor purple;
223  static const vpColor none;
224 
225  static const unsigned int nbColors;
226  static const vpColor allColors[];
227 
235  inline vpColor() : vpRGBa(), id(id_unknown) {}
246  inline vpColor(unsigned char r, unsigned char g, unsigned char b,
248  : vpRGBa(r, g, b), id(cid)
249  {
250  }
262  inline vpColor(unsigned char r, unsigned char g, unsigned char b, unsigned char alpha,
264  : vpRGBa(r, g, b, alpha), id(cid)
265  {
266  }
273  inline vpColor(const vpColor &color, unsigned char alpha) : vpRGBa(color.R, color.G, color.B, alpha), id(color.id) {}
274 
276  inline virtual ~vpColor() {}
277 
278  friend VISP_EXPORT bool operator==(const vpColor &c1, const vpColor &c2);
279  friend VISP_EXPORT bool operator!=(const vpColor &c1, const vpColor &c2);
292  inline void setColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a = vpRGBa::alpha_default)
293  {
294  this->R = r;
295  this->G = g;
296  this->B = b;
297  this->A = a;
298  id = id_unknown;
299  }
300 
307  static inline vpColor getColor(const unsigned int &i) { return vpColor::allColors[i % vpColor::nbColors]; }
308 };
309 
310 // In this file if windows
311 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
313 vpColor const __declspec(selectany) vpColor::black = vpColor(0, 0, 0, id_black);
316 vpColor const __declspec(selectany) vpColor::white = vpColor(255, 255, 255, id_white);
319 vpColor const __declspec(selectany) vpColor::lightGray = vpColor(192, 192, 192, id_lightGray);
321 vpColor const __declspec(selectany) vpColor::gray = vpColor(128, 128, 128, id_gray);
324 vpColor const __declspec(selectany) vpColor::darkGray = vpColor(64, 64, 64, id_darkGray);
327 vpColor const __declspec(selectany) vpColor::lightRed = vpColor(255, 140, 140, id_lightRed);
330 vpColor const __declspec(selectany) vpColor::red = vpColor(255, 0, 0, id_red);
333 vpColor const __declspec(selectany) vpColor::darkRed = vpColor(128, 0, 0, id_darkRed);
336 vpColor const __declspec(selectany) vpColor::lightGreen = vpColor(140, 255, 140, id_lightGreen);
339 vpColor const __declspec(selectany) vpColor::green = vpColor(0, 255, 0, id_green);
342 vpColor const __declspec(selectany) vpColor::darkGreen = vpColor(0, 128, 0, id_darkGreen);
345 vpColor const __declspec(selectany) vpColor::lightBlue = vpColor(140, 140, 255, id_lightBlue);
348 vpColor const __declspec(selectany) vpColor::blue = vpColor(0, 0, 255, id_blue);
351 vpColor const __declspec(selectany) vpColor::darkBlue = vpColor(0, 0, 128, id_darkBlue);
354 vpColor const __declspec(selectany) vpColor::yellow = vpColor(255, 255, 0, id_yellow);
357 vpColor const __declspec(selectany) vpColor::cyan = vpColor(0, 255, 255, id_cyan);
360 vpColor const __declspec(selectany) vpColor::orange = vpColor(255, 165, 0, id_orange);
363 vpColor const __declspec(selectany) vpColor::purple = vpColor(128, 0, 128, id_purple);
365 vpColor const __declspec(selectany) vpColor::none = vpColor(0, 0, 0, id_unknown);
366 
367 const __declspec(selectany) unsigned int vpColor::nbColors = 18;
368 
370 vpColor const __declspec(selectany) vpColor::allColors[vpColor::nbColors] = {vpColor::blue, // 12
371  vpColor::green, // 9
372  vpColor::red, // 6
373  vpColor::cyan, // 15
374  vpColor::purple, // 4
375  vpColor::yellow, // 14
376  vpColor::orange, // 16
377  vpColor::lightBlue, // 11
378  vpColor::lightGreen, // 8
379  vpColor::lightRed, // 5
380  vpColor::darkBlue, // 13
381  vpColor::darkGreen, // 10
382  vpColor::darkRed, // 7
383  vpColor::lightGray, // 2
384  vpColor::gray, // 3
385  vpColor::darkGray, // 4
386  vpColor::black, // 0
387  vpColor::white}; // 17
388 
389 #endif
390 
391 #endif
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:152
static const vpColor white
Definition: vpColor.h:206
vpColorIdentifier id
Definition: vpColor.h:200
vpColor(const vpColor &color, unsigned char alpha)
Definition: vpColor.h:273
static vpColor getColor(const unsigned int &i)
Definition: vpColor.h:307
static const vpColor red
Definition: vpColor.h:211
static const vpColor darkGray
Definition: vpColor.h:209
static const vpColor black
Definition: vpColor.h:205
static const vpColor cyan
Definition: vpColor.h:220
static const vpColor none
Definition: vpColor.h:223
static const vpColor orange
Definition: vpColor.h:221
static const vpColor darkRed
Definition: vpColor.h:212
static const vpColor blue
Definition: vpColor.h:217
static const vpColor lightGray
Definition: vpColor.h:207
static const vpColor lightBlue
Definition: vpColor.h:216
vpColor(unsigned char r, unsigned char g, unsigned char b, unsigned char alpha, vpColor::vpColorIdentifier cid=vpColor::id_unknown)
Definition: vpColor.h:262
vpColor(unsigned char r, unsigned char g, unsigned char b, vpColor::vpColorIdentifier cid=vpColor::id_unknown)
Definition: vpColor.h:246
static const vpColor darkGreen
Definition: vpColor.h:215
static const unsigned int nbColors
Definition: vpColor.h:225
void setColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a=vpRGBa::alpha_default)
Definition: vpColor.h:292
virtual ~vpColor()
Definition: vpColor.h:276
static const vpColor darkBlue
Definition: vpColor.h:218
static const vpColor purple
Definition: vpColor.h:222
static const vpColor lightGreen
Definition: vpColor.h:213
static const vpColor yellow
Definition: vpColor.h:219
static const vpColor allColors[]
Definition: vpColor.h:226
vpColor()
Definition: vpColor.h:235
vpColorIdentifier
Definition: vpColor.h:155
@ id_unknown
Definition: vpColor.h:193
static const vpColor lightRed
Definition: vpColor.h:210
static const vpColor green
Definition: vpColor.h:214
static const vpColor gray
Definition: vpColor.h:208
Definition: vpRGBa.h:61
@ alpha_default
Definition: vpRGBa.h:63
bool operator!=(const vpRGBa &v) const
Definition: vpRGBa.cpp:123
bool operator==(const vpRGBa &v) const
Definition: vpRGBa.cpp:114