Visual Servoing Platform  version 3.6.1 under development (2024-07-18)
vpPoseVector.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  * 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 
43 #ifndef VP_POSE_VECTOR_H
44 #define VP_POSE_VECTOR_H
45 
46 #include <visp3/core/vpConfig.h>
47 #include <visp3/core/vpArray2D.h>
48 #include <visp3/core/vpHomogeneousMatrix.h>
49 #include <visp3/core/vpMatrix.h>
50 #include <visp3/core/vpRotationMatrix.h>
51 
53 class vpRotationMatrix;
56 class vpThetaUVector;
57 class vpRowVector;
58 
202 class VISP_EXPORT vpPoseVector : public vpArray2D<double>
203 {
204 public:
205  // constructor
206  vpPoseVector();
207  // constructor from 3 angles (in radian)
208  vpPoseVector(double tx, double ty, double tz, double tux, double tuy, double tuz);
209  // constructor convert an homogeneous matrix in a pose
210  VP_EXPLICIT vpPoseVector(const vpHomogeneousMatrix &M);
211  // constructor convert a translation and a "thetau" vector into a pose
212  vpPoseVector(const vpTranslationVector &tv, const vpThetaUVector &tu);
213  // constructor convert a translation and a rotation matrix into a pose
215 
216  virtual ~vpPoseVector() { }
217 
218 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
219  VP_DEPRECATED vpPoseVector buildFrom(double tx, double ty, double tz, double tux, double tuy, double tuz);
220  // convert an homogeneous matrix in a pose
221  VP_DEPRECATED vpPoseVector buildFrom(const vpHomogeneousMatrix &M);
222  // convert a translation and a "thetau" vector into a pose
223  VP_DEPRECATED vpPoseVector buildFrom(const vpTranslationVector &tv, const vpThetaUVector &tu);
224  // convert a translation and a rotation matrix into a pose
225  VP_DEPRECATED vpPoseVector buildFrom(const vpTranslationVector &tv, const vpRotationMatrix &R);
226 #endif
227 
228  vpPoseVector &build(const double &tx, const double &ty, const double &tz, const double &tux, const double &tuy, const double &tuz);
229  // convert an homogeneous matrix in a pose
230  vpPoseVector &build(const vpHomogeneousMatrix &M);
231  // convert a translation and a "thetau" vector into a pose
232  vpPoseVector &build(const vpTranslationVector &tv, const vpThetaUVector &tu);
233  // convert a translation and a rotation matrix into a pose
234  vpPoseVector &build(const vpTranslationVector &tv, const vpRotationMatrix &R);
235 
236  void extract(vpRotationMatrix &R) const;
237  void extract(vpThetaUVector &tu) const;
238  void extract(vpTranslationVector &tv) const;
239  void extract(vpQuaternionVector &q) const;
240 
241  vpRotationMatrix getRotationMatrix() const;
242  vpThetaUVector getThetaUVector() const;
243  vpTranslationVector getTranslationVector() const;
244 
245  // Load an homogeneous matrix from a file
246  void load(std::ifstream &f);
247 
272  inline double &operator[](unsigned int i) { return *(data + i); }
291  inline const double &operator[](unsigned int i) const { return *(data + i); }
292 
293  // Print a vector [T thetaU] thetaU in degree
294  void print() const;
295  int print(std::ostream &s, unsigned int length, char const *intro = 0) const;
296 
302  void resize(unsigned int nrows, unsigned int ncols, bool flagNullify = true)
303  {
304  (void)nrows;
305  (void)ncols;
306  (void)flagNullify;
307  throw(vpException(vpException::fatalError, "Cannot resize a pose vector"));
308  }
309 
310  // Save an homogeneous matrix in a file
311  void save(std::ofstream &f) const;
312  void set(double tx, double ty, double tz, double tux, double tuy, double tuz);
313  vpRowVector t() const;
314 
315  std::vector<double> toStdVector() const;
316 
317 #ifdef VISP_HAVE_NLOHMANN_JSON
318 public:
319  static const std::string jsonTypeName;
320 private:
321  friend void to_json(nlohmann::json &j, const vpPoseVector &cam);
322  friend void from_json(const nlohmann::json &j, vpPoseVector &cam);
323  // Conversion helper function to avoid circular dependencies and MSVC errors that are not exported in the DLL
324  void parse_json(const nlohmann::json &j);
325  void convert_to_json(nlohmann::json &j) const;
326 public:
327 #endif
328 
329 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
338  VP_DEPRECATED void init() { };
340 #endif
341 };
342 
343 #ifdef VISP_HAVE_NLOHMANN_JSON
344 #include <nlohmann/json.hpp>
345 inline void to_json(nlohmann::json &j, const vpPoseVector &r)
346 {
347  r.convert_to_json(j);
348 }
349 
350 inline void from_json(const nlohmann::json &j, vpPoseVector &r)
351 {
352  r.parse_json(j);
353 }
354 #endif
355 END_VISP_NAMESPACE
356 #endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition: vpArray2D.h:145
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:666
vpArray2D< Type > t() const
Compute the transpose of the array.
Definition: vpArray2D.h:1163
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:871
friend void from_json(const nlohmann::json &j, vpArray2D< T > &array)
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.
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:203
VP_DEPRECATED void init()
Definition: vpPoseVector.h:338
const double & operator[](unsigned int i) const
Definition: vpPoseVector.h:291
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true)
Definition: vpPoseVector.h:302
double & operator[](unsigned int i)
Definition: vpPoseVector.h:272
static const std::string jsonTypeName
Definition: vpPoseVector.h:319
virtual ~vpPoseVector()
Definition: vpPoseVector.h:216
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:124
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.