Visual Servoing Platform  version 3.6.1 under development (2024-12-17)
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 
52 BEGIN_VISP_NAMESPACE
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  vpPoseVector &buildFrom(const double &tx, const double &ty, const double &tz, const double &tux, const double &tuy, const double &tuz);
219  // convert an homogeneous matrix in a pose
220  vpPoseVector &buildFrom(const vpHomogeneousMatrix &M);
221  // convert a translation and a "thetau" vector into a pose
222  vpPoseVector &buildFrom(const vpTranslationVector &tv, const vpThetaUVector &tu);
223  // convert a translation and a rotation matrix into a pose
224  vpPoseVector &buildFrom(const vpTranslationVector &tv, const vpRotationMatrix &R);
225 
226  void extract(vpRotationMatrix &R) const;
227  void extract(vpThetaUVector &tu) const;
228  void extract(vpTranslationVector &tv) const;
229  void extract(vpQuaternionVector &q) const;
230 
231  vpRotationMatrix getRotationMatrix() const;
232  vpThetaUVector getThetaUVector() const;
233  vpTranslationVector getTranslationVector() const;
234 
235  // Load an homogeneous matrix from a file
236  void load(std::ifstream &f);
237 
262  inline double &operator[](unsigned int i) { return *(data + i); }
281  inline const double &operator[](unsigned int i) const { return *(data + i); }
282 
283  // Print a vector [T thetaU] thetaU in degree
284  void print() const;
285  int print(std::ostream &s, unsigned int length, char const *intro = 0) const;
286 
292  void resize(unsigned int nrows, unsigned int ncols, bool flagNullify = true)
293  {
294  (void)nrows;
295  (void)ncols;
296  (void)flagNullify;
297  throw(vpException(vpException::fatalError, "Cannot resize a pose vector"));
298  }
299 
300  // Save an homogeneous matrix in a file
301  void save(std::ofstream &f) const;
302  void set(double tx, double ty, double tz, double tux, double tuy, double tuz);
303  vpRowVector t() const;
304 
305  std::vector<double> toStdVector() const;
306 
307 #ifdef VISP_HAVE_NLOHMANN_JSON
308 public:
309  static const std::string jsonTypeName;
310 private:
311  friend void to_json(nlohmann::json &j, const vpPoseVector &cam);
312  friend void from_json(const nlohmann::json &j, vpPoseVector &cam);
313  // Conversion helper function to avoid circular dependencies and MSVC errors that are not exported in the DLL
314  void parse_json(const nlohmann::json &j);
315  void convert_to_json(nlohmann::json &j) const;
316 public:
317 #endif
318 
319 private:
320  static const unsigned int constr_value_6;
321 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
330  VP_DEPRECATED void init() { };
332 #endif
333 };
334 
335 #ifdef VISP_HAVE_NLOHMANN_JSON
336 #include VISP_NLOHMANN_JSON(json.hpp)
337 inline void to_json(nlohmann::json &j, const vpPoseVector &r)
338 {
339  r.convert_to_json(j);
340 }
341 
342 inline void from_json(const nlohmann::json &j, vpPoseVector &r)
343 {
344  r.parse_json(j);
345 }
346 #endif
347 END_VISP_NAMESPACE
348 #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:669
vpArray2D< Type > t() const
Compute the transpose of the array.
Definition: vpArray2D.h:1166
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:874
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
const double & operator[](unsigned int i) const
Definition: vpPoseVector.h:281
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true)
Definition: vpPoseVector.h:292
double & operator[](unsigned int i)
Definition: vpPoseVector.h:262
static const std::string jsonTypeName
Definition: vpPoseVector.h:309
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.