Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpFeatureDepth.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/vpFeatureDepth.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
attributes and members directly related to the vpBasicFeature needs
56
other functionalities ar useful but not mandatory
57
*/
58
59
BEGIN_VISP_NAMESPACE
63
void
vpFeatureDepth::init
()
64
{
65
// feature dimension
66
dim_s
= 1;
67
nbParameters
= 3;
68
69
// memory allocation
70
s
.resize(
dim_s
);
71
if
(
flags
==
nullptr
)
72
flags
=
new
bool
[
nbParameters
];
73
for
(
unsigned
int
i = 0; i <
nbParameters
; i++)
74
flags
[i] =
false
;
75
x = y = 0.;
76
Z = 1.;
77
}
78
82
vpFeatureDepth::vpFeatureDepth
() : x(0), y(0), Z(1.) {
init
(); }
83
90
void
vpFeatureDepth::set_LogZoverZstar
(
double
LogZoverZstar) {
s
[0] = LogZoverZstar; }
91
98
double
vpFeatureDepth::get_LogZoverZstar
()
const
{
return
s
[0]; }
99
106
void
vpFeatureDepth::set_x
(
double
x_)
107
{
108
this->x = x_;
109
flags
[0] =
true
;
110
}
111
118
double
vpFeatureDepth::get_x
()
const
{
return
x; }
119
126
void
vpFeatureDepth::set_y
(
double
y_)
127
{
128
this->y = y_;
129
flags
[1] =
true
;
130
}
131
138
double
vpFeatureDepth::get_y
()
const
{
return
y; }
139
146
void
vpFeatureDepth::set_Z
(
double
Z_)
147
{
148
this->Z = Z_;
149
flags
[2] =
true
;
150
}
151
158
double
vpFeatureDepth::get_Z
()
const
{
return
Z; }
159
172
void
vpFeatureDepth::set_xyZLogZoverZstar
(
double
x_,
double
y_,
double
Z_,
double
LogZoverZstar)
173
{
174
set_x
(x_);
175
set_y
(y_);
176
set_Z
(Z_);
177
set_LogZoverZstar
(LogZoverZstar);
178
for
(
unsigned
int
i = 0; i <
nbParameters
; i++)
179
flags
[i] =
true
;
180
}
181
207
vpMatrix
vpFeatureDepth::interaction
(
unsigned
int
select)
208
{
209
vpMatrix
L;
210
211
if
(
deallocate
==
vpBasicFeature::user
) {
212
for
(
unsigned
int
i = 0; i <
nbParameters
; i++) {
213
if
(
flags
[i] ==
false
) {
214
switch
(i) {
215
case
0:
216
vpTRACE
(
"Warning !!! The interaction matrix is computed but x was "
217
"not set yet"
);
218
break
;
219
case
1:
220
vpTRACE
(
"Warning !!! The interaction matrix is computed but y was "
221
"not set yet"
);
222
break
;
223
case
2:
224
vpTRACE
(
"Warning !!! The interaction matrix is computed but z was "
225
"not set yet"
);
226
break
;
227
default
:
228
vpTRACE
(
"Problem during the reading of the variable flags"
);
229
}
230
}
231
}
232
resetFlags
();
233
}
234
235
L.
resize
(1, 6);
236
237
double
x_ =
get_x
();
238
double
y_ =
get_y
();
239
double
Z_ =
get_Z
();
240
241
if
(Z_ < 0) {
242
vpERROR_TRACE
(
"Point is behind the camera "
);
243
std::cout <<
"Z = "
<< Z_ << std::endl;
244
245
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point is behind the camera "
));
246
}
247
248
if
(fabs(Z_) < 1e-6) {
249
vpERROR_TRACE
(
"Point Z coordinates is null "
);
250
std::cout <<
"Z = "
<< Z_ << std::endl;
251
252
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point Z coordinates is null"
));
253
}
254
255
if
(
FEATURE_ALL
& select) {
256
L = 0;
257
L[0][0] = 0;
258
L[0][1] = 0;
259
L[0][2] = -1 / Z_;
260
L[0][3] = -y_;
261
L[0][4] = x_;
262
L[0][5] = 0;
263
}
264
265
return
L;
266
}
267
304
vpColVector
vpFeatureDepth::error
(
const
vpBasicFeature
&s_star,
unsigned
int
select)
305
{
306
307
if
(fabs(s_star.
get_s
().
sumSquare
()) > 1e-6) {
308
vpERROR_TRACE
(
"s* should be zero ! "
);
309
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"s* should be zero !"
));
310
}
311
312
vpColVector
e(1);
313
if
(
FEATURE_ALL
& select) {
314
e[0] =
s
[0];
315
}
316
317
return
e;
318
}
319
335
void
vpFeatureDepth::print
(
unsigned
int
select)
const
336
{
337
if
(
FEATURE_ALL
& select) {
338
std::cout <<
"Point: x="
<<
get_x
();
339
std::cout <<
" Point: y="
<<
get_y
();
340
std::cout <<
" Point: Z="
<<
get_Z
();
341
342
std::cout <<
" log(Z/Z*)="
<<
get_LogZoverZstar
();
343
344
std::cout << std::endl;
345
}
346
}
347
359
vpFeatureDepth
&
vpFeatureDepth::buildFrom
(
const
double
&x_,
const
double
&y_,
const
double
&Z_,
const
double
&LogZoverZstar)
360
{
361
362
s
[0] = LogZoverZstar;
363
364
this->x = x_;
365
this->y = y_;
366
this->Z = Z_;
367
368
if
(Z < 0) {
369
vpERROR_TRACE
(
"Point is behind the camera "
);
370
std::cout <<
"Z = "
<< Z << std::endl;
371
372
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point is behind the camera "
));
373
}
374
375
if
(fabs(Z) < 1e-6) {
376
vpERROR_TRACE
(
"Point Z coordinates is null "
);
377
std::cout <<
"Z = "
<< Z << std::endl;
378
379
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point Z coordinates is null"
));
380
}
381
382
for
(
unsigned
int
i = 0; i <
nbParameters
; ++i) {
383
flags
[i] =
true
;
384
}
385
return
*
this
;
386
}
387
398
vpFeatureDepth
*
vpFeatureDepth::duplicate
()
const
399
{
400
vpFeatureDepth
*feature =
new
vpFeatureDepth
;
401
return
feature;
402
}
403
409
void
vpFeatureDepth::display
(
const
vpCameraParameters
&
/* cam */
,
const
vpImage<unsigned char>
&
/* I */
,
410
const
vpColor
&
/* color */
,
unsigned
int
/* thickness */
)
const
411
{
412
static
int
firsttime = 0;
413
414
if
(firsttime == 0) {
415
firsttime = 1;
416
vpERROR_TRACE
(
"not implemented"
);
417
// Do not throw and error since it is not subject
418
// to produce a failure
419
}
420
}
421
426
void
vpFeatureDepth::display
(
const
vpCameraParameters
&
/* cam */
,
const
vpImage<vpRGBa>
&
/* I */
,
427
const
vpColor
&
/* color */
,
unsigned
int
/* thickness */
)
const
428
{
429
static
int
firsttime = 0;
430
431
if
(firsttime == 0) {
432
firsttime = 1;
433
vpERROR_TRACE
(
"not implemented"
);
434
// Do not throw and error since it is not subject
435
// to produce a failure
436
}
437
}
438
END_VISP_NAMESPACE
439
/*
440
* Local variables:
441
* c-basic-offset: 2
442
* End:
443
*/
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::get_s
vpColVector get_s(unsigned int select=FEATURE_ALL) const
Get the feature vector .
Definition
vpBasicFeature.cpp:113
vpBasicFeature::dim_s
unsigned int dim_s
Dimension of the visual feature.
Definition
vpBasicFeature.h:92
vpBasicFeature::deallocate
vpBasicFeatureDeallocatorType deallocate
Definition
vpBasicFeature.h:146
vpBasicFeature::FEATURE_ALL
@ FEATURE_ALL
Definition
vpBasicFeature.h:81
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::sumSquare
double sumSquare() const
Definition
vpColVector.cpp:938
vpColor
Class to define RGB colors available for display functionalities.
Definition
vpColor.h:157
vpFeatureDepth::set_x
void set_x(double x)
Definition
vpFeatureDepth.cpp:106
vpFeatureDepth::print
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
Definition
vpFeatureDepth.cpp:335
vpFeatureDepth::get_y
double get_y() const
Definition
vpFeatureDepth.cpp:138
vpFeatureDepth::interaction
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpFeatureDepth.cpp:207
vpFeatureDepth::buildFrom
vpFeatureDepth & buildFrom(const double &x, const double &y, const double &Z, const double &LogZoverZstar)
Definition
vpFeatureDepth.cpp:359
vpFeatureDepth::set_y
void set_y(double y)
Definition
vpFeatureDepth.cpp:126
vpFeatureDepth::display
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const VP_OVERRIDE
Definition
vpFeatureDepth.cpp:409
vpFeatureDepth::init
void init() VP_OVERRIDE
Definition
vpFeatureDepth.cpp:63
vpFeatureDepth::error
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpFeatureDepth.cpp:304
vpFeatureDepth::get_LogZoverZstar
double get_LogZoverZstar() const
Definition
vpFeatureDepth.cpp:98
vpFeatureDepth::set_LogZoverZstar
void set_LogZoverZstar(double LogZoverZstar)
Definition
vpFeatureDepth.cpp:90
vpFeatureDepth::set_xyZLogZoverZstar
void set_xyZLogZoverZstar(double x, double y, double Z, double logZZs)
Definition
vpFeatureDepth.cpp:172
vpFeatureDepth::duplicate
vpFeatureDepth * duplicate() const VP_OVERRIDE
Definition
vpFeatureDepth.cpp:398
vpFeatureDepth::vpFeatureDepth
vpFeatureDepth()
Definition
vpFeatureDepth.cpp:82
vpFeatureDepth::get_Z
double get_Z() const
Definition
vpFeatureDepth.cpp:158
vpFeatureDepth::set_Z
void set_Z(double Z)
Definition
vpFeatureDepth.cpp:146
vpFeatureDepth::get_x
double get_x() const
Definition
vpFeatureDepth.cpp:118
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
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
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
vpFeatureDepth.cpp
Generated by
1.17.0