Visual Servoing Platform  version 3.0.0
vpRowVector.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  * Operation on row vectors.
32  *
33  * Authors:
34  * Eric Marchand
35  *
36  *****************************************************************************/
37 
38 #ifndef vpRowVector_H
39 #define vpRowVector_H
40 
41 #include <vector>
42 
43 #include <visp3/core/vpArray2D.h>
44 #include <visp3/core/vpColVector.h>
45 #include <visp3/core/vpMatrix.h>
46 #include <visp3/core/vpMath.h>
47 
48 class vpMatrix;
49 class vpColVector;
50 
70 class VISP_EXPORT vpRowVector : public vpArray2D<double>
71 {
72 public:
74  vpRowVector() : vpArray2D<double>() {};
76  vpRowVector(unsigned int n) : vpArray2D<double>(1, n){};
78  vpRowVector(unsigned int n, double val) : vpArray2D<double>(1, n, val){};
80  vpRowVector(const vpRowVector &v) : vpArray2D<double>(v) {};
81  vpRowVector(const vpRowVector &v, unsigned int c, unsigned int ncols) ;
82  vpRowVector(const vpMatrix &M);
83  vpRowVector(const vpMatrix &M, unsigned int i);
84  vpRowVector(const std::vector<double> &v);
85  vpRowVector(const std::vector<float> &v);
89  virtual ~vpRowVector() {};
90 
95  void clear()
96  {
97  if (data != NULL ) {
98  free(data);
99  data=NULL;
100  }
101 
102  if (rowPtrs!=NULL) {
103  free(rowPtrs);
104  rowPtrs=NULL ;
105  }
106  rowNum = colNum = dsize = 0;
107  }
108 
113  inline void deg2rad() {
114  double d2r = M_PI/180.0;
115 
116  (*this) *= d2r;
117  }
118 
119  double euclideanNorm() const;
135  vpRowVector extract(unsigned int c, unsigned int rowsize) const
136  {
137  if (c >= colNum || c+rowsize > colNum) {
139  "Cannot extract a (1x%d) row vector from a (1x%d) row vector starting at index %d",
140  rowsize, colNum, c));
141  }
142 
143  return vpRowVector(*this, c, rowsize);
144  }
145 
146  void init(const vpRowVector &v, unsigned int c, unsigned int ncols);
147  void insert(unsigned int i, const vpRowVector &v);
148 
149  vpRowVector &normalize() ;
150  vpRowVector &normalize(vpRowVector &x) const ;
151 
153  inline double &operator[](unsigned int n) { return *(data+n); }
155  inline const double &operator[](unsigned int n) const { return *(data+n) ; }
156 
158  vpRowVector &operator=(const vpRowVector &v);
159  vpRowVector &operator=(const vpMatrix &M);
160  vpRowVector &operator=(const std::vector<double> &v);
161  vpRowVector &operator=(const std::vector<float> &v);
162  vpRowVector &operator=(const double x);
163 
164  double operator*(const vpColVector &x) const;
165  vpRowVector operator*(const vpMatrix &M) const;
166  vpRowVector operator*(const double x) const;
167  vpRowVector &operator*=(double x);
168 
169  vpRowVector operator/(const double x) const;
170  vpRowVector &operator/=(double x);
171 
172  vpRowVector operator+(const vpRowVector &v) const;
173  vpRowVector &operator+=(vpRowVector v);
174 
175  vpRowVector operator-(const vpRowVector &v) const;
176  vpRowVector &operator-=(vpRowVector v);
177  vpRowVector operator-() const;
178 
180 
181  int print(std::ostream& s, unsigned int length, char const* intro=0) const;
186  inline void rad2deg() {
187  double r2d = 180.0/M_PI;
188 
189  (*this) *= r2d;
190  }
191  void reshape(vpMatrix & M,const unsigned int &nrows,const unsigned int &ncols);
192  vpMatrix reshape(const unsigned int &nrows,const unsigned int &ncols);
193 
199  inline void resize(const unsigned int i, const bool flagNullify = true)
200  {
201  vpArray2D<double>::resize(1, i, flagNullify);
202  }
203 
214  void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify)
215  {
216  if (nrows != 1)
218  "Cannot resize a row vector to a (%dx%d) dimension vector that has more than one row",
219  nrows, ncols));
220  vpArray2D<double>::resize(nrows, ncols, flagNullify);
221  };
222 
223  void stack(const double &d);
224  void stack(const vpRowVector &v);
225 
226  double sumSquare() const;
227  vpColVector t() const;
228  vpColVector transpose() const;
229  void transpose(vpColVector &v) const;
230 
231  static double mean(const vpRowVector &v) ;
232  static double median(const vpRowVector &v) ;
233  static vpRowVector stack(const vpRowVector &A, const vpRowVector &B);
234  static void stack(const vpRowVector &A, const vpRowVector &B, vpRowVector &C);
235  static double stdev(const vpRowVector &v, const bool useBesselCorrection=false);
236 
237 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
238 
246  vp_deprecated void init() {};
250  vp_deprecated void stackMatrices(const vpRowVector &r) { stack(r); };
254  vp_deprecated static vpRowVector stackMatrices(const vpRowVector &A, const vpRowVector &B) { return stack(A, B); };
258  vp_deprecated static void stackMatrices(const vpRowVector &A, const vpRowVector &B, vpRowVector &C) { stack(A, B, C); };
259 
263  vp_deprecated void setIdentity(const double & val=1.0) ;
265 #endif
266 
267 };
268 
269 VISP_EXPORT vpRowVector operator*(const double &x, const vpRowVector &v) ;
270 
271 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:92
const double & operator[](unsigned int n) const
Operator that allows to get the value of an element : x = v[i].
Definition: vpRowVector.h:155
static vp_deprecated vpRowVector stackMatrices(const vpRowVector &A, const vpRowVector &B)
Definition: vpRowVector.h:254
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:239
vpRowVector(const vpRowVector &v)
Copy constructor that allows to construct a row vector from an other one.
Definition: vpRowVector.h:80
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Definition: vpArray2D.h:167
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:70
vpColVector operator*(const double &x, const vpColVector &v)
static vp_deprecated void stackMatrices(const vpRowVector &A, const vpRowVector &B, vpRowVector &C)
Definition: vpRowVector.h:258
vp_deprecated void stackMatrices(const vpRowVector &r)
Definition: vpRowVector.h:250
error that can be emited by ViSP classes.
Definition: vpException.h:73
vpRowVector extract(unsigned int c, unsigned int rowsize) const
Definition: vpRowVector.h:135
vp_deprecated void init()
Definition: vpRowVector.h:246
Implementation of a generic 2D array used as vase class of matrices and vectors.
Definition: vpArray2D.h:70
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify)
Definition: vpRowVector.h:214
vpColVector operator*(const double &x, const vpColVector &v)
double & operator[](unsigned int n)
Operator that allows to set a value of an element : v[i] = x.
Definition: vpRowVector.h:153
virtual ~vpRowVector()
Definition: vpRowVector.h:89
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:267
void clear()
Definition: vpRowVector.h:95
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpRowVector.h:199
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
vpRowVector(unsigned int n, double val)
Construct a row vector of size n. Each element is set to val.
Definition: vpRowVector.h:78
void deg2rad()
Definition: vpRowVector.h:113
vpRowVector(unsigned int n)
Construct a row vector of size n. All the elements are initialized to zero.
Definition: vpRowVector.h:76
vpRowVector()
Basic constructor that creates an empty 0-size row vector.
Definition: vpRowVector.h:74
void rad2deg()
Definition: vpRowVector.h:186