Point Cloud Library (PCL)  1.10.0-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_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:
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>
shared_ptr< KdTree< PointT, Tree > > Ptr
Definition: kdtree.h:78
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
void setSourceNormals(const NormalsConstPtr &normals)
Set the normals computed on the source point cloud.
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition: kdtree.h:61
unsigned int getKSearch() const
Get the number of nearest neighbours considered in the target point cloud for computing correspondenc...
CorrespondenceEstimationBackprojection computes correspondences as points in the target cloud which h...
shared_ptr< PointCloud< PointSource > > Ptr
Definition: point_cloud.h:415
typename PointCloudSource::ConstPtr PointCloudSourceConstPtr
std::string corr_name_
The correspondence estimation method name.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
shared_ptr< CorrespondenceEstimationBase< PointSource, PointTarget, Scalar > > Ptr
shared_ptr< const CorrespondenceEstimationBase< PointSource, PointTarget, Scalar > > ConstPtr
bool requiresTargetNormals() const
See if this rejector requires target 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.
PCL base class.
Definition: pcl_base.h:69
typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr
void setTargetNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Method for setting the target normals.
virtual CorrespondenceEstimationBase< PointSource, PointTarget, Scalar >::Ptr clone() const
Clone and cast to CorrespondenceEstimationBase.
shared_ptr< const PointCloud< PointSource > > ConstPtr
Definition: point_cloud.h:416
NormalsConstPtr getSourceNormals() const
Get the normals of the source point cloud.
void setKSearch(unsigned int k)
Set the number of nearest neighbours to be considered in the target point cloud.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
virtual void determineReciprocalCorrespondences(pcl::Correspondences &correspondences, double max_distance=std::numeric_limits< double >::max())
Determine the reciprocal correspondences between input and target cloud.
bool requiresSourceNormals() const
See if this rejector requires source normals.
boost::shared_ptr< T > shared_ptr
Alias for boost::shared_ptr.
Definition: pcl_macros.h:90
NormalsConstPtr getTargetNormals() const
Get the normals of the target point cloud.
void setSourceNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Blob method for setting the source normals.
Abstract CorrespondenceEstimationBase class.