Commit 3b86ab52 authored by Kuntal  Majumder's avatar Kuntal Majumder 😟

Added the heuristic function for boost::astar_search

Task: T10894
parent d4b3b07f
......@@ -265,7 +265,6 @@ public:
LABEL_B
};
vertices_size_type x;
vertices_size_type y;
VertexType type;
......@@ -273,6 +272,7 @@ public:
VertexDescriptor(vertices_size_type _x, vertices_size_type _y, VertexType _type = NORMAL)
: x(_x), y(_y), type(_type) {}
// TODO: Extra constructors look unnecessary, ask Dmitry before removing
VertexDescriptor(VertexType _type)
: x(0), y(0), type(_type) {}
......
......@@ -18,11 +18,58 @@
#include "KisMagneticWorker.h"
#include "kis_gaussian_kernel.h"
#include <kis_painter.h>
#include <QtCore>
#include <boost/graph/astar_search.hpp>
#include <boost/functional/hash.hpp>
#include <boost/unordered_map.hpp>
#include <libs/image/lazybrush/kis_lazy_fill_graph.h>
typedef KisLazyFillGraph::VertexDescriptor VertexDescriptor;
struct VertexHash : std::unary_function<VertexDescriptor, std::size_t> {
std::size_t operator()(VertexDescriptor const& u) const {
std::size_t seed = 0;
boost::hash_combine(seed, u.x);
boost::hash_combine(seed, u.y);
return seed;
}
};
typedef boost::unordered_map<VertexDescriptor, VertexDescriptor, VertexHash> PredMap;
typedef boost::associative_property_map<PredMap> APredMap;
class AstarHeuristic : public boost::astar_heuristic<KisLazyFillGraph, double> {
private:
APredMap m_pmap;
VertexDescriptor m_goal;
double coeff_a, coeff_b;
public:
AstarHeuristic(VertexDescriptor goal, APredMap pmap, double a, double b):
m_pmap(pmap), m_goal(goal), coeff_a(a), coeff_b(b)
{ }
AstarHeuristic(VertexDescriptor goal, APredMap pmap):
m_pmap(pmap), m_goal(goal), coeff_a(0.5), coeff_b(0.5)
{ }
double operator()(VertexDescriptor v){
auto prev = m_pmap[v];
auto di = (m_goal.y - prev.y) * v.x + (m_goal.x - prev.x) * v.y;
di = std::abs(di + prev.x * m_goal.y + prev.y * m_goal.x);
auto dist = [](VertexDescriptor p1, VertexDescriptor p2){
return std::sqrt(std::pow(p1.y-p2.y, 2) + std::pow(p1.x-p2.x, 2));
};
auto dz = dist(prev, m_goal);
di = di/dz;
auto dm = dist(v, m_goal);
return coeff_a * di + coeff_b * (dm - dz);
}
};
void KisMagneticWorker::run(KisPaintDeviceSP dev, const QRect &rect)
{
KisGaussianKernel::applyLoG(dev, rect, 2, -1.0, QBitArray(), 0);
}
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