eigen.h
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <Eigen/Geometry> // for Quaternion
5
7
13
14namespace armarx
15{
16 // Helper methods for code generation to convert json/aron to bo and vice versa
17 namespace aron
18 {
19 template <class ReaderT, class EigenT, int rows, int cols, int options>
21
22 void
23 read(ReaderT& aron_r,
24 typename ReaderT::InputType& input,
26 {
27 std::string typeAsString;
28 std::vector<int> shape;
29 std::vector<unsigned char> data;
30 aron_r.readNDArray(input, shape, typeAsString, data);
31
32 std::stringstream ss;
33 ss << "Received wrong dimensions for matrix member. Dimensions are (" << shape.at(0)
34 << "," << shape.at(1) << ") but should be (" << ret.rows() << "," << ret.cols()
35 << ").";
36
38 typeAsString == TypeName<EigenT>::Get(),
40 "Received wrong typename",
41 typeAsString,
44 ret.rows() == shape.at(0) and ret.cols() == shape.at(1),
45 ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, ss.str()));
46
47 std::memcpy(reinterpret_cast<unsigned char*>(ret.data()), data.data(), data.size());
48 }
49
50 template <class ReaderT, class EigenT, int cols, int options>
51 requires data::isReader<ReaderT>
52
53 void
54 read(ReaderT& aron_r,
55 typename ReaderT::InputType& input,
57 {
58 std::string typeAsString;
59 std::vector<int> shape;
60 std::vector<unsigned char> data;
61 aron_r.readNDArray(input, shape, typeAsString, data);
62
63 ret.resize(shape.at(0));
64
66 ret.rows() == shape.at(0) and ret.cols() == shape.at(1),
68 __PRETTY_FUNCTION__, "Received wrong dimensions for member 'pose'."));
70 typeAsString == TypeName<EigenT>::Get(),
72 "Received wrong typename",
73 typeAsString,
75 std::memcpy(reinterpret_cast<unsigned char*>(ret.data()), data.data(), data.size());
76 }
77
78 template <class ReaderT, class EigenT, int rows, int options>
79 requires data::isReader<ReaderT>
80
81 void
82 read(ReaderT& aron_r,
83 typename ReaderT::InputType& input,
85 {
86 std::string typeAsString;
87 std::vector<int> shape;
88 std::vector<unsigned char> data;
89 aron_r.readNDArray(input, shape, typeAsString, data);
90
91 ret.resize(shape.at(1));
92
94 ret.rows() == shape.at(0) and ret.cols() == shape.at(1),
96 __PRETTY_FUNCTION__, "Received wrong dimensions for member 'pose'."));
98 typeAsString == TypeName<EigenT>::Get(),
100 "Received wrong typename",
101 typeAsString,
103 std::memcpy(reinterpret_cast<unsigned char*>(ret.data()), data.data(), data.size());
104 }
105
106 template <class ReaderT, class EigenT, int options>
107 requires data::isReader<ReaderT>
108
109 void
110 read(ReaderT& aron_r,
111 typename ReaderT::InputType& input,
113 {
114 std::string typeAsString;
115 std::vector<int> shape;
116 std::vector<unsigned char> data;
117 aron_r.readNDArray(input, shape, typeAsString, data);
118
119 ret.resize(shape.at(0), shape.at(1));
120
122 ret.rows() == shape.at(0) and ret.cols() == shape.at(1),
124 __PRETTY_FUNCTION__, "Received wrong dimensions for member 'pose'."));
126 typeAsString == TypeName<EigenT>::Get(),
128 "Received wrong typename",
129 typeAsString,
131 std::memcpy(reinterpret_cast<unsigned char*>(ret.data()), data.data(), data.size());
132 }
133
134 template <class WriterT, class EigenT, int rows, int cols, int options>
135 requires data::isWriter<WriterT>
136
137 void
138 write(WriterT& aron_w,
140 typename WriterT::ReturnType& ret,
141 const armarx::aron::Path& aron_p = armarx::aron::Path())
142 {
143 ret = aron_w.writeNDArray(
144 {static_cast<int>(input.rows()), static_cast<int>(input.cols()), sizeof(EigenT)},
146 reinterpret_cast<const unsigned char*>(input.data()),
147 aron_p);
148 }
149
150 template <class ReaderT, class EigenT>
151 requires data::isReader<ReaderT>
152
153 void
154 read(ReaderT& aron_r, typename ReaderT::InputType& input, Eigen::Quaternion<EigenT>& ret)
155 {
156 std::string typeAsString;
157 std::vector<int> shape;
158 std::vector<unsigned char> data;
159 aron_r.readNDArray(input, shape, typeAsString, data);
160 std::memcpy(
161 reinterpret_cast<unsigned char*>(ret.coeffs().data()), data.data(), data.size());
162 }
163
164 template <class WriterT, class EigenT>
165 requires data::isWriter<WriterT>
166
167 void
168 write(WriterT& aron_w,
169 const Eigen::Quaternion<EigenT>& input,
170 typename WriterT::ReturnType& ret,
171 const armarx::aron::Path& aron_p = armarx::aron::Path())
172 {
173 ret = aron_w.writeNDArray({1, 4, sizeof(EigenT)},
175 reinterpret_cast<const unsigned char*>(input.coeffs().data()),
176 aron_p);
177 }
178 } // namespace aron
179
180} // namespace armarx
The Path class.
Definition Path.h:36
A base class for aron exceptions.
Definition Exception.h:37
The ValueNotValidException class.
Definition Exception.h:99
#define ARMARX_CHECK_AND_THROW(expression, ExceptionType)
This macro evaluates the expression and if it turns out to be false it will throw an exception of the...
A convenience header to include all aron files (full include, not forward declared)
void read(ReaderT &aron_r, typename ReaderT::InputType &input, Eigen::Matrix< EigenT, rows, cols, options > &ret)
Definition eigen.h:23
void write(WriterT &aron_w, const Eigen::Matrix< EigenT, rows, cols, options > &input, typename WriterT::ReturnType &ret, const armarx::aron::Path &aron_p=armarx::aron::Path())
Definition eigen.h:138
This file offers overloads of toIce() and fromIce() functions for STL container types.
static const char * Get()
Definition TypeName.h:14