Point Cloud Library (PCL)  1.10.1
correspondence_estimation_normal_shooting.h
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  * 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  * $Id$
38  *
39  */
40 
41 #pragma once
42 
43 #include <pcl/registration/correspondence_types.h>
44 #include <pcl/registration/correspondence_estimation.h>
45 
46 namespace pcl
47 {
48  namespace registration
49  {
50  /** \brief @b CorrespondenceEstimationNormalShooting computes
51  * correspondences as points in the target cloud which have minimum
52  * distance to normals computed on the input cloud
53  *
54  * Code example:
55  *
56  * \code
57  * pcl::PointCloud<pcl::PointNormal>::Ptr source, target;
58  * // ... read or fill in source and target
59  * pcl::CorrespondenceEstimationNormalShooting<pcl::PointNormal, pcl::PointNormal, pcl::PointNormal> est;
60  * est.setInputSource (source);
61  * est.setSourceNormals (source);
62  *
63  * est.setInputTarget (target);
64  *
65  * // Test the first 10 correspondences for each point in source, and return the best
66  * est.setKSearch (10);
67  *
68  * pcl::Correspondences all_correspondences;
69  * // Determine all correspondences
70  * est.determineCorrespondences (all_correspondences);
71  * \endcode
72  *
73  * \author Aravindhan K. Krishnan, Radu B. Rusu
74  * \ingroup registration
75  */
76  template <typename PointSource, typename PointTarget, typename NormalT, typename Scalar = float>
77  class CorrespondenceEstimationNormalShooting : public CorrespondenceEstimationBase<PointSource, PointTarget, Scalar>
78  {
79  public:
82 
92 
94  using KdTreePtr = typename KdTree::Ptr;
95 
99 
103 
107 
108  /** \brief Empty constructor.
109  *
110  * \note
111  * Sets the number of neighbors to be considered in the target point cloud (k_) to 10.
112  */
114  : source_normals_ ()
115  , source_normals_transformed_ ()
116  , k_ (10)
117  {
118  corr_name_ = "CorrespondenceEstimationNormalShooting";
119  }
120 
121  /** \brief Empty destructor */
123 
124  /** \brief Set the normals computed on the source point cloud
125  * \param[in] normals the normals computed for the source cloud
126  */
127  inline void
128  setSourceNormals (const NormalsConstPtr &normals) { source_normals_ = normals; }
129 
130  /** \brief Get the normals of the source point cloud
131  */
132  inline NormalsConstPtr
133  getSourceNormals () const { return (source_normals_); }
134 
135 
136  /** \brief See if this rejector requires source normals */
137  bool
138  requiresSourceNormals () const override
139  { return (true); }
140 
141  /** \brief Blob method for setting the source normals */
142  void
144  {
145  NormalsPtr cloud (new PointCloudNormals);
146  fromPCLPointCloud2 (*cloud2, *cloud);
147  setSourceNormals (cloud);
148  }
149 
150  /** \brief Determine the correspondences between input and target cloud.
151  * \param[out] correspondences the found correspondences (index of query point, index of target point, distance)
152  * \param[in] max_distance maximum distance between the normal on the source point cloud and the corresponding point in the target
153  * point cloud
154  */
155  void
157  double max_distance = std::numeric_limits<double>::max ()) override;
158 
159  /** \brief Determine the reciprocal correspondences between input and target cloud.
160  * A correspondence is considered reciprocal if both Src_i has Tgt_i as a
161  * correspondence, and Tgt_i has Src_i as one.
162  *
163  * \param[out] correspondences the found correspondences (index of query and target point, distance)
164  * \param[in] max_distance maximum allowed distance between correspondences
165  */
166  void
168  double max_distance = std::numeric_limits<double>::max ()) override;
169 
170  /** \brief Set the number of nearest neighbours to be considered in the target
171  * point cloud. By default, we use k = 10 nearest neighbors.
172  *
173  * \param[in] k the number of nearest neighbours to be considered
174  */
175  inline void
176  setKSearch (unsigned int k) { k_ = k; }
177 
178  /** \brief Get the number of nearest neighbours considered in the target point
179  * cloud for computing correspondences. By default we use k = 10 nearest
180  * neighbors.
181  */
182  inline unsigned int
183  getKSearch () const { return (k_); }
184 
185  /** \brief Clone and cast to CorrespondenceEstimationBase */
187  clone () const override
188  {
190  return (copy);
191  }
192 
193  protected:
194 
199 
200  /** \brief Internal computation initialization. */
201  bool
202  initCompute ();
203 
204  private:
205 
206  /** \brief The normals computed at each point in the source cloud */
207  NormalsConstPtr source_normals_;
208 
209  /** \brief The normals computed at each point in the source cloud */
210  NormalsPtr source_normals_transformed_;
211 
212  /** \brief The number of neighbours to be considered in the target point cloud */
213  unsigned int k_;
214  };
215  }
216 }
217 
218 #include <pcl/registration/impl/correspondence_estimation_normal_shooting.hpp>
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::registration::CorrespondenceEstimationNormalShooting::determineCorrespondences
void determineCorrespondences(pcl::Correspondences &correspondences, double max_distance=std::numeric_limits< double >::max()) override
Determine the correspondences between input and target cloud.
Definition: correspondence_estimation_normal_shooting.hpp:60
pcl::registration::CorrespondenceEstimationNormalShooting
CorrespondenceEstimationNormalShooting computes correspondences as points in the target cloud which h...
Definition: correspondence_estimation_normal_shooting.h:77
pcl::registration::CorrespondenceEstimationNormalShooting::getKSearch
unsigned int getKSearch() const
Get the number of nearest neighbours considered in the target point cloud for computing correspondenc...
Definition: correspondence_estimation_normal_shooting.h:183
pcl::registration::CorrespondenceEstimationNormalShooting::determineReciprocalCorrespondences
void determineReciprocalCorrespondences(pcl::Correspondences &correspondences, double max_distance=std::numeric_limits< double >::max()) override
Determine the reciprocal correspondences between input and target cloud.
Definition: correspondence_estimation_normal_shooting.hpp:174
pcl::registration::CorrespondenceEstimationNormalShooting::clone
CorrespondenceEstimationBase< PointSource, PointTarget, Scalar >::Ptr clone() const override
Clone and cast to CorrespondenceEstimationBase.
Definition: correspondence_estimation_normal_shooting.h:187
pcl::registration::CorrespondenceEstimationNormalShooting::setSourceNormals
void setSourceNormals(const NormalsConstPtr &normals)
Set the normals computed on the source point cloud.
Definition: correspondence_estimation_normal_shooting.h:128
pcl::registration::CorrespondenceEstimationNormalShooting::CorrespondenceEstimationNormalShooting
CorrespondenceEstimationNormalShooting()
Empty constructor.
Definition: correspondence_estimation_normal_shooting.h:113
pcl::registration::CorrespondenceEstimationBase::PointCloudTargetPtr
typename PointCloudTarget::Ptr PointCloudTargetPtr
Definition: correspondence_estimation.h:85
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:69
pcl::registration::CorrespondenceEstimationBase
Abstract CorrespondenceEstimationBase class.
Definition: correspondence_estimation.h:62
pcl::PointCloud< PointSource >
pcl::registration::CorrespondenceEstimationBase::PointCloudTargetConstPtr
typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr
Definition: correspondence_estimation.h:86
pcl::search::KdTree::Ptr
shared_ptr< KdTree< PointT, Tree > > Ptr
Definition: kdtree.h:78
pcl::registration::CorrespondenceEstimationNormalShooting::NormalsConstPtr
typename PointCloudNormals::ConstPtr NormalsConstPtr
Definition: correspondence_estimation_normal_shooting.h:106
pcl::registration::CorrespondenceEstimationBase::PointCloudSourcePtr
typename PointCloudSource::Ptr PointCloudSourcePtr
Definition: correspondence_estimation.h:81
pcl::registration::CorrespondenceEstimationNormalShooting::NormalsPtr
typename PointCloudNormals::Ptr NormalsPtr
Definition: correspondence_estimation_normal_shooting.h:105
pcl::PCLPointCloud2::ConstPtr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Definition: PCLPointCloud2.h:34
pcl::registration::CorrespondenceEstimationBase::Ptr
shared_ptr< CorrespondenceEstimationBase< PointSource, PointTarget, Scalar > > Ptr
Definition: correspondence_estimation.h:65
pcl::registration::CorrespondenceEstimationBase::ConstPtr
shared_ptr< const CorrespondenceEstimationBase< PointSource, PointTarget, Scalar > > ConstPtr
Definition: correspondence_estimation.h:66
pcl::registration::CorrespondenceEstimationNormalShooting::initCompute
bool initCompute()
Internal computation initialization.
Definition: correspondence_estimation_normal_shooting.hpp:47
pcl::registration::CorrespondenceEstimationNormalShooting::setKSearch
void setKSearch(unsigned int k)
Set the number of nearest neighbours to be considered in the target point cloud.
Definition: correspondence_estimation_normal_shooting.h:176
pcl::search::KdTree
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition: kdtree.h:61
pcl::registration::CorrespondenceEstimationNormalShooting::requiresSourceNormals
bool requiresSourceNormals() const override
See if this rejector requires source normals.
Definition: correspondence_estimation_normal_shooting.h:138
pcl::registration::CorrespondenceEstimationNormalShooting::~CorrespondenceEstimationNormalShooting
~CorrespondenceEstimationNormalShooting()
Empty destructor.
Definition: correspondence_estimation_normal_shooting.h:122
pcl::registration::CorrespondenceEstimationBase::corr_name_
std::string corr_name_
The correspondence estimation method name.
Definition: correspondence_estimation.h:284
pcl::registration::CorrespondenceEstimationBase::KdTreePtr
typename KdTree::Ptr KdTreePtr
Definition: correspondence_estimation.h:75
pcl::registration::CorrespondenceEstimationNormalShooting::setSourceNormals
void setSourceNormals(pcl::PCLPointCloud2::ConstPtr cloud2) override
Blob method for setting the source normals.
Definition: correspondence_estimation_normal_shooting.h:143
pcl::PointCloud< PointSource >::Ptr
shared_ptr< PointCloud< PointSource > > Ptr
Definition: point_cloud.h:415
pcl::registration::CorrespondenceEstimationBase::PointCloudSourceConstPtr
typename PointCloudSource::ConstPtr PointCloudSourceConstPtr
Definition: correspondence_estimation.h:82
pcl::PointCloud< PointSource >::ConstPtr
shared_ptr< const PointCloud< PointSource > > ConstPtr
Definition: point_cloud.h:416
pcl::registration::CorrespondenceEstimationNormalShooting::getSourceNormals
NormalsConstPtr getSourceNormals() const
Get the normals of the source point cloud.
Definition: correspondence_estimation_normal_shooting.h:133
pcl::Correspondences
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
Definition: correspondence.h:88
pcl::fromPCLPointCloud2
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map.
Definition: conversions.h:168
pcl::shared_ptr
boost::shared_ptr< T > shared_ptr
Alias for boost::shared_ptr.
Definition: pcl_macros.h:108