Point Cloud Library (PCL)  1.7.2
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 void
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 initalization. */
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_ */