47 #ifndef _MIRA_BASE_INCLUDE_GEOMETRY_RASTERPOLYGON_H_ 48 #define _MIRA_BASE_INCLUDE_GEOMETRY_RASTERPOLYGON_H_ 65 template<
class Visitor>
69 assert(activeEdges.
begin <= activeEdges.
end);
70 assert(std::distance(activeEdges.
begin, activeEdges.
end) % 2 == 0);
75 if (region.y0() <= activeEdges.
currentY && activeEdges.
currentY < region.y1()) {
76 for (
auto it = activeEdges.
begin; it != activeEdges.
end; std::advance(it, 2)) {
77 const auto x_start = std::max(region.x0(),
78 (int)std::floor(it->getCurrentCut()));
79 const auto x_end = std::min(region.x1() - 1,
80 (int)std::floor(std::next(it)->getCurrentCut()));
97 template<
class Visitor>
99 Visitor& visitor,
const int nextY)
101 assert(std::distance(activeEdges.
begin, activeEdges.
end) == 2);
103 auto& firstEdge = *activeEdges.
begin;
104 auto& secondEdge = *std::next(activeEdges.
begin);
105 while (activeEdges.
currentY > nextY) {
106 if (region.y0() <= activeEdges.
currentY && activeEdges.
currentY < region.y1()) {
107 auto cut1 = (int)std::floor(firstEdge.getCurrentCut());
108 auto cut2 = (int)std::floor(secondEdge.getCurrentCut());
111 std::swap(cut1, cut2);
113 const auto x_start = std::max(region.x0(), cut1);
114 const auto x_end = std::min(region.x1() - 1, cut2);
121 firstEdge.advanceToNextCut();
122 secondEdge.advanceToNextCut();
131 template<
class Visitor>
138 if (region.y0() <= y_inGrid_coordinates && y_inGrid_coordinates < region.y1()) {
140 const auto x_start = std::max(region.x0(),
142 const auto x_end = std::min(region.x1() - 1,
145 if (
visitInterval(x_start, x_end, y_inGrid_coordinates, visitor)) {
157 template<
class Visitor>
162 assert(activeEdges.
begin <= activeEdges.
end);
163 assert(std::distance(activeEdges.
begin, activeEdges.
end) % 2 == 0);
168 for (
auto it = activeEdges.
begin; it != activeEdges.
end; std::advance(it, 2)) {
169 intervals.
addOrMerge({it->getCurrentCut(), std::next(it)->getCurrentCut()});
181 template<
class Visitor>
183 Visitor& visitor,
const uint
precision,
const int nextY)
185 assert(std::distance(activeEdges.
begin, activeEdges.
end) == 2);
187 auto& firstEdge = *activeEdges.
begin;
188 auto& secondEdge = *std::next(activeEdges.
begin);
189 while (activeEdges.
currentY > nextY) {
190 auto cut1 = std::floor(firstEdge.getCurrentCut());
191 auto cut2 = std::floor(secondEdge.getCurrentCut());
194 std::swap(cut1, cut2);
202 firstEdge.advanceToNextCut();
203 secondEdge.advanceToNextCut();
231 template<
class TransformationInRegion,
class Visitor>
233 TransformationInRegion&& transformation, Visitor&& visitor)
235 if (polygon.size() <= 2)
242 std::forward<TransformationInRegion>(transformation));
244 if (edgeList.empty())
247 assert(edgeList.size() >= 2);
250 for (; activeEdges.end != edgeList.end(); ++activeEdges.end) {
251 while (activeEdges.currentY > activeEdges.end->getMaxY()) {
253 if (std::distance(activeEdges.begin, activeEdges.end) == 2) {
264 while (activeEdges.begin != activeEdges.end) {
266 if (std::distance(activeEdges.begin, activeEdges.end) == 2) {
267 const auto yEnd = activeEdges.
currentY - activeEdges.begin->getNumberOfCutsWithGrid();
296 template<
class TransformationInRegion,
class Visitor>
298 TransformationInRegion&& transformation, Visitor&& visitor, uint
precision)
302 rasterPolygon(polygon, region, std::forward<TransformationInRegion>(transformation),
303 std::forward<Visitor>(visitor));
307 if (polygon.size() <= 2)
315 return p_transformed;
318 if (edgeList.empty())
321 assert(edgeList.size() >= 2);
326 for (; activeEdges.end != edgeList.end(); ++activeEdges.end) {
327 while (activeEdges.currentY > activeEdges.end->getMaxY()) {
329 if (std::distance(activeEdges.begin, activeEdges.end) == 2) {
331 activeEdges.end->getMaxY())) {
341 while (activeEdges.begin != activeEdges.end || !intervals.empty()) {
343 if (std::distance(activeEdges.begin, activeEdges.end) == 2) {
344 const auto yEnd = activeEdges.currentY - activeEdges.begin->getNumberOfCutsWithGrid();
Definition: RasterPolygonUtils.h:165
void rasterPolygon(const Polygon2f &polygon, const Rect2i ®ion, TransformationInRegion &&transformation, Visitor &&visitor)
Function for rasterising a polygon.
Definition: RasterPolygon.h:232
bool processActiveEdges(ActiveEdgeCuts &activeEdges, const Rect2i ®ion, Visitor &visitor)
Process all active edges at current y, advance y, remove any edges that are finished, then return.
Definition: RasterPolygon.h:66
void clear()
Definition: RasterPolygonUtils.h:214
Utilities for rasterPolygon.
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void advanceEdgeCuts(ActiveEdgeCuts &activeEdges)
advance edge cuts, move empty edges to front of container (and continue behind them) ...
Definition: RasterPolygonUtils.h:275
void removeEmptyEdges(ActiveEdgeCuts &activeEdges)
move empty edges to front of container (and continue behind them)
Definition: RasterPolygonUtils.h:263
bool processTwoActiveEdges(ActiveEdgeCuts &activeEdges, const Rect2i ®ion, Visitor &visitor, const int nextY)
Optimization of processActiveEdges() for exactly 2 active edges: None of them can finish before anoth...
Definition: RasterPolygon.h:98
bool visitInterval(int x_start, int x_end, int y, Visitor &visitor)
Definition: RasterPolygonUtils.h:287
bool isValid() const
Returns true if this is a valid Rect where the maxCorner's components are not smaller than the minCor...
Definition: Rect.h:215
int scaleDown(int numToRound, int multiple)
Definition: RasterPolygonUtils.h:251
bool processIntervals(const ActiveEdgeCuts &activeEdges, Intervals &intervals, const Rect2i ®ion, Visitor &visitor, uint precision)
Definition: RasterPolygon.h:132
bool compareCurrentCut(const EdgeCuts &a, const EdgeCuts &b)
Definition: RasterPolygonUtils.h:257
const std::vector< Interval > & getIntervals() const
Definition: RasterPolygonUtils.h:242
bool processActiveEdges(ActiveEdgeCuts &activeEdges, Intervals &intervals, const Rect2i ®ion, Visitor &visitor, uint precision)
See above.
Definition: RasterPolygon.h:158
Provides multidimensional rectangle templates.
Definition: RasterPolygonUtils.h:206
iterator begin
Definition: RasterPolygonUtils.h:188
int currentY
Definition: RasterPolygonUtils.h:187
std::vector< EdgeCuts > createEdgeList(const Polygon2f &polygon, Transformation &&F)
Definition: RasterPolygonUtils.h:139
bool processTwoActiveEdges(ActiveEdgeCuts &activeEdges, Intervals &intervals, const Rect2i ®ion, Visitor &visitor, const uint precision, const int nextY)
See above.
Definition: RasterPolygon.h:182
PropertyHint precision(int p)
Sets the attribute "precision".
Definition: PropertyHint.h:285
iterator end
Definition: RasterPolygonUtils.h:189
void addOrMerge(Interval interval)
Definition: RasterPolygonUtils.h:224
boost::geometry::model::ring< Point2f > Polygon2f
A 2D polygon with 32 bit floating precision.
Definition: Polygon.h:131