Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
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     
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) { 
00087       register_ = *this->input_;
00088       return true;
00089     }
00090 
00091     float radius_=0.1;
00092 
00093     
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     
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     
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     
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     
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) { 
00150       register_ = *this->input_;
00151       return true;
00152     }
00153 
00154     
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     
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 
00240 
00241 
00242 
00243 
00244 
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