Verified Commit 58c2ab7a authored by Kuntal  Majumder's avatar Kuntal Majumder 😟

Added a couple of comments and completed the test

Ref T10894
parent 463a9b18
......@@ -64,6 +64,8 @@ struct VertexDescriptor {
return x < rhs.x || (x == rhs.x && y < rhs.y);
}
// returns one of the 8 neighboring pixel based on the direction
// it gives out multiple warnings, but I am lazy, sorry
VertexDescriptor neighbor(Direction direction) const {
int dx = 0, dy = 0;
......@@ -146,9 +148,7 @@ struct KisMagneticGraph{
return 2;
return 5;
}
return 8;
}
QRect m_rect;
......@@ -205,6 +205,9 @@ private:
KisMagneticGraph m_graph;
};
// Requirements for an Incidence Graph,
// https://www.boost.org/doc/libs/1_70_0/libs/graph/doc/IncidenceGraph.html
namespace boost{
template<>
struct graph_traits<KisMagneticGraph> {
......@@ -224,9 +227,6 @@ struct graph_traits<KisMagneticGraph> {
};
}
// Requirements for an Incidence Graph,
// https://www.boost.org/doc/libs/1_70_0/libs/graph/doc/IncidenceGraph.html
typename KisMagneticGraph::vertex_descriptor
source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g) {
Q_UNUSED(g)
......
......@@ -141,7 +141,16 @@ private:
};
QRect KisMagneticWorker::calculateRect(QPoint p1, QPoint p2, int radius) const {
// I am sure there is a simpler version of it which exists but well
// Calculates a bounding rectangle based on the radius,
// --------------------------------
// | ------------------- |
// | | A* | |
// | | | |
// | | *B| |
// | ------------------- |
// --------------------------------
double slope = (p2.y() - p1.y())/(p2.x() - p1.x());
QPoint a,b,c,d;
......@@ -181,6 +190,7 @@ QVector<QPointF> KisMagneticWorker::computeEdge(KisPaintDeviceSP dev, int radius
KisMagneticGraph g(dev, rect);
// How many maps does it require?
// Take a look here, if it doesn't make sense, https://www.boost.org/doc/libs/1_70_0/libs/graph/doc/astar_search.html
PredecessorMap pmap;
DistanceMap dmap(std::numeric_limits<double>::max());
dmap[start] = 0;
......@@ -208,7 +218,6 @@ QVector<QPointF> KisMagneticWorker::computeEdge(KisPaintDeviceSP dev, int radius
}catch(GoalFound const&){
for(VertexDescriptor u=goal; u!=start; u = pmap[u]){
result.push_back(QPointF(u.x,u.y));
//qDebug() << g.getIntensity(u);
}
}
......
......@@ -53,25 +53,65 @@ void KisMagneticWorkerTest::testWorker()
auto points = worker.computeEdge(grayscaleDev, 10, startPos, endPos);
KIS_DUMP_DEVICE_2(grayscaleDev, rect, "draw", "dd");
QImage img = dev->convertToQImage(0, rect);
img = img.convertToFormat(QImage::Format_ARGB32);
QPainter gc(&img);
QPainterPath path(points[0]);
for (int i = 1; i < points.size(); i++) {
path.lineTo(points[i]);
qDebug() << points[i];
}
gc.setPen(Qt::blue);
gc.drawPath(path);
gc.setPen(Qt::green);
gc.drawEllipse(startPos, 3, 3);
gc.setPen(Qt::red);
gc.drawEllipse(endPos, 2, 2);
img.save("result.png");
QVector<QPointF> result = { QPointF(50,65),
QPointF(49,64),
QPointF(48,63),
QPointF(47,62),
QPointF(46,61),
QPointF(45,60),
QPointF(44,59),
QPointF(44,58),
QPointF(44,57),
QPointF(44,56),
QPointF(44,55),
QPointF(44,54),
QPointF(44,53),
QPointF(44,52),
QPointF(44,51),
QPointF(44,50),
QPointF(44,49),
QPointF(44,48),
QPointF(44,47),
QPointF(44,46),
QPointF(44,45),
QPointF(44,44),
QPointF(44,43),
QPointF(44,42),
QPointF(43,41),
QPointF(43,40),
QPointF(43,39),
QPointF(44,38),
QPointF(44,37),
QPointF(44,36),
QPointF(44,35),
QPointF(44,34),
QPointF(44,33),
QPointF(44,32),
QPointF(44,31),
QPointF(44,30),
QPointF(44,29),
QPointF(44,28),
QPointF(44,27),
QPointF(44,26),
QPointF(44,25),
QPointF(44,24),
QPointF(44,23),
QPointF(44,22),
QPointF(44,21),
QPointF(44,20),
QPointF(44,19),
QPointF(44,18),
QPointF(43,17),
QPointF(44,16),
QPointF(44,15),
QPointF(44,14),
QPointF(44,13),
QPointF(43,12),
QPointF(42,11),
QPointF(41,11),
QPointF(40,10)};
QCOMPARE(result, points);
}
QTEST_MAIN(KisMagneticWorkerTest)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment