7

I have a buffer containing N 3D points stored as [XYZXYZXYZ ... XYZ].

This buffer can be directly mapped to a Eigen::Matrix<float, 3, N> using Eigen::Map. Since I will transform the points using affine transformations (i.e Eigen::Matrix4f matrices) I would like to map the same buffer to an eigen structure that allows me to consider the buffer as a Eigen::Matrix<float, 4, N> matrix where the last row only contains 1s, i.e. each single point is represented by the homogeneous vector [X Y Z 1].

Is there a convenient way to do this without copying the original buffer or applying the transformation on each single point?

Pierluigi
  • 2,212
  • 1
  • 25
  • 39

1 Answers1

7

You can apply homogenous() on each column like this:

Matrix4f mat = ...; // your affine transformation stored as a 4x4 matrix
float *data = ...;  // your raw buffer storing 3D point as [XYZXYZXYZ...]
mat * Map<Matrix<float, 3, Dynamic> >(data,3,N).colwise().homogeneous()
ggael
  • 28,425
  • 2
  • 65
  • 71
  • 2
    Thanks, this indeed does the job. I was missing the broadcast operation colwise. To clarify the answer: take the matrix and consider it as a collection of column vectors (colwise), then apply homogeneous to each column vecotrs. – Pierluigi Apr 30 '13 at 15:59
  • Where do `mat` and `data` come from? – IEatBagels Nov 29 '19 at 18:05
  • I have two Frames A and B. I have generated Rotation Matrix(R) and translation matrix(t). Now how to generate Homogeneous Transfomation? I'm using C++. Any help is greatly appreciated. – JTN Jan 24 '21 at 16:30