Iterators
These functions allow iterating efficiently over a given shape in a 2D array. On every cell lying in the shape it calls a given functor. The functions iterate over all cells whose center lies in the shape and calls the given functor with the cell indexes as arguments. Three different shapes are available, namely rectangle, polygon and circle.
Examples
Examples, can be seen in the figures:
API
The iterator functions are overloaded. In total there are three versions each, differing in how the minimum and maximum values are specified:
no minimum and maximum specified
minimum set to zero and maximum specified
minimum and maximum specified
Iterate Circle
-
template<typename T, typename Functor>
void hector_math::iterateCircle(const Vector2<T> ¢er, double radius, Eigen::Index row_min, Eigen::Index row_max, Eigen::Index col_min, Eigen::Index col_max, Functor functor) Iterates over all indexes that lie in the given circle and for each index (x, y) calls the given functor. This method will iterate all cells where the center of the cell (x+0.5, y+0.5) is inside the circle. Note: The circle has to be in the index space, hence, if it is in map coordinates it might be necessary to divide it by the map resolution.
The indexes can be limited using the ranges [row_min, row_max) and [col_min, col_max) where row/col_min is included but row/col_max is excluded, i.e., the largest x index functor may be called with will be row_max - 1.
- Template Parameters:
Functor – A function or lambda method with the signature: void(Eigen::Index x, Eigen::Index y).
- Parameters:
center – The center of the circle that is iterated over.
radius – The radius of the circle that is iterated over.
functor – The function that will be called for each index (x, y) inside the circle.
Iterate Rectangle
-
template<typename T, typename Functor>
void hector_math::iterateRectangle(const Vector2<T> &a, const Vector2<T> &b, const Vector2<T> &c, Eigen::Index row_min, Eigen::Index row_max, Eigen::Index col_min, Eigen::Index col_max, Functor functor) Iterates over all indexes that lie in the rectangle formed by the three points a, b and c - where ab, and ac form adjacent edges of the rectangle - and for each index (x, y) calls the given functor. This method will iterate all cells where the center of the cell (x+0.5, y+0.5) is inside the rectangle. Note: The polygon has to be in the index space, hence, if it is in map coordinates it might be necessary to divide it by the map resolution.
The indexes can be limited using the ranges [row_min, row_max) and [col_min, col_max) where row/col_min is included but row/col_max is excluded, i.e., the largest x index functor may be called with will be row_max - 1.
Note: This method can actually iterate not only rectangles but also parallelograms. Theoretically, it would work for any convex quadrilateral (alt. quadrangle).
- Template Parameters:
Functor –
A function or lambda method with the signature: void(Eigen::Index x, Eigen::Index
y).
- Parameters:
polygon – The polygon that is iterated over.
functor – The function that will be called for each index (x, y) inside the polygon.
-
template<typename T, typename Functor>
void hector_math::iterateRectangle(const Vector2<T> &a, const Vector2<T> &b, const Vector2<T> &c, Eigen::Index rows, Eigen::Index cols, Functor functor) Overload of iterateRectangle where row_min and col_min are set to 0 to allow for bounded iteration of 2D matrices and arrays.
Iterate Polygon
-
template<typename T, typename Functor>
void hector_math::iteratePolygon(const Polygon<T> &polygon, Eigen::Index row_min, Eigen::Index row_max, Eigen::Index col_min, Eigen::Index col_max, Functor functor) Iterates over all indexes that lie in the given polygon and for each index (x, y) calls the given functor. This method will iterate all cells where the center of the cell (x+0.5, y+0.5) is inside the polygon. Note: The polygon has to be in the index space, hence, if it is in map coordinates it might be necessary to divide it by the map resolution.
The indexes can be limited using the ranges [row_min, row_max) and [col_min, col_max) where row/col_min is included but row/col_max is excluded, i.e., the largest x index functor may be called with will be row_max - 1.
- Template Parameters:
Functor – A function or lambda method with the signature: void(Eigen::Index x, Eigen::Index y).
- Parameters:
polygon – The polygon that is iterated over.
functor – The function that will be called for each index (x, y) inside the polygon.