Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
registration.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: registration.h 6133 2012-07-04 18:41:13Z rusu $
37  *
38  */
39 
40 #ifndef PCL_REGISTRATION_H_
41 #define PCL_REGISTRATION_H_
42 
43 #include <boost/function.hpp>
44 #include <boost/bind.hpp>
45 
46 // PCL includes
47 #include <pcl/pcl_base.h>
48 #include <pcl/common/transforms.h>
49 #include <pcl/pcl_macros.h>
52 
53 namespace pcl
54 {
60  template <typename PointSource, typename PointTarget>
61  class Registration : public PCLBase<PointSource>
62  {
63  public:
68 
69  typedef boost::shared_ptr< Registration<PointSource, PointTarget> > Ptr;
70  typedef boost::shared_ptr< const Registration<PointSource, PointTarget> > ConstPtr;
71 
72  typedef typename pcl::KdTree<PointTarget> KdTree;
74 
78 
82 
84 
88 
90  Registration () : reg_name_ (),
91  tree_ (new pcl::KdTreeFLANN<PointTarget>),
92  nr_iterations_(0),
93  max_iterations_(10),
94  ransac_iterations_ (0),
95  target_ (),
96  final_transformation_ (Eigen::Matrix4f::Identity ()),
97  transformation_ (Eigen::Matrix4f::Identity ()),
98  previous_transformation_ (Eigen::Matrix4f::Identity ()),
99  transformation_epsilon_ (0.0),
100  euclidean_fitness_epsilon_ (-std::numeric_limits<double>::max ()),
101  corr_dist_threshold_ (std::sqrt (std::numeric_limits<double>::max ())),
102  inlier_threshold_ (0.05),
103  converged_ (false),
104  min_number_correspondences_ (3),
105  correspondence_distances_ (),
106  transformation_estimation_ (),
107  update_visualizer_ (NULL),
108  point_representation_ ()
109  {
110  }
111 
113  virtual ~Registration () {}
114 
118  void
119  setTransformationEstimation (const TransformationEstimationPtr &te) { transformation_estimation_ = te; }
120 
124  virtual inline void
126 
128  inline PointCloudTargetConstPtr const
129  getInputTarget () { return (target_ ); }
130 
132  inline Eigen::Matrix4f
133  getFinalTransformation () { return (final_transformation_); }
134 
136  inline Eigen::Matrix4f
137  getLastIncrementalTransformation () { return (transformation_); }
138 
142  inline void
143  setMaximumIterations (int nr_iterations) { max_iterations_ = nr_iterations; }
144 
146  inline int
147  getMaximumIterations () { return (max_iterations_); }
148 
152  inline void
153  setRANSACIterations (int ransac_iterations) { ransac_iterations_ = ransac_iterations; }
154 
156  inline double
157  getRANSACIterations () { return (ransac_iterations_); }
158 
166  inline void
167  setRANSACOutlierRejectionThreshold (double inlier_threshold) { inlier_threshold_ = inlier_threshold; }
168 
170  inline double
171  getRANSACOutlierRejectionThreshold () { return (inlier_threshold_); }
172 
178  inline void
179  setMaxCorrespondenceDistance (double distance_threshold) { corr_dist_threshold_ = distance_threshold; }
180 
184  inline double
185  getMaxCorrespondenceDistance () { return (corr_dist_threshold_); }
186 
193  inline void
194  setTransformationEpsilon (double epsilon) { transformation_epsilon_ = epsilon; }
195 
199  inline double
200  getTransformationEpsilon () { return (transformation_epsilon_); }
201 
210  inline void
211  setEuclideanFitnessEpsilon (double epsilon) { euclidean_fitness_epsilon_ = epsilon; }
212 
216  inline double
217  getEuclideanFitnessEpsilon () { return (euclidean_fitness_epsilon_); }
218 
222  inline void
224  {
225  point_representation_ = point_representation;
226  }
227 
232  template<typename FunctionSignature> inline bool
233  registerVisualizationCallback (boost::function<FunctionSignature> &visualizerCallback)
234  {
235  if (visualizerCallback != NULL)
236  {
237  update_visualizer_ = visualizerCallback;
238  return (true);
239  }
240  else
241  return (false);
242  }
243 
248  inline double
249  getFitnessScore (double max_range = std::numeric_limits<double>::max ());
250 
256  inline double
257  getFitnessScore (const std::vector<float> &distances_a, const std::vector<float> &distances_b);
258 
260  inline bool
261  hasConverged () { return (converged_); }
262 
267  inline void
268  align (PointCloudSource &output);
269 
275  inline void
276  align (PointCloudSource &output, const Eigen::Matrix4f& guess);
277 
279  inline const std::string&
280  getClassName () const { return (reg_name_); }
281 
282  protected:
284  std::string reg_name_;
285 
287  KdTreePtr tree_;
288 
290  int nr_iterations_;
291 
295  int max_iterations_;
296 
298  int ransac_iterations_;
299 
301  PointCloudTargetConstPtr target_;
302 
304  Eigen::Matrix4f final_transformation_;
305 
307  Eigen::Matrix4f transformation_;
308 
310  Eigen::Matrix4f previous_transformation_;
311 
315  double transformation_epsilon_;
316 
321  double euclidean_fitness_epsilon_;
322 
326  double corr_dist_threshold_;
327 
332  double inlier_threshold_;
333 
335  bool converged_;
336 
340  int min_number_correspondences_;
341 
345  std::vector<float> correspondence_distances_;
346 
348  TransformationEstimationPtr transformation_estimation_;
349 
353  boost::function<void(const pcl::PointCloud<PointSource> &cloud_src,
354  const std::vector<int> &indices_src,
355  const pcl::PointCloud<PointTarget> &cloud_tgt,
356  const std::vector<int> &indices_tgt)> update_visualizer_;
357 
364  inline bool
365  searchForNeighbors (const PointCloudSource &cloud, int index,
366  std::vector<int> &indices, std::vector<float> &distances)
367  {
368  int k = tree_->nearestKSearch (cloud, index, 1, indices, distances);
369  if (k == 0)
370  return (false);
371  return (true);
372  }
373 
374  private:
375 
377  virtual void
378  computeTransformation (PointCloudSource &output, const Eigen::Matrix4f& guess) = 0;
379 
381  PointRepresentationConstPtr point_representation_;
382  public:
383  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
384  };
385 }
386 
388 
389 #endif //#ifndef PCL_REGISTRATION_H_