VTK
vtkBoostGraphAdapter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkBoostGraphAdapter.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16  Copyright 2008 Sandia Corporation.
17  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18  the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
30 #ifndef vtkBoostGraphAdapter_h
31 #define vtkBoostGraphAdapter_h
32 
33 #include "vtkAbstractArray.h"
34 #include "vtkDirectedGraph.h"
36 #include "vtkDataObject.h"
37 #include "vtkDataArray.h"
38 #include "vtkDoubleArray.h"
39 #include "vtkFloatArray.h"
40 #include "vtkIdTypeArray.h"
41 #include "vtkInformation.h"
42 #include "vtkIntArray.h"
45 #include "vtkTree.h"
46 #include "vtkUndirectedGraph.h"
47 #include "vtkVariant.h"
48 
49 #include <boost/version.hpp>
50 
51 namespace boost {
52  //===========================================================================
53  // VTK arrays as property maps
54  // These need to be defined before including other boost stuff
55 
56  // Forward declarations are required here, so that we aren't forced
57  // to include boost/property_map.hpp.
58  template<typename> struct property_traits;
59  struct read_write_property_map_tag;
60 
61 #define vtkPropertyMapMacro(T, V) \
62  template <> \
63  struct property_traits<T*> \
64  { \
65  typedef V value_type; \
66  typedef V reference; \
67  typedef vtkIdType key_type; \
68  typedef read_write_property_map_tag category; \
69  }; \
70  \
71  inline property_traits<T*>::reference \
72  get( \
73  T* const & arr, \
74  property_traits<T*>::key_type key) \
75  { \
76  return arr->GetValue(key); \
77  } \
78  \
79  inline void \
80  put( \
81  T* arr, \
82  property_traits<T*>::key_type key, \
83  const property_traits<T*>::value_type & value) \
84  { \
85  arr->InsertValue(key, value); \
86  }
87 
92 
93  // vtkDataArray
94  template<>
96  {
97  typedef double value_type;
98  typedef double reference;
100  typedef read_write_property_map_tag category;
101  };
102 
103  inline double
104  get(vtkDataArray * const& arr, vtkIdType key)
105  {
106  return arr->GetTuple1(key);
107  }
108 
109  inline void
110  put(vtkDataArray *arr, vtkIdType key, const double& value)
111  {
112  arr->SetTuple1(key, value);
113  }
114 
115  // vtkAbstractArray as a property map of vtkVariants
116  template<>
118  {
122  typedef read_write_property_map_tag category;
123  };
124 
125  inline vtkVariant
126  get(vtkAbstractArray * const& arr, vtkIdType key)
127  {
128  return arr->GetVariantValue(key);
129  }
130 
131  inline void
133  {
134  arr->InsertVariantValue(key, value);
135  }
136 #if defined(_MSC_VER)
137  namespace detail {
140  }
141 #endif
142 }
143 
144 #include <utility> // STL Header
145 
146 #include <boost/config.hpp>
147 #include <boost/iterator/iterator_facade.hpp>
148 #include <boost/graph/graph_traits.hpp>
149 #include <boost/graph/properties.hpp>
150 #include <boost/graph/adjacency_iterator.hpp>
151 
152 // The functions and classes in this file allows the user to
153 // treat a vtkDirectedGraph or vtkUndirectedGraph object
154 // as a boost graph "as is".
155 
156 namespace boost {
157 
159  public iterator_facade<vtk_vertex_iterator,
160  vtkIdType,
161  bidirectional_traversal_tag,
162  vtkIdType,
163  vtkIdType>
164  {
165  public:
166  explicit vtk_vertex_iterator(vtkIdType i = 0) : index(i) {}
167 
168  private:
169  vtkIdType dereference() const { return index; }
170 
171  bool equal(const vtk_vertex_iterator& other) const
172  { return index == other.index; }
173 
174  void increment() { index++; }
175  void decrement() { index--; }
176 
178 
179  friend class iterator_core_access;
180  };
181 
183  public iterator_facade<vtk_edge_iterator,
184  vtkEdgeType,
185  forward_traversal_tag,
186  vtkEdgeType,
187  vtkIdType>
188  {
189  public:
190  explicit vtk_edge_iterator(vtkGraph *g = 0, vtkIdType v = 0) :
191  directed(false), vertex(v), lastVertex(v), iter(nullptr), end(nullptr), graph(g)
192  {
193  if (graph)
194  {
195  lastVertex = graph->GetNumberOfVertices();
196  }
197 
198  vtkIdType myRank = -1;
200  = this->graph? this->graph->GetDistributedGraphHelper() : 0;
201  if (helper)
202  {
203  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
204  vertex = helper->MakeDistributedId(myRank, vertex);
205  lastVertex = helper->MakeDistributedId(myRank, lastVertex);
206  }
207 
208  if (graph != 0)
209  {
210  directed = (vtkDirectedGraph::SafeDownCast(graph) != 0);
211  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
212  {
213  ++vertex;
214  }
215 
216  if (vertex < lastVertex)
217  {
218  // Get the outgoing edges of the first vertex that has outgoing
219  // edges
220  vtkIdType nedges;
221  graph->GetOutEdges(vertex, iter, nedges);
222  if (iter)
223  {
224  end = iter + nedges;
225 
226  if (!directed)
227  {
228  while(// Skip non-local edges
229  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
230  // Skip entirely-local edges where Source > Target
231  || (((helper
232  && myRank == helper->GetVertexOwner(iter->Target))
233  || !helper)
234  && vertex > iter->Target))
235  {
236  this->inc();
237  }
238  }
239  }
240  }
241  else
242  {
243  iter = nullptr;
244  }
245  }
246  }
247 
248  private:
249  vtkEdgeType dereference() const
250  { return vtkEdgeType(vertex, iter->Target, iter->Id); }
251 
252  bool equal(const vtk_edge_iterator& other) const
253  { return vertex == other.vertex && iter == other.iter; }
254 
255  void increment()
256  {
257  inc();
258  if (!directed)
259  {
260  vtkIdType myRank = -1;
262  = this->graph? this->graph->GetDistributedGraphHelper() : 0;
263  if (helper)
264  {
265  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
266  }
267 
268  while (iter != 0
269  && (// Skip non-local edges
270  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
271  // Skip entirely-local edges where Source > Target
272  || (((helper
273  && myRank == helper->GetVertexOwner(iter->Target))
274  || !helper)
275  && vertex > iter->Target)))
276  {
277  inc();
278  }
279  }
280  }
281 
282  void inc()
283  {
284  ++iter;
285  if (iter == end)
286  {
287  // Find a vertex with nonzero out degree.
288  ++vertex;
289  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
290  {
291  ++vertex;
292  }
293 
294  if (vertex < lastVertex)
295  {
296  vtkIdType nedges;
297  graph->GetOutEdges(vertex, iter, nedges);
298  end = iter + nedges;
299  }
300  else
301  {
302  iter = nullptr;
303  }
304  }
305  }
306 
307  bool directed;
308  vtkIdType vertex;
309  vtkIdType lastVertex;
310  const vtkOutEdgeType * iter;
311  const vtkOutEdgeType * end;
312  vtkGraph *graph;
313 
314  friend class iterator_core_access;
315  };
316 
318  public iterator_facade<vtk_out_edge_pointer_iterator,
319  vtkEdgeType,
320  bidirectional_traversal_tag,
321  vtkEdgeType,
322  ptrdiff_t>
323  {
324  public:
325  explicit vtk_out_edge_pointer_iterator(vtkGraph *g = 0, vtkIdType v = 0, bool end = false) :
326  vertex(v)
327  {
328  if (g)
329  {
330  vtkIdType nedges;
331  g->GetOutEdges(vertex, iter, nedges);
332  if (end)
333  {
334  iter += nedges;
335  }
336  }
337  }
338 
339  private:
340  vtkEdgeType dereference() const { return vtkEdgeType(vertex, iter->Target, iter->Id); }
341 
342  bool equal(const vtk_out_edge_pointer_iterator& other) const
343  { return iter == other.iter; }
344 
345  void increment() { iter++; }
346  void decrement() { iter--; }
347 
348  vtkIdType vertex;
349  const vtkOutEdgeType *iter;
350 
351  friend class iterator_core_access;
352  };
353 
355  public iterator_facade<vtk_in_edge_pointer_iterator,
356  vtkEdgeType,
357  bidirectional_traversal_tag,
358  vtkEdgeType,
359  ptrdiff_t>
360  {
361  public:
362  explicit vtk_in_edge_pointer_iterator(vtkGraph *g = 0, vtkIdType v = 0, bool end = false) :
363  vertex(v)
364  {
365  if (g)
366  {
367  vtkIdType nedges;
368  g->GetInEdges(vertex, iter, nedges);
369  if (end)
370  {
371  iter += nedges;
372  }
373  }
374  }
375 
376  private:
377  vtkEdgeType dereference() const { return vtkEdgeType(iter->Source, vertex, iter->Id); }
378 
379  bool equal(const vtk_in_edge_pointer_iterator& other) const
380  { return iter == other.iter; }
381 
382  void increment() { iter++; }
383  void decrement() { iter--; }
384 
385  vtkIdType vertex;
386  const vtkInEdgeType *iter;
387 
388  friend class iterator_core_access;
389  };
390 
391  //===========================================================================
392  // vtkGraph
393  // VertexAndEdgeListGraphConcept
394  // BidirectionalGraphConcept
395  // AdjacencyGraphConcept
396 
398  public virtual bidirectional_graph_tag,
399  public virtual edge_list_graph_tag,
400  public virtual vertex_list_graph_tag,
401  public virtual adjacency_graph_tag { };
402 
403  template <>
404  struct graph_traits<vtkGraph*> {
406  static vertex_descriptor null_vertex() { return -1; }
408  static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); }
411 
414 
415  typedef allow_parallel_edge_tag edge_parallel_category;
420 
421  typedef adjacency_iterator_generator<vtkGraph*,
422  vertex_descriptor, out_edge_iterator>::type adjacency_iterator;
423  };
424 
425 #if BOOST_VERSION >= 104500
426  template<>
427  struct graph_property_type< vtkGraph* > {
428  typedef no_property type;
429  };
430 #endif
431 
432  template<>
433  struct vertex_property_type< vtkGraph* > {
434  typedef no_property type;
435  };
436 
437  template<>
438  struct edge_property_type< vtkGraph* > {
439  typedef no_property type;
440  };
441 
442 #if BOOST_VERSION >= 104500
443  template<>
444  struct graph_bundle_type< vtkGraph* > {
445  typedef no_property type;
446  };
447 #endif
448 
449  template<>
450  struct vertex_bundle_type< vtkGraph* > {
451  typedef no_property type;
452  };
453 
454  template<>
455  struct edge_bundle_type< vtkGraph* > {
456  typedef no_property type;
457  };
458 
459  inline bool has_no_edges(vtkGraph* g)
460  {
461  return ((g->GetNumberOfEdges() > 0) ? false : true);
462  }
463 
465  vtkGraph* g)
466  {
468  {
470  }
472  {
474  }
475  }
476 
477  //===========================================================================
478  // vtkDirectedGraph
479 
480  template <>
482  {
483  typedef directed_tag directed_category;
484  };
485 
486  // The graph_traits for a const graph are the same as a non-const graph.
487  template <>
488  struct graph_traits<const vtkDirectedGraph*> : graph_traits<vtkDirectedGraph*> { };
489 
490  // The graph_traits for a const graph are the same as a non-const graph.
491  template <>
492  struct graph_traits<vtkDirectedGraph* const> : graph_traits<vtkDirectedGraph*> { };
493 
494 #if BOOST_VERSION >= 104500
495  // Internal graph properties
496  template<>
497  struct graph_property_type< vtkDirectedGraph* >
498  : graph_property_type< vtkGraph* > { };
499 
500  // Internal graph properties
501  template<>
502  struct graph_property_type< vtkDirectedGraph* const >
503  : graph_property_type< vtkGraph* > { };
504 #endif
505 
506  // Internal vertex properties
507  template<>
508  struct vertex_property_type< vtkDirectedGraph* >
510 
511  // Internal vertex properties
512  template<>
513  struct vertex_property_type< vtkDirectedGraph* const >
515 
516  // Internal edge properties
517  template<>
518  struct edge_property_type< vtkDirectedGraph* >
520 
521  // Internal edge properties
522  template<>
523  struct edge_property_type< vtkDirectedGraph* const >
525 
526 #if BOOST_VERSION >= 104500
527  // Internal graph properties
528  template<>
529  struct graph_bundle_type< vtkDirectedGraph* >
530  : graph_bundle_type< vtkGraph* > { };
531 
532  // Internal graph properties
533  template<>
534  struct graph_bundle_type< vtkDirectedGraph* const >
535  : graph_bundle_type< vtkGraph* > { };
536 #endif
537 
538  // Internal vertex properties
539  template<>
540  struct vertex_bundle_type< vtkDirectedGraph* >
542 
543  // Internal vertex properties
544  template<>
545  struct vertex_bundle_type< vtkDirectedGraph* const >
547 
548  // Internal edge properties
549  template<>
550  struct edge_bundle_type< vtkDirectedGraph* >
552 
553  // Internal edge properties
554  template<>
555  struct edge_bundle_type< vtkDirectedGraph* const >
557 
558  //===========================================================================
559  // vtkTree
560 
561  template <>
562  struct graph_traits<vtkTree*> : graph_traits<vtkDirectedGraph*> { };
563 
564  // The graph_traits for a const graph are the same as a non-const graph.
565  template <>
566  struct graph_traits<const vtkTree*> : graph_traits<vtkTree*> { };
567 
568  // The graph_traits for a const graph are the same as a non-const graph.
569  template <>
570  struct graph_traits<vtkTree* const> : graph_traits<vtkTree*> { };
571 
572  //===========================================================================
573  // vtkUndirectedGraph
574  template <>
576  {
577  typedef undirected_tag directed_category;
578  };
579 
580  // The graph_traits for a const graph are the same as a non-const graph.
581  template <>
582  struct graph_traits<const vtkUndirectedGraph*> : graph_traits<vtkUndirectedGraph*> { };
583 
584  // The graph_traits for a const graph are the same as a non-const graph.
585  template <>
586  struct graph_traits<vtkUndirectedGraph* const> : graph_traits<vtkUndirectedGraph*> { };
587 
588 #if BOOST_VERSION >= 104500
589  // Internal graph properties
590  template<>
591  struct graph_property_type< vtkUndirectedGraph* >
592  : graph_property_type< vtkGraph* > { };
593 
594  // Internal graph properties
595  template<>
596  struct graph_property_type< vtkUndirectedGraph* const >
597  : graph_property_type< vtkGraph* > { };
598 #endif
599 
600  // Internal vertex properties
601  template<>
602  struct vertex_property_type< vtkUndirectedGraph* >
604 
605  // Internal vertex properties
606  template<>
607  struct vertex_property_type< vtkUndirectedGraph* const >
609 
610  // Internal edge properties
611  template<>
612  struct edge_property_type< vtkUndirectedGraph* >
614 
615  // Internal edge properties
616  template<>
617  struct edge_property_type< vtkUndirectedGraph* const >
619 
620 #if BOOST_VERSION >= 104500
621  // Internal graph properties
622  template<>
623  struct graph_bundle_type< vtkUndirectedGraph* >
624  : graph_bundle_type< vtkGraph* > { };
625 
626  // Internal graph properties
627  template<>
628  struct graph_bundle_type< vtkUndirectedGraph* const >
629  : graph_bundle_type< vtkGraph* > { };
630 #endif
631 
632  // Internal vertex properties
633  template<>
634  struct vertex_bundle_type< vtkUndirectedGraph* >
636 
637  // Internal vertex properties
638  template<>
639  struct vertex_bundle_type< vtkUndirectedGraph* const >
641 
642  // Internal edge properties
643  template<>
644  struct edge_bundle_type< vtkUndirectedGraph* >
646 
647  // Internal edge properties
648  template<>
649  struct edge_bundle_type< vtkUndirectedGraph* const >
651 
652  //===========================================================================
653  // vtkMutableDirectedGraph
654 
655  template <>
657 
658  // The graph_traits for a const graph are the same as a non-const graph.
659  template <>
661 
662  // The graph_traits for a const graph are the same as a non-const graph.
663  template <>
665 
666 #if BOOST_VERSION >= 104500
667  // Internal graph properties
668  template<>
669  struct graph_property_type< vtkMutableDirectedGraph* >
670  : graph_property_type< vtkDirectedGraph* > { };
671 
672  // Internal graph properties
673  template<>
674  struct graph_property_type< vtkMutableDirectedGraph* const >
675  : graph_property_type< vtkDirectedGraph* > { };
676 #endif
677 
678  // Internal vertex properties
679  template<>
680  struct vertex_property_type< vtkMutableDirectedGraph* >
682 
683  // Internal vertex properties
684  template<>
685  struct vertex_property_type< vtkMutableDirectedGraph* const >
687 
688  // Internal edge properties
689  template<>
690  struct edge_property_type< vtkMutableDirectedGraph* >
692 
693  // Internal edge properties
694  template<>
695  struct edge_property_type< vtkMutableDirectedGraph* const >
697 
698 #if BOOST_VERSION >= 104500
699  // Internal graph properties
700  template<>
701  struct graph_bundle_type< vtkMutableDirectedGraph* >
702  : graph_bundle_type< vtkDirectedGraph* > { };
703 
704  // Internal graph properties
705  template<>
706  struct graph_bundle_type< vtkMutableDirectedGraph* const >
707  : graph_bundle_type< vtkDirectedGraph* > { };
708 #endif
709 
710  // Internal vertex properties
711  template<>
712  struct vertex_bundle_type< vtkMutableDirectedGraph* >
714 
715  // Internal vertex properties
716  template<>
717  struct vertex_bundle_type< vtkMutableDirectedGraph* const >
719 
720  // Internal edge properties
721  template<>
722  struct edge_bundle_type< vtkMutableDirectedGraph* >
724 
725  // Internal edge properties
726  template<>
727  struct edge_bundle_type< vtkMutableDirectedGraph* const >
729 
730  //===========================================================================
731  // vtkMutableUndirectedGraph
732 
733  template <>
735 
736  // The graph_traits for a const graph are the same as a non-const graph.
737  template <>
739 
740  // The graph_traits for a const graph are the same as a non-const graph.
741  template <>
743 
744 #if BOOST_VERSION >= 104500
745  // Internal graph properties
746  template<>
747  struct graph_property_type< vtkMutableUndirectedGraph* >
748  : graph_property_type< vtkUndirectedGraph* > { };
749 
750  // Internal graph properties
751  template<>
752  struct graph_property_type< vtkMutableUndirectedGraph* const >
753  : graph_property_type< vtkUndirectedGraph* > { };
754 #endif
755 
756  // Internal vertex properties
757  template<>
758  struct vertex_property_type< vtkMutableUndirectedGraph* >
760 
761  // Internal vertex properties
762  template<>
763  struct vertex_property_type< vtkMutableUndirectedGraph* const >
765 
766  // Internal edge properties
767  template<>
768  struct edge_property_type< vtkMutableUndirectedGraph* >
770 
771  // Internal edge properties
772  template<>
773  struct edge_property_type< vtkMutableUndirectedGraph* const >
775 
776 #if BOOST_VERSION >= 104500
777  // Internal graph properties
778  template<>
779  struct graph_bundle_type< vtkMutableUndirectedGraph* >
780  : graph_bundle_type< vtkUndirectedGraph* > { };
781 
782  // Internal graph properties
783  template<>
784  struct graph_bundle_type< vtkMutableUndirectedGraph* const >
785  : graph_bundle_type< vtkUndirectedGraph* > { };
786 #endif
787 
788  // Internal vertex properties
789  template<>
790  struct vertex_bundle_type< vtkMutableUndirectedGraph* >
792 
793  // Internal vertex properties
794  template<>
795  struct vertex_bundle_type< vtkMutableUndirectedGraph* const >
797 
798  // Internal edge properties
799  template<>
800  struct edge_bundle_type< vtkMutableUndirectedGraph* >
802 
803  // Internal edge properties
804  template<>
805  struct edge_bundle_type< vtkMutableUndirectedGraph* const >
807 
808  //===========================================================================
809  // API implementation
810  template <>
811  class vertex_property< vtkGraph* > {
812  public:
813  typedef vtkIdType type;
814  };
815 
816  template <>
817  class edge_property< vtkGraph* > {
818  public:
819  typedef vtkIdType type;
820  };
821 } // end namespace boost
822 
825  vtkGraph *)
826 {
827  return e.Source;
828 }
829 
832  vtkGraph *)
833 {
834  return e.Target;
835 }
836 
837 inline std::pair<
841 {
843  vtkIdType start = 0;
845  {
846  int rank =
848  start = helper->MakeDistributedId(rank, start);
849  }
850 
851  return std::make_pair( Iter(start),
852  Iter(start + g->GetNumberOfVertices()) );
853 }
854 
855 inline std::pair<
859 {
861  return std::make_pair( Iter(g), Iter(g, g->GetNumberOfVertices()) );
862 }
863 
864 inline std::pair<
869  vtkGraph *g)
870 {
872  std::pair<Iter, Iter> p = std::make_pair( Iter(g, u), Iter(g, u, true) );
873  return p;
874 }
875 
876 inline std::pair<
881  vtkGraph *g)
882 {
884  std::pair<Iter, Iter> p = std::make_pair( Iter(g, u), Iter(g, u, true) );
885  return p;
886 }
887 
888 inline std::pair<
893  vtkGraph *g)
894 {
897  std::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g);
898  return std::make_pair( Iter(out.first, &g), Iter(out.second, &g) );
899 }
900 
903 {
904  return g->GetNumberOfVertices();
905 }
906 
909 {
910  return g->GetNumberOfEdges();
911 }
912 
916  vtkGraph *g)
917 {
918  return g->GetOutDegree(u);
919 }
920 
924  vtkDirectedGraph *g)
925 {
926  return g->GetInDegree(u);
927 }
928 
932  vtkGraph *g)
933 {
934  return g->GetDegree(u);
935 }
936 
939 {
940  return g->AddVertex();
941 }
942 
943 inline std::pair<
945  bool>
950 {
952  return std::make_pair(e, true);
953 }
954 
957 {
958  return g->AddVertex();
959 }
960 
961 inline std::pair<
963  bool>
968 {
970  return std::make_pair(e, true);
971 }
972 
973 namespace boost {
974  //===========================================================================
975  // An edge map for vtkGraph.
976  // This is a common input needed for algorithms.
977 
978  struct vtkGraphEdgeMap { };
979 
980  template <>
982  {
986  typedef readable_property_map_tag category;
987  };
988 
990  get(
991  vtkGraphEdgeMap vtkNotUsed(arr),
993  {
994  return key.Id;
995  }
996 
997  //===========================================================================
998  // Helper for vtkGraph edge property maps
999  // Automatically converts boost edge ids to vtkGraph edge ids.
1000 
1001  template<typename PMap>
1003  {
1004  public:
1005  vtkGraphEdgePropertyMapHelper(PMap m) : pmap(m) { }
1006  PMap pmap;
1011 
1012  reference operator[] (const key_type& key) const
1013  {
1014  return get(pmap, key.Id);
1015  }
1016  };
1017 
1018  template<typename PMap>
1019  inline typename property_traits<PMap>::reference
1020  get(
1022  vtkEdgeType key)
1023  {
1024  return get(helper.pmap, key.Id);
1025  }
1026 
1027  template<typename PMap>
1028  inline void
1031  vtkEdgeType key,
1032  const typename property_traits<PMap>::value_type & value)
1033  {
1034  put(helper.pmap, key.Id, value);
1035  }
1036 
1037  //===========================================================================
1038  // Helper for vtkGraph vertex property maps
1039  // Automatically converts boost vertex ids to vtkGraph vertex ids.
1040 
1041  template<typename PMap>
1043  {
1044  public:
1045  vtkGraphVertexPropertyMapHelper(PMap m) : pmap(m) { }
1046  PMap pmap;
1051 
1052  reference operator[] (const key_type& key) const
1053  {
1054  return get(pmap, key);
1055  }
1056  };
1057 
1058  template<typename PMap>
1059  inline typename property_traits<PMap>::reference
1060  get(
1062  vtkIdType key)
1063  {
1064  return get(helper.pmap, key);
1065  }
1066 
1067  template<typename PMap>
1068  inline void
1071  vtkIdType key,
1072  const typename property_traits<PMap>::value_type & value)
1073  {
1074  put(helper.pmap, key, value);
1075  }
1076 
1077  //===========================================================================
1078  // An index map for vtkGraph
1079  // This is a common input needed for algorithms
1080 
1081  struct vtkGraphIndexMap { };
1082 
1083  template <>
1085  {
1089  typedef readable_property_map_tag category;
1090  };
1091 
1093  get(
1094  vtkGraphIndexMap vtkNotUsed(arr),
1096  {
1097  return key;
1098  }
1099 
1100  //===========================================================================
1101  // Helper for vtkGraph property maps
1102  // Automatically multiplies the property value by some value (default 1)
1103  template<typename PMap>
1105  {
1106  public:
1107  vtkGraphPropertyMapMultiplier(PMap m, float multi=1) : pmap(m),multiplier(multi){}
1108  PMap pmap;
1109  float multiplier;
1114  };
1115 
1116  template<typename PMap>
1117  inline typename property_traits<PMap>::reference
1118  get(
1120  const typename property_traits<PMap>::key_type & key)
1121  {
1122  return multi.multiplier * get(multi.pmap, key);
1123  }
1124 
1125  template<typename PMap>
1126  inline void
1129  const typename property_traits<PMap>::key_type & key,
1130  const typename property_traits<PMap>::value_type & value)
1131  {
1132  put(multi.pmap, key, value);
1133  }
1134 
1135  // Allow algorithms to automatically extract vtkGraphIndexMap from a
1136  // VTK graph
1137  template<>
1138  struct property_map<vtkGraph*, vertex_index_t>
1139  {
1142  };
1143 
1144  template<>
1145  struct property_map<vtkDirectedGraph*, vertex_index_t>
1147 
1148  template<>
1149  struct property_map<vtkUndirectedGraph*, vertex_index_t>
1151 
1152  inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*) { return vtkGraphIndexMap(); }
1153 
1154  template<>
1155  struct property_map<vtkGraph*, edge_index_t>
1156  {
1159  };
1160 
1161  template<>
1162  struct property_map<vtkDirectedGraph*, edge_index_t>
1164 
1165  template<>
1166  struct property_map<vtkUndirectedGraph*, edge_index_t>
1168 
1169  inline vtkGraphIndexMap get(edge_index_t, vtkGraph*) { return vtkGraphIndexMap(); }
1170 
1171  // property_map specializations for const-qualified graphs
1172  template<>
1173  struct property_map<vtkDirectedGraph* const, vertex_index_t>
1175 
1176  template<>
1177  struct property_map<vtkUndirectedGraph* const, vertex_index_t>
1179 
1180  template<>
1181  struct property_map<vtkDirectedGraph* const, edge_index_t>
1183 
1184  template<>
1185  struct property_map<vtkUndirectedGraph* const, edge_index_t>
1187 } // namespace boost
1188 
1189 #if BOOST_VERSION > 104000
1190 #include <boost/property_map/vector_property_map.hpp>
1191 #else
1192 #include <boost/vector_property_map.hpp>
1193 #endif
1194 
1195 
1196 #endif // vtkBoostGraphAdapter_h
1197 // VTK-HeaderTest-Exclude: vtkBoostGraphAdapter.h
static vtkDirectedGraph * SafeDownCast(vtkObjectBase *o)
virtual vtkIdType GetNumberOfEdges()
The number of edges in the graph.
helper for the vtkGraph class that allows the graph to be distributed across multiple memory spaces...
property_traits< PMap >::reference reference
property_traits< PMap >::category category
vtk_out_edge_pointer_iterator(vtkGraph *g=0, vtkIdType v=0, bool end=false)
vtkEdgeType AddEdge(vtkIdType u, vtkIdType v)
Adds a directed edge from u to v, where u and v are vertex indices, and returns a vtkEdgeType structu...
virtual vtkInformation * GetInformation()
Set/Get the information object associated with this data object.
void put(vtkGraphPropertyMapMultiplier< PMap > multi, const typename property_traits< PMap >::key_type &key, const typename property_traits< PMap >::value_type &value)
double GetTuple1(vtkIdType tupleIdx)
These methods are included as convenience for the wrappers.
vtkIdType AddVertex()
Adds a vertex to the graph and returns the index of the new vertex.
Forward declaration required for Boost serialization.
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
virtual vtkIdType GetNumberOfVertices()
The number of vertices in the graph.
vtk_out_edge_pointer_iterator out_edge_iterator
property_traits< PMap >::reference reference
vtkPropertyMapMacro(vtkIntArray, int) vtkPropertyMapMacro(vtkIdTypeArray
Abstract superclass for all arrays.
vtkGraphPropertyMapMultiplier(PMap m, float multi=1)
property_traits< PMap >::category category
vtkIdType GetEdgeOwner(vtkIdType e_id) const
Returns owner of edge with ID e_id, by extracting top ceil(log2 P) bits of e_id.
vtkGraph_traversal_category traversal_category
vtk_in_edge_pointer_iterator in_edge_iterator
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:41
vtkIdType GetVertexOwner(vtkIdType v) const
Returns owner of vertex v, by extracting top ceil(log2 P) bits of v.
An undirected graph.
dynamic, self-adjusting array of vtkIdType
property_traits< PMap >::key_type key_type
int vtkIdType
Definition: vtkType.h:349
virtual vtkVariant GetVariantValue(vtkIdType valueIdx)
Retrieve value from the array as a variant.
property_traits< PMap >::reference reference
boost::graph_traits< vtkGraph * >::edges_size_type num_edges(vtkGraph *g)
boost::graph_traits< vtkMutableDirectedGraph * >::vertex_descriptor add_vertex(vtkMutableDirectedGraph *g)
A atomic type representing the union of many types.
Definition: vtkVariant.h:71
boost::graph_traits< vtkDirectedGraph * >::degree_size_type in_degree(boost::graph_traits< vtkDirectedGraph * >::vertex_descriptor u, vtkDirectedGraph *g)
dynamic, self-adjusting array of double
void remove_edge(graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *g)
A directed graph.
Base class for graph data types.
Definition: vtkGraph.h:287
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:45
static vtkInformationIntegerKey * DATA_PIECE_NUMBER()
adjacency_iterator_generator< vtkGraph *, vertex_descriptor, out_edge_iterator >::type adjacency_iterator
vtkEdgeType AddEdge(vtkIdType u, vtkIdType v)
Adds an undirected edge from u to v, where u and v are vertex indices, and returns a vtkEdgeType stru...
virtual vtkIdType GetDegree(vtkIdType v)
The total of all incoming and outgoing vertices for vertex v.
static vertex_descriptor null_vertex()
allow_parallel_edge_tag edge_parallel_category
property_traits< PMap >::category category
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
std::pair< boost::graph_traits< vtkGraph * >::vertex_iterator, boost::graph_traits< vtkGraph * >::vertex_iterator > vertices(vtkGraph *g)
void put(vtkDataArray *arr, vtkIdType key, const double &value)
An editable directed graph.
bool has_no_edges(vtkGraph *g)
vtkIdType Id
Definition: vtkGraph.h:255
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Insert a value into the array from a variant.
void SetTuple1(vtkIdType tupleIdx, double value)
These methods are included as convenience for the wrappers.
An editable undirected graph.
virtual vtkIdType GetInDegree(vtkIdType v)
The number of incoming edges to vertex v.
property_traits< PMap >::value_type value_type
boost::graph_traits< vtkGraph * >::vertices_size_type num_vertices(vtkGraph *g)
static vtkMutableDirectedGraph * SafeDownCast(vtkObjectBase *o)
vtkDistributedGraphHelper * GetDistributedGraphHelper()
Retrieves the distributed graph helper for this graph.
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_edge_iterator(vtkGraph *g=0, vtkIdType v=0)
property_traits< PMap >::value_type value_type
boost::graph_traits< vtkGraph * >::degree_size_type degree(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
vtkIdType AddVertex()
Adds a vertex to the graph and returns the index of the new vertex.
A rooted tree data structure.
Definition: vtkTree.h:60
std::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 >::value_type value_type
std::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)
std::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)
void RemoveEdge(vtkIdType e)
Removes the edge from the graph.
VTKCOMMONCORE_EXPORT int Get(vtkInformationIntegerKey *key)
Get/Set an integer-valued entry.
boost::graph_traits< vtkGraph * >::degree_size_type out_degree(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
void RemoveEdge(vtkIdType e)
Removes the edge from the graph.
vtkIdType MakeDistributedId(int owner, vtkIdType local)
Builds a distributed ID consisting of the given owner and the local ID.
static vtkMutableUndirectedGraph * SafeDownCast(vtkObjectBase *o)
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
std::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)
virtual vtkIdType GetOutDegree(vtkIdType v)
The number of outgoing edges from vertex v.
vtkGraphIndexMap get(edge_index_t, vtkGraph *)