registration_icp.hpp
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2011
00004  *
00005  * Fraunhofer Institute for Manufacturing Engineering
00006  * and Automation (IPA)
00007  *
00008  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00009  *
00010  * Project name: care-o-bot
00011  * ROS stack name: cob_vision
00012  * ROS package name: dynamic_tutorials
00013  * Description:
00014  *
00015  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00016  *
00017  * Author: goa-jh
00018  * Supervised by: Georg Arbeiter, email:georg.arbeiter@ipa.fhg.de
00019  *
00020  * Date of creation: Oct 26, 2011
00021  * ToDo:
00022  *
00023  *
00024  *
00025  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00026  *
00027  * Redistribution and use in source and binary forms, with or without
00028  * modification, are permitted provided that the following conditions are met:
00029  *
00030  *     * Redistributions of source code must retain the above copyright
00031  *       notice, this list of conditions and the following disclaimer.
00032  *     * Redistributions in binary form must reproduce the above copyright
00033  *       notice, this list of conditions and the following disclaimer in the
00034  *       documentation and/or other materials provided with the distribution.
00035  *     * Neither the name of the Fraunhofer Institute for Manufacturing
00036  *       Engineering and Automation (IPA) nor the names of its
00037  *       contributors may be used to endorse or promote products derived from
00038  *       this software without specific prior written permission.
00039  *
00040  * This program is free software: you can redistribute it and/or modify
00041  * it under the terms of the GNU Lesser General Public License LGPL as
00042  * published by the Free Software Foundation, either version 3 of the
00043  * License, or (at your option) any later version.
00044  *
00045  * This program is distributed in the hope that it will be useful,
00046  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00047  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00048  * GNU Lesser General Public License LGPL for more details.
00049  *
00050  * You should have received a copy of the GNU Lesser General Public
00051  * License LGPL along with this program.
00052  * If not, see <http://www.gnu.org/licenses/>.
00053  *
00054  ****************************************************************/
00055 
00056 /*
00057  * point_map.cpp
00058  *
00059  * Created on: Sep 6, 2011
00060  * Author: goa-jh
00061  */
00062 
00063 
00064 #ifndef REGISTRATION_ICP_HPP_
00065 #define REGISTRATION_ICP_HPP_
00066 
00067 namespace cob_3d_registration {
00068 
00069   template <typename Point>
00070   bool Registration_ICP<Point>::compute_features()
00071   {
00072 
00073     //pre-transform input data to achieve incremental transformation
00074     boost::shared_ptr<pcl::PointCloud<Point> > transformed_pc(new pcl::PointCloud<Point>);
00075     pcl::transformPointCloud(*this->input_, *transformed_pc, this->transformation_);
00076     this->setInputCloud(transformed_pc);
00077 
00078     return true;
00079   }
00080 
00081   template <typename Point>
00082   bool Registration_ICP<Point>::compute_corrospondences()
00083   {
00084     return true;
00085 #if 0
00086     if(register_.size()==0) { //first time
00087       register_ = *this->input_;
00088       return true;
00089     }
00090 
00091     float radius_=0.1;
00092 
00093     // Initialize estimators for surface normals and FPFH features
00094     boost::shared_ptr<pcl::KdTreeFLANN<Point> > tree (new pcl::KdTreeFLANN<Point>);
00095 
00096     pcl::NormalEstimation<Point, pcl::Normal> norm_est;
00097     norm_est.setSearchMethod (tree);
00098     norm_est.setRadiusSearch (radius_);
00099     pcl::PointCloud<pcl::Normal> normals;
00100 
00101     pcl::FPFHEstimation<Point, pcl::Normal, pcl::FPFHSignature33> fpfh_est;
00102     fpfh_est.setSearchMethod (tree);
00103     fpfh_est.setRadiusSearch (radius_);
00104     pcl::PointCloud<pcl::FPFHSignature33> features_source, features_target;
00105 
00106     // Estimate the FPFH features for the source cloud
00107     norm_est.setInputCloud (this->input_);
00108     norm_est.compute (normals);
00109     ROS_INFO("abc 1");
00110     fpfh_est.setInputCloud (this->input_);
00111     fpfh_est.setInputNormals (normals.makeShared ());
00112     fpfh_est.compute (features_source);
00113 
00114     // Estimate the FPFH features for the target cloud
00115     norm_est.setInputCloud (register_.makeShared());
00116     norm_est.compute (normals);
00117     ROS_INFO("abc 2");
00118     fpfh_est.setInputCloud (register_.makeShared());
00119     fpfh_est.setInputNormals (normals.makeShared ());
00120     fpfh_est.compute (features_target);
00121 
00122     // Initialize Sample Consensus Initial Alignment (SAC-IA)
00123     pcl::SampleConsensusInitialAlignment<Point, Point, pcl::FPFHSignature33> reg;
00124     reg.setMinSampleDistance (radius_);
00125     reg.setMaxCorrespondenceDistance (icp_max_corr_dist_);
00126     reg.setMaximumIterations (1000);
00127 
00128     reg.setInputCloud (this->input_);
00129     reg.setInputTarget (register_.makeShared());
00130     reg.setSourceFeatures (features_source.makeShared ());
00131     reg.setTargetFeatures (features_target.makeShared ());
00132 
00133     // Register
00134     pcl::PointCloud<Point> result;
00135     reg.align (result);
00136 
00137     this->transformation_ = reg.getFinalTransformation();
00138 
00139     std::cout<<"transf\n"<<this->transformation_<<"\n";
00140 
00141     register_ += result;
00142 #endif
00143     return true;
00144   }
00145 
00146   template <typename Point>
00147   bool Registration_ICP<Point>::compute_transformation()
00148   {
00149     if(register_.size()==0) { //first time
00150       register_ = *this->input_;
00151       return true;
00152     }
00153 
00154     //do ICP
00155     ModifiedICP<Point> icp_;
00156     pcl::IterativeClosestPoint<Point,Point> *icp = &icp_;
00157 
00158 #ifdef GICP_ENABLE
00159     ModifiedGICP<Point> gicp_;
00160     if(use_gicp_)
00161       icp = &gicp_;
00162     setSettingsForICP(&gicp_);
00163 #else
00164     setSettingsForICP(&icp_);
00165 #endif
00166 
00167     icp->setInputCloud( this->input_);
00168     //icp->setIndices(boost::make_shared<pcl::PointIndices>(indices));
00169     icp->setInputTarget(register_.makeShared());
00170     icp->setMaximumIterations(icp_max_iterations_);
00171     icp->setRANSACOutlierRejectionThreshold(outlier_rejection_threshold_);
00172     icp->setMaxCorrespondenceDistance(icp_max_corr_dist_);
00173     icp->setTransformationEpsilon (icp_trf_epsilon_);
00174 
00175     ROS_INFO("icp with %d, %d", (int)register_.size(), (int)this->input_->size());
00176 
00177     pcl::PointCloud<Point> result;
00178     icp->align(result);
00179 
00180     bool res = false;
00181 
00182 #ifdef GICP_ENABLE
00183     if(use_gicp_)
00184       res=gicp_.getMaximumIterations()!=gicp_.getNeededIterations()&&gicp_.getNeededIterations()>0;
00185     else
00186 #endif
00187       res=icp_.getMaximumIterations()!=icp_.getNeededIterations()&&icp_.getNeededIterations()>0;
00188 
00189     if(!res)
00190       return false;
00191 
00192     this->transformation_ = this->transformation_*icp->getFinalTransformation();
00193 
00194     std::cout<<"transf\n"<<this->transformation_<<"\n";
00195 
00196     if(use_only_last_refrence_)
00197       register_ = result;
00198     else
00199       register_ += result;
00200 
00201     return res;
00202   }
00203 
00204   template <typename Point>
00205   void Registration_ICP<Point>::setSettingsForICP(ModifiedICP_G *icp) {
00206     if(non_linear_)
00207       icp->setLM();
00208   }
00209 
00210   template <typename Point>
00211   void Registration_ICP_Features<Point>::setSettingsForICP(ModifiedICP_G *icp) {
00212     Registration_ICP<Point>::setSettingsForICP(icp);
00213 
00214     this->Registration_ICP<Point>::setSettingsForICP(icp);
00215 
00216     if(features_)
00217       icp->setSearchFeatures(features_);
00218   }
00219 
00220 
00221   template <typename Point, typename FeatureType>
00222   bool Registration_ICP_Features_Extra<Point,FeatureType>::compute_features()
00223   {
00224     boost::shared_ptr<pcl::PointCloud<Point> > inp = boost::shared_ptr<pcl::PointCloud<Point> >(new pcl::PointCloud<Point>);
00225     boost::shared_ptr<pcl::PointCloud<Point> > out = boost::shared_ptr<pcl::PointCloud<Point> >(new pcl::PointCloud<Point>);
00226 
00227     if(!calculateFeature(((Registration_ICP_Features<Point>*)this)->input, inp, ((Registration_ICP_Features<Point>*)this)->features_.getTargetFeature()))
00228       return false;
00229 
00230     if(!calculateFeature(((Registration_ICP_Features<Point>*)this)->register_, out, ((Registration_ICP_Features<Point>*)this)->features_.getSourceFeature()))
00231       return false;
00232 
00233     ((Registration_ICP_Features<Point>*)this)->input_    = inp;
00234     ((Registration_ICP_Features<Point>*)this)->register_ = out;
00235 
00236     return true;
00237   }
00238   /*
00239 template <typename Point, typename FeatureType>
00240 bool Registration_ICP_Features_Extra<Point,FeatureType>::calculateFeature(boost::shared_ptr<pcl::PointCloud<Point> > input, boost::shared_ptr<pcl::PointCloud<Point> > output, boost::shared_ptr<pcl::PointCloud<FeatureType> > features)
00241 {
00242   ASSERT(input.size() == );
00243 
00244   findFeatureCorrespondences
00245 
00246 }
00247    */
00248 
00249 
00250 }
00251 
00252 #define PCL_INSTANTIATE_Registration_ICP(T) template class PCL_EXPORTS cob_3d_registration::Registration_ICP<T>;
00253 #define PCL_INSTANTIATE_Registration_ICP_Features(T) template class PCL_EXPORTS cob_3d_registration::Registration_ICP_Features<T>;
00254 
00255 
00256 #endif


cob_3d_registration
Author(s): Joshua Hampp
autogenerated on Wed Aug 26 2015 11:02:36