Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpTranslationVector.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  * Translation vector.
32  */
33 
39 #ifndef VP_TRANSLATION_VECTOR_H
40 #define VP_TRANSLATION_VECTOR_H
41 
42 #include <visp3/core/vpConfig.h>
43 #include <visp3/core/vpArray2D.h>
44 #include <visp3/core/vpHomogeneousMatrix.h>
45 #include <visp3/core/vpPoseVector.h>
46 
48 class vpMatrix;
49 
118 class VISP_EXPORT vpTranslationVector : public vpArray2D<double>
119 {
120 public:
125  vpTranslationVector() : vpArray2D<double>(3, 1), m_index(0) { }
126  vpTranslationVector(double tx, double ty, double tz);
128  VP_EXPLICIT vpTranslationVector(const vpHomogeneousMatrix &M);
129  VP_EXPLICIT vpTranslationVector(const vpPoseVector &p);
130  VP_EXPLICIT vpTranslationVector(const vpColVector &v);
131 
132 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
133  VP_DEPRECATED vpTranslationVector buildFrom(double tx, double ty, double tz);
134  VP_DEPRECATED vpTranslationVector buildFrom(const vpHomogeneousMatrix &M);
135  VP_DEPRECATED vpTranslationVector buildFrom(const vpPoseVector &p);
136  VP_DEPRECATED vpTranslationVector buildFrom(const vpColVector &v);
137 #endif
138  vpTranslationVector &build(const double &tx, const double &ty, const double &tz);
139  vpTranslationVector &build(const vpHomogeneousMatrix &M);
140  vpTranslationVector &build(const vpPoseVector &p);
141  vpTranslationVector &build(const vpColVector &v);
142 
143  double frobeniusNorm() const;
144 
145  // operators
146 
147  // translation vectors additions c = a + b (a, b unchanged)
148  vpTranslationVector operator+(const vpTranslationVector &tv) const;
149  vpTranslationVector operator+(const vpColVector &v) const;
150  // translation vectors subtraction c = a - b (a, b unchanged)
151  vpTranslationVector operator-(const vpTranslationVector &tv) const;
152  // negate t = -a (t is unchanged)
153  vpTranslationVector operator-() const;
154  vpMatrix operator*(const vpRowVector &v) const;
155  // b = x * a (x=scalar)
156  vpTranslationVector operator*(double x) const;
157  vpTranslationVector &operator*=(double x);
158  vpTranslationVector operator/(double x) const;
159  vpTranslationVector &operator/=(double x);
160  // Copy operator. Allow operation such as A = v
163  vpTranslationVector &operator=(double x);
164 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
165  vpTranslationVector &operator=(const std::initializer_list<double> &list);
166 #endif
167 
169  inline double &operator[](unsigned int n) { return *(data + n); }
171  inline const double &operator[](unsigned int n) const { return *(data + n); }
172 
173  vpTranslationVector &operator<<(double val);
174  vpTranslationVector &operator,(double val);
175 
181  void resize(unsigned int nrows, unsigned int ncols, bool flagNullify = true)
182  {
183  (void)nrows;
184  (void)ncols;
185  (void)flagNullify;
186  throw(vpException(vpException::fatalError, "Cannot resize a translation vector"));
187  }
188 
189  void set(double tx, double ty, double tz);
190 
191  // Skew Symmetric matrix
192  vpMatrix skew() const;
193 
194  double sumSquare() const;
195 
196  vpRowVector t() const;
197 
198  static vpTranslationVector cross(const vpTranslationVector &a, const vpTranslationVector &b);
199  static vpTranslationVector mean(const std::vector<vpHomogeneousMatrix> &vec_M);
200  static vpTranslationVector mean(const std::vector<vpTranslationVector> &vec_t);
201  static vpMatrix skew(const vpTranslationVector &tv);
202  static void skew(const vpTranslationVector &tv, vpMatrix &M);
203 
204 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
209  VP_DEPRECATED double euclideanNorm() const;
210  //}
211 #endif
212 
213 protected:
214  unsigned int m_index; // index used for operator<< and operator, to fill a vector
215 };
216 END_VISP_NAMESPACE
217 #endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition: vpArray2D.h:145
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:611
vpArray2D< Type > t() const
Compute the transpose of the array.
Definition: vpArray2D.h:1163
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:523
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
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 matrix and operations on matrices.
Definition: vpMatrix.h:169
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:203
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:124
Class that consider the case of a translation vector.
double & operator[](unsigned int n)
Operator that allows to set a value of an element : t[i] = x.
const double & operator[](unsigned int n) const
Operator that allows to get the value of an element : x = t[i].
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true)
vpMatrix operator*(const double &x, const vpMatrix &A)