PCL error in moving least squares
I am using the Moving Least square code provided in pcl, here is my code exaclty:
<iostream>
<pcl/point_types.h>
<pcl/point_cloud.h>
<pcl/io/pcd_io.h>
<pcl/visualization/pcl_visualizer.h>
<pcl/kdtree/kdtree_flann.h>
<pcl/surface/mls.h>
int main(int argc, char **argv) {
pcl::PointCloud <pcl::PointXYZ> cloud;
pcl::io::loadPCDFile("KinectPointCloudChest2_filtered.pcd", cloud); // Create a KD-Tree
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree <pcl::PointXYZ>);
// Output has the PointNormal type in order to store the normals calculated by MLS
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.setComputeNormals(true); // Set parameters
mls.setInputCloud(cloud.makeShared());
mls.setPolynomialFit(true);
mls.setPolynomialOrder(2);
mls.setSearchMethod(tree);
mls.setSearchRadius(0.03); // Reconstruct
mls.process(mls_points);
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.x = mls_points.points.x; //error
mls_cloud->points.y = mls_points.points.y;
//error
mls_cloud->points.z = mls_points.points.z;
//error
}
pcl::io::savePCDFile("KinectPointCloudChest2_mls.pcd", mls_points);
return 0;
}
but I get an error throw pcl::IOException ("[pcl::PCDWriter::writeASCII] Input point cloud has no data!"); what to do in this case?