1 #include "DocumentModelGridRemoval.h"
2 #include "EngaugeAssert.h"
3 #include "GridHealer.h"
4 #include "GridRemoval.h"
9 #include "Transformation.h"
11 const double EPSILON = 0.000001;
17 QPointF GridRemoval::clipX (
const QPointF &posUnprojected,
19 const QPointF &posOther)
const
21 double s = (xBoundary - posUnprojected.x()) / (posOther.x() - posUnprojected.x());
22 ENGAUGE_ASSERT ((-1.0 * EPSILON < s) && (s < 1.0 + EPSILON));
24 return QPointF ((1.0 - s) * posUnprojected.x() + s * posOther.x(),
25 (1.0 - s) * posUnprojected.y() + s * posOther.y());
28 QPointF GridRemoval::clipY (
const QPointF &posUnprojected,
30 const QPointF &posOther)
const
32 double s = (yBoundary - posUnprojected.y()) / (posOther.y() - posUnprojected.y());
33 ENGAUGE_ASSERT ((-1.0 * EPSILON < s) && (s < 1.0 + EPSILON));
35 return QPointF ((1.0 - s) * posUnprojected.x() + s * posOther.x(),
36 (1.0 - s) * posUnprojected.y() + s * posOther.y());
41 const QImage &imageBefore)
43 LOG4CPP_INFO_S ((*mainCat)) <<
"GridRemoval::remove"
44 <<
" transformationIsDefined=" << (transformation.
transformIsDefined() ?
"true" :
"false")
47 QImage image = imageBefore;
56 double yGraphMin = modelGridRemoval.
startY();
57 double yGraphMax = modelGridRemoval.
stopY();
58 for (
int i = 0; i < modelGridRemoval.
countX(); i++) {
59 double xGraph = modelGridRemoval.
startX() + i * modelGridRemoval.
stepX();
62 QPointF posScreenMin, posScreenMax;
70 removeLine (posScreenMin,
76 double xGraphMin = modelGridRemoval.
startX();
77 double xGraphMax = modelGridRemoval.
stopX();
78 for (
int j = 0; j < modelGridRemoval.
countY(); j++) {
79 double yGraph = modelGridRemoval.
startY() + j * modelGridRemoval.
stepY();
82 QPointF posScreenMin, posScreenMax;
90 removeLine (posScreenMin,
97 gridHealer.
heal (image);
100 return QPixmap::fromImage (image);
103 void GridRemoval::removeLine (
const QPointF &posMin,
104 const QPointF &posMax,
108 double w = image.width() - 1;
109 double h = image.height() - 1;
111 QPointF pos1 = posMin;
112 QPointF pos2 = posMax;
116 bool onLeft = (pos1.x() < 0 && pos2.x () < 0);
117 bool onTop = (pos1.y() < 0 && pos2.y () < 0);
118 bool onRight = (pos1.x() > w && pos2.x () > w);
119 bool onBottom = (pos1.y() > h && pos2.y () > h);
120 if (!onLeft && !onTop && !onRight && !onBottom) {
123 if (pos1.x() < 0) { pos1 = clipX (pos1, 0, pos2); }
124 if (pos2.x() < 0) { pos2 = clipX (pos2, 0, pos1); }
125 if (pos1.y() < 0) { pos1 = clipY (pos1, 0, pos2); }
126 if (pos2.y() < 0) { pos2 = clipY (pos2, 0, pos1); }
127 if (pos1.x() > w) { pos1 = clipX (pos1, w, pos2); }
128 if (pos2.x() > w) { pos2 = clipX (pos2, w, pos1); }
129 if (pos1.y() > h) { pos1 = clipY (pos1, h, pos2); }
130 if (pos2.y() > h) { pos2 = clipY (pos2, h, pos1); }
133 double deltaX = qAbs (pos1.x() - pos2.x());
134 double deltaY = qAbs (pos1.y() - pos2.y());
135 if (deltaX > deltaY) {
138 int xMin = qMin (pos1.x(), pos2.x());
139 int xMax = qMax (pos1.x(), pos2.x());
140 int yAtXMin = (pos1.x() < pos2.x() ? pos1.y() : pos2.y());
141 int yAtXMax = (pos1.x() < pos2.x() ? pos2.y() : pos1.y());
142 for (
int x = xMin; x <= xMax; x++) {
143 double s = (double) (x - xMin) / (double) (xMax - xMin);
144 double yLine = (1.0 - s) * yAtXMin + s * yAtXMax;
145 for (
int yOffset = -1; yOffset <= 1; yOffset++) {
146 int y = (int) (0.5 + yLine + yOffset);
147 image.setPixel (x, y, QColor(Qt::white).rgb());
154 int yMin = qMin (pos1.y(), pos2.y());
155 int yMax = qMax (pos1.y(), pos2.y());
156 int xAtYMin = (pos1.y() < pos2.y() ? pos1.x() : pos2.x());
157 int xAtYMax = (pos1.y() < pos2.y() ? pos2.x() : pos1.x());
158 for (
int y = yMin; y <= yMax; y++) {
159 double s = (double) (y - yMin) / (double) (yMax - yMin);
160 double xLine = (1.0 - s) * xAtYMin + s * xAtYMax;
161 for (
int xOffset = -1; xOffset <= 1; xOffset++) {
162 int x = (int) (0.5 + xLine + xOffset);
163 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.