Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpHomogeneousMatrix.h
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 * Description:
31 * Homogeneous matrix.
32 */
33
38
39#ifndef VP_HOMOGENEOUS_MATRIX_H
40#define VP_HOMOGENEOUS_MATRIX_H
41
42#include <fstream>
43#include <vector>
44
45#include <visp3/core/vpConfig.h>
46
48
50class vpPoseVector;
51class vpMatrix;
53class vpPoseVector;
54class vpThetaUVector;
56class vpPoint;
57
58END_VISP_NAMESPACE
59
60#include <visp3/core/vpArray2D.h>
61#include <visp3/core/vpRotationMatrix.h>
62#include <visp3/core/vpThetaUVector.h>
63#include <visp3/core/vpPoseVector.h>
64
65#ifdef VISP_HAVE_NLOHMANN_JSON
66#include VISP_NLOHMANN_JSON(json.hpp)
67#endif
68
220class VISP_EXPORT vpHomogeneousMatrix : public vpArray2D<double>
221{
222public:
228 VP_EXPLICIT vpHomogeneousMatrix(const vpPoseVector &p);
229 VP_EXPLICIT vpHomogeneousMatrix(const std::vector<float> &v);
230 VP_EXPLICIT vpHomogeneousMatrix(const std::vector<double> &v);
231 vpHomogeneousMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz);
232#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
233 VP_EXPLICIT vpHomogeneousMatrix(const std::initializer_list<double> &list);
234#endif
235
240 vpHomogeneousMatrix &buildFrom(const std::vector<float> &v);
241 vpHomogeneousMatrix &buildFrom(const std::vector<double> &v);
242 vpHomogeneousMatrix &buildFrom(const double &tx, const double &ty, const double &tz, const double &tux, const double &tuy, const double &tuz);
243
244 void convert(std::vector<float> &M);
245 void convert(std::vector<double> &M);
246
247 // Set to identity
248 void eye();
249
250 vpColVector getCol(unsigned int j) const;
254
255 // Invert the homogeneous matrix.
257 // Invert the homogeneous matrix.
258 void inverse(vpHomogeneousMatrix &Mi) const;
259
260 // Test if the rotational part of the matrix is a rotation matrix.
261 bool isAnHomogeneousMatrix(double threshold = 1e-6) const;
262 bool isValid() const;
263
264 void insert(const vpRotationMatrix &R);
265 void insert(const vpThetaUVector &tu);
266 void insert(const vpTranslationVector &t);
267 void insert(const vpQuaternionVector &t);
268
269 void extract(vpRotationMatrix &R) const;
270 void extract(vpThetaUVector &tu) const;
271 void extract(vpTranslationVector &t) const;
272 void extract(vpQuaternionVector &q) const;
273
291 void load(std::ifstream &f);
292
309 void load(const std::string &filename);
310
339 void save(std::ofstream &f) const;
340
368 void save(const std::string &filename) const;
369
373
374 vpColVector operator*(const vpColVector &v) const;
377
378 // Multiply by a point
379 vpPoint operator*(const vpPoint &bP) const;
380
381 vpHomogeneousMatrix &operator<<(double val);
382 vpHomogeneousMatrix &operator,(double val);
383
385
386 void print() const;
387
393 VP_NORETURN void resize(unsigned int nrows, unsigned int ncols, bool flagNullify = true)
394 {
395 (void)nrows;
396 (void)ncols;
397 (void)flagNullify;
398 throw(vpException(vpException::fatalError, "Cannot resize an homogeneous matrix"));
399 }
400
401 static vpHomogeneousMatrix compute3d3dTransformation(const std::vector<vpPoint> &p, const std::vector<vpPoint> &q);
402
403 static vpHomogeneousMatrix mean(const std::vector<vpHomogeneousMatrix> &vec_M);
404
405#ifdef VISP_HAVE_NLOHMANN_JSON
406public:
407 static const std::string jsonTypeName;
408private:
409 friend void to_json(nlohmann::json &j, const vpHomogeneousMatrix &T);
410 friend void from_json(const nlohmann::json &j, vpHomogeneousMatrix &T);
411 // Conversion helper function to avoid circular dependencies and MSVC errors that are not exported in the DLL
412 void parse_json(const nlohmann::json &j);
413 void convert_to_json(nlohmann::json &j) const;
414public:
415
416#endif
417
418#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
423
427 VP_DEPRECATED void init() { }
431 VP_DEPRECATED void setIdentity();
433#endif
434
435protected:
436 unsigned int m_index;
437private:
438 static const unsigned int constr_value_4;
439};
440
441#ifdef VISP_HAVE_NLOHMANN_JSON
442inline void to_json(nlohmann::json &j, const vpHomogeneousMatrix &T)
443{
444 T.convert_to_json(j);
445}
446
447inline void from_json(const nlohmann::json &j, vpHomogeneousMatrix &T)
448{
449 T.parse_json(j);
450}
451#endif
452END_VISP_NAMESPACE
453#endif
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition vpArray2D.h:615
void insert(const vpArray2D< Type > &A, unsigned int r, unsigned int c)
Definition vpArray2D.h:586
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition vpArray2D.h:705
friend void to_json(nlohmann::json &j, const vpArray2D< T > &array)
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=nullptr)
Definition vpArray2D.h:760
vpArray2D< double > t() const
Definition vpArray2D.h:1273
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition vpArray2D.h:965
friend void from_json(const nlohmann::json &j, vpArray2D< T > &array)
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ fatalError
Fatal error.
Definition vpException.h:72
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpThetaUVector getThetaUVector() const
friend void from_json(const nlohmann::json &j, vpHomogeneousMatrix &T)
void print() const
Print the matrix as a pose vector .
vpRotationMatrix getRotationMatrix() const
bool isAnHomogeneousMatrix(double threshold=1e-6) const
VP_DEPRECATED void init()
vpHomogeneousMatrix & operator*=(const vpHomogeneousMatrix &M)
VP_NORETURN void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true)
vpHomogeneousMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpHomogeneousMatrix inverse() const
vpTranslationVector getTranslationVector() const
void convert(std::vector< float > &M)
void extract(vpRotationMatrix &R) const
vpColVector getCol(unsigned int j) const
vpHomogeneousMatrix operator*(const vpHomogeneousMatrix &M) const
friend void to_json(nlohmann::json &j, const vpHomogeneousMatrix &T)
static const std::string jsonTypeName
vpHomogeneousMatrix & operator,(double val)
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:79
Implementation of a pose vector and operations on poses.
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.