Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
correspondence_rejection.h
Go to the documentation of this file.
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  *
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 Willow Garage, Inc. 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  *
37  */
38 
39 #ifndef PCL_REGISTRATION_CORRESPONDENCE_REJECTION_H_
40 #define PCL_REGISTRATION_CORRESPONDENCE_REJECTION_H_
41 
44 #include <pcl/console/print.h>
45 #include <pcl/point_cloud.h>
47 
48 namespace pcl
49 {
50  namespace registration
51  {
57  {
58  public:
60  CorrespondenceRejector () : rejection_name_ (), input_correspondences_ () {};
61 
64 
68  virtual inline void
70  {
71  input_correspondences_ = correspondences;
72  };
73 
78  getInputCorrespondences () { return input_correspondences_; };
79 
83  inline void
85  {
86  if (!input_correspondences_ || (input_correspondences_->empty ()))
87  return;
88 
89  applyRejection (correspondences);
90  }
91 
99  virtual inline void
100  getRemainingCorrespondences (const pcl::Correspondences& original_correspondences,
101  pcl::Correspondences& remaining_correspondences) = 0;
102 
111  inline void
113  std::vector<int>& indices)
114  {
115  if (!input_correspondences_ || input_correspondences_->empty ())
116  {
117  PCL_WARN ("[pcl::%s::getRejectedQueryIndices] Input correspondences not set (lookup of rejected correspondences _not_ possible).\n", getClassName ().c_str ());
118  return;
119  }
120 
121  pcl::getRejectedQueryIndices(*input_correspondences_, correspondences, indices);
122  }
123 
124  protected:
125 
127  std::string rejection_name_;
128 
130  CorrespondencesConstPtr input_correspondences_;
131 
133  inline const std::string&
134  getClassName () const { return (rejection_name_); }
135 
137  virtual void
138  applyRejection (Correspondences &correspondences) = 0;
139  };
140 
146  {
147  public:
149  virtual double getCorrespondenceScore (int index) = 0;
150  virtual double getCorrespondenceScore (const pcl::Correspondence &) = 0;
151  };
152 
157  template <typename PointT, typename NormalT=pcl::PointNormal>
159  {
160  typedef typename pcl::PointCloud<PointT>::ConstPtr PointCloudConstPtr;
161  typedef typename pcl::KdTree<PointT>::Ptr KdTreePtr;
162  typedef typename pcl::PointCloud<NormalT>::ConstPtr NormalsPtr;
163 
164  public:
165 
167  DataContainer () : input_ (), target_ ()
168  {
169  tree_.reset (new pcl::KdTreeFLANN<PointT>);
170  }
171 
176  inline void
177  setInputCloud (const PointCloudConstPtr &cloud)
178  {
179  input_ = cloud;
180  }
181 
186  inline void
187  setInputTarget (const PointCloudConstPtr &target)
188  {
189  target_ = target;
190  tree_->setInputCloud (target_);
191  }
192 
196  inline void
197  setInputNormals (const NormalsPtr &normals) { input_normals_ = normals; }
198 
202  inline void
203  setTargetNormals (const NormalsPtr &normals) { target_normals_ = normals; }
204 
206  inline NormalsPtr
207  getInputNormals () { return input_normals_; }
208 
210  inline NormalsPtr
211  getTargetNormals () { return target_normals_; }
212 
216  inline double
218  {
219  std::vector<int> indices (1);
220  std::vector<float> distances (1);
221  if (tree_->nearestKSearch (input_->points[index], 1, indices, distances))
222  {
223  return (distances[0]);
224  }
225  else
226  return (std::numeric_limits<double>::max ());
227  }
228 
232  inline double
234  {
235  // Get the source and the target feature from the list
236  const PointT &src = input_->points[corr.index_query];
237  const PointT &tgt = target_->points[corr.index_match];
238 
239  return ((src.getVector4fMap () - tgt.getVector4fMap ()).squaredNorm ());
240  }
241 
247  double
249  {
250  //assert ( (input_normals_->points.size () != 0) && (target_normals_->points.size () != 0) && "Normals are not set for the input and target point clouds");
251  assert ( input_normals_ && target_normals_ && "Normals are not set for the input and target point clouds");
252  const NormalT &src = input_normals_->points[corr.index_query];
253  const NormalT &tgt = target_normals_->points[corr.index_match];
254  double score = (src.normal[0] * tgt.normal[0]) + (src.normal[1] * tgt.normal[1]) + (src.normal[2] * tgt.normal[2]);
255  return score;
256  }
257  private:
258 
260  PointCloudConstPtr input_;
261 
263  PointCloudConstPtr target_;
264 
266  NormalsPtr input_normals_;
267 
269  NormalsPtr target_normals_;
270 
272  KdTreePtr tree_;
273  };
274  }
275 }
276 
277 #endif /* PCL_REGISTRATION_CORRESPONDENCE_REJECTION_H_ */
278