Point Cloud Library (PCL)  1.7.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  /** \brief Determine the correspondences between input and target cloud.
137  * \param[out] correspondences the found correspondences (index of query point, index of target point, distance)
138  * \param[in] max_distance maximum distance between the normal on the source point cloud and the corresponding point in the target
139  * point cloud
140  */
141  void
143  double max_distance = std::numeric_limits<double>::max ());
144 
145  /** \brief Determine the reciprocal correspondences between input and target cloud.
146  * A correspondence is considered reciprocal if both Src_i has Tgt_i as a
147  * correspondence, and Tgt_i has Src_i as one.
148  *
149  * \param[out] correspondences the found correspondences (index of query and target point, distance)
150  * \param[in] max_distance maximum allowed distance between correspondences
151  */
152  virtual void
154  double max_distance = std::numeric_limits<double>::max ());
155 
156  /** \brief Set the number of nearest neighbours to be considered in the target
157  * point cloud. By default, we use k = 10 nearest neighbors.
158  *
159  * \param[in] k the number of nearest neighbours to be considered
160  */
161  inline void
162  setKSearch (unsigned int k) { k_ = k; }
163 
164  /** \brief Get the number of nearest neighbours considered in the target point
165  * cloud for computing correspondences. By default we use k = 10 nearest
166  * neighbors.
167  */
168  inline void
169  getKSearch () const { return (k_); }
170 
171  protected:
172 
177 
178  /** \brief Internal computation initalization. */
179  bool
180  initCompute ();
181 
182  private:
183 
184  /** \brief The normals computed at each point in the source cloud */
185  NormalsConstPtr source_normals_;
186 
187  /** \brief The normals computed at each point in the source cloud */
188  NormalsPtr source_normals_transformed_;
189 
190  /** \brief The number of neighbours to be considered in the target point cloud */
191  unsigned int k_;
192  };
193  }
194 }
195 
196 #include <pcl/registration/impl/correspondence_estimation_normal_shooting.hpp>
197 
198 #endif /* PCL_REGISTRATION_CORRESPONDENCE_ESTIMATION_NORMAL_SHOOTING_H_ */