7#ifndef __KIS_LAZY_FILL_GRAPH_H
8#define __KIS_LAZY_FILL_GRAPH_H
11#include <boost/limits.hpp>
12#include <boost/operators.hpp>
14#include <boost/graph/graph_traits.hpp>
15#include <boost/graph/properties.hpp>
16#include <boost/iterator/counting_iterator.hpp>
17#include <boost/iterator/transform_iterator.hpp>
23#ifdef USE_LAZY_FILL_SANITY_CHECKS
24#define LF_SANITY_ASSERT(x) KIS_ASSERT(x)
25#define LF_SANITY_ASSERT_RECOVER(x) KIS_ASSERT_RECOVER(x)
27#define LF_SANITY_ASSERT(x)
28#define LF_SANITY_ASSERT_RECOVER(x) if (0)
44template <
typename Graph,
70 return (index_map[key]);
81template <
typename Descriptor>
96 friend inline Descriptor
100 return (rev_map[key]);
111 template <
typename Graph>
114 typedef typename graph_traits<Graph>::vertex_descriptor
result_type;
123 (
typename graph_traits<Graph>::vertices_size_type vertex_index)
const {
124 return (vertex(vertex_index, *
m_graph));
132 template <
typename Graph>
139 typedef typename graph_traits<Graph>::edge_descriptor
result_type;
144 const Graph* graph) :
150 (
typename graph_traits<Graph>::degree_size_type out_edge_index)
const {
160 template <
typename Graph>
167 typedef typename graph_traits<Graph>::edge_descriptor
result_type;
172 const Graph* graph) :
178 (
typename graph_traits<Graph>::degree_size_type in_edge_index)
const {
188 template <
typename Graph>
191 typedef typename graph_traits<Graph>::edge_descriptor
result_type;
200 (
typename graph_traits<Graph>::edges_size_type edge_index)
const {
201 return (edge_at(edge_index, *
m_graph));
209 template <
typename Graph>
213 typedef typename graph_traits<Graph>::vertex_descriptor
result_type;
216 const Graph* graph) :
222 (
typename graph_traits<Graph>::degree_size_type adjacent_index)
const {
261 :
x(_x),
y(_y),
type(_type) {}
265 :
x(0),
y(0),
type(_type) {}
290 typedef transform_iterator<edge_function, edge_index_iterator>
edge_iterator;
305 virtual public adjacency_graph_tag,
306 virtual public vertex_list_graph_tag,
307 virtual public edge_list_graph_tag,
308 virtual public adjacency_matrix_tag { };
313 std::numeric_limits<vertices_size_type>::max(),
314 std::numeric_limits<vertices_size_type>::max(),
317 return (maxed_out_vertex);
419 size(_rect.width() * _rect.height()),
431 size(_rect.width() * _rect.height()),
444 return index >= 0 && index <
size;
460 if (srcColoredA || dstColoredA) {
461 const bool edgeReversed = srcColoredA;
470 }
else if (srcColoredB || dstColoredB) {
471 const bool edgeReversed = srcColoredB;
485 const bool edgeReversed = xDiff < 0 || yDiff < 0;
492 xAbsDiff == yAbsDiff) {
499 std::swap(src_vertex, dst_vertex);
503 const int x = src_vertex.
x;
504 const int y = src_vertex.
y;
505 if (x <
rect.x() || x >
rect.right() ||
506 y <
rect.y() || y >
rect.bottom()) {
518 return internalIndex +
start;
525 if (localOffset < 0 || localOffset >=
size) {
538 dst_vertex.
x = x + 1;
545 dst_vertex.
y = y + 1;
559 std::swap(src_vertex, dst_vertex);
562 return std::make_pair(src_vertex, dst_vertex);
624 }
else if (vertex_index >= 0) {
650 return m_edgeBins[binIndex].edgeAt(edge_index);
660 index = it->indexOf(
edge);
661 if (index >= 0)
break;
693 auto it = rects.constBegin();
694 for (; it != rects.constEnd(); ++it) {
696 if (it->contains(pt)) {
733 return (out_edge_count);
760 qFatal(
"Wrong edge sub-index");
765 dst_vertex =
edge.second;
770 dst_vertex =
edge.second;
775 return std::make_pair(
vertex, dst_vertex);
791 return (std::make_pair
822 return (std::make_pair
855 return (std::make_pair
866 friend std::pair<typename type::edge_descriptor, bool>
871 std::pair<typename type::edge_descriptor, bool> edge_exists =
872 std::make_pair(std::make_pair(source_vertex, destination_vertex),
false);
876 edge_exists.second = index >= 0;
893 return (graph.
edge_at(edge_index));
903 return (std::make_pair
964 template<
typename Graph,
969 template<
typename Descriptor>
977 typename graph_traits<KisLazyFillGraph>::vertex_descriptor,
978 typename graph_traits<KisLazyFillGraph>::vertices_size_type>
type;
985 typename graph_traits<KisLazyFillGraph>::edge_descriptor,
986 typename graph_traits<KisLazyFillGraph>::edges_size_type>
type;
1000 const QString
type =
1005 dbg.nospace() <<
"(" <<
v.x <<
", " <<
v.y <<
", " <<
type <<
")";
1013 dbg.nospace() <<
"(" << src <<
" -> " << dst <<
")";
KisMagneticGraph::vertex_descriptor target(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
transform_iterator< out_edge_function, degree_iterator > out_edge_iterator
vertices_size_type m_aReversedEdgesStart
kis_detail::lazy_fill_graph_edge_at< type > edge_function
transform_iterator< adjacent_vertex_function, degree_iterator > adjacency_iterator
EdgeIndex degree_size_type
QVector< QRect > m_aLabelRects
friend std::pair< typename type::adjacency_iterator, typename type::adjacency_iterator > adjacent_vertices(typename type::vertex_descriptor vertex, const type &graph)
transform_iterator< edge_function, edge_index_iterator > edge_iterator
friend type::vertex_descriptor vertex(typename type::vertices_size_type vertex_index, const type &graph)
edges_size_type num_edges() const
friend type::vertices_size_type get(vertex_index_t, const type &graph, typename type::vertex_descriptor vertex)
edge_descriptor edge_at(edges_size_type edge_index) const
counting_iterator< vertices_size_type > vertex_index_iterator
QVector< EdgeIndexBin > m_edgeBins
vertex_descriptor vertex_at(vertices_size_type vertex_index) const
vertices_size_type num_vertices() const
friend QDebug operator<<(QDebug dbg, const KisLazyFillGraph::edge_descriptor &e)
static bool findInRects(const QVector< QRect > &rects, const QPoint &pt)
friend type::edges_size_type get(edge_index_t, const type &graph, typename type::edge_descriptor edge)
vertices_size_type m_width
VertexDescriptor vertex_descriptor
kis_detail::lazy_fill_graph_out_edge_at< type > out_edge_function
vertices_size_type m_numEdges
edge_descriptor out_edge_at(vertex_descriptor vertex, degree_size_type out_edge_index) const
edges_size_type index_of(edge_descriptor edge) const
KisLazyFillGraph(const QRect &mainRect, const KisRegion &aLabelRegion, const KisRegion &bLabelRegion)
EdgeIndex edges_size_type
vertices_size_type m_numBEdges
counting_iterator< degree_size_type > degree_iterator
vertices_size_type m_numVertices
friend std::pair< typename type::vertex_iterator, typename type::vertex_iterator > vertices(const type &graph)
friend lazy_fill_graph_reverse_edge_map< typename type::edge_descriptor > get(edge_reverse_t, const type &graph)
friend std::pair< typename type::edge_iterator, typename type::edge_iterator > edges(const type &graph)
degree_size_type out_degree(vertex_descriptor vertex) const
vertices_size_type m_numAEdges
static vertex_descriptor null_vertex()
friend type::vertices_size_type num_vertices(const type &graph)
counting_iterator< edges_size_type > edge_index_iterator
static vertices_size_type numVacantEdges(const vertex_descriptor &vertex, const QRect &rc)
friend lazy_fill_graph_index_map< type, typename type::vertex_descriptor, typename type::vertices_size_type > get(vertex_index_t, const type &graph)
friend lazy_fill_graph_index_map< type, typename type::edge_descriptor, typename type::edges_size_type > get(edge_index_t, const type &graph)
vertices_size_type m_height
friend type::degree_size_type out_degree(typename type::vertex_descriptor vertex, const type &graph)
friend std::pair< typename type::edge_descriptor, bool > edge(typename type::vertex_descriptor source_vertex, typename type::vertex_descriptor destination_vertex, const type &graph)
disallow_parallel_edge_tag edge_parallel_category
vertices_size_type m_bReversedEdgesStart
vertices_size_type index_of(vertex_descriptor vertex) const
friend type::edge_descriptor edge_at(typename type::edges_size_type edge_index, const type &graph)
friend type::edges_size_type num_edges(const type &graph)
friend type::edge_descriptor out_edge_at(typename type::vertex_descriptor vertex, typename type::degree_size_type out_edge_index, const type &graph)
QVector< QRect > m_bLabelRects
friend std::pair< typename type::out_edge_iterator, typename type::out_edge_iterator > out_edges(typename type::vertex_descriptor vertex, const type &graph)
transform_iterator< vertex_function, vertex_index_iterator > vertex_iterator
directed_tag directed_category
kis_detail::lazy_fill_graph_vertex_at< KisLazyFillGraph > vertex_function
kis_detail::lazy_fill_graph_adjacent_vertex_at< type > adjacent_vertex_function
VertexIndex vertices_size_type
std::pair< vertex_descriptor, vertex_descriptor > edge_descriptor
QRect boundingRect() const
QVector< QRect > rects() const
QDebug operator<<(QDebug dbg, const KisLazyFillGraph::vertex_descriptor &v)
#define LF_SANITY_ASSERT_RECOVER(x)
#define LF_SANITY_ASSERT(x)
EdgeIndexBin(const EdgeIndexBin &putAfter, const QRect &_rect, EdgeIndexBinId _binId)
bool contains(const edge_descriptor &edge) const
edges_size_type indexOf(const edge_descriptor &edge) const
edges_size_type last() const
edge_descriptor edgeAt(edges_size_type index) const
EdgeIndexBin(edges_size_type _start, const QRect &_rect, EdgeIndexBinId _binId)
bool contains(edges_size_type index) const
bool operator==(const VertexDescriptor &rhs) const
VertexDescriptor(vertices_size_type _x, vertices_size_type _y, VertexType _type=NORMAL)
VertexDescriptor(VertexType _type)
lazy_fill_graph_index_map< KisLazyFillGraph, typename graph_traits< KisLazyFillGraph >::edge_descriptor, typename graph_traits< KisLazyFillGraph >::edges_size_type > type
lazy_fill_graph_reverse_edge_map< typename graph_traits< KisLazyFillGraph >::edge_descriptor > type
lazy_fill_graph_index_map< KisLazyFillGraph, typename graph_traits< KisLazyFillGraph >::vertex_descriptor, typename graph_traits< KisLazyFillGraph >::vertices_size_type > type
lazy_fill_graph_adjacent_vertex_at(result_type source_vertex, const Graph *graph)
graph_traits< Graph >::vertex_descriptor result_type
graph_traits< Graph >::edge_descriptor result_type
lazy_fill_graph_edge_at(const Graph *graph)
lazy_fill_graph_edge_at()
graph_traits< Graph >::vertex_descriptor vertex_descriptor
graph_traits< Graph >::edge_descriptor result_type
lazy_fill_graph_in_edge_at()
lazy_fill_graph_in_edge_at(vertex_descriptor target_vertex, const Graph *graph)
vertex_descriptor m_vertex
vertex_descriptor m_vertex
lazy_fill_graph_out_edge_at(vertex_descriptor source_vertex, const Graph *graph)
graph_traits< Graph >::edge_descriptor result_type
graph_traits< Graph >::vertex_descriptor vertex_descriptor
lazy_fill_graph_out_edge_at()
lazy_fill_graph_vertex_at()
lazy_fill_graph_vertex_at(const Graph *graph)
graph_traits< Graph >::vertex_descriptor result_type
readable_property_map_tag category
value_type operator[](key_type key) const
friend Index get(const lazy_fill_graph_index_map< Graph, Descriptor, Index > &index_map, const typename lazy_fill_graph_index_map< Graph, Descriptor, Index >::key_type &key)
lazy_fill_graph_index_map()
lazy_fill_graph_index_map(const Graph &graph)
Descriptor reference_type
lazy_fill_graph_reverse_edge_map()
value_type operator[](const key_type &key) const
friend Descriptor get(const lazy_fill_graph_reverse_edge_map< Descriptor > &rev_map, const typename lazy_fill_graph_reverse_edge_map< Descriptor >::key_type &key)
readable_property_map_tag category