Point Cloud Library (PCL)  1.7.0
correspondence_rejection_distance.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 #ifndef PCL_REGISTRATION_CORRESPONDENCE_REJECTION_DISTANCE_H_
41 #define PCL_REGISTRATION_CORRESPONDENCE_REJECTION_DISTANCE_H_
42 
43 #include <pcl/registration/correspondence_rejection.h>
44 
45 namespace pcl
46 {
47  namespace registration
48  {
49  /**
50  * @b CorrespondenceRejectorDistance implements a simple correspondence
51  * rejection method based on thresholding the distances between the
52  * correspondences.
53  *
54  * \note If \ref setInputCloud and \ref setInputTarget are given, then the
55  * distances between correspondences will be estimated using the given XYZ
56  * data, and not read from the set of input correspondences.
57  *
58  * \author Dirk Holz, Radu B. Rusu
59  * \ingroup registration
60  */
62  {
66 
67  public:
68  typedef boost::shared_ptr<CorrespondenceRejectorDistance> Ptr;
69  typedef boost::shared_ptr<const CorrespondenceRejectorDistance> ConstPtr;
70 
71  /** \brief Empty constructor. */
72  CorrespondenceRejectorDistance () : max_distance_(std::numeric_limits<float>::max ()),
73  data_container_ ()
74  {
75  rejection_name_ = "CorrespondenceRejectorDistance";
76  }
77 
78  /** \brief Empty destructor */
80 
81  /** \brief Get a list of valid correspondences after rejection from the original set of correspondences.
82  * \param[in] original_correspondences the set of initial correspondences given
83  * \param[out] remaining_correspondences the resultant filtered set of remaining correspondences
84  */
85  void
86  getRemainingCorrespondences (const pcl::Correspondences& original_correspondences,
87  pcl::Correspondences& remaining_correspondences);
88 
89  /** \brief Set the maximum distance used for thresholding in correspondence rejection.
90  * \param[in] distance Distance to be used as maximum distance between correspondences.
91  * Correspondences with larger distances are rejected.
92  * \note Internally, the distance will be stored squared.
93  */
94  virtual inline void
95  setMaximumDistance (float distance) { max_distance_ = distance * distance; };
96 
97  /** \brief Get the maximum distance used for thresholding in correspondence rejection. */
98  inline float
99  getMaximumDistance () { return std::sqrt (max_distance_); };
100 
101  /** \brief Provide a source point cloud dataset (must contain XYZ
102  * data!), used to compute the correspondence distance.
103  * \param[in] cloud a cloud containing XYZ data
104  */
105  template <typename PointT> inline void
107  {
108  PCL_WARN ("[pcl::registration::%s::setInputCloud] setInputCloud is deprecated. Please use setInputSource instead.\n", getClassName ().c_str ());
109  if (!data_container_)
110  data_container_.reset (new DataContainer<PointT>);
111  boost::static_pointer_cast<DataContainer<PointT> > (data_container_)->setInputSource (cloud);
112  }
113 
114  /** \brief Provide a source point cloud dataset (must contain XYZ
115  * data!), used to compute the correspondence distance.
116  * \param[in] cloud a cloud containing XYZ data
117  */
118  template <typename PointT> inline void
120  {
121  if (!data_container_)
122  data_container_.reset (new DataContainer<PointT>);
123  boost::static_pointer_cast<DataContainer<PointT> > (data_container_)->setInputSource (cloud);
124  }
125 
126  /** \brief Provide a target point cloud dataset (must contain XYZ
127  * data!), used to compute the correspondence distance.
128  * \param[in] target a cloud containing XYZ data
129  */
130  template <typename PointT> inline void
132  {
133  if (!data_container_)
134  data_container_.reset (new DataContainer<PointT>);
135  boost::static_pointer_cast<DataContainer<PointT> > (data_container_)->setInputTarget (target);
136  }
137 
138  /** \brief Provide a pointer to the search object used to find correspondences in
139  * the target cloud.
140  * \param[in] tree a pointer to the spatial search object.
141  * \param[in] force_no_recompute If set to true, this tree will NEVER be
142  * recomputed, regardless of calls to setInputTarget. Only use if you are
143  * confident that the tree will be set correctly.
144  */
145  template <typename PointT> inline void
146  setSearchMethodTarget (const boost::shared_ptr<pcl::search::KdTree<PointT> > &tree,
147  bool force_no_recompute = false)
148  {
149  boost::static_pointer_cast< DataContainer<PointT> >
150  (data_container_)->setSearchMethodTarget (tree, force_no_recompute );
151  }
152 
153 
154  protected:
155 
156  /** \brief Apply the rejection algorithm.
157  * \param[out] correspondences the set of resultant correspondences.
158  */
159  inline void
161  {
162  getRemainingCorrespondences (*input_correspondences_, correspondences);
163  }
164 
165  /** \brief The maximum distance threshold between two correspondent points in source <-> target. If the
166  * distance is larger than this threshold, the points will not be ignored in the alignment process.
167  */
169 
170  typedef boost::shared_ptr<DataContainerInterface> DataContainerPtr;
171 
172  /** \brief A pointer to the DataContainer object containing the input and target point clouds */
174  };
175 
176  }
177 }
178 
179 #include <pcl/registration/impl/correspondence_rejection_distance.hpp>
180 
181 #endif /* PCL_REGISTRATION_CORRESPONDENCE_REJECTION_DISTANCE_H_ */
DataContainer is a container for the input and target point clouds and implements the interface to co...
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition: kdtree.h:62
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
void setSearchMethodTarget(const boost::shared_ptr< pcl::search::KdTree< PointT > > &tree, bool force_no_recompute=false)
Provide a pointer to the search object used to find correspondences in the target cloud...
virtual void setMaximumDistance(float distance)
Set the maximum distance used for thresholding in correspondence rejection.
CorrespondenceRejector represents the base class for correspondence rejection methods ...
boost::shared_ptr< CorrespondenceRejectorDistance > Ptr
float getMaximumDistance()
Get the maximum distance used for thresholding in correspondence rejection.
boost::shared_ptr< DataContainerInterface > DataContainerPtr
DataContainerPtr data_container_
A pointer to the DataContainer object containing the input and target point clouds.
const std::string & getClassName() const
Get a string representation of the name of this class.
float max_distance_
The maximum distance threshold between two correspondent points in source &lt;-&gt; target.
void applyRejection(pcl::Correspondences &correspondences)
Apply the rejection algorithm.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
void setInputTarget(const typename pcl::PointCloud< PointT >::ConstPtr &target)
Provide a target point cloud dataset (must contain XYZ data!), used to compute the correspondence dis...
CorrespondenceRejectorDistance implements a simple correspondence rejection method based on threshold...
void setInputSource(const typename pcl::PointCloud< PointT >::ConstPtr &cloud)
Provide a source point cloud dataset (must contain XYZ data!), used to compute the correspondence dis...
CorrespondencesConstPtr input_correspondences_
The input correspondences.
std::string rejection_name_
The name of the rejection method.
void setInputCloud(const typename pcl::PointCloud< PointT >::ConstPtr &cloud)
Provide a source point cloud dataset (must contain XYZ data!), used to compute the correspondence dis...
boost::shared_ptr< const CorrespondenceRejectorDistance > ConstPtr