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

Subclass of GridHealerAbstractBase for horizontal lines. More...

#include <GridHealerHorizontal.h>

Inheritance diagram for GridHealerHorizontal:
Inheritance graph
Collaboration diagram for GridHealerHorizontal:
Collaboration graph

Public Member Functions

 GridHealerHorizontal (GridLog &gridLog, const DocumentModelGridRemoval &modelGridRemoval)
 Single constructor.
virtual void applyMutualPairs (const QImage &image)
 Apply mutual pair points after all grid removal is done.
virtual void doHealingAcrossGaps (QImage &image)
 Guts of the algorithm in which sequences of black pixels across the gap from each other are filled in.
Public Member Functions inherited from GridHealerAbstractBase
 GridHealerAbstractBase (GridLog &gridLog, const DocumentModelGridRemoval &modelGridRemoval)
 Single constructor.
virtual ~GridHealerAbstractBase ()
void addMutualPair (int x0, int y0, int x1, int y1)
 Add two points on either side of a gap. Later, after removal, the black points will be processed.
void healed (QImage &image)
 Return healed image after grid removal.

Additional Inherited Members

Static Public Member Functions inherited from GridHealerAbstractBase
static int pixelCountInRegionThreshold (const DocumentModelGridRemoval &modelGridRemoval)
 Threshold number of pixels in a region to be considered too-small or big-enough.
Protected Member Functions inherited from GridHealerAbstractBase
void fillTrapezoid (QImage &image, int xBL, int yBL, int xBR, int yBR, int xTR, int yTR, int xTL, int yTL)
 Fill trapezoid with bottom left, bottom right, top right, and top left points.
GridLoggridLog ()
 Logging get method.
double maxPointSeparation () const
 Max point separation get method.
DocumentModelGridRemovalmodelGridRemoval ()
 DocumentModelGridRemoval get method.
const MutualPairHalvesmutualPairHalvesAbove () const
 Mutual pair halves for below grid line.
const MutualPairHalvesmutualPairHalvesBelow () const
 Mutual pair halves for above grid line.
bool pointsAreGood (const QImage &image, int x0, int y0, int x1, int y1) const
 Apply blackPixelRegionIsBigEnough to regions around each of two points.
void saveGapSeparation (double gapSeparation)
 Gap separation set method.

Detailed Description

Subclass of GridHealerAbstractBase for horizontal lines.

Definition at line 20 of file GridHealerHorizontal.h.

Constructor & Destructor Documentation

◆ GridHealerHorizontal()

GridHealerHorizontal::GridHealerHorizontal ( GridLog & gridLog,
const DocumentModelGridRemoval & modelGridRemoval )

Single constructor.

Definition at line 13 of file GridHealerHorizontal.cpp.

14 :
17{
18}
DocumentModelGridRemoval & modelGridRemoval()
DocumentModelGridRemoval get method.
GridHealerAbstractBase(GridLog &gridLog, const DocumentModelGridRemoval &modelGridRemoval)
Single constructor.
GridLog & gridLog()
Logging get method.

Member Function Documentation

◆ applyMutualPairs()

void GridHealerHorizontal::applyMutualPairs ( const QImage & image)
virtual

Apply mutual pair points after all grid removal is done.

Implements GridHealerAbstractBase.

Definition at line 20 of file GridHealerHorizontal.cpp.

21{
22 MutualPairHalves::const_iterator itrBelow = mutualPairHalvesBelow().begin();
23 MutualPairHalves::const_iterator itrAbove = mutualPairHalvesAbove().begin();
24
25 while (itrBelow != mutualPairHalvesBelow().end() &&
26 itrAbove != mutualPairHalvesAbove().end()) {
27
28 QPoint p0 = *(itrBelow++);
29 QPoint p1 = *(itrAbove++);
30
31 // Save (independent,dependent) pairs
32 if (Pixels::pixelIsBlack (image, p0.x(), p0.y())) {
33 m_blackPixelsBelow [p0.x()] = p0.y();
34 }
35
36 if (Pixels::pixelIsBlack (image, p1.x(), p1.y())) {
37 m_blackPixelsAbove [p1.x()] = p1.y();
38 }
39
40 saveGapSeparation (qAbs (p1.y() - p0.y()));
41 }
42}
const MutualPairHalves & mutualPairHalvesAbove() const
Mutual pair halves for below grid line.
const MutualPairHalves & mutualPairHalvesBelow() const
Mutual pair halves for above grid line.
void saveGapSeparation(double gapSeparation)
Gap separation set method.
static bool pixelIsBlack(const QImage &image, int x, int y)
Return true if pixel is black in black and white image.
Definition Pixels.cpp:286

◆ doHealingAcrossGaps()

void GridHealerHorizontal::doHealingAcrossGaps ( QImage & image)
virtual

Guts of the algorithm in which sequences of black pixels across the gap from each other are filled in.

Specifically, trapezoids with endpoints separated by no more than the closest distance are filled in. A greedy algorithm is used which makes each trapezoid as big as possible

Implements GridHealerAbstractBase.

Definition at line 44 of file GridHealerHorizontal.cpp.

45{
46 // LOG4CPP_INFO_S is replaced by GridLog
47 GridIndependentToDependent::const_iterator itrBelow, itrAbove;
48 for (itrBelow = m_blackPixelsBelow.begin(); itrBelow != m_blackPixelsBelow.end(); itrBelow++) {
49 QPoint p (itrBelow.key(),
50 itrBelow.value());
53 }
54 for (itrAbove = m_blackPixelsAbove.begin(); itrAbove != m_blackPixelsAbove.end(); itrAbove++) {
55 QPoint p (itrAbove.key(),
56 itrAbove.value());
59 }
60
61 // Algorithm requires at least one point in each of the lists
62 if (m_blackPixelsBelow.count() > 0 &&
63 m_blackPixelsAbove.count() > 0) {
64
65 int xFirst = qMin (m_blackPixelsBelow.firstKey (),
66 m_blackPixelsAbove.firstKey ());
67 int xLast = qMax (m_blackPixelsBelow.lastKey (),
68 m_blackPixelsAbove.lastKey ());
69
70 int xBelowEnd = 0; // Used by inner loop to skip to this iterator value
71
72 for (int xBelowStart = xFirst; xBelowStart <= xLast; xBelowStart++) {
73
74 if ((xBelowEnd < xBelowStart) &&
75 m_blackPixelsBelow.contains (xBelowStart)) {
76
77 // This could be the start of a new trapezoid. Find where the range on the same side ends
78 int xBelowOutOfBounds = xLast + 1; // Value forcing transition to out of range
79
80 for (xBelowEnd = xBelowStart + 1; xBelowEnd <= xBelowOutOfBounds; xBelowEnd++) {
81
82 if (!m_blackPixelsBelow.contains (xBelowEnd) || (xBelowEnd == xBelowOutOfBounds)) {
83
84 doHealingOnBelowRange (image,
85 xBelowStart,
86 xBelowEnd,
87 qFloor (maxPointSeparation()));
88
89 // Go back to outer loop, which will skip to xBelowEnd
90 break;
91 }
92 }
93 }
94 }
95 }
96}
const double HALFWIDTH_HORIZONTAL
double maxPointSeparation() const
Max point separation get method.
void showInputPixel(const QPoint &p, double halfWidth)
Show pixels that are inputs to GridHealer.
Definition GridLog.cpp:68

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