123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #ifndef CLOUD_CONVERSION_H_
- #define CLOUD_CONVERSION_H_
- #include <iostream>
- #include <pcl/point_types.h>
- #include <pcl/point_cloud.h>
- #define DEFAULT_BEGAIN 0XAA
- #define DEFAULT_END 0XFF
- class Conversion {
- public:
- /**
- * @brief 将点云数据打包组成二进制数据,数据包含头、包长、数据、包尾,未添加校验位。
- * @param cloud 点云数据
- * @param data 指针需要在外部提前分配好空间大小,大小应该为cloud->size() * sizeof(float) * 3 + 4
- * @param length 数据长度,大小应该为cloud->size() * sizeof(float) * 3 + 4
- **/
- static bool PackHexPointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, unsigned char* data, unsigned int length);
- /**
- * @brief 将二进制数据转换为点云数据,二进制数据应包含头、包长、数据、包尾,未添加校验位。
- * @param cloud 点云数据
- * @param data 二进制数据,数据应包含头、包长、数据、包尾,未添加校验位
- **/
- static bool UnPackHexPointCloud(unsigned char *data, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud);
- /**
- * @brief 将点云数据组成string类型数据,数据格式可以自己打印看一下。
- * @param cloud 点云数据
- * @param data 转换后的数据,数据包含开头、点云数量、点云数据、结尾
- **/
- static bool PackStringPointCloud(const pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, std::string &data);
- /**
- * @brief 将组包的string点云数据转为pointcloud格式,点云组包数据应包含开头、点云数量、点云数据、结尾
- * @param data 组包的string点云数据
- * @param cloud 点云数据
- **/
- static bool UnPackStringPointCloud(const std::string &data, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud);
- /**
- * @brief 将一串全部是点云数据的string转换为二进制数据
- * @param cloud 点云数据
- * @param data 二进制数据,指针需要在外部提前分配好空间大小,大小应该为cloud->size() * sizeof(float) * 3
- * @param length 数据长度,大小应该为cloud->size() * sizeof(float) * 3
- **/
- static bool String2Hex(const std::string &cloud, unsigned char* data, unsigned int length);
- static bool String2Hex(const std::string &cloud, unsigned char* data, unsigned int &length);
- private:
- static void Float2Bytes(float value, unsigned char *bytes, int pos = 0);
- static void Bytes2Float(unsigned char * bytes, float* number);
- };
- #endif
|