Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
SegmentFactory.h
1 #ifndef SEGMENT_FACTORY_H
2 #define SEGMENT_FACTORY_H
3 
4 #include <QList>
5 #include <QPointF>
6 #include <vector>
7 
8 class ColorFilter;
10 class QGraphicsScene;
11 class QImage;
12 class Segment;
13 
14 typedef std::vector<Segment*> SegmentVector;
15 
22 {
23 public:
25  SegmentFactory(QGraphicsScene &scene,
26  bool isGnuplot);
27 
29  void clearSegments(QList<Segment*> &segments);
30 
32  QList<QPoint> fillPoints(const DocumentModelSegments &modelSegments,
33  QList<Segment*> segments);
34 
36  void makeSegments (const QImage &imageFiltered,
37  const DocumentModelSegments &modelSegments,
38  QList<Segment*> &segments);
39 
40 private:
42 
43  // Return the number of runs adjacent to the pixels from yStart to yStop (inclusive)
44  int adjacentRuns(bool *columnBool,
45  int yStart,
46  int yStop,
47  int height);
48 
49  // Find the single segment pointer among the adjacent pixels from yStart-1 to yStop+1
50  Segment *adjacentSegment(SegmentVector &lastSegment,
51  int yStart,
52  int yStop,
53  int height);
54 
55  // Return the number of segments adjacent to the pixels from yStart to yStop (inclusive)
56  int adjacentSegments(SegmentVector &lastSegment,
57  int yStart,
58  int yStop,
59  int height);
60 
61  // Process a run of pixels. If there are fewer than two adjacent pixel runs on
62  // either side, this run will be added to an existing segment, or the start of
63  // a new segment
64  void finishRun(bool *lastBool,
65  bool *nextBool,
66  SegmentVector &lastSegment,
67  SegmentVector &currSegment,
68  int x,
69  int yStart,
70  int yStop,
71  int height,
72  const DocumentModelSegments &modelSegments,
73  int* madeLines);
74 
75  // Initialize one column of boolean flags using the pixels of the specified column
76  void loadBool (const ColorFilter &filter,
77  bool *columnBool,
78  const QImage &image,
79  int x);
80 
81  // Initialize one column of segment pointers
82  void loadSegment (SegmentVector &columnSegment,
83  int height);
84 
85  // Identify the runs in a column, and connect them to segments
86  void matchRunsToSegments (int x,
87  int height,
88  bool *lastBool,
89  SegmentVector &lastSegment,
90  bool *currBool,
91  SegmentVector &currSegment,
92  bool *nextBool,
93  const DocumentModelSegments &modelSegments,
94  int *madeLines,
95  int *foldedLines,
96  int *shortLine,
97  QList<Segment*> &segments);
98 
100  void removeEmptySegments (QList<Segment*> &segments) const;
101 
102  // Remove unneeded lines belonging to segments that just finished in the previous column.
103  // The results of this function are displayed in the debug spew of makeSegments
104  void removeUnneededLines(SegmentVector &lastSegment,
105  SegmentVector &currSegment,
106  int height,
107  int *foldedLines,
108  int *shortLines,
109  const DocumentModelSegments &modelSegments,
110  QList<Segment*> &segments);
111 
112  // Scroll the boolean flags of the right column into the left column
113  void scrollBool(bool *left,
114  bool *right,
115  int height);
116 
117  // Scroll the segment pointers of the right column into the left column
118  void scrollSegment(SegmentVector &left,
119  SegmentVector &right,
120  int height);
121 
122  QGraphicsScene &m_scene;
123 
124  bool m_isGnuplot;
125 };
126 
127 #endif // SEGMENT_FACTORY_H
void makeSegments(const QImage &imageFiltered, const DocumentModelSegments &modelSegments, QList< Segment * > &segments)
Main entry point for creating all Segments for the filtered image.
QList< QPoint > fillPoints(const DocumentModelSegments &modelSegments, QList< Segment * > segments)
Return segment fill points for all segments, for previewing.
Class for filtering image to remove unimportant information.
Definition: ColorFilter.h:12
void clearSegments(QList< Segment * > &segments)
Remove the segments created by makeSegments.
Factory class for Segment objects.
Selectable piecewise-defined line that follows a filtered line in the image.
Definition: Segment.h:15
Model for DlgSettingsSegments and CmdSettingsSegments.