Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpFeaturePointPolar.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/vpFeaturePointPolar.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
71
void
vpFeaturePointPolar::init
()
72
{
73
// feature dimension
74
dim_s
= 2;
75
nbParameters
= 3;
76
77
// memory allocation
78
s
.resize(
dim_s
);
79
if
(
flags
==
nullptr
)
80
flags
=
new
bool
[
nbParameters
];
81
for
(
unsigned
int
i = 0; i <
nbParameters
; i++)
82
flags
[i] =
false
;
83
84
// default value Z (1 meters)
85
Z = 1;
86
}
87
98
vpFeaturePointPolar::vpFeaturePointPolar
() : Z(1.) {
init
(); }
99
105
void
vpFeaturePointPolar::set_rho
(
double
rho)
106
{
107
s
[0] = rho;
108
flags
[0] =
true
;
109
}
110
115
void
vpFeaturePointPolar::set_theta
(
double
theta)
116
{
117
s
[1] = theta;
118
flags
[1] =
true
;
119
}
120
125
void
vpFeaturePointPolar::set_Z
(
double
Z_)
126
{
127
this->Z = Z_;
128
flags
[2] =
true
;
129
}
130
140
void
vpFeaturePointPolar::set_rhoThetaZ
(
double
rho,
double
theta,
double
Z_)
141
{
142
set_rho
(rho);
143
set_theta
(theta);
144
set_Z
(Z_);
145
146
for
(
unsigned
int
i = 0; i <
nbParameters
; ++i) {
147
flags
[i] =
true
;
148
}
149
}
150
156
double
vpFeaturePointPolar::get_rho
()
const
{
return
s
[0]; }
157
163
double
vpFeaturePointPolar::get_theta
()
const
{
return
s
[1]; }
168
double
vpFeaturePointPolar::get_Z
()
const
{
return
this->Z; }
169
244
vpMatrix
vpFeaturePointPolar::interaction
(
unsigned
int
select)
245
{
246
vpMatrix
L;
247
248
L.
resize
(0, 6);
249
250
if
(
deallocate
==
vpBasicFeature::user
) {
251
for
(
unsigned
int
i = 0; i <
nbParameters
; i++) {
252
if
(
flags
[i] ==
false
) {
253
switch
(i) {
254
case
0:
255
vpTRACE
(
"Warning !!! The interaction matrix is computed but rho "
256
"was not set yet"
);
257
break
;
258
case
1:
259
vpTRACE
(
"Warning !!! The interaction matrix is computed but theta "
260
"was not set yet"
);
261
break
;
262
case
2:
263
vpTRACE
(
"Warning !!! The interaction matrix is computed but Z was "
264
"not set yet"
);
265
break
;
266
default
:
267
vpTRACE
(
"Problem during the reading of the variable flags"
);
268
}
269
}
270
}
271
resetFlags
();
272
}
273
274
double
rho =
get_rho
();
275
double
theta =
get_theta
();
276
double
Z_ =
get_Z
();
277
278
double
c_ = cos(theta);
279
double
s_ = sin(theta);
280
281
double
rho2 = rho * rho;
282
283
if
(fabs(rho) < 1e-6) {
284
vpERROR_TRACE
(
"rho polar coordinate of the point is null"
);
285
std::cout <<
"rho = "
<< rho << std::endl;
286
287
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"rho polar coordinate of the point is null"
));
288
}
289
290
if
(Z_ < 0) {
291
vpERROR_TRACE
(
"Point is behind the camera "
);
292
std::cout <<
"Z = "
<< Z_ << std::endl;
293
294
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point is behind the camera "
));
295
}
296
297
if
(fabs(Z_) < 1e-6) {
298
vpERROR_TRACE
(
"Point Z coordinates is null "
);
299
std::cout <<
"Z = "
<< Z_ << std::endl;
300
301
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point Z coordinates is null"
));
302
}
303
304
if
(
vpFeaturePointPolar::selectRho
() & select) {
305
vpMatrix
Lrho(1, 6);
306
Lrho = 0;
307
308
Lrho[0][0] = -c_ / Z_;
309
Lrho[0][1] = -s_ / Z_;
310
Lrho[0][2] = rho / Z_;
311
Lrho[0][3] = (1 + rho2) * s_;
312
Lrho[0][4] = -(1 + rho2) * c_;
313
Lrho[0][5] = 0;
314
315
// printf("Lrho: rho %f theta %f Z %f\n", rho, theta, Z);
316
// std::cout << "Lrho: " << Lrho << std::endl;
317
318
L =
vpMatrix::stack
(L, Lrho);
319
}
320
321
if
(
vpFeaturePointPolar::selectTheta
() & select) {
322
vpMatrix
Ltheta(1, 6);
323
Ltheta = 0;
324
325
Ltheta[0][0] = s_ / (rho * Z_);
326
Ltheta[0][1] = -c_ / (rho * Z_);
327
Ltheta[0][2] = 0;
328
Ltheta[0][3] = c_ / rho;
329
Ltheta[0][4] = s_ / rho;
330
Ltheta[0][5] = -1;
331
332
// printf("Ltheta: rho %f theta %f Z %f\n", rho, theta, Z);
333
// std::cout << "Ltheta: " << Ltheta << std::endl;
334
L =
vpMatrix::stack
(L, Ltheta);
335
}
336
return
L;
337
}
338
381
vpColVector
vpFeaturePointPolar::error
(
const
vpBasicFeature
&s_star,
unsigned
int
select)
382
{
383
vpColVector
e(0);
384
385
try
{
386
if
(
vpFeaturePointPolar::selectRho
() & select) {
387
vpColVector
erho(1);
388
erho[0] =
s
[0] - s_star[0];
389
390
e =
vpColVector::stack
(e, erho);
391
}
392
393
if
(
vpFeaturePointPolar::selectTheta
() & select) {
394
395
// printf("err: %f - %f = %f\n", s[1], s_star[1], s[1] -
396
// s_star[1]);
397
double
err =
s
[1] - s_star[1];
398
399
// printf("Error: %f ", err );
400
while
(err < -M_PI)
401
err += 2 * M_PI;
402
while
(err > M_PI)
403
err -= 2 * M_PI;
404
// printf(" modif %f \n", err );
405
406
vpColVector
etheta(1);
407
etheta[0] = err;
408
e =
vpColVector::stack
(e, etheta);
409
}
410
}
411
catch
(...) {
412
throw
;
413
}
414
415
return
e;
416
}
417
439
void
vpFeaturePointPolar::print
(
unsigned
int
select)
const
440
{
441
442
std::cout <<
"Point: Z="
<<
get_Z
();
443
if
(
vpFeaturePointPolar::selectRho
() & select)
444
std::cout <<
" rho="
<<
get_rho
();
445
if
(
vpFeaturePointPolar::selectTheta
() & select)
446
std::cout <<
" theta="
<<
get_theta
();
447
std::cout << std::endl;
448
}
449
450
vpFeaturePointPolar
&
vpFeaturePointPolar::buildFrom
(
const
double
&rho,
const
double
&theta,
const
double
&Z_)
451
{
452
453
s
[0] = rho;
454
s
[1] = theta;
455
456
this->Z = Z_;
457
458
if
(Z < 0) {
459
vpERROR_TRACE
(
"Point is behind the camera "
);
460
std::cout <<
"Z = "
<< Z << std::endl;
461
462
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point is behind the camera "
));
463
}
464
465
if
(fabs(Z) < 1e-6) {
466
vpERROR_TRACE
(
"Point Z coordinates is null "
);
467
std::cout <<
"Z = "
<< Z << std::endl;
468
469
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"Point Z coordinates is null"
));
470
}
471
472
for
(
unsigned
int
i = 0; i <
nbParameters
; ++i) {
473
flags
[i] =
true
;
474
}
475
return
*
this
;
476
}
477
488
void
vpFeaturePointPolar::display
(
const
vpCameraParameters
&cam,
const
vpImage<unsigned char>
&I,
const
vpColor
&color,
489
unsigned
int
thickness)
const
490
{
491
try
{
492
double
rho, theta;
493
rho =
get_rho
();
494
theta =
get_theta
();
495
496
double
x, y;
497
x = rho * cos(theta);
498
y = rho * sin(theta);
499
500
vpFeatureDisplay::displayPoint
(x, y, cam, I, color, thickness);
501
}
502
catch
(...) {
503
vpERROR_TRACE
(
"Error caught"
);
504
throw
;
505
}
506
}
507
518
void
vpFeaturePointPolar::display
(
const
vpCameraParameters
&cam,
const
vpImage<vpRGBa>
&I,
const
vpColor
&color,
519
unsigned
int
thickness)
const
520
{
521
try
{
522
double
rho, theta;
523
rho =
get_rho
();
524
theta =
get_theta
();
525
526
double
x, y;
527
x = rho * cos(theta);
528
y = rho * sin(theta);
529
530
vpFeatureDisplay::displayPoint
(x, y, cam, I, color, thickness);
531
532
}
533
catch
(...) {
534
vpERROR_TRACE
(
"Error caught"
);
535
throw
;
536
}
537
}
538
550
vpFeaturePointPolar
*
vpFeaturePointPolar::duplicate
()
const
551
{
552
vpFeaturePointPolar
*feature =
new
vpFeaturePointPolar
;
553
return
feature;
554
}
555
579
unsigned
int
vpFeaturePointPolar::selectRho
() {
return
FEATURE_LINE
[0]; }
580
603
unsigned
int
vpFeaturePointPolar::selectTheta
() {
return
FEATURE_LINE
[1]; }
604
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
vpFeaturePointPolar::print
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
Definition
vpFeaturePointPolar.cpp:439
vpFeaturePointPolar::buildFrom
vpFeaturePointPolar & buildFrom(const double &rho, const double &theta, const double &Z)
Definition
vpFeaturePointPolar.cpp:450
vpFeaturePointPolar::display
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const VP_OVERRIDE
Definition
vpFeaturePointPolar.cpp:488
vpFeaturePointPolar::selectTheta
static unsigned int selectTheta()
Definition
vpFeaturePointPolar.cpp:603
vpFeaturePointPolar::set_theta
void set_theta(double theta)
Definition
vpFeaturePointPolar.cpp:115
vpFeaturePointPolar::init
void init() VP_OVERRIDE
Definition
vpFeaturePointPolar.cpp:71
vpFeaturePointPolar::vpFeaturePointPolar
vpFeaturePointPolar()
Definition
vpFeaturePointPolar.cpp:98
vpFeaturePointPolar::set_rho
void set_rho(double rho)
Definition
vpFeaturePointPolar.cpp:105
vpFeaturePointPolar::error
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpFeaturePointPolar.cpp:381
vpFeaturePointPolar::duplicate
vpFeaturePointPolar * duplicate() const VP_OVERRIDE
Definition
vpFeaturePointPolar.cpp:550
vpFeaturePointPolar::selectRho
static unsigned int selectRho()
Definition
vpFeaturePointPolar.cpp:579
vpFeaturePointPolar::set_rhoThetaZ
void set_rhoThetaZ(double rho, double theta, double Z)
Definition
vpFeaturePointPolar.cpp:140
vpFeaturePointPolar::set_Z
void set_Z(double Z)
Definition
vpFeaturePointPolar.cpp:125
vpFeaturePointPolar::get_theta
double get_theta() const
Definition
vpFeaturePointPolar.cpp:163
vpFeaturePointPolar::get_Z
double get_Z() const
Definition
vpFeaturePointPolar.cpp:168
vpFeaturePointPolar::get_rho
double get_rho() const
Definition
vpFeaturePointPolar.cpp:156
vpFeaturePointPolar::interaction
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpFeaturePointPolar.cpp:244
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
vpFeaturePointPolar.cpp
Generated by
1.17.0