VTK  9.3.0
vtkBoostGraphAdapter.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright 2008 Sandia Corporation
3 // SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
23 #ifndef vtkBoostGraphAdapter_h
24 #define vtkBoostGraphAdapter_h
25 
26 #include "vtkAbstractArray.h"
27 #include "vtkDataArray.h"
28 #include "vtkDataObject.h"
29 #include "vtkDirectedGraph.h"
31 #include "vtkDoubleArray.h"
32 #include "vtkFloatArray.h"
33 #include "vtkIdTypeArray.h"
34 #include "vtkInformation.h"
35 #include "vtkIntArray.h"
38 #include "vtkTree.h"
39 #include "vtkUndirectedGraph.h"
40 #include "vtkVariant.h"
41 
42 #include <boost/version.hpp>
43 
44 namespace boost
45 {
46 //===========================================================================
47 // VTK arrays as property maps
48 // These need to be defined before including other boost stuff
49 
50 // Forward declarations are required here, so that we aren't forced
51 // to include boost/property_map.hpp.
52 template <typename>
54 struct read_write_property_map_tag;
55 
56 #define vtkPropertyMapMacro(T, V) \
57  template <> \
58  struct property_traits<T*> \
59  { \
60  typedef V value_type; \
61  typedef V reference; \
62  typedef vtkIdType key_type; \
63  typedef read_write_property_map_tag category; \
64  }; \
65  \
66  inline property_traits<T*>::reference get(T* const& arr, property_traits<T*>::key_type key) \
67  { \
68  return arr->GetValue(key); \
69  } \
70  \
71  inline void put( \
72  T* arr, property_traits<T*>::key_type key, const property_traits<T*>::value_type& value) \
73  { \
74  arr->InsertValue(key, value); \
75  }
76 
81 
82 // vtkDataArray
83 template <>
85 {
86  typedef double value_type;
87  typedef double reference;
89  typedef read_write_property_map_tag category;
90 };
91 
92 inline double get(vtkDataArray* const& arr, vtkIdType key)
93 {
94  return arr->GetTuple1(key);
95 }
96 
97 inline void put(vtkDataArray* arr, vtkIdType key, const double& value)
98 {
99  arr->SetTuple1(key, value);
100 }
101 
102 // vtkAbstractArray as a property map of vtkVariants
103 template <>
105 {
109  typedef read_write_property_map_tag category;
110 };
111 
113 {
114  return arr->GetVariantValue(key);
115 }
116 
117 inline void put(vtkAbstractArray* arr, vtkIdType key, const vtkVariant& value)
118 {
120 }
121 
122 #if defined(_MSC_VER)
123 namespace detail
124 {
127 }
128 #endif
129 }
130 
131 #include <utility> // STL Header
132 
133 #include <boost/config.hpp>
134 #include <boost/version.hpp>
135 
136 #if BOOST_VERSION > 107300 && BOOST_VERSION < 107600
137 #define BOOST_ALLOW_DEPRECATED_HEADERS
138 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
139 #endif
140 
141 #include <boost/graph/adjacency_iterator.hpp>
142 #include <boost/graph/graph_traits.hpp>
143 #include <boost/graph/properties.hpp>
144 #include <boost/iterator/iterator_facade.hpp>
145 
146 // The functions and classes in this file allows the user to
147 // treat a vtkDirectedGraph or vtkUndirectedGraph object
148 // as a boost graph "as is".
149 
150 namespace boost
151 {
152 
154  : public iterator_facade<vtk_vertex_iterator, vtkIdType, bidirectional_traversal_tag,
155  const vtkIdType&, vtkIdType>
156 {
157 public:
159  : index(i)
160  {
161  }
162 
163 private:
164  const vtkIdType& dereference() const { return index; }
165 
166  bool equal(const vtk_vertex_iterator& other) const { return index == other.index; }
167 
168  void increment() { index++; }
169  void decrement() { index--; }
170 
171  vtkIdType index;
172 
173  friend class iterator_core_access;
174 };
175 
177  : public iterator_facade<vtk_edge_iterator, vtkEdgeType, forward_traversal_tag,
178  const vtkEdgeType&, vtkIdType>
179 {
180 public:
181  explicit vtk_edge_iterator(vtkGraph* g = nullptr, vtkIdType v = 0)
182  : directed(false)
183  , vertex(v)
184  , lastVertex(v)
185  , iter(nullptr)
186  , end(nullptr)
187  , graph(g)
188  {
189  if (graph)
190  {
191  lastVertex = graph->GetNumberOfVertices();
192  }
193 
194  vtkIdType myRank = -1;
195  vtkDistributedGraphHelper* helper =
196  this->graph ? this->graph->GetDistributedGraphHelper() : nullptr;
197  if (helper)
198  {
199  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
200  vertex = helper->MakeDistributedId(myRank, vertex);
201  lastVertex = helper->MakeDistributedId(myRank, lastVertex);
202  }
203 
204  if (graph != nullptr)
205  {
206  directed = (vtkDirectedGraph::SafeDownCast(graph) != nullptr);
207  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
208  {
209  ++vertex;
210  }
211 
212  if (vertex < lastVertex)
213  {
214  // Get the outgoing edges of the first vertex that has outgoing
215  // edges
216  vtkIdType nedges;
217  graph->GetOutEdges(vertex, iter, nedges);
218  if (iter)
219  {
220  end = iter + nedges;
221 
222  if (!directed)
223  {
224  while ( // Skip non-local edges
225  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
226  // Skip entirely-local edges where Source > Target
227  || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
228  vertex > iter->Target))
229  {
230  this->inc();
231  }
232  }
233  }
234  }
235  else
236  {
237  iter = nullptr;
238  }
239  }
240 
241  RecalculateEdge();
242  }
243 
244 private:
245  const vtkEdgeType& dereference() const
246  {
247  assert(iter);
248  return edge;
249  }
250 
251  bool equal(const vtk_edge_iterator& other) const
252  {
253  return vertex == other.vertex && iter == other.iter;
254  }
255 
256  void increment()
257  {
258  inc();
259  if (!directed)
260  {
261  vtkIdType myRank = -1;
262  vtkDistributedGraphHelper* helper =
263  this->graph ? this->graph->GetDistributedGraphHelper() : nullptr;
264  if (helper)
265  {
266  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
267  }
268 
269  while (iter != nullptr &&
270  ( // Skip non-local edges
271  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
272  // Skip entirely-local edges where Source > Target
273  || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
274  vertex > iter->Target)))
275  {
276  inc();
277  }
278  }
279  RecalculateEdge();
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  void RecalculateEdge()
308  {
309  if (iter)
310  {
311  edge = vtkEdgeType(vertex, iter->Target, iter->Id);
312  }
313  }
314 
315  bool directed;
316  vtkIdType vertex;
317  vtkIdType lastVertex;
318  const vtkOutEdgeType* iter;
319  const vtkOutEdgeType* end;
320  vtkGraph* graph;
321  vtkEdgeType edge;
322 
323  friend class iterator_core_access;
324 };
325 
327  : public iterator_facade<vtk_out_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
328  const vtkEdgeType&, ptrdiff_t>
329 {
330 public:
331  explicit vtk_out_edge_pointer_iterator(vtkGraph* g = nullptr, vtkIdType v = 0, bool end = false)
332  : vertex(v)
333  , iter(nullptr)
334  {
335  if (g)
336  {
337  vtkIdType nedges;
338  g->GetOutEdges(vertex, iter, nedges);
339  if (end)
340  {
341  iter += nedges;
342  }
343  }
344  RecalculateEdge();
345  }
346 
347 private:
348  const vtkEdgeType& dereference() const
349  {
350  assert(iter);
351  return edge;
352  }
353 
354  bool equal(const vtk_out_edge_pointer_iterator& other) const { return iter == other.iter; }
355 
356  void increment()
357  {
358  iter++;
359  RecalculateEdge();
360  }
361 
362  void decrement()
363  {
364  iter--;
365  RecalculateEdge();
366  }
367 
368  void RecalculateEdge()
369  {
370  if (iter)
371  {
372  edge = vtkEdgeType(vertex, iter->Target, iter->Id);
373  }
374  }
375 
376  vtkIdType vertex;
377  const vtkOutEdgeType* iter;
378  vtkEdgeType edge;
379 
380  friend class iterator_core_access;
381 };
382 
384  : public iterator_facade<vtk_in_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
385  const vtkEdgeType&, ptrdiff_t>
386 {
387 public:
388  explicit vtk_in_edge_pointer_iterator(vtkGraph* g = nullptr, vtkIdType v = 0, bool end = false)
389  : vertex(v)
390  , iter(nullptr)
391  {
392  if (g)
393  {
394  vtkIdType nedges;
395  g->GetInEdges(vertex, iter, nedges);
396  if (end)
397  {
398  iter += nedges;
399  }
400  }
401  RecalculateEdge();
402  }
403 
404 private:
405  const vtkEdgeType& dereference() const
406  {
407  assert(iter);
408  return edge;
409  }
410 
411  bool equal(const vtk_in_edge_pointer_iterator& other) const { return iter == other.iter; }
412 
413  void increment()
414  {
415  iter++;
416  RecalculateEdge();
417  }
418 
419  void decrement()
420  {
421  iter--;
422  RecalculateEdge();
423  }
424 
425  void RecalculateEdge()
426  {
427  if (iter)
428  {
429  edge = vtkEdgeType(iter->Source, vertex, iter->Id);
430  }
431  }
432 
433  vtkIdType vertex;
434  const vtkInEdgeType* iter;
435  vtkEdgeType edge;
436 
437  friend class iterator_core_access;
438 };
439 
440 //===========================================================================
441 // vtkGraph
442 // VertexAndEdgeListGraphConcept
443 // BidirectionalGraphConcept
444 // AdjacencyGraphConcept
445 VTK_ABI_NAMESPACE_BEGIN
446 
448  : public virtual bidirectional_graph_tag
449  , public virtual edge_list_graph_tag
450  , public virtual vertex_list_graph_tag
451  , public virtual adjacency_graph_tag
452 {
453 };
454 
455 VTK_ABI_NAMESPACE_END
456 
457 template <>
458 struct graph_traits<vtkGraph*>
459 {
461  static vertex_descriptor null_vertex() { return -1; }
463  static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); }
466 
469 
470  typedef allow_parallel_edge_tag edge_parallel_category;
475 
478 };
479 
480 #if BOOST_VERSION >= 104500
481 template <>
482 struct graph_property_type<vtkGraph*>
483 {
484  typedef no_property type;
485 };
486 #endif
487 
488 template <>
489 struct vertex_property_type<vtkGraph*>
490 {
491  typedef no_property type;
492 };
493 
494 template <>
495 struct edge_property_type<vtkGraph*>
496 {
497  typedef no_property type;
498 };
499 
500 #if BOOST_VERSION >= 104500
501 template <>
502 struct graph_bundle_type<vtkGraph*>
503 {
504  typedef no_property type;
505 };
506 #endif
507 
508 template <>
509 struct vertex_bundle_type<vtkGraph*>
510 {
511  typedef no_property type;
512 };
513 
514 template <>
515 struct edge_bundle_type<vtkGraph*>
516 {
517  typedef no_property type;
518 };
519 
520 inline bool has_no_edges(vtkGraph* g)
521 {
522  return ((g->GetNumberOfEdges() > 0) ? false : true);
523 }
524 
526 {
528  {
530  }
532  {
534  }
535 }
536 
537 //===========================================================================
538 // vtkDirectedGraph
539 
540 template <>
542 {
543  typedef directed_tag directed_category;
544 };
545 
546 // The graph_traits for a const graph are the same as a non-const graph.
547 template <>
549 {
550 };
551 
552 // The graph_traits for a const graph are the same as a non-const graph.
553 template <>
555 {
556 };
557 
558 #if BOOST_VERSION >= 104500
559 // Internal graph properties
560 template <>
561 struct graph_property_type<vtkDirectedGraph*> : graph_property_type<vtkGraph*>
562 {
563 };
564 
565 // Internal graph properties
566 template <>
567 struct graph_property_type<vtkDirectedGraph* const> : graph_property_type<vtkGraph*>
568 {
569 };
570 #endif
571 
572 // Internal vertex properties
573 template <>
574 struct vertex_property_type<vtkDirectedGraph*> : vertex_property_type<vtkGraph*>
575 {
576 };
577 
578 // Internal vertex properties
579 template <>
580 struct vertex_property_type<vtkDirectedGraph* const> : vertex_property_type<vtkGraph*>
581 {
582 };
583 
584 // Internal edge properties
585 template <>
586 struct edge_property_type<vtkDirectedGraph*> : edge_property_type<vtkGraph*>
587 {
588 };
589 
590 // Internal edge properties
591 template <>
592 struct edge_property_type<vtkDirectedGraph* const> : edge_property_type<vtkGraph*>
593 {
594 };
595 
596 #if BOOST_VERSION >= 104500
597 // Internal graph properties
598 template <>
599 struct graph_bundle_type<vtkDirectedGraph*> : graph_bundle_type<vtkGraph*>
600 {
601 };
602 
603 // Internal graph properties
604 template <>
605 struct graph_bundle_type<vtkDirectedGraph* const> : graph_bundle_type<vtkGraph*>
606 {
607 };
608 #endif
609 
610 // Internal vertex properties
611 template <>
612 struct vertex_bundle_type<vtkDirectedGraph*> : vertex_bundle_type<vtkGraph*>
613 {
614 };
615 
616 // Internal vertex properties
617 template <>
618 struct vertex_bundle_type<vtkDirectedGraph* const> : vertex_bundle_type<vtkGraph*>
619 {
620 };
621 
622 // Internal edge properties
623 template <>
625 {
626 };
627 
628 // Internal edge properties
629 template <>
630 struct edge_bundle_type<vtkDirectedGraph* const> : edge_bundle_type<vtkGraph*>
631 {
632 };
633 
634 //===========================================================================
635 // vtkTree
636 
637 template <>
639 {
640 };
641 
642 // The graph_traits for a const graph are the same as a non-const graph.
643 template <>
644 struct graph_traits<const vtkTree*> : graph_traits<vtkTree*>
645 {
646 };
647 
648 // The graph_traits for a const graph are the same as a non-const graph.
649 template <>
650 struct graph_traits<vtkTree* const> : graph_traits<vtkTree*>
651 {
652 };
653 
654 //===========================================================================
655 // vtkUndirectedGraph
656 template <>
658 {
659  typedef undirected_tag directed_category;
660 };
661 
662 // The graph_traits for a const graph are the same as a non-const graph.
663 template <>
665 {
666 };
667 
668 // The graph_traits for a const graph are the same as a non-const graph.
669 template <>
671 {
672 };
673 
674 #if BOOST_VERSION >= 104500
675 // Internal graph properties
676 template <>
677 struct graph_property_type<vtkUndirectedGraph*> : graph_property_type<vtkGraph*>
678 {
679 };
680 
681 // Internal graph properties
682 template <>
683 struct graph_property_type<vtkUndirectedGraph* const> : graph_property_type<vtkGraph*>
684 {
685 };
686 #endif
687 
688 // Internal vertex properties
689 template <>
691 {
692 };
693 
694 // Internal vertex properties
695 template <>
696 struct vertex_property_type<vtkUndirectedGraph* const> : vertex_property_type<vtkGraph*>
697 {
698 };
699 
700 // Internal edge properties
701 template <>
703 {
704 };
705 
706 // Internal edge properties
707 template <>
708 struct edge_property_type<vtkUndirectedGraph* const> : edge_property_type<vtkGraph*>
709 {
710 };
711 
712 #if BOOST_VERSION >= 104500
713 // Internal graph properties
714 template <>
715 struct graph_bundle_type<vtkUndirectedGraph*> : graph_bundle_type<vtkGraph*>
716 {
717 };
718 
719 // Internal graph properties
720 template <>
721 struct graph_bundle_type<vtkUndirectedGraph* const> : graph_bundle_type<vtkGraph*>
722 {
723 };
724 #endif
725 
726 // Internal vertex properties
727 template <>
729 {
730 };
731 
732 // Internal vertex properties
733 template <>
734 struct vertex_bundle_type<vtkUndirectedGraph* const> : vertex_bundle_type<vtkGraph*>
735 {
736 };
737 
738 // Internal edge properties
739 template <>
741 {
742 };
743 
744 // Internal edge properties
745 template <>
746 struct edge_bundle_type<vtkUndirectedGraph* const> : edge_bundle_type<vtkGraph*>
747 {
748 };
749 
750 //===========================================================================
751 // vtkMutableDirectedGraph
752 
753 template <>
755 {
756 };
757 
758 // The graph_traits for a const graph are the same as a non-const graph.
759 template <>
761 {
762 };
763 
764 // The graph_traits for a const graph are the same as a non-const graph.
765 template <>
767 {
768 };
769 
770 #if BOOST_VERSION >= 104500
771 // Internal graph properties
772 template <>
773 struct graph_property_type<vtkMutableDirectedGraph*> : graph_property_type<vtkDirectedGraph*>
774 {
775 };
776 
777 // Internal graph properties
778 template <>
779 struct graph_property_type<vtkMutableDirectedGraph* const> : graph_property_type<vtkDirectedGraph*>
780 {
781 };
782 #endif
783 
784 // Internal vertex properties
785 template <>
787 {
788 };
789 
790 // Internal vertex properties
791 template <>
792 struct vertex_property_type<vtkMutableDirectedGraph* const>
794 {
795 };
796 
797 // Internal edge properties
798 template <>
800 {
801 };
802 
803 // Internal edge properties
804 template <>
806 {
807 };
808 
809 #if BOOST_VERSION >= 104500
810 // Internal graph properties
811 template <>
812 struct graph_bundle_type<vtkMutableDirectedGraph*> : graph_bundle_type<vtkDirectedGraph*>
813 {
814 };
815 
816 // Internal graph properties
817 template <>
818 struct graph_bundle_type<vtkMutableDirectedGraph* const> : graph_bundle_type<vtkDirectedGraph*>
819 {
820 };
821 #endif
822 
823 // Internal vertex properties
824 template <>
826 {
827 };
828 
829 // Internal vertex properties
830 template <>
832 {
833 };
834 
835 // Internal edge properties
836 template <>
838 {
839 };
840 
841 // Internal edge properties
842 template <>
844 {
845 };
846 
847 //===========================================================================
848 // vtkMutableUndirectedGraph
849 
850 template <>
852 {
853 };
854 
855 // The graph_traits for a const graph are the same as a non-const graph.
856 template <>
858 {
859 };
860 
861 // The graph_traits for a const graph are the same as a non-const graph.
862 template <>
864 {
865 };
866 
867 #if BOOST_VERSION >= 104500
868 // Internal graph properties
869 template <>
870 struct graph_property_type<vtkMutableUndirectedGraph*> : graph_property_type<vtkUndirectedGraph*>
871 {
872 };
873 
874 // Internal graph properties
875 template <>
876 struct graph_property_type<vtkMutableUndirectedGraph* const>
877  : graph_property_type<vtkUndirectedGraph*>
878 {
879 };
880 #endif
881 
882 // Internal vertex properties
883 template <>
885 {
886 };
887 
888 // Internal vertex properties
889 template <>
890 struct vertex_property_type<vtkMutableUndirectedGraph* const>
892 {
893 };
894 
895 // Internal edge properties
896 template <>
898 {
899 };
900 
901 // Internal edge properties
902 template <>
903 struct edge_property_type<vtkMutableUndirectedGraph* const>
905 {
906 };
907 
908 #if BOOST_VERSION >= 104500
909 // Internal graph properties
910 template <>
911 struct graph_bundle_type<vtkMutableUndirectedGraph*> : graph_bundle_type<vtkUndirectedGraph*>
912 {
913 };
914 
915 // Internal graph properties
916 template <>
917 struct graph_bundle_type<vtkMutableUndirectedGraph* const> : graph_bundle_type<vtkUndirectedGraph*>
918 {
919 };
920 #endif
921 
922 // Internal vertex properties
923 template <>
925 {
926 };
927 
928 // Internal vertex properties
929 template <>
930 struct vertex_bundle_type<vtkMutableUndirectedGraph* const>
932 {
933 };
934 
935 // Internal edge properties
936 template <>
938 {
939 };
940 
941 // Internal edge properties
942 template <>
944 {
945 };
946 
947 //===========================================================================
948 // API implementation
949 template <>
950 class vertex_property<vtkGraph*>
951 {
952 public:
953  typedef vtkIdType type;
954 };
955 
956 template <>
957 class edge_property<vtkGraph*>
958 {
959 public:
960  typedef vtkIdType type;
961 };
962 } // end namespace boost
963 
966 {
967  return e.Source;
968 }
969 
972 {
973  return e.Target;
974 }
975 
976 inline std::pair<boost::graph_traits<vtkGraph*>::vertex_iterator,
979 {
981  vtkIdType start = 0;
983  {
985  start = helper->MakeDistributedId(rank, start);
986  }
987 
988  return std::make_pair(Iter(start), Iter(start + g->GetNumberOfVertices()));
989 }
990 
991 inline std::pair<boost::graph_traits<vtkGraph*>::edge_iterator,
994 {
996  return std::make_pair(Iter(g), Iter(g, g->GetNumberOfVertices()));
997 }
998 
999 inline std::pair<boost::graph_traits<vtkGraph*>::out_edge_iterator,
1002 {
1004  std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
1005  return p;
1006 }
1007 
1008 inline std::pair<boost::graph_traits<vtkGraph*>::in_edge_iterator,
1011 {
1013  std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
1014  return p;
1015 }
1016 
1017 inline std::pair<boost::graph_traits<vtkGraph*>::adjacency_iterator,
1020 {
1023  std::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g);
1024  return std::make_pair(Iter(out.first, &g), Iter(out.second, &g));
1025 }
1026 
1028 {
1029  return g->GetNumberOfVertices();
1030 }
1031 
1033 {
1034  return g->GetNumberOfEdges();
1035 }
1036 
1039 {
1040  return g->GetOutDegree(u);
1041 }
1042 
1045 {
1046  return g->GetInDegree(u);
1047 }
1048 
1051 {
1052  return g->GetDegree(u);
1053 }
1054 
1057 {
1058  return g->AddVertex();
1059 }
1060 
1061 inline std::pair<boost::graph_traits<vtkMutableDirectedGraph*>::edge_descriptor, bool> add_edge(
1064 {
1066  return std::make_pair(e, true);
1067 }
1068 
1071 {
1072  return g->AddVertex();
1073 }
1074 
1075 inline std::pair<boost::graph_traits<vtkMutableUndirectedGraph*>::edge_descriptor, bool> add_edge(
1079 {
1081  return std::make_pair(e, true);
1082 }
1083 
1084 namespace boost
1085 {
1086 VTK_ABI_NAMESPACE_BEGIN
1087 //===========================================================================
1088 // An edge map for vtkGraph.
1089 // This is a common input needed for algorithms.
1090 
1092 {
1093 };
1094 
1095 VTK_ABI_NAMESPACE_END
1096 
1097 template <>
1099 {
1103  typedef readable_property_map_tag category;
1104 };
1105 
1108 {
1109  return key.Id;
1110 }
1111 
1112 //===========================================================================
1113 // Helper for vtkGraph edge property maps
1114 // Automatically converts boost edge ids to vtkGraph edge ids.
1115 
1116 VTK_ABI_NAMESPACE_BEGIN
1117 template <typename PMap>
1119 {
1120 public:
1122  : pmap(m)
1123  {
1124  }
1125  PMap pmap;
1130 
1131  reference operator[](const key_type& key) const { return get(pmap, key.Id); }
1132 };
1133 VTK_ABI_NAMESPACE_END
1134 
1135 template <typename PMap>
1138 {
1139  return get(helper.pmap, key.Id);
1140 }
1141 
1142 template <typename PMap>
1144  const typename property_traits<PMap>::value_type& value)
1145 {
1146  put(helper.pmap, key.Id, value);
1147 }
1148 
1149 //===========================================================================
1150 // Helper for vtkGraph vertex property maps
1151 // Automatically converts boost vertex ids to vtkGraph vertex ids.
1152 
1153 VTK_ABI_NAMESPACE_BEGIN
1154 template <typename PMap>
1156 {
1157 public:
1159  : pmap(m)
1160  {
1161  }
1162  PMap pmap;
1167 
1168  reference operator[](const key_type& key) const { return get(pmap, key); }
1169 };
1170 VTK_ABI_NAMESPACE_END
1171 
1172 template <typename PMap>
1175 {
1176  return get(helper.pmap, key);
1177 }
1178 
1179 template <typename PMap>
1181  const typename property_traits<PMap>::value_type& value)
1182 {
1183  put(helper.pmap, key, value);
1184 }
1185 
1186 //===========================================================================
1187 // An index map for vtkGraph
1188 // This is a common input needed for algorithms
1189 
1190 VTK_ABI_NAMESPACE_BEGIN
1192 {
1193 };
1194 VTK_ABI_NAMESPACE_END
1195 
1196 template <>
1198 {
1202  typedef readable_property_map_tag category;
1203 };
1204 
1207 {
1208  return key;
1209 }
1210 
1211 //===========================================================================
1212 // Helper for vtkGraph property maps
1213 // Automatically multiplies the property value by some value (default 1)
1214 VTK_ABI_NAMESPACE_BEGIN
1215 template <typename PMap>
1217 {
1218 public:
1219  vtkGraphPropertyMapMultiplier(PMap m, float multi = 1)
1220  : pmap(m)
1221  , multiplier(multi)
1222  {
1223  }
1224  PMap pmap;
1225  float multiplier;
1230 };
1231 VTK_ABI_NAMESPACE_END
1232 
1233 template <typename PMap>
1236 {
1237  return multi.multiplier * get(multi.pmap, key);
1238 }
1239 
1240 template <typename PMap>
1242  const typename property_traits<PMap>::key_type& key,
1243  const typename property_traits<PMap>::value_type& value)
1244 {
1245  put(multi.pmap, key, value);
1246 }
1247 
1248 // Allow algorithms to automatically extract vtkGraphIndexMap from a
1249 // VTK graph
1250 template <>
1251 struct property_map<vtkGraph*, vertex_index_t>
1252 {
1255 };
1256 
1257 template <>
1258 struct property_map<vtkDirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1259 {
1260 };
1261 
1262 template <>
1263 struct property_map<vtkUndirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1264 {
1265 };
1266 
1267 inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*)
1268 {
1269  return vtkGraphIndexMap();
1270 }
1271 
1272 template <>
1273 struct property_map<vtkGraph*, edge_index_t>
1274 {
1277 };
1278 
1279 template <>
1280 struct property_map<vtkDirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1281 {
1282 };
1283 
1284 template <>
1285 struct property_map<vtkUndirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1286 {
1287 };
1288 
1289 inline vtkGraphIndexMap get(edge_index_t, vtkGraph*)
1290 {
1291  return vtkGraphIndexMap();
1292 }
1293 
1294 // property_map specializations for const-qualified graphs
1295 template <>
1296 struct property_map<vtkDirectedGraph* const, vertex_index_t>
1298 {
1299 };
1300 
1301 template <>
1302 struct property_map<vtkUndirectedGraph* const, vertex_index_t>
1304 {
1305 };
1306 
1307 template <>
1308 struct property_map<vtkDirectedGraph* const, edge_index_t>
1310 {
1311 };
1312 
1313 template <>
1314 struct property_map<vtkUndirectedGraph* const, edge_index_t>
1316 {
1317 };
1318 } // namespace boost
1319 
1320 #if BOOST_VERSION > 104000
1321 #include <boost/property_map/vector_property_map.hpp>
1322 #else
1323 #include <boost/vector_property_map.hpp>
1324 #endif
1325 
1326 #endif // vtkBoostGraphAdapter_h
1327 // VTK-HeaderTest-Exclude: vtkBoostGraphAdapter.h
property_traits< PMap >::reference reference
property_traits< PMap >::category category
property_traits< PMap >::value_type value_type
reference operator[](const key_type &key) const
vtkGraphPropertyMapMultiplier(PMap m, float multi=1)
property_traits< PMap >::value_type value_type
property_traits< PMap >::reference reference
property_traits< PMap >::key_type key_type
property_traits< PMap >::category category
property_traits< PMap >::reference reference
property_traits< PMap >::value_type value_type
reference operator[](const key_type &key) const
property_traits< PMap >::category category
vtk_edge_iterator(vtkGraph *g=nullptr, vtkIdType v=0)
vtk_in_edge_pointer_iterator(vtkGraph *g=nullptr, vtkIdType v=0, bool end=false)
vtk_out_edge_pointer_iterator(vtkGraph *g=nullptr, vtkIdType v=0, bool end=false)
Abstract superclass for all arrays.
virtual vtkVariant GetVariantValue(vtkIdType valueIdx)
Retrieve value from the array as a variant.
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Insert a value into the array from a variant.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
void SetTuple1(vtkIdType tupleIdx, double value)
These methods are included as convenience for the wrappers.
double GetTuple1(vtkIdType tupleIdx)
These methods are included as convenience for the wrappers.
static vtkInformationIntegerKey * DATA_PIECE_NUMBER()
virtual vtkInformation * GetInformation()
Set/Get the information object associated with this data object.
A directed graph.
static vtkDirectedGraph * SafeDownCast(vtkObjectBase *o)
helper for the vtkGraph class that allows the graph to be distributed across multiple memory spaces.
vtkIdType GetEdgeOwner(vtkIdType e_id) const
Returns owner of edge with ID e_id, by extracting top ceil(log2 P) bits of e_id.
vtkIdType MakeDistributedId(int owner, vtkIdType local)
Builds a distributed ID consisting of the given owner and the local ID.
vtkIdType GetVertexOwner(vtkIdType v) const
Returns owner of vertex v, by extracting top ceil(log2 P) bits of v.
dynamic, self-adjusting array of double
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:40
Base class for graph data types.
Definition: vtkGraph.h:290
virtual vtkIdType GetOutDegree(vtkIdType v)
The number of outgoing edges from vertex v.
vtkDistributedGraphHelper * GetDistributedGraphHelper()
Retrieves the distributed graph helper for this graph.
virtual vtkIdType GetNumberOfVertices()
The number of vertices in the graph.
virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator *it)
Initializes the out edge iterator to iterate over all outgoing edges of vertex v.
virtual vtkIdType GetNumberOfEdges()
The number of edges in the graph.
virtual vtkIdType GetInDegree(vtkIdType v)
The number of incoming edges to vertex v.
virtual vtkIdType GetDegree(vtkIdType v)
The total of all incoming and outgoing vertices for vertex v.
dynamic, self-adjusting array of vtkIdType
int Get(vtkInformationIntegerKey *key)
Get/Set an integer-valued entry.
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:44
An editable directed graph.
void RemoveEdge(vtkIdType e)
Removes the edge from the graph.
vtkIdType AddVertex()
Adds a vertex to the graph and returns the index of the new vertex.
static vtkMutableDirectedGraph * SafeDownCast(vtkObjectBase *o)
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...
An editable undirected graph.
static vtkMutableUndirectedGraph * SafeDownCast(vtkObjectBase *o)
void RemoveEdge(vtkIdType e)
Removes the edge from the graph.
vtkIdType AddVertex()
Adds a vertex to the graph and returns the index of the new vertex.
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...
A rooted tree data structure.
Definition: vtkTree.h:55
An undirected graph.
A type representing the union of many types.
Definition: vtkVariant.h:62
Forward declaration required for Boost serialization.
bool has_no_edges(vtkGraph *g)
vtkPropertyMapMacro(vtkIntArray, int)
void remove_edge(graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *g)
vtkGraphIndexMap get(edge_index_t, vtkGraph *)
void put(vtkGraphPropertyMapMultiplier< PMap > multi, const typename property_traits< PMap >::key_type &key, const typename property_traits< PMap >::value_type &value)
double get(vtkDataArray *const &arr, vtkIdType key)
void put(vtkDataArray *arr, vtkIdType key, const double &value)
@ key
Definition: vtkX3D.h:257
@ value
Definition: vtkX3D.h:220
@ type
Definition: vtkX3D.h:516
vtk_in_edge_pointer_iterator in_edge_iterator
allow_parallel_edge_tag edge_parallel_category
vtk_out_edge_pointer_iterator out_edge_iterator
static vertex_descriptor null_vertex()
adjacency_iterator_generator< vtkGraph *, vertex_descriptor, out_edge_iterator >::type adjacency_iterator
vtkGraph_traversal_category traversal_category
vtkIdType Id
Definition: vtkGraph.h:251
vtkIdType Source
Definition: vtkGraph.h:273
vtkIdType Target
Definition: vtkGraph.h:262
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)
boost::graph_traits< vtkDirectedGraph * >::degree_size_type in_degree(boost::graph_traits< vtkDirectedGraph * >::vertex_descriptor u, vtkDirectedGraph *g)
boost::graph_traits< vtkGraph * >::degree_size_type degree(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
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)
boost::graph_traits< vtkGraph * >::vertices_size_type num_vertices(vtkGraph *g)
boost::graph_traits< vtkGraph * >::degree_size_type out_degree(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *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)
boost::graph_traits< vtkMutableDirectedGraph * >::vertex_descriptor add_vertex(vtkMutableDirectedGraph *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)
std::pair< boost::graph_traits< vtkGraph * >::vertex_iterator, boost::graph_traits< vtkGraph * >::vertex_iterator > vertices(vtkGraph *g)
boost::graph_traits< vtkGraph * >::edges_size_type num_edges(vtkGraph *g)
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition: vtkType.h:315