Ask Your Question
0

PointNormal to PointXYZ transfer problem.

asked 2013-04-26 17:45:52 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I want to transfer some PointNormal values to PointXYZ. I tried by following way, but it gave error. How can I do this?

int main(...) 
{ 
......... 
........ 
pcl::PointCloud<pcl::PointNormal> mls_points; 

// Init object (second point type is for the normals, even if unused) 
pcl::MovingLeastSquares<pcl::PointXYZ, pcl::PointNormal> mls; 
...................................... 
..................................... 
mls.process (mls_points); 
pcl::PointCloud<pcl::PointXYZ>::Ptr mls_cloud (new pcl::PointCloud<pcl::PointXYZ>); 


                  for (size_t i = 0; i < mls_points.points.size(); ++i) 
                  { 
                          mls_cloud->points[i].x=mls_points.points[i].x; //error 
                          mls_cloud->points[i].y=mls_points.points[i].y; //error 
                          mls_cloud->points[i].z=mls_points.points[i].z; //error 
                  } 
................................ 

}
edit retag flag offensive close merge delete

Comments

Thanks ,xoxo

Wjwhynot gravatar imageWjwhynot ( 2014-12-02 02:44:28 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-04-27 03:25:34 -0600

You probably need to resize your target point cloud (mls_cloud). The constructor creates the cloud object, but doesn't know how many points you want to store. You can't just start assigning point data by index until you first allocate space to store them.

Try this:

pcl::PointCloud<pcl::PointXYZ>::Ptr mls_cloud (new pcl::PointCloud<pcl::PointXYZ>); 
mls_cloud->resize(mls_points.size());

for (size_t i = 0; i < mls_points.points.size(); ++i) 
{ 
    mls_cloud->points[i].x=mls_points.points[i].x; //error 
    mls_cloud->points[i].y=mls_points.points[i].y; //error 
    mls_cloud->points[i].z=mls_points.points[i].z; //error 
}

Alternatively, you can dynamically build the cloud if you don't know ahead-of-time how many points it will contain:

pcl::PointCloud<pcl::PointXYZ>::Ptr mls_cloud (new pcl::PointCloud<pcl::PointXYZ>); 

for (size_t i = 0; i < mls_points.points.size(); ++i) 
{
    const pcl::PointNormal &mls_pt = mls_points.points[i];
    pcl::PointXYZ pt(mls_pt.x, mls_pt.y, mls_pt.z);
    mls_cloud.push_back(pt);
}

Or, even better, don't re-create the wheel, and use the built-in PCL copyPointCloud function to convert cloud types:

pcl::PointCloud<pcl::PointXYZ>::Ptr mls_cloud (new pcl::PointCloud<pcl::PointXYZ>);
copyPointCloud(cloud_xyz, cloud_xyzrgb);
edit flag offensive delete link more

Comments

Thnx. First one works fine.

Nihad gravatar imageNihad ( 2013-04-27 18:41:16 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-04-26 17:45:52 -0600

Seen: 5,536 times

Last updated: Apr 27 '13