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