ViSP  2.6.2
vpColVector.h
1 /****************************************************************************
2  *
3  * $Id: vpColVector.h 3694 2012-05-03 07:18:31Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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 vpColVector &B);
137  static vpColVector stack(const vpColVector &A, const vpColVector &B);
138  static void stack(const vpColVector &A, const vpColVector &B, vpColVector &C);
139 
141  vpRowVector t() const;
142 
144  vpColVector &normalize() ;
146  // vpColVector &normalize(vpColVector &x) const ;
147 
149  static vpColVector crossProd(const vpColVector &a, const vpColVector &b) ;
150 
151  // compute the cross product of two vectors C = a x b
152  inline static vpColVector cross(const vpColVector &a, const vpColVector &b){
153  return crossProd(a,b);}
154 
155  // compute the skew matrix [v]x
156  static vpMatrix skew(const vpColVector &v);
158 
159  static double dotProd(const vpColVector &a, const vpColVector &b) ;
160 
162  static vpColVector sort(const vpColVector &v) ;
164  static vpColVector invSort(const vpColVector &v) ;
166  static double median(const vpColVector &v) ;
168  static double mean(const vpColVector &v) ;
169 
176  inline void rad2deg() {
177  double rad2deg = 180.0/M_PI;
178 
179  for (unsigned int i=0; i < rowNum; i++)
180  (*this)[i] *= rad2deg;
181  }
186  inline void deg2rad() {
187  double deg2rad = M_PI/180.0;
188 
189  for (unsigned int i=0; i < rowNum; i++)
190  (*this)[i] *= deg2rad;
191  }
192 
198  inline unsigned int size() const
199  {
200  return getRows();
201  }
202 
203 };
204 
205 
206 #endif
207 
208 
209 /*
210  * Local variables:
211  * c-basic-offset: 2
212  * End:
213  */
friend VISP_EXPORT std::ostream & operator<<(std::ostream &s, const vpMatrix &m)
std::cout a matrix
Definition: vpMatrix.cpp:2574
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:152
Definition of the row vector class.
Definition: vpRowVector.h:73
void skew(const vpTranslationVector &t, vpMatrix &M)
void deg2rad()
Definition: vpColVector.h:186
unsigned int size() const
Definition: vpColVector.h:198
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:314
vpMatrix operator+(const vpMatrix &B) const
Definition: vpMatrix.cpp:542
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:1174
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:247
vpMatrix operator*(const vpMatrix &B) const
Definition: vpMatrix.cpp:434
vpColVector()
basic constructor
Definition: vpColVector.h:82
vpMatrix operator-() const
Definition: vpMatrix.cpp:749
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:157
void rad2deg()
Definition: vpColVector.h:176
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:94