humoto
spatial_transform.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4  @copyright 2014-2017 INRIA. Licensed under the Apache License, Version 2.0.
5  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
6 
7  @brief
8 */
9 
10 #pragma once
11 
12 namespace humoto
13 {
14  namespace rbdl
15  {
16  /**
17  * @brief This class collects enums and methods to facilitate partial
18  * handling of spatial data, e.g., for discrimination of rotational,
19  * translational, and complete Jacobians.
20  */
22  {
23  public:
24  /**
25  * @brief Type os spatial data.
26  */
27  enum Type
28  {
29  UNDEFINED = 0,
30  COMPLETE = 1,
31  TRANSLATION = 2,
32  ROTATION = 3
33  };
34 
35 
36  /**
37  * @brief Returns number of elements (dimensionality) for given
38  * spatial data type.
39  *
40  * @param[in] spatial_type
41  *
42  * @return 3 or 6
43  */
44  static std::size_t getNumberOfElements(const Type &spatial_type)
45  {
46  switch(spatial_type)
47  {
48  case COMPLETE:
49  return(6);
50  case ROTATION:
51  case TRANSLATION:
52  return(3);
53  default:
54  HUMOTO_THROW_MSG("Unknown spatial type.");
55  }
56  }
57  };
58 
59 
60  /**
61  * @brief Efficient spatial transform with identity rotation matrix.
62  */
64  {
65  private:
66  etools::Vector3 translation_;
67 
68 
69  public:
70  /**
71  * @brief Constructor
72  *
73  * @param[in] translation translation vector
74  */
75  explicit SpatialTransformWithoutRotation(const etools::Vector3 & translation)
76  : translation_(translation)
77  {
78  }
79 
80 
81  /**
82  * @brief Apply complete transformation
83  *
84  * @tparam t_Derived Eigen template parameter
85  *
86  * @param[out] result_block 6xN result matrix (@ref eigentools_casting_hack "const is dropped inside")
87  * @param[in] matrix 6xN matrix to transform
88  */
89  template<class t_Derived>
90  void apply( Eigen::MatrixBase< t_Derived > const & result_block,
91  const Eigen::MatrixXd & matrix) const
92  {
93  for (EigenIndex i = 0; i < result_block.cols(); ++i)
94  {
95  (const_cast< Eigen::MatrixBase<t_Derived>& >(result_block)).col(i)
96  << matrix(0,i),
97  matrix(1,i),
98  matrix(2,i),
99  translation_(2) * matrix(1,i) - translation_(1) * matrix(2,i) + matrix(3,i),
100  translation_(0) * matrix(2,i) - translation_(2) * matrix(0,i) + matrix(4,i),
101  translation_(1) * matrix(0,i) - translation_(0) * matrix(1,i) + matrix(5,i);
102  }
103  }
104 
105 
106  /**
107  * @brief Apply transformation and obtain only translational
108  * part of the result
109  *
110  * @tparam t_Derived Eigen template parameter
111  *
112  * @param[out] result_block 3xN result matrix (@ref eigentools_casting_hack "const is dropped inside")
113  * @param[in] matrix 6xN matrix to transform
114  */
115  template<class t_Derived>
116  void applyGetTranslationPart(Eigen::MatrixBase< t_Derived > const & result_block,
117  const Eigen::MatrixXd & matrix) const
118  {
119  for (EigenIndex i = 0; i < result_block.cols(); ++i)
120  {
121  (const_cast< Eigen::MatrixBase<t_Derived>& >(result_block)).col(i)
122  << translation_(2) * matrix(1,i) - translation_(1) * matrix(2,i) + matrix(3,i),
123  translation_(0) * matrix(2,i) - translation_(2) * matrix(0,i) + matrix(4,i),
124  translation_(1) * matrix(0,i) - translation_(0) * matrix(1,i) + matrix(5,i);
125  }
126  }
127 
128 
129  /**
130  * @brief Apply transformation and obtain only rotational part
131  * of the result
132  *
133  * @tparam t_Derived Eigen template parameter
134  *
135  * @param[out] result_block 3xN result matrix (@ref eigentools_casting_hack "const is dropped inside")
136  * @param[in] matrix 6xN matrix to transform
137  */
138  template<class t_Derived>
139  static void applyGetRotationPart( Eigen::MatrixBase< t_Derived > const & result_block,
140  const Eigen::MatrixXd & matrix)
141  {
142  const_cast< Eigen::MatrixBase<t_Derived>& >(result_block) = matrix.topRows(3);
143  }
144 
145 
146  template<SpatialType::Type t_type, class t_Derived>
147  void applySelective(Eigen::MatrixBase< t_Derived > const & result_block,
148  const Eigen::MatrixXd & matrix) const
149  {
150  switch (t_type)
151  {
153  apply(result_block, matrix);
154  break;
155 
157  applyGetTranslationPart(result_block, matrix);
158  break;
159 
161  applyGetRotationPart(result_block, matrix);
162  break;
163 
164  default:
165  HUMOTO_THROW_MSG("Unknown SpatialType.");
166  }
167  }
168  };
169  }
170 }
static std::size_t getNumberOfElements(const Type &spatial_type)
Returns number of elements (dimensionality) for given spatial data type.
void applySelective(Eigen::MatrixBase< t_Derived > const &result_block, const Eigen::MatrixXd &matrix) const
#define HUMOTO_LOCAL
Definition: export_import.h:26
#define HUMOTO_THROW_MSG(s)
HUMOTO_THROW_MSG throws an error message concatenated with the name of the function (if supported)...
void applyGetTranslationPart(Eigen::MatrixBase< t_Derived > const &result_block, const Eigen::MatrixXd &matrix) const
Apply transformation and obtain only translational part of the result.
EIGEN_DEFAULT_DENSE_INDEX_TYPE EigenIndex
Definition: utility.h:26
void apply(Eigen::MatrixBase< t_Derived > const &result_block, const Eigen::MatrixXd &matrix) const
Apply complete transformation.
This class collects enums and methods to facilitate partial handling of spatial data, e.g., for discrimination of rotational, translational, and complete Jacobians.
The root namespace of HuMoTo.
Definition: config.h:12
static void applyGetRotationPart(Eigen::MatrixBase< t_Derived > const &result_block, const Eigen::MatrixXd &matrix)
Apply transformation and obtain only rotational part of the result.
Efficient spatial transform with identity rotation matrix.
Type
Type os spatial data.
SpatialTransformWithoutRotation(const etools::Vector3 &translation)
Constructor.