Point Cloud Library (PCL) 1.12.1
sac_model_circle.hpp
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2009, 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
41#ifndef PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_CIRCLE_H_
42#define PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_CIRCLE_H_
43
44#include <unsupported/Eigen/NonLinearOptimization> // for LevenbergMarquardt
45#include <pcl/sample_consensus/sac_model_circle.h>
46#include <pcl/common/concatenate.h>
47
48//////////////////////////////////////////////////////////////////////////
49template <typename PointT> bool
51{
52 if (samples.size () != sample_size_)
53 {
54 PCL_ERROR ("[pcl::SampleConsensusModelCircle2D::isSampleGood] Wrong number of samples (is %lu, should be %lu)!\n", samples.size (), sample_size_);
55 return (false);
56 }
57 // Get the values at the two points
58 Eigen::Array2d p0 ((*input_)[samples[0]].x, (*input_)[samples[0]].y);
59 Eigen::Array2d p1 ((*input_)[samples[1]].x, (*input_)[samples[1]].y);
60 Eigen::Array2d p2 ((*input_)[samples[2]].x, (*input_)[samples[2]].y);
61
62 // Compute the segment values (in 2d) between p1 and p0
63 p1 -= p0;
64 // Compute the segment values (in 2d) between p2 and p0
65 p2 -= p0;
66
67 Eigen::Array2d dy1dy2 = p1 / p2;
68
69 return (dy1dy2[0] != dy1dy2[1]);
70}
71
72//////////////////////////////////////////////////////////////////////////
73template <typename PointT> bool
74pcl::SampleConsensusModelCircle2D<PointT>::computeModelCoefficients (const Indices &samples, Eigen::VectorXf &model_coefficients) const
75{
76 // Need 3 samples
77 if (samples.size () != sample_size_)
78 {
79 PCL_ERROR ("[pcl::SampleConsensusModelCircle2D::computeModelCoefficients] Invalid set of samples given (%lu)!\n", samples.size ());
80 return (false);
81 }
82
83 model_coefficients.resize (model_size_);
84
85 Eigen::Vector2d p0 ((*input_)[samples[0]].x, (*input_)[samples[0]].y);
86 Eigen::Vector2d p1 ((*input_)[samples[1]].x, (*input_)[samples[1]].y);
87 Eigen::Vector2d p2 ((*input_)[samples[2]].x, (*input_)[samples[2]].y);
88
89 Eigen::Vector2d u = (p0 + p1) / 2.0;
90 Eigen::Vector2d v = (p1 + p2) / 2.0;
91
92 Eigen::Vector2d p1p0dif = p1 - p0;
93 Eigen::Vector2d p2p1dif = p2 - p1;
94 Eigen::Vector2d uvdif = u - v;
95
96 Eigen::Vector2d m (- p1p0dif[0] / p1p0dif[1], - p2p1dif[0] / p2p1dif[1]);
97
98 // Center (x, y)
99 model_coefficients[0] = static_cast<float> ((m[0] * u[0] - m[1] * v[0] - uvdif[1] ) / (m[0] - m[1]));
100 model_coefficients[1] = static_cast<float> ((m[0] * m[1] * uvdif[0] + m[0] * v[1] - m[1] * u[1]) / (m[0] - m[1]));
101
102 // Radius
103 model_coefficients[2] = static_cast<float> (sqrt ((model_coefficients[0] - p0[0]) * (model_coefficients[0] - p0[0]) +
104 (model_coefficients[1] - p0[1]) * (model_coefficients[1] - p0[1])));
105 PCL_DEBUG ("[pcl::SampleConsensusModelCircle2D::computeModelCoefficients] Model is (%g,%g,%g).\n",
106 model_coefficients[0], model_coefficients[1], model_coefficients[2]);
107 return (true);
108}
109
110#define AT(POS) ((*input_)[(*indices_)[(POS)]])
111
112#ifdef __AVX__
113// This function computes the squared distances (i.e. the distances without the square root) of 8 points to the center of the circle
114template <typename PointT> inline __m256 pcl::SampleConsensusModelCircle2D<PointT>::sqr_dist8 (const std::size_t i, const __m256 a_vec, const __m256 b_vec) const
115{
116 const __m256 tmp1 = _mm256_sub_ps (_mm256_set_ps (AT(i ).x, AT(i+1).x, AT(i+2).x, AT(i+3).x, AT(i+4).x, AT(i+5).x, AT(i+6).x, AT(i+7).x), a_vec);
117 const __m256 tmp2 = _mm256_sub_ps (_mm256_set_ps (AT(i ).y, AT(i+1).y, AT(i+2).y, AT(i+3).y, AT(i+4).y, AT(i+5).y, AT(i+6).y, AT(i+7).y), b_vec);
118 return _mm256_add_ps (_mm256_mul_ps (tmp1, tmp1), _mm256_mul_ps (tmp2, tmp2));
119}
120#endif // ifdef __AVX__
121
122#ifdef __SSE__
123// This function computes the squared distances (i.e. the distances without the square root) of 4 points to the center of the circle
124template <typename PointT> inline __m128 pcl::SampleConsensusModelCircle2D<PointT>::sqr_dist4 (const std::size_t i, const __m128 a_vec, const __m128 b_vec) const
125{
126 const __m128 tmp1 = _mm_sub_ps (_mm_set_ps (AT(i ).x, AT(i+1).x, AT(i+2).x, AT(i+3).x), a_vec);
127 const __m128 tmp2 = _mm_sub_ps (_mm_set_ps (AT(i ).y, AT(i+1).y, AT(i+2).y, AT(i+3).y), b_vec);
128 return _mm_add_ps (_mm_mul_ps (tmp1, tmp1), _mm_mul_ps (tmp2, tmp2));
129}
130#endif // ifdef __SSE__
131
132#undef AT
133
134//////////////////////////////////////////////////////////////////////////
135template <typename PointT> void
136pcl::SampleConsensusModelCircle2D<PointT>::getDistancesToModel (const Eigen::VectorXf &model_coefficients, std::vector<double> &distances) const
137{
138 // Check if the model is valid given the user constraints
139 if (!isModelValid (model_coefficients))
140 {
141 distances.clear ();
142 return;
143 }
144 distances.resize (indices_->size ());
145
146 // Iterate through the 3d points and calculate the distances from them to the circle
147 for (std::size_t i = 0; i < indices_->size (); ++i)
148 // Calculate the distance from the point to the circle as the difference between
149 // dist(point,circle_origin) and circle_radius
150 distances[i] = std::abs (std::sqrt (
151 ( (*input_)[(*indices_)[i]].x - model_coefficients[0] ) *
152 ( (*input_)[(*indices_)[i]].x - model_coefficients[0] ) +
153
154 ( (*input_)[(*indices_)[i]].y - model_coefficients[1] ) *
155 ( (*input_)[(*indices_)[i]].y - model_coefficients[1] )
156 ) - model_coefficients[2]);
157}
158
159//////////////////////////////////////////////////////////////////////////
160template <typename PointT> void
162 const Eigen::VectorXf &model_coefficients, const double threshold,
163 Indices &inliers)
164{
165 // Check if the model is valid given the user constraints
166 if (!isModelValid (model_coefficients))
168 inliers.clear ();
169 return;
170 }
171 inliers.clear ();
172 error_sqr_dists_.clear ();
173 inliers.reserve (indices_->size ());
174 error_sqr_dists_.reserve (indices_->size ());
175
176 const float sqr_inner_radius = (model_coefficients[2] <= threshold ? 0.0f : (model_coefficients[2] - threshold) * (model_coefficients[2] - threshold));
177 const float sqr_outer_radius = (model_coefficients[2] + threshold) * (model_coefficients[2] + threshold);
178 // Iterate through the 3d points and calculate the distances from them to the circle
179 for (std::size_t i = 0; i < indices_->size (); ++i)
180 {
181 // To avoid sqrt computation: consider one larger circle (radius + threshold) and one smaller circle (radius - threshold).
182 // Valid if point is in larger circle, but not in smaller circle.
183 const float sqr_dist = ( (*input_)[(*indices_)[i]].x - model_coefficients[0] ) *
184 ( (*input_)[(*indices_)[i]].x - model_coefficients[0] ) +
185 ( (*input_)[(*indices_)[i]].y - model_coefficients[1] ) *
186 ( (*input_)[(*indices_)[i]].y - model_coefficients[1] );
187 if ((sqr_dist <= sqr_outer_radius) && (sqr_dist >= sqr_inner_radius))
189 // Returns the indices of the points whose distances are smaller than the threshold
190 inliers.push_back ((*indices_)[i]);
191 // Only compute exact distance if necessary (if point is inlier)
192 error_sqr_dists_.push_back (static_cast<double> (std::abs (std::sqrt (sqr_dist) - model_coefficients[2])));
193 }
194 }
195}
196
197//////////////////////////////////////////////////////////////////////////
198template <typename PointT> std::size_t
200 const Eigen::VectorXf &model_coefficients, const double threshold) const
201{
202 // Check if the model is valid given the user constraints
203 if (!isModelValid (model_coefficients))
204 return (0);
205
206#if defined (__AVX__) && defined (__AVX2__)
207 return countWithinDistanceAVX (model_coefficients, threshold);
208#elif defined (__SSE__) && defined (__SSE2__) && defined (__SSE4_1__)
209 return countWithinDistanceSSE (model_coefficients, threshold);
210#else
211 return countWithinDistanceStandard (model_coefficients, threshold);
212#endif
213}
214
215//////////////////////////////////////////////////////////////////////////
216template <typename PointT> std::size_t
218 const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i) const
219{
220 std::size_t nr_p = 0;
221 const float sqr_inner_radius = (model_coefficients[2] <= threshold ? 0.0f : (model_coefficients[2] - threshold) * (model_coefficients[2] - threshold));
222 const float sqr_outer_radius = (model_coefficients[2] + threshold) * (model_coefficients[2] + threshold);
223 // Iterate through the 3d points and calculate the distances from them to the circle
224 for (; i < indices_->size (); ++i)
225 {
226 // To avoid sqrt computation: consider one larger circle (radius + threshold) and one smaller circle (radius - threshold).
227 // Valid if point is in larger circle, but not in smaller circle.
228 const float sqr_dist = ( (*input_)[(*indices_)[i]].x - model_coefficients[0] ) *
229 ( (*input_)[(*indices_)[i]].x - model_coefficients[0] ) +
230 ( (*input_)[(*indices_)[i]].y - model_coefficients[1] ) *
231 ( (*input_)[(*indices_)[i]].y - model_coefficients[1] );
232 if ((sqr_dist <= sqr_outer_radius) && (sqr_dist >= sqr_inner_radius))
233 nr_p++;
234 }
235 return (nr_p);
236}
237
238//////////////////////////////////////////////////////////////////////////
239#if defined (__SSE__) && defined (__SSE2__) && defined (__SSE4_1__)
240template <typename PointT> std::size_t
242 const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i) const
243{
244 std::size_t nr_p = 0;
245 const __m128 a_vec = _mm_set1_ps (model_coefficients[0]);
246 const __m128 b_vec = _mm_set1_ps (model_coefficients[1]);
247 // To avoid sqrt computation: consider one larger circle (radius + threshold) and one smaller circle (radius - threshold). Valid if point is in larger circle, but not in smaller circle.
248 const __m128 sqr_inner_radius = _mm_set1_ps ((model_coefficients[2] <= threshold ? 0.0 : (model_coefficients[2]-threshold)*(model_coefficients[2]-threshold)));
249 const __m128 sqr_outer_radius = _mm_set1_ps ((model_coefficients[2]+threshold)*(model_coefficients[2]+threshold));
250 __m128i res = _mm_set1_epi32(0); // This corresponds to nr_p: 4 32bit integers that, summed together, hold the number of inliers
251 for (; (i + 4) <= indices_->size (); i += 4)
252 {
253 const __m128 sqr_dist = sqr_dist4 (i, a_vec, b_vec);
254 const __m128 mask = _mm_and_ps (_mm_cmplt_ps (sqr_inner_radius, sqr_dist), _mm_cmplt_ps (sqr_dist, sqr_outer_radius)); // The mask contains 1 bits if the corresponding points are inliers, else 0 bits
255 res = _mm_add_epi32 (res, _mm_and_si128 (_mm_set1_epi32 (1), _mm_castps_si128 (mask))); // The latter part creates a vector with ones (as 32bit integers) where the points are inliers
256 //const int res = _mm_movemask_ps (mask);
257 //if (res & 1) nr_p++;
258 //if (res & 2) nr_p++;
259 //if (res & 4) nr_p++;
260 //if (res & 8) nr_p++;
261 }
262 nr_p += _mm_extract_epi32 (res, 0);
263 nr_p += _mm_extract_epi32 (res, 1);
264 nr_p += _mm_extract_epi32 (res, 2);
265 nr_p += _mm_extract_epi32 (res, 3);
266
267 // Process the remaining points (at most 3)
268 nr_p += countWithinDistanceStandard (model_coefficients, threshold, i);
269 return (nr_p);
270}
271#endif
272
273//////////////////////////////////////////////////////////////////////////
274#if defined (__AVX__) && defined (__AVX2__)
275template <typename PointT> std::size_t
277 const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i) const
278{
279 std::size_t nr_p = 0;
280 const __m256 a_vec = _mm256_set1_ps (model_coefficients[0]);
281 const __m256 b_vec = _mm256_set1_ps (model_coefficients[1]);
282 // To avoid sqrt computation: consider one larger circle (radius + threshold) and one smaller circle (radius - threshold). Valid if point is in larger circle, but not in smaller circle.
283 const __m256 sqr_inner_radius = _mm256_set1_ps ((model_coefficients[2] <= threshold ? 0.0 : (model_coefficients[2]-threshold)*(model_coefficients[2]-threshold)));
284 const __m256 sqr_outer_radius = _mm256_set1_ps ((model_coefficients[2]+threshold)*(model_coefficients[2]+threshold));
285 __m256i res = _mm256_set1_epi32(0); // This corresponds to nr_p: 8 32bit integers that, summed together, hold the number of inliers
286 for (; (i + 8) <= indices_->size (); i += 8)
287 {
288 const __m256 sqr_dist = sqr_dist8 (i, a_vec, b_vec);
289 const __m256 mask = _mm256_and_ps (_mm256_cmp_ps (sqr_inner_radius, sqr_dist, _CMP_LT_OQ), _mm256_cmp_ps (sqr_dist, sqr_outer_radius, _CMP_LT_OQ)); // The mask contains 1 bits if the corresponding points are inliers, else 0 bits
290 res = _mm256_add_epi32 (res, _mm256_and_si256 (_mm256_set1_epi32 (1), _mm256_castps_si256 (mask))); // The latter part creates a vector with ones (as 32bit integers) where the points are inliers
291 //const int res = _mm256_movemask_ps (mask);
292 //if (res & 1) nr_p++;
293 //if (res & 2) nr_p++;
294 //if (res & 4) nr_p++;
295 //if (res & 8) nr_p++;
296 //if (res & 16) nr_p++;
297 //if (res & 32) nr_p++;
298 //if (res & 64) nr_p++;
299 //if (res & 128) nr_p++;
300 }
301 nr_p += _mm256_extract_epi32 (res, 0);
302 nr_p += _mm256_extract_epi32 (res, 1);
303 nr_p += _mm256_extract_epi32 (res, 2);
304 nr_p += _mm256_extract_epi32 (res, 3);
305 nr_p += _mm256_extract_epi32 (res, 4);
306 nr_p += _mm256_extract_epi32 (res, 5);
307 nr_p += _mm256_extract_epi32 (res, 6);
308 nr_p += _mm256_extract_epi32 (res, 7);
309
310 // Process the remaining points (at most 7)
311 nr_p += countWithinDistanceStandard (model_coefficients, threshold, i);
312 return (nr_p);
313}
314#endif
315
316//////////////////////////////////////////////////////////////////////////
317template <typename PointT> void
319 const Indices &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients) const
320{
321 optimized_coefficients = model_coefficients;
322
323 // Needs a set of valid model coefficients
324 if (!isModelValid (model_coefficients))
325 {
326 PCL_ERROR ("[pcl::SampleConsensusModelCircle2D::optimizeModelCoefficients] Given model is invalid!\n");
327 return;
328 }
329
330 // Need more than the minimum sample size to make a difference
331 if (inliers.size () <= sample_size_)
332 {
333 PCL_ERROR ("[pcl::SampleConsensusModelCircle2D::optimizeModelCoefficients] Not enough inliers to refine/optimize the model's coefficients (%lu)! Returning the same coefficients.\n", inliers.size ());
334 return;
335 }
336
337 OptimizationFunctor functor (this, inliers);
338 Eigen::NumericalDiff<OptimizationFunctor> num_diff (functor);
339 Eigen::LevenbergMarquardt<Eigen::NumericalDiff<OptimizationFunctor>, float> lm (num_diff);
340 int info = lm.minimize (optimized_coefficients);
341
342 // Compute the L2 norm of the residuals
343 PCL_DEBUG ("[pcl::SampleConsensusModelCircle2D::optimizeModelCoefficients] LM solver finished with exit code %i, having a residual norm of %g. \nInitial solution: %g %g %g \nFinal solution: %g %g %g\n",
344 info, lm.fvec.norm (), model_coefficients[0], model_coefficients[1], model_coefficients[2], optimized_coefficients[0], optimized_coefficients[1], optimized_coefficients[2]);
345}
346
347//////////////////////////////////////////////////////////////////////////
348template <typename PointT> void
350 const Indices &inliers, const Eigen::VectorXf &model_coefficients,
351 PointCloud &projected_points, bool copy_data_fields) const
352{
353 // Needs a valid set of model coefficients
354 if (!isModelValid (model_coefficients))
355 {
356 PCL_ERROR ("[pcl::SampleConsensusModelCircle2D::projectPoints] Given model is invalid!\n");
357 return;
358 }
359
360 projected_points.header = input_->header;
361 projected_points.is_dense = input_->is_dense;
362
363 // Copy all the data fields from the input cloud to the projected one?
364 if (copy_data_fields)
365 {
366 // Allocate enough space and copy the basics
367 projected_points.resize (input_->size ());
368 projected_points.width = input_->width;
369 projected_points.height = input_->height;
370
371 using FieldList = typename pcl::traits::fieldList<PointT>::type;
372 // Iterate over each point
373 for (std::size_t i = 0; i < projected_points.size (); ++i)
374 // Iterate over each dimension
375 pcl::for_each_type <FieldList> (NdConcatenateFunctor <PointT, PointT> ((*input_)[i], projected_points[i]));
376
377 // Iterate through the points and project them to the circle
378 for (const auto &inlier : inliers)
379 {
380 float dx = (*input_)[inlier].x - model_coefficients[0];
381 float dy = (*input_)[inlier].y - model_coefficients[1];
382 float a = std::sqrt ( (model_coefficients[2] * model_coefficients[2]) / (dx * dx + dy * dy) );
383
384 projected_points[inlier].x = a * dx + model_coefficients[0];
385 projected_points[inlier].y = a * dy + model_coefficients[1];
386 }
387 }
388 else
389 {
390 // Allocate enough space and copy the basics
391 projected_points.resize (inliers.size ());
392 projected_points.width = inliers.size ();
393 projected_points.height = 1;
394
395 using FieldList = typename pcl::traits::fieldList<PointT>::type;
396 // Iterate over each point
397 for (std::size_t i = 0; i < inliers.size (); ++i)
398 // Iterate over each dimension
399 pcl::for_each_type <FieldList> (NdConcatenateFunctor <PointT, PointT> ((*input_)[inliers[i]], projected_points[i]));
400
401 // Iterate through the points and project them to the circle
402 for (std::size_t i = 0; i < inliers.size (); ++i)
403 {
404 float dx = (*input_)[inliers[i]].x - model_coefficients[0];
405 float dy = (*input_)[inliers[i]].y - model_coefficients[1];
406 float a = std::sqrt ( (model_coefficients[2] * model_coefficients[2]) / (dx * dx + dy * dy) );
407
408 projected_points[i].x = a * dx + model_coefficients[0];
409 projected_points[i].y = a * dy + model_coefficients[1];
410 }
411 }
412}
413
414//////////////////////////////////////////////////////////////////////////
415template <typename PointT> bool
417 const std::set<index_t> &indices, const Eigen::VectorXf &model_coefficients, const double threshold) const
418{
419 // Needs a valid model coefficients
420 if (!isModelValid (model_coefficients))
421 {
422 PCL_ERROR ("[pcl::SampleConsensusModelCircle2D::doSamplesVerifyModel] Given model is invalid!\n");
423 return (false);
424 }
425
426 const float sqr_inner_radius = (model_coefficients[2] <= threshold ? 0.0f : (model_coefficients[2] - threshold) * (model_coefficients[2] - threshold));
427 const float sqr_outer_radius = (model_coefficients[2] + threshold) * (model_coefficients[2] + threshold);
428 for (const auto &index : indices)
429 {
430 // To avoid sqrt computation: consider one larger circle (radius + threshold) and one smaller circle (radius - threshold).
431 // Valid if point is in larger circle, but not in smaller circle.
432 const float sqr_dist = ( (*input_)[index].x - model_coefficients[0] ) *
433 ( (*input_)[index].x - model_coefficients[0] ) +
434 ( (*input_)[index].y - model_coefficients[1] ) *
435 ( (*input_)[index].y - model_coefficients[1] );
436 if ((sqr_dist > sqr_outer_radius) || (sqr_dist < sqr_inner_radius))
437 return (false);
438 }
439 return (true);
440}
441
442//////////////////////////////////////////////////////////////////////////
443template <typename PointT> bool
444pcl::SampleConsensusModelCircle2D<PointT>::isModelValid (const Eigen::VectorXf &model_coefficients) const
445{
446 if (!SampleConsensusModel<PointT>::isModelValid (model_coefficients))
447 return (false);
448
449 if (radius_min_ != -std::numeric_limits<double>::max() && model_coefficients[2] < radius_min_)
450 {
451 PCL_DEBUG ("[pcl::SampleConsensusModelCircle2D::isModelValid] Radius of circle is too small: should be larger than %g, but is %g.\n",
452 radius_min_, model_coefficients[2]);
453 return (false);
454 }
455 if (radius_max_ != std::numeric_limits<double>::max() && model_coefficients[2] > radius_max_)
456 {
457 PCL_DEBUG ("[pcl::SampleConsensusModelCircle2D::isModelValid] Radius of circle is too big: should be smaller than %g, but is %g.\n",
458 radius_max_, model_coefficients[2]);
459 return (false);
460 }
461
462 return (true);
463}
464
465#define PCL_INSTANTIATE_SampleConsensusModelCircle2D(T) template class PCL_EXPORTS pcl::SampleConsensusModelCircle2D<T>;
466
467#endif // PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_CIRCLE_H_
468
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
Definition: point_cloud.h:403
void resize(std::size_t count)
Resizes the container to contain count elements.
Definition: point_cloud.h:462
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:398
pcl::PCLHeader header
The point cloud header.
Definition: point_cloud.h:392
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:400
std::size_t size() const
Definition: point_cloud.h:443
SampleConsensusModelCircle2D defines a model for 2D circle segmentation on the X-Y plane.
std::size_t countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const override
Count all the points which respect the given model coefficients as inliers.
bool computeModelCoefficients(const Indices &samples, Eigen::VectorXf &model_coefficients) const override
Check whether the given index samples can form a valid 2D circle model, compute the model coefficient...
void projectPoints(const Indices &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields=true) const override
Create a new point cloud with inliers projected onto the 2d circle model.
bool isModelValid(const Eigen::VectorXf &model_coefficients) const override
Check whether a model is valid given the user constraints.
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers) override
Compute all distances from the cloud data to a given 2D circle model.
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const override
Compute all distances from the cloud data to a given 2D circle model.
void optimizeModelCoefficients(const Indices &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients) const override
Recompute the 2d circle coefficients using the given inlier set and return them to the user.
std::size_t countWithinDistanceStandard(const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i=0) const
This implementation uses no SIMD instructions.
bool isSampleGood(const Indices &samples) const override
Check if a sample of indices results in a good sample of points indices.
bool doSamplesVerifyModel(const std::set< index_t > &indices, const Eigen::VectorXf &model_coefficients, const double threshold) const override
Verify whether a subset of indices verifies the given 2d circle model coefficients.
SampleConsensusModel represents the base model class.
Definition: sac_model.h:70
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
Helper functor structure for concatenate.
Definition: concatenate.h:50