Engauge Digitizer 2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
GridHealerAbstractBase Class Referenceabstract

Class that 'heals' the curves after one grid line has been removed. More...

#include <GridHealerAbstractBase.h>

Inheritance diagram for GridHealerAbstractBase:
Inheritance graph
Collaboration diagram for GridHealerAbstractBase:
Collaboration graph

Public Member Functions

 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.
 

Static Public Member Functions

static int pixelCountInRegionThreshold (const DocumentModelGridRemoval &modelGridRemoval)
 Threshold number of pixels in a region to be considered too-small or big-enough.
 

Protected Member Functions

virtual void applyMutualPairs (const QImage &image)=0
 Apply mutual pair points after all grid removal is done.
 
virtual void doHealingAcrossGaps (QImage &image)=0
 Guts of the algorithm in which sequences of black pixels across the gap from each other are filled in.
 
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

Class that 'heals' the curves after one grid line has been removed.

Specifically, gaps that span the pixels in the removed grid line are filled in, when a black pixel on one side of the gap is across from a black pixel on the other side of the pixel

A range is defined as a continous set of pixels on the same side of the gap

Definition at line 30 of file GridHealerAbstractBase.h.

Constructor & Destructor Documentation

◆ GridHealerAbstractBase()

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

Single constructor.

Definition at line 20 of file GridHealerAbstractBase.cpp.

21 :
22 m_modelGridRemoval (modelGridRemoval),
23 m_maxPointSeparation (0),
24 m_gridLog (gridLog)
25{
26}
DocumentModelGridRemoval & modelGridRemoval()
DocumentModelGridRemoval get method.
GridLog & gridLog()
Logging get method.

◆ ~GridHealerAbstractBase()

GridHealerAbstractBase::~GridHealerAbstractBase ( )
virtual

Definition at line 28 of file GridHealerAbstractBase.cpp.

29{
30}

Member Function Documentation

◆ addMutualPair()

void GridHealerAbstractBase::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.

Definition at line 32 of file GridHealerAbstractBase.cpp.

36{
37 m_mutualPairHalvesBelow.push_back (QPoint (x0, y0));
38 m_mutualPairHalvesAbove.push_back (QPoint (x1, y1));
39}
const int INNER_RADIUS_MIN

◆ applyMutualPairs()

virtual void GridHealerAbstractBase::applyMutualPairs ( const QImage & image)
protectedpure virtual

Apply mutual pair points after all grid removal is done.

Implemented in GridHealerHorizontal, and GridHealerVertical.

◆ doHealingAcrossGaps()

virtual void GridHealerAbstractBase::doHealingAcrossGaps ( QImage & image)
protectedpure 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

Implemented in GridHealerHorizontal, and GridHealerVertical.

◆ fillTrapezoid()

void GridHealerAbstractBase::fillTrapezoid ( QImage & image,
int xBL,
int yBL,
int xBR,
int yBR,
int xTR,
int yTR,
int xTL,
int yTL )
protected

Fill trapezoid with bottom left, bottom right, top right, and top left points.

Definition at line 41 of file GridHealerAbstractBase.cpp.

