7 #ifndef DYNAMIC_GRAPH_EIGEN_IO_H
8 #define DYNAMIC_GRAPH_EIGEN_IO_H
10 #include <dynamic-graph/exception-signal.h>
11 #include <dynamic-graph/linear-algebra.h>
13 #include <Eigen/Geometry>
14 #include <boost/format.hpp>
15 #include <boost/numeric/conversion/cast.hpp>
28 typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE eigen_index;
30 inline std::istringstream &operator>>(std::istringstream &iss,
31 dynamicgraph::Vector &inst) {
36 "Failed to enter %s as vector."
37 " Reenter as [N](val1,val2,val3,...,valN)");
39 if (iss >> _ch && _ch !=
'[') {
42 if (iss >> _size && !iss.fail()) {
46 if (iss >> _ch && _ch !=
']')
49 if (iss >> _ch && _ch !=
'(')
52 for (
unsigned int i = 0; i < _size; i++) {
54 if (iss.peek() ==
',' || iss.peek() ==
' ') iss.ignore();
57 if (iss >> _ch && _ch !=
')')
72 template <
typename Derived>
73 inline std::istringstream &operator>>(std::istringstream &iss,
74 DenseBase<Derived> &inst) {
75 unsigned int _colsize;
76 unsigned int _rowsize;
80 "Failed to enter %s as matrix. Reenter as "
81 "((val11,val12,val13,...,val1N),"
82 "...,(valM1,valM2,...,valMN))");
85 if (iss >> _ch && _ch !=
'[') {
89 if (iss.peek() ==
',' || iss.peek() ==
' ') iss.ignore();
94 _tmp_matrix.resize(_rowsize, _colsize);
95 if (iss >> _ch && _ch !=
']')
98 if (iss >> _ch && _ch !=
'(')
101 for (
unsigned int j = 0; j < _rowsize; j++) {
102 if (iss >> _ch && _ch !=
'(')
104 for (
unsigned int i = 0; i < _colsize; i++) {
106 if (iss.peek() ==
',' || iss.peek() ==
' ') iss.ignore();
107 _tmp_matrix(j, i) = _dbl_val;
109 if (iss >> _ch && _ch !=
')')
111 if (iss.peek() ==
',' || iss.peek() ==
' ') iss.ignore();
113 if (iss >> _ch && _ch !=
')')
123 inline std::istringstream &operator>>(std::istringstream &iss,
124 Transform<double, 3, Affine> &inst) {
138 inline std::ostream &operator<<(std::ostream &os,
139 Transform<double, 3, Affine> MH) {
140 IOFormat boostFmt(StreamPrecision, DontAlignCols,
",",
",",
"(",
")",
"(",
143 os <<
"[4,4]" << MH.matrix().format(boostFmt);
147 inline std::ostream &operator<<(std::ostream &os, AngleAxisd quat) {
150 v.tail<3>() = quat.axis();
155 inline std::istringstream &operator>>(std::istringstream &iss,
160 inst.axis() = v.tail<3>();
Exceptions raised when an error related to signals happen.