Point Cloud Library (PCL) 1.12.1
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#pragma once
39
40#include <pcl/cuda/sample_consensus/sac.h>
41#include <pcl/cuda/sample_consensus/sac_model.h>
42
43namespace pcl
44{
45 namespace cuda
46 {
47 /** \brief @b RandomSampleConsensus represents an implementation of the
48 * RANSAC (RAndom SAmple Consensus) algorithm, as described in: "Random
49 * Sample Consensus: A Paradigm for Model Fitting with Applications to Image
50 * Analysis and Automated Cartography", Martin A. Fischler and Robert C. Bolles,
51 * Comm. Of the ACM 24: 381–395, June 1981.
52 * \author Radu Bogdan Rusu
53 */
54 template <template <typename> class Storage>
56 {
58 using SampleConsensus<Storage>::threshold_;
59 using SampleConsensus<Storage>::iterations_;
60 using SampleConsensus<Storage>::sac_model_;
61 using SampleConsensus<Storage>::model_;
63 using SampleConsensus<Storage>::inliers_;
65 using SampleConsensus<Storage>::probability_;
66
67 using SampleConsensusModelPtr = typename SampleConsensusModel<Storage>::Ptr;
68 using Coefficients = typename SampleConsensusModel<Storage>::Coefficients;
69 using Hypotheses = typename SampleConsensusModel<Storage>::Hypotheses;
70
71 using Indices = typename SampleConsensusModel<Storage>::Indices;
72 using IndicesPtr = typename SampleConsensusModel<Storage>::IndicesPtr;
73 using IndicesConstPtr = typename SampleConsensusModel<Storage>::IndicesConstPtr;
74
75 public:
76 /** \brief RANSAC (RAndom SAmple Consensus) main constructor
77 * \param model a Sample Consensus model
78 */
79 MultiRandomSampleConsensus (const SampleConsensusModelPtr &model) :
80 SampleConsensus<Storage> (model),
81 min_coverage_percent_ (0.9),
82 max_batches_ (5),
83 iterations_per_batch_ (1000)
84 {
85 // Maximum number of trials before we give up.
86 max_iterations_ = 10000;
87 }
88
89 /** \brief RANSAC (RAndom SAmple Consensus) main constructor
90 * \param model a Sample Consensus model
91 * \param threshold distance to model threshold
92 */
93 MultiRandomSampleConsensus (const SampleConsensusModelPtr &model, double threshold) :
94 SampleConsensus<Storage> (model, threshold)
95 {
96 // Maximum number of trials before we give up.
97 max_iterations_ = 10000;
98 }
99
100 /** \brief Compute the actual model and find the inliers
101 * \param debug_verbosity_level enable/disable on-screen debug
102 * information and set the verbosity level
103 */
104 bool
105 computeModel (int debug_verbosity_level = 0);
106
107 /** \brief how much (in percent) of the point cloud should be covered?
108 * If it is not possible to find enough planes, it will stop according to the regular ransac criteria
109 */
110 void
111 setMinimumCoverage (float percent)
112 {
113 min_coverage_percent_ = percent;
114 }
115
116 /** \brief Sets the maximum number of batches that should be processed.
117 * Every Batch computes up to iterations_per_batch_ models and verifies them.
118 * If planes with a sufficiently high total inlier count are found earlier, the
119 * actual number of batch runs might be lower.
120 */
121 void
122 setMaximumBatches (int max_batches)
123 {
124 max_batches_ = max_batches_;
125 }
126
127 /** \brief Sets the maximum number of batches that should be processed.
128 * Every Batch computes up to max_iterations_ models and verifies them.
129 * If planes with a sufficiently high total inlier count are found earlier, the
130 * actual number of batch runs might be lower.
131 */
132 void
133 setIerationsPerBatch(int iterations_per_batch)
134 {
135 iterations_per_batch_ = iterations_per_batch;
136 }
137
138 inline std::vector<IndicesPtr>
139 getAllInliers () { return all_inliers_; }
140
141 inline std::vector<int>
142 getAllInlierCounts () { return all_inlier_counts_; }
143
144 /** \brief Return the model coefficients of the best model found so far.
145 */
146 inline std::vector<float4>
148 {
149 return all_model_coefficients_;
150 }
151
152 /** \brief Return the model coefficients of the best model found so far.
153 */
154 inline std::vector<float3>
156 {
157 return all_model_centroids_;
158 }
159
160 private:
161 float min_coverage_percent_;
162 unsigned int max_batches_;
163 unsigned int iterations_per_batch_;
164
165 /** \brief The vector of the centroids of our models computed directly from the models found. */
166 std::vector<float3> all_model_centroids_;
167
168 /** \brief The vector of coefficients of our models computed directly from the models found. */
169 std::vector<float4> all_model_coefficients_;
170
171 std::vector<IndicesPtr> all_inliers_;
172 std::vector<int> all_inlier_counts_;
173 };
174
175 } // namespace
176} // namespace
RandomSampleConsensus represents an implementation of the RANSAC (RAndom SAmple Consensus) algorithm,...
Definition: multi_ransac.h:56
void setMaximumBatches(int max_batches)
Sets the maximum number of batches that should be processed.
Definition: multi_ransac.h:122
std::vector< int > getAllInlierCounts()
Definition: multi_ransac.h:142
MultiRandomSampleConsensus(const SampleConsensusModelPtr &model, double threshold)
RANSAC (RAndom SAmple Consensus) main constructor.
Definition: multi_ransac.h:93
std::vector< float3 > getAllModelCentroids()
Return the model coefficients of the best model found so far.
Definition: multi_ransac.h:155
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:111
void setIerationsPerBatch(int iterations_per_batch)
Sets the maximum number of batches that should be processed.
Definition: multi_ransac.h:133
std::vector< float4 > getAllModelCoefficients()
Return the model coefficients of the best model found so far.
Definition: multi_ransac.h:147
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:79
std::vector< IndicesPtr > getAllInliers()
Definition: multi_ransac.h:139
IndicesPtr inliers_stencil_
Definition: sac.h:180
Indices model_
The model found after the last computeModel () as point cloud indices.
Definition: sac.h:176
float probability_
Desired probability of choosing at least one sample free from outliers.
Definition: sac.h:186
float threshold_
Distance to model threshold.
Definition: sac.h:192
int max_iterations_
Maximum number of iterations before giving up.
Definition: sac.h:195
Coefficients model_coefficients_
The coefficients of our model computed directly from the model found.
Definition: sac.h:183
IndicesPtr inliers_
The indices of the points that were chosen as inliers after the last call.
Definition: sac.h:179
SampleConsensusModelPtr sac_model_
The underlying data model used (what is it that we attempt to search for).
Definition: sac.h:173
int iterations_
Total number of internal loop iterations that we've done so far.
Definition: sac.h:189
typename Storage< float4 >::type Hypotheses
Definition: sac_model.h:105
shared_ptr< const typename Storage< int >::type > IndicesConstPtr
Definition: sac_model.h:99
shared_ptr< typename Storage< int >::type > IndicesPtr
Definition: sac_model.h:98
typename Storage< float >::type Coefficients
Definition: sac_model.h:101
typename Storage< int >::type Indices
Definition: sac_model.h:97
shared_ptr< SampleConsensusModel > Ptr
Definition: sac_model.h:94