Visual Servoing Platform  version 3.6.1 under development (2025-01-20)
vpRBFeatureTracker.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 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 
31 #include <visp3/rbt/vpRBFeatureTracker.h>
32 
33 #if defined(VISP_HAVE_SIMDLIB)
34 #include <Simd/SimdLib.h>
35 #endif
36 
37 BEGIN_VISP_NAMESPACE
38 
40 {
41  m_numFeatures = 0;
42  m_userVvsWeight = 1.0;
43  m_vvsConverged = false;
44  m_enableDisplay = true;
45 }
46 
47 void vpRBFeatureTracker::updateCovariance(const double lambda)
48 {
49  vpMatrix D;
50  D.diag(m_covWeightDiag);
51  m_cov = computeCovarianceMatrix(m_L, lambda * m_error, D);
52 }
53 
54 void vpRBFeatureTracker::computeJTR(const vpMatrix &interaction, const vpColVector &error, vpColVector &JTR)
55 {
56  if (interaction.getRows() != error.getRows() || interaction.getCols() != 6) {
57  throw vpMatrixException(vpMatrixException::incorrectMatrixSizeError, "Incorrect matrices size in computeJTR.");
58  }
59 
60  JTR.resize(6, false);
61 #if defined(VISP_HAVE_SIMDLIB)
62  SimdComputeJtR(interaction.data, interaction.getRows(), error.data, JTR.data);
63 #else
64  const unsigned int N = interaction.getRows();
65 
66  for (unsigned int i = 0; i < 6; ++i) {
67  double ssum = 0;
68  for (unsigned int j = 0; j < N; ++j) {
69  ssum += interaction[j][i] * error[j];
70  }
71  JTR[i] = ssum;
72 }
73 #endif
74 }
75 
77 {
78  const vpColVector covDiagE = covDiag * e;
79  double sigma2 = (covDiagE.t() * covDiag * e) / ((double)e.getRows());
80  return (DJ.t() * covDiag * DJ).pseudoInverse() * sigma2;
81 }
82 
83 END_VISP_NAMESPACE
unsigned int getCols() const
Definition: vpArray2D.h:337
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:148
unsigned int getRows() const
Definition: vpArray2D.h:347
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
vpRowVector t() const
void resize(unsigned int i, bool flagNullify=true)
Definition: vpColVector.h:1143
error that can be emitted by the vpMatrix class and its derivatives
@ incorrectMatrixSizeError
Incorrect matrix size.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
vpMatrix t() const
bool m_enableDisplay
Whether VVS has converged, should be updated every VVS iteration.
static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &b, const vpMatrix &W)
vpColVector m_covWeightDiag
Covariance matrix.
double m_userVvsWeight
Number of considered features.
static void computeJTR(const vpMatrix &interaction, const vpColVector &error, vpColVector &JTR)
bool m_vvsConverged
User-defined weight for this specific type of feature.
virtual void updateCovariance(const double lambda)
Update the covariance matrix.
unsigned m_numFeatures
Error weights.
vpMatrix m_cov
Right side of the Gauss Newton minimization.