JE42 JE42 - 1 year ago 60
C++ Question

Shorter way to apply transform to matrix containing vectors in Eigen?

Is there a shorter way to apply the transform?

auto vecs = Matrix<float, Dynamic, 3>(); //vector in each row.
Affine3f transform = ...; // some Affine3 transform

for (int r = 0; r < vecs.rows(); r++) {
Vector3f v = vecs.row(r);
v = transform * v;
vecs.row(r) = v;

Answer Source

@JE42 is right, for loops are almost never necessary with Eigen. It is certainly possible to simplify. However, note that transform * v in your case is not a simple multiplication but an affine transformation equivalent to transform.linear() * v + transform.translation().

Also, your "points" are rows, so additional transposes are needed.

In sum, (without actually compiling or testing it) your calculation should be equivalent to

vecs.transpose() = (transform.linear() * vecs.transpose()).array() + transform.translation();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download