Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpFeaturePoint.cpp
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2025 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
* 2D point visual feature.
32
*/
33
38
39
#include <visp3/visual_features/vpBasicFeature.h>
40
#include <visp3/visual_features/vpFeaturePoint.h>
41
42
// Exception
43
#include <visp3/core/vpException.h>
44
#include <visp3/visual_features/vpFeatureException.h>
45
46
// Debug trace
47
#include <visp3/core/vpDebug.h>
48
49
// math
50
#include <visp3/core/vpMath.h>
51
52
#include <visp3/core/vpFeatureDisplay.h>
53
54
/*
55
56
attributes and members directly related to the vpBasicFeature needs
57
other functionalities ar useful but not mandatory
58
59
*/
60
61
BEGIN_VISP_NAMESPACE
65
void
vpFeaturePoint::init
()
66
{
67
// feature dimension
68
dim_s
= 2;
69
nbParameters
= 3;
70
71
// memory allocation
72
s
.resize(
dim_s
);
73
if
(
flags
==
nullptr
)
74
flags
=
new
bool
[
nbParameters
];
75
for
(
unsigned
int
i = 0; i <
nbParameters
; i++)
76
flags
[i] =
false
;
77
78
// default value Z (1 meters)
79
Z = 1;
80
}
81
85
vpFeaturePoint::vpFeaturePoint
() : Z(1.) {
init
(); }
86
93
void
vpFeaturePoint::set_Z
(
double
Z_)
94
{
95
this->Z = Z_;
96
flags
[2] =
true
;
97
}
98
105
double
vpFeaturePoint::get_Z
()
const
{
return
Z; }
106
114
void
vpFeaturePoint::set_x
(
double
x)
115
{
116
s
[0] = x;
117
flags
[0] =
true
;
118
}
119
126
double
vpFeaturePoint::get_x
()
const
{
return
s
[0]; }
127
134
void
vpFeaturePoint::set_y
(
double
y)
135
{
136
s
[1] = y;
137
flags
[1] =
true
;
138
}
139
146
double
vpFeaturePoint::get_y
()
const
{
return
s
[1]; }
147
159
void
vpFeaturePoint::set_xyZ
(
double
x_,
double
y_,
double
Z_)
160
{
161
set_x
(x_);
162
set_y
(y_);
163
set_Z
(Z_);
164
for
(
unsigned
int
i = 0; i <
nbParameters
; i++)
165
flags
[i] =
true
;
166
}
167
211
vpMatrix
vpFeaturePoint::interaction
(
unsigned
int
select)
212
{
213
vpMatrix
L;
214
215
L.
resize
(0, 6);
216
217
if
(
deallocate
==
vpBasicFeature::user
) {
218
for
(
unsigned
int
i = 0; i <
nbParameters
; i++) {
219
if
(
flags
[i] ==
false
) {
220
switch
(i) {
221
case
0:
222
vpTRACE
(
"Warning !!! The interaction matrix is computed but x was "
223
"not set yet"
);
224
break
;
225
case
1:
226
vpTRACE
(
"Warning !!! The interaction matrix is computed but y was "
227
"not set yet"
);
228
break
;
229
case
2:
230
vpTRACE
(
"Warning !!! The interaction matrix is computed but Z was "
231
"not set yet"
);
232
break
;
233
default
:
234
vpTRACE
(
"Problem during the reading of the variable flags"
);
235
}
236
}
237
}
238
resetFlags
();
239
}
240
241
double
x_ =
get_x
();
242
double
y_ =
get_y
();
243
double
Z_ =
get_Z
();
244
245
if
(Z_ < 0) {
246
vpERROR_TRACE
(
"Point is behind the camera "
);
247
std::cout <<
"Z = "
<< Z_ << std::endl;
248
249
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point is behind the camera "
));
250
}
251
252
if
(fabs(Z_) < 1e-6) {
253
vpERROR_TRACE
(
"Point Z coordinates is null "
);
254
std::cout <<
"Z = "
<< Z_ << std::endl;
255
256
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point Z coordinates is null"
));
257
}
258
259
if
(
vpFeaturePoint::selectX
() & select) {
260
vpMatrix
Lx(1, 6);
261
Lx = 0;
262
263
Lx[0][0] = -1 / Z_;
264
Lx[0][1] = 0;
265
Lx[0][2] = x_ / Z_;
266
Lx[0][3] = x_ * y_;
267
Lx[0][4] = -(1 + x_ * x_);
268
Lx[0][5] = y_;
269
270
L =
vpMatrix::stack
(L, Lx);
271
}
272
273
if
(
vpFeaturePoint::selectY
() & select) {
274
vpMatrix
Ly(1, 6);
275
Ly = 0;
276
277
Ly[0][0] = 0;
278
Ly[0][1] = -1 / Z_;
279
Ly[0][2] = y_ / Z_;
280
Ly[0][3] = 1 + y_ * y_;
281
Ly[0][4] = -x_ * y_;
282
Ly[0][5] = -x_;
283
284
L =
vpMatrix::stack
(L, Ly);
285
}
286
return
L;
287
}
288
325
vpColVector
vpFeaturePoint::error
(
const
vpBasicFeature
&s_star,
unsigned
int
select)
326
{
327
vpColVector
e(0);
328
329
try
{
330
if
(
vpFeaturePoint::selectX
() & select) {
331
vpColVector
ex(1);
332
ex[0] =
s
[0] - s_star[0];
333
334
e =
vpColVector::stack
(e, ex);
335
}
336
337
if
(
vpFeaturePoint::selectY
() & select) {
338
vpColVector
ey(1);
339
ey[0] =
s
[1] - s_star[1];
340
e =
vpColVector::stack
(e, ey);
341
}
342
}
343
catch
(...) {
344
throw
;
345
}
346
347
return
e;
348
}
349
369
void
vpFeaturePoint::print
(
unsigned
int
select)
const
370
{
371
372
std::cout <<
"Point: Z="
<<
get_Z
();
373
if
(
vpFeaturePoint::selectX
() & select)
374
std::cout <<
" x="
<<
get_x
();
375
if
(
vpFeaturePoint::selectY
() & select)
376
std::cout <<
" y="
<<
get_y
();
377
std::cout << std::endl;
378
}
379
392
vpFeaturePoint
&
vpFeaturePoint::buildFrom
(
const
double
&x_,
const
double
&y_,
const
double
&Z_)
393
{
394
395
s
[0] = x_;
396
s
[1] = y_;
397
398
this->Z = Z_;
399
400
if
(Z_ < 0) {
401
vpERROR_TRACE
(
"Point is behind the camera "
);
402
std::cout <<
"Z = "
<< Z_ << std::endl;
403
404
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point is behind the camera "
));
405
}
406
407
if
(fabs(Z_) < 1e-6) {
408
vpERROR_TRACE
(
"Point Z coordinates is null "
);
409
std::cout <<
"Z = "
<< Z_ << std::endl;
410
411
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point Z coordinates is null"
));
412
}
413
414
for
(
unsigned
int
i = 0; i <
nbParameters
; ++i) {
415
flags
[i] =
true
;
416
}
417
return
*
this
;
418
}
419
430
void
vpFeaturePoint::display
(
const
vpCameraParameters
&cam,
const
vpImage<unsigned char>
&I,
const
vpColor
&color,
431
unsigned
int
thickness)
const
432
{
433
try
{
434
double
x, y;
435
x =
get_x
();
436
y =
get_y
();
437
438
vpFeatureDisplay::displayPoint
(x, y, cam, I, color, thickness);
439
440
}
441
catch
(...) {
442
vpERROR_TRACE
(
"Error caught"
);
443
throw
;
444
}
445
}
446
457
void
vpFeaturePoint::display
(
const
vpCameraParameters
&cam,
const
vpImage<vpRGBa>
&I,
const
vpColor
&color,
458
unsigned
int
thickness)
const
459
{
460
try
{
461
double
x, y;
462
x =
get_x
();
463
y =
get_y
();
464
465
vpFeatureDisplay::displayPoint
(x, y, cam, I, color, thickness);
466
467
}
468
catch
(...) {
469
vpERROR_TRACE
(
"Error caught"
);
470
throw
;
471
}
472
}
473
484
vpFeaturePoint
*
vpFeaturePoint::duplicate
()
const
485
{
486
vpFeaturePoint
*feature =
new
vpFeaturePoint
;
487
return
feature;
488
}
489
508
unsigned
int
vpFeaturePoint::selectX
() {
return
FEATURE_LINE
[0]; }
509
528
unsigned
int
vpFeaturePoint::selectY
() {
return
FEATURE_LINE
[1]; }
529
END_VISP_NAMESPACE
vpArray2D::resize
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition
vpArray2D.h:448
vpBasicFeature::flags
bool * flags
Definition
vpBasicFeature.h:96
vpBasicFeature::user
@ user
Definition
vpBasicFeature.h:86
vpBasicFeature::s
vpColVector s
State of the visual feature.
Definition
vpBasicFeature.h:90
vpBasicFeature::nbParameters
unsigned int nbParameters
Number of parameters needed to compute the interaction matrix.
Definition
vpBasicFeature.h:98
vpBasicFeature::resetFlags
void resetFlags()
Definition
vpBasicFeature.cpp:130
vpBasicFeature::dim_s
unsigned int dim_s
Dimension of the visual feature.
Definition
vpBasicFeature.h:92
vpBasicFeature::FEATURE_LINE
static const unsigned int FEATURE_LINE[32]
Definition
vpBasicFeature.h:45
vpBasicFeature::deallocate
vpBasicFeatureDeallocatorType deallocate
Definition
vpBasicFeature.h:146
vpBasicFeature::vpBasicFeature
vpBasicFeature()
Definition
vpBasicFeature.cpp:59
vpCameraParameters
Generic class defining intrinsic camera parameters.
Definition
vpCameraParameters.h:311
vpColVector
Implementation of column vector and the associated operations.
Definition
vpColVector.h:191
vpColVector::stack
void stack(double d)
Definition
vpColVector.cpp:669
vpColor
Class to define RGB colors available for display functionalities.
Definition
vpColor.h:157
vpFeatureDisplay::displayPoint
static void displayPoint(double x, double y, const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1)
Definition
vpFeatureDisplay.cpp:60
vpFeatureException
Error that can be emitted by the vpBasicFeature class and its derivates.
Definition
vpFeatureException.h:55
vpFeatureException::badInitializationError
@ badInitializationError
Wrong feature initialization.
Definition
vpFeatureException.h:70
vpFeaturePoint::buildFrom
vpFeaturePoint & buildFrom(const double &x, const double &y, const double &Z)
Definition
vpFeaturePoint.cpp:392
vpFeaturePoint::selectX
static unsigned int selectX()
Definition
vpFeaturePoint.cpp:508
vpFeaturePoint::set_xyZ
void set_xyZ(double x, double y, double Z)
Definition
vpFeaturePoint.cpp:159
vpFeaturePoint::duplicate
vpFeaturePoint * duplicate() const VP_OVERRIDE
Definition
vpFeaturePoint.cpp:484
vpFeaturePoint::error
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpFeaturePoint.cpp:325
vpFeaturePoint::print
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
Definition
vpFeaturePoint.cpp:369
vpFeaturePoint::selectY
static unsigned int selectY()
Definition
vpFeaturePoint.cpp:528
vpFeaturePoint::interaction
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpFeaturePoint.cpp:211
vpFeaturePoint::set_y
void set_y(double y)
Definition
vpFeaturePoint.cpp:134
vpFeaturePoint::display
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const VP_OVERRIDE
Definition
vpFeaturePoint.cpp:430
vpFeaturePoint::get_y
double get_y() const
Definition
vpFeaturePoint.cpp:146
vpFeaturePoint::get_x
double get_x() const
Definition
vpFeaturePoint.cpp:126
vpFeaturePoint::set_x
void set_x(double x)
Definition
vpFeaturePoint.cpp:114
vpFeaturePoint::vpFeaturePoint
vpFeaturePoint()
Definition
vpFeaturePoint.cpp:85
vpFeaturePoint::init
void init() VP_OVERRIDE
Definition
vpFeaturePoint.cpp:65
vpFeaturePoint::get_Z
double get_Z() const
Definition
vpFeaturePoint.cpp:105
vpFeaturePoint::set_Z
void set_Z(double Z)
Definition
vpFeaturePoint.cpp:93
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpMatrix
Implementation of a matrix and operations on matrices.
Definition
vpMatrix.h:175
vpMatrix::stack
void stack(const vpMatrix &A)
Definition
vpMatrix_stack.cpp:239
vpTRACE
#define vpTRACE
Definition
vpDebug.h:450
vpERROR_TRACE
#define vpERROR_TRACE
Definition
vpDebug.h:423
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
visual_features
src
visual-feature
vpFeaturePoint.cpp
Generated by
1.17.0