jcm
jcm

Reputation: 977

Construct Eigen::Transform from Eigen::Translation

I have following code:

void mySetTransform(const Eigen::Affine3d& T);
...
mySetTransform(Eigen::Translation3d(1.0,2.0,3.0));

This doesn't compile, it can't convert the Eigen::Translation3d to Eigen::Affine3d. Following line causes the same error:

Eigen::Affine3d test = Eigen::Translation3d(r);

But this is fine:

Eigen::Affine3d test;
test = Eigen::Translation3d(r);

So, it looks like the the = operator works fine, but the constructor building Eigen::Affine3d with an Eigen::Translation3d is not defined.

The documentation has following note for the Translation class:

This class is not aimed to be used to store a translation transformation, but rather to make easier the constructions and updates of Transform objects.

Is there any way to declare the above function so that it can be called directly using any of the transformation objects like Translation declared in Eigen/Geomerty (without using a temporary variable)?

Upvotes: 4

Views: 2408

Answers (1)

ggael
ggael

Reputation: 29205

This is because the constructor of Transform from a Translation is explicit. So you have to explicitly call it:

Translation3d t(1.0,2.0,3.0);
mySetTransform(Affine3f(t));

Let's consider the following two examples:

Affine3d test1(t);  // OK
Affine3d test2 = t; // NOT OK

Even though in both cases that's the constructor which is called (not operator=), only the first one will be OK for an explicit constructor. That's a standard C++ rule. Of course you can also do:

Affine3d test3 = Affine3d(t); // OK

Upvotes: 3

Related Questions