Beispiel #1
0
	// PointNormal: float x, y, znormal[3], curvature
	pcl::PointCloud<pcl::PointNormal>::Ptr smoothAndNormalEstimation(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,
																	 const double radius)
	{
		// Smoothing and normal estimation based on polynomial reconstruction
		// Moving Least Squares (MLS) surface reconstruction method can be used to smooth and resample noisy data

		// Create a KD-Tree
		pcl::search::KdTree<pcl::PointXYZ>::Ptr kdtree(new pcl::search::KdTree<pcl::PointXYZ>);

		// Init object (second point type is for the normals, even if unused)
		pcl::MovingLeastSquares<pcl::PointXYZ, pcl::PointNormal> mls;

		// Set parameters
		mls.setInputCloud(cloud);
		mls.setPolynomialFit(true);
		mls.setSearchMethod(kdtree);
		mls.setSearchRadius(radius);
		// void 	setPointDensity (int desired_num_points_in_radius);
		// void 	setDilationVoxelSize (float voxel_size)
		// void 	setDilationIterations (int iterations);
		// void 	setSqrGaussParam (double sqr_gauss_param)
		// void 	setPolynomialOrder (int order)
		// void 	setPolynomialFit (bool polynomial_fit)

		// Reconstruct
		// PCL v1.6
#if 1
		mls.setComputeNormals(true);

		// Output has the PointNormal type in order to store the normals calculated by MLS
		pcl::PointCloud<pcl::PointNormal>::Ptr mls_points(new pcl::PointCloud<pcl::PointNormal>());
		mls.process (*mls_points);
		return mls_points;
#else
		mls.reconstruct(*pPoints);

		// Output has the PointNormal type in order to store the normals calculated by MLS
		pPointNormals = mls.getOutputNormals();
		//mls.setOutputNormals(mls_points);
#endif
	}
inline void smooth(boost::shared_ptr<pcl::PointCloud<PointT>> &cloud, double radius) {

    // Create a KD-Tree
    typename pcl::search::KdTree<PointT>::Ptr tree (new pcl::search::KdTree<PointT>);

    // Output has the PointNormal type in order to store the normals calculated by MLS
    boost::shared_ptr<pcl::PointCloud<PointT>> mls_points (new pcl::PointCloud<PointT>(512, 424));

    // Init object (second point type is for the normals, even if unused)
    pcl::MovingLeastSquares<PointT, PointT> mls;

    mls.setComputeNormals (true);

    // Set parameters
    mls.setInputCloud (cloud);
    mls.setPolynomialFit (false);
    mls.setSearchMethod (tree);
    mls.setSearchRadius (radius);

    // Reconstruct
    mls.process (*mls_points);
    mls_points.swap(cloud);
}