Point Cloud Library (PCL) 1.15.0
Loading...
Searching...
No Matches
sac.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_model.h>
41#include <pcl/cuda/point_cloud.h>
42#include <limits>
43//#include <set>
44
45namespace pcl
46{
47 namespace cuda
48 {
49 template <template <typename> class Storage>
51 {
52 using SampleConsensusModelPtr = typename SampleConsensusModel<Storage>::Ptr;
53 using Hypotheses = typename SampleConsensusModel<Storage>::Hypotheses;
54
55 using Indices = typename SampleConsensusModel<Storage>::Indices;
56 using IndicesPtr = typename SampleConsensusModel<Storage>::IndicesPtr;
57 using IndicesConstPtr = typename SampleConsensusModel<Storage>::IndicesConstPtr;
58
59 private:
60 /** \brief Constructor for base SAC. */
61 SampleConsensus () {};
62
63 public:
64 using Coefficients = typename Storage<float>::type;
65 using CoefficientsPtr = shared_ptr <Coefficients>;
66 using CoefficientsConstPtr = shared_ptr <const Coefficients>;
67
68 using Ptr = shared_ptr<SampleConsensus>;
69 using ConstPtr = shared_ptr<const SampleConsensus>;
70
71 /** \brief Constructor for base SAC.
72 * \param model a Sample Consensus model
73 */
74 SampleConsensus (const SampleConsensusModelPtr &model) :
75 sac_model_(model), probability_(0.99), iterations_(0),
76 threshold_(std::numeric_limits<double>::max()), max_iterations_(1000)
77 {};
78
79 /** \brief Constructor for base SAC.
80 * \param model a Sample Consensus model
81 * \param threshold distance to model threshold
82 */
83 SampleConsensus (const SampleConsensusModelPtr &model, float threshold) :
84 sac_model_(model), probability_ (0.99), iterations_ (0), threshold_ (threshold),
85 max_iterations_ (1000)
86 {};
87
88 /** \brief Destructor for base SAC. */
89 virtual ~SampleConsensus() = default;
90
91 /** \brief Set the distance to model threshold.
92 * \param threshold distance to model threshold
93 */
94 inline void
95 setDistanceThreshold (float threshold) { threshold_ = threshold; }
96
97 /** \brief Get the distance to model threshold, as set by the user. */
98 inline float
100
101 /** \brief Set the maximum number of iterations.
102 * \param max_iterations maximum number of iterations
103 */
104 inline void
105 setMaxIterations (int max_iterations) { max_iterations_ = max_iterations; }
106
107 /** \brief Get the maximum number of iterations, as set by the user. */
108 inline int
110
111 /** \brief Set the desired probability of choosing at least one sample free from
112 * outliers.
113 * \param probability the desired probability of choosing at least one sample free
114 * from outliers
115 * \note internally, the probability is set to 99% (0.99) by default.
116 */
117 inline void
118 setProbability (float probability) { probability_ = probability; }
119
120 /** \brief Obtain the probability of choosing at least one sample free from outliers,
121 * as set by the user.
122 */
123 inline float
125
126 /** \brief Compute the actual model. Pure virtual. */
127 virtual bool
128 computeModel (int debug_verbosity_level = 0) = 0;
129
130 /* \brief Get a set of randomly selected indices.
131 * \param indices the input indices vector
132 * \param nr_samples the desired number of point indices to randomly select
133 * \param indices_subset the resultant output set of randomly selected indices
134 */
135/* inline void
136 getRandomSamples (const IndicesPtr &indices, std::size_t nr_samples,
137 std::set<int> &indices_subset)
138 {
139 indices_subset.clear ();
140 while (indices_subset.size () < nr_samples)
141 indices_subset.insert ((*indices)[(int) (indices->size () * (rand () / (RAND_MAX + 1.0)))]);
142 }*/
143
144 /** \brief Return the best model found so far.
145 * \param model the resultant model
146 */
147 inline void
148 getModel (Indices &model) { model = model_; }
149
150 /** \brief Return the best set of inliers found so far for this model.
151 */
152 // inline void
153 // getInliers (std::vector<int> &inliers) { inliers = inliers_; }
154 inline IndicesPtr
155 getInliers () { return inliers_; }
156
157 // inline void
158 // getInliersStencil (Indices &inliers) { inliers = inliers_stencil_; }
159 inline IndicesPtr
161
162 /** \brief Return the model coefficients of the best model found so far.
163 * \param model_coefficients the resultant model coefficients
164 */
165 inline void
166 getModelCoefficients (Coefficients &model_coefficients)
167 {
168 model_coefficients = model_coefficients_;
169 }
170
171 protected:
172 /** \brief The underlying data model used (what is it that we attempt to search for). */
173 SampleConsensusModelPtr sac_model_;
174
175 /** \brief The model found after the last computeModel () as point cloud indices. */
176 Indices model_;
177
178 /** \brief The indices of the points that were chosen as inliers after the last call. */
179 IndicesPtr inliers_;
181
182 /** \brief The coefficients of our model computed directly from the model found. */
184
185 /** \brief Desired probability of choosing at least one sample free from outliers. */
187
188 /** \brief Total number of internal loop iterations that we've done so far. */
190
191 /** \brief Distance to model threshold. */
193
194 /** \brief Maximum number of iterations before giving up. */
196 };
197 } // namespace
198} // namespace
void setDistanceThreshold(float threshold)
Set the distance to model threshold.
Definition sac.h:95
SampleConsensus(const SampleConsensusModelPtr &model, float threshold)
Constructor for base SAC.
Definition sac.h:83
IndicesPtr inliers_stencil_
Definition sac.h:180
shared_ptr< const SampleConsensus > ConstPtr
Definition sac.h:69
IndicesPtr getInliersStencil()
Definition sac.h:160
IndicesPtr getInliers()
Return the best set of inliers found so far for this model.
Definition sac.h:155
typename Storage< float >::type Coefficients
Definition sac.h:64
int getMaxIterations()
Get the maximum number of iterations, as set by the user.
Definition sac.h:109
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
void getModel(Indices &model)
Return the best model found so far.
Definition sac.h:148
int max_iterations_
Maximum number of iterations before giving up.
Definition sac.h:195
void getModelCoefficients(Coefficients &model_coefficients)
Return the model coefficients of the best model found so far.
Definition sac.h:166
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
SampleConsensus(const SampleConsensusModelPtr &model)
Constructor for base SAC.
Definition sac.h:74
virtual bool computeModel(int debug_verbosity_level=0)=0
Compute the actual model.
void setMaxIterations(int max_iterations)
Set the maximum number of iterations.
Definition sac.h:105
shared_ptr< SampleConsensus > Ptr
Definition sac.h:68
virtual ~SampleConsensus()=default
Destructor for base SAC.
float getProbability()
Obtain the probability of choosing at least one sample free from outliers, as set by the user.
Definition sac.h:124
SampleConsensusModelPtr sac_model_
The underlying data model used (what is it that we attempt to search for).
Definition sac.h:173
shared_ptr< const Coefficients > CoefficientsConstPtr
Definition sac.h:66
int iterations_
Total number of internal loop iterations that we've done so far.
Definition sac.h:189
shared_ptr< Coefficients > CoefficientsPtr
Definition sac.h:65
void setProbability(float probability)
Set the desired probability of choosing at least one sample free from outliers.
Definition sac.h:118
float getDistanceThreshold()
Get the distance to model threshold, as set by the user.
Definition sac.h:99
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< int >::type Indices
Definition sac_model.h:97
shared_ptr< SampleConsensusModel > Ptr
Definition sac_model.h:94
shared_ptr< Indices > IndicesPtr
Definition pcl_base.h:58