Visual Servoing Platform  version 3.0.0
vpColVector.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 
124  inline void deg2rad() {
125  double d2r = M_PI/180.0;
126 
127  (*this) *= d2r;
128  }
129 
130  double euclideanNorm() const;
146  vpColVector extract(unsigned int r, unsigned int colsize) const
147  {
148  if (r >= rowNum || r+colsize > rowNum) {
150  "Cannot extract a (%dx1) column vector from a (%dx1) column vector starting at index %d",
151  colsize, rowNum, r));
152  }
153 
154  return vpColVector(*this, r, colsize);
155  }
156 
157  double infinityNorm() const;
158  void init(const vpColVector &v, unsigned int r, unsigned int nrows);
159  void insert(unsigned int i, const vpColVector &v);
160 
161  vpColVector &normalize() ;
162  vpColVector &normalize(vpColVector &x) const ;
163 
165  inline double &operator[](unsigned int n) { return *(data + n); }
167  inline const double &operator[](unsigned int n) const { return *(data+n); }
169  vpColVector &operator=(const vpColVector &v);
173  vpColVector &operator=(const vpMatrix &M);
174  vpColVector &operator=(const std::vector<double> &v);
175  vpColVector &operator=(const std::vector<float> &v);
176  vpColVector &operator=(double x);
177 
178  double operator*(const vpColVector &x) const;
179  vpMatrix operator*(const vpRowVector &v) const;
180  vpColVector operator*(const double x) const;
181  vpColVector &operator*=(double x);
182 
183  vpColVector operator/(const double x) const;
184  vpColVector &operator/=(double x);
185 
186  vpColVector operator+(const vpColVector &v) const;
188 
189  vpColVector operator-(const vpColVector &v) const;
191  vpColVector operator-() const;
192 
194  vpColVector &operator<<(double *);
195 
196  int print(std::ostream& s, unsigned int length, char const* intro=0) const;
197 
202  inline void rad2deg() {
203  double r2d = 180.0/M_PI;
204 
205  (*this) *= r2d;
206  }
207 
208  void reshape(vpMatrix & M, const unsigned int &nrows, const unsigned int &ncols);
209  vpMatrix reshape(const unsigned int &nrows, const unsigned int &ncols);
210 
217  void resize(const unsigned int i, const bool flagNullify = true)
218  {
219  vpArray2D<double>::resize(i, 1, flagNullify);
220  }
231  void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify)
232  {
233  if (ncols != 1)
235  "Cannot resize a column vector to a (%dx%d) dimension vector that has more than one column",
236  nrows, ncols));
237  vpArray2D<double>::resize(nrows, ncols, flagNullify);
238  };
239 
240  void stack(const double &d);
241  void stack(const vpColVector &v);
242 
243  double sumSquare() const;
244  vpRowVector t() const;
245  vpRowVector transpose() const;
246  void transpose(vpRowVector &v) const;
247 
257  inline static vpColVector cross(const vpColVector &a, const vpColVector &b)
258  {
259  return crossProd(a,b);
260  }
261  static vpColVector crossProd(const vpColVector &a, const vpColVector &b) ;
262 
263  static double dotProd(const vpColVector &a, const vpColVector &b) ;
264  static vpColVector invSort(const vpColVector &v) ;
265  static double median(const vpColVector &v) ;
266  static double mean(const vpColVector &v) ;
267  // Compute the skew matrix [v]x
268  static vpMatrix skew(const vpColVector &v);
269 
270  static vpColVector sort(const vpColVector &v) ;
271 
272  static vpColVector stack(const vpColVector &A, const vpColVector &B);
273  static void stack(const vpColVector &A, const vpColVector &B, vpColVector &C);
274 
275  static double stdev(const vpColVector &v, const bool useBesselCorrection=false);
276 
277 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
278 
286  vp_deprecated void init() {};
290  vp_deprecated vpColVector rows(unsigned int first_row, unsigned int last_row) const
291  {
292  return vpColVector(*this, first_row-1, last_row-first_row+1);
293  }
297  vp_deprecated void setIdentity(const double & val=1.0) ;
301  vp_deprecated void stackMatrices(const vpColVector &r) { stack(r); };
305  vp_deprecated static vpColVector stackMatrices(const vpColVector &A, const vpColVector &B) { return stack(A, B); };
309  vp_deprecated static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C) { stack(A, B, C); };
310 
312 #endif
313 };
314 
315 #ifndef DOXYGEN_SHOULD_SKIP_THIS
316 VISP_EXPORT
317 #endif
318 vpColVector operator*(const double &x, const vpColVector &v) ;
319 
320 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:92
Implementation of a generic rotation vector.
vpColVector extract(unsigned int r, unsigned int colsize) const
Definition: vpColVector.h:146
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:239
double infinityNorm() const
Definition: vpMatrix.cpp:3518
vp_deprecated void init()
Definition: vpColVector.h:286
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:257
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:70
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:1281
void stack(const vpMatrix &A)
Definition: vpMatrix.cpp:2922
vpMatrix & operator/=(double x)
Divide all the element of the matrix by x : Aij = Aij / x.
Definition: vpMatrix.cpp:1291
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:165
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:1096
static vp_deprecated void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C)
Definition: vpColVector.h:309
double sumSquare() const
Definition: vpMatrix.cpp:3539
vpMatrix & operator-=(const vpMatrix &B)
Operation A = A - B.
Definition: vpMatrix.cpp:1114
void deg2rad()
Definition: vpColVector.h:124
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:2952
vp_deprecated void setIdentity(const double &val=1.0)
Definition: vpMatrix.cpp:209
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:582
void clear()
Definition: vpColVector.h:106
virtual ~vpColVector()
Definition: vpColVector.h:100
vp_deprecated void stackMatrices(const vpColVector &r)
Definition: vpColVector.h:301
vpMatrix operator+(const vpMatrix &B) const
Definition: vpMatrix.cpp:998
vpMatrix transpose() const
Definition: vpMatrix.cpp:247
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:231
int print(std::ostream &s, unsigned int length, char const *intro=0) const
Definition: vpMatrix.cpp:2649
const double & operator[](unsigned int n) const
Operator that allows to get the value of an element : x = v[i].
Definition: vpColVector.h:167
vp_deprecated vpColVector rows(unsigned int first_row, unsigned int last_row) const
Definition: vpColVector.h:290
vpMatrix t() const
Definition: vpMatrix.cpp:221
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
double euclideanNorm() const
Definition: vpMatrix.cpp:3497
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:1230
vpMatrix operator*(const vpMatrix &B) const
Definition: vpMatrix.cpp:790
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:305
vpMatrix operator-() const
Definition: vpMatrix.cpp:1161
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:202
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:217