point_cloud_utilities.cpp
Go to the documentation of this file.
2 
3 #include <limits>
4 #include <string>
5 #include <vector>
6 
7 #include <ros/ros.h>
8 
9 double const NXLIB_TIMESTAMP_OFFSET = 11644473600;
10 
11 pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloudFromNxLib(NxLibItem const& node, std::string const& frame,
12  PointCloudROI const* roi)
13 {
14  int width, height;
15  double timestamp;
16  std::vector<float> data;
17 
18  node.getBinaryDataInfo(&width, &height, 0, 0, 0, &timestamp);
19  node.getBinaryData(data, 0);
20 
21  auto cloud = boost::make_shared<pcl::PointCloud<pcl::PointXYZ>>();
22 
23  // PCL timestamp is in microseconds and Unix time.
24  cloud->header.stamp = (timestamp - NXLIB_TIMESTAMP_OFFSET) * 1e6;
25  cloud->header.frame_id = frame;
26 
27  cloud->width = width;
28  cloud->height = height;
29  cloud->is_dense = false;
30  cloud->points.resize(width * height);
31  for (int i = 0; i < width * height; i++)
32  {
33  cloud->points[i].x = data[3 * i] / 1000.0f;
34  cloud->points[i].y = data[3 * i + 1] / 1000.0f;
35  cloud->points[i].z = data[3 * i + 2] / 1000.0f;
36 
37  if (roi != 0 && !roi->contains(cloud->points[i].x, cloud->points[i].y, cloud->points[i].z))
38  {
39  cloud->points[i].x = std::numeric_limits<float>::quiet_NaN();
40  cloud->points[i].y = std::numeric_limits<float>::quiet_NaN();
41  cloud->points[i].z = std::numeric_limits<float>::quiet_NaN();
42  }
43  }
44 
45  return cloud;
46 }
47 
48 pcl::PointCloud<pcl::PointNormal>::Ptr pointCloudWithNormalsFromNxLib(NxLibItem const& pointMapNode,
49  NxLibItem const& normalNode,
50  std::string const& frame,
51  PointCloudROI const* roi)
52 {
53  int width, height;
54  double timestamp;
55  std::vector<float> pointData;
56  std::vector<float> normalData;
57 
58  pointMapNode.getBinaryDataInfo(&width, &height, 0, 0, 0, &timestamp);
59  pointMapNode.getBinaryData(pointData, 0);
60  normalNode.getBinaryData(normalData, 0);
61 
62  auto cloud = boost::make_shared<pcl::PointCloud<pcl::PointNormal>>();
63 
64  // PCL timestamp is in microseconds and Unix time.
65  cloud->header.stamp = (timestamp - NXLIB_TIMESTAMP_OFFSET) * 1e6;
66  cloud->header.frame_id = frame;
67 
68  cloud->width = width;
69  cloud->height = height;
70  cloud->is_dense = false;
71  cloud->points.resize(width * height);
72  for (int i = 0; i < width * height; i++)
73  {
74  // The NxLib point cloud is in millimeters, ROS needs everything in meters.
75  cloud->points[i].x = pointData[3 * i] / 1000.0f;
76  cloud->points[i].y = pointData[3 * i + 1] / 1000.0f;
77  cloud->points[i].z = pointData[3 * i + 2] / 1000.0f;
78 
79  if (roi != 0 && !roi->contains(cloud->points[i].x, cloud->points[i].y, cloud->points[i].z))
80  {
81  cloud->points[i].x = std::numeric_limits<float>::quiet_NaN();
82  cloud->points[i].y = std::numeric_limits<float>::quiet_NaN();
83  cloud->points[i].z = std::numeric_limits<float>::quiet_NaN();
84  continue;
85  }
86 
87  cloud->points[i].normal_x = normalData[3 * i];
88  cloud->points[i].normal_y = normalData[3 * i + 1];
89  cloud->points[i].normal_z = normalData[3 * i + 2];
90  }
91 
92  return cloud;
93 }
pcl::PointCloud< pcl::PointXYZ >::Ptr pointCloudFromNxLib(NxLibItem const &node, std::string const &frame, PointCloudROI const *roi)
double const NXLIB_TIMESTAMP_OFFSET
pcl::PointCloud< pcl::PointNormal >::Ptr pointCloudWithNormalsFromNxLib(NxLibItem const &pointMapNode, NxLibItem const &normalNode, std::string const &frame, PointCloudROI const *roi)
bool contains(float x, float y, float z) const


ensenso_camera
Author(s): Ensenso
autogenerated on Thu May 16 2019 02:44:23