Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpRGBf.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 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 https://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 * 32-bit floating point RGB pixel.
33 *
34*****************************************************************************/
35
42#include <limits>
43#include <visp3/core/vpColor.h>
44#include <visp3/core/vpDebug.h>
45#include <visp3/core/vpException.h>
46#include <visp3/core/vpRGBf.h>
47
54{
55 this->R = v;
56 this->G = v;
57 this->B = v;
58 return *this;
59}
60
65{
66 this->R = v.R;
67 this->G = v.G;
68 this->B = v.B;
69 return *this;
70}
71
72#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
77{
78 this->R = std::move(v.R);
79 this->G = std::move(v.G);
80 this->B = std::move(v.B);
81 return *this;
82}
83#endif
84
94{
95 if (v.getRows() != 3) {
96 vpERROR_TRACE("Bad vector dimension");
97 throw(vpException(vpException::dimensionError, "Bad vector dimension"));
98 }
99 R = (float) v[0];
100 G = (float) v[1];
101 B = (float) v[2];
102 return *this;
103}
104
110bool vpRGBf::operator==(const vpRGBf &v) const
111{
112 if (std::fabs(R - v.R) > std::numeric_limits<float>::epsilon())
113 return false;
114 if (std::fabs(G - v.G) > std::numeric_limits<float>::epsilon())
115 return false;
116 if (std::fabs(B - v.B) > std::numeric_limits<float>::epsilon())
117 return false;
118
119 return true;
120}
126bool vpRGBf::operator!=(const vpRGBf &v) const
127{
128 return (std::fabs(R - v.R) > std::numeric_limits<float>::epsilon() ||
129 std::fabs(G - v.G) > std::numeric_limits<float>::epsilon() ||
130 std::fabs(B - v.B) > std::numeric_limits<float>::epsilon());
131}
132
139{
140 vpColVector n(3); // new color
141 n[0] = (double)R - (double)v.R;
142 n[1] = (double)G - (double)v.G;
143 n[2] = (double)B - (double)v.B;
144 return n;
145}
146
154{
155 vpRGBf n; // new color
156 n.R = R + v.R;
157 n.G = G + v.G;
158 n.B = B + v.B;
159 return n;
160}
161
168{
169 vpColVector n(3); // new color
170 n[0] = R - v[0];
171 n[1] = G - v[1];
172 n[2] = B - v[2];
173 return n;
174}
175
182{
183 vpColVector n(3); // new color
184 n[0] = R + v[0];
185 n[1] = G + v[1];
186 n[2] = B + v[2];
187 return n;
188}
189
196{
197 vpColVector n(3);
198 n[0] = R * v;
199 n[1] = G * v;
200 n[2] = B * v;
201 return n;
202}
203
210{
211 vpColVector n(3);
212 n[0] = R * v;
213 n[1] = G * v;
214 n[2] = B * v;
215 return n;
216}
217
218bool vpRGBf::operator<(const vpRGBf &v) const
219{
220 double gray1 = 0.2126 * R + 0.7152 * G + 0.0722 * B;
221 double gray2 = 0.2126 * v.R + 0.7152 * v.G + 0.0722 * v.B;
222
223 return (gray1 < gray2);
224}
225
226bool vpRGBf::operator>(const vpRGBf &v) const
227{
228 double gray1 = 0.2126 * R + 0.7152 * G + 0.0722 * B;
229 double gray2 = 0.2126 * v.R + 0.7152 * v.G + 0.0722 * v.B;
230
231 return (gray1 > gray2);
232}
233
234vpRGBf operator*(double x, const vpRGBf &rgb) { return rgb * x; }
235
257VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpRGBf &rgb)
258{
259 os << "(" << rgb.R << "," << rgb.G << "," << rgb.B << ")";
260 return os;
261}
unsigned int getRows() const
Definition vpArray2D.h:290
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:59
@ dimensionError
Bad dimension.
Definition vpException.h:83
float B
Blue component.
Definition vpRGBf.h:127
friend VISP_EXPORT vpRGBf operator*(double x, const vpRGBf &rgb)
Definition vpRGBf.cpp:234
vpRGBf & operator=(float v)
Definition vpRGBf.cpp:53
vpColVector operator-(const vpRGBf &v) const
Definition vpRGBf.cpp:138
bool operator>(const vpRGBf &v) const
Definition vpRGBf.cpp:226
bool operator==(const vpRGBf &v) const
Definition vpRGBf.cpp:110
vpRGBf operator+(const vpRGBf &v) const
Definition vpRGBf.cpp:153
float G
Green component.
Definition vpRGBf.h:126
bool operator<(const vpRGBf &v) const
Definition vpRGBf.cpp:218
bool operator!=(const vpRGBf &v) const
Definition vpRGBf.cpp:126
float R
Red component.
Definition vpRGBf.h:125
#define vpERROR_TRACE
Definition vpDebug.h:388
vpColVector operator*(const double &x, const vpColVector &v)