77
88namespace feh {
99
10- template <typename T >
10+ template <typename Type >
1111class SO3Type {
1212public:
13- using BaseType = Eigen::Matrix<T , 3 , 3 >;
14- using PointType = Eigen::Matrix<T , 3 , 1 >;
13+ using BaseType = Eigen::Matrix<Type , 3 , 3 >;
14+ using PointType = Eigen::Matrix<Type , 3 , 1 >;
1515 using AxisType = PointType;
1616
1717 SO3Type () : R_ {BaseType::Identity ()} {}
1818
19- SO3Type (const BaseType &R) : R_ {R} {}
19+ SO3Type (const Eigen::Matrix<Type, 3 , 3 > &R): R_ {R} {}
2020
21- SO3Type (const AxisType &axis, T angle) :
21+ SO3Type (const AxisType &axis, Type angle) :
2222 R_ {rodrigues (AxisType{axis / axis.norm () * angle})} {}
2323
2424 SO3Type operator *(const SO3Type &other) {
@@ -54,6 +54,19 @@ class SO3Type {
5454 return BaseType{svd.matrixU () * BaseType::Identity () * svd.matrixV ().transpose ()};
5555 }
5656
57+ template <typename TT >
58+ SO3Type<TT > cast () const {
59+ return R_ .template cast <TT >();
60+ }
61+
62+ // factory methods
63+ template <typename Derived>
64+ static SO3Type from_matrix (const Eigen::MatrixBase<Derived> &other) {
65+ EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE (Derived, 3 , 3 );
66+ Eigen::Matrix<Type, 3 , 3 > R = other.template cast <Type>();
67+ return R;
68+ }
69+
5770private:
5871 BaseType R_ ;
5972};
@@ -65,6 +78,12 @@ class SE3Type {
6578
6679 SE3Type () : R_ {}, T_ {0 , 0 , 0 } {}
6780
81+ /*
82+ SE3Type(const Eigen::Matrix<Type, 3, 4> &RT):
83+ R_{RT.template block<3, 3>(0, 0)},
84+ T_{RT.template block<3, 1>(0, 3)} {}
85+ */
86+
6887 SE3Type (const Eigen::Matrix<Type, 4 , 4 > &RT ):
6988 R_ {RT .template block <3 , 3 >(0 , 0 )},
7089 T_ {RT .template block <3 , 1 >(0 , 3 )} {}
@@ -111,6 +130,31 @@ class SE3Type {
111130 return out;
112131 };
113132
133+ template <typename TT >
134+ SE3Type<TT > cast () {
135+ return SE3Type<TT >(R_ .cast <TT >(), T_ .cast <TT >());
136+ }
137+
138+ // factory methods
139+ template <typename Derived>
140+ static SE3Type from_matrix3x4 (const Eigen::MatrixBase<Derived> &other) {
141+ EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE (Derived, 3 , 4 );
142+ Eigen::Matrix<Type, 3 , 3 > R = other.template block <3 , 3 >(0 , 0 ).template cast <Type>();
143+ Eigen::Matrix<Type, 3 , 1 > T = other.template block <3 , 1 >(0 , 3 ).template cast <Type>();
144+ return {R, T};
145+ }
146+
147+ template <typename Derived1, typename Derived2>
148+ static SE3Type from_RT (const Eigen::MatrixBase<Derived1> &Rin,
149+ const Eigen::MatrixBase<Derived2> &Tin) {
150+ EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE (Derived1, 3 , 3 );
151+ EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE (Derived2, 3 , 1 );
152+
153+ Eigen::Matrix<Type, 3 , 3 > R = Rin.template cast <Type>();
154+ Eigen::Matrix<Type, 3 , 1 > T = Tin.template cast <Type>();
155+ return {R, T};
156+ }
157+
114158private:
115159 SO3Type<Type> R_ ;
116160 Eigen::Matrix<Type, 3 , 1 > T_ ;
0 commit comments