7 #include "DocumentModelGridRemoval.h"
8 #include "EngaugeAssert.h"
9 #include "GridHealer.h"
10 #include "GridRemoval.h"
15 #include "Transformation.h"
17 const double EPSILON = 0.000001;
23 QPointF GridRemoval::clipX (
const QPointF &posUnprojected,
25 const QPointF &posOther)
const
28 if (posOther.x() != posUnprojected.x()) {
29 s = (xBoundary - posUnprojected.x()) / (posOther.x() - posUnprojected.x());
31 ENGAUGE_ASSERT ((-1.0 * EPSILON < s) && (s < 1.0 + EPSILON));
33 return QPointF ((1.0 - s) * posUnprojected.x() + s * posOther.x(),
34 (1.0 - s) * posUnprojected.y() + s * posOther.y());
37 QPointF GridRemoval::clipY (
const QPointF &posUnprojected,
39 const QPointF &posOther)
const
42 if (posOther.y() != posUnprojected.y()) {
43 s = (yBoundary - posUnprojected.y()) / (posOther.y() - posUnprojected.y());
45 ENGAUGE_ASSERT ((-1.0 * EPSILON < s) && (s < 1.0 + EPSILON));
47 return QPointF ((1.0 - s) * posUnprojected.x() + s * posOther.x(),
48 (1.0 - s) * posUnprojected.y() + s * posOther.y());
53 const QImage &imageBefore)
55 LOG4CPP_INFO_S ((*mainCat)) <<
"GridRemoval::remove"
56 <<
" transformationIsDefined=" << (transformation.
transformIsDefined() ?
"true" :
"false")
59 QImage image = imageBefore;
68 double yGraphMin = modelGridRemoval.
startY();
69 double yGraphMax = modelGridRemoval.
stopY();
70 for (
int i = 0; i < modelGridRemoval.
countX(); i++) {
71 double xGraph = modelGridRemoval.
startX() + i * modelGridRemoval.
stepX();
74 QPointF posScreenMin, posScreenMax;
82 removeLine (posScreenMin,
88 double xGraphMin = modelGridRemoval.
startX();
89 double xGraphMax = modelGridRemoval.
stopX();
90 for (
int j = 0; j < modelGridRemoval.
countY(); j++) {
91 double yGraph = modelGridRemoval.
startY() + j * modelGridRemoval.
stepY();
94 QPointF posScreenMin, posScreenMax;
102 removeLine (posScreenMin,
109 gridHealer.
heal (image);
112 return QPixmap::fromImage (image);
115 void GridRemoval::removeLine (
const QPointF &posMin,
116 const QPointF &posMax,
120 double w = image.width() - 1;
121 double h = image.height() - 1;
123 QPointF pos1 = posMin;
124 QPointF pos2 = posMax;
128 bool onLeft = (pos1.x() < 0 && pos2.x () < 0);
129 bool onTop = (pos1.y() < 0 && pos2.y () < 0);
130 bool onRight = (pos1.x() > w && pos2.x () > w);
131 bool onBottom = (pos1.y() > h && pos2.y () > h);
132 if (!onLeft && !onTop && !onRight && !onBottom) {
135 if (pos1.x() < 0) { pos1 = clipX (pos1, 0, pos2); }
136 if (pos2.x() < 0) { pos2 = clipX (pos2, 0, pos1); }
137 if (pos1.y() < 0) { pos1 = clipY (pos1, 0, pos2); }
138 if (pos2.y() < 0) { pos2 = clipY (pos2, 0, pos1); }
139 if (pos1.x() > w) { pos1 = clipX (pos1, w, pos2); }
140 if (pos2.x() > w) { pos2 = clipX (pos2, w, pos1); }
141 if (pos1.y() > h) { pos1 = clipY (pos1, h, pos2); }
142 if (pos2.y() > h) { pos2 = clipY (pos2, h, pos1); }
145 double deltaX = qAbs (pos1.x() - pos2.x());
146 double deltaY = qAbs (pos1.y() - pos2.y());
147 if (deltaX > deltaY) {
150 int xMin = qMin (pos1.x(), pos2.x());
151 int xMax = qMax (pos1.x(), pos2.x());
152 int yAtXMin = (pos1.x() < pos2.x() ? pos1.y() : pos2.y());
153 int yAtXMax = (pos1.x() < pos2.x() ? pos2.y() : pos1.y());
154 for (
int x = xMin; x <= xMax; x++) {
155 double s = (double) (x - xMin) / (double) (xMax - xMin);
156 double yLine = (1.0 - s) * yAtXMin + s * yAtXMax;
157 for (
int yOffset = -1; yOffset <= 1; yOffset++) {
158 int y = (int) (0.5 + yLine + yOffset);
159 image.setPixel (x, y, QColor(Qt::white).rgb());
166 int yMin = qMin (pos1.y(), pos2.y());
167 int yMax = qMax (pos1.y(), pos2.y());
168 int xAtYMin = (pos1.y() < pos2.y() ? pos1.x() : pos2.x());
169 int xAtYMax = (pos1.y() < pos2.y() ? pos2.x() : pos1.x());
170 for (
int y = yMin; y <= yMax; y++) {
171 double s = (double) (y - yMin) / (double) (yMax - yMin);
172 double xLine = (1.0 - s) * xAtYMin + s * xAtYMax;
173 for (
int xOffset = -1; xOffset <= 1; xOffset++) {
174 int x = (int) (0.5 + xLine + xOffset);
175 image.setPixel (x, y, QColor(Qt::white).rgb());
bool removeDefinedGridLines() const
Get method for removing defined grid lines.
double startY() const
Get method for y start.
void erasePixel(int xCol, int yRow)
Remember that pixel was erased since it belongs to an grid line.
double stepY() const
Get method for y step.
Class that 'heals' the curves after grid lines have been removed.
double stopX() const
Get method for x stop.
QPixmap remove(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const QImage &imageBefore)
Process QImage into QPixmap, removing the grid lines.
double startX() const
Get method for x start.
double stopY() const
Get method for y stop.
int countX() const
Get method for x count.
int countY() const
Get method for y count.
double stepX() const
Get method for x step.
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
GridRemoval()
Single constructor.
void heal(QImage &imageToHeal)
Heal the broken curve lines by spanning the gaps across the newly-removed grid lines.