Engauge Digitizer 2
Loading...
Searching...
No Matches
GridTriangleFill Class Reference

Class that does raster-line fill of a triangle, with logging customizations for GridHealer (and therefore not a generic class in util subdirectory). More...

#include <GridTriangleFill.h>

Collaboration diagram for GridTriangleFill:
Collaboration graph

Public Member Functions

 GridTriangleFill ()
void fill (GridLog &gridLog, QImage &image, const QPoint &p0, const QPoint &p1, const QPoint &p2)
 Fill triangle between these three points.

Detailed Description

Class that does raster-line fill of a triangle, with logging customizations for GridHealer (and therefore not a generic class in util subdirectory).

Inspired by http://www.sunshine2k.de/coding/java/TriangleRasterization/TriangleRasterization.html

Definition at line 18 of file GridTriangleFill.h.

Constructor & Destructor Documentation

◆ GridTriangleFill()

GridTriangleFill::GridTriangleFill ( )

Definition at line 29 of file GridTriangleFill.cpp.

30{
31}

Member Function Documentation

◆ fill()

void GridTriangleFill::fill ( GridLog & gridLog,
QImage & image,
const QPoint & p0,
const QPoint & p1,
const QPoint & p2 )

Fill triangle between these three points.

Definition at line 57 of file GridTriangleFill.cpp.

62{
63 if (p0In.x() > 0 && p0In.y() > 0 &&
64 p1In.x() > 0 && p1In.y() > 0 &&
65 p2In.x() > 0 && p2In.y() > 0) {
66
67 QPoint p0, p1, p2;
68
69 sortByAscendingY (p0In, p1In, p2In, p0, p1, p2);
70
71 if (p1.y() == p2.y()) {
72
73 // Triangle with flat bottom
74 flatBottom (gridLog, image, p0, p1, p2);
75
76 } else if (p0.y() == p1.y()) {
77
78 // Triangle with flat top
79 flatTop (gridLog, image, p0, p1, p2);
80
81 } else {
82
83 // General case is handled by splitting the triangle into one flat top piece and
84 // one flat bottom piece. Fourth point is at same y value as middle point p1
85 double s = double (p1.y() - p0.y()) / double (p2.y() - p0.y());
86 QPoint p3 (qFloor (p0.x() + s * (p2.x() - p0.x())),
87 p1.y());
88 flatBottom (gridLog, image, p0, p1, p3);
89 flatTop (gridLog, image, p1, p3, p2);
90 }
91 }
92}

The documentation for this class was generated from the following files: