1 #include "EngaugeAssert.h"
2 #include "GridRemoval.h"
7 #include "Transformation.h"
9 const double EPSILON = 0.000001;
15 QPointF GridRemoval::clipX (
const QPointF &posUnprojected,
17 const QPointF &posOther)
const
19 double s = (xBoundary - posUnprojected.x()) / (posOther.x() - posUnprojected.x());
20 ENGAUGE_ASSERT ((-1.0 * EPSILON < s) && (s < 1.0 + EPSILON));
22 return QPointF ((1.0 - s) * posUnprojected.x() + s * posOther.x(),
23 (1.0 - s) * posUnprojected.y() + s * posOther.y());
26 QPointF GridRemoval::clipY (
const QPointF &posUnprojected,
28 const QPointF &posOther)
const
30 double s = (yBoundary - posUnprojected.y()) / (posOther.y() - posUnprojected.y());
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());
39 const QImage &imageBefore)
41 LOG4CPP_INFO_S ((*mainCat)) <<
"GridRemoval::remove"
42 <<
" transformationIsDefined=" << (transformation.
transformIsDefined() ?
"true" :
"false")
45 QImage image = imageBefore;
51 double yGraphMin = modelGridRemoval.
startY();
52 double yGraphMax = modelGridRemoval.
stopY();
53 for (
int i = 0; i < modelGridRemoval.
countX(); i++) {
54 double xGraph = modelGridRemoval.
startX() + i * modelGridRemoval.
stepX();
57 QPointF posScreenMin, posScreenMax;
65 removeLine (posScreenMin,
70 double xGraphMin = modelGridRemoval.
startX();
71 double xGraphMax = modelGridRemoval.
stopX();
72 for (
int j = 0; j < modelGridRemoval.
countY(); j++) {
73 double yGraph = modelGridRemoval.
startY() + j * modelGridRemoval.
stepY();
76 QPointF posScreenMin, posScreenMax;
84 removeLine (posScreenMin,
90 return QPixmap::fromImage (image);
93 void GridRemoval::removeLine (
const QPointF &posMin,
94 const QPointF &posMax,
97 double w = image.width() - 1;
98 double h = image.height() - 1;
100 QPointF pos1 = posMin;
101 QPointF pos2 = posMax;
105 bool onLeft = (pos1.x() < 0 && pos2.x () < 0);
106 bool onTop = (pos1.y() < 0 && pos2.y () < 0);
107 bool onRight = (pos1.x() > w && pos2.x () > w);
108 bool onBottom = (pos1.y() > h && pos2.y () > h);
109 if (!onLeft && !onTop && !onRight && !onBottom) {
112 if (pos1.x() < 0) { pos1 = clipX (pos1, 0, pos2); }
113 if (pos2.x() < 0) { pos2 = clipX (pos2, 0, pos1); }
114 if (pos1.y() < 0) { pos1 = clipY (pos1, 0, pos2); }
115 if (pos2.y() < 0) { pos2 = clipY (pos2, 0, pos1); }
116 if (pos1.x() > w) { pos1 = clipX (pos1, w, pos2); }
117 if (pos2.x() > w) { pos2 = clipX (pos2, w, pos1); }
118 if (pos1.y() > h) { pos1 = clipY (pos1, h, pos2); }
119 if (pos2.y() > h) { pos2 = clipY (pos2, h, pos1); }
122 double deltaX = qAbs (pos1.x() - pos2.x());
123 double deltaY = qAbs (pos1.y() - pos2.y());
124 if (deltaX > deltaY) {
127 int xMin = qMin (pos1.x(), pos2.x());
128 int xMax = qMax (pos1.x(), pos2.x());
129 int yAtXMin = (pos1.x() < pos2.x() ? pos1.y() : pos2.y());
130 int yAtXMax = (pos1.x() < pos2.x() ? pos2.y() : pos1.y());
131 for (
int x = xMin; x <= xMax; x++) {
132 double s = (double) (x - xMin) / (double) (xMax - xMin);
133 double yLine = (1.0 - s) * yAtXMin + s * yAtXMax;
134 for (
int yOffset = -1; yOffset <= 1; yOffset++) {
135 int y = (int) (0.5 + yLine + yOffset);
136 image.setPixel (x, y, QColor(Qt::white).rgb());
142 int yMin = qMin (pos1.y(), pos2.y());
143 int yMax = qMax (pos1.y(), pos2.y());
144 int xAtYMin = (pos1.y() < pos2.y() ? pos1.x() : pos2.x());
145 int xAtYMax = (pos1.y() < pos2.y() ? pos2.x() : pos1.x());
146 for (
int y = yMin; y <= yMax; y++) {
147 double s = (double) (y - yMin) / (double) (yMax - yMin);
148 double xLine = (1.0 - s) * xAtYMin + s * xAtYMax;
149 for (
int xOffset = -1; xOffset <= 1; xOffset++) {
150 int x = (int) (0.5 + xLine + xOffset);
151 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.
double stepY() const
Get method for y step.
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.