46{
47 // Sanity checks
48 if (xBL == 0 || yBL == 0 || xBR == 0 || yBR == 0 || xTR == 0 || yTR == 0 || xTL == 0 || yTL == 0) {
49 LOG4CPP_ERROR_S ((*mainCat)) << "GridHealerAbstractBase::fillTrapezoid received undefined corner coordinate "
50 << "xBL=" << xBL << " yBL=" << yBL << " xBR=" << xBR << " yBR=" << yBR
51 << "xTR=" << xTR << " yTR=" << yTR << " xTL=" << xTL << " yTL=" << yTL;
52 }
53
54 if (!Pixels::pixelIsBlack(image, xBL, yBL)) {
55 LOG4CPP_ERROR_S ((*mainCat)) << "GridHealerAbstractBase::fillTrapezoid has bad bottom left point";
56 }
57 if (!Pixels::pixelIsBlack(image, xBR, yBR)) {
58 LOG4CPP_ERROR_S ((*mainCat)) << "GridHealerAbstractBase::fillTrapezoid has bad bottom right point";
59 }
60 if (!Pixels::pixelIsBlack(image, xTR, yTR)) {
61 LOG4CPP_ERROR_S ((*mainCat)) << "GridHealerAbstractBase::fillTrapezoid has bad top right point";
62 }
63 if (!Pixels::pixelIsBlack(image, xTL, yTL)) {
64 LOG4CPP_ERROR_S ((*mainCat)) << "GridHealerAbstractBase::fillTrapezoid has bad top left point";
65 }
66
67 // Any quadrilateral (including this trapezoid) can be considered the union of two triangles
69 triangleFill.fill (m_gridLog,
70 image,
71 QPoint (xBL, yBL),
72 QPoint (xBR, yBR),
73 QPoint (xTR, yTR));
74 triangleFill.fill (m_gridLog,
75 image,
76 QPoint (xBL, yBL),
77 QPoint (xTL, yTL),
78 QPoint (xTR, yTR));
79}
log4cpp::Category * mainCat
Definition Logger.cpp:14
Class that does raster-line fill of a triangle, with logging customizations for GridHealer (and there...
void fill(GridLog &gridLog, QImage &image, const QPoint &p0, const QPoint &p1, const QPoint &p2)
Fill triangle between these three points.
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
#define LOG4CPP_ERROR_S(logger)
Definition convenience.h:12

◆ gridLog()

GridLog & GridHealerAbstractBase::gridLog ( )
protected

Logging get method.

Definition at line 81 of file GridHealerAbstractBase.cpp.

82{
83 return m_gridLog;
84}

◆ healed()

void GridHealerAbstractBase::healed ( QImage & image)

Return healed image after grid removal.

Definition at line 86 of file GridHealerAbstractBase.cpp.

87{
88 applyMutualPairs (image);
89 doHealingAcrossGaps (image);
90}
virtual void applyMutualPairs(const QImage &image)=0
Apply mutual pair points after all grid removal is done.
virtual void doHealingAcrossGaps(QImage &image)=0
Guts of the algorithm in which sequences of black pixels across the gap from each other are filled in...

◆ maxPointSeparation()

double GridHealerAbstractBase::maxPointSeparation ( ) const
protected

Max point separation get method.

Definition at line 92 of file GridHealerAbstractBase.cpp.

93{
94 return m_maxPointSeparation;
95}

◆ modelGridRemoval()

DocumentModelGridRemoval & GridHealerAbstractBase::modelGridRemoval ( )
protected

DocumentModelGridRemoval get method.

Definition at line 97 of file GridHealerAbstractBase.cpp.

98{
99 return m_modelGridRemoval;
100}

◆ mutualPairHalvesAbove()

const MutualPairHalves & GridHealerAbstractBase::mutualPairHalvesAbove ( ) const
protected

Mutual pair halves for below grid line.

Definition at line 102 of file GridHealerAbstractBase.cpp.

103{
104 return m_mutualPairHalvesAbove;
105}

◆ mutualPairHalvesBelow()

const MutualPairHalves & GridHealerAbstractBase::mutualPairHalvesBelow ( ) const
protected

Mutual pair halves for above grid line.

Definition at line 107 of file GridHealerAbstractBase.cpp.

108{
109 return m_mutualPairHalvesBelow;
110}

◆ pixelCountInRegionThreshold()

int GridHealerAbstractBase::pixelCountInRegionThreshold ( const DocumentModelGridRemoval & modelGridRemoval)
static

Threshold number of pixels in a region to be considered too-small or big-enough.

Definition at line 112 of file GridHealerAbstractBase.cpp.

113{
114 // For now we will use the close distance as the minimum pixel count
116}
double closeDistance() const
Get method for close distance.

◆ pointsAreGood()

bool GridHealerAbstractBase::pointsAreGood ( const QImage & image,
int x0,
int y0,
int x1,
int y1 ) const
protected

Apply blackPixelRegionIsBigEnough to regions around each of two points.

Definition at line 118 of file GridHealerAbstractBase.cpp.

123{
125
126 int stopCountAt = pixelCountInRegionThreshold (m_modelGridRemoval);
127
128 // Skip if either endpoint is an unwanted artifact. Look at start point below (since it is connected
129 // to the end point below), and the start point above (which is connected to the end point above)
130 return ((pixels.countBlackPixelsAroundPoint (image, x0, y0, stopCountAt) >= stopCountAt) &&
131 (pixels.countBlackPixelsAroundPoint (image, x1, y1, stopCountAt) >= stopCountAt));
132}
static int pixelCountInRegionThreshold(const DocumentModelGridRemoval &modelGridRemoval)
Threshold number of pixels in a region to be considered too-small or big-enough.
Utility class for pixel manipulation.
Definition Pixels.h:32

◆ saveGapSeparation()

void GridHealerAbstractBase::saveGapSeparation ( double gapSeparation)
protected

Gap separation set method.

Definition at line 134 of file GridHealerAbstractBase.cpp.

135{
136 // Right triangle with one edge crossing the gap (separation value) and hypotenuse giving
137 // maximum point separation (closest distance) gives the maximum horizontal separation
138 m_maxPointSeparation = qFloor (qSqrt (qPow (modelGridRemoval().closeDistance(), 2) -
139 qPow (gapSeparation, 2)));
140}

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