Skip to content
Snippets Groups Projects
Commit 844d1d49 authored by Rohan Budhiraja's avatar Rohan Budhiraja Committed by Olivier Stasse
Browse files

[c++] fix bug in matrix istream input operator

parent 8cff599b
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,7 @@ using dynamicgraph::ExceptionSignal; ...@@ -39,6 +39,7 @@ using dynamicgraph::ExceptionSignal;
*/ */
namespace Eigen { namespace Eigen {
typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE eigen_index; typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE eigen_index;
inline std::istringstream& operator >> (std::istringstream &iss, inline std::istringstream& operator >> (std::istringstream &iss,
dynamicgraph::Vector &inst) { dynamicgraph::Vector &inst) {
unsigned int _size; unsigned int _size;
...@@ -88,7 +89,8 @@ namespace Eigen { ...@@ -88,7 +89,8 @@ namespace Eigen {
unsigned int _rowsize; unsigned int _rowsize;
double _dbl_val; double _dbl_val;
char _ch; char _ch;
boost::format fmt ("Failed to enter %s as vector. Reenter as [N](val1,val2,val3,...,valN)"); boost::format fmt ("Failed to enter %s as matrix. Reenter as ((val11,val12,val13,...,val1N),...,(valM1,valM2,...,valMN))");
MatrixXd _tmp_matrix;
fmt %iss.str(); fmt %iss.str();
if(iss>> _ch && _ch != '['){ if(iss>> _ch && _ch != '['){
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str()); throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
...@@ -101,7 +103,7 @@ namespace Eigen { ...@@ -101,7 +103,7 @@ namespace Eigen {
if (iss.fail()) if (iss.fail())
throw ExceptionSignal(ExceptionSignal::GENERIC,fmt.str()); throw ExceptionSignal(ExceptionSignal::GENERIC,fmt.str());
else { else {
inst.resize(_rowsize,_colsize); _tmp_matrix.resize(_rowsize,_colsize);
if(iss >> _ch && _ch != ']') if(iss >> _ch && _ch != ']')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str()); throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else { else {
...@@ -115,7 +117,7 @@ namespace Eigen { ...@@ -115,7 +117,7 @@ namespace Eigen {
iss >> _dbl_val; iss >> _dbl_val;
if (iss.peek() == ',' || iss.peek() == ' ') if (iss.peek() == ',' || iss.peek() == ' ')
iss.ignore(); iss.ignore();
inst(j,i) = _dbl_val; _tmp_matrix(j,i) = _dbl_val;
} }
if(iss >> _ch && _ch != ')') if(iss >> _ch && _ch != ')')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str()); throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
...@@ -128,13 +130,14 @@ namespace Eigen { ...@@ -128,13 +130,14 @@ namespace Eigen {
} }
} }
} }
inst = _tmp_matrix;
return iss; return iss;
} }
inline std::istringstream& operator >> (std::istringstream &iss, inline std::istringstream& operator >> (std::istringstream &iss,
Transform<double,3,Affine> &inst) { Transform<double,3,Affine> &inst) {
Matrix4d M; iss >> M; inst = M; return iss; } MatrixXd M; iss >> M; inst.matrix() = M; return iss; }
...@@ -157,12 +160,12 @@ namespace Eigen { ...@@ -157,12 +160,12 @@ namespace Eigen {
inline std::ostream& operator << (std::ostream &os, inline std::ostream& operator << (std::ostream &os,
AngleAxisd quat) { AngleAxisd quat) {
Vector4d v; v(0) = quat.angle(); v.tail<3>() = quat.axis(); VectorXd v(4); v(0) = quat.angle(); v.tail<3>() = quat.axis();
os << v; return os; } os << v; return os; }
inline std::istringstream& operator >> (std::istringstream &iss, inline std::istringstream& operator >> (std::istringstream &iss,
AngleAxisd &inst) { AngleAxisd &inst) {
Vector4d v; iss >>v; VectorXd v(4); iss >>v;
inst.angle() = v(0); inst.axis() = v.tail<3>(); inst.angle() = v(0); inst.axis() = v.tail<3>();
return iss; } return iss; }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment