create_xyzinormal_type.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  *
00035  */
00036 
00045 #include "pcl/io/pcd_io.h"
00046 #include "pcl/point_types.h"
00047 #include <pcl/features/normal_3d.h>
00048 
00049 int
00050   main (int argc, char** argv)
00051 {
00052   //read input cloud
00053   pcl::PCDReader reader;
00054   pcl::PointCloud<pcl::PointXYZ> cloud_xyz;
00055   if (argc != 2)
00056     {
00057       ROS_ERROR("Usage: %s <input_cloud.pcd>", argv[0]);
00058       exit(2);
00059     }
00060   reader.read (argv[1], cloud_xyz);
00061   ROS_INFO ("PointCloud has: %zu data points.", cloud_xyz.points.size ());
00062 
00063 
00064   //construct PointXYZI cloud
00065   pcl::PointCloud<pcl::PointXYZI> cloud_a;
00066   cloud_a.points.resize(cloud_xyz.points.size ());
00067   for (unsigned int i = 0; i < cloud_xyz.points.size(); i++)
00068     {
00069       cloud_a.points[i].x = cloud_xyz.points[i].x;
00070       cloud_a.points[i].y = cloud_xyz.points[i].y;
00071       cloud_a.points[i].z = cloud_xyz.points[i].z;
00072       cloud_a.points[i].intensity = 0;
00073     }
00074 
00075 
00076   //estimate normals
00077   pcl::PointCloud<pcl::Normal> cloud_b;
00078   pcl::NormalEstimation<pcl::PointXYZI, pcl::Normal> ne;
00079   pcl::search::KdTree<pcl::PointXYZI>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZI> ());
00080   ne.setSearchMethod (tree);
00081   ne.setInputCloud (cloud_a.makeShared());
00082   ne.setKSearch (10);
00083   ne.compute (cloud_b);
00084 
00085 
00086   //concatenate fields
00087   pcl::PointCloud<pcl::PointXYZINormal> cloud_c;
00088   pcl::concatenateFields (cloud_a, cloud_b, cloud_c);
00089   
00090 
00091   //write result to disk as ASCII
00092   pcl::PCDWriter writer;
00093   ROS_INFO ("Writing PointCloud with: %zu data points.", cloud_c.points.size ());
00094   writer.write (std::string(argv[1]) + "_normals.pcd", cloud_c, false);
00095   return (0);
00096 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


pcl_cloud_tools
Author(s): Nico Blodow, Zoltan-Csaba Marton, Dejan Pangercic
autogenerated on Sun Oct 6 2013 11:58:06