Point Cloud Library (PCL)  1.11.1-dev
correspondence_estimation_backprojection.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2012-, Open Perception, 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 the copyright holder(s) 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$
37  *
38  */
39 
40 #pragma once
41 
42 #include <pcl/registration/correspondence_estimation.h>
43 #include <pcl/registration/correspondence_types.h>
44 
45 namespace pcl {
46 namespace registration {
47 /** \brief @b CorrespondenceEstimationBackprojection computes
48  * correspondences as points in the target cloud which have minimum
49  * \author Suat Gedikli
50  * \ingroup registration
51  */
52 template <typename PointSource,
53  typename PointTarget,
54  typename NormalT,
55  typename Scalar = float>
57 : public CorrespondenceEstimationBase<PointSource, PointTarget, Scalar> {
58 public:
59  using Ptr = shared_ptr<CorrespondenceEstimationBackProjection<PointSource,
60  PointTarget,
61  NormalT,
62  Scalar>>;
63  using ConstPtr = shared_ptr<const CorrespondenceEstimationBackProjection<PointSource,
64  PointTarget,
65  NormalT,
66  Scalar>>;
67 
80 
82  using KdTreePtr = typename KdTree::Ptr;
83 
87 
91 
95 
96  /** \brief Empty constructor.
97  *
98  * \note
99  * Sets the number of neighbors to be considered in the target point cloud (k_) to 10.
100  */
102  : source_normals_(), source_normals_transformed_(), target_normals_(), k_(10)
103  {
104  corr_name_ = "CorrespondenceEstimationBackProjection";
105  }
106 
107  /** \brief Empty destructor */
109 
110  /** \brief Set the normals computed on the source point cloud
111  * \param[in] normals the normals computed for the source cloud
112  */
113  inline void
115  {
116  source_normals_ = normals;
117  }
118 
119  /** \brief Get the normals of the source point cloud
120  */
121  inline NormalsConstPtr
123  {
124  return (source_normals_);
125  }
126 
127  /** \brief Set the normals computed on the target point cloud
128  * \param[in] normals the normals computed for the target cloud
129  */
130  inline void
132  {
133  target_normals_ = normals;
134  }
135 
136  /** \brief Get the normals of the target point cloud
137  */
138  inline NormalsConstPtr
140  {
141  return (target_normals_);
142  }
143 
144  /** \brief See if this rejector requires source normals */
145  bool
147  {
148  return (true);
149  }
150 
151  /** \brief Blob method for setting the source normals */
152  void
154  {
155  NormalsPtr cloud(new PointCloudNormals);
156  fromPCLPointCloud2(*cloud2, *cloud);
157  setSourceNormals(cloud);
158  }
159 
160  /** \brief See if this rejector requires target normals*/
161  bool
163  {
164  return (true);
165  }
166 
167  /** \brief Method for setting the target normals */
168  void
170  {
171  NormalsPtr cloud(new PointCloudNormals);
172  fromPCLPointCloud2(*cloud2, *cloud);
173  setTargetNormals(cloud);
174  }
175 
176  /** \brief Determine the correspondences between input and target cloud.
177  * \param[out] correspondences the found correspondences (index of query point, index
178  * of target point, distance) \param[in] max_distance maximum distance between the
179  * normal on the source point cloud and the corresponding point in the target point
180  * cloud
181  */
182  void
184  double max_distance = std::numeric_limits<double>::max());
185 
186  /** \brief Determine the reciprocal correspondences between input and target cloud.
187  * A correspondence is considered reciprocal if both Src_i has Tgt_i as a
188  * correspondence, and Tgt_i has Src_i as one.
189  *
190  * \param[out] correspondences the found correspondences (index of query and target
191  * point, distance) \param[in] max_distance maximum allowed distance between
192  * correspondences
193  */
194  virtual void
196  pcl::Correspondences& correspondences,
197  double max_distance = std::numeric_limits<double>::max());
198 
199  /** \brief Set the number of nearest neighbours to be considered in the target
200  * point cloud. By default, we use k = 10 nearest neighbors.
201  *
202  * \param[in] k the number of nearest neighbours to be considered
203  */
204  inline void
205  setKSearch(unsigned int k)
206  {
207  k_ = k;
208  }
209 
210  /** \brief Get the number of nearest neighbours considered in the target point
211  * cloud for computing correspondences. By default we use k = 10 nearest
212  * neighbors.
213  */
214  inline unsigned int
215  getKSearch() const
216  {
217  return (k_);
218  }
219 
220  /** \brief Clone and cast to CorrespondenceEstimationBase */
222  clone() const
223  {
224  Ptr copy(new CorrespondenceEstimationBackProjection<PointSource,
225  PointTarget,
226  NormalT,
227  Scalar>(*this));
228  return (copy);
229  }
230 
231 protected:
237 
238  /** \brief Internal computation initialization. */
239  bool
240  initCompute();
241 
242 private:
243  /** \brief The normals computed at each point in the source cloud */
244  NormalsConstPtr source_normals_;
245 
246  /** \brief The normals computed at each point in the source cloud */
247  NormalsPtr source_normals_transformed_;
248 
249  /** \brief The normals computed at each point in the target cloud */
250  NormalsConstPtr target_normals_;
251 
252  /** \brief The number of neighbours to be considered in the target point cloud */
253  unsigned int k_;
254 };
255 } // namespace registration
256 } // namespace pcl
257 
258 #include <pcl/registration/impl/correspondence_estimation_backprojection.hpp>
pcl
Definition: convolution.h:46
pcl::Normal
A point structure representing normal coordinates and the surface curvature estimate.
Definition: point_types.hpp:812
pcl::registration::CorrespondenceEstimationBackProjection::getTargetNormals
NormalsConstPtr getTargetNormals() const
Get the normals of the target point cloud.
Definition: correspondence_estimation_backprojection.h:139
pcl::registration::CorrespondenceEstimationBackProjection::clone
virtual CorrespondenceEstimationBase< PointSource, PointTarget, Scalar >::Ptr clone() const
Clone and cast to CorrespondenceEstimationBase.
Definition: correspondence_estimation_backprojection.h:222
pcl::registration::CorrespondenceEstimationBackProjection::setKSearch
void setKSearch(unsigned int k)
Set the number of nearest neighbours to be considered in the target point cloud.
Definition: correspondence_estimation_backprojection.h:205
pcl::registration::CorrespondenceEstimationBackProjection::setSourceNormals
void setSourceNormals(const NormalsConstPtr &normals)
Set the normals computed on the source point cloud.
Definition: correspondence_estimation_backprojection.h:114
pcl::registration::CorrespondenceEstimationBackProjection
CorrespondenceEstimationBackprojection computes correspondences as points in the target cloud which h...
Definition: correspondence_estimation_backprojection.h:56
pcl::registration::CorrespondenceEstimationBackProjection::PointCloudTargetConstPtr
typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr
Definition: correspondence_estimation_backprojection.h:90
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:69
pcl::registration::CorrespondenceEstimationBase
Abstract CorrespondenceEstimationBase class.
Definition: correspondence_estimation.h:60
pcl::registration::CorrespondenceEstimationBase< PointSource, PointTarget, float >::tree_reciprocal_
KdTreeReciprocalPtr tree_reciprocal_
A pointer to the spatial search object used for the source dataset.
Definition: correspondence_estimation.h:300
pcl::PointCloud< PointSource >
pcl::registration::CorrespondenceEstimationBackProjection::~CorrespondenceEstimationBackProjection
virtual ~CorrespondenceEstimationBackProjection()
Empty destructor.
Definition: correspondence_estimation_backprojection.h:108
pcl::search::KdTree::Ptr
shared_ptr< KdTree< PointT, Tree > > Ptr
Definition: kdtree.h:75
pcl::registration::CorrespondenceEstimationBase< PointSource, PointTarget, float >::initComputeReciprocal
bool initComputeReciprocal()
Internal computation initialization for reciprocal correspondences.
Definition: correspondence_estimation.hpp:97
pcl::registration::CorrespondenceEstimationBackProjection::CorrespondenceEstimationBackProjection
CorrespondenceEstimationBackProjection()
Empty constructor.
Definition: correspondence_estimation_backprojection.h:101
pcl::registration::CorrespondenceEstimationBase< PointSource, PointTarget, float >::point_representation_
PointRepresentationConstPtr point_representation_
The point representation used (internal).
Definition: correspondence_estimation.h:309
pcl::registration::CorrespondenceEstimationBase< PointSource, PointTarget, float >::input_transformed_
PointCloudTargetPtr input_transformed_
The transformed input source point cloud dataset.
Definition: correspondence_estimation.h:312
pcl::registration::CorrespondenceEstimationBackProjection::requiresTargetNormals
bool requiresTargetNormals() const
See if this rejector requires target normals.
Definition: correspondence_estimation_backprojection.h:162
pcl::PCLPointCloud2::ConstPtr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Definition: PCLPointCloud2.h:36
pcl::registration::CorrespondenceEstimationBase::Ptr
shared_ptr< CorrespondenceEstimationBase< PointSource, PointTarget, Scalar > > Ptr
Definition: correspondence_estimation.h:63
pcl::registration::CorrespondenceEstimationBackProjection::Ptr
shared_ptr< CorrespondenceEstimationBackProjection< PointSource, PointTarget, NormalT, Scalar > > Ptr
Definition: correspondence_estimation_backprojection.h:62
pcl::registration::CorrespondenceEstimationBackProjection::getSourceNormals
NormalsConstPtr getSourceNormals() const
Get the normals of the source point cloud.
Definition: correspondence_estimation_backprojection.h:122
pcl::registration::CorrespondenceEstimationBackProjection::setTargetNormals
void setTargetNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Method for setting the target normals.
Definition: correspondence_estimation_backprojection.h:169
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::CorrespondenceEstimationBackProjection::determineReciprocalCorrespondences
virtual void determineReciprocalCorrespondences(pcl::Correspondences &correspondences, double max_distance=std::numeric_limits< double >::max())
Determine the reciprocal correspondences between input and target cloud.
Definition: correspondence_estimation_backprojection.hpp:168
pcl::registration::CorrespondenceEstimationBackProjection::requiresSourceNormals
bool requiresSourceNormals() const
See if this rejector requires source normals.
Definition: correspondence_estimation_backprojection.h:146
pcl::registration::CorrespondenceEstimationBackProjection::setTargetNormals
void setTargetNormals(const NormalsConstPtr &normals)
Set the normals computed on the target point cloud.
Definition: correspondence_estimation_backprojection.h:131
pcl::registration::CorrespondenceEstimationBackProjection::PointCloudSourceConstPtr
typename PointCloudSource::ConstPtr PointCloudSourceConstPtr
Definition: correspondence_estimation_backprojection.h:86
pcl::registration::CorrespondenceEstimationBackProjection::ConstPtr
shared_ptr< const CorrespondenceEstimationBackProjection< PointSource, PointTarget, NormalT, Scalar > > ConstPtr
Definition: correspondence_estimation_backprojection.h:66
pcl::registration::CorrespondenceEstimationBackProjection::NormalsConstPtr
typename PointCloudNormals::ConstPtr NormalsConstPtr
Definition: correspondence_estimation_backprojection.h:94
pcl::registration::CorrespondenceEstimationBase< PointSource, PointTarget, float >::corr_name_
std::string corr_name_
The correspondence estimation method name.
Definition: correspondence_estimation.h:294
pcl::registration::CorrespondenceEstimationBackProjection::setSourceNormals
void setSourceNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Blob method for setting the source normals.
Definition: correspondence_estimation_backprojection.h:153
pcl::PointCloud< PointSource >::Ptr
shared_ptr< PointCloud< PointSource > > Ptr
Definition: point_cloud.h:406
pcl::registration::CorrespondenceEstimationBackProjection::getKSearch
unsigned int getKSearch() const
Get the number of nearest neighbours considered in the target point cloud for computing correspondenc...
Definition: correspondence_estimation_backprojection.h:215
pcl::registration::CorrespondenceEstimationBackProjection::NormalsPtr
typename PointCloudNormals::Ptr NormalsPtr
Definition: correspondence_estimation_backprojection.h:93
pcl::PointCloud< PointSource >::ConstPtr
shared_ptr< const PointCloud< PointSource > > ConstPtr
Definition: point_cloud.h:407
pcl::registration::CorrespondenceEstimationBackProjection::determineCorrespondences
void determineCorrespondences(pcl::Correspondences &correspondences, double max_distance=std::numeric_limits< double >::max())
Determine the correspondences between input and target cloud.
Definition: correspondence_estimation_backprojection.hpp:69
pcl::registration::CorrespondenceEstimationBackProjection::KdTreePtr
typename KdTree::Ptr KdTreePtr
Definition: correspondence_estimation_backprojection.h:82
pcl::Correspondences
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
Definition: correspondence.h:89
pcl::registration::CorrespondenceEstimationBackProjection::PointCloudSourcePtr
typename PointCloudSource::Ptr PointCloudSourcePtr
Definition: correspondence_estimation_backprojection.h:85
pcl::registration::CorrespondenceEstimationBackProjection::PointCloudTargetPtr
typename PointCloudTarget::Ptr PointCloudTargetPtr
Definition: correspondence_estimation_backprojection.h:89
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:167
pcl::registration::CorrespondenceEstimationBackProjection::initCompute
bool initCompute()
Internal computation initialization.
Definition: correspondence_estimation_backprojection.hpp:52