Point Cloud Library (PCL)  1.12.1-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() : overlap_ratio_(0.5f), nr_min_correspondences_(0)
72  {
73  rejection_name_ = "CorrespondenceRejectorTrimmed";
74  }
75 
76  /** \brief Destructor. */
77  ~CorrespondenceRejectorTrimmed() override = default;
78 
79  /** \brief Set the expected ratio of overlap between point clouds (in
80  * terms of correspondences).
81  * \param[in] ratio ratio of overlap between 0 (no overlap, no
82  * correspondences) and 1 (full overlap, all correspondences)
83  */
84  virtual inline void
85  setOverlapRatio(float ratio)
86  {
87  overlap_ratio_ = std::min(1.0f, std::max(0.0f, ratio));
88  };
89 
90  /** \brief Get the maximum distance used for thresholding in correspondence rejection.
91  */
92  inline float
94  {
95  return overlap_ratio_;
96  };
97 
98  /** \brief Set a minimum number of correspondences. If the specified overlap ratio
99  * causes to have less correspondences, \a CorrespondenceRejectorTrimmed will try to
100  * return at least \a nr_min_correspondences_ correspondences (or all correspondences
101  * in case \a nr_min_correspondences_ is less than the number of given
102  * correspondences). \param[in] min_correspondences the minimum number of
103  * correspondences
104  */
105  inline void
106  setMinCorrespondences(unsigned int min_correspondences)
107  {
108  nr_min_correspondences_ = min_correspondences;
109  };
110 
111  /** \brief Get the minimum number of correspondences. */
112  inline unsigned int
114  {
115  return nr_min_correspondences_;
116  };
117 
118  /** \brief Get a list of valid correspondences after rejection from the original set
119  * of correspondences. \param[in] original_correspondences the set of initial
120  * correspondences given \param[out] remaining_correspondences the resultant filtered
121  * set of remaining correspondences
122  */
123  void
124  getRemainingCorrespondences(const pcl::Correspondences& original_correspondences,
125  pcl::Correspondences& remaining_correspondences) override;
126 
127 protected:
128  /** \brief Apply the rejection algorithm.
129  * \param[out] correspondences the set of resultant correspondences.
130  */
131  inline void
132  applyRejection(pcl::Correspondences& correspondences) override
133  {
134  getRemainingCorrespondences(*input_correspondences_, correspondences);
135  }
136 
137  /** Overlap Ratio in [0..1] */
139 
140  /** Minimum number of correspondences. */
142 };
143 
144 } // namespace registration
145 } // 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).
unsigned int nr_min_correspondences_
Minimum number 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