10

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.

Launa
  • 183
  • 2
  • 13

3 Answers3

10

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();
Ardiya
  • 677
  • 6
  • 19
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 .

Launa
  • 183
  • 2
  • 13
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);
Martin Valgur
  • 5,793
  • 1
  • 33
  • 45
mobooya
  • 213
  • 2
  • 7