Verified Commit 84a3aea2 authored by Kuntal  Majumder's avatar Kuntal Majumder 😟

Adapting KisPaintDevice to boost::graph, added incidence graph and vertex list graph properties

parent 9a05e626
...@@ -20,12 +20,136 @@ ...@@ -20,12 +20,136 @@
#include <boost/limits.hpp> #include <boost/limits.hpp>
#include <boost/operators.hpp> #include <boost/operators.hpp>
#include <boost/graph/graph_traits.hpp> #include <boost/graph/graph_traits.hpp>
#include <boost/graph/properties.hpp> #include <boost/graph/properties.hpp>
#include <boost/iterator/counting_iterator.hpp> #include <boost/iterator/counting_iterator.hpp>
#include <boost/iterator/transform_iterator.hpp> #include <boost/iterator/transform_iterator.hpp>
#include <QDebug>
// vertex_at
template <typename Graph>
struct magnetic_graph_vertex_at {
typedef typename boost::graph_traits<Graph>::vertex_descriptor result_type;
magnetic_graph_vertex_at() : m_graph(0) {}
magnetic_graph_vertex_at(const Graph* graph) :
m_graph(graph) { }
result_type
operator() (typename boost::graph_traits<Graph>::vertices_size_type vertex_index) const {
return (vertex(vertex_index, *m_graph));
}
private:
const Graph* m_graph;
};
// out_edge_at
template <typename Graph>
struct magnetic_graph_out_edge_at {
private:
typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
public:
typedef typename boost::graph_traits<Graph>::edge_descriptor result_type;
magnetic_graph_out_edge_at() :
m_vertex(), m_graph(0)
{ }
magnetic_graph_out_edge_at(vertex_descriptor source_vertex, const Graph* graph) :
m_vertex(source_vertex), m_graph(graph)
{ }
result_type
operator() (typename boost::graph_traits<Graph>::degree_size_type out_edge_index) const {
return (out_edge_at(m_vertex, out_edge_index, *m_graph));
}
private:
vertex_descriptor m_vertex;
const Graph* m_graph;
};
// in_edge_at
template <typename Graph>
struct magnetic_graph_in_edge_at {
private:
typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
public:
typedef typename boost::graph_traits<Graph>::edge_descriptor result_type;
magnetic_graph_in_edge_at() :
m_vertex(), m_graph(0)
{ }
magnetic_graph_in_edge_at(vertex_descriptor target_vertex, const Graph* graph) :
m_vertex(target_vertex), m_graph(graph)
{ }
result_type
operator() (typename boost::graph_traits<Graph>::degree_size_type in_edge_index) const {
return (in_edge_at(m_vertex, in_edge_index, *m_graph));
}
private:
vertex_descriptor m_vertex;
const Graph* m_graph;
};
// edge_at
template <typename Graph>
struct magnetic_graph_edge_at {
typedef typename boost::graph_traits<Graph>::edge_descriptor result_type;
magnetic_graph_edge_at () :
m_graph(0)
{ }
magnetic_graph_edge_at (const Graph* graph) :
m_graph(graph)
{ }
result_type operator()
(typename boost::graph_traits<Graph>::edges_size_type edge_index) const {
return (edge_at(edge_index, *m_graph));
}
private:
const Graph* m_graph;
};
// adjacent_vertex_at
template <typename Graph>
struct magnetic_graph_adjacent_vertex_at {
public:
typedef typename boost::graph_traits<Graph>::vertex_descriptor result_type;
magnetic_graph_adjacent_vertex_at
(result_type source_vertex, const Graph* graph) :
m_vertex(source_vertex), m_graph(graph)
{ }
result_type operator()
(typename boost::graph_traits<Graph>::degree_size_type adjacent_index) const {
return (target(out_edge_at(m_vertex, adjacent_index, *m_graph), *m_graph));
}
private:
result_type m_vertex;
const Graph* m_graph;
};
class KisMagneticGraph{ class KisMagneticGraph{
public: public:
typedef KisMagneticGraph type; typedef KisMagneticGraph type;
...@@ -57,6 +181,30 @@ public: ...@@ -57,6 +181,30 @@ public:
typedef VertexDescriptor vertex_descriptor; typedef VertexDescriptor vertex_descriptor;
typedef std::pair<vertex_descriptor, vertex_descriptor> edge_descriptor; typedef std::pair<vertex_descriptor, vertex_descriptor> edge_descriptor;
friend QDebug operator<<(QDebug dbg, const KisMagneticGraph::edge_descriptor &e);
friend QDebug operator<<(QDebug dbg, const KisMagneticGraph::vertex_descriptor &v);
typedef boost::directed_tag directed_category;
typedef boost::disallow_parallel_edge_tag edge_parallel_category;
struct traversal_category : virtual public boost::incidence_graph_tag,
virtual public boost::vertex_list_graph_tag
{ };
KisMagneticGraph() { }
}; };
QDebug operator<<(QDebug dbg, const KisMagneticGraph::vertex_descriptor &v) {
dbg.nospace() << "(" << v.x << ", " << v.y << ")";
return dbg.space();
}
QDebug operator<<(QDebug dbg, const KisMagneticGraph::edge_descriptor &e) {
KisMagneticGraph::vertex_descriptor src = e.first;
KisMagneticGraph::vertex_descriptor dst = e.second;
dbg.nospace() << "(" << src << " -> " << dst << ")";
return dbg.space();
}
#endif #endif
...@@ -39,7 +39,7 @@ struct VertexHash : std::unary_function<VertexDescriptor, std::size_t> { ...@@ -39,7 +39,7 @@ struct VertexHash : std::unary_function<VertexDescriptor, std::size_t> {
typedef boost::unordered_map<VertexDescriptor, VertexDescriptor, VertexHash> PredMap; typedef boost::unordered_map<VertexDescriptor, VertexDescriptor, VertexHash> PredMap;
typedef boost::associative_property_map<PredMap> APredMap; typedef boost::associative_property_map<PredMap> APredMap;
class AstarHeuristic : public boost::astar_heuristic<KisLazyFillGraph, double> { class AstarHeuristic : public boost::astar_heuristic<KisMagneticGraph, double> {
private: private:
APredMap m_pmap; APredMap m_pmap;
VertexDescriptor m_goal; VertexDescriptor m_goal;
...@@ -68,6 +68,10 @@ class AstarHeuristic : public boost::astar_heuristic<KisLazyFillGraph, double> { ...@@ -68,6 +68,10 @@ class AstarHeuristic : public boost::astar_heuristic<KisLazyFillGraph, double> {
} }
}; };
KisMagneticWorker::KisMagneticWorker():
m_dev(0), m_rect(QRect())
{ }
KisMagneticWorker::KisMagneticWorker(KisPaintDeviceSP dev, const QRect &rect): KisMagneticWorker::KisMagneticWorker(KisPaintDeviceSP dev, const QRect &rect):
m_dev(dev), m_rect(rect) m_dev(dev), m_rect(rect)
{ } { }
...@@ -79,5 +83,7 @@ void KisMagneticWorker::run(KisPaintDeviceSP dev, const QRect &rect) ...@@ -79,5 +83,7 @@ void KisMagneticWorker::run(KisPaintDeviceSP dev, const QRect &rect)
void KisMagneticWorker::computeEdge(QPoint start, QPoint end) void KisMagneticWorker::computeEdge(QPoint start, QPoint end)
{ {
Q_UNUSED(start)
Q_UNUSED(end)
KisGaussianKernel::applyLoG(m_dev, m_rect, 2, -1.0, QBitArray(), 0); KisGaussianKernel::applyLoG(m_dev, m_rect, 2, -1.0, QBitArray(), 0);
} }
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
class KRITASELECTIONTOOLS_EXPORT KisMagneticWorker{ class KRITASELECTIONTOOLS_EXPORT KisMagneticWorker{
public: public:
KisMagneticWorker();
KisMagneticWorker(KisPaintDeviceSP dev, const QRect &rect); KisMagneticWorker(KisPaintDeviceSP dev, const QRect &rect);
void run(KisPaintDeviceSP dev, const QRect& rect); void run(KisPaintDeviceSP dev, const QRect& rect);
void computeEdge(QPoint start, QPoint end); void computeEdge(QPoint start, QPoint end);
......
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