snark
eigen.h
1 // This file is part of snark, a generic and flexible library
2 // for robotics research.
3 //
4 // Copyright (C) 2011 The University of Sydney
5 //
6 // snark is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // snark is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 // for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with snark. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef SNARK_VISITING_EIGEN_H
20 #define SNARK_VISITING_EIGEN_H
21 
22 #include <Eigen/Core>
23 #include <Eigen/Geometry>
24 #include <comma/visiting/apply.h>
25 #include <comma/visiting/visit.h>
26 
27 namespace comma { namespace visiting {
28 
29 template < typename T > struct traits< ::Eigen::Matrix< T, 2, 1 > >
30 {
31  template < typename Key, class Visitor >
32  static void visit( const Key&, ::Eigen::Matrix< T, 2, 1 >& p, Visitor& v )
33  {
34  v.apply( "x", p.x() );
35  v.apply( "y", p.y() );
36  }
37 
38  template < typename Key, class Visitor >
39  static void visit( const Key&, const ::Eigen::Matrix< T, 2, 1 >& p, Visitor& v )
40  {
41  v.apply( "x", p.x() );
42  v.apply( "y", p.y() );
43  }
44 };
45 
46 template < typename T > struct traits< ::Eigen::Matrix< T, 3, 1 > >
47 {
48  template < typename Key, class Visitor >
49  static void visit( const Key&, ::Eigen::Matrix< T, 3, 1 >& p, Visitor& v )
50  {
51  v.apply( "x", p.x() );
52  v.apply( "y", p.y() );
53  v.apply( "z", p.z() );
54  }
55 
56  template < typename Key, class Visitor >
57  static void visit( const Key&, const ::Eigen::Matrix< T, 3, 1 >& p, Visitor& v )
58  {
59  v.apply( "x", p.x() );
60  v.apply( "y", p.y() );
61  v.apply( "z", p.z() );
62  }
63 };
64 
65 template < typename T > struct traits< ::Eigen::Matrix< T, 4, 1 > >
66 {
67  template < typename Key, class Visitor >
68  static void visit( const Key&, ::Eigen::Matrix< T, 4, 1 >& p, Visitor& v )
69  {
70  v.apply( "x", p.x() );
71  v.apply( "y", p.y() );
72  v.apply( "z", p.z() );
73  v.apply( "w", p.w() );
74  }
75 
76  template < typename Key, class Visitor >
77  static void visit( const Key&, const ::Eigen::Matrix< T, 4, 1 >& p, Visitor& v )
78  {
79  v.apply( "x", p.x() );
80  v.apply( "y", p.y() );
81  v.apply( "z", p.z() );
82  v.apply( "w", p.w() );
83  }
84 };
85 
86 
87 template < typename T > struct traits< ::Eigen::Quaternion< T > >
88 {
89  template < typename Key, class Visitor >
90  static void visit( const Key&, ::Eigen::Quaternion< T >& p, Visitor& v )
91  {
92  v.apply( "x", p.x() );
93  v.apply( "y", p.y() );
94  v.apply( "z", p.z() );
95  v.apply( "w", p.w() );
96  }
97 
98  template < typename Key, class Visitor >
99  static void visit( const Key&, const ::Eigen::Quaternion< T >& p, Visitor& v )
100  {
101  v.apply( "x", p.x() );
102  v.apply( "y", p.y() );
103  v.apply( "z", p.z() );
104  v.apply( "w", p.w() );
105  }
106 };
107 
108 template < typename T > struct traits< ::Eigen::Translation< T, 3 > >
109 {
110  template < typename Key, class Visitor >
111  static void visit( const Key&, ::Eigen::Translation< T, 3 >& p, Visitor& v )
112  {
113  v.apply( "x", p.vector().x() );
114  v.apply( "y", p.vector().y() );
115  v.apply( "z", p.vector().z() );
116  }
117 
118  template < typename Key, class Visitor >
119  static void visit( const Key&, const ::Eigen::Translation< T, 3 >& p, Visitor& v )
120  {
121  v.apply( "x", p.vector().x() );
122  v.apply( "y", p.vector().y() );
123  v.apply( "z", p.vector().z() );
124  }
125 };
126 
127 
128 } }
129 
130 #endif // SNARK_VISITING_EIGEN_H
131