Engauge Digitizer  2
GridHealerAbstractBase.h
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #ifndef GRID_HEALER_ABSTRACT_BASE_H
8 #define GRID_HEALER_ABSTRACT_BASE_H
9 
10 #include "DocumentModelGridRemoval.h"
11 #include "GridIndependentToDependent.h"
12 #include <QImage>
13 
14 class GridLog;
15 class QImage;
16 class QTextStream;
17 
18 // Trick to discriminate horizontal and vertical pixels is to use different sizes
19 const double HALFWIDTH_HORIZONTAL = 0.46;
20 const double HALFWIDTH_VERTICAL = 0.54;
21 
23 typedef QList<QPoint> MutualPairHalves;
24 
31 {
32  public:
33 
37  virtual ~GridHealerAbstractBase();
38 
40  void addMutualPair (int x0,
41  int y0,
42  int x1,
43  int y1);
44 
47 
49  void healed (QImage &image);
50 
51  protected:
52 
54  virtual void applyMutualPairs (const QImage &image) = 0;
55 
60  virtual void doHealingAcrossGaps (QImage &image) = 0;
61 
63  void fillTrapezoid (QImage &image,
64  int xBL, int yBL,
65  int xBR, int yBR,
66  int xTR, int yTR,
67  int xTL, int yTL);
68 
70  GridLog &gridLog ();
71 
73  double maxPointSeparation () const;
74 
77 
79  const MutualPairHalves &mutualPairHalvesAbove () const;
80 
82  const MutualPairHalves &mutualPairHalvesBelow () const;
83 
85  bool pointsAreGood (const QImage &image,
86  int x0,
87  int y0,
88  int x1,
89  int y1) const;
90 
92  void saveGapSeparation (double gapSeparation);
93 
94  private:
96 
104  bool blackPixelRegionIsBigEnough (const QImage &image,
105  int x,
106  int y) const;
107 
109  void doHealingOnBelowAndAboveRangePair (QImage &image,
110  int xBelowStart,
111  int xBelowEnd,
112  int xAboveStart,
113  int xAboveEnd);
114 
116  void doHealingOnBelowRange (QImage &image,
117  int xBelowStart,
118  int xBelowEnd,
119  int maxHorSep);
120 
121  DocumentModelGridRemoval m_modelGridRemoval;
122 
123  int m_maxPointSeparation; // Pixel distance between two connected points
124 
125  // Store opposing mutual pair points as each grid line is removed, then after all removals are
126  // done (when complex vertical/horizontal interactions have finished) we heal
127  // across these mutual pairs
128  MutualPairHalves m_mutualPairHalvesBelow;
129  MutualPairHalves m_mutualPairHalvesAbove;
130 
131  GridLog &m_gridLog;
132 };
133 
134 #endif // GRID_HEALER_ABSTRACT_BASE_H
Class that does special logging for GridLog and GridRemoval classes.
Definition: GridLog.h:16
double maxPointSeparation() const
Max point separation get method.
void saveGapSeparation(double gapSeparation)
Gap separation set method.
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...
bool pointsAreGood(const QImage &image, int x0, int y0, int x1, int y1) const
Apply blackPixelRegionIsBigEnough to regions around each of two points.
const MutualPairHalves & mutualPairHalvesBelow() const
Mutual pair halves for above grid line.
void healed(QImage &image)
Return healed image after grid removal.
Class that &#39;heals&#39; the curves after one grid line has been removed.
GridLog & gridLog()
Logging get method.
virtual void applyMutualPairs(const QImage &image)=0
Apply mutual pair points after all grid removal is done.
static int pixelCountInRegionThreshold(const DocumentModelGridRemoval &modelGridRemoval)
Threshold number of pixels in a region to be considered too-small or big-enough.
const MutualPairHalves & mutualPairHalvesAbove() const
Mutual pair halves for below grid line.
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...
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
DocumentModelGridRemoval & modelGridRemoval()
DocumentModelGridRemoval get method.
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.