25QPointF 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());
35 return QPointF ((1.0 - s) * posUnprojected.x() + s * posOther.x(),
36 (1.0 - s) * posUnprojected.y() + s * posOther.y());
39QPointF 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());
49 return QPointF ((1.0 - s) * posUnprojected.x() + s * posOther.x(),
50 (1.0 - s) * posUnprojected.y() + s * posOther.y());
55 const QImage &imageBefore)
58 <<
" transformationIsDefined=" << (transformation.
transformIsDefined() ?
"true" :
"false")
61 QImage image = imageBefore;
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);
124void GridRemoval::removeLine (
const QPointF &posMin,
125 const QPointF &posMax,
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) {
162 GridHealerAbstractBase *gridHealer =
new GridHealerHorizontal (m_gridLog,
164 gridHealers.push_back (gridHealer);
166 int xMin = qMin (qFloor (pos1.x()), qFloor (pos2.x()));
167 int xMax = qMax (qFloor (pos1.x()), qFloor (pos2.x()));
168 int yAtXMin = (pos1.x() < pos2.x() ? qFloor (pos1.y()) : qFloor (pos2.y()));
169 int yAtXMax = (pos1.x() < pos2.x() ? qFloor (pos2.y()) : qFloor (pos1.y()));
170 for (
int x = xMin; x <= xMax; x++) {
171 double s = double (x - xMin) / double (xMax - xMin);
172 int yLine = qFloor (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);
183 GridHealerAbstractBase *gridHealer =
new GridHealerVertical (m_gridLog,
185 gridHealers.push_back (gridHealer);
187 int yMin = qMin (qFloor (pos1.y()), qFloor (pos2.y()));
188 int yMax = qMax (qFloor (pos1.y()), qFloor (pos2.y()));
189 int xAtYMin = (pos1.y() < pos2.y() ? qFloor (pos1.x()) : qFloor (pos2.x()));
190 int xAtYMax = (pos1.y() < pos2.y() ? qFloor (pos2.x()) : qFloor (pos1.x()));
191 for (
int y = yMin; y <= yMax; y++) {
192 double s = double (y - yMin) / double (yMax - yMin);
193 int xLine = qFloor (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);
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
QList< GridHealerAbstractBase * > GridHealers
Storage of GridHealer instances.
log4cpp::Category * mainCat
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval.
bool removeDefinedGridLines() const
Get method for removing defined grid lines.
double stopX() const
Get method for x stop.
double startX() const
Get method for x start.
double stopY() const
Get method for y stop.
double stepX() const
Get method for x step.
double stepY() const
Get method for y step.
int countY() const
Get method for y count.
int countX() const
Get method for x count.
double startY() const
Get method for y start.
Class that 'heals' the curves after one grid line has been removed.
void healed(QImage &image)
Return healed image after grid removal.
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.
QPixmap remove(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const QImage &imageBefore)
Process QImage into QPixmap, removing the grid lines.
GridRemoval(bool isGnuplot)
Single constructor.
#define LOG4CPP_INFO_S(logger)