33 #include <pcl/search/impl/search.hpp>
34 #include <pcl/features/normal_3d.h>
35 #include <pcl/kdtree/kdtree_flann.h>
39 int main(
int argc,
char *argv[])
44 std::cout <<
"Usage: " << argv[0]
45 <<
" input_mesh_filename output_mesh_filename" << std::endl;
46 std::cout <<
"Example: " << argv[0] <<
" ../Testing/Data/tetra.xyz tetra.out.ply"
50 std::string input_file = argv[1];
51 std::string output_file = argv[2];
60 std::cout <<
"load point cloud" << std::endl;
68 PointCloudT >::pmap_type;
70 std::cout <<
"create vertex-normal map" << std::endl;
77 std::cout <<
"compute normals" << std::endl;
87 pcl::NormalEstimation< PointType, NormalType > normal_estimator;
88 normal_estimator.setInputCloud(pc.makeShared());
90 pcl::search::KdTree< PointType >::Ptr kdtree(
91 new pcl::search::KdTree< PointType >);
92 normal_estimator.setSearchMethod(kdtree);
94 normal_estimator.setRadiusSearch(0.03);
95 normal_estimator.compute(pc);
102 std::cout <<
"save point cloud with normals" << std::endl;
157 #include <pcl/search/impl/search.hpp>
159 #include <pcl/io/pcd_io.h>
160 #include <pcl/io/ascii_io.h>
161 #include <pcl/point_cloud.h>
162 #include <pcl/features/normal_3d.h>
163 #include <pcl/kdtree/kdtree_flann.h>
170 showHelp(
char * program_name)
172 std::cout << std::endl;
173 std::cout <<
"Usage: " << program_name <<
" cloud_filename.xyz" << std::endl;
178 template<
typename CloudType >
180 print_cloud(
const CloudType &cloud)
182 std::cout <<
"*** PointCloud = \n" << cloud << std::endl;
184 std::cout <<
"*** points = " << std::endl;
185 for(
int i = 0; i < cloud.points.size(); i++)
187 std::cout <<
"cloud.points[" << i <<
"] = " << cloud.points[i]
194 std::cout <<
"*** points.data = " << std::endl;
195 for(
int i = 0; i < cloud.points.size(); i++)
197 for(
int j = 0; j < 4; j++)
199 std::cout <<
"cloud.points[" << i <<
"].data[" << j <<
"] = " << cloud.points[i].data[j]
204 std::cout <<
"*** points.normal = " << std::endl;
205 for(
int i = 0; i < cloud.points.size(); i++)
207 for(
int j = 0; j < 4; j++)
209 std::cout <<
"cloud.points[" << i <<
"].normal[" << j <<
"] = " << cloud.points[i].normal[j]
218 main (
int argc,
char** argv)
228 std::string input_filename(argv[1]);
231 typedef pcl::PointXYZ PointType;
232 pcl::PointCloud< PointType >::Ptr cloud(
new pcl::PointCloud< PointType >());
235 pcl::ASCIIReader reader;
236 reader.setInputFields< PointType >();
237 reader.setExtension(
".xyz");
239 if(reader.read(input_filename, *cloud) < 0)
241 std::cout <<
"Error loading point cloud from " << input_filename << std::endl
247 std::cout <<
"Point cloud successfully loaded from " << input_filename << std::endl;
251 std::cout << std::endl <<
"cloud after loading :" << std::endl;
256 typedef pcl::PointNormal NormalType;
257 pcl::NormalEstimation< PointType, NormalType > normal_estimation;
258 normal_estimation.setInputCloud(cloud);
260 pcl::search::KdTree< PointType >::Ptr kdtree(
261 new pcl::search::KdTree< PointType >);
262 normal_estimation.setSearchMethod(kdtree);
264 pcl::PointCloud< NormalType > normals;
265 normal_estimation.setRadiusSearch(0.03);
266 normal_estimation.compute(normals);
270 for(
size_t i = 0; i < normals.points.size(); ++i)
272 normals.points[i].x = cloud->points[i].x;
273 normals.points[i].y = cloud->points[i].y;
274 normals.points[i].z = cloud->points[i].z;
279 std::cout << std::endl <<
"cloud with normals :" << std::endl;
280 print_cloud(normals);
284 std::string output_filename(
"test.pcd");
285 if(pcl::io::savePCDFile(output_filename, normals) < 0)
287 std::cout <<
"Error saving point cloud to " << output_filename << std::endl;
292 std::cout <<
"Point cloud successfully saved to " << output_filename << std::endl;