K.Epf
K.Epf

Reputation: 67

how to access a point in the type of PCLPointCloud2

Is this correct to obtain a point cloud from a STL file 'sphere.stl' by the following code?

pcl::PolygonMesh mesh;
pcl::io::loadPolygonFileSTL("sphere.stl", mesh);
pcl::PCLPointCloud2::Ptr ThisCloud = boost::make_shared<pcl::PCLPointCloud2>(mesh.ThisCloud);

Then, how to access each point of 'ThisCloud'?

Upvotes: 2

Views: 3195

Answers (1)

Adrian Schneider
Adrian Schneider

Reputation: 1507

I think I converted the pcl::PCLPointCloud2 to a pcl::PointCloud<PointXYZ>:

...
// conversion
pcl::PointCloud<pcl::PointXYZ>::Ptr vertices( new pcl::PointCloud<pcl::PointXYZ> );
pcl::fromPCLPointCloud2( mesh.cloud, *vertices ); 

// access each vertex 
for( int idx = 0; idx < vertices->size(); idx++ )
{
   pcl::PointXYZ v = vertices->points[ idx ];

   float x = v._PointXYZ::data[ 0 ];
   float y = v._PointXYZ::data[ 1 ];
   float z = v._PointXYZ::data[ 2 ];
}

Upvotes: 4

Related Questions