libalmath  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
occupancymapparams.h
Go to the documentation of this file.
1 #ifndef OCCUPANCYMAPPARAMS_H
2 #define OCCUPANCYMAPPARAMS_H
3 
4 #include <almath/tools/almath.h>
5 #include <almath/api.h>
6 
7 namespace AL {
8 namespace Math {
9 
18  struct ALMATH_API Point2Di {
19  explicit Point2Di(int _x=0, int _y=0): x(_x), y(_y) {}
20  int x;
21  int y;
22  bool operator == (const Point2Di& other) const {
23  return (x == other.x && y == other.y);
24  }
25  };
26 
35  struct ALMATH_API Pose2Di {
36  explicit Pose2Di(int _x=0, int _y=0, float _angle=0.0f)
37  : x(_x), y(_y), theta(_angle) {}
38  explicit Pose2Di(const Point2Di& pt, float _angle=0.0f)
39  : x(pt.x), y(pt.y), theta(_angle) {}
40 
41  int x;
42  int y;
43  float theta;
44  bool operator == (const Pose2Di& other) const {
45  return (x == other.x && y == other.y && std::abs(theta - other.theta) < 1e-6f);
46  }
47  };
48 
49  typedef std::vector<Pose2D> Pose2DVect;
50  typedef std::vector<Pose2Di> Pose2DiVect;
51 
52  static inline int roundToInt(float x) {
53  if (x >= 0.0f) {
54  return static_cast<int>(x + 0.5f);
55  }
56  return static_cast<int>(x - 0.5f);
57  }
58 
67 struct ALMATH_API OccupancyMapParams {
68  explicit OccupancyMapParams(int size, float metersPerPixel,
69  const Position2D &mapCenter, float obstacleThreshold = 0.25f);
70 
76  void initOriginOffset(const Position2D &mapCenter);
77 
79  const Math::Pose2D& pose,
80  float metersPerPixel,
81  const Math::Position2D& originOffset) {
82  const float kPixelPerMeter = 1.0f / metersPerPixel;
83 
84  const float xx = (pose.x - originOffset.x) * kPixelPerMeter;
85  const int x = roundToInt(xx);
86 
87  const float yy = -(pose.y - originOffset.y) * kPixelPerMeter;
88  const int y = roundToInt(yy);
89  return Point2Di(x, y);
90  }
91 
97  Point2Di getPixelFromPose(const Pose2D& pose) const;
98 
104  Point2Di getPixelFromPosition(const Position2D& position) const;
105 
111  Pose2D getPoseFromPixel(const Pose2Di &pixel) const;
112 
118  Position2D getPositionFromPixel(const Point2Di &pixel) const;
119 
126  Point2Di getDeltaPixelFromDeltaPosition(const Position2D& position) const;
127 
130  float getObstacleProbabilityThreshold() const;
131 
133  int size;
140 };
141 } // Math
142 } // AL
143 
144 #endif // OCCUPANCYMAPPARAMS_H
145 
std::vector< Pose2Di > Pose2DiVect
Create and play with a Position2D.
Definition: alposition2d.h:24
Create a OccupancyMapParams. OccupancyMapParams are used used to define occupancy maps and to provide...
float obstacleProbabilityThreshold
Maximum pixel value of an obstacle in the map
std::vector< Pose2D > Pose2DVect
Create a Point2Di. Point2Di are used on objects that deal with pixels only, and should not care about...
Position2D originOffset
Metrical coordinate of the (0, 0) pixel.
Point2Di(int _x=0, int _y=0)
float metersPerPixel
Factor representing the metrical size of each pixel.
A pose in a 2-dimentional space.
Definition: alpose2d.h:26
static Point2Di getPixelFromOffsetAndScale(const Math::Pose2D &pose, float metersPerPixel, const Math::Position2D &originOffset)
Pose2Di(int _x=0, int _y=0, float _angle=0.0f)
Pose2Di(const Point2Di &pt, float _angle=0.0f)
bool operator==(const BodyMass< T > &lhs, const BodyMass< T > &rhs)
Definition: bodymass.h:79
int size
Pixel size of the associated squared occupancy map.
Create a Pose2Di. Pose2Di are used on objects that deal with pixels only, and should not care about m...