Point Cloud Library (PCL)  1.13.0-dev
sac_model_cylinder.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2009-2010, 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_CYLINDER_H_
42 #define PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_CYLINDER_H_
43 
44 #include <unsupported/Eigen/NonLinearOptimization> // for LevenbergMarquardt
45 #include <pcl/sample_consensus/sac_model_cylinder.h>
46 #include <pcl/common/common.h> // for getAngle3D
47 #include <pcl/common/concatenate.h>
48 
49 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50 template <typename PointT, typename PointNT> bool
52 {
53  if (samples.size () != sample_size_)
54  {
55  PCL_ERROR ("[pcl::SampleConsensusModelCylinder::isSampleGood] Wrong number of samples (is %lu, should be %lu)!\n", samples.size (), sample_size_);
56  return (false);
57  }
58 
59  // Make sure that the two sample points are not identical
60  if (
61  std::abs ((*input_)[samples[0]].x - (*input_)[samples[1]].x) <= std::numeric_limits<float>::epsilon ()
62  &&
63  std::abs ((*input_)[samples[0]].y - (*input_)[samples[1]].y) <= std::numeric_limits<float>::epsilon ()
64  &&
65  std::abs ((*input_)[samples[0]].z - (*input_)[samples[1]].z) <= std::numeric_limits<float>::epsilon ())
66  {
67  PCL_ERROR ("[pcl::SampleConsensusModelCylinder::isSampleGood] The two sample points are (almost) identical!\n");
68  return (false);
69  }
70 
71  return (true);
72 }
73 
74 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75 template <typename PointT, typename PointNT> bool
77  const Indices &samples, Eigen::VectorXf &model_coefficients) const
78 {
79  // Make sure that the samples are valid
80  if (!isSampleGood (samples))
81  {
82  PCL_ERROR ("[pcl::SampleConsensusModelCylinder::computeModelCoefficients] Invalid set of samples given!\n");
83  return (false);
84  }
85 
86  if (!normals_)
87  {
88  PCL_ERROR ("[pcl::SampleConsensusModelCylinder::computeModelCoefficients] No input dataset containing normals was given!\n");
89  return (false);
90  }
91 
92  Eigen::Vector4f p1 ((*input_)[samples[0]].x, (*input_)[samples[0]].y, (*input_)[samples[0]].z, 0.0f);
93  Eigen::Vector4f p2 ((*input_)[samples[1]].x, (*input_)[samples[1]].y, (*input_)[samples[1]].z, 0.0f);
94 
95  Eigen::Vector4f n1 ((*normals_)[samples[0]].normal[0], (*normals_)[samples[0]].normal[1], (*normals_)[samples[0]].normal[2], 0.0f);
96  Eigen::Vector4f n2 ((*normals_)[samples[1]].normal[0], (*normals_)[samples[1]].normal[1], (*normals_)[samples[1]].normal[2], 0.0f);
97  Eigen::Vector4f w = n1 + p1 - p2;
98 
99  float a = n1.dot (n1);
100  float b = n1.dot (n2);
101  float c = n2.dot (n2);
102  float d = n1.dot (w);
103  float e = n2.dot (w);
104  float denominator = a*c - b*b;
105  float sc, tc;
106  // Compute the line parameters of the two closest points
107  if (denominator < 1e-8) // The lines are almost parallel
108  {
109  sc = 0.0f;
110  tc = (b > c ? d / b : e / c); // Use the largest denominator
111  }
112  else
113  {
114  sc = (b*e - c*d) / denominator;
115  tc = (a*e - b*d) / denominator;
116  }
117 
118  // point_on_axis, axis_direction
119  Eigen::Vector4f line_pt = p1 + n1 + sc * n1;
120  Eigen::Vector4f line_dir = p2 + tc * n2 - line_pt;
121  line_dir.normalize ();
122 
123  model_coefficients.resize (model_size_);
124  // model_coefficients.template head<3> () = line_pt.template head<3> ();
125  model_coefficients[0] = line_pt[0];
126  model_coefficients[1] = line_pt[1];
127  model_coefficients[2] = line_pt[2];
128  // model_coefficients.template segment<3> (3) = line_dir.template head<3> ();
129  model_coefficients[3] = line_dir[0];
130  model_coefficients[4] = line_dir[1];
131  model_coefficients[5] = line_dir[2];
132  // cylinder radius
133  model_coefficients[6] = static_cast<float> (sqrt (pcl::sqrPointToLineDistance (p1, line_pt, line_dir)));
134 
135  if (model_coefficients[6] > radius_max_ || model_coefficients[6] < radius_min_)
136  return (false);
137 
138  PCL_DEBUG ("[pcl::SampleConsensusModelCylinder::computeModelCoefficients] Model is (%g,%g,%g,%g,%g,%g,%g).\n",
139  model_coefficients[0], model_coefficients[1], model_coefficients[2], model_coefficients[3],
140  model_coefficients[4], model_coefficients[5], model_coefficients[6]);
141  return (true);
142 }
143 
144 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
145 template <typename PointT, typename PointNT> void
147  const Eigen::VectorXf &model_coefficients, std::vector<double> &distances) const
148 {
149  // Check if the model is valid given the user constraints
150  if (!isModelValid (model_coefficients))
151  {
152  distances.clear ();
153  return;
154  }
155 
156  distances.resize (indices_->size ());
157 
158  Eigen::Vector4f line_pt (model_coefficients[0], model_coefficients[1], model_coefficients[2], 0.0f);
159  Eigen::Vector4f line_dir (model_coefficients[3], model_coefficients[4], model_coefficients[5], 0.0f);
160  float ptdotdir = line_pt.dot (line_dir);
161  float dirdotdir = 1.0f / line_dir.dot (line_dir);
162  // Iterate through the 3d points and calculate the distances from them to the sphere
163  for (std::size_t i = 0; i < indices_->size (); ++i)
164  {
165  // Approximate the distance from the point to the cylinder as the difference between
166  // dist(point,cylinder_axis) and cylinder radius
167  // @note need to revise this.
168  Eigen::Vector4f pt ((*input_)[(*indices_)[i]].x, (*input_)[(*indices_)[i]].y, (*input_)[(*indices_)[i]].z, 0.0f);
169 
170  const double weighted_euclid_dist = (1.0 - normal_distance_weight_) * std::abs (pointToLineDistance (pt, model_coefficients) - model_coefficients[6]);
171 
172  // Calculate the point's projection on the cylinder axis
173  float k = (pt.dot (line_dir) - ptdotdir) * dirdotdir;
174  Eigen::Vector4f pt_proj = line_pt + k * line_dir;
175  Eigen::Vector4f dir = pt - pt_proj;
176  dir.normalize ();
177 
178  // Calculate the angular distance between the point normal and the (dir=pt_proj->pt) vector
179  Eigen::Vector4f n ((*normals_)[(*indices_)[i]].normal[0], (*normals_)[(*indices_)[i]].normal[1], (*normals_)[(*indices_)[i]].normal[2], 0.0f);
180  double d_normal = std::abs (getAngle3D (n, dir));
181  d_normal = (std::min) (d_normal, M_PI - d_normal);
182 
183  distances[i] = std::abs (normal_distance_weight_ * d_normal + weighted_euclid_dist);
184  }
185 }
186 
187 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
188 template <typename PointT, typename PointNT> void
190  const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers)
191 {
192  // Check if the model is valid given the user constraints
193  if (!isModelValid (model_coefficients))
194  {
195  inliers.clear ();
196  return;
197  }
198 
199  inliers.clear ();
200  error_sqr_dists_.clear ();
201  inliers.reserve (indices_->size ());
202  error_sqr_dists_.reserve (indices_->size ());
203 
204  Eigen::Vector4f line_pt (model_coefficients[0], model_coefficients[1], model_coefficients[2], 0.0f);
205  Eigen::Vector4f line_dir (model_coefficients[3], model_coefficients[4], model_coefficients[5], 0.0f);
206  float ptdotdir = line_pt.dot (line_dir);
207  float dirdotdir = 1.0f / line_dir.dot (line_dir);
208  // Iterate through the 3d points and calculate the distances from them to the sphere
209  for (std::size_t i = 0; i < indices_->size (); ++i)
210  {
211  // Approximate the distance from the point to the cylinder as the difference between
212  // dist(point,cylinder_axis) and cylinder radius
213  Eigen::Vector4f pt ((*input_)[(*indices_)[i]].x, (*input_)[(*indices_)[i]].y, (*input_)[(*indices_)[i]].z, 0.0f);
214  const double weighted_euclid_dist = (1.0 - normal_distance_weight_) * std::abs (pointToLineDistance (pt, model_coefficients) - model_coefficients[6]);
215  if (weighted_euclid_dist > threshold) // Early termination: cannot be an inlier
216  continue;
217 
218  // Calculate the point's projection on the cylinder axis
219  float k = (pt.dot (line_dir) - ptdotdir) * dirdotdir;
220  Eigen::Vector4f pt_proj = line_pt + k * line_dir;
221  Eigen::Vector4f dir = pt - pt_proj;
222  dir.normalize ();
223 
224  // Calculate the angular distance between the point normal and the (dir=pt_proj->pt) vector
225  Eigen::Vector4f n ((*normals_)[(*indices_)[i]].normal[0], (*normals_)[(*indices_)[i]].normal[1], (*normals_)[(*indices_)[i]].normal[2], 0.0f);
226  double d_normal = std::abs (getAngle3D (n, dir));
227  d_normal = (std::min) (d_normal, M_PI - d_normal);
228 
229  double distance = std::abs (normal_distance_weight_ * d_normal + weighted_euclid_dist);
230  if (distance < threshold)
231  {
232  // Returns the indices of the points whose distances are smaller than the threshold
233  inliers.push_back ((*indices_)[i]);
234  error_sqr_dists_.push_back (distance);
235  }
236  }
237 }
238 
239 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
240 template <typename PointT, typename PointNT> std::size_t
242  const Eigen::VectorXf &model_coefficients, const double threshold) const
243 {
244  // Check if the model is valid given the user constraints
245  if (!isModelValid (model_coefficients))
246  return (0);
247 
248  std::size_t nr_p = 0;
249 
250  Eigen::Vector4f line_pt (model_coefficients[0], model_coefficients[1], model_coefficients[2], 0);
251  Eigen::Vector4f line_dir (model_coefficients[3], model_coefficients[4], model_coefficients[5], 0);
252  float ptdotdir = line_pt.dot (line_dir);
253  float dirdotdir = 1.0f / line_dir.dot (line_dir);
254  // Iterate through the 3d points and calculate the distances from them to the sphere
255  for (std::size_t i = 0; i < indices_->size (); ++i)
256  {
257  // Approximate the distance from the point to the cylinder as the difference between
258  // dist(point,cylinder_axis) and cylinder radius
259  Eigen::Vector4f pt ((*input_)[(*indices_)[i]].x, (*input_)[(*indices_)[i]].y, (*input_)[(*indices_)[i]].z, 0.0f);
260  const double weighted_euclid_dist = (1.0 - normal_distance_weight_) * std::abs (pointToLineDistance (pt, model_coefficients) - model_coefficients[6]);
261  if (weighted_euclid_dist > threshold) // Early termination: cannot be an inlier
262  continue;
263 
264  // Calculate the point's projection on the cylinder axis
265  float k = (pt.dot (line_dir) - ptdotdir) * dirdotdir;
266  Eigen::Vector4f pt_proj = line_pt + k * line_dir;
267  Eigen::Vector4f dir = pt - pt_proj;
268  dir.normalize ();
269 
270  // Calculate the angular distance between the point normal and the (dir=pt_proj->pt) vector
271  Eigen::Vector4f n ((*normals_)[(*indices_)[i]].normal[0], (*normals_)[(*indices_)[i]].normal[1], (*normals_)[(*indices_)[i]].normal[2], 0.0f);
272  double d_normal = std::abs (getAngle3D (n, dir));
273  d_normal = (std::min) (d_normal, M_PI - d_normal);
274 
275  if (std::abs (normal_distance_weight_ * d_normal + weighted_euclid_dist) < threshold)
276  nr_p++;
277  }
278  return (nr_p);
279 }
280 
281 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
282 template <typename PointT, typename PointNT> void
284  const Indices &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients) const
285 {
286  optimized_coefficients = model_coefficients;
287 
288  // Needs a set of valid model coefficients
289  if (!isModelValid (model_coefficients))
290  {
291  PCL_ERROR ("[pcl::SampleConsensusModelCylinder::optimizeModelCoefficients] Given model is invalid!\n");
292  return;
293  }
294 
295  // Need more than the minimum sample size to make a difference
296  if (inliers.size () <= sample_size_)
297  {
298  PCL_ERROR ("[pcl::SampleConsensusModelCylinder:optimizeModelCoefficients] Not enough inliers found to optimize model coefficients (%lu)! Returning the same coefficients.\n", inliers.size ());
299  return;
300  }
301 
302  OptimizationFunctor functor (this, inliers);
303  Eigen::NumericalDiff<OptimizationFunctor > num_diff (functor);
304  Eigen::LevenbergMarquardt<Eigen::NumericalDiff<OptimizationFunctor>, float> lm (num_diff);
305  int info = lm.minimize (optimized_coefficients);
306 
307  // Compute the L2 norm of the residuals
308  PCL_DEBUG ("[pcl::SampleConsensusModelCylinder::optimizeModelCoefficients] LM solver finished with exit code %i, having a residual norm of %g. \nInitial solution: %g %g %g %g %g %g %g \nFinal solution: %g %g %g %g %g %g %g\n",
309  info, lm.fvec.norm (), model_coefficients[0], model_coefficients[1], model_coefficients[2], model_coefficients[3],
310  model_coefficients[4], model_coefficients[5], model_coefficients[6], optimized_coefficients[0], optimized_coefficients[1], optimized_coefficients[2], optimized_coefficients[3], optimized_coefficients[4], optimized_coefficients[5], optimized_coefficients[6]);
311 
312  Eigen::Vector3f line_dir (optimized_coefficients[3], optimized_coefficients[4], optimized_coefficients[5]);
313  line_dir.normalize ();
314  optimized_coefficients[3] = line_dir[0];
315  optimized_coefficients[4] = line_dir[1];
316  optimized_coefficients[5] = line_dir[2];
317 }
318 
319 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
320 template <typename PointT, typename PointNT> void
322  const Indices &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields) const
323 {
324  // Needs a valid set of model coefficients
325  if (!isModelValid (model_coefficients))
326  {
327  PCL_ERROR ("[pcl::SampleConsensusModelCylinder::projectPoints] Given model is invalid!\n");
328  return;
329  }
330 
331  projected_points.header = input_->header;
332  projected_points.is_dense = input_->is_dense;
333 
334  Eigen::Vector4f line_pt (model_coefficients[0], model_coefficients[1], model_coefficients[2], 0.0f);
335  Eigen::Vector4f line_dir (model_coefficients[3], model_coefficients[4], model_coefficients[5], 0.0f);
336  float ptdotdir = line_pt.dot (line_dir);
337  float dirdotdir = 1.0f / line_dir.dot (line_dir);
338 
339  // Copy all the data fields from the input cloud to the projected one?
340  if (copy_data_fields)
341  {
342  // Allocate enough space and copy the basics
343  projected_points.resize (input_->size ());
344  projected_points.width = input_->width;
345  projected_points.height = input_->height;
346 
347  using FieldList = typename pcl::traits::fieldList<PointT>::type;
348  // Iterate over each point
349  for (std::size_t i = 0; i < projected_points.size (); ++i)
350  // Iterate over each dimension
351  pcl::for_each_type <FieldList> (NdConcatenateFunctor <PointT, PointT> ((*input_)[i], projected_points[i]));
352 
353  // Iterate through the 3d points and calculate the distances from them to the cylinder
354  for (const auto &inlier : inliers)
355  {
356  Eigen::Vector4f p ((*input_)[inlier].x,
357  (*input_)[inlier].y,
358  (*input_)[inlier].z,
359  1);
360 
361  float k = (p.dot (line_dir) - ptdotdir) * dirdotdir;
362 
363  pcl::Vector4fMap pp = projected_points[inlier].getVector4fMap ();
364  pp.matrix () = line_pt + k * line_dir;
365 
366  Eigen::Vector4f dir = p - pp;
367  dir[3] = 0.0f;
368  dir.normalize ();
369 
370  // Calculate the projection of the point onto the cylinder
371  pp += dir * model_coefficients[6];
372  }
373  }
374  else
375  {
376  // Allocate enough space and copy the basics
377  projected_points.resize (inliers.size ());
378  projected_points.width = inliers.size ();
379  projected_points.height = 1;
380 
381  using FieldList = typename pcl::traits::fieldList<PointT>::type;
382  // Iterate over each point
383  for (std::size_t i = 0; i < inliers.size (); ++i)
384  // Iterate over each dimension
385  pcl::for_each_type <FieldList> (NdConcatenateFunctor <PointT, PointT> ((*input_)[inliers[i]], projected_points[i]));
386 
387  // Iterate through the 3d points and calculate the distances from them to the cylinder
388  for (std::size_t i = 0; i < inliers.size (); ++i)
389  {
390  pcl::Vector4fMap pp = projected_points[i].getVector4fMap ();
391  pcl::Vector4fMapConst p = (*input_)[inliers[i]].getVector4fMap ();
392 
393  float k = (p.dot (line_dir) - ptdotdir) * dirdotdir;
394  // Calculate the projection of the point on the line
395  pp.matrix () = line_pt + k * line_dir;
396 
397  Eigen::Vector4f dir = p - pp;
398  dir[3] = 0.0f;
399  dir.normalize ();
400 
401  // Calculate the projection of the point onto the cylinder
402  pp += dir * model_coefficients[6];
403  }
404  }
405 }
406 
407 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
408 template <typename PointT, typename PointNT> bool
410  const std::set<index_t> &indices, const Eigen::VectorXf &model_coefficients, const double threshold) const
411 {
412  // Needs a valid model coefficients
413  if (!isModelValid (model_coefficients))
414  {
415  PCL_ERROR ("[pcl::SampleConsensusModelCylinder::doSamplesVerifyModel] Given model is invalid!\n");
416  return (false);
417  }
418 
419  for (const auto &index : indices)
420  {
421  // Approximate the distance from the point to the cylinder as the difference between
422  // dist(point,cylinder_axis) and cylinder radius
423  // @note need to revise this.
424  Eigen::Vector4f pt ((*input_)[index].x, (*input_)[index].y, (*input_)[index].z, 0.0f);
425  if (std::abs (pointToLineDistance (pt, model_coefficients) - model_coefficients[6]) > threshold)
426  return (false);
427  }
428 
429  return (true);
430 }
431 
432 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
433 template <typename PointT, typename PointNT> double
435  const Eigen::Vector4f &pt, const Eigen::VectorXf &model_coefficients) const
436 {
437  Eigen::Vector4f line_pt (model_coefficients[0], model_coefficients[1], model_coefficients[2], 0.0f);
438  Eigen::Vector4f line_dir (model_coefficients[3], model_coefficients[4], model_coefficients[5], 0.0f);
439  return sqrt(pcl::sqrPointToLineDistance (pt, line_pt, line_dir));
440 }
441 
442 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
443 template <typename PointT, typename PointNT> void
445  const Eigen::Vector4f &pt, const Eigen::VectorXf &model_coefficients, Eigen::Vector4f &pt_proj) const
446 {
447  Eigen::Vector4f line_pt (model_coefficients[0], model_coefficients[1], model_coefficients[2], 0.0f);
448  Eigen::Vector4f line_dir (model_coefficients[3], model_coefficients[4], model_coefficients[5], 0.0f);
449 
450  float k = (pt.dot (line_dir) - line_pt.dot (line_dir)) * line_dir.dot (line_dir);
451  pt_proj = line_pt + k * line_dir;
452 
453  Eigen::Vector4f dir = pt - pt_proj;
454  dir.normalize ();
455 
456  // Calculate the projection of the point onto the cylinder
457  pt_proj += dir * model_coefficients[6];
458 }
459 
460 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
461 template <typename PointT, typename PointNT> bool
462 pcl::SampleConsensusModelCylinder<PointT, PointNT>::isModelValid (const Eigen::VectorXf &model_coefficients) const
463 {
464  if (!SampleConsensusModel<PointT>::isModelValid (model_coefficients))
465  return (false);
466 
467  // Check against template, if given
468  if (eps_angle_ > 0.0)
469  {
470  // Obtain the cylinder direction
471  const Eigen::Vector3f coeff(model_coefficients[3], model_coefficients[4], model_coefficients[5]);
472 
473  double angle_diff = std::abs (getAngle3D (axis_, coeff));
474  angle_diff = (std::min) (angle_diff, M_PI - angle_diff);
475  // Check whether the current cylinder model satisfies our angle threshold criterion with respect to the given axis
476  if (angle_diff > eps_angle_)
477  {
478  PCL_DEBUG ("[pcl::SampleConsensusModelCylinder::isModelValid] Angle between cylinder direction and given axis is too large.\n");
479  return (false);
480  }
481  }
482 
483  if (radius_min_ != -std::numeric_limits<double>::max() && model_coefficients[6] < radius_min_)
484  {
485  PCL_DEBUG ("[pcl::SampleConsensusModelCylinder::isModelValid] Radius is too small: should be larger than %g, but is %g.\n",
486  radius_min_, model_coefficients[6]);
487  return (false);
488  }
489  if (radius_max_ != std::numeric_limits<double>::max() && model_coefficients[6] > radius_max_)
490  {
491  PCL_DEBUG ("[pcl::SampleConsensusModelCylinder::isModelValid] Radius is too big: should be smaller than %g, but is %g.\n",
492  radius_max_, model_coefficients[6]);
493  return (false);
494  }
495 
496  return (true);
497 }
498 
499 #define PCL_INSTANTIATE_SampleConsensusModelCylinder(PointT, PointNT) template class PCL_EXPORTS pcl::SampleConsensusModelCylinder<PointT, PointNT>;
500 
501 #endif // PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_CYLINDER_H_
502 
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
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const override
Compute all distances from the cloud data to a given cylinder model.
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 cylinder model.
bool isModelValid(const Eigen::VectorXf &model_coefficients) const override
Check whether a model is valid given the user constraints.
void optimizeModelCoefficients(const Indices &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients) const override
Recompute the cylinder coefficients using the given inlier set and return them to the user.
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.
void projectPointToCylinder(const Eigen::Vector4f &pt, const Eigen::VectorXf &model_coefficients, Eigen::Vector4f &pt_proj) const
Project a point onto a cylinder given by its model coefficients (point_on_axis, axis_direction,...
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers) override
Select all the points which respect the given model coefficients as inliers.
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 cylinder model coefficients.
double pointToLineDistance(const Eigen::Vector4f &pt, const Eigen::VectorXf &model_coefficients) const
Get the distance from a point to a line (represented by a point and a direction)
bool computeModelCoefficients(const Indices &samples, Eigen::VectorXf &model_coefficients) const override
Check whether the given index samples can form a valid cylinder model, compute the model coefficients...
SampleConsensusModel represents the base model class.
Definition: sac_model.h:70
Define standard C methods and C++ classes that are common to all methods.
double getAngle3D(const Eigen::Vector4f &v1, const Eigen::Vector4f &v2, const bool in_degree=false)
Compute the smallest angle between two 3D vectors in radians (default) or degree.
Definition: common.hpp:47
double sqrPointToLineDistance(const Eigen::Vector4f &pt, const Eigen::Vector4f &line_pt, const Eigen::Vector4f &line_dir)
Get the square distance from a point to a line (represented by a point and a direction)
Definition: distances.h:75
float distance(const PointT &p1, const PointT &p2)
Definition: geometry.h:60
Eigen::Map< Eigen::Vector4f, Eigen::Aligned > Vector4fMap
const Eigen::Map< const Eigen::Vector4f, Eigen::Aligned > Vector4fMapConst
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
#define M_PI
Definition: pcl_macros.h:201
Helper functor structure for concatenate.
Definition: concatenate.h:50