Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpFeatureTranslation.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 translation visual feature.
32
*/
33
38
39
#include <visp3/visual_features/vpBasicFeature.h>
40
#include <visp3/visual_features/vpFeatureTranslation.h>
41
42
#include <visp3/core/vpMath.h>
43
44
// Exception
45
#include <visp3/core/vpException.h>
46
#include <visp3/visual_features/vpFeatureException.h>
47
48
// Debug trace
49
#include <visp3/core/vpDebug.h>
50
51
/*
52
53
attributes and members directly related to the vpBasicFeature needs
54
other functionalities are useful but not mandatory
55
56
*/
57
58
BEGIN_VISP_NAMESPACE
64
void
vpFeatureTranslation::init
()
65
{
66
// feature dimension
67
dim_s
= 3;
68
nbParameters
= 1;
69
70
// memory allocation
71
s
.resize(
dim_s
);
72
if
(
flags
==
nullptr
)
73
flags
=
new
bool
[
nbParameters
];
74
for
(
unsigned
int
i = 0; i <
nbParameters
; i++)
75
flags
[i] =
false
;
76
}
77
84
vpFeatureTranslation::vpFeatureTranslation
() : f2Mf1(), translation(
vpFeatureTranslation
::
cdMc
) {
init
(); }
85
93
vpFeatureTranslation::vpFeatureTranslation
(
vpFeatureTranslationRepresentationType
r) : f2Mf1(), translation(r)
94
{
95
init
();
96
}
97
110
vpFeatureTranslation::vpFeatureTranslation
(
vpHomogeneousMatrix
&f2Mf1_,
vpFeatureTranslationRepresentationType
r)
111
: f2Mf1(), translation(r)
112
{
113
init
();
114
115
buildFrom
(f2Mf1_);
116
}
117
127
vpFeatureTranslation
&
vpFeatureTranslation::buildFrom
(
const
vpHomogeneousMatrix
&f2Mf1_)
128
{
129
this->f2Mf1 = f2Mf1_;
130
s
[0] = f2Mf1[0][3];
131
s
[1] = f2Mf1[1][3];
132
s
[2] = f2Mf1[2][3];
133
134
flags
[0] =
true
;
135
return
*
this
;
136
}
137
147
void
vpFeatureTranslation::setFeatureTranslationType
(
const
vpFeatureTranslationRepresentationType
r)
148
{
149
translation = r;
150
}
151
161
void
vpFeatureTranslation::set_Tx
(
double
t_x) {
s
[0] = t_x; }
171
void
vpFeatureTranslation::set_Ty
(
double
t_y) {
s
[1] = t_y; }
181
void
vpFeatureTranslation::set_Tz
(
double
t_z) {
s
[2] = t_z; }
182
192
vpFeatureTranslation::vpFeatureTranslationRepresentationType
vpFeatureTranslation::getFeatureTranslationType
()
const
193
{
194
return
translation;
195
}
196
202
double
vpFeatureTranslation::get_Tx
()
const
{
return
s
[0]; }
203
209
double
vpFeatureTranslation::get_Ty
()
const
{
return
s
[1]; }
210
216
double
vpFeatureTranslation::get_Tz
()
const
{
return
s
[2]; }
217
299
vpMatrix
vpFeatureTranslation::interaction
(
unsigned
int
select)
300
{
301
302
vpMatrix
L;
303
L.
resize
(0, 6);
304
305
if
(
deallocate
==
vpBasicFeature::user
) {
306
for
(
unsigned
int
i = 0; i <
nbParameters
; i++) {
307
if
(
flags
[i] ==
false
) {
308
switch
(i) {
309
case
0:
310
vpTRACE
(
"Warning !!! The interaction matrix is computed but f2Mf1 "
311
"was not set yet"
);
312
break
;
313
default
:
314
vpTRACE
(
"Problem during the reading of the variable flags"
);
315
}
316
}
317
}
318
resetFlags
();
319
}
320
321
if
(translation ==
cdMc
) {
322
// This version is a simplification
323
if
(
vpFeatureTranslation::selectTx
() & select) {
324
vpMatrix
Lx(1, 6);
325
326
for
(
int
i = 0; i < 3; i++)
327
Lx[0][i] = f2Mf1[0][i];
328
Lx[0][3] = 0;
329
Lx[0][4] = 0;
330
Lx[0][5] = 0;
331
332
L =
vpMatrix::stack
(L, Lx);
333
}
334
335
if
(
vpFeatureTranslation::selectTy
() & select) {
336
vpMatrix
Ly(1, 6);
337
338
for
(
int
i = 0; i < 3; i++)
339
Ly[0][i] = f2Mf1[1][i];
340
Ly[0][3] = 0;
341
Ly[0][4] = 0;
342
Ly[0][5] = 0;
343
344
L =
vpMatrix::stack
(L, Ly);
345
}
346
347
if
(
vpFeatureTranslation::selectTz
() & select) {
348
vpMatrix
Lz(1, 6);
349
350
for
(
int
i = 0; i < 3; i++)
351
Lz[0][i] = f2Mf1[2][i];
352
Lz[0][3] = 0;
353
Lz[0][4] = 0;
354
Lz[0][5] = 0;
355
356
L =
vpMatrix::stack
(L, Lz);
357
}
358
}
359
if
(translation ==
cMcd
) {
360
// This version is a simplification
361
if
(
vpFeatureTranslation::selectTx
() & select) {
362
vpMatrix
Lx(1, 6);
363
Lx[0][0] = -1;
364
Lx[0][1] = 0;
365
Lx[0][2] = 0;
366
Lx[0][3] = 0;
367
Lx[0][4] = -
s
[2];
368
Lx[0][5] =
s
[1];
369
370
L =
vpMatrix::stack
(L, Lx);
371
}
372
373
if
(
vpFeatureTranslation::selectTy
() & select) {
374
vpMatrix
Ly(1, 6);
375
Ly[0][0] = 0;
376
Ly[0][1] = -1;
377
Ly[0][2] = 0;
378
Ly[0][3] =
s
[2];
379
Ly[0][4] = 0;
380
Ly[0][5] = -
s
[0];
381
382
L =
vpMatrix::stack
(L, Ly);
383
}
384
385
if
(
vpFeatureTranslation::selectTz
() & select) {
386
vpMatrix
Lz(1, 6);
387
Lz[0][0] = 0;
388
Lz[0][1] = 0;
389
Lz[0][2] = -1;
390
Lz[0][3] = -
s
[1];
391
Lz[0][4] =
s
[0];
392
Lz[0][5] = 0;
393
394
L =
vpMatrix::stack
(L, Lz);
395
}
396
}
397
398
if
(translation ==
cMo
) {
399
// This version is a simplification
400
if
(
vpFeatureTranslation::selectTx
() & select) {
401
vpMatrix
Lx(1, 6);
402
Lx[0][0] = -1;
403
Lx[0][1] = 0;
404
Lx[0][2] = 0;
405
Lx[0][3] = 0;
406
Lx[0][4] = -
s
[2];
407
Lx[0][5] =
s
[1];
408
409
L =
vpMatrix::stack
(L, Lx);
410
}
411
412
if
(
vpFeatureTranslation::selectTy
() & select) {
413
vpMatrix
Ly(1, 6);
414
Ly[0][0] = 0;
415
Ly[0][1] = -1;
416
Ly[0][2] = 0;
417
Ly[0][3] =
s
[2];
418
Ly[0][4] = 0;
419
Ly[0][5] = -
s
[0];
420
421
L =
vpMatrix::stack
(L, Ly);
422
}
423
424
if
(
vpFeatureTranslation::selectTz
() & select) {
425
vpMatrix
Lz(1, 6);
426
Lz[0][0] = 0;
427
Lz[0][1] = 0;
428
Lz[0][2] = -1;
429
Lz[0][3] = -
s
[1];
430
Lz[0][4] =
s
[0];
431
Lz[0][5] = 0;
432
433
L =
vpMatrix::stack
(L, Lz);
434
}
435
}
436
437
return
L;
438
}
439
506
vpColVector
vpFeatureTranslation::error
(
const
vpBasicFeature
&s_star,
unsigned
int
select)
507
{
508
vpColVector
e(0);
509
510
if
(translation ==
cdMc
|| translation ==
cMcd
) {
511
if
(s_star.
get_s
().
sumSquare
() > 1e-6) {
512
vpERROR_TRACE
(
"s* should be zero ! "
);
513
throw
(
vpFeatureException
(
vpFeatureException::badInitializationError
,
"s* should be zero !"
));
514
}
515
}
516
517
if
(
vpFeatureTranslation::selectTx
() & select) {
518
vpColVector
ex(1);
519
ex[0] =
s
[0] - s_star[0];
520
e =
vpColVector::stack
(e, ex);
521
}
522
523
if
(
vpFeatureTranslation::selectTy
() & select) {
524
vpColVector
ey(1);
525
ey[0] =
s
[1] - s_star[1];
526
e =
vpColVector::stack
(e, ey);
527
}
528
529
if
(
vpFeatureTranslation::selectTz
() & select) {
530
vpColVector
ez(1);
531
ez[0] =
s
[2] - s_star[2];
532
e =
vpColVector::stack
(e, ez);
533
}
534
535
return
e;
536
}
537
561
void
vpFeatureTranslation::print
(
unsigned
int
select)
const
562
{
563
std::cout <<
"Translation 3D:"
;
564
if
(
vpFeatureTranslation::selectTx
() & select) {
565
std::cout <<
" tx="
<<
s
[0];
566
}
567
if
(
vpFeatureTranslation::selectTy
() & select) {
568
std::cout <<
" ty="
<<
s
[1];
569
}
570
if
(
vpFeatureTranslation::selectTz
() & select) {
571
std::cout <<
" tz="
<<
s
[2];
572
}
573
std::cout << std::endl;
574
}
575
589
vpFeatureTranslation
*
vpFeatureTranslation::duplicate
()
const
590
{
591
vpFeatureTranslation
*feature =
nullptr
;
592
if
(translation ==
cdMc
)
593
feature =
new
vpFeatureTranslation
(
cdMc
);
594
if
(translation ==
cMo
)
595
feature =
new
vpFeatureTranslation
(
cMo
);
596
if
(translation ==
cMcd
)
597
feature =
new
vpFeatureTranslation
(
cMcd
);
598
return
feature;
599
}
600
606
void
vpFeatureTranslation::display
(
const
vpCameraParameters
&
/* cam */
,
const
vpImage<unsigned char>
&
/* I */
,
607
const
vpColor
&
/* color */
,
unsigned
int
/* thickness */
)
const
608
{
609
static
int
firsttime = 0;
610
611
if
(firsttime == 0) {
612
firsttime = 1;
613
vpERROR_TRACE
(
"not implemented"
);
614
// Do not throw and error since it is not subject
615
// to produce a failure
616
}
617
}
618
623
void
vpFeatureTranslation::display
(
const
vpCameraParameters
&
/* cam */
,
const
vpImage<vpRGBa>
&
/* I */
,
624
const
vpColor
&
/* color */
,
unsigned
int
/* thickness */
)
const
625
{
626
static
int
firsttime = 0;
627
628
if
(firsttime == 0) {
629
firsttime = 1;
630
vpERROR_TRACE
(
"not implemented"
);
631
// Do not throw and error since it is not subject
632
// to produce a failure
633
}
634
}
635
680
unsigned
int
vpFeatureTranslation::selectTx
() {
return
FEATURE_LINE
[0]; }
681
725
unsigned
int
vpFeatureTranslation::selectTy
() {
return
FEATURE_LINE
[1]; }
726
770
unsigned
int
vpFeatureTranslation::selectTz
() {
return
FEATURE_LINE
[2]; }
771
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::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::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::sumSquare
double sumSquare() const
Definition
vpColVector.cpp:938
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
vpFeatureTranslation::vpFeatureTranslation
vpFeatureTranslation()
Definition
vpFeatureTranslation.cpp:84
vpFeatureTranslation::set_Tx
void set_Tx(double t_x)
Definition
vpFeatureTranslation.cpp:161
vpFeatureTranslation::selectTz
static unsigned int selectTz()
Definition
vpFeatureTranslation.cpp:770
vpFeatureTranslation::get_Tz
double get_Tz() const
Definition
vpFeatureTranslation.cpp:216
vpFeatureTranslation::setFeatureTranslationType
void setFeatureTranslationType(const vpFeatureTranslationRepresentationType r)
Definition
vpFeatureTranslation.cpp:147
vpFeatureTranslation::error
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpFeatureTranslation.cpp:506
vpFeatureTranslation::selectTx
static unsigned int selectTx()
Definition
vpFeatureTranslation.cpp:680
vpFeatureTranslation::set_Tz
void set_Tz(double t_z)
Definition
vpFeatureTranslation.cpp:181
vpFeatureTranslation::get_Ty
double get_Ty() const
Definition
vpFeatureTranslation.cpp:209
vpFeatureTranslation::set_Ty
void set_Ty(double t_y)
Definition
vpFeatureTranslation.cpp:171
vpFeatureTranslation::print
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
Definition
vpFeatureTranslation.cpp:561
vpFeatureTranslation::display
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const VP_OVERRIDE
Definition
vpFeatureTranslation.cpp:606
vpFeatureTranslation::getFeatureTranslationType
vpFeatureTranslationRepresentationType getFeatureTranslationType() const
Definition
vpFeatureTranslation.cpp:192
vpFeatureTranslation::get_Tx
double get_Tx() const
Definition
vpFeatureTranslation.cpp:202
vpFeatureTranslation::interaction
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpFeatureTranslation.cpp:299
vpFeatureTranslation::buildFrom
vpFeatureTranslation & buildFrom(const vpHomogeneousMatrix &f2Mf1)
Definition
vpFeatureTranslation.cpp:127
vpFeatureTranslation::duplicate
vpFeatureTranslation * duplicate() const VP_OVERRIDE
Feature duplication.
Definition
vpFeatureTranslation.cpp:589
vpFeatureTranslation::init
void init() VP_OVERRIDE
Definition
vpFeatureTranslation.cpp:64
vpFeatureTranslation::selectTy
static unsigned int selectTy()
Definition
vpFeatureTranslation.cpp:725
vpFeatureTranslation::vpFeatureTranslationRepresentationType
vpFeatureTranslationRepresentationType
Definition
vpFeatureTranslation.h:289
vpFeatureTranslation::cMo
@ cMo
Definition
vpFeatureTranslation.h:301
vpFeatureTranslation::cdMc
@ cdMc
Definition
vpFeatureTranslation.h:293
vpFeatureTranslation::cMcd
@ cMcd
Definition
vpFeatureTranslation.h:297
vpHomogeneousMatrix
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition
vpHomogeneousMatrix.h:221
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
vpFeatureTranslation.cpp
Generated by
1.17.0