Point Cloud Library (PCL)  1.9.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
multi_ransac.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2009, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id$
35  *
36  */
37 
38 #ifndef PCL_CUDA_SAMPLE_CONSENSUS_RANSAC_H_
39 #define PCL_CUDA_SAMPLE_CONSENSUS_RANSAC_H_
40 
41 #include <pcl/cuda/sample_consensus/sac.h>
42 #include <pcl/cuda/sample_consensus/sac_model.h>
43 
44 namespace pcl
45 {
46  namespace cuda
47  {
48  /** \brief @b RandomSampleConsensus represents an implementation of the
49  * RANSAC (RAndom SAmple Consensus) algorithm, as described in: "Random
50  * Sample Consensus: A Paradigm for Model Fitting with Applications to Image
51  * Analysis and Automated Cartography", Martin A. Fischler and Robert C. Bolles,
52  * Comm. Of the ACM 24: 381–395, June 1981.
53  * \author Radu Bogdan Rusu
54  */
55  template <template <typename> class Storage>
57  {
67 
68  typedef typename SampleConsensusModel<Storage>::Ptr SampleConsensusModelPtr;
69  typedef typename SampleConsensusModel<Storage>::Coefficients Coefficients;
70  typedef typename SampleConsensusModel<Storage>::Hypotheses Hypotheses;
71 
72  typedef typename SampleConsensusModel<Storage>::Indices Indices;
73  typedef typename SampleConsensusModel<Storage>::IndicesPtr IndicesPtr;
74  typedef typename SampleConsensusModel<Storage>::IndicesConstPtr IndicesConstPtr;
75 
76  public:
77  /** \brief RANSAC (RAndom SAmple Consensus) main constructor
78  * \param model a Sample Consensus model
79  */
80  MultiRandomSampleConsensus (const SampleConsensusModelPtr &model) :
81  SampleConsensus<Storage> (model),
82  min_coverage_percent_ (0.9),
83  max_batches_ (5),
84  iterations_per_batch_ (1000)
85  {
86  // Maximum number of trials before we give up.
87  max_iterations_ = 10000;
88  }
89 
90  /** \brief RANSAC (RAndom SAmple Consensus) main constructor
91  * \param model a Sample Consensus model
92  * \param threshold distance to model threshold
93  */
94  MultiRandomSampleConsensus (const SampleConsensusModelPtr &model, double threshold) :
95  SampleConsensus<Storage> (model, threshold)
96  {
97  // Maximum number of trials before we give up.
98  max_iterations_ = 10000;
99  }
100 
101  /** \brief Compute the actual model and find the inliers
102  * \param debug_verbosity_level enable/disable on-screen debug
103  * information and set the verbosity level
104  */
105  bool
106  computeModel (int debug_verbosity_level = 0);
107 
108  /** \brief how much (in percent) of the point cloud should be covered?
109  * If it is not possible to find enough planes, it will stop according to the regular ransac criteria
110  */
111  void
112  setMinimumCoverage (float percent)
113  {
114  min_coverage_percent_ = percent;
115  }
116 
117  /** \brief Sets the maximum number of batches that should be processed.
118  * Every Batch computes up to iterations_per_batch_ models and verifies them.
119  * If planes with a sufficiently high total inlier count are found earlier, the
120  * actual number of batch runs might be lower.
121  */
122  void
123  setMaximumBatches (int max_batches)
124  {
125  max_batches_ = max_batches_;
126  }
127 
128  /** \brief Sets the maximum number of batches that should be processed.
129  * Every Batch computes up to max_iterations_ models and verifies them.
130  * If planes with a sufficiently high total inlier count are found earlier, the
131  * actual number of batch runs might be lower.
132  */
133  void
134  setIerationsPerBatch(int iterations_per_batch)
135  {
136  iterations_per_batch_ = iterations_per_batch;
137  }
138 
139  inline std::vector<IndicesPtr>
140  getAllInliers () { return all_inliers_; }
141 
142  inline std::vector<int>
143  getAllInlierCounts () { return all_inlier_counts_; }
144 
145  /** \brief Return the model coefficients of the best model found so far.
146  */
147  inline std::vector<float4>
149  {
150  return all_model_coefficients_;
151  }
152 
153  /** \brief Return the model coefficients of the best model found so far.
154  */
155  inline std::vector<float3>
157  {
158  return all_model_centroids_;
159  }
160 
161  private:
162  float min_coverage_percent_;
163  unsigned int max_batches_;
164  unsigned int iterations_per_batch_;
165 
166  /** \brief The vector of the centroids of our models computed directly from the models found. */
167  std::vector<float3> all_model_centroids_;
168 
169  /** \brief The vector of coefficients of our models computed directly from the models found. */
170  std::vector<float4> all_model_coefficients_;
171 
172  std::vector<IndicesPtr> all_inliers_;
173  std::vector<int> all_inlier_counts_;
174  };
175 
176  } // namespace
177 } // namespace
178 
179 #endif //#ifndef PCL_CUDA_SAMPLE_CONSENSUS_RANSAC_H_
180 
boost::shared_ptr< typename Storage< int >::type > IndicesPtr
Definition: sac_model.h:99
MultiRandomSampleConsensus(const SampleConsensusModelPtr &model, double threshold)
RANSAC (RAndom SAmple Consensus) main constructor.
Definition: multi_ransac.h:94
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
std::vector< IndicesPtr > getAllInliers()
Definition: multi_ransac.h:140
void setMaximumBatches(int max_batches)
Sets the maximum number of batches that should be processed.
Definition: multi_ransac.h:123
boost::shared_ptr< const typename Storage< int >::type > IndicesConstPtr
Definition: sac_model.h:100
Storage< float >::type Coefficients
Definition: sac_model.h:102
Storage< int >::type Indices
Definition: sac_model.h:98
std::vector< int > getAllInlierCounts()
Definition: multi_ransac.h:143
Storage< float4 >::type Hypotheses
Definition: sac_model.h:106
boost::shared_ptr< SampleConsensusModel > Ptr
Definition: sac_model.h:95
bool computeModel(int debug_verbosity_level=0)
Compute the actual model and find the inliers.
MultiRandomSampleConsensus(const SampleConsensusModelPtr &model)
RANSAC (RAndom SAmple Consensus) main constructor.
Definition: multi_ransac.h:80
int max_iterations_
Maximum number of iterations before giving up.
Definition: sac.h:196
RandomSampleConsensus represents an implementation of the RANSAC (RAndom SAmple Consensus) algorithm...
Definition: multi_ransac.h:56
void setMinimumCoverage(float percent)
how much (in percent) of the point cloud should be covered? If it is not possible to find enough plan...
Definition: multi_ransac.h:112
std::vector< float3 > getAllModelCentroids()
Return the model coefficients of the best model found so far.
Definition: multi_ransac.h:156
std::vector< float4 > getAllModelCoefficients()
Return the model coefficients of the best model found so far.
Definition: multi_ransac.h:148
void setIerationsPerBatch(int iterations_per_batch)
Sets the maximum number of batches that should be processed.
Definition: multi_ransac.h:134