Point Cloud Library (PCL)  1.14.0-dev
correspondence_rejection_trimmed.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 
45 namespace pcl {
46 namespace registration {
47 /** \brief CorrespondenceRejectorTrimmed implements a correspondence
48  * rejection for ICP-like registration algorithms that uses only the best
49  * 'k' correspondences where 'k' is some estimate of the overlap between
50  * the two point clouds being registered.
51  *
52  * Reference:
53  * 'The Trimmed Iterative Closest Point Algorithm' by
54  * D. Chetverikov, D. Svirko, D. Stepanov, and Pavel Krsek.
55  * In Proceedings of the 16th International Conference on Pattern
56  * Recognition (ICPR 2002).
57  *
58  * \author Dirk Holz
59  * \ingroup registration
60  */
65 
66 public:
67  using Ptr = shared_ptr<CorrespondenceRejectorTrimmed>;
68  using ConstPtr = shared_ptr<const CorrespondenceRejectorTrimmed>;
69 
70  /** \brief Empty constructor. */
71  CorrespondenceRejectorTrimmed() { rejection_name_ = "CorrespondenceRejectorTrimmed"; }
72 
73  /** \brief Destructor. */
74  ~CorrespondenceRejectorTrimmed() override = default;
75 
76  /** \brief Set the expected ratio of overlap between point clouds (in
77  * terms of correspondences).
78  * \param[in] ratio ratio of overlap between 0 (no overlap, no
79  * correspondences) and 1 (full overlap, all correspondences)
80  */
81  virtual inline void
82  setOverlapRatio(float ratio)
83  {
84  overlap_ratio_ = std::min(1.0f, std::max(0.0f, ratio));
85  };
86 
87  /** \brief Get the maximum distance used for thresholding in correspondence rejection.
88  */
89  inline float
91  {
92  return overlap_ratio_;
93  };
94 
95  /** \brief Set a minimum number of correspondences. If the specified overlap ratio
96  * causes to have less correspondences, \a CorrespondenceRejectorTrimmed will try to
97  * return at least \a nr_min_correspondences_ correspondences (or all correspondences
98  * in case \a nr_min_correspondences_ is less than the number of given
99  * correspondences). \param[in] min_correspondences the minimum number of
100  * correspondences
101  */
102  inline void
103  setMinCorrespondences(unsigned int min_correspondences)
104  {
105  nr_min_correspondences_ = min_correspondences;
106  };
107 
108  /** \brief Get the minimum number of correspondences. */
109  inline unsigned int
111  {
112  return nr_min_correspondences_;
113  };
114 
115  /** \brief Get a list of valid correspondences after rejection from the original set
116  * of correspondences. \param[in] original_correspondences the set of initial
117  * correspondences given \param[out] remaining_correspondences the resultant filtered
118  * set of remaining correspondences
119  */
120  void
121  getRemainingCorrespondences(const pcl::Correspondences& original_correspondences,
122  pcl::Correspondences& remaining_correspondences) override;
123 
124 protected:
125  /** \brief Apply the rejection algorithm.
126  * \param[out] correspondences the set of resultant correspondences.
127  */
128  inline void
129  applyRejection(pcl::Correspondences& correspondences) override
130  {
131  getRemainingCorrespondences(*input_correspondences_, correspondences);
132  }
133 
134  /** Overlap Ratio in [0..1] */
135  float overlap_ratio_{0.5f};
136 
137  /** Minimum number of correspondences. */
138  unsigned int nr_min_correspondences_{0};
139 };
140 
141 } // namespace registration
142 } // namespace pcl
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.
CorrespondenceRejectorTrimmed implements a correspondence rejection for ICP-like registration algorit...
void setMinCorrespondences(unsigned int min_correspondences)
Set a minimum number of correspondences.
float getOverlapRatio() const
Get the maximum distance used for thresholding in correspondence rejection.
unsigned int getMinCorrespondences() const
Get the minimum number of correspondences.
~CorrespondenceRejectorTrimmed() override=default
Destructor.
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.
virtual void setOverlapRatio(float ratio)
Set the expected ratio of overlap between point clouds (in terms of correspondences).
void applyRejection(pcl::Correspondences &correspondences) override
Apply the rejection algorithm.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
#define PCL_EXPORTS
Definition: pcl_macros.h:323