Visual Servoing Platform  version 3.3.1 under development (2020-09-18)
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
205 
206  vpColorIdentifier id;
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){}
266  inline vpColor(unsigned char r, unsigned char g, unsigned char b, unsigned char alpha,
268  : vpRGBa(r, g, b, alpha), id(cid){}
275  inline vpColor(const vpColor &color, unsigned char alpha)
276  : vpRGBa(color.R, color.G, color.B, alpha), id(color.id) {}
277 
279  inline virtual ~vpColor(){}
280 
281  friend VISP_EXPORT bool operator==(const vpColor &c1, const vpColor &c2);
282  friend VISP_EXPORT bool operator!=(const vpColor &c1, const vpColor &c2);
295  inline void setColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a=vpRGBa::alpha_default)
296  {
297  this->R = r;
298  this->G = g;
299  this->B = b;
300  this->A = a;
301  id = id_unknown;
302  }
303 
310  static inline vpColor getColor(const unsigned int &i) { return vpColor::allColors[i % vpColor::nbColors]; }
311 };
312 
313 // In this file if windows
314 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
315 
316 vpColor const __declspec(selectany) vpColor::black = vpColor(0, 0, 0, id_black);
319 vpColor const __declspec(selectany) vpColor::white = vpColor(255, 255, 255, id_white);
322 vpColor const __declspec(selectany) vpColor::lightGray = vpColor(192, 192, 192, id_lightGray);
324 vpColor const __declspec(selectany) vpColor::gray = vpColor(128, 128, 128, id_gray);
327 vpColor const __declspec(selectany) vpColor::darkGray = vpColor(64, 64, 64, id_darkGray);
330 vpColor const __declspec(selectany) vpColor::lightRed = vpColor(255, 140, 140, id_lightRed);
333 vpColor const __declspec(selectany) vpColor::red = vpColor(255, 0, 0, id_red);
336 vpColor const __declspec(selectany) vpColor::darkRed = vpColor(128, 0, 0, id_darkRed);
339 vpColor const __declspec(selectany) vpColor::lightGreen = vpColor(140, 255, 140, id_lightGreen);
342 vpColor const __declspec(selectany) vpColor::green = vpColor(0, 255, 0, id_green);
345 vpColor const __declspec(selectany) vpColor::darkGreen = vpColor(0, 128, 0, id_darkGreen);
348 vpColor const __declspec(selectany) vpColor::lightBlue = vpColor(140, 140, 255, id_lightBlue);
351 vpColor const __declspec(selectany) vpColor::blue = vpColor(0, 0, 255, id_blue);
354 vpColor const __declspec(selectany) vpColor::darkBlue = vpColor(0, 0, 128, id_darkBlue);
357 vpColor const __declspec(selectany) vpColor::yellow = vpColor(255, 255, 0, id_yellow);
360 vpColor const __declspec(selectany) vpColor::cyan = vpColor(0, 255, 255, id_cyan);
363 vpColor const __declspec(selectany) vpColor::orange = vpColor(255, 165, 0, id_orange);
366 vpColor const __declspec(selectany) vpColor::purple = vpColor(128, 0, 128, id_purple);
368 vpColor const __declspec(selectany) vpColor::none = vpColor(0, 0, 0, id_unknown);
369 
370 const __declspec(selectany) unsigned int vpColor::nbColors = 18;
371 
373 vpColor const __declspec(selectany) vpColor::allColors[vpColor::nbColors] = {vpColor::blue, // 12
374  vpColor::green, // 9
375  vpColor::red, // 6
376  vpColor::cyan, // 15
377  vpColor::purple, // 4
378  vpColor::yellow, // 14
379  vpColor::orange, // 16
380  vpColor::lightBlue, // 11
381  vpColor::lightGreen, // 8
382  vpColor::lightRed, // 5
383  vpColor::darkBlue, // 13
384  vpColor::darkGreen, // 10
385  vpColor::darkRed, // 7
386  vpColor::lightGray, // 2
387  vpColor::gray, // 3
388  vpColor::darkGray, // 4
389  vpColor::black, // 0
390  vpColor::white}; // 17
391 
392 #endif
393 
394 #endif
vpColor(unsigned char r, unsigned char g, unsigned char b, unsigned char alpha, vpColor::vpColorIdentifier cid=vpColor::id_unknown)
Definition: vpColor.h:266
vpColor()
Definition: vpColor.h:241
static const vpColor allColors[]
Definition: vpColor.h:232
static const vpColor black
Definition: vpColor.h:211
static const vpColor darkRed
Definition: vpColor.h:218
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:157
static const vpColor none
Definition: vpColor.h:229
vpColor(const vpColor &color, unsigned char alpha)
Definition: vpColor.h:275
static const vpColor lightGray
Definition: vpColor.h:213
static const vpColor darkBlue
Definition: vpColor.h:224
static const vpColor green
Definition: vpColor.h:220
void setColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a=vpRGBa::alpha_default)
Definition: vpColor.h:295
static const vpColor lightRed
Definition: vpColor.h:216
Definition: vpRGBa.h:66
static const vpColor red
Definition: vpColor.h:217
static const vpColor orange
Definition: vpColor.h:227
vpColorIdentifier id
Definition: vpColor.h:206
bool operator==(const vpRGBa &v)
Definition: vpRGBa.cpp:118
static const vpColor cyan
Definition: vpColor.h:226
static const vpColor lightGreen
Definition: vpColor.h:219
vpColorIdentifier
Definition: vpColor.h:161
static const vpColor gray
Definition: vpColor.h:214
static const vpColor darkGray
Definition: vpColor.h:215
virtual ~vpColor()
Definition: vpColor.h:279
static const vpColor darkGreen
Definition: vpColor.h:221
static vpColor getColor(const unsigned int &i)
Definition: vpColor.h:310
static const vpColor yellow
Definition: vpColor.h:225
static const vpColor lightBlue
Definition: vpColor.h:222
static const vpColor purple
Definition: vpColor.h:228
static const vpColor white
Definition: vpColor.h:212
bool operator!=(const vpRGBa &v)
Definition: vpRGBa.cpp:136
static const unsigned int nbColors
Definition: vpColor.h:231
static const vpColor blue
Definition: vpColor.h:223
vpColor(unsigned char r, unsigned char g, unsigned char b, vpColor::vpColorIdentifier cid=vpColor::id_unknown)
Definition: vpColor.h:252