Visual Servoing Platform  version 3.6.1 under development (2024-03-28)
vpPoseVector.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 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  * Pose object. A pose is a size 6 vector [t, tu]^T where tu is
32  * a rotation vector (theta u representation) and t is a translation vector.
33  */
34 
35 #ifndef vpPOSEVECTOR_H
36 #define vpPOSEVECTOR_H
37 
46 class vpRotationMatrix;
49 class vpThetaUVector;
50 class vpRowVector;
51 
52 #include <visp3/core/vpArray2D.h>
53 #include <visp3/core/vpHomogeneousMatrix.h>
54 #include <visp3/core/vpMatrix.h>
55 #include <visp3/core/vpRotationMatrix.h>
56 
57 #ifdef VISP_HAVE_NLOHMANN_JSON
58 #include <nlohmann/json.hpp>
59 #endif
60 
188 class VISP_EXPORT vpPoseVector : public vpArray2D<double>
189 {
190 public:
191  // constructor
192  vpPoseVector();
193  // constructor from 3 angles (in radian)
194  vpPoseVector(double tx, double ty, double tz, double tux, double tuy, double tuz);
195  // constructor convert an homogeneous matrix in a pose
196  explicit vpPoseVector(const vpHomogeneousMatrix &M);
197  // constructor convert a translation and a "thetau" vector into a pose
198  vpPoseVector(const vpTranslationVector &tv, const vpThetaUVector &tu);
199  // constructor convert a translation and a rotation matrix into a pose
201 
202  vpPoseVector buildFrom(double tx, double ty, double tz, double tux, double tuy, double tuz);
203  // convert an homogeneous matrix in a pose
204  vpPoseVector buildFrom(const vpHomogeneousMatrix &M);
205  // convert a translation and a "thetau" vector into a pose
206  vpPoseVector buildFrom(const vpTranslationVector &tv, const vpThetaUVector &tu);
207  // convert a translation and a rotation matrix into a pose
208  vpPoseVector buildFrom(const vpTranslationVector &tv, const vpRotationMatrix &R);
209 
210  void extract(vpRotationMatrix &R) const;
211  void extract(vpThetaUVector &tu) const;
212  void extract(vpTranslationVector &tv) const;
213  void extract(vpQuaternionVector &q) const;
214 
215  vpRotationMatrix getRotationMatrix() const;
216  vpThetaUVector getThetaUVector() const;
217  vpTranslationVector getTranslationVector() const;
218 
219  // Load an homogeneous matrix from a file
220  void load(std::ifstream &f);
221 
246  inline double &operator[](unsigned int i) { return *(data + i); }
265  inline const double &operator[](unsigned int i) const { return *(data + i); }
266 
267  // Print a vector [T thetaU] thetaU in degree
268  void print() const;
269  int print(std::ostream &s, unsigned int length, char const *intro = 0) const;
270 
276  void resize(unsigned int nrows, unsigned int ncols, bool flagNullify = true)
277  {
278  (void)nrows;
279  (void)ncols;
280  (void)flagNullify;
281  throw(vpException(vpException::fatalError, "Cannot resize a pose vector"));
282  }
283 
284  // Save an homogeneous matrix in a file
285  void save(std::ofstream &f) const;
286  void set(double tx, double ty, double tz, double tux, double tuy, double tuz);
287  vpRowVector t() const;
288 
289  std::vector<double> toStdVector() const;
290 
291 #ifdef VISP_HAVE_NLOHMANN_JSON
292 public:
293  static const std::string jsonTypeName;
294 private:
295  friend void to_json(nlohmann::json &j, const vpPoseVector &cam);
296  friend void from_json(const nlohmann::json &j, vpPoseVector &cam);
297  // Conversion helper function to avoid circular dependencies and MSVC errors that are not exported in the DLL
298  void parse_json(const nlohmann::json &j);
299  void convert_to_json(nlohmann::json &j) const;
300 public:
301 #endif
302 
303 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
312  vp_deprecated void init() { };
314 #endif
315 };
316 
317 #ifdef VISP_HAVE_NLOHMANN_JSON
318 #include <nlohmann/json.hpp>
319 inline void to_json(nlohmann::json &j, const vpPoseVector &r)
320 {
321  r.convert_to_json(j);
322 }
323 inline void from_json(const nlohmann::json &j, vpPoseVector &r)
324 {
325  r.parse_json(j);
326 }
327 #endif
328 
329 #endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition: vpArray2D.h:125
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:600
vpArray2D< Type > t() const
Compute the transpose of the array.
Definition: vpArray2D.h:1079
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:802
friend void from_json(const nlohmann::json &j, vpArray2D< T > &array)
error that can be emitted by ViSP classes.
Definition: vpException.h:59
@ fatalError
Fatal error.
Definition: vpException.h:84
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:189
vp_deprecated void init()
Definition: vpPoseVector.h:312
const double & operator[](unsigned int i) const
Definition: vpPoseVector.h:265
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true)
Definition: vpPoseVector.h:276
double & operator[](unsigned int i)
Definition: vpPoseVector.h:246
static const std::string jsonTypeName
Definition: vpPoseVector.h:293
Implementation of a rotation vector as quaternion angle minimal representation.
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:107
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.