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