amino  1.0-beta2
Lightweight Robot Utility Library
eigen_compat.hpp
1 /* -*- mode: C++; c-basic-offset: 4 -*- */
2 /* ex: set shiftwidth=4 tabstop=4 expandtab: */
3 /*
4  * Copyright (c) 2019, Colorado School of Mines
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or
8  * without modification, are permitted provided that the following
9  * conditions are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
20  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 #ifndef AA_EIGEN_COMPAT_H
35 #define AA_EIGEN_COMPAT_H
36 
37 #include <Eigen/Core>
38 #include <Eigen/Dense>
39 #include <Eigen/Geometry>
40 
41 namespace amino {
42 
44 template <typename T>
45 void conv(const aa_tf_quat *src, ::Eigen::Quaternion<T> *dst)
46 {
47  dst->x() = src->x;
48  dst->y() = src->y;
49  dst->z() = src->z;
50  dst->w() = src->w;
51 }
52 
54 template <typename T>
55 void conv(const aa_tf_vec3 *src, ::Eigen::Translation<T, 3> *dst)
56 {
57  dst->x() = src->x;
58  dst->y() = src->y;
59  dst->z() = src->z;
60 }
61 
63 template <typename T>
64 void conv(const aa_tf_vec3 *src, ::Eigen::Matrix<T, 3, 1> *dst)
65 {
66  dst->x() = src->x;
67  dst->y() = src->y;
68  dst->z() = src->z;
69 }
70 
72 template <typename T>
73 void conv(const aa_tf_rotmat *src, ::Eigen::Matrix<T, 3, 3> *dst)
74 {
75  for (int i = 0; i < 3; i++) {
76  for (int j = 0; j < 3; j++) {
77  (*dst)(i, j) = src->data[j * 3 + i];
78  }
79  }
80 }
81 
83 template <typename T>
84 void conv(const aa_tf_tfmat *src,
85  ::Eigen::Transform<T, 3, ::Eigen::Isometry> *dst)
86 {
87  for (int i = 0; i < 3; i++) {
88  for (int j = 0; j < 4; j++) {
89  (*dst)(i, j) = src->data[j * 3 + i];
90  }
91  }
92 }
93 
95 template <typename T>
96 void conv(const aa_tf_tfmat *src,
97  ::Eigen::Transform<T, 3, ::Eigen::Affine> *dst)
98 {
99  for (int i = 0; i < 3; i++) {
100  for (int j = 0; j < 4; j++) {
101  (*dst)(i, j) = src->data[j * 3 + i];
102  }
103  }
104 }
105 
107 template <typename T>
108 void conv(const aa_tf_qv *src, ::Eigen::Transform<T, 3, ::Eigen::Affine> *dst)
109 {
110  struct aa_tf_tfmat tmp;
111  aa_tf_qutr2tfmat(src->data, tmp.data);
112  ::amino::conv(&tmp, dst);
113 }
114 
116 template <typename T>
117 void conv(const aa_tf_qv *src, ::Eigen::Transform<T, 3, ::Eigen::Isometry> *dst)
118 {
119  struct aa_tf_tfmat tmp;
120  aa_tf_qutr2tfmat(src->data, tmp.data);
121  ::amino::conv(&tmp, dst);
122 }
123 
124 } // namespace amino
125 
126 #endif // AA_EIGEN_COMPAT_H
amino namespace
Definition: amino.hpp:60
void conv(const aa_tf_quat *src, ::Eigen::Quaternion< T > *dst)
Convert an amino quaternion to an Eigen quaternion.
AA_API void aa_tf_qutr2tfmat(const double e[7], double T[12])
quaternion-translation to transformation matrix
Memory layout for a quaternion, x,y,z,w order.
Definition: type.h:189
double x
x component
Definition: type.h:192
double z
z component
Definition: type.h:194
double w
w component
Definition: type.h:195
double y
y component
Definition: type.h:193
Memory layout for a Transformation as rotation quaternion and translation vector.
Definition: type.h:270
double data[7]
data array
Definition: type.h:276
Memory layout for a rotation matrix.
Definition: type.h:140
double data[9]
data array
Definition: type.h:147
Memory layout for a transformation matrix.
Definition: type.h:232
double data[12]
data array
Definition: type.h:238
Memory layout for a vector of length 3.
Definition: type.h:124
double y
y component
Definition: type.h:128
double x
x component
Definition: type.h:127
double z
z component
Definition: type.h:129