2014-01-15 68 views
0

我得到以下樣本代碼的編譯器錯誤,這是從PCL教程PCL轉換請求

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

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

完整編譯錯誤是

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

我目前的pcl版本是pcl 1.6,它在我安裝ROS groovy時安裝,所以我不確定這是否是問題所在。

回答

0

問題是你不能做到這一點:

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

因爲PointXYZ型是大小3(X,Y,Z)的載體,你需要一個矩陣保存一堆ØpointXYZs。

但如果你想保存點,你可以使用for循環。

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; 
} 

如果要定義一個點,併爲其分配與價值做到這一點:

pcl::PointXYZ point; 

因爲定義是:

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

編譯器無法將點雲轉換爲點向量。 我認爲你必須自己做:

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]; 

希望它能幫助!