7 #include "DocumentModelGridRemoval.h" 8 #include "EngaugeAssert.h" 9 #include "GridHealerHorizontal.h" 10 #include "GridHealerVertical.h" 11 #include "GridRemoval.h" 16 #include "Transformation.h" 18 const double EPSILON = 0.000001;
25 QPointF GridRemoval::clipX (
const QPointF &posUnprojected,
27 const QPointF &posOther)
const 30 if (posOther.x() != posUnprojected.x()) {
31 s = (xBoundary - posUnprojected.x()) / (posOther.x() - posUnprojected.x());
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());
39 QPointF GridRemoval::clipY (
const QPointF &posUnprojected,
41 const QPointF &posOther)
const 44 if (posOther.y() != posUnprojected.y()) {
45 s = (yBoundary - posUnprojected.y()) / (posOther.y() - posUnprojected.y());
47 ENGAUGE_ASSERT ((-1.0 * EPSILON < s) && (s < 1.0 + EPSILON));
49 return QPointF ((1.0 - s) * posUnprojected.x() + s * posOther.x(),
50 (1.0 - s) * posUnprojected.y() + s * posOther.y());
55 const QImage &imageBefore)
57 LOG4CPP_INFO_S ((*mainCat)) <<
"GridRemoval::remove" 58 <<
" transformationIsDefined=" << (transformation.
transformIsDefined() ?
"true" :
"false")
61 QImage image = imageBefore;
64 GridHealers gridHealers;
70 double yGraphMin = modelGridRemoval.
startY();
71 double yGraphMax = modelGridRemoval.
stopY();
72 for (
int i = 0; i < modelGridRemoval.
countX(); i++) {
73 double xGraph = modelGridRemoval.
startX() + i * modelGridRemoval.
stepX();
76 QPointF posScreenMin, posScreenMax;
84 removeLine (posScreenMin,
91 double xGraphMin = modelGridRemoval.
startX();
92 double xGraphMax = modelGridRemoval.
stopX();
93 for (
int j = 0; j < modelGridRemoval.
countY(); j++) {
94 double yGraph = modelGridRemoval.
startY() + j * modelGridRemoval.
stepY();
97 QPointF posScreenMin, posScreenMax;
105 removeLine (posScreenMin,
113 GridHealers::iterator itr;
114 for (itr = gridHealers.begin(); itr != gridHealers.end(); itr++) {
116 gridHealer->
healed (image);
121 return QPixmap::fromImage (image);
124 void GridRemoval::removeLine (
const QPointF &posMin,
125 const QPointF &posMax,
128 GridHealers &gridHealers)
130 const int HALF_WIDTH = 1;
132 double w = image.width() - 1;
133 double h = image.height() - 1;
135 QPointF pos1 = posMin;
136 QPointF pos2 = posMax;
140 bool onLeft = (pos1.x() < 0 && pos2.x () < 0);
141 bool onTop = (pos1.y() < 0 && pos2.y () < 0);
142 bool onRight = (pos1.x() > w && pos2.x () > w);
143 bool onBottom = (pos1.y() > h && pos2.y () > h);
144 if (!onLeft && !onTop && !onRight && !onBottom) {
147 if (pos1.x() < 0) { pos1 = clipX (pos1, 0, pos2); }
148 if (pos2.x() < 0) { pos2 = clipX (pos2, 0, pos1); }
149 if (pos1.y() < 0) { pos1 = clipY (pos1, 0, pos2); }
150 if (pos2.y() < 0) { pos2 = clipY (pos2, 0, pos1); }
151 if (pos1.x() > w) { pos1 = clipX (pos1, w, pos2); }
152 if (pos2.x() > w) { pos2 = clipX (pos2, w, pos1); }
153 if (pos1.y() > h) { pos1 = clipY (pos1, h, pos2); }
154 if (pos2.y() > h) { pos2 = clipY (pos2, h, pos1); }
157 double deltaX = qAbs (pos1.x() - pos2.x());
158 double deltaY = qAbs (pos1.y() - pos2.y());
159 if (deltaX > deltaY) {
164 gridHealers.push_back (gridHealer);
166 int xMin = qMin (pos1.x(), pos2.x());
167 int xMax = qMax (pos1.x(), pos2.x());
168 int yAtXMin = (pos1.x() < pos2.x() ? pos1.y() : pos2.y());
169 int yAtXMax = (pos1.x() < pos2.x() ? pos2.y() : pos1.y());
170 for (
int x = xMin; x <= xMax; x++) {
171 double s = (double) (x - xMin) / (double) (xMax - xMin);
172 int yLine = (int) (0.5 + (1.0 - s) * yAtXMin + s * yAtXMax);
173 for (
int yOffset = -HALF_WIDTH; yOffset <= HALF_WIDTH; yOffset++) {
174 int y = yLine + yOffset;
175 image.setPixel (x, y, QColor(Qt::white).rgb());
177 gridHealer->
addMutualPair (x, yLine - HALF_WIDTH - 1, x, yLine + HALF_WIDTH + 1);
185 gridHealers.push_back (gridHealer);
187 int yMin = qMin (pos1.y(), pos2.y());
188 int yMax = qMax (pos1.y(), pos2.y());
189 int xAtYMin = (pos1.y() < pos2.y() ? pos1.x() : pos2.x());
190 int xAtYMax = (pos1.y() < pos2.y() ? pos2.x() : pos1.x());
191 for (
int y = yMin; y <= yMax; y++) {
192 double s = (double) (y - yMin) / (double) (yMax - yMin);
193 int xLine = (int) (0.5 + (1.0 - s) * xAtYMin + s * xAtYMax);
194 for (
int xOffset = -HALF_WIDTH; xOffset <= HALF_WIDTH; xOffset++) {
195 int x = xLine + xOffset;
196 image.setPixel (x, y, QColor(Qt::white).rgb());
198 gridHealer->
addMutualPair (xLine - HALF_WIDTH - 1, y, xLine + HALF_WIDTH + 1, y);
double stopY() const
Get method for y stop.
double stopX() const
Get method for x stop.
int countY() const
Get method for y count.
double startY() const
Get method for y start.
void healed(QImage &image)
Return healed image after grid removal.
double stepX() const
Get method for x step.
Class that 'heals' the curves after one grid line has been removed.
Subclass of GridHealerAbstractBase for horizontal lines.
bool removeDefinedGridLines() const
Get method for removing defined grid lines.
GridRemoval(bool isGnuplot)
Single constructor.
QPixmap remove(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const QImage &imageBefore)
Process QImage into QPixmap, removing the grid lines.
Subclass of GridHealerAbstractBase for vertical lines.
int countX() const
Get method for x count.
double startX() const
Get method for x start.
void addMutualPair(int x0, int y0, int x1, int y1)
Add two points on either side of a gap. Later, after removal, the black points will be processed.
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
double stepY() const
Get method for y step.