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