Visual Servoing Platform version 3.7.0
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
53attributes and members directly related to the vpBasicFeature needs
54other functionalities are useful but not mandatory
55
56*/
57
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
85
97
111 : f2Mf1(), translation(r)
112{
113 init();
114
115 buildFrom(f2Mf1_);
116}
117
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
151
161void vpFeatureTranslation::set_Tx(double t_x) { s[0] = t_x; }
171void vpFeatureTranslation::set_Ty(double t_y) { s[1] = t_y; }
181void vpFeatureTranslation::set_Tz(double t_z) { s[2] = t_z; }
182
196
202double vpFeatureTranslation::get_Tx() const { return s[0]; }
203
209double vpFeatureTranslation::get_Ty() const { return s[1]; }
210
216double vpFeatureTranslation::get_Tz() const { return s[2]; }
217
300{
301
302 vpMatrix L;
303 L.resize(0, 6);
304
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
506vpColVector 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 ! ");
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
561void 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
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
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
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
680unsigned int vpFeatureTranslation::selectTx() { return FEATURE_LINE[0]; }
681
725unsigned int vpFeatureTranslation::selectTy() { return FEATURE_LINE[1]; }
726
770unsigned int vpFeatureTranslation::selectTz() { return FEATURE_LINE[2]; }
771END_VISP_NAMESPACE
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition vpArray2D.h:448
vpColVector s
State of the visual feature.
unsigned int nbParameters
Number of parameters needed to compute the interaction matrix.
vpColVector get_s(unsigned int select=FEATURE_ALL) const
Get the feature vector .
unsigned int dim_s
Dimension of the visual feature.
static const unsigned int FEATURE_LINE[32]
vpBasicFeatureDeallocatorType deallocate
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
double sumSquare() const
void stack(double d)
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
Error that can be emitted by the vpBasicFeature class and its derivates.
@ badInitializationError
Wrong feature initialization.
static unsigned int selectTz()
void setFeatureTranslationType(const vpFeatureTranslationRepresentationType r)
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
static unsigned int selectTx()
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const VP_OVERRIDE
vpFeatureTranslationRepresentationType getFeatureTranslationType() const
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
vpFeatureTranslation & buildFrom(const vpHomogeneousMatrix &f2Mf1)
vpFeatureTranslation * duplicate() const VP_OVERRIDE
Feature duplication.
static unsigned int selectTy()
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
void stack(const vpMatrix &A)
#define vpTRACE
Definition vpDebug.h:450
#define vpERROR_TRACE
Definition vpDebug.h:423