Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
transformation_estimation_lm.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: transformation_estimation_lm.h 5155 2012-03-17 21:45:48Z rusu $
37  *
38  */
39 #ifndef PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_LM_H_
40 #define PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_LM_H_
41 
45 
46 namespace pcl
47 {
48  namespace registration
49  {
56  template <typename PointSource, typename PointTarget>
57  class TransformationEstimationLM : public TransformationEstimation<PointSource, PointTarget>
58  {
60  typedef typename PointCloudSource::Ptr PointCloudSourcePtr;
61  typedef typename PointCloudSource::ConstPtr PointCloudSourceConstPtr;
62 
64 
65  typedef PointIndices::Ptr PointIndicesPtr;
66  typedef PointIndices::ConstPtr PointIndicesConstPtr;
67 
68  public:
71  weights_ (), tmp_src_ (), tmp_tgt_ (), tmp_idx_src_ (), tmp_idx_tgt_ (), warp_point_ ()
72  {};
73 
78  weights_ (src.weights_),
79  tmp_src_ (src.tmp_src_),
80  tmp_tgt_ (src.tmp_tgt_),
81  tmp_idx_src_ (src.tmp_idx_src_),
82  tmp_idx_tgt_ (src.tmp_idx_tgt_),
83  warp_point_ (src.warp_point_)
84  {};
85 
91  {
92  weights_ = src.weights_;
93  tmp_src_ = src.tmp_src_;
94  tmp_tgt_ = src.tmp_tgt_;
95  tmp_idx_src_ = src.tmp_idx_src_;
96  tmp_idx_tgt_ = src.tmp_idx_tgt_;
97  warp_point_ = src.warp_point_;
98  }
99 
102 
108  inline void
110  const pcl::PointCloud<PointSource> &cloud_src,
111  const pcl::PointCloud<PointTarget> &cloud_tgt,
112  Eigen::Matrix4f &transformation_matrix);
113 
120  inline void
122  const pcl::PointCloud<PointSource> &cloud_src,
123  const std::vector<int> &indices_src,
124  const pcl::PointCloud<PointTarget> &cloud_tgt,
125  Eigen::Matrix4f &transformation_matrix);
126 
135  inline void
137  const pcl::PointCloud<PointSource> &cloud_src,
138  const std::vector<int> &indices_src,
139  const pcl::PointCloud<PointTarget> &cloud_tgt,
140  const std::vector<int> &indices_tgt,
141  Eigen::Matrix4f &transformation_matrix);
142 
149  inline void
151  const pcl::PointCloud<PointSource> &cloud_src,
152  const pcl::PointCloud<PointTarget> &cloud_tgt,
153  const pcl::Correspondences &correspondences,
154  Eigen::Matrix4f &transformation_matrix);
155 
159  void
160  setWarpFunction (const boost::shared_ptr<WarpPointRigid<PointSource, PointTarget> > &warp_fcn)
161  {
162  warp_point_ = warp_fcn;
163  }
164 
165  protected:
174  virtual double
175  computeDistance (const PointSource &p_src, const PointTarget &p_tgt)
176  {
177  Vector4fMapConst s = p_src.getVector4fMap ();
178  Vector4fMapConst t = p_tgt.getVector4fMap ();
179  return (pcl::distances::l2 (s, t));
180  }
181 
183  std::vector<double> weights_;
184 
186  const PointCloudSource *tmp_src_;
187 
189  const PointCloudTarget *tmp_tgt_;
190 
192  const std::vector<int> *tmp_idx_src_;
193 
195  const std::vector<int> *tmp_idx_tgt_;
196 
198  boost::shared_ptr<WarpPointRigid<PointSource, PointTarget> > warp_point_;
199 
204  template<typename _Scalar, int NX=Eigen::Dynamic, int NY=Eigen::Dynamic>
205  struct Functor
206  {
207  typedef _Scalar Scalar;
208  enum
209  {
210  InputsAtCompileTime = NX,
211  ValuesAtCompileTime = NY
212  };
213  typedef Eigen::Matrix<Scalar,InputsAtCompileTime,1> InputType;
214  typedef Eigen::Matrix<Scalar,ValuesAtCompileTime,1> ValueType;
215  typedef Eigen::Matrix<Scalar,ValuesAtCompileTime,InputsAtCompileTime> JacobianType;
216 
218  Functor () : m_data_points_ (ValuesAtCompileTime) {}
219 
223  Functor (int m_data_points) : m_data_points_ (m_data_points) {}
224 
226  virtual ~Functor () {}
227 
229  int
230  values () const { return (m_data_points_); }
231 
232  protected:
233  int m_data_points_;
234  };
235 
236  struct OptimizationFunctor : public Functor<double>
237  {
238  using Functor<double>::values;
239 
244  OptimizationFunctor (int m_data_points, TransformationEstimationLM<PointSource, PointTarget> *estimator) :
245  Functor<double> (m_data_points), estimator_ (estimator) {}
246 
250  inline OptimizationFunctor (const OptimizationFunctor &src) :
251  Functor<double> (src.m_data_points_), estimator_ ()
252  {
253  *this = src;
254  }
255 
259  inline OptimizationFunctor&
260  operator = (const OptimizationFunctor &src)
261  {
262  Functor<double>::operator=(src);
263  estimator_ = src.estimator_;
264  return (*this);
265  }
266 
268  virtual ~OptimizationFunctor () {}
269 
274  int
275  operator () (const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const;
276 
277  TransformationEstimationLM<PointSource, PointTarget> *estimator_;
278  };
279 
280  struct OptimizationFunctorWithIndices : public Functor<double>
281  {
282  using Functor<double>::values;
283 
288  OptimizationFunctorWithIndices (int m_data_points, TransformationEstimationLM *estimator) :
289  Functor<double> (m_data_points), estimator_ (estimator) {}
290 
294  inline OptimizationFunctorWithIndices (const OptimizationFunctorWithIndices &src) :
295  Functor<double> (src.m_data_points_), estimator_ ()
296  {
297  *this = src;
298  }
299 
303  inline OptimizationFunctorWithIndices&
304  operator = (const OptimizationFunctorWithIndices &src)
305  {
306  Functor<double>::operator=(src);
307  estimator_ = src.estimator_;
308  return (*this);
309  }
310 
312  virtual ~OptimizationFunctorWithIndices () {}
313 
318  int
319  operator () (const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const;
320 
321  TransformationEstimationLM<PointSource, PointTarget> *estimator_;
322  };
323  public:
324  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
325  };
326  }
327 }
328 
330 
331 #endif /* PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_LM_H_ */
332