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 27 double s = (xBoundary - posUnprojected.x()) / (posOther.x() - posUnprojected.x());
28 ENGAUGE_ASSERT ((-1.0 * EPSILON < s) && (s < 1.0 + EPSILON));
30 return QPointF ((1.0 - s) * posUnprojected.x() + s * posOther.x(),
31 (1.0 - s) * posUnprojected.y() + s * posOther.y());
34 QPointF GridRemoval::clipY (
const QPointF &posUnprojected,
36 const QPointF &posOther)
const 38 double s = (yBoundary - posUnprojected.y()) / (posOther.y() - posUnprojected.y());
39 ENGAUGE_ASSERT ((-1.0 * EPSILON < s) && (s < 1.0 + EPSILON));
41 return QPointF ((1.0 - s) * posUnprojected.x() + s * posOther.x(),
42 (1.0 - s) * posUnprojected.y() + s * posOther.y());
47 const QImage &imageBefore)
49 LOG4CPP_INFO_S ((*mainCat)) <<
"GridRemoval::remove" 50 <<
" transformationIsDefined=" << (transformation.
transformIsDefined() ?
"true" :
"false")
53 QImage image = imageBefore;
62 double yGraphMin = modelGridRemoval.
startY();
63 double yGraphMax = modelGridRemoval.
stopY();
64 for (
int i = 0; i < modelGridRemoval.
countX(); i++) {
65 double xGraph = modelGridRemoval.
startX() + i * modelGridRemoval.
stepX();
68 QPointF posScreenMin, posScreenMax;
76 removeLine (posScreenMin,
82 double xGraphMin = modelGridRemoval.
startX();
83 double xGraphMax = modelGridRemoval.
stopX();
84 for (
int j = 0; j < modelGridRemoval.
countY(); j++) {
85 double yGraph = modelGridRemoval.
startY() + j * modelGridRemoval.
stepY();
88 QPointF posScreenMin, posScreenMax;
96 removeLine (posScreenMin,
103 gridHealer.
heal (image);
106 return QPixmap::fromImage (image);
109 void GridRemoval::removeLine (
const QPointF &posMin,
110 const QPointF &posMax,
114 double w = image.width() - 1;
115 double h = image.height() - 1;
117 QPointF pos1 = posMin;
118 QPointF pos2 = posMax;
122 bool onLeft = (pos1.x() < 0 && pos2.x () < 0);
123 bool onTop = (pos1.y() < 0 && pos2.y () < 0);
124 bool onRight = (pos1.x() > w && pos2.x () > w);
125 bool onBottom = (pos1.y() > h && pos2.y () > h);
126 if (!onLeft && !onTop && !onRight && !onBottom) {
129 if (pos1.x() < 0) { pos1 = clipX (pos1, 0, pos2); }
130 if (pos2.x() < 0) { pos2 = clipX (pos2, 0, pos1); }
131 if (pos1.y() < 0) { pos1 = clipY (pos1, 0, pos2); }
132 if (pos2.y() < 0) { pos2 = clipY (pos2, 0, pos1); }
133 if (pos1.x() > w) { pos1 = clipX (pos1, w, pos2); }
134 if (pos2.x() > w) { pos2 = clipX (pos2, w, pos1); }
135 if (pos1.y() > h) { pos1 = clipY (pos1, h, pos2); }
136 if (pos2.y() > h) { pos2 = clipY (pos2, h, pos1); }
139 double deltaX = qAbs (pos1.x() - pos2.x());
140 double deltaY = qAbs (pos1.y() - pos2.y());
141 if (deltaX > deltaY) {
144 int xMin = qMin (pos1.x(), pos2.x());
145 int xMax = qMax (pos1.x(), pos2.x());
146 int yAtXMin = (pos1.x() < pos2.x() ? pos1.y() : pos2.y());
147 int yAtXMax = (pos1.x() < pos2.x() ? pos2.y() : pos1.y());
148 for (
int x = xMin; x <= xMax; x++) {
149 double s = (double) (x - xMin) / (double) (xMax - xMin);
150 double yLine = (1.0 - s) * yAtXMin + s * yAtXMax;
151 for (
int yOffset = -1; yOffset <= 1; yOffset++) {
152 int y = (int) (0.5 + yLine + yOffset);
153 image.setPixel (x, y, QColor(Qt::white).rgb());
160 int yMin = qMin (pos1.y(), pos2.y());
161 int yMax = qMax (pos1.y(), pos2.y());
162 int xAtYMin = (pos1.y() < pos2.y() ? pos1.x() : pos2.x());
163 int xAtYMax = (pos1.y() < pos2.y() ? pos2.x() : pos1.x());
164 for (
int y = yMin; y <= yMax; y++) {
165 double s = (double) (y - yMin) / (double) (yMax - yMin);
166 double xLine = (1.0 - s) * xAtYMin + s * xAtYMax;
167 for (
int xOffset = -1; xOffset <= 1; xOffset++) {
168 int x = (int) (0.5 + xLine + xOffset);
169 image.setPixel (x, y, QColor(Qt::white).rgb());
double stopY() const
Get method for y stop.
double stopX() const
Get method for x stop.
int countY() const
Get method for y count.
void erasePixel(int xCol, int yRow)
Remember that pixel was erased since it belongs to an grid line.
double startY() const
Get method for y start.
double stepX() const
Get method for x step.
Class that 'heals' the curves after grid lines have been removed.
bool removeDefinedGridLines() const
Get method for removing defined grid lines.
QPixmap remove(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const QImage &imageBefore)
Process QImage into QPixmap, removing the grid lines.
int countX() const
Get method for x count.
double startX() const
Get method for x start.
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.
double stepY() const
Get method for y step.