Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpRowVector.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  * 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 
109  std::ostream & cppPrint(std::ostream & os, const std::string &matrixName="A", bool octet = false) const;
110  std::ostream & csvPrint(std::ostream & os) const;
111 
116  inline void deg2rad() {
117  double d2r = M_PI/180.0;
118 
119  (*this) *= d2r;
120  }
121 
122  double euclideanNorm() const;
138  vpRowVector extract(unsigned int c, unsigned int rowsize) const
139  {
140  if (c >= colNum || c+rowsize > colNum) {
142  "Cannot extract a (1x%d) row vector from a (1x%d) row vector starting at index %d",
143  rowsize, colNum, c));
144  }
145 
146  return vpRowVector(*this, c, rowsize);
147  }
148 
149  void init(const vpRowVector &v, unsigned int c, unsigned int ncols);
150  void insert(unsigned int i, const vpRowVector &v);
151 
152  std::ostream & maplePrint(std::ostream & os) const;
153  std::ostream & matlabPrint(std::ostream & os) const;
154 
155  vpRowVector &normalize() ;
156  vpRowVector &normalize(vpRowVector &x) const ;
157 
159  inline double &operator[](unsigned int n) { return *(data+n); }
161  inline const double &operator[](unsigned int n) const { return *(data+n) ; }
162 
164  vpRowVector &operator=(const vpRowVector &v);
165  vpRowVector &operator=(const vpMatrix &M);
166  vpRowVector &operator=(const std::vector<double> &v);
167  vpRowVector &operator=(const std::vector<float> &v);
168  vpRowVector &operator=(const double x);
169 
170  double operator*(const vpColVector &x) const;
171  vpRowVector operator*(const vpMatrix &M) const;
172  vpRowVector operator*(const double x) const;
173  vpRowVector &operator*=(double x);
174 
175  vpRowVector operator/(const double x) const;
176  vpRowVector &operator/=(double x);
177 
178  vpRowVector operator+(const vpRowVector &v) const;
179  vpRowVector &operator+=(vpRowVector v);
180 
181  vpRowVector operator-(const vpRowVector &v) const;
182  vpRowVector &operator-=(vpRowVector v);
183  vpRowVector operator-() const;
184 
186 
187  int print(std::ostream& s, unsigned int length, char const* intro=0) const;
192  inline void rad2deg() {
193  double r2d = 180.0/M_PI;
194 
195  (*this) *= r2d;
196  }
197  void reshape(vpMatrix & M,const unsigned int &nrows,const unsigned int &ncols);
198  vpMatrix reshape(const unsigned int &nrows,const unsigned int &ncols);
199 
205  inline void resize(const unsigned int i, const bool flagNullify = true)
206  {
207  vpArray2D<double>::resize(1, i, flagNullify);
208  }
209 
220  void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify)
221  {
222  if (nrows != 1)
224  "Cannot resize a row vector to a (%dx%d) dimension vector that has more than one row",
225  nrows, ncols));
226  vpArray2D<double>::resize(nrows, ncols, flagNullify);
227  };
228 
229  void stack(const double &d);
230  void stack(const vpRowVector &v);
231 
232  double sum() const;
233  double sumSquare() const;
234  vpColVector t() const;
235  vpColVector transpose() const;
236  void transpose(vpColVector &v) const;
237 
238  static double mean(const vpRowVector &v) ;
239  static double median(const vpRowVector &v) ;
240  static vpRowVector stack(const vpRowVector &A, const vpRowVector &B);
241  static void stack(const vpRowVector &A, const vpRowVector &B, vpRowVector &C);
242  static double stdev(const vpRowVector &v, const bool useBesselCorrection=false);
243 
244 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
245 
253  vp_deprecated void init() {};
257  vp_deprecated void stackMatrices(const vpRowVector &r) { stack(r); };
261  vp_deprecated static vpRowVector stackMatrices(const vpRowVector &A, const vpRowVector &B) { return stack(A, B); };
265  vp_deprecated static void stackMatrices(const vpRowVector &A, const vpRowVector &B, vpRowVector &C) { stack(A, B, C); };
266 
270  vp_deprecated void setIdentity(const double & val=1.0) ;
272 #endif
273 
274 };
275 
276 VISP_EXPORT vpRowVector operator*(const double &x, const vpRowVector &v) ;
277 
278 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
const double & operator[](unsigned int n) const
Operator that allows to get the value of an element : x = v[i].
Definition: vpRowVector.h:161
static vp_deprecated vpRowVector stackMatrices(const vpRowVector &A, const vpRowVector &B)
Definition: vpRowVector.h:261
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:265
vp_deprecated void stackMatrices(const vpRowVector &r)
Definition: vpRowVector.h:257
error that can be emited by ViSP classes.
Definition: vpException.h:73
vpRowVector extract(unsigned int c, unsigned int rowsize) const
Definition: vpRowVector.h:138
vp_deprecated void init()
Definition: vpRowVector.h:253
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:220
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:159
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:205
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:116
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:192