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