Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert pcl point type XYZ to Eigen Vector 4f

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.

like image 986
Launa Avatar asked May 18 '15 12:05

Launa


3 Answers

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);
like image 199
mobooya Avatar answered Oct 20 '22 17:10

mobooya


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();
like image 44
Ardiya Avatar answered Oct 20 '22 17:10

Ardiya


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 .

like image 26
Launa Avatar answered Oct 20 '22 18:10

Launa