Visual Servoing Platform  version 3.6.1 under development (2024-10-09)
vpColor.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 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 VP_COLOR_H
35 #define VP_COLOR_H
36 
37 #include <visp3/core/vpConfig.h>
38 #include <visp3/core/vpRGBa.h>
39 
40 BEGIN_VISP_NAMESPACE
156 class VISP_EXPORT vpColor : public vpRGBa
157 {
158 public:
160  typedef enum
161  {
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  { }
267  inline vpColor(unsigned char r, unsigned char g, unsigned char b, unsigned char alpha,
269  : vpRGBa(r, g, b, alpha), id(cid)
270  { }
277  inline vpColor(const vpColor &color, unsigned char alpha) : vpRGBa(color.R, color.G, color.B, alpha), id(color.id) { }
278 
280  inline virtual ~vpColor() { }
281 
282  friend VISP_EXPORT bool operator==(const vpColor &c1, const vpColor &c2);
283  friend VISP_EXPORT bool operator!=(const vpColor &c1, const vpColor &c2);
296  inline void setColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a = vpRGBa::alpha_default)
297  {
298  this->R = r;
299  this->G = g;
300  this->B = b;
301  this->A = a;
302  id = id_unknown;
303  }
304 
311  static inline vpColor getColor(const unsigned int &i) { return vpColor::allColors[i % vpColor::nbColors]; }
312 };
313 
314 // In this file if windows
315 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
317 vpColor const __declspec(selectany) vpColor::black = vpColor(0, 0, 0, id_black);
320 vpColor const __declspec(selectany) vpColor::white = vpColor(255, 255, 255, id_white);
323 vpColor const __declspec(selectany) vpColor::lightGray = vpColor(192, 192, 192, id_lightGray);
325 vpColor const __declspec(selectany) vpColor::gray = vpColor(128, 128, 128, id_gray);
328 vpColor const __declspec(selectany) vpColor::darkGray = vpColor(64, 64, 64, id_darkGray);
331 vpColor const __declspec(selectany) vpColor::lightRed = vpColor(255, 140, 140, id_lightRed);
334 vpColor const __declspec(selectany) vpColor::red = vpColor(255, 0, 0, id_red);
337 vpColor const __declspec(selectany) vpColor::darkRed = vpColor(128, 0, 0, id_darkRed);
340 vpColor const __declspec(selectany) vpColor::lightGreen = vpColor(140, 255, 140, id_lightGreen);
343 vpColor const __declspec(selectany) vpColor::green = vpColor(0, 255, 0, id_green);
346 vpColor const __declspec(selectany) vpColor::darkGreen = vpColor(0, 128, 0, id_darkGreen);
349 vpColor const __declspec(selectany) vpColor::lightBlue = vpColor(140, 140, 255, id_lightBlue);
352 vpColor const __declspec(selectany) vpColor::blue = vpColor(0, 0, 255, id_blue);
355 vpColor const __declspec(selectany) vpColor::darkBlue = vpColor(0, 0, 128, id_darkBlue);
358 vpColor const __declspec(selectany) vpColor::yellow = vpColor(255, 255, 0, id_yellow);
361 vpColor const __declspec(selectany) vpColor::cyan = vpColor(0, 255, 255, id_cyan);
364 vpColor const __declspec(selectany) vpColor::orange = vpColor(255, 165, 0, id_orange);
367 vpColor const __declspec(selectany) vpColor::purple = vpColor(128, 0, 128, id_purple);
369 vpColor const __declspec(selectany) vpColor::none = vpColor(0, 0, 0, id_unknown);
370 
371 const __declspec(selectany) unsigned int vpColor::nbColors = 18;
372 
374 vpColor const __declspec(selectany) vpColor::allColors[vpColor::nbColors] = { vpColor::blue, // 12
375  vpColor::green, // 9
376  vpColor::red, // 6
377  vpColor::cyan, // 15
378  vpColor::purple, // 4
379  vpColor::yellow, // 14
380  vpColor::orange, // 16
381  vpColor::lightBlue, // 11
382  vpColor::lightGreen, // 8
383  vpColor::lightRed, // 5
384  vpColor::darkBlue, // 13
385  vpColor::darkGreen, // 10
386  vpColor::darkRed, // 7
387  vpColor::lightGray, // 2
388  vpColor::gray, // 3
389  vpColor::darkGray, // 4
390  vpColor::black, // 0
392 }; // 17
393 
394 #endif
395 END_VISP_NAMESPACE
396 #endif
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static const vpColor white
Definition: vpColor.h:212
vpColorIdentifier id
Definition: vpColor.h:206
vpColor(const vpColor &color, unsigned char alpha)
Definition: vpColor.h:277
static vpColor getColor(const unsigned int &i)
Definition: vpColor.h:311
static const vpColor red
Definition: vpColor.h:217
static const vpColor darkGray
Definition: vpColor.h:215
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:267
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:296
virtual ~vpColor()
Definition: vpColor.h:280
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 black
Definition: vpColor.h:211
static const vpColor green
Definition: vpColor.h:220
static const vpColor gray
Definition: vpColor.h:214
Definition: vpRGBa.h:65
@ alpha_default
Definition: vpRGBa.h:67
bool operator!=(const vpRGBa &v) const
Definition: vpRGBa.cpp:154
bool operator==(const vpRGBa &v) const
Definition: vpRGBa.cpp:145