Problems of NaN positions when converting PointCloud2 to pcl::PointCloud PointXYZRGB
Hello
I have tried to convert PointCloud2 message from openni_kinect to pcl::PointCloud<pcl::pointxyzrgb>. And I have some critical problem when I check position information of PointXYZRGB. All position data is written as 'nan'.
OS: Ubuntu Linux 10.04
ROS version: Electric
Sensor: Primesensor
The procedure of my code is like bellow:
A. get sensor_msg(camera/depth_registered/points) from openni_launch
B. convert sensor_msgs::PointCloud2 data (=pc2) to pcl::PointCloud<pcl::pointxyzrgb> data (=pcl_pc) as
pcl::fromROSMsg(pc2, pcl_pc);
at this time, I check the data of pcl_pc data like bellow
cout << pcl_pc.points[0].x << endl;
the result is 'nan'
C. I convert inversely from pcl::PointCloud<pcl::pointxyzrgb> data (=pcl_pc) to convert sensor_msgs::PointCloud2 data (=pc2) for publishing to rviz a
pcl::toROSMsg(pcl_pc, pc2);
pub_pc_rgb.publish(pc2);
and I can make certain that point clouds data displayed correctly on rviz.
D. Moreover Moreover I saved pcl::PointCloud<pcl::pointxyzrgb> into pcd format. the values of position in this case also 'nan' like below:
# .PCD v.7 - Point Cloud Data file format
VERSION .7
FIELDS x y z rgb
SIZE 4 4 4 4
TYPE F F F F
COUNT 1 1 1 1
WIDTH 640
HEIGHT 480
VIEWPOINT 0 0 0 1 0 0 0
POINTS 307200
DATA ascii
nan nan nan 7.1023033e-39
nan nan nan 7.1023033e-39
nan nan nan 6.8275213e-39
nan nan nan 6.9197169e-39
nan nan nan 6.8278744e-39
nan nan nan 6.7356788e-39
nan nan nan 6.367262e-39
...
...
I guess this problem is associated with conversion of data format. Because the type of PointCloud2.data is unsigned char and the type of PointXYZRGB.points is float. Inside of function pcl::fromROSMsg, they copy data between these two data structure using memcpy. That's the reason that it displays correctly on rviz when I convert inversely because the function toROSMsg also use memcpy between float data(pcl::PointCloud.points) and corresponding 4 unsigned char data (PointCloud2.data).
Is there any idea about this problem?? or this only happen to me ??