expander.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef _EXPANDER_H
  2. #define _EXPANDER_H
  3. #include <global_planner/potential_calculator.h>
  4. #include <global_planner/planner_core.h>
  5. namespace global_planner {
  6. class Expander {
  7. public:
  8. Expander(PotentialCalculator* p_calc, int nx, int ny) :
  9. lethal_cost_(253), neutral_cost_(50), factor_(3.0), p_calc_(p_calc) {
  10. setSize(nx, ny);
  11. }
  12. virtual bool calculatePotentials(unsigned char* costs, double start_x, double start_y, double end_x, double end_y,int cycles, float* potential) = 0;
  13. /**
  14. * @brief Sets or resets the size of the map
  15. * @param nx The x size of the map
  16. * @param ny The y size of the map
  17. */
  18. virtual void setSize(int nx, int ny)
  19. {
  20. nx_ = nx;
  21. ny_ = ny;
  22. ns_ = nx * ny;
  23. } /**< sets or resets the size of the map */
  24. void setLethalCost(unsigned char lethal_cost)
  25. {
  26. lethal_cost_ = lethal_cost;
  27. }
  28. void setNeutralCost(unsigned char neutral_cost)
  29. {
  30. neutral_cost_ = neutral_cost;
  31. }
  32. void setFactor(float factor)
  33. {
  34. factor_ = factor;
  35. }
  36. void clearEndpoint(unsigned char* costs, float* potential, int gx, int gy, int s)
  37. {
  38. int startCell = toIndex(gx, gy);
  39. for(int i=-s;i<=s;i++)
  40. {
  41. for(int j=-s;j<=s;j++)
  42. {
  43. int n = startCell+i+nx_*j;
  44. if(potential[n]<POT_HIGH)
  45. continue;
  46. float c = costs[n] + neutral_cost_;
  47. float pot = p_calc_->calculatePotential(potential, c, n);
  48. potential[n] = pot;
  49. }
  50. }
  51. }
  52. protected:
  53. inline int toIndex(int x, int y)
  54. {
  55. return x + nx_ * y;
  56. }
  57. int nx_, ny_, ns_; /**< size of grid, in pixels */
  58. unsigned char lethal_cost_, neutral_cost_;
  59. float factor_;
  60. PotentialCalculator* p_calc_;
  61. };
  62. } //end namespace global_planner
  63. #endif