Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpFeatureThetaU.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 * ThetaU visual feature.
32 */
33
38
39#include <visp3/core/vpMath.h>
40#include <visp3/visual_features/vpBasicFeature.h>
41#include <visp3/visual_features/vpFeatureThetaU.h>
42
43// Exception
44#include <visp3/core/vpException.h>
45#include <visp3/visual_features/vpFeatureException.h>
46
47// Debug trace
48#include <visp3/core/vpDebug.h>
49
50/*
51
52attributes and members directly related to the vpBasicFeature needs
53other functionalities are useful but not mandatory
54
55*/
56
64{
65 // feature dimension
66 dim_s = 3;
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}
76
85{
86 // vpTRACE("0x%x", this);
87 init();
88}
89
98{
99 // vpTRACE("0x%x", this);
100 init();
101
102 // kind of rotation representation
103 rotation = r;
104}
105
124
131
148
156
184
202{
203 s[0] = tu[0];
204 s[1] = tu[1];
205 s[2] = tu[2];
206 for (unsigned int i = 0; i < nbParameters; ++i) {
207 flags[i] = true;
208 }
209 return *this;
210}
211
228{
229 vpThetaUVector tu(R);
230 buildFrom(tu);
231 return *this;
232}
233
253{
255 M.extract(R);
256 vpThetaUVector tu(R);
257 buildFrom(tu);
258 return *this;
259}
260
270
280{
281 s[0] = tu_x;
282 flags[0] = true;
283}
284
293{
294 s[1] = tu_y;
295 flags[1] = true;
296}
297
306{
307 s[2] = tu_z;
308 flags[2] = true;
309}
310
323
330double vpFeatureThetaU::get_TUx() const { return s[0]; }
331
337double vpFeatureThetaU::get_TUy() const { return s[1]; }
338
344double vpFeatureThetaU::get_TUz() const { return s[2]; }
345
409{
410
411 vpMatrix L;
412 L.resize(0, 6);
413
415 for (unsigned int i = 0; i < nbParameters; i++) {
416 if (flags[i] == false) {
417 switch (i) {
418 case 0:
419 vpTRACE("Warning !!! The interaction matrix is computed but Tu_x "
420 "was not set yet");
421 break;
422 case 1:
423 vpTRACE("Warning !!! The interaction matrix is computed but Tu_y "
424 "was not set yet");
425 break;
426 case 2:
427 vpTRACE("Warning !!! The interaction matrix is computed but Tu_z "
428 "was not set yet");
429 break;
430 default:
431 vpTRACE("Problem during the reading of the variable flags");
432 }
433 }
434 }
435 resetFlags();
436 }
437
438 // Lw computed using Lw = [theta/2 u]_x +/- (I + alpha [u]_x [u]_x)
439 vpColVector u(3);
440 for (unsigned int i = 0; i < 3; i++) {
441 u[i] = s[i] / 2.0;
442 }
443
444 vpMatrix Lw(3, 3);
445 Lw = vpColVector::skew(u); /* [theta/2 u]_x */
446
447 vpMatrix U2(3, 3);
448 U2.eye();
449
450 double theta = sqrt(s.sumSquare());
451 if (theta >= 1e-6) {
452 for (unsigned int i = 0; i < 3; i++)
453 u[i] = s[i] / theta;
454
455 vpMatrix skew_u;
456 skew_u = vpColVector::skew(u);
457 U2 += (1 - vpMath::sinc(theta) / vpMath::sqr(vpMath::sinc(theta / 2.0))) * skew_u * skew_u;
458 }
459
460 if (rotation == cdRc) {
461 Lw += U2;
462 }
463 else {
464 Lw -= U2;
465 }
466
467 // This version is a simplification
468 if (vpFeatureThetaU::selectTUx() & select) {
469 vpMatrix Lx(1, 6);
470
471 Lx[0][0] = 0;
472 Lx[0][1] = 0;
473 Lx[0][2] = 0;
474 for (int i = 0; i < 3; i++)
475 Lx[0][i + 3] = Lw[0][i];
476
477 L = vpMatrix::stack(L, Lx);
478 }
479
480 if (vpFeatureThetaU::selectTUy() & select) {
481 vpMatrix Ly(1, 6);
482
483 Ly[0][0] = 0;
484 Ly[0][1] = 0;
485 Ly[0][2] = 0;
486 for (int i = 0; i < 3; i++)
487 Ly[0][i + 3] = Lw[1][i];
488
489 L = vpMatrix::stack(L, Ly);
490 }
491
492 if (vpFeatureThetaU::selectTUz() & select) {
493 vpMatrix Lz(1, 6);
494
495 Lz[0][0] = 0;
496 Lz[0][1] = 0;
497 Lz[0][2] = 0;
498 for (int i = 0; i < 3; i++)
499 Lz[0][i + 3] = Lw[2][i];
500
501 L = vpMatrix::stack(L, Lz);
502 }
503
504 return L;
505}
506
568vpColVector vpFeatureThetaU::error(const vpBasicFeature &s_star, unsigned int select)
569{
570
571 if (fabs(s_star.get_s().sumSquare()) > 1e-6) {
572 vpERROR_TRACE("s* should be zero ! ");
574 }
575
576 vpColVector e(0);
577
578 if (vpFeatureThetaU::selectTUx() & select) {
579 vpColVector ex(1);
580 ex[0] = s[0];
581 e = vpColVector::stack(e, ex);
582 }
583
584 if (vpFeatureThetaU::selectTUy() & select) {
585 vpColVector ey(1);
586 ey[0] = s[1];
587 e = vpColVector::stack(e, ey);
588 }
589
590 if (vpFeatureThetaU::selectTUz() & select) {
591 vpColVector ez(1);
592 ez[0] = s[2];
593 e = vpColVector::stack(e, ez);
594 }
595 return e;
596}
597
624void vpFeatureThetaU::print(unsigned int select) const
625{
626 std::cout << "ThetaU:";
627 if (vpFeatureThetaU::selectTUx() & select) {
628 std::cout << " tux=" << s[0];
629 }
630 if (vpFeatureThetaU::selectTUy() & select) {
631 std::cout << " tuy=" << s[1];
632 }
633 if (vpFeatureThetaU::selectTUz() & select) {
634 std::cout << " tuz=" << s[2];
635 }
636 std::cout << std::endl;
637}
638
651{
652 vpFeatureThetaU *feature;
653 if (rotation == cdRc)
655 else // if (rotation == cRcd
657
658 return feature;
659}
660
667 const vpColor & /* color */, unsigned int /* thickness */) const
668{
669 static int firsttime = 0;
670
671 if (firsttime == 0) {
672 firsttime = 1;
673 vpERROR_TRACE("not implemented");
674 // Do not throw and error since it is not subject
675 // to produce a failure
676 }
677}
678
683void vpFeatureThetaU::display(const vpCameraParameters & /* cam */, const vpImage<vpRGBa> & /* I */,
684 const vpColor & /* color */, unsigned int /* thickness */) const
685{
686 static int firsttime = 0;
687
688 if (firsttime == 0) {
689 firsttime = 1;
690 vpERROR_TRACE("not implemented");
691 // Do not throw and error since it is not subject
692 // to produce a failure
693 }
694}
695
720unsigned int vpFeatureThetaU::selectTUx() { return FEATURE_LINE[0]; }
745unsigned int vpFeatureThetaU::selectTUy() { return FEATURE_LINE[1]; }
770unsigned int vpFeatureThetaU::selectTUz() { 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)
static vpMatrix skew(const vpColVector &v)
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.
vpFeatureThetaU * duplicate() const VP_OVERRIDE
Feature duplication.
vpFeatureThetaURotationRepresentationType getFeatureThetaURotationType() const
static unsigned int selectTUy()
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
void set_TUx(double tu_x)
double get_TUx() const
void set_TUz(double tu_z)
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
double get_TUy() const
double get_TUz() const
static unsigned int selectTUx()
void setFeatureThetaURotationType(const vpFeatureThetaURotationRepresentationType r)
vpFeatureThetaU & buildFrom(const vpThetaUVector &tu)
static unsigned int selectTUz()
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const VP_OVERRIDE
void set_TUy(double tu_y)
void init() VP_OVERRIDE
Implementation of an homogeneous matrix and operations on such kind of matrices.
void extract(vpRotationMatrix &R) const
Definition of the vpImage class member functions.
Definition vpImage.h:131
static double sinc(double x)
Definition vpMath.cpp:289
static double sqr(double x)
Definition vpMath.h:203
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
void stack(const vpMatrix &A)
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as axis-angle minimal representation.
#define vpTRACE
Definition vpDebug.h:450
#define vpERROR_TRACE
Definition vpDebug.h:423