map.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef _MAP_H_
  2. #define _MAP_H_
  3. #include <Eigen/Core>
  4. #include <Eigen/Geometry>
  5. #include <memory>
  6. #include <map>
  7. #include <string>
  8. #include "common/common.h"
  9. namespace hlzn_slam {
  10. class Map
  11. {
  12. public:
  13. /**
  14. * @说明:初始化一张空白地图
  15. * @param [in] length: 地图长度(列)
  16. * @param [in] width: 地图宽度(行)
  17. * @param [in] resolution: 地图分辨率
  18. */
  19. Map(float length, float width, float resolution);
  20. /**
  21. * @说明:使用eigen矩阵初始化地图,eigen矩阵矩阵的最大值为1
  22. * @param [in] map: eigen矩阵
  23. * @param [in] resolution: 地图分辨率
  24. */
  25. Map(Eigen::MatrixXf& map, float resolution, float x_origin, float y_origin);
  26. ~Map(){};
  27. /**
  28. * @说明:添加点云数据到地图中,点云对应的像素值逐渐增加
  29. * @param [in] pinot_cloud: 点云数据, [in] probablity 单次增加概率
  30. * @param [in] upper: 像素值的上限
  31. */
  32. void pixelValuePlus(const std::vector<Eigen::Vector3f>& pinot_cloud, const float& probablity, const float& upper);
  33. void pixelValuePlus2(const std::vector<Eigen::Vector3f>& pinot_cloud, const float& probablity, const float& upper);
  34. void pixelValuePlus3(const std::vector<Eigen::Vector3f>& pinot_cloud, const float& probablity, const float& upper);
  35. void pixelValuePlusShadow(const std::vector<Eigen::Vector3f>& pinot_cloud, const float& probablity, const float& upper);
  36. void pixelValuePlusShadow2(const std::vector<Eigen::Vector3f>& pinot_cloud, const float& probablity, const float& upper);
  37. void out(std::string path);
  38. /**
  39. * @说明:像素值衰减,构造概率梯度,防止地图僵化
  40. * @param [in] attenuate_value: 单次衰减量
  41. */
  42. void mapAttenuate(const float& attenuate_value);
  43. void mapShadowAttenuate(const float& attenuate_value);
  44. /**
  45. * @说明:清除地图上添加的点云数据
  46. */
  47. void clearMap();
  48. void clearShadowMap();
  49. /**
  50. * @说明:配置是否使用影子地图
  51. * @param [in] ok: 是否使用
  52. */
  53. void useShadow(bool ok);
  54. void word2Map(float x, float y, int& row, int& col);
  55. bool empty();
  56. int getRows();
  57. int getCols();
  58. float getLength();
  59. float getWidth();
  60. float getResolution();
  61. const float& getXorigin();
  62. const float& getYorigin();
  63. const float& getReciprocalResolution();
  64. /**
  65. * @说明:点云数据对应到地图上的代价值
  66. * @返回:代价(归一化)
  67. */
  68. float getCost(const common::PointCloud& point_cloud);
  69. float getPixelProbablity(const int row, const int col);
  70. /**
  71. * @说明:获取地图矩阵的引用
  72. * @返回:矩阵的引用
  73. */
  74. Eigen::MatrixXf& getMapCite();
  75. Eigen::MatrixXf& getInverseMapCite();
  76. /**
  77. * @说明:获取地图矩阵的指针
  78. * @返回:矩阵的指针
  79. */
  80. Eigen::MatrixXf* getMapPtr();
  81. void __sharpenMap(Eigen::MatrixXf& map);
  82. void weakenPixel(float x, float y, float value);
  83. private:
  84. void __increaseProbablity(int& row, int& col, const float& probablity, const float& upper);
  85. void __increaseProbablity2(int& row, int& col, const float& probablity, const float& upper);
  86. void __gaussianIncrease(int& row, int& col, const float& probablity, const float& upper);
  87. void __increaseProbablityShadow(int& row, int& col, const float& probablity, const float& upper);
  88. void __increaseProbablityShadow2(int& row, int& col, const float& probablity, const float& upper);
  89. void __world2Map(float x, float y, int& row, int& col);
  90. void __writeMap(int row, int col, float value);
  91. void __normProbablity(const float& upper);
  92. void __clearMap();
  93. bool __outBound(int row, int col);
  94. bool __outBound(Eigen::MatrixXf& map, int row, int col);
  95. float& __read(int row, int col);
  96. float& __read(Eigen::MatrixXf& map, int row, int col);
  97. float __readShadow(int row, int col);
  98. Eigen::MatrixXf map_;
  99. Eigen::MatrixXf shadow_map_;
  100. std::map<const std::tuple<int /*row*/, int /*col*/>,
  101. float* /*概率*/> index_table_;
  102. std::map<const std::tuple<int /*row*/, int /*col*/>,
  103. float* /*概率*/> shadow_;
  104. bool use_shadow_;
  105. int rows_, cols_;
  106. float width_, length_, resolution_, reciprocal_resolution_;
  107. float x_origin_, y_origin_;
  108. };
  109. }
  110. #endif