Convert pcl point type XYZ to Eigen Vector 4f
Asked Answered
L

3

11

I am trying to convert pcl pointXYZ to eigen vector

Eigen::Vector4f min (minPnt.x, minPnt.y, minPnt.z);  
Eigen::Vector4f max (maxPnt.x, maxPnt.y, maxPnt.z);

where minPnt and maxPnt are of type pcl::PointXYZ. However, I get an error as "error C2338: THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE" . Could you suggest some other approaches or let me know if my approach is wrong.

Latonya answered 18/5, 2015 at 12:25 Comment(0)
I
12

Please use getVector4fMap() to get Eigen::Vector4f and use getVector3fMap() to get Eigen::Vector3f

Example:

PointT pcl_pt = ...;
Eigen::Vector3f e_v3f_pt = pcl_pt.getVector3fMap();
Eigen::Vector4f e_v4f_pt = pcl_pt.getVector4fMap();

If what you have is a pcl::Normal, you can try to use getNormalVector4fMap as shown below

pcl::Normal pcl_normal(0, 0, 1);
Eigen::Vector4f eigen_normal = pcl_normal.getNormalVector4fMap();
Inapprehensible answered 3/4, 2019 at 9:17 Comment(0)
L
2

I solved the above problem with following code.

auto x_min = static_cast<float>(minPnt.x); 
auto y_min = static_cast<float>(minPnt.y); 
auto z_min = static_cast<float>(minPnt.z); 

auto x_max = static_cast<float>(maxPnt.x); 
auto y_max = static_cast<float>(maxPnt.y); 
auto z_max = static_cast<float>(maxPnt.z); 

Eigen::Vector4f min(x_min, y_min, z_min, 0.0); 
Eigen::Vector4f max(x_max, y_max, z_max, 0.0); 

If there is better approach , please suggest .

Latonya answered 18/5, 2015 at 14:29 Comment(0)
C
2

eigen::Vector4f is looking for 4 floats, but you only gave it 3 (x, y, z). try adding a 0 at the end:

Eigen::Vector4f min (minPnt.x, minPnt.y, minPnt.z, 0);  
Eigen::Vector4f max (maxPnt.x, maxPnt.y, maxPnt.z, 0);
Classmate answered 19/1, 2016 at 17:49 Comment(1)
Or a 1 if you're using (x,y,z,w) coordinatesNasturtium

© 2022 - 2024 — McMap. All rights reserved.