29 #ifndef __vtkBoostGraphAdapter_h
30 #define __vtkBoostGraphAdapter_h
32 #include "vtkAbstractArray.h"
33 #include "vtkDirectedGraph.h"
34 #include "vtkDistributedGraphHelper.h"
35 #include "vtkDataObject.h"
36 #include "vtkDataArray.h"
37 #include "vtkDoubleArray.h"
38 #include "vtkFloatArray.h"
39 #include "vtkIdTypeArray.h"
40 #include "vtkInformation.h"
41 #include "vtkIntArray.h"
42 #include "vtkMutableDirectedGraph.h"
43 #include "vtkMutableUndirectedGraph.h"
45 #include "vtkUndirectedGraph.h"
46 #include "vtkVariant.h"
48 #include <boost/version.hpp>
58 struct read_write_property_map_tag;
60 #define vtkPropertyMapMacro(T, V) \
62 struct property_traits<T*> \
64 typedef V value_type; \
65 typedef V reference; \
66 typedef vtkIdType key_type; \
67 typedef read_write_property_map_tag category; \
70 inline property_traits<T*>::reference \
73 property_traits<T*>::key_type key) \
75 return arr->GetValue(key); \
81 property_traits<T*>::key_type key, \
82 const property_traits<T*>::value_type & value) \
84 arr->InsertValue(key, value); \
103 get(vtkDataArray *
const& arr, vtkIdType key)
105 return arr->GetTuple1(key);
109 put(vtkDataArray *arr, vtkIdType key,
const double& value)
111 arr->SetTuple1(key, value);
125 get(vtkAbstractArray *
const& arr, vtkIdType key)
127 return arr->GetVariantValue(key);
131 put(vtkAbstractArray *arr, vtkIdType key,
const vtkVariant& value)
133 arr->InsertVariantValue(key, value);
137 #include <vtksys/stl/utility>
139 #include <boost/config.hpp>
140 #include <boost/iterator/iterator_facade.hpp>
141 #include <boost/graph/graph_traits.hpp>
142 #include <boost/graph/properties.hpp>
143 #include <boost/graph/adjacency_iterator.hpp>
152 public iterator_facade<vtk_vertex_iterator,
154 bidirectional_traversal_tag,
162 vtkIdType dereference()
const {
return index; }
165 {
return index == other.index; }
167 void increment() { index++; }
168 void decrement() { index--; }
176 public iterator_facade<vtk_edge_iterator,
178 forward_traversal_tag,
184 directed(false), vertex(v), lastVertex(v), iter(0), end(0), graph(g)
188 lastVertex = graph->GetNumberOfVertices();
191 vtkIdType myRank = -1;
192 vtkDistributedGraphHelper *helper
193 = this->graph? this->graph->GetDistributedGraphHelper() : 0;
196 myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
197 vertex = helper->MakeDistributedId(myRank, vertex);
198 lastVertex = helper->MakeDistributedId(myRank, lastVertex);
203 directed = (vtkDirectedGraph::SafeDownCast(graph) != 0);
204 while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
209 if (vertex < lastVertex)
214 graph->GetOutEdges(vertex, iter, nedges);
221 (helper && helper->GetEdgeOwner(iter->Id) != myRank)
224 && myRank == helper->GetVertexOwner(iter->Target))
226 && vertex > iter->Target)))
240 vtkEdgeType dereference()
const
241 {
return vtkEdgeType(vertex, iter->Target, iter->Id); }
244 {
return vertex == other.vertex && iter == other.iter; }
251 vtkIdType myRank = -1;
252 vtkDistributedGraphHelper *helper
253 = this->graph? this->graph->GetDistributedGraphHelper() : 0;
256 myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
261 (helper && helper->GetEdgeOwner(iter->Id) != myRank)
264 && myRank == helper->GetVertexOwner(iter->Target))
266 && vertex > iter->Target)))
280 while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
285 if (vertex < lastVertex)
288 graph->GetOutEdges(vertex, iter, nedges);
300 vtkIdType lastVertex;
301 const vtkOutEdgeType * iter;
302 const vtkOutEdgeType * end;
309 public iterator_facade<vtk_out_edge_pointer_iterator,
311 bidirectional_traversal_tag,
322 g->GetOutEdges(vertex, iter, nedges);
331 vtkEdgeType dereference()
const {
return vtkEdgeType(vertex, iter->Target, iter->Id); }
334 {
return iter == other.iter; }
336 void increment() { iter++; }
337 void decrement() { iter--; }
340 const vtkOutEdgeType *iter;
346 public iterator_facade<vtk_in_edge_pointer_iterator,
348 bidirectional_traversal_tag,
359 g->GetInEdges(vertex, iter, nedges);
368 vtkEdgeType dereference()
const {
return vtkEdgeType(iter->Source, vertex, iter->Id); }
371 {
return iter == other.iter; }
373 void increment() { iter++; }
374 void decrement() { iter--; }
377 const vtkInEdgeType *iter;
389 public virtual bidirectional_graph_tag,
390 public virtual edge_list_graph_tag,
391 public virtual vertex_list_graph_tag,
392 public virtual adjacency_graph_tag { };
395 struct graph_traits<vtkGraph*> {
399 static edge_descriptor
null_edge() {
return vtkEdgeType(-1, -1, -1); }
412 typedef adjacency_iterator_generator<vtkGraph*,
416 #if BOOST_VERSION >= 104500
418 struct graph_property_type< vtkGraph* > {
419 typedef no_property type;
424 struct vertex_property_type< vtkGraph* > {
429 struct edge_property_type< vtkGraph* > {
433 #if BOOST_VERSION >= 104500
435 struct graph_bundle_type< vtkGraph* > {
436 typedef no_property type;
441 struct vertex_bundle_type< vtkGraph* > {
446 struct edge_bundle_type< vtkGraph* > {
452 return ((g->GetNumberOfEdges() > 0) ?
false :
true);
458 if(vtkMutableDirectedGraph::SafeDownCast(g))
460 vtkMutableDirectedGraph::SafeDownCast(g)->RemoveEdge(e.Id);
462 else if(vtkMutableUndirectedGraph::SafeDownCast(g))
464 vtkMutableUndirectedGraph::SafeDownCast(g)->RemoveEdge(e.Id);
485 #if BOOST_VERSION >= 104500
489 : graph_property_type< vtkGraph* > { };
494 : graph_property_type< vtkGraph* > { };
517 #if BOOST_VERSION >= 104500
521 : graph_bundle_type< vtkGraph* > { };
526 : graph_bundle_type< vtkGraph* > { };
579 #if BOOST_VERSION >= 104500
582 struct graph_property_type< vtkUndirectedGraph* >
583 : graph_property_type< vtkGraph* > { };
587 struct graph_property_type< vtkUndirectedGraph*
const >
588 : graph_property_type< vtkGraph* > { };
593 struct vertex_property_type< vtkUndirectedGraph* >
598 struct vertex_property_type< vtkUndirectedGraph*
const >
603 struct edge_property_type< vtkUndirectedGraph* >
608 struct edge_property_type< vtkUndirectedGraph*
const >
611 #if BOOST_VERSION >= 104500
614 struct graph_bundle_type< vtkUndirectedGraph* >
615 : graph_bundle_type< vtkGraph* > { };
619 struct graph_bundle_type< vtkUndirectedGraph*
const >
620 : graph_bundle_type< vtkGraph* > { };
625 struct vertex_bundle_type< vtkUndirectedGraph* >
630 struct vertex_bundle_type< vtkUndirectedGraph*
const >
635 struct edge_bundle_type< vtkUndirectedGraph* >
640 struct edge_bundle_type< vtkUndirectedGraph*
const >
657 #if BOOST_VERSION >= 104500
660 struct graph_property_type< vtkMutableDirectedGraph* >
661 : graph_property_type< vtkDirectedGraph* > { };
665 struct graph_property_type< vtkMutableDirectedGraph*
const >
666 : graph_property_type< vtkDirectedGraph* > { };
671 struct vertex_property_type< vtkMutableDirectedGraph* >
676 struct vertex_property_type< vtkMutableDirectedGraph*
const >
681 struct edge_property_type< vtkMutableDirectedGraph* >
686 struct edge_property_type< vtkMutableDirectedGraph*
const >
689 #if BOOST_VERSION >= 104500
692 struct graph_bundle_type< vtkMutableDirectedGraph* >
693 : graph_bundle_type< vtkDirectedGraph* > { };
697 struct graph_bundle_type< vtkMutableDirectedGraph*
const >
698 : graph_bundle_type< vtkDirectedGraph* > { };
703 struct vertex_bundle_type< vtkMutableDirectedGraph* >
708 struct vertex_bundle_type< vtkMutableDirectedGraph*
const >
713 struct edge_bundle_type< vtkMutableDirectedGraph* >
718 struct edge_bundle_type< vtkMutableDirectedGraph*
const >
735 #if BOOST_VERSION >= 104500
738 struct graph_property_type< vtkMutableUndirectedGraph* >
739 : graph_property_type< vtkUndirectedGraph* > { };
743 struct graph_property_type< vtkMutableUndirectedGraph*
const >
744 : graph_property_type< vtkUndirectedGraph* > { };
749 struct vertex_property_type< vtkMutableUndirectedGraph* >
754 struct vertex_property_type< vtkMutableUndirectedGraph*
const >
759 struct edge_property_type< vtkMutableUndirectedGraph* >
764 struct edge_property_type< vtkMutableUndirectedGraph*
const >
767 #if BOOST_VERSION >= 104500
770 struct graph_bundle_type< vtkMutableUndirectedGraph* >
771 : graph_bundle_type< vtkUndirectedGraph* > { };
775 struct graph_bundle_type< vtkMutableUndirectedGraph*
const >
776 : graph_bundle_type< vtkUndirectedGraph* > { };
781 struct vertex_bundle_type< vtkMutableUndirectedGraph* >
786 struct vertex_bundle_type< vtkMutableUndirectedGraph*
const >
791 struct edge_bundle_type< vtkMutableUndirectedGraph* >
796 struct edge_bundle_type< vtkMutableUndirectedGraph*
const >
802 class vertex_property< vtkGraph* > {
808 class edge_property< vtkGraph* > {
828 inline vtksys_stl::pair<
830 boost::graph_traits< vtkGraph* >::vertex_iterator >
833 typedef boost::graph_traits< vtkGraph* >::vertex_iterator Iter;
835 if (vtkDistributedGraphHelper *helper = g->GetDistributedGraphHelper())
838 g->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
839 start = helper->MakeDistributedId(rank, start);
842 return vtksys_stl::make_pair( Iter(start),
843 Iter(start + g->GetNumberOfVertices()) );
846 inline vtksys_stl::pair<
848 boost::graph_traits< vtkGraph* >::edge_iterator >
851 typedef boost::graph_traits< vtkGraph* >::edge_iterator Iter;
852 return vtksys_stl::make_pair( Iter(g), Iter(g, g->GetNumberOfVertices()) );
855 inline vtksys_stl::pair<
857 boost::graph_traits< vtkGraph* >::out_edge_iterator >
862 typedef boost::graph_traits< vtkGraph* >::out_edge_iterator Iter;
863 vtksys_stl::pair<Iter, Iter> p = vtksys_stl::make_pair( Iter(g, u), Iter(g, u,
true) );
867 inline vtksys_stl::pair<
869 boost::graph_traits< vtkGraph* >::in_edge_iterator >
874 typedef boost::graph_traits< vtkGraph* >::in_edge_iterator Iter;
875 vtksys_stl::pair<Iter, Iter> p = vtksys_stl::make_pair( Iter(g, u), Iter(g, u,
true) );
879 inline vtksys_stl::pair<
881 boost::graph_traits< vtkGraph* >::adjacency_iterator >
886 typedef boost::graph_traits< vtkGraph* >::adjacency_iterator Iter;
887 typedef boost::graph_traits< vtkGraph* >::out_edge_iterator OutEdgeIter;
888 vtksys_stl::pair<OutEdgeIter, OutEdgeIter> out =
out_edges(u, g);
889 return vtksys_stl::make_pair( Iter(out.first, &g), Iter(out.second, &g) );
895 return g->GetNumberOfVertices();
901 return g->GetNumberOfEdges();
909 return g->GetOutDegree(u);
917 return g->GetInDegree(u);
925 return g->GetDegree(u);
931 return g->AddVertex();
934 inline vtksys_stl::pair<
940 vtkMutableDirectedGraph *g)
942 boost::graph_traits< vtkMutableDirectedGraph* >::edge_descriptor e = g->AddEdge(u, v);
943 return vtksys_stl::make_pair(e,
true);
949 return g->AddVertex();
952 inline vtksys_stl::pair<
958 vtkMutableUndirectedGraph *g)
960 boost::graph_traits< vtkMutableUndirectedGraph* >::edge_descriptor e = g->AddEdge(u, v);
961 return vtksys_stl::make_pair(e,
true);
992 template<
typename PMap>
1004 template<
typename PMap>
1010 return get(helper.pmap, key.Id);
1013 template<
typename PMap>
1020 put(helper.
pmap, key.Id, value);
1049 template<
typename PMap>
1062 template<
typename PMap>
1068 return multi.multiplier *
get(multi.pmap, key);
1071 template<
typename PMap>
1084 struct property_map<vtkGraph*, vertex_index_t>
1095 struct property_map<vtkUndirectedGraph*, vertex_index_t>
1101 struct property_map<vtkGraph*, edge_index_t>
1112 struct property_map<vtkUndirectedGraph*, edge_index_t>
1123 struct property_map<vtkUndirectedGraph*
const, vertex_index_t>
1131 struct property_map<vtkUndirectedGraph*
const, edge_index_t>
1135 #if BOOST_VERSION > 104000
1136 #include <boost/property_map/vector_property_map.hpp>
1138 #include <boost/vector_property_map.hpp>
1142 #endif // __vtkBoostGraphAdapter_h
property_traits< PMap >::reference reference
property_traits< PMap >::category category
vtk_out_edge_pointer_iterator(vtkGraph *g=0, vtkIdType v=0, bool end=false)
vtkGraphEdgePropertyMapHelper(PMap m)
read_write_property_map_tag category
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtksys_stl::pair< boost::graph_traits< vtkGraph * >::vertex_iterator, boost::graph_traits< vtkGraph * >::vertex_iterator > vertices(vtkGraph *g)
vtk_out_edge_pointer_iterator out_edge_iterator
vtksys_stl::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
property_traits< PMap >::reference reference
vtkIdType degree_size_type
vtkPropertyMapMacro(vtkIntArray, int) vtkPropertyMapMacro(vtkIdTypeArray
vtkGraphPropertyMapMultiplier(PMap m, float multi=1)
friend class iterator_core_access
vtkGraph_traversal_category traversal_category
directed_tag directed_category
vtksys_stl::pair< boost::graph_traits< vtkMutableDirectedGraph * >::edge_descriptor, bool > add_edge(boost::graph_traits< vtkMutableDirectedGraph * >::vertex_descriptor u, boost::graph_traits< vtkMutableDirectedGraph * >::vertex_descriptor v, vtkMutableDirectedGraph *g)
vtk_in_edge_pointer_iterator in_edge_iterator
vtkIdType edges_size_type
vtk_edge_iterator edge_iterator
vtksys_stl::pair< boost::graph_traits< vtkGraph * >::adjacency_iterator, boost::graph_traits< vtkGraph * >::adjacency_iterator > adjacent_vertices(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
property_traits< PMap >::key_type key_type
read_write_property_map_tag category
vtkGraphIndexMap const_type
boost::graph_traits< vtkGraph * >::edges_size_type num_edges(vtkGraph *g)
vtkIdType vertices_size_type
boost::graph_traits< vtkMutableDirectedGraph * >::vertex_descriptor add_vertex(vtkMutableDirectedGraph *g)
vtkEdgeType edge_descriptor
boost::graph_traits< vtkDirectedGraph * >::degree_size_type in_degree(boost::graph_traits< vtkDirectedGraph * >::vertex_descriptor u, vtkDirectedGraph *g)
void remove_edge(graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *g)
readable_property_map_tag category
adjacency_iterator_generator< vtkGraph *, vertex_descriptor, out_edge_iterator >::type adjacency_iterator
vtksys_stl::pair< boost::graph_traits< vtkGraph * >::out_edge_iterator, boost::graph_traits< vtkGraph * >::out_edge_iterator > out_edges(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
undirected_tag directed_category
static vertex_descriptor null_vertex()
vtkIdType vertex_descriptor
allow_parallel_edge_tag edge_parallel_category
static edge_descriptor null_edge()
property_traits< PMap >::category category
friend class iterator_core_access
friend class iterator_core_access
void put(vtkDataArray *arr, vtkIdType key, const double &value)
bool has_no_edges(vtkGraph *g)
vtkGraphIndexMap const_type
property_traits< PMap >::value_type value_type
boost::graph_traits< vtkGraph * >::vertices_size_type num_vertices(vtkGraph *g)
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtk_in_edge_pointer_iterator(vtkGraph *g=0, vtkIdType v=0, bool end=false)
vtk_vertex_iterator(vtkIdType i=0)
vtk_edge_iterator(vtkGraph *g=0, vtkIdType v=0)
readable_property_map_tag category
vtk_vertex_iterator vertex_iterator
boost::graph_traits< vtkGraph * >::degree_size_type degree(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
vtksys_stl::pair< boost::graph_traits< vtkGraph * >::in_edge_iterator, boost::graph_traits< vtkGraph * >::in_edge_iterator > in_edges(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
friend class iterator_core_access
property_traits< PMap >::value_type value_type
boost::graph_traits< vtkGraph * >::degree_size_type out_degree(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)