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(iter != 0
229  && (// Skip non-local edges
230  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
231  // Skip entirely-local edges where Source > Target
232  || (((helper
233  && myRank == helper->GetVertexOwner(iter->Target))
234  || !helper)
235  && vertex > iter->Target)))
236  {
237  this->inc();
238  }
239  }
240  }
241  }
242  else
243  {
244  iter = 0;
245  }
246  }
247  }
248 
249  private:
250  vtkEdgeType dereference() const
251  { return vtkEdgeType(vertex, iter->Target, iter->Id); }
252 
253  bool equal(const vtk_edge_iterator& other) const
254  { return vertex == other.vertex && iter == other.iter; }
255 
256  void increment()
257  {
258  inc();
259  if (!directed)
260  {
261  vtkIdType myRank = -1;
263  = this->graph? this->graph->GetDistributedGraphHelper() : 0;
264  if (helper)
265  {
266  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
267  }
268 
269  while (iter != 0
270  && (// Skip non-local edges
271  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
272  // Skip entirely-local edges where Source > Target
273  || (((helper
274  && myRank == helper->GetVertexOwner(iter->Target))
275  || !helper)
276  && vertex > iter->Target)))
277  {
278  inc();
279  }
280  }
281  }
282 
283  void inc()
284  {
285  ++iter;
286  if (iter == end)
287  {
288  // Find a vertex with nonzero out degree.
289  ++vertex;
290  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
291  {
292  ++vertex;
293  }
294 
295  if (vertex < lastVertex)
296  {
297  vtkIdType nedges;
298  graph->GetOutEdges(vertex, iter, nedges);
299  end = iter + nedges;
300  }
301  else
302  {
303  iter = 0;
304  }
305  }
306  }
307 
308  bool directed;
309  vtkIdType vertex;
310  vtkIdType lastVertex;
311  const vtkOutEdgeType * iter;
312  const vtkOutEdgeType * end;
313  vtkGraph *graph;
314 
315  friend class iterator_core_access;
316  };
317 
319  public iterator_facade<vtk_out_edge_pointer_iterator,
320  vtkEdgeType,
321  bidirectional_traversal_tag,
322  vtkEdgeType,
323  ptrdiff_t>
324  {
325  public:
326  explicit vtk_out_edge_pointer_iterator(vtkGraph *g = 0, vtkIdType v = 0, bool end = false) :
327  vertex(v)
328  {
329  if (g)
330  {
331  vtkIdType nedges;
332  g->GetOutEdges(vertex, iter, nedges);
333  if (end)
334  {
335  iter += nedges;
336  }
337  }
338  }
339 
340  private:
341  vtkEdgeType dereference() const { return vtkEdgeType(vertex, iter->Target, iter->Id); }
342 
343  bool equal(const vtk_out_edge_pointer_iterator& other) const
344  { return iter == other.iter; }
345 
346  void increment() { iter++; }
347  void decrement() { iter--; }
348 
349  vtkIdType vertex;
350  const vtkOutEdgeType *iter;
351 
352  friend class iterator_core_access;
353  };
354 
356  public iterator_facade<vtk_in_edge_pointer_iterator,
357  vtkEdgeType,
358  bidirectional_traversal_tag,
359  vtkEdgeType,
360  ptrdiff_t>
361  {
362  public:
363  explicit vtk_in_edge_pointer_iterator(vtkGraph *g = 0, vtkIdType v = 0, bool end = false) :
364  vertex(v)
365  {
366  if (g)
367  {
368  vtkIdType nedges;
369  g->GetInEdges(vertex, iter, nedges);
370  if (end)
371  {
372  iter += nedges;
373  }
374  }
375  }
376 
377  private:
378  vtkEdgeType dereference() const { return vtkEdgeType(iter->Source, vertex, iter->Id); }
379 
380  bool equal(const vtk_in_edge_pointer_iterator& other) const
381  { return iter == other.iter; }
382 
383  void increment() { iter++; }
384  void decrement() { iter--; }
385 
386  vtkIdType vertex;
387  const vtkInEdgeType *iter;
388 
389  friend class iterator_core_access;
390  };
391 
392  //===========================================================================
393  // vtkGraph
394  // VertexAndEdgeListGraphConcept
395  // BidirectionalGraphConcept
396  // AdjacencyGraphConcept
397 
399  public virtual bidirectional_graph_tag,
400  public virtual edge_list_graph_tag,
401  public virtual vertex_list_graph_tag,
402  public virtual adjacency_graph_tag { };
403 
404  template <>
405  struct graph_traits<vtkGraph*> {
407  static vertex_descriptor null_vertex() { return -1; }
409  static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); }
412 
415 
416  typedef allow_parallel_edge_tag edge_parallel_category;
421 
422  typedef adjacency_iterator_generator<vtkGraph*,
423  vertex_descriptor, out_edge_iterator>::type adjacency_iterator;
424  };
425 
426 #if BOOST_VERSION >= 104500
427  template<>
428  struct graph_property_type< vtkGraph* > {
429  typedef no_property type;
430  };
431 #endif
432 
433  template<>
434  struct vertex_property_type< vtkGraph* > {
435  typedef no_property type;
436  };
437 
438  template<>
439  struct edge_property_type< vtkGraph* > {
440  typedef no_property type;
441  };
442 
443 #if BOOST_VERSION >= 104500
444  template<>
445  struct graph_bundle_type< vtkGraph* > {
446  typedef no_property type;
447  };
448 #endif
449 
450  template<>
451  struct vertex_bundle_type< vtkGraph* > {
452  typedef no_property type;
453  };
454 
455  template<>
456  struct edge_bundle_type< vtkGraph* > {
457  typedef no_property type;
458  };
459 
460  inline bool has_no_edges(vtkGraph* g)
461  {
462  return ((g->GetNumberOfEdges() > 0) ? false : true);
463  }
464 
466  vtkGraph* g)
467  {
469  {
471  }
473  {
475  }
476  }
477 
478  //===========================================================================
479  // vtkDirectedGraph
480 
481  template <>
483  {
484  typedef directed_tag directed_category;
485  };
486 
487  // The graph_traits for a const graph are the same as a non-const graph.
488  template <>
489  struct graph_traits<const vtkDirectedGraph*> : graph_traits<vtkDirectedGraph*> { };
490 
491  // The graph_traits for a const graph are the same as a non-const graph.
492  template <>
493  struct graph_traits<vtkDirectedGraph* const> : graph_traits<vtkDirectedGraph*> { };
494 
495 #if BOOST_VERSION >= 104500
496  // Internal graph properties
497  template<>
498  struct graph_property_type< vtkDirectedGraph* >
499  : graph_property_type< vtkGraph* > { };
500 
501  // Internal graph properties
502  template<>
503  struct graph_property_type< vtkDirectedGraph* const >
504  : graph_property_type< vtkGraph* > { };
505 #endif
506 
507  // Internal vertex properties
508  template<>
509  struct vertex_property_type< vtkDirectedGraph* >
511 
512  // Internal vertex properties
513  template<>
514  struct vertex_property_type< vtkDirectedGraph* const >
516 
517  // Internal edge properties
518  template<>
519  struct edge_property_type< vtkDirectedGraph* >
521 
522  // Internal edge properties
523  template<>
524  struct edge_property_type< vtkDirectedGraph* const >
526 
527 #if BOOST_VERSION >= 104500
528  // Internal graph properties
529  template<>
530  struct graph_bundle_type< vtkDirectedGraph* >
531  : graph_bundle_type< vtkGraph* > { };
532 
533  // Internal graph properties
534  template<>
535  struct graph_bundle_type< vtkDirectedGraph* const >
536  : graph_bundle_type< vtkGraph* > { };
537 #endif
538 
539  // Internal vertex properties
540  template<>
541  struct vertex_bundle_type< vtkDirectedGraph* >
543 
544  // Internal vertex properties
545  template<>
546  struct vertex_bundle_type< vtkDirectedGraph* const >
548 
549  // Internal edge properties
550  template<>
551  struct edge_bundle_type< vtkDirectedGraph* >
553 
554  // Internal edge properties
555  template<>
556  struct edge_bundle_type< vtkDirectedGraph* const >
558 
559  //===========================================================================
560  // vtkTree
561 
562  template <>
563  struct graph_traits<vtkTree*> : graph_traits<vtkDirectedGraph*> { };
564 
565  // The graph_traits for a const graph are the same as a non-const graph.
566  template <>
567  struct graph_traits<const vtkTree*> : graph_traits<vtkTree*> { };
568 
569  // The graph_traits for a const graph are the same as a non-const graph.
570  template <>
571  struct graph_traits<vtkTree* const> : graph_traits<vtkTree*> { };
572 
573  //===========================================================================
574  // vtkUndirectedGraph
575  template <>
577  {
578  typedef undirected_tag directed_category;
579  };
580 
581  // The graph_traits for a const graph are the same as a non-const graph.
582  template <>
583  struct graph_traits<const vtkUndirectedGraph*> : graph_traits<vtkUndirectedGraph*> { };
584 
585  // The graph_traits for a const graph are the same as a non-const graph.
586  template <>
587  struct graph_traits<vtkUndirectedGraph* const> : graph_traits<vtkUndirectedGraph*> { };
588 
589 #if BOOST_VERSION >= 104500
590  // Internal graph properties
591  template<>
592  struct graph_property_type< vtkUndirectedGraph* >
593  : graph_property_type< vtkGraph* > { };
594 
595  // Internal graph properties
596  template<>
597  struct graph_property_type< vtkUndirectedGraph* const >
598  : graph_property_type< vtkGraph* > { };
599 #endif
600 
601  // Internal vertex properties
602  template<>
603  struct vertex_property_type< vtkUndirectedGraph* >
605 
606  // Internal vertex properties
607  template<>
608  struct vertex_property_type< vtkUndirectedGraph* const >
610 
611  // Internal edge properties
612  template<>
613  struct edge_property_type< vtkUndirectedGraph* >
615 
616  // Internal edge properties
617  template<>
618  struct edge_property_type< vtkUndirectedGraph* const >
620 
621 #if BOOST_VERSION >= 104500
622  // Internal graph properties
623  template<>
624  struct graph_bundle_type< vtkUndirectedGraph* >
625  : graph_bundle_type< vtkGraph* > { };
626 
627  // Internal graph properties
628  template<>
629  struct graph_bundle_type< vtkUndirectedGraph* const >
630  : graph_bundle_type< vtkGraph* > { };
631 #endif
632 
633  // Internal vertex properties
634  template<>
635  struct vertex_bundle_type< vtkUndirectedGraph* >
637 
638  // Internal vertex properties
639  template<>
640  struct vertex_bundle_type< vtkUndirectedGraph* const >
642 
643  // Internal edge properties
644  template<>
645  struct edge_bundle_type< vtkUndirectedGraph* >
647 
648  // Internal edge properties
649  template<>
650  struct edge_bundle_type< vtkUndirectedGraph* const >
652 
653  //===========================================================================
654  // vtkMutableDirectedGraph
655 
656  template <>
658 
659  // The graph_traits for a const graph are the same as a non-const graph.
660  template <>
662 
663  // The graph_traits for a const graph are the same as a non-const graph.
664  template <>
666 
667 #if BOOST_VERSION >= 104500
668  // Internal graph properties
669  template<>
670  struct graph_property_type< vtkMutableDirectedGraph* >
671  : graph_property_type< vtkDirectedGraph* > { };
672 
673  // Internal graph properties
674  template<>
675  struct graph_property_type< vtkMutableDirectedGraph* const >
676  : graph_property_type< vtkDirectedGraph* > { };
677 #endif
678 
679  // Internal vertex properties
680  template<>
681  struct vertex_property_type< vtkMutableDirectedGraph* >
683 
684  // Internal vertex properties
685  template<>
686  struct vertex_property_type< vtkMutableDirectedGraph* const >
688 
689  // Internal edge properties
690  template<>
691  struct edge_property_type< vtkMutableDirectedGraph* >
693 
694  // Internal edge properties
695  template<>
696  struct edge_property_type< vtkMutableDirectedGraph* const >
698 
699 #if BOOST_VERSION >= 104500
700  // Internal graph properties
701  template<>
702  struct graph_bundle_type< vtkMutableDirectedGraph* >
703  : graph_bundle_type< vtkDirectedGraph* > { };
704 
705  // Internal graph properties
706  template<>
707  struct graph_bundle_type< vtkMutableDirectedGraph* const >
708  : graph_bundle_type< vtkDirectedGraph* > { };
709 #endif
710 
711  // Internal vertex properties
712  template<>
713  struct vertex_bundle_type< vtkMutableDirectedGraph* >
715 
716  // Internal vertex properties
717  template<>
718  struct vertex_bundle_type< vtkMutableDirectedGraph* const >
720 
721  // Internal edge properties
722  template<>
723  struct edge_bundle_type< vtkMutableDirectedGraph* >
725 
726  // Internal edge properties
727  template<>
728  struct edge_bundle_type< vtkMutableDirectedGraph* const >
730 
731  //===========================================================================
732  // vtkMutableUndirectedGraph
733 
734  template <>
736 
737  // The graph_traits for a const graph are the same as a non-const graph.
738  template <>
740 
741  // The graph_traits for a const graph are the same as a non-const graph.
742  template <>
744 
745 #if BOOST_VERSION >= 104500
746  // Internal graph properties
747  template<>
748  struct graph_property_type< vtkMutableUndirectedGraph* >
749  : graph_property_type< vtkUndirectedGraph* > { };
750 
751  // Internal graph properties
752  template<>
753  struct graph_property_type< vtkMutableUndirectedGraph* const >
754  : graph_property_type< vtkUndirectedGraph* > { };
755 #endif
756 
757  // Internal vertex properties
758  template<>
759  struct vertex_property_type< vtkMutableUndirectedGraph* >
761 
762  // Internal vertex properties
763  template<>
764  struct vertex_property_type< vtkMutableUndirectedGraph* const >
766 
767  // Internal edge properties
768  template<>
769  struct edge_property_type< vtkMutableUndirectedGraph* >
771 
772  // Internal edge properties
773  template<>
774  struct edge_property_type< vtkMutableUndirectedGraph* const >
776 
777 #if BOOST_VERSION >= 104500
778  // Internal graph properties
779  template<>
780  struct graph_bundle_type< vtkMutableUndirectedGraph* >
781  : graph_bundle_type< vtkUndirectedGraph* > { };
782 
783  // Internal graph properties
784  template<>
785  struct graph_bundle_type< vtkMutableUndirectedGraph* const >
786  : graph_bundle_type< vtkUndirectedGraph* > { };
787 #endif
788 
789  // Internal vertex properties
790  template<>
791  struct vertex_bundle_type< vtkMutableUndirectedGraph* >
793 
794  // Internal vertex properties
795  template<>
796  struct vertex_bundle_type< vtkMutableUndirectedGraph* const >
798 
799  // Internal edge properties
800  template<>
801  struct edge_bundle_type< vtkMutableUndirectedGraph* >
803 
804  // Internal edge properties
805  template<>
806  struct edge_bundle_type< vtkMutableUndirectedGraph* const >
808 
809  //===========================================================================
810  // API implementation
811  template <>
812  class vertex_property< vtkGraph* > {
813  public:
814  typedef vtkIdType type;
815  };
816 
817  template <>
818  class edge_property< vtkGraph* > {
819  public:
820  typedef vtkIdType type;
821  };
822 } // end namespace boost
823 
826  vtkGraph *)
827 {
828  return e.Source;
829 }
830 
833  vtkGraph *)
834 {
835  return e.Target;
836 }
837 
838 inline std::pair<
842 {
844  vtkIdType start = 0;
846  {
847  int rank =
849  start = helper->MakeDistributedId(rank, start);
850  }
851 
852  return std::make_pair( Iter(start),
853  Iter(start + g->GetNumberOfVertices()) );
854 }
855 
856 inline std::pair<
860 {
862  return std::make_pair( Iter(g), Iter(g, g->GetNumberOfVertices()) );
863 }
864 
865 inline std::pair<
870  vtkGraph *g)
871 {
873  std::pair<Iter, Iter> p = std::make_pair( Iter(g, u), Iter(g, u, true) );
874  return p;
875 }
876 
877 inline std::pair<
882  vtkGraph *g)
883 {
885  std::pair<Iter, Iter> p = std::make_pair( Iter(g, u), Iter(g, u, true) );
886  return p;
887 }
888 
889 inline std::pair<
894  vtkGraph *g)
895 {
898  std::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g);
899  return std::make_pair( Iter(out.first, &g), Iter(out.second, &g) );
900 }
901 
904 {
905  return g->GetNumberOfVertices();
906 }
907 
910 {
911  return g->GetNumberOfEdges();
912 }
913 
917  vtkGraph *g)
918 {
919  return g->GetOutDegree(u);
920 }
921 
925  vtkDirectedGraph *g)
926 {
927  return g->GetInDegree(u);
928 }
929 
933  vtkGraph *g)
934 {
935  return g->GetDegree(u);
936 }
937 
940 {
941  return g->AddVertex();
942 }
943 
944 inline std::pair<
946  bool>
951 {
953  return std::make_pair(e, true);
954 }
955 
958 {
959  return g->AddVertex();
960 }
961 
962 inline std::pair<
964  bool>
969 {
971  return std::make_pair(e, true);
972 }
973 
974 namespace boost {
975  //===========================================================================
976  // An edge map for vtkGraph.
977  // This is a common input needed for algorithms.
978 
979  struct vtkGraphEdgeMap { };
980 
981  template <>
983  {
987  typedef readable_property_map_tag category;
988  };
989 
991  get(
992  vtkGraphEdgeMap vtkNotUsed(arr),
994  {
995  return key.Id;
996  }
997 
998  //===========================================================================
999  // Helper for vtkGraph edge property maps
1000  // Automatically converts boost edge ids to vtkGraph edge ids.
1001 
1002  template<typename PMap>
1004  {
1005  public:
1006  vtkGraphEdgePropertyMapHelper(PMap m) : pmap(m) { }
1007  PMap pmap;
1012 
1013  reference operator[] (const key_type& key) const
1014  {
1015  return get(pmap, key.Id);
1016  }
1017  };
1018 
1019  template<typename PMap>
1020  inline typename property_traits<PMap>::reference
1021  get(
1023  vtkEdgeType key)
1024  {
1025  return get(helper.pmap, key.Id);
1026  }
1027 
1028  template<typename PMap>
1029  inline void
1032  vtkEdgeType key,
1033  const typename property_traits<PMap>::value_type & value)
1034  {
1035  put(helper.pmap, key.Id, value);
1036  }
1037 
1038  //===========================================================================
1039  // Helper for vtkGraph vertex property maps
1040  // Automatically converts boost vertex ids to vtkGraph vertex ids.
1041 
1042  template<typename PMap>
1044  {
1045  public:
1046  vtkGraphVertexPropertyMapHelper(PMap m) : pmap(m) { }
1047  PMap pmap;
1052 
1053  reference operator[] (const key_type& key) const
1054  {
1055  return get(pmap, key);
1056  }
1057  };
1058 
1059  template<typename PMap>
1060  inline typename property_traits<PMap>::reference
1061  get(
1063  vtkIdType key)
1064  {
1065  return get(helper.pmap, key);
1066  }
1067 
1068  template<typename PMap>
1069  inline void
1072  vtkIdType key,
1073  const typename property_traits<PMap>::value_type & value)
1074  {
1075  put(helper.pmap, key, value);
1076  }
1077 
1078  //===========================================================================
1079  // An index map for vtkGraph
1080  // This is a common input needed for algorithms
1081 
1082  struct vtkGraphIndexMap { };
1083 
1084  template <>
1086  {
1090  typedef readable_property_map_tag category;
1091  };
1092 
1094  get(
1095  vtkGraphIndexMap vtkNotUsed(arr),
1097  {
1098  return key;
1099  }
1100 
1101  //===========================================================================
1102  // Helper for vtkGraph property maps
1103  // Automatically multiplies the property value by some value (default 1)
1104  template<typename PMap>
1106  {
1107  public:
1108  vtkGraphPropertyMapMultiplier(PMap m, float multi=1) : pmap(m),multiplier(multi){}
1109  PMap pmap;
1110  float multiplier;
1115  };
1116 
1117  template<typename PMap>
1118  inline typename property_traits<PMap>::reference
1119  get(
1121  const typename property_traits<PMap>::key_type & key)
1122  {
1123  return multi.multiplier * get(multi.pmap, key);
1124  }
1125 
1126  template<typename PMap>
1127  inline void
1130  const typename property_traits<PMap>::key_type & key,
1131  const typename property_traits<PMap>::value_type & value)
1132  {
1133  put(multi.pmap, key, value);
1134  }
1135 
1136  // Allow algorithms to automatically extract vtkGraphIndexMap from a
1137  // VTK graph
1138  template<>
1139  struct property_map<vtkGraph*, vertex_index_t>
1140  {
1143  };
1144 
1145  template<>
1146  struct property_map<vtkDirectedGraph*, vertex_index_t>
1148 
1149  template<>
1150  struct property_map<vtkUndirectedGraph*, vertex_index_t>
1152 
1153  inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*) { return vtkGraphIndexMap(); }
1154 
1155  template<>
1156  struct property_map<vtkGraph*, edge_index_t>
1157  {
1160  };
1161 
1162  template<>
1163  struct property_map<vtkDirectedGraph*, edge_index_t>
1165 
1166  template<>
1167  struct property_map<vtkUndirectedGraph*, edge_index_t>
1169 
1170  inline vtkGraphIndexMap get(edge_index_t, vtkGraph*) { return vtkGraphIndexMap(); }
1171 
1172  // property_map specializations for const-qualified graphs
1173  template<>
1174  struct property_map<vtkDirectedGraph* const, vertex_index_t>
1176 
1177  template<>
1178  struct property_map<vtkUndirectedGraph* const, vertex_index_t>
1180 
1181  template<>
1182  struct property_map<vtkDirectedGraph* const, edge_index_t>
1184 
1185  template<>
1186  struct property_map<vtkUndirectedGraph* const, edge_index_t>
1188 } // namespace boost
1189 
1190 #if BOOST_VERSION > 104000
1191 #include <boost/property_map/vector_property_map.hpp>
1192 #else
1193 #include <boost/vector_property_map.hpp>
1194 #endif
1195 
1196 
1197 #endif // vtkBoostGraphAdapter_h
1198 // 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:347
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: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
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 *)