Point Cloud Library (PCL)  1.14.1-dev
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/conversions.h> // for fromPCLPointCloud2
45 #include <pcl/memory.h> // for static_pointer_cast
46 
47 namespace pcl {
48 namespace registration {
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  */
65 
66 public:
67  using Ptr = shared_ptr<CorrespondenceRejectorDistance>;
68  using ConstPtr = shared_ptr<const CorrespondenceRejectorDistance>;
69 
70  /** \brief Empty constructor. */
71  CorrespondenceRejectorDistance() : max_distance_(std::numeric_limits<float>::max())
72  {
73  rejection_name_ = "CorrespondenceRejectorDistance";
74  }
75 
76  /** \brief Empty destructor */
77  ~CorrespondenceRejectorDistance() override = default;
78 
79  /** \brief Get a list of valid correspondences after rejection from the original set
80  * of correspondences. \param[in] original_correspondences the set of initial
81  * correspondences given \param[out] remaining_correspondences the resultant filtered
82  * set of remaining correspondences
83  */
84  void
85  getRemainingCorrespondences(const pcl::Correspondences& original_correspondences,
86  pcl::Correspondences& remaining_correspondences) override;
87 
88  /** \brief Set the maximum distance used for thresholding in correspondence rejection.
89  * \param[in] distance Distance to be used as maximum distance between
90  * correspondences. Correspondences with larger distances are rejected. \note
91  * Internally, the distance will be stored squared.
92  */
93  virtual inline void
95  {
96  max_distance_ = distance * distance;
97  };
98 
99  /** \brief Get the maximum distance used for thresholding in correspondence rejection.
100  */
101  inline float
103  {
104  return std::sqrt(max_distance_);
105  };
106 
107  /** \brief Provide a source point cloud dataset (must contain XYZ
108  * data!), used to compute the correspondence distance.
109  * \param[in] cloud a cloud containing XYZ data
110  */
111  template <typename PointT>
112  inline void
114  {
115  if (!data_container_)
116  data_container_.reset(new DataContainer<PointT>);
117  static_pointer_cast<DataContainer<PointT>>(data_container_)->setInputSource(cloud);
118  }
119 
120  /** \brief Provide a target point cloud dataset (must contain XYZ
121  * data!), used to compute the correspondence distance.
122  * \param[in] target a cloud containing XYZ data
123  */
124  template <typename PointT>
125  inline void
127  {
128  if (!data_container_)
129  data_container_.reset(new DataContainer<PointT>);
130  static_pointer_cast<DataContainer<PointT>>(data_container_)->setInputTarget(target);
131  }
132 
133  /** \brief See if this rejector requires source points */
134  bool
135  requiresSourcePoints() const override
136  {
137  return (true);
138  }
139 
140  /** \brief Blob method for setting the source cloud */
141  void
143  {
145  fromPCLPointCloud2(*cloud2, *cloud);
146  setInputSource<PointXYZ>(cloud);
147  }
148 
149  /** \brief See if this rejector requires a target cloud */
150  bool
151  requiresTargetPoints() const override
152  {
153  return (true);
154  }
155 
156  /** \brief Method for setting the target cloud */
157  void
159  {
161  fromPCLPointCloud2(*cloud2, *cloud);
162  setInputTarget<PointXYZ>(cloud);
163  }
164 
165  /** \brief Provide a pointer to the search object used to find correspondences in
166  * the target cloud.
167  * \param[in] tree a pointer to the spatial search object.
168  * \param[in] force_no_recompute If set to true, this tree will NEVER be
169  * recomputed, regardless of calls to setInputTarget. Only use if you are
170  * confident that the tree will be set correctly.
171  */
172  template <typename PointT>
173  inline void
175  bool force_no_recompute = false)
176  {
177  static_pointer_cast<DataContainer<PointT>>(data_container_)
178  ->setSearchMethodTarget(tree, force_no_recompute);
179  }
180 
181 protected:
182  /** \brief Apply the rejection algorithm.
183  * \param[out] correspondences the set of resultant correspondences.
184  */
185  inline void
186  applyRejection(pcl::Correspondences& correspondences) override
187  {
188  getRemainingCorrespondences(*input_correspondences_, correspondences);
189  }
190 
191  /** \brief The maximum distance threshold between two correspondent points in source
192  * <-> target. If the distance is larger than this threshold, the points will not be
193  * ignored in the alignment process.
194  */
196 
198 
199  /** \brief A pointer to the DataContainer object containing the input and target point
200  * clouds */
202 };
203 
204 } // namespace registration
205 } // namespace pcl
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
CorrespondenceRejectorDistance implements a simple correspondence rejection method based on threshold...
float max_distance_
The maximum distance threshold between two correspondent points in source <-> target.
void applyRejection(pcl::Correspondences &correspondences) override
Apply the rejection algorithm.
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.
~CorrespondenceRejectorDistance() override=default
Empty destructor.
bool requiresSourcePoints() const override
See if this rejector requires source points.
float getMaximumDistance() const
Get the maximum distance used for thresholding in correspondence rejection.
void setTargetPoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
Method for setting the target cloud.
void getRemainingCorrespondences(const pcl::Correspondences &original_correspondences, pcl::Correspondences &remaining_correspondences) override
Get a list of valid correspondences after rejection from the original set of correspondences.
void setSourcePoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
Blob method for setting the source cloud.
virtual void setMaximumDistance(float distance)
Set the maximum distance used for thresholding in correspondence rejection.
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...
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...
DataContainerPtr data_container_
A pointer to the DataContainer object containing the input and target point clouds.
bool requiresTargetPoints() const override
See if this rejector requires a target cloud.
CorrespondenceRejector represents the base class for correspondence rejection methods
shared_ptr< const CorrespondenceRejector > ConstPtr
CorrespondencesConstPtr input_correspondences_
The input correspondences.
const std::string & getClassName() const
Get a string representation of the name of this class.
shared_ptr< CorrespondenceRejector > Ptr
std::string rejection_name_
The name of the rejection method.
DataContainer is a container for the input and target point clouds and implements the interface to co...
shared_ptr< DataContainerInterface > Ptr
shared_ptr< KdTree< PointT, Tree > > Ptr
Definition: kdtree.h:75
Defines functions, macros and traits for allocating and using memory.
float distance(const PointT &p1, const PointT &p2)
Definition: geometry.h:60
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map, const std::uint8_t *msg_data)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map.
Definition: conversions.h:229
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
#define PCL_EXPORTS
Definition: pcl_macros.h:323
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr