Visual Servoing Platform  version 3.6.1 under development (2024-12-03)
vpRotationVector.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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  * Generic rotation vector (cannot be used as is !).
32  *
33 *****************************************************************************/
34 
41 #include <algorithm>
42 #include <math.h>
43 
44 #include <visp3/core/vpColVector.h>
45 #include <visp3/core/vpRotationVector.h>
46 #include <visp3/core/vpRowVector.h>
47 
48 BEGIN_VISP_NAMESPACE
54 {
55  vpRowVector v(dsize);
56 
57  for (unsigned int i = 0; i < dsize; ++i) {
58  v[i] = data[i];
59  }
60 
61  return v;
62 }
63 
68 std::vector<double> vpRotationVector::toStdVector() const
69 {
70  std::vector<double> v(this->size());
71 
72  unsigned int this_size = this->size();
73  for (unsigned int i = 0; i < this_size; ++i) {
74  v[i] = data[i];
75  }
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  }
96  return v;
97 }
98 
127 {
128  m_index = 0;
129  data[m_index] = val;
130  return *this;
131 }
132 
161 {
162  ++m_index;
163  if (m_index >= size()) {
165  "Cannot set rotation vector out of bounds. It has only %d elements while you try to initialize "
166  "with %d elements",
167  size(), m_index + 1));
168  }
169  data[m_index] = val;
170  return *this;
171 }
172 
180 {
181  double sum_square = 0.0;
182 
183  for (unsigned int i = 0; i < rowNum; ++i) {
184  double x = rowPtrs[i][0];
185  sum_square += x * x;
186  }
187 
188  return sum_square;
189 }
190 
195 vpColVector operator*(const double &x, const vpRotationVector &v)
196 {
197  vpColVector vout;
198  vout = v * x;
199  return vout;
200 }
201 END_VISP_NAMESPACE
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:148
double ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:1105
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:1101
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:1107
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:349
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
error that can be emitted by ViSP classes.
Definition: vpException.h:60
@ dimensionError
Bad dimension.
Definition: vpException.h:71
Implementation of a generic rotation vector.
unsigned int m_index
double sumSquare() const
vpRotationVector & operator<<(double val)
std::vector< double > toStdVector() const
vpColVector operator*(double x) const
vpColVector operator*(const double &x, const vpRotationVector &v)
vpRotationVector & operator,(double val)
vpRowVector t() const
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:124