i have this c struct from a third party library:
typedef struct Point3d
{
enum{ SIZE = 3 };
typedef double value_type; ///< type export
double& operator[](size_t index) { return vec[index];} ///< random-access
const double& operator[](size_t index) const { return vec[index];} ///< random-access
double vec[3]; ///< point data, e.g. 0=x,1=y,2=z
void* data; ///< pointer to additional user-defined data
} Point3d;
this struct is used as an array like this:
Point3d* mypoints = new Point3d[200];
i now want to map this array – specifically the 3 doubles saved in Point3d::vec – to an Eigen::Matrix<double, 3, Eigen::Dynamic>.
I do this by following this answer:
/a/58980755/10825362
which resulted in this function:
Eigen::Matrix<double, 3, Eigen::Dynamic> exportToEigen(Point3d *points, int size)
{
Eigen::MatrixXd result(size, 3);
constexpr int stride = sizeof(ALG3D_Point3d)/sizeof(double);
Eigen::VectorXd X =
Eigen::Map<Eigen::VectorXd, Eigen::Unaligned, Eigen::InnerStride<stride>>(
&points[0].vec[0], size
);
Eigen::VectorXd Y =
Eigen::Map<Eigen::VectorXd, Eigen::Unaligned, Eigen::InnerStride<stride>>(
&points[0].vec[1], size
);
Eigen::VectorXd Z =
Eigen::Map<Eigen::VectorXd, Eigen::Unaligned, Eigen::InnerStride<stride>>(
&points[0].vec[2], size
);
result << X, Y, Z;
return result.transpose();
}
now i was wondering if this can be done without the need for the temporary X, Y, Z Eigen::VectorXd
s?
1