Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpColorGetter.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 getter.
32 */
33
34#ifndef VP_COLOR_GETTER_H
35#define VP_COLOR_GETTER_H
36
37#include <visp3/core/vpConfig.h>
38#include <visp3/core/vpHSV.h>
39#include <visp3/core/vpRGBa.h>
40
47 template <int ID>
49{
50public:
51#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
61 template <typename ArithmeticType, bool useFullScale >
62 static ArithmeticType &get(vpHSV<ArithmeticType, useFullScale> &col);
63
73 template <typename ArithmeticType, bool useFullScale >
74 static const ArithmeticType &get(const vpHSV<ArithmeticType, useFullScale> &col);
75#endif
76
83 static unsigned char &get(vpRGBa &col);
84
91 static const unsigned char &get(const vpRGBa &col);
92};
93
94#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
95template<>
96template<typename ArithmeticType, bool useFullScale>
98{
99 return hsv.H;
100}
101
102template<>
103template<typename ArithmeticType, bool useFullScale>
105{
106 return hsv.S;
107}
108
109template<>
110template<typename ArithmeticType, bool useFullScale>
112{
113 return hsv.V;
114}
115
116template<>
117template<typename ArithmeticType, bool useFullScale>
118inline const ArithmeticType &vpColorGetter<0>::get(const vpHSV<ArithmeticType, useFullScale> &hsv)
119{
120 return hsv.H;
121}
122
123template<>
124template<typename ArithmeticType, bool useFullScale>
125inline const ArithmeticType &vpColorGetter<1>::get(const vpHSV<ArithmeticType, useFullScale> &hsv)
126{
127 return hsv.S;
128}
129
130template<>
131template<typename ArithmeticType, bool useFullScale>
132inline const ArithmeticType &vpColorGetter<2>::get(const vpHSV<ArithmeticType, useFullScale> &hsv)
133{
134 return hsv.V;
135}
136#endif
137
138template<>
139inline unsigned char &vpColorGetter<0>::get(vpRGBa &rgba)
140{
141 return rgba.R;
142}
143
144template<>
145inline unsigned char &vpColorGetter<1>::get(vpRGBa &rgba)
146{
147 return rgba.G;
148}
149
150template<>
151inline unsigned char &vpColorGetter<2>::get(vpRGBa &rgba)
152{
153 return rgba.B;
154}
155
156template<>
157inline unsigned char &vpColorGetter<3>::get(vpRGBa &rgba)
158{
159 return rgba.A;
160}
161
162template<>
163inline const unsigned char &vpColorGetter<0>::get(const vpRGBa &rgba)
164{
165 return rgba.R;
166}
167
168template<>
169inline const unsigned char &vpColorGetter<1>::get(const vpRGBa &rgba)
170{
171 return rgba.G;
172}
173
174template<>
175inline const unsigned char &vpColorGetter<2>::get(const vpRGBa &rgba)
176{
177 return rgba.B;
178}
179
180template<>
181inline const unsigned char &vpColorGetter<3>::get(const vpRGBa &rgba)
182{
183 return rgba.A;
184}
185END_VISP_NAMESPACE
186#endif
Helper class that permits to get a channel of a color type by its index instead of its name.
static const unsigned char & get(const vpRGBa &col)
Getter for a vpRGBA pixel.
static ArithmeticType & get(vpHSV< ArithmeticType, useFullScale > &col)
Setter for a channel of a HSV pixel.
static unsigned char & get(vpRGBa &col)
Setter for a vpRGBa pixel.
static const ArithmeticType & get(const vpHSV< ArithmeticType, useFullScale > &col)
Getter for a channel of a HSV pixel.
Class implementing the HSV pixel format.
Definition vpHSV.h:135
T V
Definition vpHSV.h:539
T S
Definition vpHSV.h:538
T H
Definition vpHSV.h:537
unsigned char B
Blue component.
Definition vpRGBa.h:327
unsigned char R
Red component.
Definition vpRGBa.h:325
unsigned char G
Green component.
Definition vpRGBa.h:326
unsigned char A
Additional component.
Definition vpRGBa.h:328