Question

I get a compiler error for the following sample code, which is from a pcl tutorial

pcl::PointCloud<pcl::PointXYZ> cloud;
std::vector<pcl::PointXYZ> data = cloud.points;

http://pointclouds.org/documentation/tutorials/basic_structures.php

The full compile error is

> error: conversion from ‘std::vector<pcl::PointXYZ,
> Eigen::aligned_allocator<pcl::PointXYZ> >’ to non-scalar type
> ‘std::vector<pcl::PointXYZ>’ requested

My current pcl version is pcl 1.6, it was installed when I installed ROS groovy so I am not sure if thats the problem.

Was it helpful?

Solution

the problem is you cannot do this:

std::vector<pcl::PointXYZ> data ;

because PointXYZ type is a vector of size 3 (x,y,z), you would need a matrix to save a bunch o pointXYZs.

but if you want to save the points you can use a for loop.

for (int i=0; i < cloud.size()); i++)
{
    vector[0] = cloud.points[i].x;
    vector[1] = cloud.points[i].y;
    vector[2] = cloud.points[i].z;
}

if you want to define a point and assign it with values do this:

pcl::PointXYZ point;

because the definition is :

pcl::PointXYZ::PointXYZ (   
float   _x,
float   _y,
float   _z   
)       

OTHER TIPS

The compiler can not convert a cloud of points into the vector of points. I think you have to do it by yourself:

pcl::PointCloud<pcl::PointXYZ> cloud;
std::vector<pcl::PointXYZ> data ;
//initialize your cloud here
if (!cloud.empty())
for (int i=0;i<cloud.size();i++)
    data[0]=cloud.points[0];

hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top