bool GroundPlaneGenerator::generateGroundPlane(const QString & boardSvg, QSizeF boardImageSize, const QString & svg, QSizeF copperImageSize, QStringList & exceptions, QGraphicsItem * board, double res, const QString & color) { double bWidth, bHeight; QImage * image = generateGroundPlaneAux(boardSvg, boardImageSize, svg, copperImageSize, exceptions, board, res, bWidth, bHeight); if (image == NULL) return false; scanImage(*image, bWidth, bHeight, GraphicsUtils::StandardFritzingDPI / res, res, color, true, true, QSizeF(.05, .05), 1 / FSvgRenderer::printerScale(), QPointF(0,0)); delete image; return true; }
bool GroundPlaneGenerator::generateGroundPlaneUnit(const QString & boardSvg, QSizeF boardImageSize, const QString & svg, QSizeF copperImageSize, QStringList & exceptions, QGraphicsItem * board, double res, const QString & color, const QString & layerName, QPointF whereToStart, double blurBy) { double bWidth, bHeight; QImage * image = generateGroundPlaneAux(boardSvg, boardImageSize, svg, copperImageSize, exceptions, board, res, bWidth, bHeight, blurBy); if (image == NULL) return false; QPoint s(qRound(res * (whereToStart.x() - board->pos().x()) / FSvgRenderer::printerScale()), qRound(res * (whereToStart.y() - board->pos().y()) / FSvgRenderer::printerScale())); QBitArray redMarker(image->height() * image->width(), false); QRgb pixel = image->pixel(s); int gray = QGRAY(pixel); if (gray <= THRESHOLD) { // starting off in bad territory delete image; return false; } // step 1 flood fill white to "red" (keep max locations) int minY = image->height(); int maxY = 0; int minX = image->width(); int maxX = 0; QList<QPoint> stack; stack << s; while (stack.count() > 0) { QPoint p = stack.takeFirst(); if (p.x() < 0) continue; if (p.y() < 0) continue; if (p.x() >= image->width()) continue; if (p.y() >= image->height()) continue; if (redMarker.testBit(OFFSET(p.x(), p.y(), image))) continue; // already been here QRgb pixel = image->pixel(p); int gray = QGRAY(pixel); if (gray <= THRESHOLD) continue; // black; bail redMarker.setBit(OFFSET(p.x(), p.y(), image), true); if (p.x() > maxX) maxX = p.x(); if (p.x() < minX) minX = p.x(); if (p.y() > maxY) maxY = p.y(); if (p.y() < minY) minY = p.y(); stack.append(QPoint(p.x() - 1, p.y())); stack.append(QPoint(p.x() + 1, p.y())); stack.append(QPoint(p.x(), p.y() - 1)); stack.append(QPoint(p.x(), p.y() + 1)); } //image->save("testPoly1.png"); // step 2 replace white with black image->fill(0); // step 3 replace "red" with white for (int y = 0; y < image->height(); y++) { for (int x = 0; x < image->width(); x++) { if (redMarker.testBit(OFFSET(x, y, image))) { image->setPixel(x, y, 1); } } } #ifndef QT_NO_DEBUG image->save("testGroundPlaneUnit3.png"); #endif scanImage(*image, bWidth, bHeight, GraphicsUtils::StandardFritzingDPI / res, res, color, layerName, true, res / 50, true, QSizeF(.05, .05), 1 / FSvgRenderer::printerScale(), QPointF(0,0)); delete image; return true; }