Point Cloud Library (PCL)  1.14.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_()
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_{10};
254 };
255 } // namespace registration
256 } // namespace pcl
257 
258 #include <pcl/registration/impl/correspondence_estimation_backprojection.hpp>
PCL base class.
Definition: pcl_base.h:70
shared_ptr< PointCloud< PointSource > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointSource > > ConstPtr
Definition: point_cloud.h:414
CorrespondenceEstimationBackprojection computes correspondences as points in the target cloud which h...
void setSourceNormals(const NormalsConstPtr &normals)
Set the normals computed on the source point cloud.
virtual CorrespondenceEstimationBase< PointSource, PointTarget, Scalar >::Ptr clone() const
Clone and cast to CorrespondenceEstimationBase.
void setTargetNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Method for setting the target normals.
shared_ptr< CorrespondenceEstimationBackProjection< PointSource, PointTarget, NormalT, Scalar > > Ptr
bool requiresTargetNormals() const
See if this rejector requires target normals.
void setSourceNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Blob method for setting the source normals.
NormalsConstPtr getSourceNormals() const
Get the normals of the source point cloud.
shared_ptr< const CorrespondenceEstimationBackProjection< PointSource, PointTarget, NormalT, Scalar > > ConstPtr
void setKSearch(unsigned int k)
Set the number of nearest neighbours to be considered in the target point cloud.
unsigned int getKSearch() const
Get the number of nearest neighbours considered in the target point cloud for computing correspondenc...
NormalsConstPtr getTargetNormals() const
Get the normals of the target point cloud.
virtual void determineReciprocalCorrespondences(pcl::Correspondences &correspondences, double max_distance=std::numeric_limits< double >::max())
Determine the reciprocal correspondences between input and target cloud.
virtual ~CorrespondenceEstimationBackProjection()=default
Empty destructor.
bool requiresSourceNormals() const
See if this rejector requires source normals.
void determineCorrespondences(pcl::Correspondences &correspondences, double max_distance=std::numeric_limits< double >::max())
Determine the correspondences between input and target cloud.
void setTargetNormals(const NormalsConstPtr &normals)
Set the normals computed on the target point cloud.
Abstract CorrespondenceEstimationBase class.
PointCloudTargetPtr input_transformed_
The transformed input source point cloud dataset.
PointRepresentationConstPtr point_representation_
The target point representation used (internal).
KdTreeReciprocalPtr tree_reciprocal_
A pointer to the spatial search object used for the source dataset.
bool initComputeReciprocal()
Internal computation initialization for reciprocal correspondences.
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
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map, const std::uint8_t *msg_data)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map.
Definition: conversions.h:229
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
A point structure representing normal coordinates and the surface curvature estimate.
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr