Search code examples
point-cloud-librarypoint-clouds

pcl conversion from A to non-scalar type B requested


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.


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   
    )