1 #ifndef __AREA_OCCUPANCY_ESTIMATOR_H 2 #define __AREA_OCCUPANCY_ESTIMATOR_H 25 location(loc),
x(inters_x),
y(inters_y) {}
37 Ray(
double x_s,
double x_d,
double y_s,
double y_d) :
38 x_st(x_s), x_delta(x_d), y_st(y_s), y_delta(y_d) {}
48 double inters_alpha = (y - y_st) / y_delta;
49 double inters_x = x_st + inters_alpha * x_delta;
50 if (inters_x < st_x || end_x < inters_x)
61 double inters_alpha = (x - x_st) / x_delta;
62 double inters_y = y_st + inters_alpha * y_delta;
63 if (inters_y < st_y || end_y < inters_y)
83 bool is_occ)
override {
108 return intersections;
113 const std::vector<Intersection> inters) {
114 if (inters.size() == 0) {
116 return bnds.
area() / 2;
119 assert(inters.size() == 2 || inters.size() == 4);
120 if (inters.size() == 4) {
125 double corner_x = 0, corner_y = 0, area = 0;
126 double chunk_is_triangle = inters[0].is_horiz() ^ inters[1].is_horiz();
127 if (chunk_is_triangle) {
130 for (
auto &inter : inters) {
131 switch (inter.location) {
140 for (
auto &inter : inters) {
141 if (inter.is_horiz()) {
142 area *= inter.x - corner_x;
144 area *= inter.y - corner_y;
150 corner_x = bnds.
bot, corner_y = bnds.
left;
152 for (
auto &inter : inters) {
153 if (inter.is_horiz()) {
154 base_sum += inter.x - corner_x;
156 base_sum += inter.y - corner_y;
160 area = 0.5 * (bnds.
top - bnds.
bot) * base_sum;
164 beam.
x_st, beam.
y_st, corner_x, corner_y)) {
165 area = bnds.
area() - area;
171 double line_x2,
double line_y2,
172 double x1,
double y1,
double x2,
double y2) {
173 double dx = line_x2 - line_x1, dy = line_y2 - line_y1;
174 return 0 < (dy*y1 - dx*x1 + dy*x1 - dx*y1) *
175 (dy*y2 - dx*x2 + dy*x2 - dx*y2);
180 double area_rate = chunk_area / total_area;
185 if (0.5 < area_rate) {
186 area_rate = 1 - area_rate;
double top
The top of a rectangle.
double bot
The bottom of a rectangle.
double base_empty_prob()
Returns the probability of being empty.
std::vector< Intersection > Intersections
void intersect_vert_segm(double st_y, double end_y, double x, IntersLocation loc, Intersections &consumer)
double right
The right side of a rectangle.
void intersect_horiz_segm(double st_x, double end_x, double y, IntersLocation loc, Intersections &consumer)
TFSIMD_FORCE_INLINE const tfScalar & y() const
double compute_chunk_area(const Beam &beam, const Rectangle &bnds, bool is_occ, const std::vector< Intersection > inters)
double y_end
Coordinates where the beam reaches an obstacle.
Defines interface Cell Occupancy Estimator. There are structures Occupancy and Beam that are used in ...
A strategy that estimates a grid cell's occupancy based on how a laser beam passes through the cell...
double left
The left side of a rectangle.
TFSIMD_FORCE_INLINE const tfScalar & x() const
Defines an axis-aligned rectangle.
AreaOccupancyEstimator(double occ, double empty)
bool are_on_the_same_side(double line_x1, double line_y1, double line_x2, double line_y2, double x1, double y1, double x2, double y2)
Intersection(IntersLocation loc, double inters_x, double inters_y)
Occupancy estimate_occupancy(double chunk_area, double total_area, bool is_occ)
double y_st
Coordinates of a start of the beam.
virtual Occupancy estimate_occupancy(const Beam &beam, const Rectangle &cell_bnds, bool is_occ) override
Intersections find_intersections(const Beam &beam, const Rectangle &bnds, bool is_occ)
Ray(double x_s, double x_d, double y_s, double y_d)