Point Cloud Library (PCL)  1.7.0
correspondence_rejection_sample_consensus.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 #ifndef PCL_REGISTRATION_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_H_
41 #define PCL_REGISTRATION_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_H_
42 
43 #include <pcl/registration/correspondence_rejection.h>
44 
45 #include <pcl/sample_consensus/ransac.h>
46 #include <pcl/sample_consensus/sac_model_registration.h>
47 #include <pcl/common/transforms.h>
48 
49 namespace pcl
50 {
51  namespace registration
52  {
53  /** \brief CorrespondenceRejectorSampleConsensus implements a correspondence rejection
54  * using Random Sample Consensus to identify inliers (and reject outliers)
55  * \author Dirk Holz
56  * \ingroup registration
57  */
58  template <typename PointT>
60  {
62  typedef typename PointCloud::Ptr PointCloudPtr;
63  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
64 
65  public:
69 
70  typedef boost::shared_ptr<CorrespondenceRejectorSampleConsensus> Ptr;
71  typedef boost::shared_ptr<const CorrespondenceRejectorSampleConsensus> ConstPtr;
72 
73  /** \brief Empty constructor. Sets the inlier threshold to 5cm (0.05m),
74  * and the maximum number of iterations to 1000.
75  */
77  : inlier_threshold_ (0.05)
78  , max_iterations_ (1000) // std::numeric_limits<int>::max ()
79  , input_ ()
81  , target_ ()
83  , refine_ (false)
84  {
85  rejection_name_ = "CorrespondenceRejectorSampleConsensus";
86  }
87 
88  /** \brief Empty destructor. */
90 
91  /** \brief Get a list of valid correspondences after rejection from the original set of correspondences.
92  * \param[in] original_correspondences the set of initial correspondences given
93  * \param[out] remaining_correspondences the resultant filtered set of remaining correspondences
94  */
95  inline void
96  getRemainingCorrespondences (const pcl::Correspondences& original_correspondences,
97  pcl::Correspondences& remaining_correspondences);
98 
99  /** \brief Provide a source point cloud dataset (must contain XYZ data!)
100  * \param[in] cloud a cloud containing XYZ data
101  */
102  PCL_DEPRECATED (virtual void setInputCloud (const PointCloudConstPtr &cloud),
103  "[pcl::registration::CorrespondenceRejectorSampleConsensus::setInputCloud] setInputCloud is deprecated. Please use setInputSource instead.");
104 
105  /** \brief Get a pointer to the input point cloud dataset target. */
106  PCL_DEPRECATED (PointCloudConstPtr const getInputCloud (), "[pcl::registration::CorrespondenceRejectorSampleConsensus::getInputCloud] getInputCloud is deprecated. Please use getInputSource instead.");
107 
108  /** \brief Provide a source point cloud dataset (must contain XYZ data!)
109  * \param[in] cloud a cloud containing XYZ data
110  */
111  virtual inline void
112  setInputSource (const PointCloudConstPtr &cloud)
113  {
114  input_ = cloud;
115  }
116 
117  /** \brief Get a pointer to the input point cloud dataset target. */
118  inline PointCloudConstPtr const
119  getInputSource () { return (input_); }
120 
121  /** \brief Provide a target point cloud dataset (must contain XYZ data!)
122  * \param[in] cloud a cloud containing XYZ data
123  */
124  PCL_DEPRECATED (virtual void setTargetCloud (const PointCloudConstPtr &cloud), "[pcl::registration::CorrespondenceRejectorSampleConsensus::setTargetCloud] setTargetCloud is deprecated. Please use setInputTarget instead.");
125 
126  /** \brief Provide a target point cloud dataset (must contain XYZ data!)
127  * \param[in] cloud a cloud containing XYZ data
128  */
129  virtual inline void
130  setInputTarget (const PointCloudConstPtr &cloud) { target_ = cloud; }
131 
132  /** \brief Get a pointer to the input point cloud dataset target. */
133  inline PointCloudConstPtr const
134  getInputTarget () { return (target_ ); }
135 
136  /** \brief Set the maximum distance between corresponding points.
137  * Correspondences with distances below the threshold are considered as inliers.
138  * \param[in] threshold Distance threshold in the same dimension as source and target data sets.
139  */
140  inline void
141  setInlierThreshold (double threshold) { inlier_threshold_ = threshold; };
142 
143  /** \brief Get the maximum distance between corresponding points.
144  * \return Distance threshold in the same dimension as source and target data sets.
145  */
146  inline double
148 
149  /** \brief Set the maximum number of iterations.
150  * \param[in] max_iterations Maximum number if iterations to run
151  */
152  PCL_DEPRECATED (void setMaxIterations (int max_iterations), "[pcl::registration::CorrespondenceRejectorSampleConsensus::setMaxIterations] setMaxIterations is deprecated. Please use setMaximumIterations instead.");
153 
154  /** \brief Set the maximum number of iterations.
155  * \param[in] max_iterations Maximum number if iterations to run
156  */
157  inline void
158  setMaximumIterations (int max_iterations) { max_iterations_ = std::max (max_iterations, 0); }
159 
160  /** \brief Get the maximum number of iterations.
161  * \return max_iterations Maximum number if iterations to run
162  */
163  PCL_DEPRECATED (int getMaxIterations (), "[pcl::registration::CorrespondenceRejectorSampleConsensus::getMaxIterations] getMaxIterations is deprecated. Please use getMaximumIterations instead.");
164 
165  /** \brief Get the maximum number of iterations.
166  * \return max_iterations Maximum number if iterations to run
167  */
168  inline int
170 
171  /** \brief Get the best transformation after RANSAC rejection.
172  * \return The homogeneous 4x4 transformation yielding the largest number of inliers.
173  */
174  inline Eigen::Matrix4f
176 
177  /** \brief Specify whether the model should be refined internally using the variance of the inliers
178  * \param[in] refine true if the model should be refined, false otherwise
179  */
180  inline void
181  setRefineModel (const bool refine)
182  {
183  refine_ = refine;
184  }
185 
186  /** \brief Get the internal refine parameter value as set by the user using setRefineModel */
187  inline bool
188  getRefineModel () const
189  {
190  return (refine_);
191  }
192  protected:
193 
194  /** \brief Apply the rejection algorithm.
195  * \param[out] correspondences the set of resultant correspondences.
196  */
197  inline void
199  {
201  }
202 
204 
206 
207  PointCloudConstPtr input_;
208  PointCloudPtr input_transformed_;
209  PointCloudConstPtr target_;
210 
211  Eigen::Matrix4f best_transformation_;
212 
213  bool refine_;
214  public:
215  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
216  };
217  }
218 }
219 
220 #include <pcl/registration/impl/correspondence_rejection_sample_consensus.hpp>
221 
222 #endif // PCL_REGISTRATION_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_H_
double getInlierThreshold()
Get the maximum distance between corresponding points.
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
CorrespondenceRejector represents the base class for correspondence rejection methods ...
const std::string & getClassName() const
Get a string representation of the name of this class.
boost::shared_ptr< CorrespondenceRejectorSampleConsensus > Ptr
Eigen::Matrix4f getBestTransformation()
Get the best transformation after RANSAC rejection.
virtual void setInputTarget(const PointCloudConstPtr &cloud)
Provide a target point cloud dataset (must contain XYZ data!)
void setMaximumIterations(int max_iterations)
Set the maximum number of iterations.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
PointCloudConstPtr const getInputSource()
Get a pointer to the input point cloud dataset target.
void setInlierThreshold(double threshold)
Set the maximum distance between corresponding points.
CorrespondenceRejectorSampleConsensus implements a correspondence rejection using Random Sample Conse...
PointCloudConstPtr const getInputTarget()
Get a pointer to the input point cloud dataset target.
void applyRejection(pcl::Correspondences &correspondences)
Apply the rejection algorithm.
CorrespondencesConstPtr input_correspondences_
The input correspondences.
virtual void setInputSource(const PointCloudConstPtr &cloud)
Provide a source point cloud dataset (must contain XYZ data!)
std::string rejection_name_
The name of the rejection method.
boost::shared_ptr< const CorrespondenceRejectorSampleConsensus > ConstPtr
void getRemainingCorrespondences(const pcl::Correspondences &original_correspondences, pcl::Correspondences &remaining_correspondences)
Get a list of valid correspondences after rejection from the original set of correspondences.
bool getRefineModel() const
Get the internal refine parameter value as set by the user using setRefineModel.
void setRefineModel(const bool refine)
Specify whether the model should be refined internally using the variance of the inliers.
PCL_DEPRECATED(virtual void setInputCloud(const PointCloudConstPtr &cloud),"[pcl::registration::CorrespondenceRejectorSampleConsensus::setInputCloud] setInputCloud is deprecated. Please use setInputSource instead.")
Provide a source point cloud dataset (must contain XYZ data!)