16static bool compareByY (
const QPoint &first,
19 if (first.y() < second.y()) {
21 }
else if (first.y() > second.y()) {
25 return (first.x() < second.x());
33void GridTriangleFill::drawLine (
GridLog &gridLog,
39 const double RADIUS = 0.1;
48 for (
int x = x0; x <= x1; x++) {
52 image.setPixel (QPoint (x, y),
63 if (p0In.x() > 0 && p0In.y() > 0 &&
64 p1In.x() > 0 && p1In.y() > 0 &&
65 p2In.x() > 0 && p2In.y() > 0) {
69 sortByAscendingY (p0In, p1In, p2In, p0, p1, p2);
71 if (p1.y() == p2.y()) {
74 flatBottom (gridLog, image, p0, p1, p2);
76 }
else if (p0.y() == p1.y()) {
79 flatTop (gridLog, image, p0, p1, p2);
85 double s = double (p1.y() - p0.y()) / double (p2.y() - p0.y());
86 QPoint p3 (qFloor (p0.x() + s * (p2.x() - p0.x())),
88 flatBottom (gridLog, image, p0, p1, p3);
89 flatTop (gridLog, image, p1, p3, p2);
94void GridTriangleFill::flatBottom (
GridLog &gridLog,
101 double denom0 = p1.y() - p0.y();
102 double denom1 = p2.y() - p0.y();
103 if (qAbs (denom0) <= 0 || qAbs (denom1) <= 0) {
110 double slopeInverse0 = (p1.x() - p0.x()) / denom0;
111 double slopeInverse1 = (p2.x() - p0.x()) / denom1;
115 if (slopeInverse0 > slopeInverse1) {
116 double temp = slopeInverse0;
117 slopeInverse0 = slopeInverse1;
118 slopeInverse1 = temp;
124 for (
int scanLineY = p0.y(); scanLineY <= p1.y(); scanLineY++) {
136void GridTriangleFill::flatTop (
GridLog &gridLog,
143 double denom0 = p2.y() - p0.y();
144 double denom1 = p2.y() - p1.y();
145 if (qAbs (denom0) <= 0 || qAbs (denom1) <= 0) {
152 double slopeInverse0 = (p2.x() - p0.x()) / denom0;
153 double slopeInverse1 = (p2.x() - p1.x()) / denom1;
157 if (slopeInverse1 > slopeInverse0) {
158 double temp = slopeInverse0;
159 slopeInverse0 = slopeInverse1;
160 slopeInverse1 = temp;
166 for (
int scanLineY = p2.y(); scanLineY >= p0.y(); scanLineY--) {
178void GridTriangleFill::sortByAscendingY (QPoint p0In,
187 list << p0In << p1In << p2In;
188 std::sort (list.begin(), list.end(), compareByY);
Class that does special logging for GridLog and GridRemoval classes.
void showOutputScanLinePixel(int x, int y, double radius)
Show scan line pixel that is the output of GridHealer.
void fill(GridLog &gridLog, QImage &image, const QPoint &p0, const QPoint &p1, const QPoint &p2)
Fill triangle between these three points.