Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpGenericFeature.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
* Generic feature (used to create new feature not implemented in ViSP).
32
*/
33
34
#include <visp3/visual_features/vpGenericFeature.h>
35
36
// Exception
37
#include <visp3/core/vpException.h>
38
#include <visp3/visual_features/vpFeatureException.h>
39
40
// Debug trace
41
#include <visp3/core/vpDebug.h>
42
43
BEGIN_VISP_NAMESPACE
44
void
vpGenericFeature::init
() {
s
= 0; }
45
56
vpGenericFeature::vpGenericFeature() : L(), err(), errorStatus(errorNotInitialized)
57
{
58
/*
59
vpERROR_TRACE("You are not allow to use this constructor ") ;
60
vpERROR_TRACE("Please, use vpGenericFeature::vpGenericFeature(int _dim) "
61
"constructor") ;
62
vpERROR_TRACE("And provide the dimension of the visual feature ") ;
63
throw(vpException(vpException::cannotUseConstructorError,
64
"You are not allow to use this constructor ")) ;
65
*/
66
}
67
75
vpGenericFeature::vpGenericFeature(
unsigned
int
dimension_gen_s) : L(), err(), errorStatus(errorNotInitialized)
76
{
77
this->
dim_s
= dimension_gen_s;
78
s
.resize(dimension_gen_s);
79
}
80
90
void
vpGenericFeature::setError
(
const
vpColVector
&error_vector)
91
{
92
if
(error_vector.
getRows
() !=
dim_s
) {
93
vpERROR_TRACE
(
"size mismatch between error dimension"
94
"and feature dimension"
);
95
throw
(
vpFeatureException
(
vpFeatureException::sizeMismatchError
,
"size mismatch between error dimension"
96
"and feature dimension"
));
97
}
98
errorStatus = errorInitialized;
99
err = error_vector;
100
}
101
157
vpColVector
vpGenericFeature::error
(
const
vpBasicFeature
&s_star,
unsigned
int
select)
158
{
159
if
(s_star.
get_s
().
getRows
() !=
dim_s
) {
160
vpERROR_TRACE
(
"size mismatch between s* dimension "
161
"and feature dimension"
);
162
throw
(
vpFeatureException
(
vpFeatureException::sizeMismatchError
,
"size mismatch between s* dimension "
163
"and feature dimension"
));
164
}
165
166
vpColVector
e(0);
167
168
try
{
169
if
(errorStatus == errorHasToBeUpdated) {
170
vpERROR_TRACE
(
"Error has no been updated since last iteration"
171
"you should have used vpGenericFeature::setError"
172
"in you visual servoing loop"
);
173
throw
(
vpFeatureException
(
vpFeatureException::badErrorVectorError
,
174
"Error has no been updated since last iteration"
));
175
}
176
else
if
(errorStatus == errorInitialized) {
177
vpDEBUG_TRACE
(25,
"Error init: e=e."
);
178
errorStatus = errorHasToBeUpdated;
179
for
(
unsigned
int
i = 0; i <
dim_s
; i++)
180
if
(
FEATURE_LINE
[i] & select) {
181
vpColVector
ex(1);
182
ex[i] = err[i];
183
184
e =
vpColVector::stack
(e, ex);
185
}
186
}
187
else
{
188
vpDEBUG_TRACE
(25,
"Error not init: e=s-s*."
);
189
190
for
(
unsigned
int
i = 0; i <
dim_s
; i++)
191
if
(
FEATURE_LINE
[i] & select) {
192
vpColVector
ex(1);
193
ex[0] =
s
[i] - s_star[i];
194
195
e =
vpColVector::stack
(e, ex);
196
}
197
}
198
}
199
catch
(...) {
200
throw
;
201
}
202
return
e;
203
}
204
245
vpColVector
vpGenericFeature::error
(
unsigned
int
select)
246
{
247
vpColVector
e(0);
248
249
try
{
250
if
(errorStatus == errorHasToBeUpdated) {
251
vpERROR_TRACE
(
"Error has no been updated since last iteration"
252
"you should have used vpGenericFeature::setError"
253
"in you visual servoing loop"
);
254
throw
(
vpFeatureException
(
vpFeatureException::badErrorVectorError
,
255
"Error has no been updated since last iteration"
));
256
}
257
else
if
(errorStatus == errorInitialized) {
258
errorStatus = errorHasToBeUpdated;
259
for
(
unsigned
int
i = 0; i <
dim_s
; i++)
260
if
(
FEATURE_LINE
[i] & select) {
261
vpColVector
ex(1);
262
ex[i] = err[i];
263
264
e =
vpColVector::stack
(e, ex);
265
}
266
}
267
else
{
268
269
for
(
unsigned
int
i = 0; i <
dim_s
; i++)
270
if
(
FEATURE_LINE
[i] & select) {
271
vpColVector
ex(1);
272
ex[i] =
s
[i];
273
274
e =
vpColVector::stack
(e, ex);
275
}
276
}
277
}
278
catch
(...) {
279
throw
;
280
}
281
282
return
e;
283
}
284
335
vpMatrix
vpGenericFeature::interaction
(
unsigned
int
select)
336
{
337
if
(L.getRows() == 0) {
338
std::cout <<
"interaction matrix "
<< L << std::endl;
339
vpERROR_TRACE
(
"Interaction has not been initialized"
);
340
std::cout <<
"A possible reason (may be) is that you have set"
<< std::endl;
341
std::cout <<
"the interaction matrix for s and compute a control "
<< std::endl;
342
std::cout <<
"with Ls=s* (default) or vice versa"
<< std::endl;
343
344
throw
(
vpFeatureException
(
vpFeatureException::notInitializedError
,
"size mismatch between s* dimension "
345
"and feature dimension"
));
346
}
347
348
vpMatrix
Ls;
349
350
Ls.
resize
(0, 6);
351
352
for
(
unsigned
int
i = 0; i <
dim_s
; i++)
353
if
(
FEATURE_LINE
[i] & select) {
354
vpMatrix
Lx(1, 6);
355
Lx = 0;
356
357
for
(
int
j = 0; j < 6; j++)
358
Lx[0][j] = L[i][j];
359
360
Ls =
vpMatrix::stack
(Ls, Lx);
361
}
362
363
return
Ls;
364
}
365
375
void
vpGenericFeature::setInteractionMatrix
(
const
vpMatrix
&L_)
376
{
377
if
(L_.
getRows
() !=
dim_s
) {
378
std::cout << L_.
getRows
() <<
" "
<<
dim_s
<< std::endl;
379
vpERROR_TRACE
(
"size mismatch between interaction matrix size "
380
"and feature dimension"
);
381
throw
(
vpFeatureException
(
vpFeatureException::sizeMismatchError
,
"size mismatch between interaction matrix size "
382
"and feature dimension"
));
383
}
384
385
this->L = L_;
386
}
387
398
void
vpGenericFeature::set_s
(
const
vpColVector
&s_vector)
399
{
400
401
if
(s_vector.
getRows
() !=
dim_s
) {
402
vpERROR_TRACE
(
"size mismatch between s dimension"
403
"and feature dimension"
);
404
throw
(
vpFeatureException
(
vpFeatureException::sizeMismatchError
,
"size mismatch between s dimension"
405
"and feature dimension"
));
406
}
407
this->
s
= s_vector;
408
}
409
420
void
vpGenericFeature::get_s
(
vpColVector
&s_vector)
const
421
{
422
if
(s_vector.
getRows
() !=
dim_s
) {
423
vpERROR_TRACE
(
"size mismatch between s dimension"
424
"and feature dimension"
);
425
throw
(
vpFeatureException
(
vpFeatureException::sizeMismatchError
,
"size mismatch between s dimension"
426
"and feature dimension"
));
427
}
428
s_vector = this->
s
;
429
}
430
445
void
vpGenericFeature::set_s
(
double
s0,
double
s1,
double
s2)
446
{
447
448
if
(3 !=
dim_s
) {
449
vpERROR_TRACE
(
"size mismatch between number of parameters"
450
"and feature dimension"
);
451
throw
(
vpFeatureException
(
vpFeatureException::sizeMismatchError
,
"size mismatch between number of parameters"
452
"and feature dimension"
));
453
}
454
s
[0] = s0;
455
s
[1] = s1;
456
s
[2] = s2;
457
}
458
473
void
vpGenericFeature::get_s
(
double
&s0,
double
&s1,
double
&s2)
const
474
{
475
476
if
(3 !=
dim_s
) {
477
vpERROR_TRACE
(
"size mismatch between number of parameters"
478
"and feature dimension"
);
479
throw
(
vpFeatureException
(
vpFeatureException::sizeMismatchError
,
"size mismatch between number of parameters"
480
"and feature dimension"
));
481
}
482
s0 =
s
[0];
483
s1 =
s
[1];
484
s2 =
s
[2];
485
}
486
498
void
vpGenericFeature::set_s
(
double
s0,
double
s1)
499
{
500
501
if
(2 !=
dim_s
) {
502
vpERROR_TRACE
(
"size mismatch between number of parameters"
503
"and feature dimension"
);
504
throw
(
vpFeatureException
(
vpFeatureException::sizeMismatchError
,
"size mismatch between number of parameters"
505
"and feature dimension"
));
506
}
507
s
[0] = s0;
508
s
[1] = s1;
509
}
510
522
void
vpGenericFeature::get_s
(
double
&s0,
double
&s1)
const
523
{
524
525
if
(2 !=
dim_s
) {
526
vpERROR_TRACE
(
"size mismatch between number of parameters"
527
"and feature dimension"
);
528
throw
(
vpFeatureException
(
vpFeatureException::sizeMismatchError
,
"size mismatch between number of parameters"
529
"and feature dimension"
));
530
}
531
s0 =
s
[0];
532
s1 =
s
[1];
533
}
534
544
void
vpGenericFeature::set_s
(
double
s0)
545
{
546
547
if
(1 !=
dim_s
) {
548
vpERROR_TRACE
(
"size mismatch between number of parameters"
549
"and feature dimension"
);
550
throw
(
vpFeatureException
(
vpFeatureException::sizeMismatchError
,
"size mismatch between number of parameters"
551
"and feature dimension"
));
552
}
553
s
[0] = s0;
554
}
555
565
void
vpGenericFeature::get_s
(
double
&s0)
const
566
{
567
568
if
(1 !=
dim_s
) {
569
vpERROR_TRACE
(
"size mismatch between number of parameters"
570
"and feature dimension"
);
571
throw
(
vpFeatureException
(
vpFeatureException::sizeMismatchError
,
"size mismatch between number of parameters"
572
"and feature dimension"
));
573
}
574
s0 =
s
[0];
575
}
576
598
void
vpGenericFeature::print
(
unsigned
int
select)
const
599
{
600
601
std::cout <<
"Generic Feature: "
;
602
for
(
unsigned
int
i = 0; i <
dim_s
; i++)
603
if
(
FEATURE_LINE
[i] & select) {
604
std::cout <<
" s["
<< i <<
"]="
<<
s
[i];
605
}
606
607
std::cout << std::endl;
608
}
609
610
vpGenericFeature *
vpGenericFeature::duplicate
()
const
611
{
612
vpGenericFeature *feature =
new
vpGenericFeature(
dim_s
);
613
614
vpTRACE
(
"dims = %d"
,
dim_s
);
615
return
feature;
616
}
617
621
void
vpGenericFeature::display
(
const
vpCameraParameters
&
/* cam */
,
const
vpImage<unsigned char>
&
/* I */
,
622
const
vpColor
&
/* color */
,
unsigned
int
/* thickness */
)
const
623
{
624
static
int
firsttime = 0;
625
626
if
(firsttime == 0) {
627
firsttime = 1;
628
vpERROR_TRACE
(
"not implemented"
);
629
// Do not throw and error since it is not subject
630
// to produce a failure
631
}
632
}
633
636
void
vpGenericFeature::display
(
const
vpCameraParameters
&
/* cam */
,
const
vpImage<vpRGBa>
&
/* I */
,
637
const
vpColor
&
/* color */
,
unsigned
int
/* thickness */
)
const
638
{
639
static
int
firsttime = 0;
640
641
if
(firsttime == 0) {
642
firsttime = 1;
643
vpERROR_TRACE
(
"not implemented"
);
644
// Do not throw and error since it is not subject
645
// to produce a failure
646
}
647
}
648
END_VISP_NAMESPACE
649
/*
650
* Local variables:
651
* c-basic-offset: 2
652
* End:
653
*/
vpArray2D::resize
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition
vpArray2D.h:448
vpArray2D::getRows
unsigned int getRows() const
Definition
vpArray2D.h:433
vpBasicFeature::s
vpColVector s
State of the visual feature.
Definition
vpBasicFeature.h:90
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::FEATURE_LINE
static const unsigned int FEATURE_LINE[32]
Definition
vpBasicFeature.h:45
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::notInitializedError
@ notInitializedError
Feature not initialized.
Definition
vpFeatureException.h:68
vpFeatureException::badErrorVectorError
@ badErrorVectorError
Feature list or desired feature list is empty.
Definition
vpFeatureException.h:64
vpFeatureException::sizeMismatchError
@ sizeMismatchError
Size mismatch error.
Definition
vpFeatureException.h:66
vpGenericFeature::duplicate
vpGenericFeature * duplicate() const VP_OVERRIDE
Definition
vpGenericFeature.cpp:610
vpGenericFeature::error
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpGenericFeature.cpp:157
vpGenericFeature::setInteractionMatrix
void setInteractionMatrix(const vpMatrix &L)
set the value of the interaction matrix.
Definition
vpGenericFeature.cpp:375
vpGenericFeature::init
void init() VP_OVERRIDE
Definition
vpGenericFeature.cpp:44
vpGenericFeature::display
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const VP_OVERRIDE
Definition
vpGenericFeature.cpp:621
vpGenericFeature::get_s
void get_s(vpColVector &s) const
get the value of all the features.
Definition
vpGenericFeature.cpp:420
vpGenericFeature::interaction
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpGenericFeature.cpp:335
vpGenericFeature::print
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
Definition
vpGenericFeature.cpp:598
vpGenericFeature::set_s
void set_s(const vpColVector &s)
set the value of all the features.
Definition
vpGenericFeature.cpp:398
vpGenericFeature::setError
void setError(const vpColVector &error_vector)
Definition
vpGenericFeature.cpp:90
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
vpDEBUG_TRACE
#define vpDEBUG_TRACE
Definition
vpDebug.h:526
vpERROR_TRACE
#define vpERROR_TRACE
Definition
vpDebug.h:423
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
visual_features
src
visual-feature
vpGenericFeature.cpp
Generated by
1.17.0