Visual Servoing Platform  version 3.4.0
vpRotationVector.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Generic rotation vector (cannot be used as is !).
33  *
34  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
39 #include <algorithm>
40 #include <math.h>
41 
42 #include <visp3/core/vpColVector.h>
43 #include <visp3/core/vpRotationVector.h>
44 #include <visp3/core/vpRowVector.h>
45 
57 {
58  vpRowVector v(dsize);
59 
60  for (unsigned int i = 0; i < dsize; i++)
61  v[i] = data[i];
62 
63  return v;
64 }
65 
70 std::vector<double> vpRotationVector::toStdVector()
71 {
72  std::vector<double> v(this->size());
73 
74  for (unsigned int i = 0; i < this->size(); i++)
75  v[i] = data[i];
76  return v;
77 }
78 
90 {
91  vpColVector v(dsize);
92 
93  for (unsigned int i = 0; i < dsize; i++)
94  v[i] = (*this)[i] * x;
95  return v;
96 }
97 
102 vpColVector operator*(const double &x, const vpRotationVector &v)
103 {
104  vpColVector vout;
105  vout = v * x;
106  return vout;
107 }
108 
133 {
134  m_index = 0;
135  data[m_index] = val;
136  return *this;
137 }
138 
163 {
164  m_index ++;
165  if (m_index >= size()) {
166  throw(vpException(vpException::dimensionError, "Cannot set rotation vector out of bounds. It has only %d elements while you try to initialize with %d elements", size(), m_index+1));
167  }
168  data[m_index] = val;
169  return *this;
170 }
171 
179 {
180  double sum_square = 0.0;
181 
182  for (unsigned int i = 0; i < rowNum; i++) {
183  double x = rowPtrs[i][0];
184  sum_square += x * x;
185  }
186 
187  return sum_square;
188 }
Implementation of a generic rotation vector.
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:115
vpRowVector t() const
error that can be emited by ViSP classes.
Definition: vpException.h:71
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:145
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:291
vpRotationVector & operator,(double val)
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:135
vpRotationVector & operator<<(double val)
std::vector< double > toStdVector()
unsigned int m_index
vpColVector operator*(double x) const
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
double sumSquare() const
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:141
vpColVector operator*(const double &x, const vpRotationVector &v)
double ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:139