Visual Servoing Platform  version 3.6.1 under development (2025-01-24)
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,
181  id_unknown
185  } vpColorIdentifier;
186 
191  /* Predefined colors. */
192  static const vpColor black;
193  static const vpColor white;
194  static const vpColor lightGray;
195  static const vpColor gray;
196  static const vpColor darkGray;
197  static const vpColor lightRed;
198  static const vpColor red;
199  static const vpColor darkRed;
200  static const vpColor lightGreen;
201  static const vpColor green;
202  static const vpColor darkGreen;
203  static const vpColor lightBlue;
204  static const vpColor blue;
205  static const vpColor darkBlue;
206  static const vpColor yellow;
207  static const vpColor cyan;
208  static const vpColor orange;
209  static const vpColor purple;
210  static const vpColor none;
211 
212  static const unsigned int nbColors;
213  static const vpColor allColors[];
214 
222  inline vpColor() : vpRGBa(), id(id_unknown) { }
233  inline vpColor(unsigned char r, unsigned char g, unsigned char b,
235  : vpRGBa(r, g, b), id(cid)
236  { }
248  inline vpColor(unsigned char r, unsigned char g, unsigned char b, unsigned char alpha,
250  : vpRGBa(r, g, b, alpha), id(cid)
251  { }
258  inline vpColor(const vpColor &color, unsigned char alpha) : vpRGBa(color.R, color.G, color.B, alpha), id(color.id) { }
259 
261  inline virtual ~vpColor() { }
262 
263  friend VISP_EXPORT bool operator==(const vpColor &c1, const vpColor &c2);
264  friend VISP_EXPORT bool operator!=(const vpColor &c1, const vpColor &c2);
277  inline void setColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a = vpRGBa::alpha_default)
278  {
279  this->R = r;
280  this->G = g;
281  this->B = b;
282  this->A = a;
283  id = id_unknown;
284  }
285 
292  static inline vpColor getColor(const unsigned int &i) { return vpColor::allColors[i % vpColor::nbColors]; }
293 };
294 
295 // In this file if windows
296 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
298 vpColor const __declspec(selectany) vpColor::black = vpColor(0, 0, 0, id_black);
301 vpColor const __declspec(selectany) vpColor::white = vpColor(255, 255, 255, id_white);
304 vpColor const __declspec(selectany) vpColor::lightGray = vpColor(192, 192, 192, id_lightGray);
306 vpColor const __declspec(selectany) vpColor::gray = vpColor(128, 128, 128, id_gray);
309 vpColor const __declspec(selectany) vpColor::darkGray = vpColor(64, 64, 64, id_darkGray);
312 vpColor const __declspec(selectany) vpColor::lightRed = vpColor(255, 140, 140, id_lightRed);
315 vpColor const __declspec(selectany) vpColor::red = vpColor(255, 0, 0, id_red);
318 vpColor const __declspec(selectany) vpColor::darkRed = vpColor(128, 0, 0, id_darkRed);
321 vpColor const __declspec(selectany) vpColor::lightGreen = vpColor(140, 255, 140, id_lightGreen);
324 vpColor const __declspec(selectany) vpColor::green = vpColor(0, 255, 0, id_green);
327 vpColor const __declspec(selectany) vpColor::darkGreen = vpColor(0, 128, 0, id_darkGreen);
330 vpColor const __declspec(selectany) vpColor::lightBlue = vpColor(140, 140, 255, id_lightBlue);
333 vpColor const __declspec(selectany) vpColor::blue = vpColor(0, 0, 255, id_blue);
336 vpColor const __declspec(selectany) vpColor::darkBlue = vpColor(0, 0, 128, id_darkBlue);
339 vpColor const __declspec(selectany) vpColor::yellow = vpColor(255, 255, 0, id_yellow);
342 vpColor const __declspec(selectany) vpColor::cyan = vpColor(0, 255, 255, id_cyan);
345 vpColor const __declspec(selectany) vpColor::orange = vpColor(255, 165, 0, id_orange);
348 vpColor const __declspec(selectany) vpColor::purple = vpColor(128, 0, 128, id_purple);
350 vpColor const __declspec(selectany) vpColor::none = vpColor(0, 0, 0, id_unknown);
351 
352 const __declspec(selectany) unsigned int vpColor::nbColors = 18;
353 
355 vpColor const __declspec(selectany) vpColor::allColors[vpColor::nbColors] = { vpColor::blue, // 12
356  vpColor::green, // 9
357  vpColor::red, // 6
358  vpColor::cyan, // 15
359  vpColor::purple, // 4
360  vpColor::yellow, // 14
361  vpColor::orange, // 16
362  vpColor::lightBlue, // 11
363  vpColor::lightGreen, // 8
364  vpColor::lightRed, // 5
365  vpColor::darkBlue, // 13
366  vpColor::darkGreen, // 10
367  vpColor::darkRed, // 7
368  vpColor::lightGray, // 2
369  vpColor::gray, // 3
370  vpColor::darkGray, // 4
371  vpColor::black, // 0
373 }; // 17
374 
375 #endif
376 END_VISP_NAMESPACE
377 #endif
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static const vpColor white
Definition: vpColor.h:193
vpColorIdentifier id
Definition: vpColor.h:187
vpColor(const vpColor &color, unsigned char alpha)
Definition: vpColor.h:258
static vpColor getColor(const unsigned int &i)
Definition: vpColor.h:292
static const vpColor red
Definition: vpColor.h:198
static const vpColor darkGray
Definition: vpColor.h:196
static const vpColor cyan
Definition: vpColor.h:207
static const vpColor none
Definition: vpColor.h:210
static const vpColor orange
Definition: vpColor.h:208
static const vpColor darkRed
Definition: vpColor.h:199
static const vpColor blue
Definition: vpColor.h:204
static const vpColor lightGray
Definition: vpColor.h:194
static const vpColor lightBlue
Definition: vpColor.h:203
vpColor(unsigned char r, unsigned char g, unsigned char b, unsigned char alpha, vpColor::vpColorIdentifier cid=vpColor::id_unknown)
Definition: vpColor.h:248
vpColor(unsigned char r, unsigned char g, unsigned char b, vpColor::vpColorIdentifier cid=vpColor::id_unknown)
Definition: vpColor.h:233
static const vpColor darkGreen
Definition: vpColor.h:202
static const unsigned int nbColors
Definition: vpColor.h:212
void setColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a=vpRGBa::alpha_default)
Definition: vpColor.h:277
virtual ~vpColor()
Definition: vpColor.h:261
static const vpColor darkBlue
Definition: vpColor.h:205
static const vpColor purple
Definition: vpColor.h:209
static const vpColor lightGreen
Definition: vpColor.h:200
static const vpColor yellow
Definition: vpColor.h:206
static const vpColor allColors[]
Definition: vpColor.h:213
vpColor()
Definition: vpColor.h:222
vpColorIdentifier
Definition: vpColor.h:161
@ id_lightBlue
Definition: vpColor.h:173
@ id_yellow
Definition: vpColor.h:176
@ id_darkGray
Definition: vpColor.h:166
@ id_green
Definition: vpColor.h:171
@ id_darkRed
Definition: vpColor.h:169
@ id_lightGray
Definition: vpColor.h:164
@ id_red
Definition: vpColor.h:168
@ id_lightRed
Definition: vpColor.h:167
@ id_white
Definition: vpColor.h:163
@ id_blue
Definition: vpColor.h:174
@ id_darkGreen
Definition: vpColor.h:172
@ id_gray
Definition: vpColor.h:165
@ id_lightGreen
Definition: vpColor.h:170
@ id_purple
Definition: vpColor.h:179
@ id_orange
Definition: vpColor.h:178
@ id_cyan
Definition: vpColor.h:177
@ id_darkBlue
Definition: vpColor.h:175
@ id_unknown
Definition: vpColor.h:181
static const vpColor lightRed
Definition: vpColor.h:197
static const vpColor black
Definition: vpColor.h:192
static const vpColor green
Definition: vpColor.h:201
static const vpColor gray
Definition: vpColor.h:195
Definition: vpRGBa.h:70
@ alpha_default
Definition: vpRGBa.h:72
bool operator!=(const vpRGBa &v) const
Definition: vpRGBa.cpp:129
bool operator==(const vpRGBa &v) const
Definition: vpRGBa.cpp:120