47 #ifndef _MIRA_BASE_INCLUDE_GEOMETRY_RASTERPOLYGONUTILS_H_ 48 #define _MIRA_BASE_INCLUDE_GEOMETRY_RASTERPOLYGONUTILS_H_ 53 namespace mira {
namespace Private {
63 if (start.y() < end.y()) {
64 std::swap(start, end);
69 const auto m = (end.x() - start.x()) / (end.y() - start.y());
70 const auto n = start.x() - m * start.y();
72 auto startY = (int)std::round(start.y());
73 auto endY = (int)std::round(end.y());
75 const float currentGrid = startY - 0.5;
120 constexpr
float epsilon = 0.001;
121 const auto diffy = std::round(point.y() - 0.5) - (point.y() - 0.5);
122 if (std::abs(diffy) < epsilon)
123 point.y() += diffy - std::copysign(epsilon, diffy);
130 if (prev.y() != current.y()) {
131 auto edge =
EdgeCuts(current, prev);
132 if (edge.hasCuts()) {
133 cuts.push_back(std::move(edge));
138 template<
class Transformation>
141 assert(polygon.size() > 1);
143 std::vector<EdgeCuts> cuts;
144 cuts.reserve(polygon.size());
148 for (
auto it = polygon.cbegin(); std::next(it) != polygon.cend(); ++it) {
152 prevPoint = currentPoint;
159 std::sort(cuts.begin(), cuts.end(),
200 assert(interval1.
end >= interval1.
start);
201 assert(interval2.
end >= interval2.
start);
203 return !(interval2.
end < interval1.
start || interval2.
start > interval1.
end);
211 mIntervals.reserve(size);
221 return mIntervals.empty();
227 const auto it = std::remove_if(mIntervals.begin(), mIntervals.end(), [&](
const Interval& tInterval) {
230 interval.
start = std::min(interval.
start, tInterval.start);
231 interval.
end = std::max(interval.
end, tInterval.end);
237 mIntervals.erase(it, mIntervals.end());
239 mIntervals.push_back(std::move(interval));
248 std::vector<Interval> mIntervals;
253 int isNegative = (int)(numToRound < 0);
254 return ((numToRound - isNegative * (multiple - 1)) / multiple);
268 activeEdges.
begin = it.base();
279 a.advanceToNextCut();
282 activeEdges.
begin = it.base();
286 template<
class Visitor>
289 for (
int x = x_start; x <= x_end; ++x) {
Definition: RasterPolygonUtils.h:165
float mCurrentCut
Definition: RasterPolygonUtils.h:115
void processEdge(const Point2f ¤t, const Point2f &prev, std::vector< EdgeCuts > &cuts)
Definition: RasterPolygonUtils.h:128
Point2f roundAwayFromGrid(Point2f point)
Definition: RasterPolygonUtils.h:118
bool empty() const
Definition: RasterPolygonUtils.h:219
void clear()
Definition: RasterPolygonUtils.h:214
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
int getMaxY() const
Definition: RasterPolygonUtils.h:85
bool visitInterval(int x_start, int x_end, int y, Visitor &visitor)
Definition: RasterPolygonUtils.h:287
int scaleDown(int numToRound, int multiple)
Definition: RasterPolygonUtils.h:251
std::vector< EdgeCuts >::iterator iterator
Definition: RasterPolygonUtils.h:167
bool compareCurrentCut(const EdgeCuts &a, const EdgeCuts &b)
Definition: RasterPolygonUtils.h:257
ActiveEdgeCuts(iterator first)
Definition: RasterPolygonUtils.h:170
bool intervalsOverlap(const Interval &interval1, const Interval &interval2)
Definition: RasterPolygonUtils.h:198
const std::vector< Interval > & getIntervals() const
Definition: RasterPolygonUtils.h:242
bool hasCuts() const
Definition: RasterPolygonUtils.h:95
Definition: RasterPolygonUtils.h:206
int mNumberOfCutsWithGrid
Definition: RasterPolygonUtils.h:113
Definition: RasterPolygonUtils.h:192
Simple Wrapper for Boost::geometry polygon.
reverse_iterator rbegin()
Definition: RasterPolygonUtils.h:177
iterator begin
Definition: RasterPolygonUtils.h:188
float getCurrentCut() const
Definition: RasterPolygonUtils.h:100
float start
Definition: RasterPolygonUtils.h:194
EdgeCuts(Point2f start, Point2f end)
Definition: RasterPolygonUtils.h:61
int currentY
Definition: RasterPolygonUtils.h:187
std::vector< EdgeCuts > createEdgeList(const Polygon2f &polygon, Transformation &&F)
Definition: RasterPolygonUtils.h:139
float mDeltaToNextCut
Definition: RasterPolygonUtils.h:114
reverse_iterator rend()
Definition: RasterPolygonUtils.h:182
iterator end
Definition: RasterPolygonUtils.h:189
void addOrMerge(Interval interval)
Definition: RasterPolygonUtils.h:224
Definition: RasterPolygonUtils.h:57
boost::geometry::model::ring< Point2f > Polygon2f
A 2D polygon with 32 bit floating precision.
Definition: Polygon.h:131
float end
Definition: RasterPolygonUtils.h:195
void advanceToNextCut()
Definition: RasterPolygonUtils.h:105
void reserve(std::size_t size)
Definition: RasterPolygonUtils.h:209
int mMaxY
Definition: RasterPolygonUtils.h:112
int getNumberOfCutsWithGrid() const
Definition: RasterPolygonUtils.h:90
std::reverse_iterator< iterator > reverse_iterator
Definition: RasterPolygonUtils.h:168