Visual Servoing Platform  version 3.1.0
vpColVector.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Provide some simple operation on column vectors.
33  *
34  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
39 #ifndef vpColVector_H
40 #define vpColVector_H
41 
42 #include <visp3/core/vpArray2D.h>
43 #include <visp3/core/vpMath.h>
44 #include <visp3/core/vpPoseVector.h>
45 #include <visp3/core/vpRotationVector.h>
46 #include <visp3/core/vpRowVector.h>
47 
48 class vpMatrix;
49 class vpRowVector;
50 class vpRotationVector;
52 class vpPoseVector;
53 
72 class VISP_EXPORT vpColVector : public vpArray2D<double>
73 {
74  friend class vpMatrix;
75 
76 public:
78  vpColVector() : vpArray2D<double>() {}
82  explicit vpColVector(unsigned int n) : vpArray2D<double>(n, 1) {}
84  vpColVector(unsigned int n, double val) : vpArray2D<double>(n, 1, val) {}
87  vpColVector(const vpColVector &v) : vpArray2D<double>(v) {}
88  vpColVector(const vpColVector &v, unsigned int r, unsigned int nrows);
91  vpColVector(const vpRotationVector &v);
93  vpColVector(const vpPoseVector &p);
97  vpColVector(const vpMatrix &M);
98  vpColVector(const vpMatrix &M, unsigned int j);
99  vpColVector(const std::vector<double> &v);
100  vpColVector(const std::vector<float> &v);
101 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
103 #endif
104 
107  virtual ~vpColVector() {}
108 
113  void clear()
114  {
115  if (data != NULL) {
116  free(data);
117  data = NULL;
118  }
119 
120  if (rowPtrs != NULL) {
121  free(rowPtrs);
122  rowPtrs = NULL;
123  }
124  rowNum = colNum = dsize = 0;
125  }
126 
127  std::ostream &cppPrint(std::ostream &os, const std::string &matrixName = "A", bool octet = false) const;
128  std::ostream &csvPrint(std::ostream &os) const;
129 
134  inline void deg2rad()
135  {
136  double d2r = M_PI / 180.0;
137 
138  (*this) *= d2r;
139  }
140 
141  double euclideanNorm() const;
158  vpColVector extract(unsigned int r, unsigned int colsize) const
159  {
160  if (r >= rowNum || r + colsize > rowNum) {
162  "Cannot extract a (%dx1) column vector from a (%dx1) "
163  "column vector starting at index %d",
164  colsize, rowNum, r));
165  }
166 
167  return vpColVector(*this, r, colsize);
168  }
169 
170  vpColVector hadamard(const vpColVector &v) const;
171 
172  double infinityNorm() const;
173  void init(const vpColVector &v, unsigned int r, unsigned int nrows);
174  void insert(unsigned int i, const vpColVector &v);
175  void insert(const vpColVector &v, unsigned int i);
176 
177  std::ostream &maplePrint(std::ostream &os) const;
178  std::ostream &matlabPrint(std::ostream &os) const;
179 
180  vpColVector &normalize();
181  vpColVector &normalize(vpColVector &x) const;
182 
184  inline double &operator[](unsigned int n) { return *(data + n); }
186  inline const double &operator[](unsigned int n) const { return *(data + n); }
188  vpColVector &operator=(const vpColVector &v);
192  vpColVector &operator=(const vpMatrix &M);
193  vpColVector &operator=(const std::vector<double> &v);
194  vpColVector &operator=(const std::vector<float> &v);
195  vpColVector &operator=(double x);
196 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
198 #endif
199 
200  double operator*(const vpColVector &x) const;
201  vpMatrix operator*(const vpRowVector &v) const;
202  vpColVector operator*(const double x) const;
203  vpColVector &operator*=(double x);
204 
205  vpColVector operator/(const double x) const;
206  vpColVector &operator/=(double x);
207 
208  vpColVector operator+(const vpColVector &v) const;
211 
212  vpColVector operator-(const vpColVector &v) const;
214  vpColVector operator-() const;
215 
217  vpColVector &operator<<(double *);
218 
219  int print(std::ostream &s, unsigned int length, char const *intro = 0) const;
220 
225  inline void rad2deg()
226  {
227  double r2d = 180.0 / M_PI;
228 
229  (*this) *= r2d;
230  }
231 
232  void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols);
233  vpMatrix reshape(const unsigned int &nrows, const unsigned int &ncols);
234 
241  void resize(const unsigned int i, const bool flagNullify = true) { vpArray2D<double>::resize(i, 1, flagNullify); }
252  void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify)
253  {
254  if (ncols != 1)
256  "Cannot resize a column vector to a (%dx%d) "
257  "dimension vector that has more than one column",
258  nrows, ncols));
259  vpArray2D<double>::resize(nrows, ncols, flagNullify);
260  }
261 
262  void stack(const double &d);
263  void stack(const vpColVector &v);
264 
265  double sum() const;
266  double sumSquare() const;
267  vpRowVector t() const;
268  vpRowVector transpose() const;
269  void transpose(vpRowVector &v) const;
270 
280  inline static vpColVector cross(const vpColVector &a, const vpColVector &b) { return crossProd(a, b); }
281  static vpColVector crossProd(const vpColVector &a, const vpColVector &b);
282 
283  static double dotProd(const vpColVector &a, const vpColVector &b);
284  static vpColVector invSort(const vpColVector &v);
285  static double median(const vpColVector &v);
286  static double mean(const vpColVector &v);
287  // Compute the skew matrix [v]x
288  static vpMatrix skew(const vpColVector &v);
289 
290  static vpColVector sort(const vpColVector &v);
291 
292  static vpColVector stack(const vpColVector &A, const vpColVector &B);
293  static void stack(const vpColVector &A, const vpColVector &B, vpColVector &C);
294 
295  static double stdev(const vpColVector &v, const bool useBesselCorrection = false);
296 
297 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
298 
306  vp_deprecated void init() {}
310  vp_deprecated vpColVector rows(unsigned int first_row, unsigned int last_row) const
311  {
312  return vpColVector(*this, first_row - 1, last_row - first_row + 1);
313  }
317  vp_deprecated void setIdentity(const double &val = 1.0);
321  vp_deprecated void stackMatrices(const vpColVector &r) { stack(r); }
326  vp_deprecated static vpColVector stackMatrices(const vpColVector &A, const vpColVector &B) { return stack(A, B); }
331  vp_deprecated static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C)
332  {
333  stack(A, B, C);
334  }
335 
336  vp_deprecated void insert(const vpColVector &v, const unsigned int r, const unsigned int c = 0);
338 #endif
339 };
340 
341 #ifndef DOXYGEN_SHOULD_SKIP_THIS
342 VISP_EXPORT
343 #endif
344 vpColVector operator*(const double &x, const vpColVector &v);
345 
346 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
double euclideanNorm() const
Definition: vpMatrix.cpp:5038
Implementation of a generic rotation vector.
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:244
vp_deprecated void init()
Definition: vpColVector.h:306
static vpColVector cross(const vpColVector &a, const vpColVector &b)
Definition: vpColVector.h:280
vpMatrix operator-() const
Definition: vpMatrix.cpp:1318
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:72
std::ostream & csvPrint(std::ostream &os) const
Definition: vpMatrix.cpp:4374
double sum() const
Definition: vpMatrix.cpp:1325
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true, const bool recopy_=true)
Definition: vpArray2D.h:171
vpMatrix & operator*=(const double x)
Multiply all the element of the matrix by x : Aij = Aij * x.
Definition: vpMatrix.cpp:1423
void stack(const vpMatrix &A)
Definition: vpMatrix.cpp:4447
vpColVector extract(unsigned int r, unsigned int colsize) const
Definition: vpColVector.h:158
vpMatrix & operator/=(double x)
Divide all the element of the matrix by x : Aij = Aij / x.
Definition: vpMatrix.cpp:1433
error that can be emited by ViSP classes.
Definition: vpException.h:71
double & operator[](unsigned int n)
Operator that allows to set a value of an element : v[i] = x.
Definition: vpColVector.h:184
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:84
Implementation of a generic 2D array used as vase class of matrices and vectors.
Definition: vpArray2D.h:70
vpMatrix & operator+=(const vpMatrix &B)
Operation A = A + B.
Definition: vpMatrix.cpp:1259
static vp_deprecated void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C)
Definition: vpColVector.h:331
double infinityNorm() const
Definition: vpMatrix.cpp:5059
vpMatrix & operator-=(const vpMatrix &B)
Operation A = A - B.
Definition: vpMatrix.cpp:1276
void deg2rad()
Definition: vpColVector.h:134
vpMatrix operator+(const vpMatrix &B) const
Definition: vpMatrix.cpp:1170
std::ostream & maplePrint(std::ostream &os) const
Definition: vpMatrix.cpp:4333
vpColVector(unsigned int n, double val)
Construct a column vector of size n. Each element is set to val.
Definition: vpColVector.h:84
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:74
double sumSquare() const
Definition: vpMatrix.cpp:5080
vpMatrix t() const
Definition: vpMatrix.cpp:375
void insert(const vpMatrix &A, const unsigned int r, const unsigned int c)
Definition: vpMatrix.cpp:4512
vp_deprecated void setIdentity(const double &val=1.0)
Definition: vpMatrix.cpp:5147
vpColVector(unsigned int n)
Definition: vpColVector.h:82
std::ostream & matlabPrint(std::ostream &os) const
Definition: vpMatrix.cpp:4289
vp_deprecated void init()
Definition: vpMatrix.h:673
void clear()
Definition: vpColVector.h:113
virtual ~vpColVector()
Definition: vpColVector.h:107
vp_deprecated void stackMatrices(const vpColVector &r)
Definition: vpColVector.h:321
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
Definition: vpMatrix.cpp:4423
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition: vpArray2D.h:690
const double & operator[](unsigned int n) const
Operator that allows to get the value of an element : x = v[i].
Definition: vpColVector.h:186
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:273
vpMatrix transpose() const
Definition: vpMatrix.cpp:394
unsigned int colNum
Number of columns in the array.
Definition: vpArray2D.h:76
vpMatrix operator/(const double x) const
Cij = Aij / x (A is unchanged)
Definition: vpMatrix.cpp:1379
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify)
Definition: vpColVector.h:252
vpMatrix operator*(const vpMatrix &B) const
Definition: vpMatrix.cpp:940
int print(std::ostream &s, unsigned int length, char const *intro=0) const
Definition: vpMatrix.cpp:4166
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:92
vpColVector()
Basic constructor that creates an empty 0-size column vector.
Definition: vpColVector.h:78
static vp_deprecated vpColVector stackMatrices(const vpColVector &A, const vpColVector &B)
Definition: vpColVector.h:326
vp_deprecated vpColVector rows(unsigned int first_row, unsigned int last_row) const
Definition: vpColVector.h:310
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:80
Class that consider the case of a translation vector.
void rad2deg()
Definition: vpColVector.h:225
double ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:78
vpColVector(const vpColVector &v)
Definition: vpColVector.h:87
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:241