Engauge Digitizer  2
Public Member Functions | List of all members
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. More...
 
virtual void applyMutualPairs (const QImage &image)
 Apply mutual pair points after all grid removal is done. More...
 
virtual void doHealingAcrossGaps (QImage &image)
 Guts of the algorithm in which sequences of black pixels across the gap from each other are filled in. More...
 
- Public Member Functions inherited from GridHealerAbstractBase
 GridHealerAbstractBase (GridLog &gridLog, const DocumentModelGridRemoval &modelGridRemoval)
 Single constructor. More...
 
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. More...
 
void healed (QImage &image)
 Return healed image after grid removal. More...
 

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. More...
 
- 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. More...
 
GridLoggridLog ()
 Logging get method. More...
 
double maxPointSeparation () const
 Max point separation get method. More...
 
DocumentModelGridRemovalmodelGridRemoval ()
 DocumentModelGridRemoval get method. More...
 
const MutualPairHalvesmutualPairHalvesAbove () const
 Mutual pair halves for below grid line. More...
 
const MutualPairHalvesmutualPairHalvesBelow () const
 Mutual pair halves for above grid line. More...
 
bool pointsAreGood (const QImage &image, int x0, int y0, int x1, int y1) const
 Apply blackPixelRegionIsBigEnough to regions around each of two points. More...
 
void saveGapSeparation (double gapSeparation)
 Gap separation set method. More...
 

Detailed Description

Subclass of GridHealerAbstractBase for horizontal lines.

Definition at line 19 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 }

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 }

◆ 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 }

The documentation for this class was generated from the following files:
GridHealerAbstractBase::gridLog
GridLog & gridLog()
Logging get method.
Definition: GridHealerAbstractBase.cpp:81
GridLog::showInputPixel
void showInputPixel(const QPoint &p, double halfWidth)
Show pixels that are inputs to GridHealer.
Definition: GridLog.cpp:67
GridHealerAbstractBase::mutualPairHalvesAbove
const MutualPairHalves & mutualPairHalvesAbove() const
Mutual pair halves for below grid line.
Definition: GridHealerAbstractBase.cpp:102
GridHealerAbstractBase::modelGridRemoval
DocumentModelGridRemoval & modelGridRemoval()
DocumentModelGridRemoval get method.
Definition: GridHealerAbstractBase.cpp:97
HALFWIDTH_HORIZONTAL
const double HALFWIDTH_HORIZONTAL
Definition: GridHealerAbstractBase.h:18
GridHealerAbstractBase::saveGapSeparation
void saveGapSeparation(double gapSeparation)
Gap separation set method.
Definition: GridHealerAbstractBase.cpp:134
GridHealerAbstractBase::maxPointSeparation
double maxPointSeparation() const
Max point separation get method.
Definition: GridHealerAbstractBase.cpp:92
GridHealerAbstractBase::mutualPairHalvesBelow
const MutualPairHalves & mutualPairHalvesBelow() const
Mutual pair halves for above grid line.
Definition: GridHealerAbstractBase.cpp:107
GridHealerAbstractBase
Class that 'heals' the curves after one grid line has been removed.
Definition: GridHealerAbstractBase.h:29
Pixels::pixelIsBlack
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