Engauge Digitizer 2
Loading...
Searching...
No Matches
Segment.h
Go to the documentation of this file.
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 SEGMENT_H
8#define SEGMENT_H
9
10#include <QList>
11#include <QObject>
12#include <QPointF>
13
15class QGraphicsScene;
16class QTextStream;
17class SegmentLine;
18
21class Segment : public QObject
22{
24
25public:
27 Segment(QGraphicsScene &scene,
28 int yLast,
29 bool isGnuplot);
30 ~Segment();
31
33 void appendColumn(int x, int y, const DocumentModelSegments &modelSegments);
34
37
40 QPointF firstPoint () const;
41
43 void forwardMousePress ();
44
46 double length() const;
47
49 int lineCount() const;
50
56
58 void updateModelSegment(const DocumentModelSegments &modelSegments);
59
60public slots:
61
63 void slotHover (bool hover);
64
66
69
70private:
71 Segment();
72
73 // While filling corners, create a point if any of the following are true:
74 // -it is the first point of the any line segment
75 // -it is different than the previous point
76 // While not filling corners, create a point if any of the following are true:
77 // -it is the first point of the first line segment
78 // -it is different than the previous point
79 void createAcceptablePoint(bool *pFirst,
81 double *xPrev,
82 double *yPrev,
83 double x,
84 double y);
85
92 void dumpToGnuplot (QTextStream &strDump,
93 int xInt,
94 int yInt,
95 const SegmentLine *lineOld,
96 const SegmentLine *lineNew) const;
97
98 // Create evenly spaced points along the segment, with extra points to fill in corners.This algorithm is the
99 // same as fillPointsWithoutFillingCorners except extra points are inserted at the corners
100 QList<QPoint> fillPointsFillingCorners(const DocumentModelSegments &modelSegments);
101
102 // Create evenly spaced points along the segment, without extra points in corners
103 QList<QPoint> fillPointsWithoutFillingCorners(const DocumentModelSegments &modelSegments);
104
105 // A corner is defined as a point where the incoming slope is positive and the outgoing slope is zero
106 // or negative, or incoming slope is negative and the outgoing slope is zero or positive
107 bool isCorner (double yLast,
108 double yPrev,
109 double yNext) const;
110
111 // Return true if point are a half pixel or less away from a line
112 bool pointIsCloseToLine(double xLeft, double yLeft, double xInt, double yInt,
113 double xRight, double yRight);
114
115 // Return true if points are a half pixel or less away from a line
116 bool pointsAreCloseToLine(double xLeft, double yLeft, QList<QPoint> removedPoints,
117 double xRight, double yRight);
118
119 QGraphicsScene &m_scene;
120
121 // Y value of last point which is in previous column
122 int m_yLast;
123
124 // Total length of lines owned by this segment, as floating point to allow fractional increments
125 double m_length;
126
127 // This segment is drawn as a series of line segments
128 QList<SegmentLine*> m_lines;
129
130 // True for gnuplot input files for debugging
131 bool m_isGnuplot;
132};
133
134#endif // SEGMENT_H
const int INNER_RADIUS_MIN
Model for DlgSettingsSegments and CmdSettingsSegments.
This class is a special case of the standard QGraphicsLineItem for segments.
Definition SegmentLine.h:18
Selectable piecewise-defined line that follows a filtered line in the image.
Definition Segment.h:22
void signalMouseClickOnSegment(QPointF posSegmentStart)
Pass mouse press event, with coordinates of first point in the Segment since that info uniquely ident...
double length() const
Get method for length in pixels.
Definition Segment.cpp:375
int lineCount() const
Get method for number of lines.
Definition Segment.cpp:380
QList< QPoint > fillPoints(const DocumentModelSegments &modelSegments)
Create evenly spaced points along the segment.
Definition Segment.cpp:205
void forwardMousePress()
Forward mouse press event from a component SegmentLine that was just clicked on.
Definition Segment.cpp:298
void slotHover(bool hover)
Slot for hover enter/leave events in the associated SegmentLines.
Definition Segment.cpp:528
void updateModelSegment(const DocumentModelSegments &modelSegments)
Update this segment given the new settings.
Definition Segment.cpp:540
~Segment()
Definition Segment.cpp:32
void appendColumn(int x, int y, const DocumentModelSegments &modelSegments)
Add some more pixels in a new column to an active segment.
Definition Segment.cpp:42
QPointF firstPoint() const
Coordinates of first point in Segment.
Definition Segment.cpp:281
void removeUnneededLines(int *foldedLines)
Try to compress a segment that was just completed, by folding together line from point i to point i+1...
Definition Segment.cpp:421