47 #ifndef _MIRA_RASTERTIRANGLE_H_ 48 #define _MIRA_RASTERTIRANGLE_H_ 65 LeftVisitor(std::vector<int>& p) : mP(p) {}
66 void operator()(
int x,
int y,
int length) {
73 RightVisitor(std::vector<int>& p) : mP(p) {}
74 void operator()(
int x,
int y,
int length) {
79 template<
typename Visitor>
86 AdaptVisitor(Visitor&& visitor) : v(
std::forward<Visitor>(visitor)) {}
87 void operator()(
int x,
int y,
int length) {
125 template<
typename Visitor>
129 if(p1[1]<p0[1] || ((p1[1]==p0[1]) && (p1[0]<p0[0]))) {
130 std::swap(p1[0], p0[0]);
131 std::swap(p1[1], p0[1]);
134 if(p2[1]<p1[1] || ((p2[1]==p1[1]) && (p2[0]<p1[0]))) {
135 std::swap(p2[0], p1[0]);
136 std::swap(p2[1], p1[1]);
139 if(p1[1]<p0[1] || ((p1[1]==p0[1]) && (p1[0]<p0[0]))) {
140 std::swap(p1[0], p0[0]);
141 std::swap(p1[1], p0[1]);
165 int x0(p0[0]), x1(p1[0]), x2(p2[0]);
166 int y0(p0[1]), y1(p1[1]), y2(p2[1]);
168 const int dx01 = x1-x0;
169 const int dy01 = y1-y0;
171 const int dx02 = x2-x0;
172 const int dy02 = y2-y0;
175 if (dx01*dy02 == dx02*dy01) {
176 bresenhamRunSlice(x0, y0, x2, y2, Private::AdaptVisitor<Visitor>(std::forward<Visitor>(visitor)));
182 float p = float(dx02 * dy01) / dy02 + x0;
184 std::vector<int> left(dy02+1);
185 std::vector<int> right(dy02+1);
187 Private::LeftVisitor leftVisitor(left);
188 Private::RightVisitor rightVisitor(right);
205 for(
int i=0; i<=dy02; ++i)
206 visitor(left[i], right[i], i+y0);
218 template<
typename Visitor>
222 if((polygon.size() < 3)||(polygon.size() > 4))
224 throw XRuntime(
"Only polygons with 3 points and no inner rings are triangles");
227 auto pointIter = polygon.begin();
229 Point2i A = *pointIter; pointIter++;
230 Point2i B = *pointIter; pointIter++;
General point class template.
Definition: Point.h:135
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void bresenhamRunSlice(int x0, int y0, int x1, int y1, Visitor &&visitor)
Rasterizes a Bresenham line starting at coordinate (x0,y0) and ending in (x1,y1). ...
Definition: Bresenham.h:572
void rasterTriangle(Point2i p0, Point2i p1, Point2i p2, Visitor &&visitor)
Rasters a triangle scanline by scanline.
Definition: RasterTriangle.h:126
Commonly used exception classes.
boost::geometry::model::ring< Point2i > Polygon2i
A 2D polygon with integer precision.
Definition: Polygon.h:128
This header provides a set of functions to iterate over lines with the Bresenham or Bresenham Run-Sli...
Simple Wrapper for Boost::geometry polygon.