point2D_tool.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // Created by huli on 2020/9/1.
  3. //
  4. #ifndef POINT2D_TOOL_H
  5. #define POINT2D_TOOL_H
  6. //#define OPEN_PCL_FLAG
  7. #ifdef OPEN_PCL_FLAG
  8. #include <pcl/point_types.h>
  9. #include <pcl/PCLPointCloud2.h>
  10. #include <pcl/conversions.h>
  11. #include <pcl/common/common.h>
  12. #endif
  13. #include <stddef.h>
  14. #include <math.h>
  15. class Point2D_tool
  16. {
  17. public:
  18. //极坐标
  19. struct Polar_coordinates
  20. {
  21. float angle=0; //弧度
  22. float distance=0; //距离
  23. };
  24. //极坐标的限定范围
  25. struct Polar_coordinates_box
  26. {
  27. float angle_min=0; //角度最小值
  28. float angle_max=0; //角度最大值
  29. float distance_min=0; //距离最小值
  30. float distance_max=0; //距离最大值
  31. };
  32. //平面坐标
  33. struct Point2D
  34. {
  35. float x=0; //x轴
  36. float y=0; //y轴
  37. };
  38. //平面坐标的限定范围
  39. struct Point2D_box
  40. {
  41. float x_min=0; //x轴最小值
  42. float x_max=0; //x轴最大值
  43. float y_min=0; //y轴最小值
  44. float y_max=0; //y轴最大值
  45. };
  46. //平面坐标的转换矩阵, 可以进行旋转和平移, 不能缩放
  47. struct Point2D_transform
  48. {
  49. float m00=1;
  50. float m01=0;
  51. float m02=0;
  52. float m10=0;
  53. float m11=1;
  54. float m12=0;
  55. };
  56. //极坐标 -> 平面坐标
  57. static bool Polar_coordinates_to_point2D(Point2D_tool::Polar_coordinates* p_polar_coordinates, Point2D_tool::Point2D* p_point2D);
  58. //平面坐标 -> 极坐标
  59. static bool Point2D_to_polar_coordinates(Point2D_tool::Point2D* p_point2D, Point2D_tool::Polar_coordinates* p_polar_coordinates);
  60. //判断极坐标点是否在限制范围
  61. static bool limit_with_polar_coordinates_box(float distance, float angle, Point2D_tool::Polar_coordinates_box* p_polar_coordinates_box);
  62. //判断平面坐标点是否在限制范围
  63. static bool limit_with_point2D_box(float x, float y, Point2D_tool::Point2D_box* p_point2D_box);
  64. #ifdef OPEN_PCL_FLAG
  65. //平面坐标的转换, 可以进行旋转和平移, 不能缩放
  66. static bool transform_with_translation_rotation(float* p_x_in, float* p_y_in, float* p_x_out, float* p_y_out,
  67. Point2D_tool::Point2D_transform* p_point2D_transform);
  68. static bool transform_with_translation_rotation(pcl::PointXYZ* p_point3D_in, pcl::PointXYZ* p_point3D_out,
  69. Point2D_tool::Point2D_transform* p_point2D_transform);
  70. static bool transform_with_translation_rotation(pcl::PointCloud<pcl::PointXYZ>::Ptr p_cloud_in,
  71. pcl::PointCloud<pcl::PointXYZ>::Ptr p_cloud_out,
  72. Point2D_tool::Point2D_transform* p_point2D_transform);
  73. #endif
  74. };
  75. #endif //POINT2D_TOOL_H