Point Cloud Library (PCL)  1.15.1-dev
joint_icp.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2009-2012, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #pragma once
40 
41 // PCL includes
42 #include <pcl/registration/icp.h>
43 namespace pcl {
44 /** \brief @b JointIterativeClosestPoint extends ICP to multiple frames which
45  * share the same transform. This is particularly useful when solving for
46  * camera extrinsics using multiple observations. When given a single pair of
47  * clouds, this reduces to vanilla ICP.
48  *
49  * \author Stephen Miller
50  * \ingroup registration
51  */
52 template <typename PointSource, typename PointTarget, typename Scalar = float>
54 : public IterativeClosestPoint<PointSource, PointTarget, Scalar> {
55 public:
56  using PointCloudSource = typename IterativeClosestPoint<PointSource,
57  PointTarget,
58  Scalar>::PointCloudSource;
59  using PointCloudSourcePtr = typename PointCloudSource::Ptr;
60  using PointCloudSourceConstPtr = typename PointCloudSource::ConstPtr;
61 
62  using PointCloudTarget = typename IterativeClosestPoint<PointSource,
63  PointTarget,
64  Scalar>::PointCloudTarget;
65  using PointCloudTargetPtr = typename PointCloudTarget::Ptr;
66  using PointCloudTargetConstPtr = typename PointCloudTarget::ConstPtr;
67 
69  using KdTreePtr = typename KdTree::Ptr;
70 
72  using KdTreeReciprocalPtr = typename KdTree::Ptr;
73 
76 
77  using Ptr = shared_ptr<JointIterativeClosestPoint<PointSource, PointTarget, Scalar>>;
78  using ConstPtr =
79  shared_ptr<const JointIterativeClosestPoint<PointSource, PointTarget, Scalar>>;
80 
85 
115 
118 
124 
125  using Matrix4 =
127 
128  /** \brief Empty constructor. */
129  JointIterativeClosestPoint() { reg_name_ = "JointIterativeClosestPoint"; };
130 
131  /** \brief Empty destructor */
132  ~JointIterativeClosestPoint() override = default;
133 
134  /** \brief Provide a pointer to the input source
135  * (e.g., the point cloud that we want to align to the target)
136  */
137  void
138  setInputSource(const PointCloudSourceConstPtr& /*cloud*/) override
139  {
140  PCL_WARN("[pcl::%s::setInputSource] Warning; JointIterativeClosestPoint expects "
141  "multiple clouds. Please use addInputSource.\n",
142  getClassName().c_str());
143  return;
144  }
145 
146  /** \brief Add a source cloud to the joint solver
147  *
148  * \param[in] cloud source cloud
149  */
150  inline void
152  {
153  // Set the parent InputSource, just to get all cached values (e.g. the existence of
154  // normals).
155  if (sources_.empty())
157  sources_.push_back(cloud);
158  }
159 
160  /** \brief Provide a pointer to the input target
161  * (e.g., the point cloud that we want to align to the target)
162  */
163  void
164  setInputTarget(const PointCloudTargetConstPtr& /*cloud*/) override
165  {
166  PCL_WARN("[pcl::%s::setInputTarget] Warning; JointIterativeClosestPoint expects "
167  "multiple clouds. Please use addInputTarget.\n",
168  getClassName().c_str());
169  return;
170  }
171 
172  /** \brief Add a target cloud to the joint solver
173  *
174  * \param[in] cloud target cloud
175  */
176  inline void
178  {
179  // Set the parent InputTarget, just to get all cached values (e.g. the existence of
180  // normals).
181  if (targets_.empty())
183  targets_.push_back(cloud);
184  }
185 
186  /** \brief Add a manual correspondence estimator
187  * If you choose to do this, you must add one for each
188  * input source / target pair. They do not need to have trees
189  * or input clouds set ahead of time.
190  *
191  * \param[in] ce Correspondence estimation
192  */
193  inline void
195  {
196  correspondence_estimations_.push_back(ce);
197  }
198 
199  /** \brief Reset my list of input sources
200  */
201  inline void
203  {
204  sources_.clear();
205  }
206 
207  /** \brief Reset my list of input targets
208  */
209  inline void
211  {
212  targets_.clear();
213  }
214 
215  /** \brief Reset my list of correspondence estimation methods.
216  */
217  inline void
219  {
221  }
222 
223 protected:
224  /** \brief Rigid transformation computation method with initial guess.
225  * \param output the transformed input point cloud dataset using the rigid
226  * transformation found \param guess the initial guess of the transformation to
227  * compute
228  */
229  void
230  computeTransformation(PointCloudSource& output, const Matrix4& guess) override;
231 
232  /** \brief Looks at the Estimators and Rejectors and determines whether their
233  * blob-setter methods need to be called */
234  void
235  determineRequiredBlobData() override;
236 
237  std::vector<PointCloudSourceConstPtr> sources_;
238  std::vector<PointCloudTargetConstPtr> targets_;
239  std::vector<CorrespondenceEstimationPtr> correspondence_estimations_;
240 };
241 
242 } // namespace pcl
243 
244 #include <pcl/registration/impl/joint_icp.hpp>
IterativeClosestPoint provides a base implementation of the Iterative Closest Point algorithm.
Definition: icp.h:98
typename Registration< PointSource, PointTarget, Scalar >::Matrix4 Matrix4
Definition: icp.h:143
bool use_reciprocal_correspondence_
The correspondence type used for correspondence estimation.
Definition: icp.h:307
void setInputTarget(const PointCloudTargetConstPtr &cloud) override
Provide a pointer to the input target (e.g., the point cloud that we want to align the input source t...
Definition: icp.h:232
void setInputSource(const PointCloudSourceConstPtr &cloud) override
Provide a pointer to the input source (e.g., the point cloud that we want to align to the target)
Definition: icp.h:199
JointIterativeClosestPoint extends ICP to multiple frames which share the same transform.
Definition: joint_icp.h:54
std::vector< PointCloudTargetConstPtr > targets_
Definition: joint_icp.h:238
typename PointCloudSource::Ptr PointCloudSourcePtr
Definition: joint_icp.h:59
void clearCorrespondenceEstimations()
Reset my list of correspondence estimation methods.
Definition: joint_icp.h:218
shared_ptr< const JointIterativeClosestPoint< PointSource, PointTarget, Scalar > > ConstPtr
Definition: joint_icp.h:79
void addInputSource(const PointCloudSourceConstPtr &cloud)
Add a source cloud to the joint solver.
Definition: joint_icp.h:151
void determineRequiredBlobData() override
Looks at the Estimators and Rejectors and determines whether their blob-setter methods need to be cal...
Definition: joint_icp.hpp:295
typename IterativeClosestPoint< PointSource, PointTarget, Scalar >::PointCloudTarget PointCloudTarget
Definition: joint_icp.h:64
typename KdTree::Ptr KdTreeReciprocalPtr
Definition: joint_icp.h:72
~JointIterativeClosestPoint() override=default
Empty destructor.
void computeTransformation(PointCloudSource &output, const Matrix4 &guess) override
Rigid transformation computation method with initial guess.
Definition: joint_icp.hpp:49
typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr
Definition: joint_icp.h:66
PointIndices::Ptr PointIndicesPtr
Definition: joint_icp.h:74
void clearInputSources()
Reset my list of input sources.
Definition: joint_icp.h:202
typename PointCloudTarget::Ptr PointCloudTargetPtr
Definition: joint_icp.h:65
std::vector< PointCloudSourceConstPtr > sources_
Definition: joint_icp.h:237
typename CorrespondenceEstimation::Ptr CorrespondenceEstimationPtr
Definition: joint_icp.h:83
typename IterativeClosestPoint< PointSource, PointTarget, Scalar >::PointCloudSource PointCloudSource
Definition: joint_icp.h:58
void addCorrespondenceEstimation(CorrespondenceEstimationPtr ce)
Add a manual correspondence estimator If you choose to do this, you must add one for each input sourc...
Definition: joint_icp.h:194
PointIndices::ConstPtr PointIndicesConstPtr
Definition: joint_icp.h:75
JointIterativeClosestPoint()
Empty constructor.
Definition: joint_icp.h:129
void setInputTarget(const PointCloudTargetConstPtr &) override
Provide a pointer to the input target (e.g., the point cloud that we want to align to the target)
Definition: joint_icp.h:164
typename CorrespondenceEstimation::ConstPtr CorrespondenceEstimationConstPtr
Definition: joint_icp.h:84
shared_ptr< JointIterativeClosestPoint< PointSource, PointTarget, Scalar > > Ptr
Definition: joint_icp.h:77
typename KdTree::Ptr KdTreePtr
Definition: joint_icp.h:69
std::vector< CorrespondenceEstimationPtr > correspondence_estimations_
Definition: joint_icp.h:239
typename PointCloudSource::ConstPtr PointCloudSourceConstPtr
Definition: joint_icp.h:60
typename IterativeClosestPoint< PointSource, PointTarget, Scalar >::Matrix4 Matrix4
Definition: joint_icp.h:126
void clearInputTargets()
Reset my list of input targets.
Definition: joint_icp.h:210
void setInputSource(const PointCloudSourceConstPtr &) override
Provide a pointer to the input source (e.g., the point cloud that we want to align to the target)
Definition: joint_icp.h:138
void addInputTarget(const PointCloudTargetConstPtr &cloud)
Add a target cloud to the joint solver.
Definition: joint_icp.h:177
std::string reg_name_
The registration method name.
Definition: registration.h:548
const std::string & getClassName() const
Abstract class get name method.
Definition: registration.h:485
CorrespondenceEstimationPtr correspondence_estimation_
A CorrespondenceEstimation object, used to estimate correspondences between the source and the target...
Definition: registration.h:629
Matrix4 previous_transformation_
The previous transformation matrix estimated by the registration method (used internally).
Definition: registration.h:580
TransformationEstimationPtr transformation_estimation_
A TransformationEstimation object, used to calculate the 4x4 rigid transformation.
Definition: registration.h:625
unsigned int min_number_correspondences_
The minimum number of correspondences that the algorithm needs before attempting to estimate the tran...
Definition: registration.h:618
double euclidean_fitness_epsilon_
The maximum allowed Euclidean error between two consecutive steps in the ICP loop,...
Definition: registration.h:597
double transformation_epsilon_
The maximum difference between two consecutive transformations in order to consider convergence (user...
Definition: registration.h:585
std::vector< CorrespondenceRejectorPtr > correspondence_rejectors_
The list of correspondence rejectors to use.
Definition: registration.h:632
Abstract CorrespondenceEstimationBase class.
shared_ptr< const CorrespondenceEstimationBase< PointSource, PointTarget, Scalar > > ConstPtr
shared_ptr< CorrespondenceEstimationBase< PointSource, PointTarget, Scalar > > Ptr
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition: kdtree.h:62
shared_ptr< KdTree< PointT, Tree > > Ptr
Definition: kdtree.h:75
shared_ptr< ::pcl::PointIndices > Ptr
Definition: PointIndices.h:13
shared_ptr< const ::pcl::PointIndices > ConstPtr
Definition: PointIndices.h:14