Point Cloud Library (PCL)  1.7.1
correspondence_rejection_var_trimmed.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2012, Open Perception, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Open Perception, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id$
37  *
38  */
39 #ifndef PCL_REGISTRATION_CORRESPONDENCE_REJECTION_VAR_TRIMMED_H_
40 #define PCL_REGISTRATION_CORRESPONDENCE_REJECTION_VAR_TRIMMED_H_
41 
42 #include <pcl/registration/correspondence_rejection.h>
43 #include <pcl/point_cloud.h>
44 
45 #include <vector>
46 
47 namespace pcl
48 {
49  namespace registration
50  {
51  /**
52  * @b CorrespondenceRejectoVarTrimmed implements a simple correspondence
53  * rejection method by considering as inliers a certain percentage of correspondences
54  * with the least distances. The percentage of inliers is computed internally as mentioned
55  * in the paper 'Outlier Robust ICP for minimizing Fractional RMSD, J. M. Philips et al'
56  *
57  * \note If \ref setInputCloud and \ref setInputTarget are given, then the
58  * distances between correspondences will be estimated using the given XYZ
59  * data, and not read from the set of input correspondences.
60  *
61  * \author Aravindhan K Krishnan. This code is ported from libpointmatcher (https://github.com/ethz-asl/libpointmatcher)
62  * \ingroup registration
63  */
65  {
69 
70  public:
71  typedef boost::shared_ptr<CorrespondenceRejectorVarTrimmed> Ptr;
72  typedef boost::shared_ptr<const CorrespondenceRejectorVarTrimmed> ConstPtr;
73 
74  /** \brief Empty constructor. */
76  trimmed_distance_ (0),
77  factor_ (),
78  min_ratio_ (0.05),
79  max_ratio_ (0.95),
80  lambda_ (0.95),
81  data_container_ ()
82  {
83  rejection_name_ = "CorrespondenceRejectorVarTrimmed";
84  }
85 
86  /** \brief Get a list of valid correspondences after rejection from the original set of correspondences.
87  * \param[in] original_correspondences the set of initial correspondences given
88  * \param[out] remaining_correspondences the resultant filtered set of remaining correspondences
89  */
90  void
91  getRemainingCorrespondences (const pcl::Correspondences& original_correspondences,
92  pcl::Correspondences& remaining_correspondences);
93 
94  /** \brief Get the trimmed distance used for thresholding in correspondence rejection. */
95  inline double
96  getTrimmedDistance () const { return trimmed_distance_; };
97 
98  /** \brief Provide a source point cloud dataset (must contain XYZ
99  * data!), used to compute the correspondence distance.
100  * \param[in] cloud a cloud containing XYZ data
101  */
102  template <typename PointT> inline void
104  {
105  if (!data_container_)
106  data_container_.reset (new DataContainer<PointT>);
107  boost::static_pointer_cast<DataContainer<PointT> > (data_container_)->setInputSource (cloud);
108  }
109 
110  /** \brief Provide a source point cloud dataset (must contain XYZ
111  * data!), used to compute the correspondence distance.
112  * \param[in] cloud a cloud containing XYZ data
113  */
114  template <typename PointT> inline void
116  {
117  PCL_WARN ("[pcl::registration::%s::setInputCloud] setInputCloud is deprecated. Please use setInputSource instead.\n", getClassName ().c_str ());
118  if (!data_container_)
119  data_container_.reset (new DataContainer<PointT>);
120  boost::static_pointer_cast<DataContainer<PointT> > (data_container_)->setInputSource (cloud);
121  }
122 
123  /** \brief Provide a target point cloud dataset (must contain XYZ
124  * data!), used to compute the correspondence distance.
125  * \param[in] target a cloud containing XYZ data
126  */
127  template <typename PointT> inline void
129  {
130  if (!data_container_)
131  data_container_.reset (new DataContainer<PointT>);
132  boost::static_pointer_cast<DataContainer<PointT> > (data_container_)->setInputTarget (target);
133  }
134 
135  /** \brief Provide a pointer to the search object used to find correspondences in
136  * the target cloud.
137  * \param[in] tree a pointer to the spatial search object.
138  * \param[in] force_no_recompute If set to true, this tree will NEVER be
139  * recomputed, regardless of calls to setInputTarget. Only use if you are
140  * confident that the tree will be set correctly.
141  */
142  template <typename PointT> inline void
143  setSearchMethodTarget (const boost::shared_ptr<pcl::search::KdTree<PointT> > &tree,
144  bool force_no_recompute = false)
145  {
146  boost::static_pointer_cast< DataContainer<PointT> >
147  (data_container_)->setSearchMethodTarget (tree, force_no_recompute );
148  }
149 
150  /** \brief Get the computed inlier ratio used for thresholding in correspondence rejection. */
151  inline double
152  getTrimFactor () const { return factor_; }
153 
154  /** brief set the minimum overlap ratio
155  * \param[in] ratio the overlap ratio [0..1]
156  */
157  inline void
158  setMinRatio (double ratio) { min_ratio_ = ratio; }
159 
160  /** brief get the minimum overlap ratio
161  */
162  inline double
163  getMinRatio () const { return min_ratio_; }
164 
165  /** brief set the maximum overlap ratio
166  * \param[in] ratio the overlap ratio [0..1]
167  */
168  inline void
169  setMaxRatio (double ratio) { max_ratio_ = ratio; }
170 
171  /** brief get the maximum overlap ratio
172  */
173  inline double
174  getMaxRatio () const { return max_ratio_; }
175 
176  protected:
177 
178  /** \brief Apply the rejection algorithm.
179  * \param[out] correspondences the set of resultant correspondences.
180  */
181  inline void
183  {
184  getRemainingCorrespondences (*input_correspondences_, correspondences);
185  }
186 
187  /** \brief The inlier distance threshold (based on the computed trim factor) between two correspondent points in source <-> target.
188  */
190 
191  /** \brief The factor for correspondence rejection. Only factor times the total points sorted based on
192  * the correspondence distances will be considered as inliers. Remaining points are rejected. This factor is
193  * computed internally
194  */
195  double factor_;
196 
197  /** \brief The minimum overlap ratio between the input and target clouds
198  */
199  double min_ratio_;
200 
201  /** \brief The maximum overlap ratio between the input and target clouds
202  */
203  double max_ratio_;
204 
205  /** \brief part of the term that balances the root mean square difference. This is an internal parameter
206  */
207  double lambda_;
208 
209  typedef boost::shared_ptr<DataContainerInterface> DataContainerPtr;
210 
211  /** \brief A pointer to the DataContainer object containing the input and target point clouds */
212  DataContainerPtr data_container_;
213 
214  private:
215 
216  /** \brief finds the optimal inlier ratio. This is based on the paper 'Outlier Robust ICP for minimizing Fractional RMSD, J. M. Philips et al'
217  */
218  inline float optimizeInlierRatio (std::vector <double> &dists);
219  };
220  }
221 }
222 
223 #include <pcl/registration/impl/correspondence_rejection_var_trimmed.hpp>
224 
225 #endif // PCL_REGISTRATION_CORRESPONDENCE_REJECTION_VAR_TRIMMED_H_
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
double max_ratio_
The maximum overlap ratio between the input and target clouds.
DataContainerPtr data_container_
A pointer to the DataContainer object containing the input and target point clouds.
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...
double getTrimFactor() const
Get the computed inlier ratio used for thresholding in correspondence rejection.
double min_ratio_
The minimum overlap ratio between the input and target clouds.
double getTrimmedDistance() const
Get the trimmed distance used for thresholding in correspondence rejection.
double getMaxRatio() const
brief get the maximum overlap ratio
void setMaxRatio(double ratio)
brief set the maximum overlap ratio
CorrespondenceRejector represents the base class for correspondence rejection methods ...
double trimmed_distance_
The inlier distance threshold (based on the computed trim factor) between two correspondent points in...
boost::shared_ptr< CorrespondenceRejectorVarTrimmed > Ptr
void applyRejection(pcl::Correspondences &correspondences)
Apply the rejection algorithm.
DataContainer is a container for the input and target point clouds and implements the interface to co...
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
std::string rejection_name_
The name of the rejection method.
double getMinRatio() const
brief get the minimum overlap ratio
void setMinRatio(double ratio)
brief set the minimum overlap ratio
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...
boost::shared_ptr< const CorrespondenceRejectorVarTrimmed > ConstPtr
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.
const std::string & getClassName() const
Get a string representation of the name of this class.
double lambda_
part of the term that balances the root mean square difference.
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...
CorrespondenceRejectoVarTrimmed implements a simple correspondence rejection method by considering as...
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition: kdtree.h:62