ViSP  2.8.0
vpColVector.h
1 /****************************************************************************
2  *
3  * $Id: vpColVector.h 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 nn) : vpMatrix(nn,1){};
86  vpColVector (const vpColVector &v);
88  vpColVector (const vpRotationVector &v);
89 
94  void resize(const unsigned int i, const bool flagNullify = true)
95  { vpMatrix::resize(i, 1, flagNullify); }
96 
97 
99  inline double &operator [](unsigned int n) { return *(data + n); }
101  inline const double &operator [](unsigned int n) const { return *(data+n); }
103  vpColVector &operator=(const vpColVector &v);
107  vpColVector &operator<<(double *);
109  vpColVector &operator=(const vpMatrix &m);
111  vpColVector &operator=(double x);
112 
114  vpColVector operator+(const vpColVector &v) const;
116  vpColVector operator-(const vpColVector &v) const;
118  double operator*(const vpColVector &x) const;
120  vpMatrix operator*(const vpRowVector &x) const;
122  vpColVector operator*(const double x) const;
125 
126  vpColVector rows(unsigned int first_row, unsigned int last_row)
127  {
128  return vpColVector(*this, first_row-1, last_row-first_row+1);
129  }
130 
132  void reshape(vpMatrix & m,
133  const unsigned int &nrows, const unsigned int &ncols);
134  vpMatrix reshape(const unsigned int &nrows, const unsigned int &ncols);
135 
136  void stack(const double &b);
137  void stack(const vpColVector &B);
138  static vpColVector stack(const vpColVector &A, const vpColVector &B);
139  static void stack(const vpColVector &A, const vpColVector &B, vpColVector &C);
140 
142  vpRowVector t() const;
143 
145  vpColVector &normalize() ;
147  // vpColVector &normalize(vpColVector &x) const ;
148 
150  static vpColVector crossProd(const vpColVector &a, const vpColVector &b) ;
151 
152  // compute the cross product of two vectors C = a x b
153  inline static vpColVector cross(const vpColVector &a, const vpColVector &b){
154  return crossProd(a,b);}
155 
156  // compute the skew matrix [v]x
157  static vpMatrix skew(const vpColVector &v);
159 
160  static double dotProd(const vpColVector &a, const vpColVector &b) ;
161 
163  static vpColVector sort(const vpColVector &v) ;
165  static vpColVector invSort(const vpColVector &v) ;
167  static double median(const vpColVector &v) ;
169  static double mean(const vpColVector &v) ;
170 
177  inline void rad2deg() {
178  double rad2deg = 180.0/M_PI;
179 
180  for (unsigned int i=0; i < rowNum; i++)
181  (*this)[i] *= rad2deg;
182  }
187  inline void deg2rad() {
188  double deg2rad = M_PI/180.0;
189 
190  for (unsigned int i=0; i < rowNum; i++)
191  (*this)[i] *= deg2rad;
192  }
193 
199  inline unsigned int size() const
200  {
201  return getRows();
202  }
203 
204 };
205 
206 
207 #endif
208 
209 
210 /*
211  * Local variables:
212  * c-basic-offset: 2
213  * End:
214  */
friend VISP_EXPORT std::ostream & operator<<(std::ostream &s, const vpMatrix &m)
std::cout a matrix
Definition: vpMatrix.cpp:2576
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
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:174
static vpColVector cross(const vpColVector &a, const vpColVector &b)
Definition: vpColVector.h:153
Definition of the row vector class.
Definition: vpRowVector.h:73
void skew(const vpTranslationVector &t, vpMatrix &M)
void deg2rad()
Definition: vpColVector.h:187
unsigned int size() const
Definition: vpColVector.h:199
double * data
address of the first element of the data array
Definition: vpMatrix.h:116
vpMatrix & operator=(const vpMatrix &B)
Copy operator. Allow operation such as A = B.
Definition: vpMatrix.cpp:316
vpMatrix operator+(const vpMatrix &B) const
Definition: vpMatrix.cpp:544
vpColVector(unsigned int nn)
constructor of vector of size n
Definition: vpColVector.h:84
vpColVector rows(unsigned int first_row, unsigned int last_row)
Definition: vpColVector.h:126
unsigned int rowNum
number of rows
Definition: vpMatrix.h:110
vpMatrix t() const
Definition: vpMatrix.cpp:1176
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
double * operator[](unsigned int n)
write elements Aij (usage : A[i][j] = x )
Definition: vpMatrix.h:248
vpMatrix operator*(const vpMatrix &B) const
Definition: vpMatrix.cpp:436
vpColVector()
basic constructor
Definition: vpColVector.h:82
vpMatrix operator-() const
Definition: vpMatrix.cpp:751
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:157
void rad2deg()
Definition: vpColVector.h:177
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:94