Visual Servoing Platform  version 3.5.1 under development (2022-12-04)
vpHomogeneousMatrix.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2022 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Homogeneous matrix.
33  *
34  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
44 #ifndef VPHOMOGENEOUSMATRIX_HH
45 #define VPHOMOGENEOUSMATRIX_HH
46 
48 class vpPoseVector;
49 class vpMatrix;
50 class vpRotationMatrix;
51 class vpPoseVector;
52 class vpThetaUVector;
53 class vpQuaternionVector;
54 class vpPoint;
55 
56 #include <fstream>
57 #include <vector>
58 
59 #include <visp3/core/vpArray2D.h>
60 #include <visp3/core/vpRotationMatrix.h>
61 #include <visp3/core/vpThetaUVector.h>
62 //#include <visp3/core/vpTranslationVector.h>
63 #include <visp3/core/vpPoseVector.h>
64 
157 class VISP_EXPORT vpHomogeneousMatrix : public vpArray2D<double>
158 {
159 public:
165  explicit vpHomogeneousMatrix(const vpPoseVector &p);
166  explicit vpHomogeneousMatrix(const std::vector<float> &v);
167  explicit vpHomogeneousMatrix(const std::vector<double> &v);
168  vpHomogeneousMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz);
169 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
170  vpHomogeneousMatrix(const std::initializer_list<double> &list);
171 #endif
175  virtual ~vpHomogeneousMatrix() {}
176 
177  void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R);
178  void buildFrom(const vpTranslationVector &t, const vpThetaUVector &tu);
179  void buildFrom(const vpTranslationVector &t, const vpQuaternionVector &q);
180  void buildFrom(const vpPoseVector &p);
181  void buildFrom(const std::vector<float> &v);
182  void buildFrom(const std::vector<double> &v);
183  void buildFrom(double tx, double ty, double tz, double tux, double tuy, double tuz);
184 
185  void convert(std::vector<float> &M);
186  void convert(std::vector<double> &M);
187 
188  // Set to identity
189  void eye();
190 
191  vpColVector getCol(unsigned int j) const;
192  vpRotationMatrix getRotationMatrix() const;
193  vpThetaUVector getThetaUVector() const;
194  vpTranslationVector getTranslationVector() const;
195 
196  // Invert the homogeneous matrix.
197  vpHomogeneousMatrix inverse() const;
198  // Invert the homogeneous matrix.
199  void inverse(vpHomogeneousMatrix &Mi) const;
200 
201  // Test if the rotational part of the matrix is a rotation matrix.
202  bool isAnHomogeneousMatrix(double threshold = 1e-6) const;
203  bool isValid() const;
204 
205  void insert(const vpRotationMatrix &R);
206  void insert(const vpThetaUVector &tu);
207  void insert(const vpTranslationVector &t);
208  void insert(const vpQuaternionVector &t);
209 
210  void extract(vpRotationMatrix &R) const;
211  void extract(vpThetaUVector &tu) const;
212  void extract(vpTranslationVector &t) const;
213  void extract(vpQuaternionVector &q) const;
214 
215  // Load an homogeneous matrix from a file
216  void load(std::ifstream &f);
217  // Save an homogeneous matrix in a file
218  void save(std::ofstream &f) const;
219 
222  vpHomogeneousMatrix &operator*=(const vpHomogeneousMatrix &M);
223 
224  vpColVector operator*(const vpColVector &v) const;
226 
227  // Multiply by a point
228  vpPoint operator*(const vpPoint &bP) const;
229 
230  vpHomogeneousMatrix &operator<<(double val);
231  vpHomogeneousMatrix &operator,(double val);
232 
233  void orthogonalizeRotation();
234 
235  void print() const;
236 
242  void resize(unsigned int nrows, unsigned int ncols, bool flagNullify = true)
243  {
244  (void)nrows;
245  (void)ncols;
246  (void)flagNullify;
247  throw(vpException(vpException::fatalError, "Cannot resize an homogeneous matrix"));
248  }
249 
250  static vpHomogeneousMatrix compute3d3dTransformation(const std::vector<vpPoint> &p, const std::vector<vpPoint> &q);
251 
252  static vpHomogeneousMatrix mean(const std::vector<vpHomogeneousMatrix> &vec_M);
253 
254 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
263  vp_deprecated void init() {}
267  vp_deprecated void setIdentity();
269 #endif
270 
271 protected:
272  unsigned int m_index;
273 };
274 
275 #endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition: vpArray2D.h:132
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=NULL)
Definition: vpArray2D.h:541
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:494
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:414
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:736
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
error that can be emited by ViSP classes.
Definition: vpException.h:72
@ fatalError
Fatal error.
Definition: vpException.h:96
Implementation of an homogeneous matrix and operations on such kind of matrices.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true)
vp_deprecated void init()
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:154
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:82
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:152
Implementation of a rotation vector as quaternion angle minimal representation.
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.
vpColVector operator*(const double &x, const vpColVector &v)