Two methods to iterate every points in pointcloud of PCL(两种遍历点云的方式)

懵懂的女人 提交于 2019-11-26 19:15:56

The most common way to do this is by subscript in the [] operand[1]

pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloud;
for(int nIndex = 0; nIndex < pointCloud->points.size (); nIndex++)
{
    pointCloud->points[nIndex].x;
    pointCloud->points[nIndex].y;
    pointCloud->points[nIndex].z;
}

The more efficient way is to use an iterator [2] [3]

for (std::vector<pcl::PointXYZ, Eigen::aligned_allocator<pcl::PointXYZ> >::iterator it = pointCloud.bigin(); it != cropedCloud.end(); it++)
{
    it->getVector3fMap();  // if double wanted, just say it->getVector3fMap().cast<double>
}

Note:

  1. The snippet should be modified to YOUR version before using it
  2. pcl::PointXYZ can be replaced by any type of PointT
  3. pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloud can be replaced by pcl::PointCloud<pcl::PointXYZ> pointCloud, so by the mean time replace pointCloud->points.size() instead of pointCloud.points.size()
    */

Let's talk about how to find a way to use data of unknown type

$ grep -rn -ie "points.begin ()"
surface/include/pcl/surface/impl/mls.hpp:509:    output.insert (output.end (), projected_points.begin (), projected_points.end ());
surface/include/pcl/surface/impl/convex_hull.hpp:258:  std::sort (idx_points.begin (), idx_points.end (), comparePoints2D);
apps/include/pcl/apps/vfh_nn_classifier.h:175:          training_features_->points.insert (training_features_->points.end (), training_features->points.begin (), training_features->points.end ());
keypoints/src/narf_keypoint.cpp:836:  std::sort (tmp_interest_points.begin (), tmp_interest_points.end (), isBetterInterestPoint);
tools/uniform_sampling.cpp:98:  std::sort (subsampled_indices.points.begin (), subsampled_indices.points.end ());
common/include/pcl/range_image/impl/range_image.hpp:1225:  for (typename PointCloudType::const_iterator it  = far_ranges.points.begin (); it != far_ranges.points.end (); ++it)
common/include/pcl/common/impl/polynomial_calculations.hpp:418:  for (typename std::vector<Eigen::Matrix<real, 3, 1> >::const_iterator it=samplePoints.begin ();
common/include/pcl/common/impl/polynomial_calculations.hpp:468:  //for (typename std::vector<Eigen::Matrix<real, 3, 1> >::const_iterator it=samplePoints.begin ();
common/include/pcl/common/impl/transforms.hpp:54:    cloud_out.points.assign (cloud_in.points.begin (), cloud_in.points.end ());
common/include/pcl/common/impl/transforms.hpp:155:    cloud_out.points.assign (cloud_in.points.begin (), cloud_in.points.end ());
common/include/pcl/point_cloud.h:434:      inline iterator begin () { return (points.begin ()); }
common/include/pcl/point_cloud.h:436:      inline const_iterator begin () const { return (points.begin ()); }
test/outofcore/test_outofcore.cpp:280:    for (AlignedPointTVector::iterator pointit = points.begin (); pointit != points.end (); ++pointit)
test/common/test_wrappers.cpp:111:                     cloud.points.begin ()->getVector3fMap ());
test/common/test_wrappers.cpp:115:  PointCloud<PointXYZ>::VectorType::const_iterator pit2 = cloud.points.begin ();
recognition/include/pcl/recognition/impl/hv/hv_go.hpp:617:  for (it = model_explains_scene_points.begin (); it != model_explains_scene_points.end (); it++, p++)
recognition/include/pcl/recognition/impl/implicit_shape_model.hpp:888:    for (point_i = sampled_point_cloud->points.begin (); point_i != sampled_point_cloud->points.end (); point_i++, point_index++)
recognition/include/pcl/recognition/impl/implicit_shape_model.hpp:896:      int dist = static_cast<int> (std::distance (sampled_point_cloud->points.begin (), point_i));
recognition/include/pcl/recognition/impl/implicit_shape_model.hpp:1192:  for (point_it = in_cloud->points.begin (); point_it != in_cloud->points.end (); point_it++)
features/include/pcl/features/rsd.h:66:    typename PointCloud<Histogram<N> >::VectorType::iterator it = histogramsPC.points.begin ();

References:

[1] Filtering a PointCloud using a PassThrough filter
[2] Euclidean Cluster Extraction
[3] Creating a PCL point cloud using a container of Eigen Vector3d

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!