Visual Servoing Platform  version 3.2.1 under development (2019-11-19)
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 
149 class VISP_EXPORT vpHomogeneousMatrix : public vpArray2D<double>
150 {
151 public:
157  explicit vpHomogeneousMatrix(const vpPoseVector &p);
158  explicit vpHomogeneousMatrix(const std::vector<float> &v);
159  explicit vpHomogeneousMatrix(const std::vector<double> &v);
160  vpHomogeneousMatrix(const double tx, const double ty, const double tz, const double tux, const double tuy,
161  const double tuz);
165  virtual ~vpHomogeneousMatrix(){};
166 
167  void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R);
168  void buildFrom(const vpTranslationVector &t, const vpThetaUVector &tu);
169  void buildFrom(const vpTranslationVector &t, const vpQuaternionVector &q);
170  void buildFrom(const vpPoseVector &p);
171  void buildFrom(const std::vector<float> &v);
172  void buildFrom(const std::vector<double> &v);
173  void buildFrom(const double tx, const double ty, const double tz, const double tux, const double tuy,
174  const double tuz);
175 
176  void convert(std::vector<float> &M);
177  void convert(std::vector<double> &M);
178 
179  // Set to identity
180  void eye();
181 
182  vpColVector getCol(const unsigned int j) const;
183  vpRotationMatrix getRotationMatrix() const;
184  vpThetaUVector getThetaUVector() const;
185  vpTranslationVector getTranslationVector() const;
186 
187  // Invert the homogeneous matrix.
188  vpHomogeneousMatrix inverse() const;
189  // Invert the homogeneous matrix.
190  void inverse(vpHomogeneousMatrix &Mi) const;
191 
192  // Test if the rotational part of the matrix is a rotation matrix.
193  bool isAnHomogeneousMatrix() const;
194 
195  void insert(const vpRotationMatrix &R);
196  void insert(const vpThetaUVector &tu);
197  void insert(const vpTranslationVector &t);
198  void insert(const vpQuaternionVector &t);
199 
200  void extract(vpRotationMatrix &R) const;
201  void extract(vpThetaUVector &tu) const;
202  void extract(vpTranslationVector &t) const;
203  void extract(vpQuaternionVector &q) const;
204 
205  // Load an homogeneous matrix from a file
206  void load(std::ifstream &f);
207  // Save an homogeneous matrix in a file
208  void save(std::ofstream &f) const;
209 
212  vpHomogeneousMatrix &operator*=(const vpHomogeneousMatrix &M);
213 
214  vpColVector operator*(const vpColVector &v) const;
215  vpTranslationVector operator*(const vpTranslationVector &t) const;
216 
217  // Multiply by a point
218  vpPoint operator*(const vpPoint &bP) const;
219 
220  void print() const;
221 
227  void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify = true)
228  {
229  (void)nrows;
230  (void)ncols;
231  (void)flagNullify;
232  throw(vpException(vpException::fatalError, "Cannot resize an homogeneous matrix"));
233  };
234 
235  static vpHomogeneousMatrix mean(const std::vector<vpHomogeneousMatrix> &vec_M);
236 
237 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
238 
246  vp_deprecated void init(){};
250  vp_deprecated void setIdentity();
252 #endif
253 };
254 
255 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:164
static bool save(const std::string &filename, const vpArray2D< Type > &A, const bool binary=false, const char *header="")
Definition: vpArray2D.h:739
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:415
Implementation of an homogeneous matrix and operations on such kind of matrices.
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 what is a point.
Definition: vpPoint.h:58
Implementation of a rotation matrix and operations on such kind of matrices.
vpColVector operator*(const double &x, const vpColVector &v)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
vp_deprecated void init()
static bool load(const std::string &filename, vpArray2D< Type > &A, const bool binary=false, char *header=NULL)
Definition: vpArray2D.h:542
Implementation of a rotation vector as quaternion angle minimal representation.
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.