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