ViSP  2.10.0
vpColVector.h
1 /****************************************************************************
2  *
3  * $Id: vpColVector.h 5185 2015-01-21 14:36:41Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Provide some simple operation on column vectors.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
42 
43 
44 #ifndef vpColVector_H
45 #define vpColVector_H
46 
47 #include <visp/vpMatrix.h>
48 #include <visp/vpRowVector.h>
49 #include <visp/vpMath.h>
50 
51 class vpMatrix;
52 class vpRotationVector;
53 
72 class VISP_EXPORT vpColVector : public vpMatrix
73 {
74  friend class vpMatrix;
75 protected:
76  vpColVector (vpMatrix &m, unsigned int j);
77  vpColVector (vpColVector &m, unsigned int r, unsigned int nrows) ;
78 
79 public:
80 
84  vpColVector(unsigned int n) : vpMatrix(n,1){};
86  vpColVector(unsigned int n, double val) : vpMatrix(n, 1, val){};
88  vpColVector (const vpColVector &v);
90  vpColVector (const vpRotationVector &v);
91 
92  void insert(unsigned int i, const vpColVector &v);
93 
98  void resize(const unsigned int i, const bool flagNullify = true)
99  {
100  vpMatrix::resize(i, 1, flagNullify);
101  }
102 
104  inline double &operator [](unsigned int n) { return *(data + n); }
106  inline const double &operator [](unsigned int n) const { return *(data+n); }
108  vpColVector &operator=(const vpColVector &v);
109  // Copy from a matrix.
110  vpColVector &operator=(const vpMatrix &m);
112  vpColVector &operator=(double x);
113  // Copy operator. Allow operation such as A << v
115  // Assigment operator. Allow operation such as A = *v
116  vpColVector &operator<<(double *);
117 
119  vpColVector operator+(const vpColVector &v) const;
121  vpColVector operator-(const vpColVector &v) const;
123  vpColVector operator-() const;
125  double operator*(const vpColVector &x) const;
127  vpMatrix operator*(const vpRowVector &x) const;
129  vpColVector operator*(const double x) const;
130 
131  vpColVector rows(unsigned int first_row, unsigned int last_row)
132  {
133  return vpColVector(*this, first_row-1, last_row-first_row+1);
134  }
135 
137  void reshape(vpMatrix & m,
138  const unsigned int &nrows, const unsigned int &ncols);
139  vpMatrix reshape(const unsigned int &nrows, const unsigned int &ncols);
140 
141  void stack(const double &b);
142  void stack(const vpColVector &B);
143  static vpColVector stack(const vpColVector &A, const vpColVector &B);
144  static void stack(const vpColVector &A, const vpColVector &B, vpColVector &C);
145 
147  vpRowVector t() const;
148 
150  vpColVector &normalize() ;
151  // normalise the vector
152  // vpColVector &normalize(vpColVector &x) const ;
153 
155  static vpColVector crossProd(const vpColVector &a, const vpColVector &b) ;
156 
157  // Compute the cross product of two vectors C = a x b
158  inline static vpColVector cross(const vpColVector &a, const vpColVector &b){
159  return crossProd(a,b);}
160 
161  // Compute the skew matrix [v]x
162  static vpMatrix skew(const vpColVector &v);
164 
165  static double dotProd(const vpColVector &a, const vpColVector &b) ;
166 
168  static vpColVector sort(const vpColVector &v) ;
170  static vpColVector invSort(const vpColVector &v) ;
172  static double median(const vpColVector &v) ;
174  static double mean(const vpColVector &v) ;
175 
182  inline void rad2deg() {
183  double r2d = 180.0/M_PI;
184 
185  for (unsigned int i=0; i < rowNum; i++)
186  (*this)[i] *= r2d;
187  }
192  inline void deg2rad() {
193  double d2r = M_PI/180.0;
194 
195  for (unsigned int i=0; i < rowNum; i++)
196  (*this)[i] *= d2r;
197  }
198 
204  inline unsigned int size() const
205  {
206  return getRows();
207  }
208 
209 };
210 
211 
212 #endif
213 
214 
215 /*
216  * Local variables:
217  * c-basic-offset: 2
218  * End:
219  */
friend VISP_EXPORT std::ostream & operator<<(std::ostream &s, const vpMatrix &m)
std::cout a matrix
Definition: vpMatrix.cpp:2894
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
Class that consider the case of a generic rotation vector (cannot be used as is !) consisting in thre...
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
Definition: vpMatrix.cpp:199
static vpColVector cross(const vpColVector &a, const vpColVector &b)
Definition: vpColVector.h:158
Definition of the row vector class.
Definition: vpRowVector.h:73
double * operator[](unsigned int i)
write elements Aij (usage : A[i][j] = x )
Definition: vpMatrix.h:220
void skew(const vpTranslationVector &t, vpMatrix &M)
void deg2rad()
Definition: vpColVector.h:192
unsigned int size() const
Definition: vpColVector.h:204
double * data
address of the first element of the data array
Definition: vpMatrix.h:118
vpColVector(unsigned int n, double val)
Constructor of vector of size n. Each element is set to val.
Definition: vpColVector.h:86
void insert(const vpMatrix &A, const unsigned int r, const unsigned int c)
Definition: vpMatrix.cpp:3291
vpColVector(unsigned int n)
Constructor of vector of size n. Each element is set to 0.
Definition: vpColVector.h:84
vpMatrix & operator=(const vpMatrix &B)
Copy operator. Allow operation such as A = B.
Definition: vpMatrix.cpp:385
vpMatrix operator+(const vpMatrix &B) const
Definition: vpMatrix.cpp:653
vpColVector rows(unsigned int first_row, unsigned int last_row)
Definition: vpColVector.h:131
unsigned int rowNum
number of rows
Definition: vpMatrix.h:112
vpMatrix t() const
Definition: vpMatrix.cpp:1296
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
vpMatrix operator*(const vpMatrix &B) const
Definition: vpMatrix.cpp:523
vpColVector()
Basic constructor.
Definition: vpColVector.h:82
vpMatrix operator-() const
Definition: vpMatrix.cpp:860
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:161
void rad2deg()
Definition: vpColVector.h:182
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:98