00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2009-2011, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id$ 00037 * 00038 * 00039 */ 00040 // STL 00041 #include <iostream> 00042 00043 // PCL 00044 #include <pcl/io/pcd_io.h> 00045 #include <pcl/point_types.h> 00046 #include <pcl/common/io.h> 00047 #include <pcl/features/normal_3d.h> 00048 #include <pcl/kdtree/kdtree_flann.h> 00049 #include <pcl/features/rift.h> 00050 #include <pcl/features/intensity_gradient.h> 00051 00052 int 00053 main (int, char** argv) 00054 { 00055 std::string filename = argv[1]; 00056 std::cout << "Reading " << filename << std::endl; 00057 00058 pcl::PointCloud<pcl::PointXYZI>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZI>); 00059 00060 if (pcl::io::loadPCDFile<pcl::PointXYZI> (filename, *cloud) == -1) // load the file 00061 { 00062 PCL_ERROR ("Couldn't read file"); 00063 return -1; 00064 } 00065 00066 std::cout << "points: " << cloud->points.size () << std::endl; 00067 00068 // Estimate the surface normals 00069 pcl::PointCloud<pcl::Normal>::Ptr cloud_n (new pcl::PointCloud<pcl::Normal>); 00070 pcl::NormalEstimation<pcl::PointXYZI, pcl::Normal> norm_est; 00071 norm_est.setInputCloud(cloud); 00072 pcl::search::KdTree<pcl::PointXYZI>::Ptr treept1 (new pcl::search::KdTree<pcl::PointXYZI> (false)); 00073 norm_est.setSearchMethod(treept1); 00074 norm_est.setRadiusSearch(0.25); 00075 norm_est.compute(*cloud_n); 00076 00077 std::cout<<" Surface normals estimated"; 00078 std::cout<<" with size "<< cloud_n->points.size() <<std::endl; 00079 00080 // Estimate the Intensity Gradient 00081 pcl::PointCloud<pcl::IntensityGradient>::Ptr cloud_ig (new pcl::PointCloud<pcl::IntensityGradient>); 00082 pcl::IntensityGradientEstimation<pcl::PointXYZI, pcl::Normal, pcl::IntensityGradient> gradient_est; 00083 gradient_est.setInputCloud(cloud); 00084 gradient_est.setInputNormals(cloud_n); 00085 pcl::search::KdTree<pcl::PointXYZI>::Ptr treept2 (new pcl::search::KdTree<pcl::PointXYZI> (false)); 00086 gradient_est.setSearchMethod(treept2); 00087 gradient_est.setRadiusSearch(0.25); 00088 gradient_est.compute(*cloud_ig); 00089 std::cout<<" Intesity Gradient estimated"; 00090 std::cout<<" with size "<< cloud_ig->points.size() <<std::endl; 00091 00092 00093 // Estimate the RIFT feature 00094 pcl::RIFTEstimation<pcl::PointXYZI, pcl::IntensityGradient, pcl::Histogram<32> > rift_est; 00095 pcl::search::KdTree<pcl::PointXYZI>::Ptr treept3 (new pcl::search::KdTree<pcl::PointXYZI> (false)); 00096 rift_est.setSearchMethod(treept3); 00097 rift_est.setRadiusSearch(10.0); 00098 rift_est.setNrDistanceBins (4); 00099 rift_est.setNrGradientBins (8); 00100 rift_est.setInputCloud(cloud); 00101 rift_est.setInputGradient(cloud_ig); 00102 pcl::PointCloud<pcl::Histogram<32> > rift_output; 00103 rift_est.compute(rift_output); 00104 00105 std::cout<<" RIFT feature estimated"; 00106 std::cout<<" with size "<<rift_output.points.size()<<std::endl; 00107 00108 // Display and retrieve the rift descriptor vector for the first point 00109 pcl::Histogram<32> first_descriptor = rift_output.points[0]; 00110 std::cout << first_descriptor << std::endl; 00111 return 0; 00112 }