Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
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
100 #include <visp3/gui/vpDisplayD3D.h>
101 #include <visp3/gui/vpDisplayGDI.h>
102 #include <visp3/gui/vpDisplayGTK.h>
103 #include <visp3/gui/vpDisplayOpenCV.h>
104 #include <visp3/gui/vpDisplayX.h>
105
106 #ifdef ENABLE_VISP_NAMESPACE
107 using namespace VISP_NAMESPACE_NAME;
108 #endif
109
110 int main()
111 {
112 vpImage<unsigned char> I(240, 320); // Create a black grey level image
113
114 vpDisplay *d;
115
116 // Depending on the detected third party libraries, we instantiate here the
117 // first video device which is available
118 #if defined(VISP_HAVE_X11)
119 d = new vpDisplayX;
120 #elif defined(VISP_HAVE_GTK)
121 d = new vpDisplayGTK;
122 #elif defined(VISP_HAVE_GDI)
123 d = new vpDisplayGDI;
124 #elif defined(VISP_HAVE_D3D9)
125 d = new vpDisplayD3D;
126 #elif defined(HAVE_OPENCV_HIGHGUI)
127 d = new vpDisplayOpenCV;
128 #endif
129
130 // Initialize the display with the image I. Display and image are
131 // now link together.
132 #ifdef VISP_HAVE_DISPLAY
133 d->init(I);
134 #endif
135
136 // Set the display background with image I content
137 vpDisplay::display(I);
138
139 // Draw a filled circle with the predefined blue color
140 vpDisplay::displayCircle(I, 100, 200, 30, vpColor::blue, true);
141
142 // Creation of a new brown color with its RGB values
143 vpColor color(128, 100, 50);
144
145 // Draw a brown rectangle in the display overlay (foreground)
146 vpDisplay::displayRectangle(I, 10, 10, 100, 20, color, true);
147
148 // Flush the foreground and background display
149 vpDisplay::flush(I);
150
151 delete d;
152 }
153 \endcode
154
155*/
156class VISP_EXPORT vpColor : public vpRGBa
157{
158public:
186
190
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) { }
223
225#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
226 vpColor(const vpColor &) = default;
227 virtual ~vpColor() = default;
228#else
229 virtual ~vpColor() { }
230#endif
241 inline vpColor(unsigned char r, unsigned char g, unsigned char b,
243 : vpRGBa(r, g, b), id(cid)
244 { }
245
256 inline vpColor(unsigned char r, unsigned char g, unsigned char b, unsigned char alpha,
258 : vpRGBa(r, g, b, alpha), id(cid)
259 { }
260
266 inline vpColor(const vpColor &color, unsigned char alpha) : vpRGBa(color.R, color.G, color.B, alpha), id(color.id) { }
267
268#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
269 vpColor &operator=(const vpColor &) = default;
270#endif
271 friend VISP_EXPORT bool operator==(const vpColor &c1, const vpColor &c2);
272 friend VISP_EXPORT bool operator!=(const vpColor &c1, const vpColor &c2);
285 inline void setColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a = vpRGBa::alpha_default)
286 {
287 this->R = r;
288 this->G = g;
289 this->B = b;
290 this->A = a;
291 id = id_unknown;
292 }
293
300 static inline vpColor getColor(const unsigned int &i) { return vpColor::allColors[i % vpColor::nbColors]; }
301};
302
303// In this file if windows
304#if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
306VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::black = vpColor(0, 0, 0, id_black);
309VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::white = vpColor(255, 255, 255, id_white);
312VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::lightGray = vpColor(192, 192, 192, id_lightGray);
314VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::gray = vpColor(128, 128, 128, id_gray);
317VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::darkGray = vpColor(64, 64, 64, id_darkGray);
320VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::lightRed = vpColor(255, 140, 140, id_lightRed);
323VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::red = vpColor(255, 0, 0, id_red);
326VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::darkRed = vpColor(128, 0, 0, id_darkRed);
329VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::lightGreen = vpColor(140, 255, 140, id_lightGreen);
332VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::green = vpColor(0, 255, 0, id_green);
335VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::darkGreen = vpColor(0, 128, 0, id_darkGreen);
338VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::lightBlue = vpColor(140, 140, 255, id_lightBlue);
341VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::blue = vpColor(0, 0, 255, id_blue);
344VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::darkBlue = vpColor(0, 0, 128, id_darkBlue);
347VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::yellow = vpColor(255, 255, 0, id_yellow);
350VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::cyan = vpColor(0, 255, 255, id_cyan);
353VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::orange = vpColor(255, 165, 0, id_orange);
356VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::purple = vpColor(128, 0, 128, id_purple);
358VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::none = vpColor(0, 0, 0, id_unknown);
359
360VP_ATTRIBUTE_NO_DESTROY const __declspec(selectany) unsigned int vpColor::nbColors = 18;
361
363VP_ATTRIBUTE_NO_DESTROY vpColor const __declspec(selectany) vpColor::allColors[vpColor::nbColors] = {
364 vpColor::blue, // 12
365 vpColor::green, // 9
366 vpColor::red, // 6
367 vpColor::cyan, // 15
368 vpColor::purple, // 4
369 vpColor::yellow, // 14
370 vpColor::orange, // 16
371 vpColor::lightBlue, // 11
374 vpColor::darkBlue, // 13
375 vpColor::darkGreen, // 10
376 vpColor::darkRed, // 7
378 vpColor::gray, // 3
380 vpColor::black, // 0
382}; // 17
383
384#endif
385END_VISP_NAMESPACE
386#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:266
static vpColor getColor(const unsigned int &i)
Definition vpColor.h:300
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:256
vpColor(unsigned char r, unsigned char g, unsigned char b, vpColor::vpColorIdentifier cid=vpColor::id_unknown)
Definition vpColor.h:241
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:285
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:100
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_black
Definition vpColor.h:162
@ 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
vpColor(const vpColor &)=default
static const vpColor lightRed
Definition vpColor.h:197
vpColor & operator=(const vpColor &)=default
virtual ~vpColor()=default
static const vpColor black
Definition vpColor.h:192
static const vpColor green
Definition vpColor.h:201
static const vpColor gray
Definition vpColor.h:195
unsigned char B
Blue component.
Definition vpRGBa.h:327
unsigned char R
Red component.
Definition vpRGBa.h:325
vpRGBa()
Definition vpRGBa.h:83
unsigned char G
Green component.
Definition vpRGBa.h:326
@ alpha_default
Definition vpRGBa.h:76
unsigned char A
Additional component.
Definition vpRGBa.h:328
bool operator!=(const vpRGBa &v) const
Definition vpRGBa.cpp:132
bool operator==(const vpRGBa &v) const
Definition vpRGBa.cpp:123