Skip to content

Commit 844d1d4

Browse files
Rohan Budhirajaolivier-stasse
authored andcommitted
[c++] fix bug in matrix istream input operator
1 parent 8cff599 commit 844d1d4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

include/dynamic-graph/eigen-io.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ using dynamicgraph::ExceptionSignal;
3939
*/
4040
namespace Eigen {
4141
typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE eigen_index;
42+
4243
inline std::istringstream& operator >> (std::istringstream &iss,
4344
dynamicgraph::Vector &inst) {
4445
unsigned int _size;
@@ -88,7 +89,8 @@ namespace Eigen {
8889
unsigned int _rowsize;
8990
double _dbl_val;
9091
char _ch;
91-
boost::format fmt ("Failed to enter %s as vector. Reenter as [N](val1,val2,val3,...,valN)");
92+
boost::format fmt ("Failed to enter %s as matrix. Reenter as ((val11,val12,val13,...,val1N),...,(valM1,valM2,...,valMN))");
93+
MatrixXd _tmp_matrix;
9294
fmt %iss.str();
9395
if(iss>> _ch && _ch != '['){
9496
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
@@ -101,7 +103,7 @@ namespace Eigen {
101103
if (iss.fail())
102104
throw ExceptionSignal(ExceptionSignal::GENERIC,fmt.str());
103105
else {
104-
inst.resize(_rowsize,_colsize);
106+
_tmp_matrix.resize(_rowsize,_colsize);
105107
if(iss >> _ch && _ch != ']')
106108
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
107109
else {
@@ -115,7 +117,7 @@ namespace Eigen {
115117
iss >> _dbl_val;
116118
if (iss.peek() == ',' || iss.peek() == ' ')
117119
iss.ignore();
118-
inst(j,i) = _dbl_val;
120+
_tmp_matrix(j,i) = _dbl_val;
119121
}
120122
if(iss >> _ch && _ch != ')')
121123
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
@@ -128,13 +130,14 @@ namespace Eigen {
128130
}
129131
}
130132
}
133+
inst = _tmp_matrix;
131134
return iss;
132135
}
133136

134137

135138
inline std::istringstream& operator >> (std::istringstream &iss,
136139
Transform<double,3,Affine> &inst) {
137-
Matrix4d M; iss >> M; inst = M; return iss; }
140+
MatrixXd M; iss >> M; inst.matrix() = M; return iss; }
138141

139142

140143

@@ -157,12 +160,12 @@ namespace Eigen {
157160

158161
inline std::ostream& operator << (std::ostream &os,
159162
AngleAxisd quat) {
160-
Vector4d v; v(0) = quat.angle(); v.tail<3>() = quat.axis();
163+
VectorXd v(4); v(0) = quat.angle(); v.tail<3>() = quat.axis();
161164
os << v; return os; }
162165

163166
inline std::istringstream& operator >> (std::istringstream &iss,
164167
AngleAxisd &inst) {
165-
Vector4d v; iss >>v;
168+
VectorXd v(4); iss >>v;
166169
inst.angle() = v(0); inst.axis() = v.tail<3>();
167170
return iss; }
168171

0 commit comments

Comments
 (0)