VTK  9.3.20240318
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
43 #ifndef vtkBoostGraphAdapter_h
44 #define vtkBoostGraphAdapter_h
45 
46 #include "vtkAbstractArray.h"
47 #include "vtkDataArray.h"
48 #include "vtkDataObject.h"
49 #include "vtkDirectedGraph.h"
51 #include "vtkDoubleArray.h"
52 #include "vtkFloatArray.h"
53 #include "vtkIdTypeArray.h"
54 #include "vtkInformation.h"
55 #include "vtkIntArray.h"
58 #include "vtkTree.h"
59 #include "vtkUndirectedGraph.h"
60 #include "vtkVariant.h"
61 
62 #include <boost/version.hpp>
63 
64 namespace boost
65 {
66 //===========================================================================
67 // VTK arrays as property maps
68 // These need to be defined before including other boost stuff
69 
70 // Forward declarations are required here, so that we aren't forced
71 // to include boost/property_map.hpp.
72 template <typename>
74 struct read_write_property_map_tag;
75 
76 #define vtkPropertyMapMacro(T, V) \
77  template <> \
78  struct property_traits<T*> \
79  { \
80  typedef V value_type; \
81  typedef V reference; \
82  typedef vtkIdType key_type; \
83  typedef read_write_property_map_tag category; \
84  }; \
85  \
86  inline property_traits<T*>::reference get(T* const& arr, property_traits<T*>::key_type key) \
87  { \
88  return arr->GetValue(key); \
89  } \
90  \
91  inline void put( \
92  T* arr, property_traits<T*>::key_type key, const property_traits<T*>::value_type& value) \
93  { \
94  arr->InsertValue(key, value); \
95  }
96 
101 
102 // vtkDataArray
103 template <>
105 {
106  typedef double value_type;
107  typedef double reference;
109  typedef read_write_property_map_tag category;
110 };
111 
112 inline double get(vtkDataArray* const& arr, vtkIdType key)
113 {
114  return arr->GetTuple1(key);
115 }
116 
117 inline void put(vtkDataArray* arr, vtkIdType key, const double& value)
118 {
119  arr->SetTuple1(key, value);
120 }
121 
122 // vtkAbstractArray as a property map of vtkVariants
123 template <>
125 {
129  typedef read_write_property_map_tag category;
130 };
131 
133 {
134  return arr->GetVariantValue(key);
135 }
136 
137 inline void put(vtkAbstractArray* arr, vtkIdType key, const vtkVariant& value)
138 {
140 }
141 
142 #if defined(_MSC_VER)
143 namespace detail
144 {
147 }
148 #endif
149 }
150 
151 #include <utility> // STL Header
152 
153 #include <boost/config.hpp>
154 #include <boost/version.hpp>
155 
156 #if BOOST_VERSION > 107300 && BOOST_VERSION < 107600
157 #define BOOST_ALLOW_DEPRECATED_HEADERS
158 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
159 #endif
160 
161 #include <boost/graph/adjacency_iterator.hpp>
162 #include <boost/graph/graph_traits.hpp>
163 #include <boost/graph/properties.hpp>
164 #include <boost/iterator/iterator_facade.hpp>
165 
166 // The functions and classes in this file allows the user to
167 // treat a vtkDirectedGraph or vtkUndirectedGraph object
168 // as a boost graph "as is".
169 
170 namespace boost
171 {
172 
174  : public iterator_facade<vtk_vertex_iterator, vtkIdType, bidirectional_traversal_tag,
175  const vtkIdType&, vtkIdType>
176 {
177 public:
179  : index(i)
180  {
181  }
182 
183 private:
184  const vtkIdType& dereference() const { return index; }
185 
186  bool equal(const vtk_vertex_iterator& other) const { return index == other.index; }
187 
188  void increment() { index++; }
189  void decrement() { index--; }
190 
191  vtkIdType index;
192 
193  friend class iterator_core_access;
194 };
195 
197  : public iterator_facade<vtk_edge_iterator, vtkEdgeType, forward_traversal_tag,
198  const vtkEdgeType&, vtkIdType>
199 {
200 public:
201  explicit vtk_edge_iterator(vtkGraph* g = nullptr, vtkIdType v = 0)
202  : directed(false)
203  , vertex(v)
204  , lastVertex(v)
205  , iter(nullptr)
206  , end(nullptr)
207  , graph(g)
208  {
209  if (graph)
210  {
211  lastVertex = graph->GetNumberOfVertices();
212  }
213 
214  vtkIdType myRank = -1;
215  vtkDistributedGraphHelper* helper =
216  this->graph ? this->graph->GetDistributedGraphHelper() : nullptr;
217  if (helper)
218  {
219  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
220  vertex = helper->MakeDistributedId(myRank, vertex);
221  lastVertex = helper->MakeDistributedId(myRank, lastVertex);
222  }
223 
224  if (graph != nullptr)
225  {
226  directed = (vtkDirectedGraph::SafeDownCast(graph) != nullptr);
227  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
228  {
229  ++vertex;
230  }
231 
232  if (vertex < lastVertex)
233  {
234  // Get the outgoing edges of the first vertex that has outgoing
235  // edges
236  vtkIdType nedges;
237  graph->GetOutEdges(vertex, iter, nedges);
238  if (iter)
239  {
240  end = iter + nedges;
241 
242  if (!directed)
243  {
244  while ( // Skip non-local edges
245  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
246  // Skip entirely-local edges where Source > Target
247  || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
248  vertex > iter->Target))
249  {
250  this->inc();
251  }
252  }
253  }
254  }
255  else
256  {
257  iter = nullptr;
258  }
259  }
260 
261  RecalculateEdge();
262  }
263 
264 private:
265  const vtkEdgeType& dereference() const
266  {
267  assert(iter);
268  return edge;
269  }
270 
271  bool equal(const vtk_edge_iterator& other) const
272  {
273  return vertex == other.vertex && iter == other.iter;
274  }
275 
276  void increment()
277  {
278  inc();
279  if (!directed)
280  {
281  vtkIdType myRank = -1;
282  vtkDistributedGraphHelper* helper =
283  this->graph ? this->graph->GetDistributedGraphHelper() : nullptr;
284  if (helper)
285  {
286  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
287  }
288 
289  while (iter != nullptr &&
290  ( // Skip non-local edges
291  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
292  // Skip entirely-local edges where Source > Target
293  || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
294  vertex > iter->Target)))
295  {
296  inc();
297  }
298  }
299  RecalculateEdge();
300  }
301 
302  void inc()
303  {
304  ++iter;
305  if (iter == end)
306  {
307  // Find a vertex with nonzero out degree.
308  ++vertex;
309  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
310  {
311  ++vertex;
312  }
313 
314  if (vertex < lastVertex)
315  {
316  vtkIdType nedges;
317  graph->GetOutEdges(vertex, iter, nedges);
318  end = iter + nedges;
319  }
320  else
321  {
322  iter = nullptr;
323  }
324  }
325  }
326 
327  void RecalculateEdge()
328  {
329  if (iter)
330  {
331  edge = vtkEdgeType(vertex, iter->Target, iter->Id);
332  }
333  }
334 
335  bool directed;
336  vtkIdType vertex;
337  vtkIdType lastVertex;
338  const vtkOutEdgeType* iter;
339  const vtkOutEdgeType* end;
340  vtkGraph* graph;
341  vtkEdgeType edge;
342 
343  friend class iterator_core_access;
344 };
345 
347  : public iterator_facade<vtk_out_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
348  const vtkEdgeType&, ptrdiff_t>
349 {
350 public:
351  explicit vtk_out_edge_pointer_iterator(vtkGraph* g = nullptr, vtkIdType v = 0, bool end = false)
352  : vertex(v)
353  , iter(nullptr)
354  {
355  if (g)
356  {
357  vtkIdType nedges;
358  g->GetOutEdges(vertex, iter, nedges);
359  if (end)
360  {
361  iter += nedges;
362  }
363  }
364  RecalculateEdge();
365  }
366 
367 private:
368  const vtkEdgeType& dereference() const
369  {
370  assert(iter);
371  return edge;
372  }
373 
374  bool equal(const vtk_out_edge_pointer_iterator& other) const { return iter == other.iter; }
375 
376  void increment()
377  {
378  iter++;
379  RecalculateEdge();
380  }
381 
382  void decrement()
383  {
384  iter--;
385  RecalculateEdge();
386  }
387 
388  void RecalculateEdge()
389  {
390  if (iter)
391  {
392  edge = vtkEdgeType(vertex, iter->Target, iter->Id);
393  }
394  }
395 
396  vtkIdType vertex;
397  const vtkOutEdgeType* iter;
398  vtkEdgeType edge;
399 
400  friend class iterator_core_access;
401 };
402 
404  : public iterator_facade<vtk_in_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
405  const vtkEdgeType&, ptrdiff_t>
406 {
407 public:
408  explicit vtk_in_edge_pointer_iterator(vtkGraph* g = nullptr, vtkIdType v = 0, bool end = false)
409  : vertex(v)
410  , iter(nullptr)
411  {
412  if (g)
413  {
414  vtkIdType nedges;
415  g->GetInEdges(vertex, iter, nedges);
416  if (end)
417  {
418  iter += nedges;
419  }
420  }
421  RecalculateEdge();
422  }
423 
424 private:
425  const vtkEdgeType& dereference() const
426  {
427  assert(iter);
428  return edge;
429  }
430 
431  bool equal(const vtk_in_edge_pointer_iterator& other) const { return iter == other.iter; }
432 
433  void increment()
434  {
435  iter++;
436  RecalculateEdge();
437  }
438 
439  void decrement()
440  {
441  iter--;
442  RecalculateEdge();
443  }
444 
445  void RecalculateEdge()
446  {
447  if (iter)
448  {
449  edge = vtkEdgeType(iter->Source, vertex, iter->Id);
450  }
451  }
452 
453  vtkIdType vertex;
454  const vtkInEdgeType* iter;
455  vtkEdgeType edge;
456 
457  friend class iterator_core_access;
458 };
459 
460 //===========================================================================
461 // vtkGraph
462 // VertexAndEdgeListGraphConcept
463 // BidirectionalGraphConcept
464 // AdjacencyGraphConcept
465 VTK_ABI_NAMESPACE_BEGIN
466 
468  : public virtual bidirectional_graph_tag
469  , public virtual edge_list_graph_tag
470  , public virtual vertex_list_graph_tag
471  , public virtual adjacency_graph_tag
472 {
473 };
474 
475 VTK_ABI_NAMESPACE_END
476 
477 template <>
478 struct graph_traits<vtkGraph*>
479 {
481  static vertex_descriptor null_vertex() { return -1; }
483  static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); }
486 
489 
490  typedef allow_parallel_edge_tag edge_parallel_category;
495 
498 };
499 
500 #if BOOST_VERSION >= 104500
501 template <>
502 struct graph_property_type<vtkGraph*>
503 {
504  typedef no_property type;
505 };
506 #endif
507 
508 template <>
509 struct vertex_property_type<vtkGraph*>
510 {
511  typedef no_property type;
512 };
513 
514 template <>
515 struct edge_property_type<vtkGraph*>
516 {
517  typedef no_property type;
518 };
519 
520 #if BOOST_VERSION >= 104500
521 template <>
522 struct graph_bundle_type<vtkGraph*>
523 {
524  typedef no_property type;
525 };
526 #endif
527 
528 template <>
529 struct vertex_bundle_type<vtkGraph*>
530 {
531  typedef no_property type;
532 };
533 
534 template <>
535 struct edge_bundle_type<vtkGraph*>
536 {
537  typedef no_property type;
538 };
539 
540 inline bool has_no_edges(vtkGraph* g)
541 {
542  return ((g->GetNumberOfEdges() > 0) ? false : true);
543 }
544 
546 {
548  {
550  }
552  {
554  }
555 }
556 
557 //===========================================================================
558 // vtkDirectedGraph
559 
560 template <>
562 {
563  typedef directed_tag directed_category;
564 };
565 
566 // The graph_traits for a const graph are the same as a non-const graph.
567 template <>
569 {
570 };
571 
572 // The graph_traits for a const graph are the same as a non-const graph.
573 template <>
575 {
576 };
577 
578 #if BOOST_VERSION >= 104500
579 // Internal graph properties
580 template <>
581 struct graph_property_type<vtkDirectedGraph*> : graph_property_type<vtkGraph*>
582 {
583 };
584 
585 // Internal graph properties
586 template <>
587 struct graph_property_type<vtkDirectedGraph* const> : graph_property_type<vtkGraph*>
588 {
589 };
590 #endif
591 
592 // Internal vertex properties
593 template <>
594 struct vertex_property_type<vtkDirectedGraph*> : vertex_property_type<vtkGraph*>
595 {
596 };
597 
598 // Internal vertex properties
599 template <>
600 struct vertex_property_type<vtkDirectedGraph* const> : vertex_property_type<vtkGraph*>
601 {
602 };
603 
604 // Internal edge properties
605 template <>
606 struct edge_property_type<vtkDirectedGraph*> : edge_property_type<vtkGraph*>
607 {
608 };
609 
610 // Internal edge properties
611 template <>
612 struct edge_property_type<vtkDirectedGraph* const> : edge_property_type<vtkGraph*>
613 {
614 };
615 
616 #if BOOST_VERSION >= 104500
617 // Internal graph properties
618 template <>
619 struct graph_bundle_type<vtkDirectedGraph*> : graph_bundle_type<vtkGraph*>
620 {
621 };
622 
623 // Internal graph properties
624 template <>
625 struct graph_bundle_type<vtkDirectedGraph* const> : graph_bundle_type<vtkGraph*>
626 {
627 };
628 #endif
629 
630 // Internal vertex properties
631 template <>
632 struct vertex_bundle_type<vtkDirectedGraph*> : vertex_bundle_type<vtkGraph*>
633 {
634 };
635 
636 // Internal vertex properties
637 template <>
638 struct vertex_bundle_type<vtkDirectedGraph* const> : vertex_bundle_type<vtkGraph*>
639 {
640 };
641 
642 // Internal edge properties
643 template <>
645 {
646 };
647 
648 // Internal edge properties
649 template <>
650 struct edge_bundle_type<vtkDirectedGraph* const> : edge_bundle_type<vtkGraph*>
651 {
652 };
653 
654 //===========================================================================
655 // vtkTree
656 
657 template <>
659 {
660 };
661 
662 // The graph_traits for a const graph are the same as a non-const graph.
663 template <>
664 struct graph_traits<const vtkTree*> : graph_traits<vtkTree*>
665 {
666 };
667 
668 // The graph_traits for a const graph are the same as a non-const graph.
669 template <>
670 struct graph_traits<vtkTree* const> : graph_traits<vtkTree*>
671 {
672 };
673 
674 //===========================================================================
675 // vtkUndirectedGraph
676 template <>
678 {
679  typedef undirected_tag directed_category;
680 };
681 
682 // The graph_traits for a const graph are the same as a non-const graph.
683 template <>
685 {
686 };
687 
688 // The graph_traits for a const graph are the same as a non-const graph.
689 template <>
691 {
692 };
693 
694 #if BOOST_VERSION >= 104500
695 // Internal graph properties
696 template <>
697 struct graph_property_type<vtkUndirectedGraph*> : graph_property_type<vtkGraph*>
698 {
699 };
700 
701 // Internal graph properties
702 template <>
703 struct graph_property_type<vtkUndirectedGraph* const> : graph_property_type<vtkGraph*>
704 {
705 };
706 #endif
707 
708 // Internal vertex properties
709 template <>
711 {
712 };
713 
714 // Internal vertex properties
715 template <>
716 struct vertex_property_type<vtkUndirectedGraph* const> : vertex_property_type<vtkGraph*>
717 {
718 };
719 
720 // Internal edge properties
721 template <>
723 {
724 };
725 
726 // Internal edge properties
727 template <>
728 struct edge_property_type<vtkUndirectedGraph* const> : edge_property_type<vtkGraph*>
729 {
730 };
731 
732 #if BOOST_VERSION >= 104500
733 // Internal graph properties
734 template <>
735 struct graph_bundle_type<vtkUndirectedGraph*> : graph_bundle_type<vtkGraph*>
736 {
737 };
738 
739 // Internal graph properties
740 template <>
741 struct graph_bundle_type<vtkUndirectedGraph* const> : graph_bundle_type<vtkGraph*>
742 {
743 };
744 #endif
745 
746 // Internal vertex properties
747 template <>
749 {
750 };
751 
752 // Internal vertex properties
753 template <>
754 struct vertex_bundle_type<vtkUndirectedGraph* const> : vertex_bundle_type<vtkGraph*>
755 {
756 };
757 
758 // Internal edge properties
759 template <>
761 {
762 };
763 
764 // Internal edge properties
765 template <>
766 struct edge_bundle_type<vtkUndirectedGraph* const> : edge_bundle_type<vtkGraph*>
767 {
768 };
769 
770 //===========================================================================
771 // vtkMutableDirectedGraph
772 
773 template <>
775 {
776 };
777 
778 // The graph_traits for a const graph are the same as a non-const graph.
779 template <>
781 {
782 };
783 
784 // The graph_traits for a const graph are the same as a non-const graph.
785 template <>
787 {
788 };
789 
790 #if BOOST_VERSION >= 104500
791 // Internal graph properties
792 template <>
793 struct graph_property_type<vtkMutableDirectedGraph*> : graph_property_type<vtkDirectedGraph*>
794 {
795 };
796 
797 // Internal graph properties
798 template <>
799 struct graph_property_type<vtkMutableDirectedGraph* const> : graph_property_type<vtkDirectedGraph*>
800 {
801 };
802 #endif
803 
804 // Internal vertex properties
805 template <>
807 {
808 };
809 
810 // Internal vertex properties
811 template <>
812 struct vertex_property_type<vtkMutableDirectedGraph* const>
814 {
815 };
816 
817 // Internal edge properties
818 template <>
820 {
821 };
822 
823 // Internal edge properties
824 template <>
826 {
827 };
828 
829 #if BOOST_VERSION >= 104500
830 // Internal graph properties
831 template <>
832 struct graph_bundle_type<vtkMutableDirectedGraph*> : graph_bundle_type<vtkDirectedGraph*>
833 {
834 };
835 
836 // Internal graph properties
837 template <>
838 struct graph_bundle_type<vtkMutableDirectedGraph* const> : graph_bundle_type<vtkDirectedGraph*>
839 {
840 };
841 #endif
842 
843 // Internal vertex properties
844 template <>
846 {
847 };
848 
849 // Internal vertex properties
850 template <>
852 {
853 };
854 
855 // Internal edge properties
856 template <>
858 {
859 };
860 
861 // Internal edge properties
862 template <>
864 {
865 };
866 
867 //===========================================================================
868 // vtkMutableUndirectedGraph
869 
870 template <>
872 {
873 };
874 
875 // The graph_traits for a const graph are the same as a non-const graph.
876 template <>
878 {
879 };
880 
881 // The graph_traits for a const graph are the same as a non-const graph.
882 template <>
884 {
885 };
886 
887 #if BOOST_VERSION >= 104500
888 // Internal graph properties
889 template <>
890 struct graph_property_type<vtkMutableUndirectedGraph*> : graph_property_type<vtkUndirectedGraph*>
891 {
892 };
893 
894 // Internal graph properties
895 template <>
896 struct graph_property_type<vtkMutableUndirectedGraph* const>
897  : graph_property_type<vtkUndirectedGraph*>
898 {
899 };
900 #endif
901 
902 // Internal vertex properties
903 template <>
905 {
906 };
907 
908 // Internal vertex properties
909 template <>
910 struct vertex_property_type<vtkMutableUndirectedGraph* const>
912 {
913 };
914 
915 // Internal edge properties
916 template <>
918 {
919 };
920 
921 // Internal edge properties
922 template <>
923 struct edge_property_type<vtkMutableUndirectedGraph* const>
925 {
926 };
927 
928 #if BOOST_VERSION >= 104500
929 // Internal graph properties
930 template <>
931 struct graph_bundle_type<vtkMutableUndirectedGraph*> : graph_bundle_type<vtkUndirectedGraph*>
932 {
933 };
934 
935 // Internal graph properties
936 template <>
937 struct graph_bundle_type<vtkMutableUndirectedGraph* const> : graph_bundle_type<vtkUndirectedGraph*>
938 {
939 };
940 #endif
941 
942 // Internal vertex properties
943 template <>
945 {
946 };
947 
948 // Internal vertex properties
949 template <>
950 struct vertex_bundle_type<vtkMutableUndirectedGraph* const>
952 {
953 };
954 
955 // Internal edge properties
956 template <>
958 {
959 };
960 
961 // Internal edge properties
962 template <>
964 {
965 };
966 
967 //===========================================================================
968 // API implementation
969 template <>
970 class vertex_property<vtkGraph*>
971 {
972 public:
973  typedef vtkIdType type;
974 };
975 
976 template <>
977 class edge_property<vtkGraph*>
978 {
979 public:
980  typedef vtkIdType type;
981 };
982 } // end namespace boost
983 
986 {
987  return e.Source;
988 }
989 
992 {
993  return e.Target;
994 }
995 
996 inline std::pair<boost::graph_traits<vtkGraph*>::vertex_iterator,
999 {
1001  vtkIdType start = 0;
1003  {
1005  start = helper->MakeDistributedId(rank, start);
1006  }
1007 
1008  return std::make_pair(Iter(start), Iter(start + g->GetNumberOfVertices()));
1009 }
1010 
1011 inline std::pair<boost::graph_traits<vtkGraph*>::edge_iterator,
1014 {
1016  return std::make_pair(Iter(g), Iter(g, g->GetNumberOfVertices()));
1017 }
1018 
1019 inline std::pair<boost::graph_traits<vtkGraph*>::out_edge_iterator,
1022 {
1024  std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
1025  return p;
1026 }
1027 
1028 inline std::pair<boost::graph_traits<vtkGraph*>::in_edge_iterator,
1031 {
1033  std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
1034  return p;
1035 }
1036 
1037 inline std::pair<boost::graph_traits<vtkGraph*>::adjacency_iterator,
1040 {
1043  std::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g);
1044  return std::make_pair(Iter(out.first, &g), Iter(out.second, &g));
1045 }
1046 
1048 {
1049  return g->GetNumberOfVertices();
1050 }
1051 
1053 {
1054  return g->GetNumberOfEdges();
1055 }
1056 
1059 {
1060  return g->GetOutDegree(u);
1061 }
1062 
1065 {
1066  return g->GetInDegree(u);
1067 }
1068 
1071 {
1072  return g->GetDegree(u);
1073 }
1074 
1077 {
1078  return g->AddVertex();
1079 }
1080 
1081 inline std::pair<boost::graph_traits<vtkMutableDirectedGraph*>::edge_descriptor, bool> add_edge(
1084 {
1086  return std::make_pair(e, true);
1087 }
1088 
1091 {
1092  return g->AddVertex();
1093 }
1094 
1095 inline std::pair<boost::graph_traits<vtkMutableUndirectedGraph*>::edge_descriptor, bool> add_edge(
1099 {
1101  return std::make_pair(e, true);
1102 }
1103 
1104 namespace boost
1105 {
1106 VTK_ABI_NAMESPACE_BEGIN
1107 //===========================================================================
1108 // An edge map for vtkGraph.
1109 // This is a common input needed for algorithms.
1110 
1112 {
1113 };
1114 
1115 VTK_ABI_NAMESPACE_END
1116 
1117 template <>
1119 {
1123  typedef readable_property_map_tag category;
1124 };
1125 
1128 {
1129  return key.Id;
1130 }
1131 
1132 //===========================================================================
1133 // Helper for vtkGraph edge property maps
1134 // Automatically converts boost edge ids to vtkGraph edge ids.
1135 
1136 VTK_ABI_NAMESPACE_BEGIN
1137 template <typename PMap>
1139 {
1140 public:
1142  : pmap(m)
1143  {
1144  }
1145  PMap pmap;
1150 
1151  reference operator[](const key_type& key) const { return get(pmap, key.Id); }
1152 };
1153 VTK_ABI_NAMESPACE_END
1154 
1155 template <typename PMap>
1158 {
1159  return get(helper.pmap, key.Id);
1160 }
1161 
1162 template <typename PMap>
1164  const typename property_traits<PMap>::value_type& value)
1165 {
1166  put(helper.pmap, key.Id, value);
1167 }
1168 
1169 //===========================================================================
1170 // Helper for vtkGraph vertex property maps
1171 // Automatically converts boost vertex ids to vtkGraph vertex ids.
1172 
1173 VTK_ABI_NAMESPACE_BEGIN
1174 template <typename PMap>
1176 {
1177 public:
1179  : pmap(m)
1180  {
1181  }
1182  PMap pmap;
1187 
1188  reference operator[](const key_type& key) const { return get(pmap, key); }
1189 };
1190 VTK_ABI_NAMESPACE_END
1191 
1192 template <typename PMap>
1195 {
1196  return get(helper.pmap, key);
1197 }
1198 
1199 template <typename PMap>
1201  const typename property_traits<PMap>::value_type& value)
1202 {
1203  put(helper.pmap, key, value);
1204 }
1205 
1206 //===========================================================================
1207 // An index map for vtkGraph
1208 // This is a common input needed for algorithms
1209 
1210 VTK_ABI_NAMESPACE_BEGIN
1212 {
1213 };
1214 VTK_ABI_NAMESPACE_END
1215 
1216 template <>
1218 {
1222  typedef readable_property_map_tag category;
1223 };
1224 
1227 {
1228  return key;
1229 }
1230 
1231 //===========================================================================
1232 // Helper for vtkGraph property maps
1233 // Automatically multiplies the property value by some value (default 1)
1234 VTK_ABI_NAMESPACE_BEGIN
1235 template <typename PMap>
1237 {
1238 public:
1239  vtkGraphPropertyMapMultiplier(PMap m, float multi = 1)
1240  : pmap(m)
1241  , multiplier(multi)
1242  {
1243  }
1244  PMap pmap;
1245  float multiplier;
1250 };
1251 VTK_ABI_NAMESPACE_END
1252 
1253 template <typename PMap>
1256 {
1257  return multi.multiplier * get(multi.pmap, key);
1258 }
1259 
1260 template <typename PMap>
1262  const typename property_traits<PMap>::key_type& key,
1263  const typename property_traits<PMap>::value_type& value)
1264 {
1265  put(multi.pmap, key, value);
1266 }
1267 
1268 // Allow algorithms to automatically extract vtkGraphIndexMap from a
1269 // VTK graph
1270 template <>
1271 struct property_map<vtkGraph*, vertex_index_t>
1272 {
1275 };
1276 
1277 template <>
1278 struct property_map<vtkDirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1279 {
1280 };
1281 
1282 template <>
1283 struct property_map<vtkUndirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1284 {
1285 };
1286 
1287 inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*)
1288 {
1289  return vtkGraphIndexMap();
1290 }
1291 
1292 template <>
1293 struct property_map<vtkGraph*, edge_index_t>
1294 {
1297 };
1298 
1299 template <>
1300 struct property_map<vtkDirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1301 {
1302 };
1303 
1304 template <>
1305 struct property_map<vtkUndirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1306 {
1307 };
1308 
1309 inline vtkGraphIndexMap get(edge_index_t, vtkGraph*)
1310 {
1311  return vtkGraphIndexMap();
1312 }
1313 
1314 // property_map specializations for const-qualified graphs
1315 template <>
1316 struct property_map<vtkDirectedGraph* const, vertex_index_t>
1318 {
1319 };
1320 
1321 template <>
1322 struct property_map<vtkUndirectedGraph* const, vertex_index_t>
1324 {
1325 };
1326 
1327 template <>
1328 struct property_map<vtkDirectedGraph* const, edge_index_t>
1330 {
1331 };
1332 
1333 template <>
1334 struct property_map<vtkUndirectedGraph* const, edge_index_t>
1336 {
1337 };
1338 } // namespace boost
1339 
1340 #if BOOST_VERSION > 104000
1341 #include <boost/property_map/vector_property_map.hpp>
1342 #else
1343 #include <boost/vector_property_map.hpp>
1344 #endif
1345 
1346 #endif // vtkBoostGraphAdapter_h
1347 // 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:154
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
Base class for graph data types.
Definition: vtkGraph.h:340
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:144
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:145
An undirected graph.
A type representing the union of many types.
Definition: vtkVariant.h:162
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:301
vtkIdType Source
Definition: vtkGraph.h:323
vtkIdType Target
Definition: vtkGraph.h:312
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