Point Cloud Library (PCL)  1.11.1
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 
41 #pragma once
42 
43 #include <pcl/registration/correspondence_rejection.h>
44 #include <pcl/memory.h> // for static_pointer_cast
45 
46 
47 namespace pcl
48 {
49  namespace registration
50  {
51  /**
52  * @b CorrespondenceRejectorDistance implements a simple correspondence
53  * rejection method based on thresholding the distances between the
54  * correspondences.
55  *
56  * \note If \ref setInputCloud and \ref setInputTarget are given, then the
57  * distances between correspondences will be estimated using the given XYZ
58  * data, and not read from the set of input correspondences.
59  *
60  * \author Dirk Holz, Radu B. Rusu
61  * \ingroup registration
62  */
64  {
68 
69  public:
70  using Ptr = shared_ptr<CorrespondenceRejectorDistance>;
71  using ConstPtr = shared_ptr<const CorrespondenceRejectorDistance>;
72 
73  /** \brief Empty constructor. */
74  CorrespondenceRejectorDistance () : max_distance_(std::numeric_limits<float>::max ())
75  {
76  rejection_name_ = "CorrespondenceRejectorDistance";
77  }
78 
79  /** \brief Empty destructor */
81 
82  /** \brief Get a list of valid correspondences after rejection from the original set of correspondences.
83  * \param[in] original_correspondences the set of initial correspondences given
84  * \param[out] remaining_correspondences the resultant filtered set of remaining correspondences
85  */
86  void
87  getRemainingCorrespondences (const pcl::Correspondences& original_correspondences,
88  pcl::Correspondences& remaining_correspondences) override;
89 
90  /** \brief Set the maximum distance used for thresholding in correspondence rejection.
91  * \param[in] distance Distance to be used as maximum distance between correspondences.
92  * Correspondences with larger distances are rejected.
93  * \note Internally, the distance will be stored squared.
94  */
95  virtual inline void
96  setMaximumDistance (float distance) { max_distance_ = distance * distance; };
97 
98  /** \brief Get the maximum distance used for thresholding in correspondence rejection. */
99  inline float
100  getMaximumDistance () const { return std::sqrt (max_distance_); };
101 
102  /** \brief Provide a source point cloud dataset (must contain XYZ
103  * data!), used to compute the correspondence distance.
104  * \param[in] cloud a cloud containing XYZ data
105  */
106  template <typename PointT>
107  PCL_DEPRECATED(1, 12, "pcl::registration::CorrespondenceRejectorDistance::setInputCloud is deprecated. Please use setInputSource instead")
108  inline void
109  setInputCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud)
110  {
111  if (!data_container_)
112  data_container_.reset (new DataContainer<PointT>);
113  static_pointer_cast<DataContainer<PointT> > (data_container_)->setInputSource (cloud);
114  }
115 
116  /** \brief Provide a source point cloud dataset (must contain XYZ
117  * data!), used to compute the correspondence distance.
118  * \param[in] cloud a cloud containing XYZ data
119  */
120  template <typename PointT> inline void
122  {
123  if (!data_container_)
124  data_container_.reset (new DataContainer<PointT>);
125  static_pointer_cast<DataContainer<PointT> > (data_container_)->setInputSource (cloud);
126  }
127 
128  /** \brief Provide a target point cloud dataset (must contain XYZ
129  * data!), used to compute the correspondence distance.
130  * \param[in] target a cloud containing XYZ data
131  */
132  template <typename PointT> inline void
134  {
135  if (!data_container_)
136  data_container_.reset (new DataContainer<PointT>);
137  static_pointer_cast<DataContainer<PointT> > (data_container_)->setInputTarget (target);
138  }
139 
140 
141  /** \brief See if this rejector requires source points */
142  bool
143  requiresSourcePoints () const override
144  { return (true); }
145 
146  /** \brief Blob method for setting the source cloud */
147  void
149  {
151  fromPCLPointCloud2 (*cloud2, *cloud);
152  setInputSource<PointXYZ> (cloud);
153  }
154 
155  /** \brief See if this rejector requires a target cloud */
156  bool
157  requiresTargetPoints () const override
158  { return (true); }
159 
160  /** \brief Method for setting the target cloud */
161  void
163  {
165  fromPCLPointCloud2 (*cloud2, *cloud);
166  setInputTarget<PointXYZ> (cloud);
167  }
168 
169  /** \brief Provide a pointer to the search object used to find correspondences in
170  * the target cloud.
171  * \param[in] tree a pointer to the spatial search object.
172  * \param[in] force_no_recompute If set to true, this tree will NEVER be
173  * recomputed, regardless of calls to setInputTarget. Only use if you are
174  * confident that the tree will be set correctly.
175  */
176  template <typename PointT> inline void
178  bool force_no_recompute = false)
179  {
180  static_pointer_cast< DataContainer<PointT> >
181  (data_container_)->setSearchMethodTarget (tree, force_no_recompute );
182  }
183 
184 
185  protected:
186 
187  /** \brief Apply the rejection algorithm.
188  * \param[out] correspondences the set of resultant correspondences.
189  */
190  inline void
191  applyRejection (pcl::Correspondences &correspondences) override
192  {
193  getRemainingCorrespondences (*input_correspondences_, correspondences);
194  }
195 
196  /** \brief The maximum distance threshold between two correspondent points in source <-> target. If the
197  * distance is larger than this threshold, the points will not be ignored in the alignment process.
198  */
200 
202 
203  /** \brief A pointer to the DataContainer object containing the input and target point clouds */
205  };
206 
207  }
208 }
209 
210 #include <pcl/registration/impl/correspondence_rejection_distance.hpp>
void setSearchMethodTarget(const typename pcl::search::KdTree< PointT >::Ptr &tree, bool force_no_recompute=false)
Provide a pointer to the search object used to find correspondences in the target cloud...
shared_ptr< KdTree< PointT, Tree > > Ptr
Definition: kdtree.h:75
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:168
shared_ptr< const CorrespondenceRejector > ConstPtr
DataContainer is a container for the input and target point clouds and implements the interface to co...
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:429
Defines functions, macros and traits for allocating and using memory.
shared_ptr< CorrespondenceRejector > Ptr
virtual void setMaximumDistance(float distance)
Set the maximum distance used for thresholding in correspondence rejection.
CorrespondenceRejector represents the base class for correspondence rejection methods ...
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
const std::string & getClassName() const
Get a string representation of the name of this class.
DataContainerPtr data_container_
A pointer to the DataContainer object containing the input and target point clouds.
void setTargetPoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
Method for setting the target cloud.
float max_distance_
The maximum distance threshold between two correspondent points in source <-> target.
void applyRejection(pcl::Correspondences &correspondences) override
Apply the rejection algorithm.
float getMaximumDistance() const
Get the maximum distance used for thresholding in correspondence rejection.
float distance(const PointT &p1, const PointT &p2)
Definition: geometry.h:60
bool requiresSourcePoints() const override
See if this rejector requires source points.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Definition: distances.h:55
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...
bool requiresTargetPoints() const override
See if this rejector requires a target cloud.
CorrespondenceRejectorDistance implements a simple correspondence rejection method based on threshold...
shared_ptr< DataContainerInterface > Ptr
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.
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:430
std::string rejection_name_
The name of the rejection method.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
#define PCL_DEPRECATED(Major, Minor, Message)
macro for compatibility across compilers and help remove old deprecated items for the Major...
Definition: pcl_macros.h:147
A point structure representing Euclidean xyz coordinates, and the RGB color.
#define PCL_EXPORTS
Definition: pcl_macros.h:328
void setSourcePoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
Blob method for setting the source cloud.