Verified Commit 5adb8eb6 authored by Kuntal  Majumder's avatar Kuntal Majumder 😟

AStar Search is doing its job, mostly likely

Ref T10894
parent 09c77df3
......@@ -59,6 +59,11 @@ struct VertexDescriptor {
}
};
QDebug operator<<(QDebug dbg, const VertexDescriptor &v) {
dbg.nospace() << "(" << v.x << ", " << v.y << ")";
return dbg.space();
}
struct neighbour_iterator;
struct KisMagneticGraph{
......@@ -70,6 +75,7 @@ struct KisMagneticGraph{
topLeft(graphRect.topLeft()), bottomRight(graphRect.bottomRight()), m_dev(dev)
{
outDegree = (bottomRight.y() - topLeft.y()) * (bottomRight.x() - topLeft.x()) - 1;
qDebug() << outDegree;
}
typedef VertexDescriptor vertex_descriptor;
......@@ -100,12 +106,16 @@ struct neighbour_iterator : public boost::iterator_facade<neighbour_iterator,
boost::forward_traversal_tag,
std::pair<VertexDescriptor, VertexDescriptor>>
{
neighbour_iterator(VertexDescriptor v, KisMagneticGraph g):
graph(g), currentPoint(v)
enum position{
begin, end
};
neighbour_iterator(VertexDescriptor v, KisMagneticGraph g, position p):
graph(g), currentPoint(v), pos(p)
{
nextPoint = VertexDescriptor(g.topLeft.x(), g.topLeft.y());
if(nextPoint == currentPoint){
operator++();
increment();
}
}
......@@ -120,17 +130,24 @@ struct neighbour_iterator : public boost::iterator_facade<neighbour_iterator,
void operator++() {
// I am darn sure that Dmitry is wrong, definitely wrong
if(nextPoint == graph.bottomRight)
return; // we are done, no more points
if(nextPoint.x == graph.bottomRight.x()) // end of a row move to next column
nextPoint = VertexDescriptor(graph.topLeft.x(), nextPoint.y++);
else
if(nextPoint == graph.bottomRight){
pos = position::end;
return;
}
if(nextPoint.x == graph.bottomRight.x()){ // end of a row move to next column
nextPoint = VertexDescriptor(graph.topLeft.x(), nextPoint.y + 1);
} else {
nextPoint.x++;
}
if(nextPoint == currentPoint){
increment();
}
}
bool operator==(neighbour_iterator const& that) const {
return currentPoint == that.currentPoint && nextPoint == that.nextPoint;
return pos == that.pos;
}
bool equal(neighbour_iterator const& that) const {
......@@ -144,6 +161,7 @@ struct neighbour_iterator : public boost::iterator_facade<neighbour_iterator,
private:
KisMagneticGraph graph;
VertexDescriptor currentPoint, nextPoint;
position pos;
};
namespace boost{
......@@ -183,8 +201,8 @@ target(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g) {
std::pair<KisMagneticGraph::out_edge_iterator, KisMagneticGraph::out_edge_iterator>
out_edges(typename KisMagneticGraph::vertex_descriptor v, KisMagneticGraph g) {
return std::make_pair(
KisMagneticGraph::out_edge_iterator(v, g),
KisMagneticGraph::out_edge_iterator(v, g)
KisMagneticGraph::out_edge_iterator(v, g, neighbour_iterator::begin),
KisMagneticGraph::out_edge_iterator(v, g, neighbour_iterator::end)
);
}
......@@ -194,9 +212,4 @@ out_degree(typename KisMagneticGraph::vertex_descriptor v, KisMagneticGraph g) {
return g.outDegree;
}
QDebug operator<<(QDebug dbg, const KisMagneticGraph::vertex_descriptor &v) {
dbg.nospace() << "(" << v.x << ", " << v.y << ")";
return dbg.space();
}
#endif
......@@ -169,7 +169,7 @@ QRect KisMagneticWorker::calculateRect(QPoint p1, QPoint p2, int radius) const {
return p.boundingRect();
}
QVector<QPoint> KisMagneticWorker::computeEdge(KisPaintDeviceSP dev, int radius, QPoint begin, QPoint end) {
QVector<QPointF> KisMagneticWorker::computeEdge(KisPaintDeviceSP dev, int radius, QPoint begin, QPoint end) {
QRect rect = calculateRect(begin, end, radius);
KisGaussianKernel::applyLoG(dev, rect, 2, -1.0, QBitArray(), 0);
......@@ -188,7 +188,7 @@ QVector<QPoint> KisMagneticWorker::computeEdge(KisPaintDeviceSP dev, int radius,
std::map<VertexDescriptor, unsigned> imap;
WeightMap wmap;
AStarHeuristic heuristic(goal,pmap);
QVector<QPoint> result;
QVector<QPointF> result;
try{
boost::astar_search_no_init(
......@@ -206,9 +206,15 @@ QVector<QPoint> KisMagneticWorker::computeEdge(KisPaintDeviceSP dev, int radius,
}catch(GoalFound const&){
for(VertexDescriptor u=goal; u!=start; u = pmap[u]){
result.push_back(QPoint(u.x,u.y));
result.push_back(QPointF(u.x,u.y));
}
}
result.push_back(QPoint(start.x,start.y));
for(auto val: result){
qDebug() << val;
}
return result;
}
......@@ -23,7 +23,7 @@
class KRITASELECTIONTOOLS_EXPORT KisMagneticWorker{
public:
QVector<QPoint> computeEdge(KisPaintDeviceSP dev, int radius, QPoint start, QPoint end);
QVector<QPointF> computeEdge(KisPaintDeviceSP dev, int radius, QPoint start, QPoint end);
private:
QRect calculateRect(QPoint p1, QPoint p2, int radius) const;
};
......
......@@ -44,8 +44,9 @@ void KisMagneticWorkerTest::testWorker()
const QRect rect = dev->exactBounds();
KisPaintDeviceSP grayscaleDev = KisPainter::convertToAlphaAsGray(dev);
KisMagneticWorker worker;
KIS_DUMP_DEVICE_2(grayscaleDev, rect, "main", "dd");
QVector<QPointF> result = worker.computeEdge(dev, 2, QPoint(10,10), QPoint(20,20));
KIS_DUMP_DEVICE_2(grayscaleDev, rect, "draw", "dd");
}
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