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