/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/#include<pcl/io/pcd_io.h>#include<pcl/point_cloud.h>#include<pcl/correspondence.h>#include<pcl/features/normal_3d_omp.h>#include<pcl/features/shot_omp.h>#include<pcl/features/board.h>#include<pcl/filters/uniform_sampling.h>#include<pcl/recognition/cg/hough_3d.h>#include<pcl/recognition/cg/geometric_consistency.h>#include<pcl/recognition/hv/hv_go.h>#include<pcl/registration/icp.h>#include<pcl/visualization/pcl_visualizer.h>#include<pcl/kdtree/kdtree_flann.h>#include<pcl/kdtree/impl/kdtree_flann.hpp>#include<pcl/common/transforms.h>#include<pcl/console/parse.h>typedef pcl::PointXYZRGBA PointType;typedef pcl::Normal NormalType;typedef pcl::ReferenceFrame RFType;typedef pcl::SHOT352 DescriptorType;struct CloudStyle
{
double r;double g;double b;double size;CloudStyle(double r,double g,double b,double size):r(r),g(g),b(b),size(size){
}};
CloudStyle style_white(255.0,255.0,255.0,4.0);
CloudStyle style_red(255.0,0.0,0.0,3.0);
CloudStyle style_green(0.0,255.0,0.0,5.0);
CloudStyle style_cyan(93.0,200.0,217.0,4.0);
CloudStyle style_violet(255.0,0.0,255.0,8.0);
std::string model_filename_;
std::string scene_filename_;//Algorithm params boolshow_keypoints_(false);booluse_hough_(true);floatmodel_ss_(0.02f);floatscene_ss_(0.02f);floatrf_rad_(0.015f);floatdescr_rad_(0.02f);floatcg_size_(0.01f);floatcg_thresh_(5.0f);inticp_max_iter_(5);floaticp_corr_distance_(0.005f);floathv_resolution_(0.005f);floathv_occupancy_grid_resolution_(0.01f);floathv_clutter_reg_(5.0f);floathv_inlier_th_(0.005f);floathv_occlusion_th_(0.01f);floathv_rad_clutter_(0.03f);floathv_regularizer_(3.0f);floathv_rad_normals_(0.05);boolhv_detect_clutter_(true);/**
* Prints out Help message
* @param filename Runnable App Name
*/voidshowHelp(char* filename){
std::cout << std::endl;
std::cout <<"***************************************************************************"<< std::endl;
std::cout <<"* *"<< std::endl;
std::cout <<"* Global Hypothese Verification Tutorial - Usage Guide *"<< std::endl;
std::cout <<"* *"<< std::endl;
std::cout <<"***************************************************************************"<< std::endl << std::endl;
std::cout <<"Usage: "<< filename <<" model_filename.pcd scene_filename.pcd [Options]"<< std::endl << std::endl;
std::cout <<"Options:"<< std::endl;
std::cout <<" -h: Show this help."<< std::endl;
std::cout <<" -k: Show keypoints."<< std::endl;
std::cout <<" --algorithm (Hough|GC): Clustering algorithm used (default Hough)."<< std::endl;
std::cout <<" --model_ss val: Model uniform sampling radius (default "<< model_ss_ <<")"<< std::endl;
std::cout <<" --scene_ss val: Scene uniform sampling radius (default "<< scene_ss_ <<")"<< std::endl;
std::cout <<" --rf_rad val: Reference frame radius (default "<< rf_rad_ <<")"<< std::endl;
std::cout <<" --descr_rad val: Descriptor radius (default "<< descr_rad_ <<")"<< std::endl;
std::cout <<" --cg_size val: Cluster size (default "<< cg_size_ <<")"<< std::endl;
std::cout <<" --cg_thresh val: Clustering threshold (default "<< cg_thresh_ <<")"<< std::endl << std::endl;
std::cout <<" --icp_max_iter val: ICP max iterations number (default "<< icp_max_iter_ <<")"<< std::endl;
std::cout <<" --icp_corr_distance val: ICP correspondence distance (default "<< icp_corr_distance_ <<")"<< std::endl << std::endl;
std::cout <<" --hv_clutter_reg val: Clutter Regularizer (default "