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 -------------------------------------------------------------------------*/
29 #ifndef vtkBoostGraphAdapter_h
30 #define vtkBoostGraphAdapter_h
31 
32 #include "vtkAbstractArray.h"
33 #include "vtkDirectedGraph.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"
44 #include "vtkTree.h"
45 #include "vtkUndirectedGraph.h"
46 #include "vtkVariant.h"
47 
48 #include <boost/version.hpp>
49 
50 namespace boost {
51  //===========================================================================
52  // VTK arrays as property maps
53  // These need to be defined before including other boost stuff
54 
55  // Forward declarations are required here, so that we aren't forced
56  // to include boost/property_map.hpp.
57  template<typename> struct property_traits;
58  struct read_write_property_map_tag;
59 
60 #define vtkPropertyMapMacro(T, V) \
61  template <> \
62  struct property_traits<T*> \
63  { \
64  typedef V value_type; \
65  typedef V reference; \
66  typedef vtkIdType key_type; \
67  typedef read_write_property_map_tag category; \
68  }; \
69  \
70  inline property_traits<T*>::reference \
71  get( \
72  T* const & arr, \
73  property_traits<T*>::key_type key) \
74  { \
75  return arr->GetValue(key); \
76  } \
77  \
78  inline void \
79  put( \
80  T* arr, \
81  property_traits<T*>::key_type key, \
82  const property_traits<T*>::value_type & value) \
83  { \
84  arr->InsertValue(key, value); \
85  }
86 
91 
92  // vtkDataArray
93  template<>
95  {
96  typedef double value_type;
97  typedef double reference;
99  typedef read_write_property_map_tag category;
100  };
101 
102  inline double
103  get(vtkDataArray * const& arr, vtkIdType key)
104  {
105  return arr->GetTuple1(key);
106  }
107 
108  inline void
109  put(vtkDataArray *arr, vtkIdType key, const double& value)
110  {
111  arr->SetTuple1(key, value);
112  }
113 
114  // vtkAbstractArray as a property map of vtkVariants
115  template<>
117  {
121  typedef read_write_property_map_tag category;
122  };
123 
124  inline vtkVariant
125  get(vtkAbstractArray * const& arr, vtkIdType key)
126  {
127  return arr->GetVariantValue(key);
128  }
129 
130  inline void
132  {
133  arr->InsertVariantValue(key, value);
134  }
135 #if defined(_MSC_VER)
136  namespace detail {
139  }
140 #endif
141 }
142 
143 #include <utility> // STL Header
144 
145 #include <boost/config.hpp>
146 #include <boost/iterator/iterator_facade.hpp>
147 #include <boost/graph/graph_traits.hpp>
148 #include <boost/graph/properties.hpp>
149 #include <boost/graph/adjacency_iterator.hpp>
150 
151 // The functions and classes in this file allows the user to
152 // treat a vtkDirectedGraph or vtkUndirectedGraph object
153 // as a boost graph "as is".
154 
155 namespace boost {
156 
158  public iterator_facade<vtk_vertex_iterator,
159  vtkIdType,
160  bidirectional_traversal_tag,
161  vtkIdType,
162  vtkIdType>
163  {
164  public:
165  explicit vtk_vertex_iterator(vtkIdType i = 0) : index(i) {}
166 
167  private:
168  vtkIdType dereference() const { return index; }
169 
170  bool equal(const vtk_vertex_iterator& other) const
171  { return index == other.index; }
172 
173  void increment() { index++; }
174  void decrement() { index--; }
175 
176  vtkIdType index;
177 
178  friend class iterator_core_access;
179  };
180 
182  public iterator_facade<vtk_edge_iterator,
183  vtkEdgeType,
184  forward_traversal_tag,
185  vtkEdgeType,
186  vtkIdType>
187  {
188  public:
189  explicit vtk_edge_iterator(vtkGraph *g = 0, vtkIdType v = 0) :
190  directed(false), vertex(v), lastVertex(v), iter(0), end(0), graph(g)
191  {
192  if (graph)
193  {
194  lastVertex = graph->GetNumberOfVertices();
195  }
196 
197  vtkIdType myRank = -1;
199  = this->graph? this->graph->GetDistributedGraphHelper() : 0;
200  if (helper)
201  {
202  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
203  vertex = helper->MakeDistributedId(myRank, vertex);
204  lastVertex = helper->MakeDistributedId(myRank, lastVertex);
205  }
206 
207  if (graph != 0)
208  {
209  directed = (vtkDirectedGraph::SafeDownCast(graph) != 0);
210  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
211  {
212  ++vertex;
213  }
214 
215  if (vertex < lastVertex)
216  {
217  // Get the outgoing edges of the first vertex that has outgoing
218  // edges
219  vtkIdType nedges;
220  graph->GetOutEdges(vertex, iter, nedges);
221  end = iter + nedges;
222 
223  if (!directed)
224  {
225  while(iter != 0
226  && (// Skip non-local edges
227  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
228  // Skip entirely-local edges where Source > Target
229  || (((helper
230  && myRank == helper->GetVertexOwner(iter->Target))
231  || !helper)
232  && vertex > iter->Target)))
233  {
234  this->inc();
235  }
236  }
237  }
238  else
239  {
240  iter = 0;
241  }
242  }
243  }
244 
245  private:
246  vtkEdgeType dereference() const
247  { return vtkEdgeType(vertex, iter->Target, iter->Id); }
248 
249  bool equal(const vtk_edge_iterator& other) const
250  { return vertex == other.vertex && iter == other.iter; }
251 
252  void increment()
253  {
254  inc();
255  if (!directed)
256  {
257  vtkIdType myRank = -1;
259  = this->graph? this->graph->GetDistributedGraphHelper() : 0;
260  if (helper)
261  {
262  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
263  }
264 
265  while (iter != 0
266  && (// Skip non-local edges
267  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
268  // Skip entirely-local edges where Source > Target
269  || (((helper
270  && myRank == helper->GetVertexOwner(iter->Target))
271  || !helper)
272  && vertex > iter->Target)))
273  {
274  inc();
275  }
276  }
277  }
278 
279  void inc()
280  {
281  ++iter;
282  if (iter == end)
283  {
284  // Find a vertex with nonzero out degree.
285  ++vertex;
286  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
287  {
288  ++vertex;
289  }
290 
291  if (vertex < lastVertex)
292  {
293  vtkIdType nedges;
294  graph->GetOutEdges(vertex, iter, nedges);
295  end = iter + nedges;
296  }
297  else
298  {
299  iter = 0;
300  }
301  }
302  }
303 
304  bool directed;
305  vtkIdType vertex;
306  vtkIdType lastVertex;
307  const vtkOutEdgeType * iter;
308  const vtkOutEdgeType * end;
309  vtkGraph *graph;
310 
311  friend class iterator_core_access;
312  };
313 
315  public iterator_facade<vtk_out_edge_pointer_iterator,
316  vtkEdgeType,
317  bidirectional_traversal_tag,
318  vtkEdgeType,
319  ptrdiff_t>
320  {
321  public:
322  explicit vtk_out_edge_pointer_iterator(vtkGraph *g = 0, vtkIdType v = 0, bool end = false) :
323  vertex(v)
324  {
325  if (g)
326  {
327  vtkIdType nedges;
328  g->GetOutEdges(vertex, iter, nedges);
329  if (end)
330  {
331  iter += nedges;
332  }
333  }
334  }
335 
336  private:
337  vtkEdgeType dereference() const { return vtkEdgeType(vertex, iter->Target, iter->Id); }
338 
339  bool equal(const vtk_out_edge_pointer_iterator& other) const
340  { return iter == other.iter; }
341 
342  void increment() { iter++; }
343  void decrement() { iter--; }
344 
345  vtkIdType vertex;
346  const vtkOutEdgeType *iter;
347 
348  friend class iterator_core_access;
349  };
350 
352  public iterator_facade<vtk_in_edge_pointer_iterator,
353  vtkEdgeType,
354  bidirectional_traversal_tag,
355  vtkEdgeType,
356  ptrdiff_t>
357  {
358  public:
359  explicit vtk_in_edge_pointer_iterator(vtkGraph *g = 0, vtkIdType v = 0, bool end = false) :
360  vertex(v)
361  {
362  if (g)
363  {
364  vtkIdType nedges;
365  g->GetInEdges(vertex, iter, nedges);
366  if (end)
367  {
368  iter += nedges;
369  }
370  }
371  }
372 
373  private:
374  vtkEdgeType dereference() const { return vtkEdgeType(iter->Source, vertex, iter->Id); }
375 
376  bool equal(const vtk_in_edge_pointer_iterator& other) const
377  { return iter == other.iter; }
378 
379  void increment() { iter++; }
380  void decrement() { iter--; }
381 
382  vtkIdType vertex;
383  const vtkInEdgeType *iter;
384 
385  friend class iterator_core_access;
386  };
387 
388  //===========================================================================
389  // vtkGraph
390  // VertexAndEdgeListGraphConcept
391  // BidirectionalGraphConcept
392  // AdjacencyGraphConcept
393 
395  public virtual bidirectional_graph_tag,
396  public virtual edge_list_graph_tag,
397  public virtual vertex_list_graph_tag,
398  public virtual adjacency_graph_tag { };
399 
400  template <>
401  struct graph_traits<vtkGraph*> {
403  static vertex_descriptor null_vertex() { return -1; }
405  static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); }
408 
411 
412  typedef allow_parallel_edge_tag edge_parallel_category;
417 
418  typedef adjacency_iterator_generator<vtkGraph*,
419  vertex_descriptor, out_edge_iterator>::type adjacency_iterator;
420  };
421 
422 #if BOOST_VERSION >= 104500
423  template<>
424  struct graph_property_type< vtkGraph* > {
425  typedef no_property type;
426  };
427 #endif
428 
429  template<>
430  struct vertex_property_type< vtkGraph* > {
431  typedef no_property type;
432  };
433 
434  template<>
435  struct edge_property_type< vtkGraph* > {
436  typedef no_property type;
437  };
438 
439 #if BOOST_VERSION >= 104500
440  template<>
441  struct graph_bundle_type< vtkGraph* > {
442  typedef no_property type;
443  };
444 #endif
445 
446  template<>
447  struct vertex_bundle_type< vtkGraph* > {
448  typedef no_property type;
449  };
450 
451  template<>
452  struct edge_bundle_type< vtkGraph* > {
453  typedef no_property type;
454  };
455 
456  inline bool has_no_edges(vtkGraph* g)
457  {
458  return ((g->GetNumberOfEdges() > 0) ? false : true);
459  }
460 
462  vtkGraph* g)
463  {
465  {
467  }
469  {
471  }
472  }
473 
474  //===========================================================================
475  // vtkDirectedGraph
476 
477  template <>
479  {
480  typedef directed_tag directed_category;
481  };
482 
483  // The graph_traits for a const graph are the same as a non-const graph.
484  template <>
485  struct graph_traits<const vtkDirectedGraph*> : graph_traits<vtkDirectedGraph*> { };
486 
487  // The graph_traits for a const graph are the same as a non-const graph.
488  template <>
489  struct graph_traits<vtkDirectedGraph* const> : graph_traits<vtkDirectedGraph*> { };
490 
491 #if BOOST_VERSION >= 104500
492  // Internal graph properties
493  template<>
494  struct graph_property_type< vtkDirectedGraph* >
495  : graph_property_type< vtkGraph* > { };
496 
497  // Internal graph properties
498  template<>
499  struct graph_property_type< vtkDirectedGraph* const >
500  : graph_property_type< vtkGraph* > { };
501 #endif
502 
503  // Internal vertex properties
504  template<>
505  struct vertex_property_type< vtkDirectedGraph* >
507 
508  // Internal vertex properties
509  template<>
510  struct vertex_property_type< vtkDirectedGraph* const >
512 
513  // Internal edge properties
514  template<>
515  struct edge_property_type< vtkDirectedGraph* >
517 
518  // Internal edge properties
519  template<>
520  struct edge_property_type< vtkDirectedGraph* const >
522 
523 #if BOOST_VERSION >= 104500
524  // Internal graph properties
525  template<>
526  struct graph_bundle_type< vtkDirectedGraph* >
527  : graph_bundle_type< vtkGraph* > { };
528 
529  // Internal graph properties
530  template<>
531  struct graph_bundle_type< vtkDirectedGraph* const >
532  : graph_bundle_type< vtkGraph* > { };
533 #endif
534 
535  // Internal vertex properties
536  template<>
537  struct vertex_bundle_type< vtkDirectedGraph* >
539 
540  // Internal vertex properties
541  template<>
542  struct vertex_bundle_type< vtkDirectedGraph* const >
544 
545  // Internal edge properties
546  template<>
547  struct edge_bundle_type< vtkDirectedGraph* >
549 
550  // Internal edge properties
551  template<>
552  struct edge_bundle_type< vtkDirectedGraph* const >
554 
555  //===========================================================================
556  // vtkTree
557 
558  template <>
559  struct graph_traits<vtkTree*> : graph_traits<vtkDirectedGraph*> { };
560 
561  // The graph_traits for a const graph are the same as a non-const graph.
562  template <>
563  struct graph_traits<const vtkTree*> : graph_traits<vtkTree*> { };
564 
565  // The graph_traits for a const graph are the same as a non-const graph.
566  template <>
567  struct graph_traits<vtkTree* const> : graph_traits<vtkTree*> { };
568 
569  //===========================================================================
570  // vtkUndirectedGraph
571  template <>
573  {
574  typedef undirected_tag directed_category;
575  };
576 
577  // The graph_traits for a const graph are the same as a non-const graph.
578  template <>
579  struct graph_traits<const vtkUndirectedGraph*> : graph_traits<vtkUndirectedGraph*> { };
580 
581  // The graph_traits for a const graph are the same as a non-const graph.
582  template <>
583  struct graph_traits<vtkUndirectedGraph* const> : graph_traits<vtkUndirectedGraph*> { };
584 
585 #if BOOST_VERSION >= 104500
586  // Internal graph properties
587  template<>
588  struct graph_property_type< vtkUndirectedGraph* >
589  : graph_property_type< vtkGraph* > { };
590 
591  // Internal graph properties
592  template<>
593  struct graph_property_type< vtkUndirectedGraph* const >
594  : graph_property_type< vtkGraph* > { };
595 #endif
596 
597  // Internal vertex properties
598  template<>
599  struct vertex_property_type< vtkUndirectedGraph* >
601 
602  // Internal vertex properties
603  template<>
604  struct vertex_property_type< vtkUndirectedGraph* const >
606 
607  // Internal edge properties
608  template<>
609  struct edge_property_type< vtkUndirectedGraph* >
611 
612  // Internal edge properties
613  template<>
614  struct edge_property_type< vtkUndirectedGraph* const >
616 
617 #if BOOST_VERSION >= 104500
618  // Internal graph properties
619  template<>
620  struct graph_bundle_type< vtkUndirectedGraph* >
621  : graph_bundle_type< vtkGraph* > { };
622 
623  // Internal graph properties
624  template<>
625  struct graph_bundle_type< vtkUndirectedGraph* const >
626  : graph_bundle_type< vtkGraph* > { };
627 #endif
628 
629  // Internal vertex properties
630  template<>
631  struct vertex_bundle_type< vtkUndirectedGraph* >
633 
634  // Internal vertex properties
635  template<>
636  struct vertex_bundle_type< vtkUndirectedGraph* const >
638 
639  // Internal edge properties
640  template<>
641  struct edge_bundle_type< vtkUndirectedGraph* >
643 
644  // Internal edge properties
645  template<>
646  struct edge_bundle_type< vtkUndirectedGraph* const >
648 
649  //===========================================================================
650  // vtkMutableDirectedGraph
651 
652  template <>
654 
655  // The graph_traits for a const graph are the same as a non-const graph.
656  template <>
658 
659  // The graph_traits for a const graph are the same as a non-const graph.
660  template <>
662 
663 #if BOOST_VERSION >= 104500
664  // Internal graph properties
665  template<>
666  struct graph_property_type< vtkMutableDirectedGraph* >
667  : graph_property_type< vtkDirectedGraph* > { };
668 
669  // Internal graph properties
670  template<>
671  struct graph_property_type< vtkMutableDirectedGraph* const >
672  : graph_property_type< vtkDirectedGraph* > { };
673 #endif
674 
675  // Internal vertex properties
676  template<>
677  struct vertex_property_type< vtkMutableDirectedGraph* >
679 
680  // Internal vertex properties
681  template<>
682  struct vertex_property_type< vtkMutableDirectedGraph* const >
684 
685  // Internal edge properties
686  template<>
687  struct edge_property_type< vtkMutableDirectedGraph* >
689 
690  // Internal edge properties
691  template<>
692  struct edge_property_type< vtkMutableDirectedGraph* const >
694 
695 #if BOOST_VERSION >= 104500
696  // Internal graph properties
697  template<>
698  struct graph_bundle_type< vtkMutableDirectedGraph* >
699  : graph_bundle_type< vtkDirectedGraph* > { };
700 
701  // Internal graph properties
702  template<>
703  struct graph_bundle_type< vtkMutableDirectedGraph* const >
704  : graph_bundle_type< vtkDirectedGraph* > { };
705 #endif
706 
707  // Internal vertex properties
708  template<>
709  struct vertex_bundle_type< vtkMutableDirectedGraph* >
711 
712  // Internal vertex properties
713  template<>
714  struct vertex_bundle_type< vtkMutableDirectedGraph* const >
716 
717  // Internal edge properties
718  template<>
719  struct edge_bundle_type< vtkMutableDirectedGraph* >
721 
722  // Internal edge properties
723  template<>
724  struct edge_bundle_type< vtkMutableDirectedGraph* const >
726 
727  //===========================================================================
728  // vtkMutableUndirectedGraph
729 
730  template <>
732 
733  // The graph_traits for a const graph are the same as a non-const graph.
734  template <>
736 
737  // The graph_traits for a const graph are the same as a non-const graph.
738  template <>
740 
741 #if BOOST_VERSION >= 104500
742  // Internal graph properties
743  template<>
744  struct graph_property_type< vtkMutableUndirectedGraph* >
745  : graph_property_type< vtkUndirectedGraph* > { };
746 
747  // Internal graph properties
748  template<>
749  struct graph_property_type< vtkMutableUndirectedGraph* const >
750  : graph_property_type< vtkUndirectedGraph* > { };
751 #endif
752 
753  // Internal vertex properties
754  template<>
755  struct vertex_property_type< vtkMutableUndirectedGraph* >
757 
758  // Internal vertex properties
759  template<>
760  struct vertex_property_type< vtkMutableUndirectedGraph* const >
762 
763  // Internal edge properties
764  template<>
765  struct edge_property_type< vtkMutableUndirectedGraph* >
767 
768  // Internal edge properties
769  template<>
770  struct edge_property_type< vtkMutableUndirectedGraph* const >
772 
773 #if BOOST_VERSION >= 104500
774  // Internal graph properties
775  template<>
776  struct graph_bundle_type< vtkMutableUndirectedGraph* >
777  : graph_bundle_type< vtkUndirectedGraph* > { };
778 
779  // Internal graph properties
780  template<>
781  struct graph_bundle_type< vtkMutableUndirectedGraph* const >
782  : graph_bundle_type< vtkUndirectedGraph* > { };
783 #endif
784 
785  // Internal vertex properties
786  template<>
787  struct vertex_bundle_type< vtkMutableUndirectedGraph* >
789 
790  // Internal vertex properties
791  template<>
792  struct vertex_bundle_type< vtkMutableUndirectedGraph* const >
794 
795  // Internal edge properties
796  template<>
797  struct edge_bundle_type< vtkMutableUndirectedGraph* >
799 
800  // Internal edge properties
801  template<>
802  struct edge_bundle_type< vtkMutableUndirectedGraph* const >
804 
805  //===========================================================================
806  // API implementation
807  template <>
808  class vertex_property< vtkGraph* > {
809  public:
810  typedef vtkIdType type;
811  };
812 
813  template <>
814  class edge_property< vtkGraph* > {
815  public:
816  typedef vtkIdType type;
817  };
818 } // end namespace boost
819 
822  vtkGraph *)
823 {
824  return e.Source;
825 }
826 
829  vtkGraph *)
830 {
831  return e.Target;
832 }
833 
834 inline std::pair<
836  boost::graph_traits< vtkGraph* >::vertex_iterator >
838 {
839  typedef boost::graph_traits< vtkGraph* >::vertex_iterator Iter;
840  vtkIdType start = 0;
842  {
843  int rank =
845  start = helper->MakeDistributedId(rank, start);
846  }
847 
848  return std::make_pair( Iter(start),
849  Iter(start + g->GetNumberOfVertices()) );
850 }
851 
852 inline std::pair<
854  boost::graph_traits< vtkGraph* >::edge_iterator >
856 {
857  typedef boost::graph_traits< vtkGraph* >::edge_iterator Iter;
858  return std::make_pair( Iter(g), Iter(g, g->GetNumberOfVertices()) );
859 }
860 
861 inline std::pair<
863  boost::graph_traits< vtkGraph* >::out_edge_iterator >
866  vtkGraph *g)
867 {
868  typedef boost::graph_traits< vtkGraph* >::out_edge_iterator Iter;
869  std::pair<Iter, Iter> p = std::make_pair( Iter(g, u), Iter(g, u, true) );
870  return p;
871 }
872 
873 inline std::pair<
875  boost::graph_traits< vtkGraph* >::in_edge_iterator >
878  vtkGraph *g)
879 {
880  typedef boost::graph_traits< vtkGraph* >::in_edge_iterator Iter;
881  std::pair<Iter, Iter> p = std::make_pair( Iter(g, u), Iter(g, u, true) );
882  return p;
883 }
884 
885 inline std::pair<
887  boost::graph_traits< vtkGraph* >::adjacency_iterator >
890  vtkGraph *g)
891 {
892  typedef boost::graph_traits< vtkGraph* >::adjacency_iterator Iter;
893  typedef boost::graph_traits< vtkGraph* >::out_edge_iterator OutEdgeIter;
894  std::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g);
895  return std::make_pair( Iter(out.first, &g), Iter(out.second, &g) );
896 }
897 
900 {
901  return g->GetNumberOfVertices();
902 }
903 
906 {
907  return g->GetNumberOfEdges();
908 }
909 
913  vtkGraph *g)
914 {
915  return g->GetOutDegree(u);
916 }
917 
921  vtkDirectedGraph *g)
922 {
923  return g->GetInDegree(u);
924 }
925 
929  vtkGraph *g)
930 {
931  return g->GetDegree(u);
932 }
933 
936 {
937  return g->AddVertex();
938 }
939 
940 inline std::pair<
942  bool>
947 {
948  boost::graph_traits< vtkMutableDirectedGraph* >::edge_descriptor e = g->AddEdge(u, v);
949  return std::make_pair(e, true);
950 }
951 
954 {
955  return g->AddVertex();
956 }
957 
958 inline std::pair<
960  bool>
965 {
966  boost::graph_traits< vtkMutableUndirectedGraph* >::edge_descriptor e = g->AddEdge(u, v);
967  return std::make_pair(e, true);
968 }
969 
970 namespace boost {
971  //===========================================================================
972  // An edge map for vtkGraph.
973  // This is a common input needed for algorithms.
974 
975  struct vtkGraphEdgeMap { };
976 
977  template <>
979  {
983  typedef readable_property_map_tag category;
984  };
985 
987  get(
988  vtkGraphEdgeMap vtkNotUsed(arr),
990  {
991  return key.Id;
992  }
993 
994  //===========================================================================
995  // Helper for vtkGraph edge property maps
996  // Automatically converts boost edge ids to vtkGraph edge ids.
997 
998  template<typename PMap>
1000  {
1001  public:
1003  PMap pmap;
1008  };
1009 
1010  template<typename PMap>
1011  inline typename property_traits<PMap>::reference
1012  get(
1014  vtkEdgeType key)
1015  {
1016  return get(helper.pmap, key.Id);
1017  }
1018 
1019  template<typename PMap>
1020  inline void
1023  vtkEdgeType key,
1024  const typename property_traits<PMap>::value_type & value)
1025  {
1026  put(helper.pmap, key.Id, value);
1027  }
1028 
1029  //===========================================================================
1030  // An index map for vtkGraph
1031  // This is a common input needed for algorithms
1032 
1033  struct vtkGraphIndexMap { };
1034 
1035  template <>
1037  {
1041  typedef readable_property_map_tag category;
1042  };
1043 
1045  get(
1046  vtkGraphIndexMap vtkNotUsed(arr),
1048  {
1049  return key;
1050  }
1051 
1052  //===========================================================================
1053  // Helper for vtkGraph property maps
1054  // Automatically multiplies the property value by some value (default 1)
1055  template<typename PMap>
1057  {
1058  public:
1059  vtkGraphPropertyMapMultiplier(PMap m, float multi=1) : pmap(m),multiplier(multi){}
1060  PMap pmap;
1061  float multiplier;
1066  };
1067 
1068  template<typename PMap>
1069  inline typename property_traits<PMap>::reference
1070  get(
1072  const typename property_traits<PMap>::key_type key)
1073  {
1074  return multi.multiplier * get(multi.pmap, key);
1075  }
1076 
1077  template<typename PMap>
1078  inline void
1081  const typename property_traits<PMap>::key_type key,
1082  const typename property_traits<PMap>::value_type & value)
1083  {
1084  put(multi.pmap, key, value);
1085  }
1086 
1087  // Allow algorithms to automatically extract vtkGraphIndexMap from a
1088  // VTK graph
1089  template<>
1090  struct property_map<vtkGraph*, vertex_index_t>
1091  {
1094  };
1095 
1096  template<>
1097  struct property_map<vtkDirectedGraph*, vertex_index_t>
1099 
1100  template<>
1101  struct property_map<vtkUndirectedGraph*, vertex_index_t>
1103 
1104  inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*) { return vtkGraphIndexMap(); }
1105 
1106  template<>
1107  struct property_map<vtkGraph*, edge_index_t>
1108  {
1111  };
1112 
1113  template<>
1114  struct property_map<vtkDirectedGraph*, edge_index_t>
1116 
1117  template<>
1118  struct property_map<vtkUndirectedGraph*, edge_index_t>
1120 
1121  inline vtkGraphIndexMap get(edge_index_t, vtkGraph*) { return vtkGraphIndexMap(); }
1122 
1123  // property_map specializations for const-qualified graphs
1124  template<>
1125  struct property_map<vtkDirectedGraph* const, vertex_index_t>
1127 
1128  template<>
1129  struct property_map<vtkUndirectedGraph* const, vertex_index_t>
1131 
1132  template<>
1133  struct property_map<vtkDirectedGraph* const, edge_index_t>
1135 
1136  template<>
1137  struct property_map<vtkUndirectedGraph* const, edge_index_t>
1139 } // namespace boost
1140 
1141 #if BOOST_VERSION > 104000
1142 #include <boost/property_map/vector_property_map.hpp>
1143 #else
1144 #include <boost/vector_property_map.hpp>
1145 #endif
1146 
1147 
1148 #endif // vtkBoostGraphAdapter_h
1149 // VTK-HeaderTest-Exclude: vtkBoostGraphAdapter.h
static vtkDirectedGraph * SafeDownCast(vtkObjectBase *o)
virtual vtkIdType GetNumberOfEdges()
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)
void put(vtkGraphPropertyMapMultiplier< PMap > multi, const typename property_traits< PMap >::key_type key, const typename property_traits< PMap >::value_type &value)
virtual vtkInformation * GetInformation()
Forward declaration required for Boost serialization.
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
virtual vtkIdType GetNumberOfVertices()
virtual vtkVariant GetVariantValue(vtkIdType idx)
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)
void SetTuple1(vtkIdType i, double value)
vtkIdType GetEdgeOwner(vtkIdType e_id) const
vtkGraph_traversal_category traversal_category
vtk_in_edge_pointer_iterator in_edge_iterator
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:45
vtkIdType GetVertexOwner(vtkIdType v) const
An undirected graph.
dynamic, self-adjusting array of vtkIdType
virtual void InsertVariantValue(vtkIdType idx, vtkVariant value)=0
property_traits< PMap >::key_type key_type
int vtkIdType
Definition: vtkType.h:247
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:78
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:288
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:49
static vtkInformationIntegerKey * DATA_PIECE_NUMBER()
adjacency_iterator_generator< vtkGraph *, vertex_descriptor, out_edge_iterator >::type adjacency_iterator
vtkEdgeType AddEdge(vtkIdType u, vtkIdType v)
virtual vtkIdType GetDegree(vtkIdType 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:54
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
An editable undirected graph.
virtual vtkIdType GetInDegree(vtkIdType v)
vtkIdType Target
Definition: vtkGraph.h:264
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()
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtkIdType Source
Definition: vtkGraph.h:273
double GetTuple1(vtkIdType i)
vtk_in_edge_pointer_iterator(vtkGraph *g=0, vtkIdType v=0, bool end=false)
vtk_edge_iterator(vtkGraph *g=0, vtkIdType v=0)
boost::graph_traits< vtkGraph * >::degree_size_type degree(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
A rooted tree data structure.
Definition: vtkTree.h:59
virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator *it)
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)
VTKCOMMONCORE_EXPORT int Get(vtkInformationIntegerKey *key)
boost::graph_traits< vtkGraph * >::degree_size_type out_degree(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
void RemoveEdge(vtkIdType e)
vtkIdType MakeDistributedId(int owner, vtkIdType local)
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)
vtkGraphIndexMap get(edge_index_t, vtkGraph *)