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 
00036 
00039 template <typename PointSource, typename PointTarget> inline void
00040   pcl::RegistrationCorrespondencesCheck<PointSource, PointTarget>::setInputTarget (const PointCloudTargetConstPtr &cloud)
00041 {
00042   if (cloud->points.empty ())
00043   {
00044     ROS_ERROR ("[pcl::%s::setInputTarget] Invalid or empty point cloud dataset given!", getClassName ().c_str ());
00045     return;
00046   }
00047   target_ = cloud;
00048   tree_->setInputCloud (target_);
00049 }
00050 
00052 
00055 template <typename PointSource, typename PointTarget> inline double
00056   pcl::RegistrationCorrespondencesCheck<PointSource, PointTarget>::getFitnessScore (double max_range)
00057 {
00058   double fitness_score = 0.0;
00059 
00060   
00061   PointCloudSource input_transformed;
00062   transformPointCloud (*input_, input_transformed, final_transformation_);
00063 
00064   std::vector<int> nn_indices (1);
00065   std::vector<float> nn_dists (1);
00066 
00067   
00068   int nr = 0;
00069   for (size_t i = 0; i < input_transformed.points.size (); ++i)
00070   {
00071     Eigen::Vector4f p1 = Eigen::Vector4f (input_transformed.points[i].x,
00072                                           input_transformed.points[i].y,
00073                                           input_transformed.points[i].z, 0);
00074     
00075     tree_->nearestKSearch (input_transformed.points[i], 1, nn_indices, nn_dists);
00076 
00077     
00078     if (nn_dists[0] > max_range)
00079       continue;
00080 
00081     Eigen::Vector4f p2 = Eigen::Vector4f (target_->points[nn_indices[0]].x,
00082                                           target_->points[nn_indices[0]].y,
00083                                           target_->points[nn_indices[0]].z, 0);
00084     
00085     fitness_score += fabs ((p1-p2).squaredNorm ());
00086     nr++;
00087   }
00088 
00089   if (nr > 0)
00090     return (fitness_score / nr);
00091   else
00092     return (std::numeric_limits<double>::max ());
00093 }
00094 
00096 
00099 template <typename PointSource, typename PointTarget> inline void
00100   pcl::RegistrationCorrespondencesCheck<PointSource, PointTarget>::align (PointCloudSource &output)
00101 {
00102   if (!initCompute ()) return;
00103 
00104   if (!target_)
00105   {
00106     ROS_WARN ("[pcl::%s::compute] No input target dataset was given!", getClassName ().c_str ());
00107     return;
00108   }
00109 
00110   
00111   if (output.points.size () != indices_->size ())
00112     output.points.resize (indices_->size ());
00113   
00114   output.header   = input_->header;
00115   
00116   if (indices_->size () != input_->points.size ())
00117   {
00118     output.width    = indices_->size ();
00119     output.height   = 1;
00120     output.is_dense = false;
00121   }
00122   else
00123   {
00124     output.width    = input_->width;
00125     output.height   = input_->height;
00126     output.is_dense = input_->is_dense;
00127   }
00128 
00129   
00130   for (size_t i = 0; i < indices_->size (); ++i)
00131     output.points[i] = input_->points[(*indices_)[i]];
00132 
00133   
00134   converged_ = false;
00135   final_transformation_ = transformation_ = previous_transformation_ = Eigen::Matrix4f::Identity ();
00136   ROS_INFO("[RegistrationCorrespondencesCheck:] computeTransformation");
00137   computeTransformation (output);
00138 
00139   deinitCompute ();
00140 }
00141