Visual Servoing Platform  version 3.4.0
vpHomogeneousMatrix.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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
172 
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() const;
203 
204  void insert(const vpRotationMatrix &R);
205  void insert(const vpThetaUVector &tu);
206  void insert(const vpTranslationVector &t);
207  void insert(const vpQuaternionVector &t);
208 
209  void extract(vpRotationMatrix &R) const;
210  void extract(vpThetaUVector &tu) const;
211  void extract(vpTranslationVector &t) const;
212  void extract(vpQuaternionVector &q) const;
213 
214  // Load an homogeneous matrix from a file
215  void load(std::ifstream &f);
216  // Save an homogeneous matrix in a file
217  void save(std::ofstream &f) const;
218 
221  vpHomogeneousMatrix &operator*=(const vpHomogeneousMatrix &M);
222 
223  vpColVector operator*(const vpColVector &v) const;
224  vpTranslationVector operator*(const vpTranslationVector &t) const;
225 
226  // Multiply by a point
227  vpPoint operator*(const vpPoint &bP) const;
228 
229  vpHomogeneousMatrix& operator<<(double val);
230  vpHomogeneousMatrix& operator,(double val);
231 
232  void print() const;
233 
239  void resize(unsigned int nrows, unsigned int ncols, bool flagNullify = true)
240  {
241  (void)nrows;
242  (void)ncols;
243  (void)flagNullify;
244  throw(vpException(vpException::fatalError, "Cannot resize an homogeneous matrix"));
245  };
246 
247  static vpHomogeneousMatrix mean(const std::vector<vpHomogeneousMatrix> &vec_M);
248 
249 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
250 
258  vp_deprecated void init(){};
262  vp_deprecated void setIdentity();
264 #endif
265 
266 protected:
267  unsigned int m_index;
268 };
269 
270 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:153
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:413
Implementation of an homogeneous matrix and operations on such kind of matrices.
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:737
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true)
error that can be emited by ViSP classes.
Definition: vpException.h:71
Implementation of a generic 2D array used as base class for matrices and vectors. ...
Definition: vpArray2D.h:131
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:81
Implementation of a rotation matrix and operations on such kind of matrices.
vpColVector operator*(const double &x, const vpColVector &v)
vp_deprecated void init()
Implementation of a rotation vector as quaternion angle minimal representation.
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:493
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:151
Class that consider the case of a translation vector.
Implementation of a rotation vector as axis-angle minimal representation.
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=NULL)
Definition: vpArray2D.h:540