Point Cloud Library (PCL)  1.11.0
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_types.h>
43 #include <pcl/registration/correspondence_estimation.h>
44 
45 namespace pcl
46 {
47  namespace registration
48  {
49  /** \brief @b CorrespondenceEstimationBackprojection computes
50  * correspondences as points in the target cloud which have minimum
51  * \author Suat Gedikli
52  * \ingroup registration
53  */
54  template <typename PointSource, typename PointTarget, typename NormalT, typename Scalar = float>
55  class CorrespondenceEstimationBackProjection : public CorrespondenceEstimationBase <PointSource, PointTarget, Scalar>
56  {
57  public:
58  using Ptr = shared_ptr<CorrespondenceEstimationBackProjection<PointSource, PointTarget, NormalT, Scalar> >;
59  using ConstPtr = shared_ptr<const CorrespondenceEstimationBackProjection<PointSource, PointTarget, NormalT, Scalar> >;
60 
70 
72  using KdTreePtr = typename KdTree::Ptr;
73 
77 
81 
85 
86  /** \brief Empty constructor.
87  *
88  * \note
89  * Sets the number of neighbors to be considered in the target point cloud (k_) to 10.
90  */
92  : source_normals_ ()
93  , source_normals_transformed_ ()
94  , target_normals_ ()
95  , k_ (10)
96  {
97  corr_name_ = "CorrespondenceEstimationBackProjection";
98  }
99 
100  /** \brief Empty destructor */
102 
103  /** \brief Set the normals computed on the source point cloud
104  * \param[in] normals the normals computed for the source cloud
105  */
106  inline void
107  setSourceNormals (const NormalsConstPtr &normals) { source_normals_ = normals; }
108 
109  /** \brief Get the normals of the source point cloud
110  */
111  inline NormalsConstPtr
112  getSourceNormals () const { return (source_normals_); }
113 
114  /** \brief Set the normals computed on the target point cloud
115  * \param[in] normals the normals computed for the target cloud
116  */
117  inline void
118  setTargetNormals (const NormalsConstPtr &normals) { target_normals_ = normals; }
119 
120  /** \brief Get the normals of the target point cloud
121  */
122  inline NormalsConstPtr
123  getTargetNormals () const { return (target_normals_); }
124 
125 
126  /** \brief See if this rejector requires source normals */
127  bool
129  { return (true); }
130 
131  /** \brief Blob method for setting the source normals */
132  void
134  {
135  NormalsPtr cloud (new PointCloudNormals);
136  fromPCLPointCloud2 (*cloud2, *cloud);
137  setSourceNormals (cloud);
138  }
139 
140  /** \brief See if this rejector requires target normals*/
141  bool
143  { return (true); }
144 
145  /** \brief Method for setting the target normals */
146  void
148  {
149  NormalsPtr cloud (new PointCloudNormals);
150  fromPCLPointCloud2 (*cloud2, *cloud);
151  setTargetNormals (cloud);
152  }
153 
154  /** \brief Determine the correspondences between input and target cloud.
155  * \param[out] correspondences the found correspondences (index of query point, index of target point, distance)
156  * \param[in] max_distance maximum distance between the normal on the source point cloud and the corresponding point in the target
157  * point cloud
158  */
159  void
161  double max_distance = std::numeric_limits<double>::max ());
162 
163  /** \brief Determine the reciprocal correspondences between input and target cloud.
164  * A correspondence is considered reciprocal if both Src_i has Tgt_i as a
165  * correspondence, and Tgt_i has Src_i as one.
166  *
167  * \param[out] correspondences the found correspondences (index of query and target point, distance)
168  * \param[in] max_distance maximum allowed distance between correspondences
169  */
170  virtual void
172  double max_distance = std::numeric_limits<double>::max ());
173 
174  /** \brief Set the number of nearest neighbours to be considered in the target
175  * point cloud. By default, we use k = 10 nearest neighbors.
176  *
177  * \param[in] k the number of nearest neighbours to be considered
178  */
179  inline void
180  setKSearch (unsigned int k) { k_ = k; }
181 
182  /** \brief Get the number of nearest neighbours considered in the target point
183  * cloud for computing correspondences. By default we use k = 10 nearest
184  * neighbors.
185  */
186  inline unsigned int
187  getKSearch () const { return (k_); }
188 
189  /** \brief Clone and cast to CorrespondenceEstimationBase */
191  clone () const
192  {
194  return (copy);
195  }
196 
197  protected:
198 
203 
204  /** \brief Internal computation initialization. */
205  bool
206  initCompute ();
207 
208  private:
209 
210  /** \brief The normals computed at each point in the source cloud */
211  NormalsConstPtr source_normals_;
212 
213  /** \brief The normals computed at each point in the source cloud */
214  NormalsPtr source_normals_transformed_;
215 
216  /** \brief The normals computed at each point in the target cloud */
217  NormalsConstPtr target_normals_;
218 
219  /** \brief The number of neighbours to be considered in the target point cloud */
220  unsigned int k_;
221  };
222  }
223 }
224 
225 #include <pcl/registration/impl/correspondence_estimation_backprojection.hpp>
pcl
Definition: convolution.h:46
pcl::registration::CorrespondenceEstimationBackProjection::getTargetNormals
NormalsConstPtr getTargetNormals() const
Get the normals of the target point cloud.
Definition: correspondence_estimation_backprojection.h:123
pcl::registration::CorrespondenceEstimationBackProjection::clone
virtual CorrespondenceEstimationBase< PointSource, PointTarget, Scalar >::Ptr clone() const
Clone and cast to CorrespondenceEstimationBase.
Definition: correspondence_estimation_backprojection.h:191
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:180
pcl::registration::CorrespondenceEstimationBackProjection::setSourceNormals
void setSourceNormals(const NormalsConstPtr &normals)
Set the normals computed on the source point cloud.
Definition: correspondence_estimation_backprojection.h:107
pcl::registration::CorrespondenceEstimationBackProjection
CorrespondenceEstimationBackprojection computes correspondences as points in the target cloud which h...
Definition: correspondence_estimation_backprojection.h:55
pcl::registration::CorrespondenceEstimationBackProjection::PointCloudTargetConstPtr
typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr
Definition: correspondence_estimation_backprojection.h:80
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:69
pcl::registration::CorrespondenceEstimationBase
Abstract CorrespondenceEstimationBase class.
Definition: correspondence_estimation.h:63
pcl::PointCloud< PointSource >
pcl::registration::CorrespondenceEstimationBackProjection::~CorrespondenceEstimationBackProjection
virtual ~CorrespondenceEstimationBackProjection()
Empty destructor.
Definition: correspondence_estimation_backprojection.h:101
pcl::search::KdTree::Ptr
shared_ptr< KdTree< PointT, Tree > > Ptr
Definition: kdtree.h:75
pcl::registration::CorrespondenceEstimationBackProjection::CorrespondenceEstimationBackProjection
CorrespondenceEstimationBackProjection()
Empty constructor.
Definition: correspondence_estimation_backprojection.h:91
pcl::registration::CorrespondenceEstimationBackProjection::requiresTargetNormals
bool requiresTargetNormals() const
See if this rejector requires target normals.
Definition: correspondence_estimation_backprojection.h:142
pcl::PCLPointCloud2::ConstPtr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Definition: PCLPointCloud2.h:35
pcl::registration::CorrespondenceEstimationBase::Ptr
shared_ptr< CorrespondenceEstimationBase< PointSource, PointTarget, Scalar > > Ptr
Definition: correspondence_estimation.h:66
pcl::registration::CorrespondenceEstimationBackProjection::Ptr
shared_ptr< CorrespondenceEstimationBackProjection< PointSource, PointTarget, NormalT, Scalar > > Ptr
Definition: correspondence_estimation_backprojection.h:58
pcl::registration::CorrespondenceEstimationBackProjection::getSourceNormals
NormalsConstPtr getSourceNormals() const
Get the normals of the source point cloud.
Definition: correspondence_estimation_backprojection.h:112
pcl::registration::CorrespondenceEstimationBackProjection::setTargetNormals
void setTargetNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Method for setting the target normals.
Definition: correspondence_estimation_backprojection.h:147
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:163
pcl::registration::CorrespondenceEstimationBackProjection::requiresSourceNormals
bool requiresSourceNormals() const
See if this rejector requires source normals.
Definition: correspondence_estimation_backprojection.h:128
pcl::registration::CorrespondenceEstimationBackProjection::setTargetNormals
void setTargetNormals(const NormalsConstPtr &normals)
Set the normals computed on the target point cloud.
Definition: correspondence_estimation_backprojection.h:118
pcl::registration::CorrespondenceEstimationBackProjection::PointCloudSourceConstPtr
typename PointCloudSource::ConstPtr PointCloudSourceConstPtr
Definition: correspondence_estimation_backprojection.h:76
pcl::registration::CorrespondenceEstimationBackProjection::ConstPtr
shared_ptr< const CorrespondenceEstimationBackProjection< PointSource, PointTarget, NormalT, Scalar > > ConstPtr
Definition: correspondence_estimation_backprojection.h:59
pcl::registration::CorrespondenceEstimationBackProjection::NormalsConstPtr
typename PointCloudNormals::ConstPtr NormalsConstPtr
Definition: correspondence_estimation_backprojection.h:84
pcl::registration::CorrespondenceEstimationBase< PointSource, PointTarget, float >::corr_name_
std::string corr_name_
The correspondence estimation method name.
Definition: correspondence_estimation.h:285
pcl::registration::CorrespondenceEstimationBackProjection::setSourceNormals
void setSourceNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Blob method for setting the source normals.
Definition: correspondence_estimation_backprojection.h:133
pcl::PointCloud< PointSource >::Ptr
shared_ptr< PointCloud< PointSource > > Ptr
Definition: point_cloud.h:428
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:187
pcl::registration::CorrespondenceEstimationBackProjection::NormalsPtr
typename PointCloudNormals::Ptr NormalsPtr
Definition: correspondence_estimation_backprojection.h:83
pcl::PointCloud< PointSource >::ConstPtr
shared_ptr< const PointCloud< PointSource > > ConstPtr
Definition: point_cloud.h:429
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:66
pcl::registration::CorrespondenceEstimationBackProjection::KdTreePtr
typename KdTree::Ptr KdTreePtr
Definition: correspondence_estimation_backprojection.h:72
pcl::Correspondences
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
Definition: correspondence.h:88
pcl::registration::CorrespondenceEstimationBackProjection::PointCloudSourcePtr
typename PointCloudSource::Ptr PointCloudSourcePtr
Definition: correspondence_estimation_backprojection.h:75
pcl::registration::CorrespondenceEstimationBackProjection::PointCloudTargetPtr
typename PointCloudTarget::Ptr PointCloudTargetPtr
Definition: correspondence_estimation_backprojection.h:79
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::registration::CorrespondenceEstimationBackProjection::initCompute
bool initCompute()
Internal computation initialization.
Definition: correspondence_estimation_backprojection.hpp:53