Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
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
101#include <visp3/gui/vpDisplayGTK.h>
102#include <visp3/gui/vpDisplayOpenCV.h>
103#include <visp3/gui/vpDisplayX.h>
104
105int main()
106{
107 vpImage<unsigned char> I(240, 320); // Create a black grey level image
108
109 vpDisplay *d;
110
111 // Depending on the detected third party libraries, we instantiate here the
112 // first video device which is available
113#if defined(VISP_HAVE_X11)
114 d = new vpDisplayX;
115#elif defined(VISP_HAVE_GTK)
116 d = new vpDisplayGTK;
117#elif defined(VISP_HAVE_GDI)
118 d = new vpDisplayGDI;
119#elif defined(VISP_HAVE_D3D9)
120 d = new vpDisplayD3D;
121#elif defined(HAVE_OPENCV_HIGHGUI)
122 d = new vpDisplayOpenCV;
123#endif
124
125 // Initialize the display with the image I. Display and image are
126 // now link together.
127#ifdef VISP_HAVE_DISPLAY
128 d->init(I);
129#endif
130
131 // Set the display background with image I content
132 vpDisplay::display(I);
133
134 // Draw a filled circle with the predefined blue color
135 vpDisplay::displayCircle(I, 100, 200, 30, vpColor::blue, true);
136
137 // Creation of a new brown color with its RGB values
138 vpColor color(128, 100, 50);
139
140 // Draw a brown rectangle in the display overlay (foreground)
141 vpDisplay::displayRectangle(I, 10, 10, 100, 20, color, true);
142
143 // Flush the foreground and background display
144 vpDisplay::flush(I);
145
146 delete d;
147}
148 \endcode
149
150*/
151class VISP_EXPORT vpColor : public vpRGBa
152{
153public:
199
203
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 }
251
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 }
267
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)
313vpColor const __declspec(selectany) vpColor::black = vpColor(0, 0, 0, id_black);
316vpColor const __declspec(selectany) vpColor::white = vpColor(255, 255, 255, id_white);
319vpColor const __declspec(selectany) vpColor::lightGray = vpColor(192, 192, 192, id_lightGray);
321vpColor const __declspec(selectany) vpColor::gray = vpColor(128, 128, 128, id_gray);
324vpColor const __declspec(selectany) vpColor::darkGray = vpColor(64, 64, 64, id_darkGray);
327vpColor const __declspec(selectany) vpColor::lightRed = vpColor(255, 140, 140, id_lightRed);
330vpColor const __declspec(selectany) vpColor::red = vpColor(255, 0, 0, id_red);
333vpColor const __declspec(selectany) vpColor::darkRed = vpColor(128, 0, 0, id_darkRed);
336vpColor const __declspec(selectany) vpColor::lightGreen = vpColor(140, 255, 140, id_lightGreen);
339vpColor const __declspec(selectany) vpColor::green = vpColor(0, 255, 0, id_green);
342vpColor const __declspec(selectany) vpColor::darkGreen = vpColor(0, 128, 0, id_darkGreen);
345vpColor const __declspec(selectany) vpColor::lightBlue = vpColor(140, 140, 255, id_lightBlue);
348vpColor const __declspec(selectany) vpColor::blue = vpColor(0, 0, 255, id_blue);
351vpColor const __declspec(selectany) vpColor::darkBlue = vpColor(0, 0, 128, id_darkBlue);
354vpColor const __declspec(selectany) vpColor::yellow = vpColor(255, 255, 0, id_yellow);
357vpColor const __declspec(selectany) vpColor::cyan = vpColor(0, 255, 255, id_cyan);
360vpColor const __declspec(selectany) vpColor::orange = vpColor(255, 165, 0, id_orange);
363vpColor const __declspec(selectany) vpColor::purple = vpColor(128, 0, 128, id_purple);
365vpColor const __declspec(selectany) vpColor::none = vpColor(0, 0, 0, id_unknown);
366
367const __declspec(selectany) unsigned int vpColor::nbColors = 18;
368
370vpColor 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
380 vpColor::darkBlue, // 13
381 vpColor::darkGreen, // 10
382 vpColor::darkRed, // 7
384 vpColor::gray, // 3
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:101
vpColor()
Definition vpColor.h:235
vpColorIdentifier
Definition vpColor.h:155
@ id_lightBlue
Definition vpColor.h:178
@ id_yellow
Definition vpColor.h:184
@ id_darkGray
Definition vpColor.h:164
@ id_green
Definition vpColor.h:174
@ id_darkRed
Definition vpColor.h:170
@ id_lightGray
Definition vpColor.h:160
@ id_red
Definition vpColor.h:168
@ id_lightRed
Definition vpColor.h:166
@ id_white
Definition vpColor.h:158
@ id_black
Definition vpColor.h:156
@ id_blue
Definition vpColor.h:180
@ id_darkGreen
Definition vpColor.h:176
@ id_gray
Definition vpColor.h:162
@ id_lightGreen
Definition vpColor.h:172
@ id_purple
Definition vpColor.h:190
@ id_orange
Definition vpColor.h:188
@ id_cyan
Definition vpColor.h:186
@ id_darkBlue
Definition vpColor.h:182
@ 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
unsigned char B
Blue component.
Definition vpRGBa.h:140
unsigned char R
Red component.
Definition vpRGBa.h:138
vpRGBa()
Definition vpRGBa.h:70
unsigned char G
Green component.
Definition vpRGBa.h:139
@ alpha_default
Definition vpRGBa.h:63
unsigned char A
Additionnal component.
Definition vpRGBa.h:141
bool operator!=(const vpRGBa &v) const
Definition vpRGBa.cpp:123
bool operator==(const vpRGBa &v) const
Definition vpRGBa.cpp:114