Visual Servoing Platform  version 3.4.0
vpColVector.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 
130 class VISP_EXPORT vpColVector : public vpArray2D<double>
131 {
132  friend class vpMatrix;
133 
134 public:
136  vpColVector() : vpArray2D<double>() {}
140  explicit vpColVector(unsigned int n) : vpArray2D<double>(n, 1) {}
142  vpColVector(unsigned int n, double val) : vpArray2D<double>(n, 1, val) {}
145  vpColVector(const vpColVector &v) : vpArray2D<double>(v) {}
146  vpColVector(const vpColVector &v, unsigned int r, unsigned int nrows);
149  vpColVector(const vpRotationVector &v);
151  vpColVector(const vpPoseVector &p);
155  vpColVector(const vpMatrix &M);
156  vpColVector(const vpMatrix &M, unsigned int j);
157  vpColVector(const std::vector<double> &v);
158  vpColVector(const std::vector<float> &v);
159 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
161  vpColVector(const std::initializer_list<double> &list)
162  : vpArray2D<double>(static_cast<unsigned int>(list.size()), 1) {
163  std::copy(list.begin(), list.end(), data);
164  }
165 #endif
166 
169  virtual ~vpColVector() {}
170 
175  void clear()
176  {
177  if (data != NULL) {
178  free(data);
179  data = NULL;
180  }
181 
182  if (rowPtrs != NULL) {
183  free(rowPtrs);
184  rowPtrs = NULL;
185  }
186  rowNum = colNum = dsize = 0;
187  }
188 
189  std::ostream &cppPrint(std::ostream &os, const std::string &matrixName = "A", bool octet = false) const;
190  std::ostream &csvPrint(std::ostream &os) const;
191 
196  inline void deg2rad()
197  {
198  double d2r = M_PI / 180.0;
199 
200  (*this) *= d2r;
201  }
202 
203  vp_deprecated double euclideanNorm() const;
220  vpColVector extract(unsigned int r, unsigned int colsize) const
221  {
222  if (r >= rowNum || r + colsize > rowNum) {
224  "Cannot extract a (%dx1) column vector from a (%dx1) "
225  "column vector starting at index %d",
226  colsize, rowNum, r));
227  }
228 
229  return vpColVector(*this, r, colsize);
230  }
231 
232  double frobeniusNorm() const;
233  vpColVector hadamard(const vpColVector &v) const;
234 
235  double infinityNorm() const;
236  void init(const vpColVector &v, unsigned int r, unsigned int nrows);
237  void insert(unsigned int i, const vpColVector &v);
238  void insert(const vpColVector &v, unsigned int i);
239 
240  std::ostream &maplePrint(std::ostream &os) const;
241  std::ostream &matlabPrint(std::ostream &os) const;
242 
243  vpColVector &normalize();
244  vpColVector &normalize(vpColVector &x) const;
245 
247  inline double &operator[](unsigned int n) { return *(data + n); }
249  inline const double &operator[](unsigned int n) const { return *(data + n); }
251  vpColVector &operator=(const vpColVector &v);
255  vpColVector &operator=(const vpMatrix &M);
256  vpColVector &operator=(const std::vector<double> &v);
257  vpColVector &operator=(const std::vector<float> &v);
258  vpColVector &operator=(double x);
259 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
261  vpColVector &operator=(const std::initializer_list<double> &list);
262 #endif
263  bool operator==(const vpColVector &v) const;
265  bool operator!=(const vpColVector &v) const;
266 
267  double operator*(const vpColVector &x) const;
268  vpMatrix operator*(const vpRowVector &v) const;
269  vpColVector operator*(double x) const;
270  vpColVector &operator*=(double x);
271 
272  vpColVector operator/(double x) const;
273  vpColVector &operator/=(double x);
274 
275  vpColVector operator+(const vpColVector &v) const;
278 
279  vpColVector operator-(const vpColVector &v) const;
281  vpColVector operator-() const;
282 
284  vpColVector &operator<<(double *);
285  vpColVector& operator<<(double val);
286  vpColVector& operator,(double val);
287 
288  int print(std::ostream &s, unsigned int length, char const *intro = 0) const;
289 
294  inline void rad2deg()
295  {
296  double r2d = 180.0 / M_PI;
297 
298  (*this) *= r2d;
299  }
300 
301  void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols);
302  vpMatrix reshape(unsigned int nrows, unsigned int ncols);
303 
310  void resize(unsigned int i, bool flagNullify = true) { vpArray2D<double>::resize(i, 1, flagNullify); }
321  void resize(unsigned int nrows, unsigned int ncols, bool flagNullify)
322  {
323  if (ncols != 1) {
325  "Cannot resize a column vector to a (%dx%d) "
326  "dimension vector that has more than one column",
327  nrows, ncols));
328  }
329  vpArray2D<double>::resize(nrows, ncols, flagNullify);
330  }
331 
332  void stack(double d);
333  void stack(const vpColVector &v);
334 
335  double sum() const;
336  double sumSquare() const;
337  vpRowVector t() const;
338  std::vector<double> toStdVector();
339  vpRowVector transpose() const;
340  void transpose(vpRowVector &v) const;
341 
351  inline static vpColVector cross(const vpColVector &a, const vpColVector &b) { return crossProd(a, b); }
352  static vpColVector crossProd(const vpColVector &a, const vpColVector &b);
353 
354  static double dotProd(const vpColVector &a, const vpColVector &b);
355  static vpColVector invSort(const vpColVector &v);
356  static double median(const vpColVector &v);
357  static double mean(const vpColVector &v);
358  // Compute the skew matrix [v]x
359  static vpMatrix skew(const vpColVector &v);
360 
361  static vpColVector sort(const vpColVector &v);
362 
363  static vpColVector stack(const vpColVector &A, const vpColVector &B);
364  static void stack(const vpColVector &A, const vpColVector &B, vpColVector &C);
365 
366  static double stdev(const vpColVector &v, bool useBesselCorrection = false);
367 
368 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
369 
377  vp_deprecated void init() {}
381  vp_deprecated vpColVector rows(unsigned int first_row, unsigned int last_row) const
382  {
383  return vpColVector(*this, first_row - 1, last_row - first_row + 1);
384  }
388  vp_deprecated void setIdentity(const double &val = 1.0);
392  vp_deprecated void stackMatrices(const vpColVector &r) { stack(r); }
397  vp_deprecated static vpColVector stackMatrices(const vpColVector &A, const vpColVector &B) { return stack(A, B); }
402  vp_deprecated static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C)
403  {
404  stack(A, B, C);
405  }
406 
407  vp_deprecated void insert(const vpColVector &v, unsigned int r, unsigned int c = 0);
409 #endif
410 };
411 
412 #ifndef DOXYGEN_SHOULD_SKIP_THIS
413 VISP_EXPORT
414 #endif
415 vpColVector operator*(const double &x, const vpColVector &v);
416 
417 #endif
std::ostream & csvPrint(std::ostream &os) const
Definition: vpMatrix.cpp:5806
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:153
Implementation of a generic rotation vector.
vpColVector extract(unsigned int r, unsigned int colsize) const
Definition: vpColVector.h:220
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify)
Definition: vpColVector.h:321
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition: vpArray2D.h:304
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:413
double infinityNorm() const
Definition: vpMatrix.cpp:6764
vpColVector(const std::initializer_list< double > &list)
Definition: vpColVector.h:161
vp_deprecated void init()
Definition: vpColVector.h:377
double euclideanNorm() const
Definition: vpMatrix.cpp:6900
static vpColVector cross(const vpColVector &a, const vpColVector &b)
Definition: vpColVector.h:351
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:115
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
Definition: vpMatrix.cpp:5855
void stack(const vpMatrix &A)
Definition: vpMatrix.cpp:5879
vpMatrix & operator/=(double x)
Divide all the element of the matrix by x : Aij = Aij / x.
Definition: vpMatrix.cpp:1689
error that can be emited by ViSP classes.
Definition: vpException.h:71
bool operator==(const vpArray2D< Type > &A) const
Definition: vpArray2D.h:948
vpMatrix operator/(double x) const
Cij = Aij / x (A is unchanged)
Definition: vpMatrix.cpp:1629
double & operator[](unsigned int n)
Operator that allows to set a value of an element : v[i] = x.
Definition: vpColVector.h:247
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:145
Implementation of a generic 2D array used as base class for matrices and vectors. ...
Definition: vpArray2D.h:131
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:291
vpMatrix & operator+=(const vpMatrix &B)
Operation A = A + B.
Definition: vpMatrix.cpp:1499
static vp_deprecated void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C)
Definition: vpColVector.h:402
double sumSquare() const
Definition: vpMatrix.cpp:6785
std::ostream & maplePrint(std::ostream &os) const
Definition: vpMatrix.cpp:5765
vpMatrix & operator-=(const vpMatrix &B)
Operation A = A - B.
Definition: vpMatrix.cpp:1516
void deg2rad()
Definition: vpColVector.h:196
vpMatrix & operator*=(double x)
Multiply all the element of the matrix by x : Aij = Aij * x.
Definition: vpMatrix.cpp:1675
vpColVector(unsigned int n, double val)
Construct a column vector of size n. Each element is set to val.
Definition: vpColVector.h:142
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:135
int print(std::ostream &s, unsigned int length, const std::string &intro="") const
Definition: vpMatrix.cpp:5598
double frobeniusNorm() const
Definition: vpMatrix.cpp:6704
vp_deprecated void setIdentity(const double &val=1.0)
Definition: vpMatrix.cpp:6978
vpColVector(unsigned int n)
Definition: vpColVector.h:140
vp_deprecated void init()
Definition: vpMatrix.h:781
void clear()
Definition: vpColVector.h:175
virtual ~vpColVector()
Definition: vpColVector.h:169
vp_deprecated void stackMatrices(const vpColVector &r)
Definition: vpColVector.h:392
vpMatrix operator+(const vpMatrix &B) const
Definition: vpMatrix.cpp:1410
vpMatrix transpose() const
Definition: vpMatrix.cpp:474
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:493
unsigned int colNum
Number of columns in the array.
Definition: vpArray2D.h:137
bool operator!=(const vpArray2D< Type > &A) const
Definition: vpArray2D.h:996
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition: vpArray2D.h:932
const double & operator[](unsigned int n) const
Operator that allows to get the value of an element : x = v[i].
Definition: vpColVector.h:249
vp_deprecated vpColVector rows(unsigned int first_row, unsigned int last_row) const
Definition: vpColVector.h:381
void resize(unsigned int i, bool flagNullify=true)
Definition: vpColVector.h:310
vpMatrix t() const
Definition: vpMatrix.cpp:464
double sum() const
Definition: vpMatrix.cpp:1565
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
std::ostream & matlabPrint(std::ostream &os) const
Definition: vpMatrix.cpp:5721
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:151
vpMatrix operator*(const vpMatrix &B) const
Definition: vpMatrix.cpp:1168
vpColVector()
Basic constructor that creates an empty 0-size column vector.
Definition: vpColVector.h:136
static vp_deprecated vpColVector stackMatrices(const vpColVector &A, const vpColVector &B)
Definition: vpColVector.h:397
vpMatrix operator-() const
Definition: vpMatrix.cpp:1558
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:141
void insert(const vpMatrix &A, unsigned int r, unsigned int c)
Definition: vpMatrix.cpp:5988
vpMatrix & operator,(double val)
Definition: vpMatrix.cpp:805
void reshape(unsigned int nrows, unsigned int ncols)
Definition: vpArray2D.h:379
Class that consider the case of a translation vector.
void rad2deg()
Definition: vpColVector.h:294
double ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:139
vpColVector(const vpColVector &v)
Definition: vpColVector.h:145