Skip to content

Commit 198c54d

Browse files
Rohan Budhirajaolivier-stasse
authored andcommitted
Patch for inputing Eigen::Transform as Matrix4d
1 parent 55c51cb commit 198c54d

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

include/dynamic-graph/value.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ namespace dynamicgraph {
3030
class Value;
3131
class DYNAMIC_GRAPH_DLLAPI EitherType {
3232
public:
33-
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
34-
3533
EitherType(const Value& value);
3634
~EitherType();
3735
operator bool () const;
@@ -41,16 +39,14 @@ namespace dynamicgraph {
4139
operator double () const;
4240
operator std::string () const;
4341
operator Vector () const;
44-
operator Matrix () const;
42+
operator Eigen::MatrixXd () const;
43+
operator Eigen::Matrix4d () const;
4544
private:
4645
const Value* value_;
4746
};
4847

4948
class DYNAMIC_GRAPH_DLLAPI Value {
5049
public:
51-
52-
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
53-
5450
enum Type {
5551
NONE,
5652
BOOL,
@@ -61,6 +57,7 @@ namespace dynamicgraph {
6157
STRING,
6258
VECTOR,
6359
MATRIX,
60+
MATRIX4D,
6461
NB_TYPES
6562
};
6663
~Value();
@@ -72,7 +69,8 @@ namespace dynamicgraph {
7269
explicit Value(const double& value);
7370
explicit Value(const std::string& value);
7471
explicit Value(const Vector& value);
75-
explicit Value(const Matrix& value);
72+
explicit Value(const Eigen::MatrixXd& value);
73+
explicit Value(const Eigen::Matrix4d& value);
7674
/// Copy constructor
7775
Value(const Value& value);
7876
// Construct an empty value (None)
@@ -108,7 +106,8 @@ namespace dynamicgraph {
108106
double doubleValue() const;
109107
std::string stringValue() const;
110108
Vector vectorValue() const;
111-
Matrix matrixValue() const;
109+
Eigen::MatrixXd matrixXdValue() const;
110+
Eigen::Matrix4d matrix4dValue() const;
112111
Type type_;
113112
const void* const value_;
114113
};

src/command/command.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace dynamicgraph {
5050
for (unsigned int iParam=0; iParam < values.size(); iParam++) {
5151
if (values[iParam].type() != paramTypes[iParam]) {
5252
std::stringstream ss;
53-
ss << "argument " << iParam << "is of wrong type: "
53+
ss << "argument " << iParam << " is of wrong type: "
5454
<< Value::typeName(paramTypes[iParam]) << " expected, got "
5555
<< Value::typeName(values[iParam].type());
5656
throw ExceptionAbstract(ExceptionAbstract::TOOLS, ss.str());

src/command/value.cpp

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ namespace dynamicgraph {
6161
{
6262
return value_->vectorValue();
6363
}
64-
EitherType::operator Matrix() const
64+
EitherType::operator Eigen::MatrixXd() const
6565
{
66-
return value_->matrixValue();
66+
return value_->matrixXdValue();
67+
}
68+
69+
EitherType::operator Eigen::Matrix4d() const
70+
{
71+
return value_->matrix4dValue();
6772
}
6873

6974
void Value::deleteValue ()
@@ -91,7 +96,10 @@ namespace dynamicgraph {
9196
delete(const Vector*)value_;
9297
break;
9398
case MATRIX:
94-
delete(const Matrix*)value_;
99+
delete(const Eigen::MatrixXd*)value_;
100+
break;
101+
case MATRIX4D:
102+
delete(const Eigen::Matrix4d*)value_;
95103
break;
96104
default:;
97105
}
@@ -129,8 +137,12 @@ namespace dynamicgraph {
129137
value_(new Vector(value))
130138
{
131139
}
132-
Value::Value(const Matrix& value) : type_(MATRIX),
133-
value_(new Matrix(value))
140+
Value::Value(const Eigen::MatrixXd& value) : type_(MATRIX),
141+
value_(new Eigen::MatrixXd(value))
142+
{
143+
}
144+
Value::Value(const Eigen::Matrix4d& value) : type_(MATRIX4D),
145+
value_(new Eigen::Matrix4d(value))
134146
{
135147
}
136148

@@ -168,7 +180,10 @@ namespace dynamicgraph {
168180
copy = new Vector(value.vectorValue());
169181
break;
170182
case Value::MATRIX:
171-
copy = new Matrix(value.matrixValue());
183+
copy = new Eigen::MatrixXd(value.matrixXdValue());
184+
break;
185+
case Value::MATRIX4D:
186+
copy = new Eigen::Matrix4d(value.matrix4dValue());
172187
break;
173188
default:
174189
abort();
@@ -262,12 +277,20 @@ namespace dynamicgraph {
262277
"value is not an vector");
263278
}
264279

265-
Matrix Value::matrixValue() const
280+
Eigen::MatrixXd Value::matrixXdValue() const
266281
{
267282
if(type_ == MATRIX)
268-
return *((const Matrix*)value_);
283+
return *((const Eigen::MatrixXd*)value_);
284+
throw ExceptionAbstract(ExceptionAbstract::TOOLS,
285+
"value is not a Eigen matrixXd");
286+
}
287+
288+
Eigen::Matrix4d Value::matrix4dValue() const
289+
{
290+
if(type_ == MATRIX4D)
291+
return *((const Eigen::Matrix4d*)value_);
269292
throw ExceptionAbstract(ExceptionAbstract::TOOLS,
270-
"value is not a matrix");
293+
"value is not a Eigen matrix4d");
271294
}
272295

273296
std::string Value::typeName(Type type)
@@ -288,7 +311,9 @@ namespace dynamicgraph {
288311
case VECTOR:
289312
return std::string("vector");
290313
case MATRIX:
291-
return std::string("matrix");
314+
return std::string("matrixXd");
315+
case MATRIX4D:
316+
return std::string("matrix4d");
292317
default:
293318
return std::string("unknown");
294319
}
@@ -321,7 +346,10 @@ namespace dynamicgraph {
321346
os << value.vectorValue();
322347
break;
323348
case Value::MATRIX:
324-
os << value.matrixValue();
349+
os << value.matrixXdValue();
350+
break;
351+
case Value::MATRIX4D:
352+
os << value.matrix4dValue();
325353
break;
326354
default:
327355
return os;
@@ -336,7 +364,8 @@ namespace dynamicgraph {
336364
template<> const Value::Type ValueHelper<double>::TypeID = Value::DOUBLE;
337365
template<> const Value::Type ValueHelper<std::string>::TypeID = Value::STRING;
338366
template<> const Value::Type ValueHelper<Vector>::TypeID = Value::VECTOR;
339-
template<> const Value::Type ValueHelper<Matrix>::TypeID = Value::MATRIX;
367+
template<> const Value::Type ValueHelper<Eigen::MatrixXd>::TypeID = Value::MATRIX;
368+
template<> const Value::Type ValueHelper<Eigen::Matrix4d>::TypeID = Value::MATRIX4D;
340369

341370
} // namespace command
342371
} //namespace dynamicgraph

0 commit comments

Comments
 (0)