Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Provide some simple operation on column vectors.
32  *
33  * Authors:
34  * Eric Marchand
35  *
36  *****************************************************************************/
37 
38 
39 
40 #ifndef vpColVector_H
41 #define vpColVector_H
42 
43 #include <visp3/core/vpArray2D.h>
44 #include <visp3/core/vpRowVector.h>
45 #include <visp3/core/vpMath.h>
46 #include <visp3/core/vpRotationVector.h>
47 #include <visp3/core/vpPoseVector.h>
48 
49 class vpMatrix;
50 class vpRowVector;
51 class vpRotationVector;
53 class vpPoseVector;
54 
72 class VISP_EXPORT vpColVector : public vpArray2D<double>
73 {
74  friend class vpMatrix;
75 public:
76 
78  vpColVector() : vpArray2D<double>() {}
80  vpColVector(unsigned int n) : vpArray2D<double>(n,1){}
82  vpColVector(unsigned int n, double val) : vpArray2D<double>(n, 1, val){}
84  vpColVector(const vpColVector &v) : vpArray2D<double>(v) {}
85  vpColVector(const vpColVector &v, unsigned int r, unsigned int nrows) ;
88  vpColVector(const vpRotationVector &v);
90  vpColVector(const vpPoseVector &p);
93  vpColVector(const vpMatrix &M);
94  vpColVector(const vpMatrix &M, unsigned int j);
95  vpColVector(const std::vector<double> &v);
96  vpColVector(const std::vector<float> &v);
100  virtual ~vpColVector() {}
101 
106  void clear()
107  {
108  if (data != NULL ) {
109  free(data);
110  data=NULL;
111  }
112 
113  if (rowPtrs!=NULL) {
114  free(rowPtrs);
115  rowPtrs=NULL ;
116  }
117  rowNum = colNum = dsize = 0;
118  }
119 
120  std::ostream & cppPrint(std::ostream & os, const std::string &matrixName="A", bool octet = false) const;
121  std::ostream & csvPrint(std::ostream & os) const;
122 
127  inline void deg2rad() {
128  double d2r = M_PI/180.0;
129 
130  (*this) *= d2r;
131  }
132 
133  double euclideanNorm() const;
149  vpColVector extract(unsigned int r, unsigned int colsize) const
150  {
151  if (r >= rowNum || r+colsize > rowNum) {
153  "Cannot extract a (%dx1) column vector from a (%dx1) column vector starting at index %d",
154  colsize, rowNum, r));
155  }
156 
157  return vpColVector(*this, r, colsize);
158  }
159 
160  double infinityNorm() const;
161  void init(const vpColVector &v, unsigned int r, unsigned int nrows);
162  void insert(unsigned int i, const vpColVector &v);
163  void insert(const vpColVector &v, unsigned int i);
164 
165  std::ostream & maplePrint(std::ostream & os) const;
166  std::ostream & matlabPrint(std::ostream & os) const;
167 
168  vpColVector &normalize() ;
169  vpColVector &normalize(vpColVector &x) const ;
170 
172  inline double &operator[](unsigned int n) { return *(data + n); }
174  inline const double &operator[](unsigned int n) const { return *(data+n); }
176  vpColVector &operator=(const vpColVector &v);
180  vpColVector &operator=(const vpMatrix &M);
181  vpColVector &operator=(const std::vector<double> &v);
182  vpColVector &operator=(const std::vector<float> &v);
183  vpColVector &operator=(double x);
184 
185  double operator*(const vpColVector &x) const;
186  vpMatrix operator*(const vpRowVector &v) const;
187  vpColVector operator*(const double x) const;
188  vpColVector &operator*=(double x);
189 
190  vpColVector operator/(const double x) const;
191  vpColVector &operator/=(double x);
192 
193  vpColVector operator+(const vpColVector &v) const;
196 
197  vpColVector operator-(const vpColVector &v) const;
199  vpColVector operator-() const;
200 
202  vpColVector &operator<<(double *);
203 
204  int print(std::ostream& s, unsigned int length, char const* intro=0) const;
205 
210  inline void rad2deg() {
211  double r2d = 180.0/M_PI;
212 
213  (*this) *= r2d;
214  }
215 
216  void reshape(vpMatrix & M, const unsigned int &nrows, const unsigned int &ncols);
217  vpMatrix reshape(const unsigned int &nrows, const unsigned int &ncols);
218 
225  void resize(const unsigned int i, const bool flagNullify = true)
226  {
227  vpArray2D<double>::resize(i, 1, flagNullify);
228  }
239  void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify)
240  {
241  if (ncols != 1)
243  "Cannot resize a column vector to a (%dx%d) dimension vector that has more than one column",
244  nrows, ncols));
245  vpArray2D<double>::resize(nrows, ncols, flagNullify);
246  }
247 
248  void stack(const double &d);
249  void stack(const vpColVector &v);
250 
251  double sum() const;
252  double sumSquare() const;
253  vpRowVector t() const;
254  vpRowVector transpose() const;
255  void transpose(vpRowVector &v) const;
256 
266  inline static vpColVector cross(const vpColVector &a, const vpColVector &b)
267  {
268  return crossProd(a,b);
269  }
270  static vpColVector crossProd(const vpColVector &a, const vpColVector &b) ;
271 
272  static double dotProd(const vpColVector &a, const vpColVector &b) ;
273  static vpColVector invSort(const vpColVector &v) ;
274  static double median(const vpColVector &v) ;
275  static double mean(const vpColVector &v) ;
276  // Compute the skew matrix [v]x
277  static vpMatrix skew(const vpColVector &v);
278 
279  static vpColVector sort(const vpColVector &v) ;
280 
281  static vpColVector stack(const vpColVector &A, const vpColVector &B);
282  static void stack(const vpColVector &A, const vpColVector &B, vpColVector &C);
283 
284  static double stdev(const vpColVector &v, const bool useBesselCorrection=false);
285 
286 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
287 
295  vp_deprecated void init() {}
299  vp_deprecated vpColVector rows(unsigned int first_row, unsigned int last_row) const
300  {
301  return vpColVector(*this, first_row-1, last_row-first_row+1);
302  }
306  vp_deprecated void setIdentity(const double & val=1.0) ;
310  vp_deprecated void stackMatrices(const vpColVector &r) { stack(r); }
314  vp_deprecated static vpColVector stackMatrices(const vpColVector &A, const vpColVector &B) { return stack(A, B); }
318  vp_deprecated static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C) { stack(A, B, C); }
319 
320  vp_deprecated void insert(const vpColVector &v, const unsigned int r, const unsigned int c=0);
322 #endif
323 };
324 
325 #ifndef DOXYGEN_SHOULD_SKIP_THIS
326 VISP_EXPORT
327 #endif
328 vpColVector operator*(const double &x, const vpColVector &v) ;
329 
330 #endif
std::ostream & csvPrint(std::ostream &os) const
Definition: vpMatrix.cpp:2838
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
Implementation of a generic rotation vector.
vpColVector extract(unsigned int r, unsigned int colsize) const
Definition: vpColVector.h:149
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:239
double infinityNorm() const
Definition: vpMatrix.cpp:3573
vp_deprecated void init()
Definition: vpColVector.h:295
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Definition: vpArray2D.h:167
static vpColVector cross(const vpColVector &a, const vpColVector &b)
Definition: vpColVector.h:266
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:70
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
Definition: vpMatrix.cpp:2888
vpColVector operator*(const double &x, const vpColVector &v)
vpMatrix & operator*=(const double x)
Multiply all the element of the matrix by x : Aij = Aij * x.
Definition: vpMatrix.cpp:1266
void stack(const vpMatrix &A)
Definition: vpMatrix.cpp:2981
vpMatrix & operator/=(double x)
Divide all the element of the matrix by x : Aij = Aij / x.
Definition: vpMatrix.cpp:1276
error that can be emited by ViSP classes.
Definition: vpException.h:73
double & operator[](unsigned int n)
Operator that allows to set a value of an element : v[i] = x.
Definition: vpColVector.h:172
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:1081
static vp_deprecated void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C)
Definition: vpColVector.h:318
double sumSquare() const
Definition: vpMatrix.cpp:3593
std::ostream & maplePrint(std::ostream &os) const
Definition: vpMatrix.cpp:2797
vpMatrix & operator-=(const vpMatrix &B)
Operation A = A - B.
Definition: vpMatrix.cpp:1099
void deg2rad()
Definition: vpColVector.h:127
vpColVector(unsigned int n, double val)
Construct a column vector of size n. Each element is set to val.
Definition: vpColVector.h:82
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:74
void insert(const vpMatrix &A, const unsigned int r, const unsigned int c)
Definition: vpMatrix.cpp:3011
vp_deprecated void setIdentity(const double &val=1.0)
Definition: vpMatrix.cpp:3667
vpColVector(unsigned int n)
Construct a column vector of size n. All the elements are initialized to zero.
Definition: vpColVector.h:80
vp_deprecated void init()
Definition: vpMatrix.h:587
void clear()
Definition: vpColVector.h:106
virtual ~vpColVector()
Definition: vpColVector.h:100
vp_deprecated void stackMatrices(const vpColVector &r)
Definition: vpColVector.h:310
vpMatrix operator+(const vpMatrix &B) const
Definition: vpMatrix.cpp:983
vpMatrix transpose() const
Definition: vpMatrix.cpp:233
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:267
unsigned int colNum
Number of columns in the array.
Definition: vpArray2D.h:76
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify)
Definition: vpColVector.h:239
int print(std::ostream &s, unsigned int length, char const *intro=0) const
Definition: vpMatrix.cpp:2634
const double & operator[](unsigned int n) const
Operator that allows to get the value of an element : x = v[i].
Definition: vpColVector.h:174
vp_deprecated vpColVector rows(unsigned int first_row, unsigned int last_row) const
Definition: vpColVector.h:299
vpMatrix t() const
Definition: vpMatrix.cpp:207
double sum() const
Definition: vpMatrix.cpp:1155
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
double euclideanNorm() const
Definition: vpMatrix.cpp:3552
std::ostream & matlabPrint(std::ostream &os) const
Definition: vpMatrix.cpp:2756
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:93
vpMatrix operator/(const double x) const
Cij = Aij / x (A is unchanged)
Definition: vpMatrix.cpp:1215
vpMatrix operator*(const vpMatrix &B) const
Definition: vpMatrix.cpp:775
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:314
vpMatrix operator-() const
Definition: vpMatrix.cpp:1146
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:210
double ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:78
vpColVector(const vpColVector &v)
Copy constructor that allows to construct a column vector from an other one.
Definition: vpColVector.h:84
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:225