Point Cloud Library (PCL)  1.9.1
correspondence_estimation_normal_shooting.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id$
38  *
39  */
40 
41 #ifndef PCL_REGISTRATION_CORRESPONDENCE_ESTIMATION_NORMAL_SHOOTING_H_
42 #define PCL_REGISTRATION_CORRESPONDENCE_ESTIMATION_NORMAL_SHOOTING_H_
43 
44 #include <pcl/registration/correspondence_types.h>
45 #include <pcl/registration/correspondence_estimation.h>
46 
47 namespace pcl
48 {
49  namespace registration
50  {
51  /** \brief @b CorrespondenceEstimationNormalShooting computes
52  * correspondences as points in the target cloud which have minimum
53  * distance to normals computed on the input cloud
54  *
55  * Code example:
56  *
57  * \code
58  * pcl::PointCloud<pcl::PointNormal>::Ptr source, target;
59  * // ... read or fill in source and target
60  * pcl::CorrespondenceEstimationNormalShooting<pcl::PointNormal, pcl::PointNormal, pcl::PointNormal> est;
61  * est.setInputSource (source);
62  * est.setSourceNormals (source);
63  *
64  * est.setInputTarget (target);
65  *
66  * // Test the first 10 correspondences for each point in source, and return the best
67  * est.setKSearch (10);
68  *
69  * pcl::Correspondences all_correspondences;
70  * // Determine all correspondences
71  * est.determineCorrespondences (all_correspondences);
72  * \endcode
73  *
74  * \author Aravindhan K. Krishnan, Radu B. Rusu
75  * \ingroup registration
76  */
77  template <typename PointSource, typename PointTarget, typename NormalT, typename Scalar = float>
78  class CorrespondenceEstimationNormalShooting : public CorrespondenceEstimationBase<PointSource, PointTarget, Scalar>
79  {
80  public:
81  typedef boost::shared_ptr<CorrespondenceEstimationNormalShooting<PointSource, PointTarget, NormalT, Scalar> > Ptr;
82  typedef boost::shared_ptr<const CorrespondenceEstimationNormalShooting<PointSource, PointTarget, NormalT, Scalar> > ConstPtr;
83 
93 
96 
100 
104 
108 
109  /** \brief Empty constructor.
110  *
111  * \note
112  * Sets the number of neighbors to be considered in the target point cloud (k_) to 10.
113  */
115  : source_normals_ ()
116  , source_normals_transformed_ ()
117  , k_ (10)
118  {
119  corr_name_ = "CorrespondenceEstimationNormalShooting";
120  }
121 
122  /** \brief Empty destructor */
124 
125  /** \brief Set the normals computed on the source point cloud
126  * \param[in] normals the normals computed for the source cloud
127  */
128  inline void
129  setSourceNormals (const NormalsConstPtr &normals) { source_normals_ = normals; }
130 
131  /** \brief Get the normals of the source point cloud
132  */
133  inline NormalsConstPtr
134  getSourceNormals () const { return (source_normals_); }
135 
136 
137  /** \brief See if this rejector requires source normals */
138  bool
140  { return (true); }
141 
142  /** \brief Blob method for setting the source normals */
143  void
145  {
146  NormalsPtr cloud (new PointCloudNormals);
147  fromPCLPointCloud2 (*cloud2, *cloud);
148  setSourceNormals (cloud);
149  }
150 
151  /** \brief Determine the correspondences between input and target cloud.
152  * \param[out] correspondences the found correspondences (index of query point, index of target point, distance)
153  * \param[in] max_distance maximum distance between the normal on the source point cloud and the corresponding point in the target
154  * point cloud
155  */
156  void
158  double max_distance = std::numeric_limits<double>::max ());
159 
160  /** \brief Determine the reciprocal correspondences between input and target cloud.
161  * A correspondence is considered reciprocal if both Src_i has Tgt_i as a
162  * correspondence, and Tgt_i has Src_i as one.
163  *
164  * \param[out] correspondences the found correspondences (index of query and target point, distance)
165  * \param[in] max_distance maximum allowed distance between correspondences
166  */
167  virtual void
169  double max_distance = std::numeric_limits<double>::max ());
170 
171  /** \brief Set the number of nearest neighbours to be considered in the target
172  * point cloud. By default, we use k = 10 nearest neighbors.
173  *
174  * \param[in] k the number of nearest neighbours to be considered
175  */
176  inline void
177  setKSearch (unsigned int k) { k_ = k; }
178 
179  /** \brief Get the number of nearest neighbours considered in the target point
180  * cloud for computing correspondences. By default we use k = 10 nearest
181  * neighbors.
182  */
183  inline unsigned int
184  getKSearch () const { return (k_); }
185 
186  /** \brief Clone and cast to CorrespondenceEstimationBase */
187  virtual boost::shared_ptr< CorrespondenceEstimationBase<PointSource, PointTarget, Scalar> >
188  clone () const
189  {
191  return (copy);
192  }
193 
194  protected:
195 
200 
201  /** \brief Internal computation initialization. */
202  bool
203  initCompute ();
204 
205  private:
206 
207  /** \brief The normals computed at each point in the source cloud */
208  NormalsConstPtr source_normals_;
209 
210  /** \brief The normals computed at each point in the source cloud */
211  NormalsPtr source_normals_transformed_;
212 
213  /** \brief The number of neighbours to be considered in the target point cloud */
214  unsigned int k_;
215  };
216  }
217 }
218 
219 #include <pcl/registration/impl/correspondence_estimation_normal_shooting.hpp>
220 
221 #endif /* PCL_REGISTRATION_CORRESPONDENCE_ESTIMATION_NORMAL_SHOOTING_H_ */
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
unsigned int getKSearch() const
Get the number of nearest neighbours considered in the target point cloud for computing correspondenc...
virtual void determineReciprocalCorrespondences(pcl::Correspondences &correspondences, double max_distance=std::numeric_limits< double >::max())
Determine the reciprocal correspondences between input and target cloud.
std::string corr_name_
The correspondence estimation method name.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
void setSourceNormals(const NormalsConstPtr &normals)
Set the normals computed on the source point cloud.
void setSourceNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Blob method for setting the source normals.
virtual boost::shared_ptr< CorrespondenceEstimationBase< PointSource, PointTarget, Scalar > > clone() const
Clone and cast to CorrespondenceEstimationBase.
CorrespondenceEstimationNormalShooting computes correspondences as points in the target cloud which h...
boost::shared_ptr< PointCloud< PointSource > > Ptr
Definition: point_cloud.h:428
bool requiresSourceNormals() const
See if this rejector requires source normals.
boost::shared_ptr< KdTree< PointT, Tree > > Ptr
Definition: kdtree.h:79
void setKSearch(unsigned int k)
Set the number of nearest neighbours to be considered in the target point cloud.
boost::shared_ptr< const CorrespondenceEstimationNormalShooting< PointSource, PointTarget, NormalT, Scalar > > ConstPtr
PCL base class.
Definition: pcl_base.h:68
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
boost::shared_ptr< const PointCloud< PointSource > > ConstPtr
Definition: point_cloud.h:429
boost::shared_ptr< ::pcl::PCLPointCloud2 const > ConstPtr
void determineCorrespondences(pcl::Correspondences &correspondences, double max_distance=std::numeric_limits< double >::max())
Determine the correspondences between input and target cloud.
boost::shared_ptr< CorrespondenceEstimationNormalShooting< PointSource, PointTarget, NormalT, Scalar > > Ptr
NormalsConstPtr getSourceNormals() const
Get the normals of the source point cloud.
Abstract CorrespondenceEstimationBase class.