ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Moving Least Squares (MLS) surface reconstruction method.

asked 2013-03-31 15:56:53 -0500

this post is marked as community wiki

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

I am trying to use following code which states how a Moving Least Squares (MLS) surface reconstruction method can be used to smooth and resample noisy data, but it gives error like "pcl::IOException ("[pcl::PCDWriter::writeASCII] Input point cloud has no data!");". I use same code from the link http://pointclouds.org/documentation/tutorials/resampling.php .

#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/surface/mls.h>

int
main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZ> cloud;

  // Fill in the cloud data
  cloud.width    = 5;
  cloud.height   = 1;
  cloud.is_dense = false;
  cloud.points.resize (cloud.width * cloud.height);

  for (size_t i = 0; i < cloud.points.size (); ++i)
  {
    cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
  }

  pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
  std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << std::endl;

  for (size_t i = 0; i < cloud.points.size (); ++i)
    std::cerr << "    " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;

  // 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.setSearchMethod (tree);
  mls.setSearchRadius (0.03);

  // Reconstruct
  mls.process (mls_points);

  // Save output
  pcl::io::savePCDFile ("bun0-mls.pcd", mls_points);
}
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-03-24 03:10:32 -0500

Tabjones gravatar image

Code looks ok, i'm guessing the problem is that your input point cloud has too few points (only 5) and with very sparse coordinates (you are randomizing them) so that mls can't find any surface in a radius of 3cm.

Also generally you should compute normals yourself, with NormalEstimation class and supply your normal to mls with mls.setInputNormals so that you can control how these normals are computed.

Hope this helps

edit flag offensive delete link more

Comments

Was there such a method in earlier times? I am looking for setInputNormals, but can't find it.

Hakaishin gravatar image Hakaishin  ( 2018-08-02 07:03:00 -0500 )edit
0

answered 2014-11-03 08:14:19 -0500

sarah.ali.1@ulaval.ca gravatar image

I have the same problem could anyone help us!

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-31 15:56:53 -0500

Seen: 3,812 times

Last updated: Mar 24 '15