conversion.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef CLOUD_CONVERSION_H_
  2. #define CLOUD_CONVERSION_H_
  3. #include <iostream>
  4. #include <pcl/point_types.h>
  5. #include <pcl/point_cloud.h>
  6. #define DEFAULT_BEGAIN 0XAA
  7. #define DEFAULT_END 0XFF
  8. class Conversion {
  9. public:
  10. /**
  11. * @brief 将点云数据打包组成二进制数据,数据包含头、包长、数据、包尾,未添加校验位。
  12. * @param cloud 点云数据
  13. * @param data 指针需要在外部提前分配好空间大小,大小应该为cloud->size() * sizeof(float) * 3 + 4
  14. * @param length 数据长度,大小应该为cloud->size() * sizeof(float) * 3 + 4
  15. **/
  16. static bool PackHexPointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, unsigned char* data, unsigned int length);
  17. /**
  18. * @brief 将二进制数据转换为点云数据,二进制数据应包含头、包长、数据、包尾,未添加校验位。
  19. * @param cloud 点云数据
  20. * @param data 二进制数据,数据应包含头、包长、数据、包尾,未添加校验位
  21. **/
  22. static bool UnPackHexPointCloud(unsigned char *data, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud);
  23. /**
  24. * @brief 将点云数据组成string类型数据,数据格式可以自己打印看一下。
  25. * @param cloud 点云数据
  26. * @param data 转换后的数据,数据包含开头、点云数量、点云数据、结尾
  27. **/
  28. static bool PackStringPointCloud(const pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, std::string &data);
  29. /**
  30. * @brief 将组包的string点云数据转为pointcloud格式,点云组包数据应包含开头、点云数量、点云数据、结尾
  31. * @param data 组包的string点云数据
  32. * @param cloud 点云数据
  33. **/
  34. static bool UnPackStringPointCloud(const std::string &data, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud);
  35. /**
  36. * @brief 将一串全部是点云数据的string转换为二进制数据
  37. * @param cloud 点云数据
  38. * @param data 二进制数据,指针需要在外部提前分配好空间大小,大小应该为cloud->size() * sizeof(float) * 3
  39. * @param length 数据长度,大小应该为cloud->size() * sizeof(float) * 3
  40. **/
  41. static bool String2Hex(const std::string &cloud, unsigned char* data, unsigned int length);
  42. static bool String2Hex(const std::string &cloud, unsigned char* data, unsigned int &length);
  43. private:
  44. static void Float2Bytes(float value, unsigned char *bytes, int pos = 0);
  45. static void Bytes2Float(unsigned char * bytes, float* number);
  46. };
  47. #endif