Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpFeaturePoint3D.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
* 3D point visual feature.
32
*/
33
34
#include <visp3/visual_features/vpBasicFeature.h>
35
#include <visp3/visual_features/vpFeaturePoint3D.h>
36
37
// Exception
38
#include <visp3/core/vpException.h>
39
#include <visp3/visual_features/vpFeatureException.h>
40
41
// Debug trace
42
#include <visp3/core/vpDebug.h>
43
44
/*
45
46
attributes and members directly related to the vpBasicFeature needs
47
other functionalities are useful but not mandatory
48
49
*/
50
51
BEGIN_VISP_NAMESPACE
59
void
vpFeaturePoint3D::init
()
60
{
61
// feature dimension
62
dim_s
= 3;
63
nbParameters
= 3;
64
65
// memory allocation
66
s
.resize(
dim_s
);
67
if
(
flags
==
nullptr
)
68
flags
=
new
bool
[
nbParameters
];
69
for
(
unsigned
int
i = 0; i <
nbParameters
; i++)
70
flags
[i] =
false
;
71
72
// default value XYZ
73
s
[0] = 0;
74
s
[1] = 0;
75
s
[2] = 1;
76
}
77
84
vpFeaturePoint3D::vpFeaturePoint3D
() {
init
(); }
85
95
void
vpFeaturePoint3D::set_X
(
double
X)
96
{
97
s
[0] = X;
98
flags
[0] =
true
;
99
}
100
110
void
vpFeaturePoint3D::set_Y
(
double
Y)
111
{
112
s
[1] = Y;
113
flags
[1] =
true
;
114
}
115
125
void
vpFeaturePoint3D::set_Z
(
double
Z)
126
{
127
s
[2] = Z;
128
flags
[2] =
true
;
129
}
130
140
void
vpFeaturePoint3D::set_XYZ
(
double
X,
double
Y,
double
Z)
141
{
142
set_X
(X);
143
set_Y
(Y);
144
set_Z
(Z);
145
146
for
(
unsigned
int
i = 0; i <
nbParameters
; i++)
147
flags
[i] =
true
;
148
}
149
151
double
vpFeaturePoint3D::get_X
()
const
{
return
s
[0]; }
152
154
double
vpFeaturePoint3D::get_Y
()
const
{
return
s
[1]; }
155
157
double
vpFeaturePoint3D::get_Z
()
const
{
return
s
[2]; }
158
226
vpMatrix
vpFeaturePoint3D::interaction
(
unsigned
int
select)
227
{
228
vpMatrix
L;
229
230
L.
resize
(0, 6);
231
232
if
(
deallocate
==
vpBasicFeature::user
) {
233
for
(
unsigned
int
i = 0; i <
nbParameters
; i++) {
234
if
(
flags
[i] ==
false
) {
235
switch
(i) {
236
case
0:
237
vpTRACE
(
"Warning !!! The interaction matrix is computed but X was "
238
"not set yet"
);
239
break
;
240
case
1:
241
vpTRACE
(
"Warning !!! The interaction matrix is computed but Y was "
242
"not set yet"
);
243
break
;
244
case
2:
245
vpTRACE
(
"Warning !!! The interaction matrix is computed but Z was "
246
"not set yet"
);
247
break
;
248
default
:
249
vpTRACE
(
"Problem during the reading of the variable flags"
);
250
}
251
}
252
}
253
resetFlags
();
254
}
255
256
double
X =
get_X
();
257
double
Y =
get_Y
();
258
double
Z =
get_Z
();
259
260
if
(
vpFeaturePoint3D::selectX
() & select) {
261
vpMatrix
Lx(1, 6);
262
Lx = 0;
263
264
Lx[0][0] = -1;
265
Lx[0][1] = 0;
266
Lx[0][2] = 0;
267
Lx[0][3] = 0;
268
Lx[0][4] = -Z;
269
Lx[0][5] = Y;
270
271
L =
vpMatrix::stack
(L, Lx);
272
}
273
274
if
(
vpFeaturePoint3D::selectY
() & select) {
275
vpMatrix
Ly(1, 6);
276
Ly = 0;
277
278
Ly[0][0] = 0;
279
Ly[0][1] = -1;
280
Ly[0][2] = 0;
281
Ly[0][3] = Z;
282
Ly[0][4] = 0;
283
Ly[0][5] = -X;
284
285
L =
vpMatrix::stack
(L, Ly);
286
}
287
if
(
vpFeaturePoint3D::selectZ
() & select) {
288
vpMatrix
Lz(1, 6);
289
Lz = 0;
290
291
Lz[0][0] = 0;
292
Lz[0][1] = 0;
293
Lz[0][2] = -1;
294
Lz[0][3] = -Y;
295
Lz[0][4] = X;
296
Lz[0][5] = 0;
297
298
L =
vpMatrix::stack
(L, Lz);
299
}
300
return
L;
301
}
302
354
vpColVector
vpFeaturePoint3D::error
(
const
vpBasicFeature
&s_star,
unsigned
int
select)
355
{
356
vpColVector
e(0);
357
358
try
{
359
if
(
vpFeaturePoint3D::selectX
() & select) {
360
vpColVector
ex(1);
361
ex[0] =
s
[0] - s_star[0];
362
363
e =
vpColVector::stack
(e, ex);
364
}
365
366
if
(
vpFeaturePoint3D::selectY
() & select) {
367
vpColVector
ey(1);
368
ey[0] =
s
[1] - s_star[1];
369
e =
vpColVector::stack
(e, ey);
370
}
371
372
if
(
vpFeaturePoint3D::selectZ
() & select) {
373
vpColVector
ez(1);
374
ez[0] =
s
[2] - s_star[2];
375
e =
vpColVector::stack
(e, ez);
376
}
377
}
378
catch
(...) {
379
throw
;
380
}
381
382
return
e;
383
}
384
401
vpFeaturePoint3D
&
vpFeaturePoint3D::buildFrom
(
const
vpPoint
&p)
402
{
403
// cP is expressed in homogeneous coordinates
404
// we devide by the fourth coordinate
405
s
[0] = p.cP[0] / p.cP[3];
406
s
[1] = p.cP[1] / p.cP[3];
407
s
[2] = p.cP[2] / p.cP[3];
408
409
double
Z =
s
[2];
410
if
(Z < 0) {
411
vpERROR_TRACE
(
"Point is behind the camera "
);
412
std::cout <<
"Z = "
<< Z << std::endl;
413
414
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point is behind the camera "
));
415
}
416
417
if
(fabs(Z) < 1e-6) {
418
vpERROR_TRACE
(
"Point Z coordinates is null "
);
419
std::cout <<
"Z = "
<< Z << std::endl;
420
421
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point Z coordinates is null"
));
422
}
423
424
for
(
unsigned
int
i = 0; i <
nbParameters
; ++i) {
425
flags
[i] =
true
;
426
}
427
return
*
this
;
428
}
429
448
vpFeaturePoint3D
&
vpFeaturePoint3D::buildFrom
(
const
double
&X,
const
double
&Y,
const
double
&Z)
449
{
450
s
[0] = X;
451
s
[1] = Y;
452
s
[2] = Z;
453
454
if
(Z < 0) {
455
vpERROR_TRACE
(
"Point is behind the camera "
);
456
std::cout <<
"Z = "
<< Z << std::endl;
457
458
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point is behind the camera "
));
459
}
460
461
if
(fabs(Z) < 1e-6) {
462
vpERROR_TRACE
(
"Point Z coordinates is null "
);
463
std::cout <<
"Z = "
<< Z << std::endl;
464
465
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point Z coordinates is null"
));
466
}
467
468
for
(
unsigned
int
i = 0; i <
nbParameters
; ++i) {
469
flags
[i] =
true
;
470
}
471
return
*
this
;
472
}
473
497
void
vpFeaturePoint3D::print
(
unsigned
int
select)
const
498
{
499
500
std::cout <<
"Point3D: "
;
501
if
(
vpFeaturePoint3D::selectX
() & select)
502
std::cout <<
" X="
<<
get_X
();
503
if
(
vpFeaturePoint3D::selectY
() & select)
504
std::cout <<
" Y="
<<
get_Y
();
505
if
(
vpFeaturePoint3D::selectZ
() & select)
506
std::cout <<
" Z="
<<
get_Z
();
507
std::cout << std::endl;
508
}
509
521
vpFeaturePoint3D
*
vpFeaturePoint3D::duplicate
()
const
522
{
523
vpFeaturePoint3D
*feature =
new
vpFeaturePoint3D
;
524
return
feature;
525
}
526
531
void
vpFeaturePoint3D::display
(
const
vpCameraParameters
&
/*cam*/
,
const
vpImage<unsigned char>
&
/* I */
,
532
const
vpColor
&
/* color */
,
unsigned
int
/* thickness */
)
const
533
{
534
static
int
firsttime = 0;
535
536
if
(firsttime == 0) {
537
firsttime = 1;
538
vpERROR_TRACE
(
"not implemented"
);
539
// Do not throw and error since it is not subject
540
// to produce a failure
541
}
542
}
543
548
void
vpFeaturePoint3D::display
(
const
vpCameraParameters
&
/*cam*/
,
const
vpImage<vpRGBa>
&
/* I */
,
549
const
vpColor
&
/* color */
,
unsigned
int
/* thickness */
)
const
550
{
551
static
int
firsttime = 0;
552
553
if
(firsttime == 0) {
554
firsttime = 1;
555
vpERROR_TRACE
(
"not implemented"
);
556
// Do not throw and error since it is not subject
557
// to produce a failure
558
}
559
}
560
585
unsigned
int
vpFeaturePoint3D::selectX
() {
return
FEATURE_LINE
[0]; }
586
612
unsigned
int
vpFeaturePoint3D::selectY
() {
return
FEATURE_LINE
[1]; }
613
638
unsigned
int
vpFeaturePoint3D::selectZ
() {
return
FEATURE_LINE
[2]; }
639
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
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
vpFeaturePoint3D::selectX
static unsigned int selectX()
Definition
vpFeaturePoint3D.cpp:585
vpFeaturePoint3D::get_X
double get_X() const
Return the coordinate in the camera frame of the 3D point.
Definition
vpFeaturePoint3D.cpp:151
vpFeaturePoint3D::set_XYZ
void set_XYZ(double X, double Y, double Z)
Definition
vpFeaturePoint3D.cpp:140
vpFeaturePoint3D::get_Y
double get_Y() const
Return the coordinate in the camera frame of the 3D point.
Definition
vpFeaturePoint3D.cpp:154
vpFeaturePoint3D::duplicate
vpFeaturePoint3D * duplicate() const VP_OVERRIDE
Definition
vpFeaturePoint3D.cpp:521
vpFeaturePoint3D::selectZ
static unsigned int selectZ()
Definition
vpFeaturePoint3D.cpp:638
vpFeaturePoint3D::error
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpFeaturePoint3D.cpp:354
vpFeaturePoint3D::buildFrom
vpFeaturePoint3D & buildFrom(const vpPoint &p)
Definition
vpFeaturePoint3D.cpp:401
vpFeaturePoint3D::print
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
Definition
vpFeaturePoint3D.cpp:497
vpFeaturePoint3D::set_Y
void set_Y(double Y)
Definition
vpFeaturePoint3D.cpp:110
vpFeaturePoint3D::selectY
static unsigned int selectY()
Definition
vpFeaturePoint3D.cpp:612
vpFeaturePoint3D::init
void init() VP_OVERRIDE
Definition
vpFeaturePoint3D.cpp:59
vpFeaturePoint3D::interaction
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpFeaturePoint3D.cpp:226
vpFeaturePoint3D::vpFeaturePoint3D
vpFeaturePoint3D()
Definition
vpFeaturePoint3D.cpp:84
vpFeaturePoint3D::set_Z
void set_Z(double Z)
Definition
vpFeaturePoint3D.cpp:125
vpFeaturePoint3D::set_X
void set_X(double X)
Definition
vpFeaturePoint3D.cpp:95
vpFeaturePoint3D::get_Z
double get_Z() const
Return the coordinate in the camera frame of the 3D point.
Definition
vpFeaturePoint3D.cpp:157
vpFeaturePoint3D::display
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const VP_OVERRIDE
Definition
vpFeaturePoint3D.cpp:531
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
vpPoint
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition
vpPoint.h:79
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
vpFeaturePoint3D.cpp
Generated by
1.17.0