VTK  9.3.1
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
14 #ifndef vtkBoostGraphAdapter_h
15 #define vtkBoostGraphAdapter_h
16 
17 #include "vtkAbstractArray.h"
18 #include "vtkDataArray.h"
19 #include "vtkDataObject.h"
20 #include "vtkDirectedGraph.h"
22 #include "vtkDoubleArray.h"
23 #include "vtkFloatArray.h"
24 #include "vtkIdTypeArray.h"
25 #include "vtkInformation.h"
26 #include "vtkIntArray.h"
29 #include "vtkTree.h"
30 #include "vtkUndirectedGraph.h"
31 #include "vtkVariant.h"
32 
33 #include <boost/version.hpp>
34 
35 namespace boost
36 {
37 //===========================================================================
38 // VTK arrays as property maps
39 // These need to be defined before including other boost stuff
40 
41 // Forward declarations are required here, so that we aren't forced
42 // to include boost/property_map.hpp.
43 template <typename>
45 struct read_write_property_map_tag;
46 
47 #define vtkPropertyMapMacro(T, V) \
48  template <> \
49  struct property_traits<T*> \
50  { \
51  typedef V value_type; \
52  typedef V reference; \
53  typedef vtkIdType key_type; \
54  typedef read_write_property_map_tag category; \
55  }; \
56  \
57  inline property_traits<T*>::reference get(T* const& arr, property_traits<T*>::key_type key) \
58  { \
59  return arr->GetValue(key); \
60  } \
61  \
62  inline void put( \
63  T* arr, property_traits<T*>::key_type key, const property_traits<T*>::value_type& value) \
64  { \
65  arr->InsertValue(key, value); \
66  }
67 
72 
73 // vtkDataArray
74 template <>
76 {
77  typedef double value_type;
78  typedef double reference;
80  typedef read_write_property_map_tag category;
81 };
82 
83 inline double get(vtkDataArray* const& arr, vtkIdType key)
84 {
85  return arr->GetTuple1(key);
86 }
87 
88 inline void put(vtkDataArray* arr, vtkIdType key, const double& value)
89 {
90  arr->SetTuple1(key, value);
91 }
92 
93 // vtkAbstractArray as a property map of vtkVariants
94 template <>
96 {
100  typedef read_write_property_map_tag category;
101 };
102 
103 inline vtkVariant get(vtkAbstractArray* const& arr, vtkIdType key)
104 {
105  return arr->GetVariantValue(key);
106 }
107 
108 inline void put(vtkAbstractArray* arr, vtkIdType key, const vtkVariant& value)
109 {
110  arr->InsertVariantValue(key, value);
111 }
112 
113 #if defined(_MSC_VER)
114 namespace detail
115 {
118 }
119 #endif
120 }
121 
122 #include <utility> // STL Header
123 
124 #include <boost/config.hpp>
125 #include <boost/version.hpp>
126 
127 #if BOOST_VERSION > 107300 && BOOST_VERSION < 107600
128 #define BOOST_ALLOW_DEPRECATED_HEADERS
129 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
130 #endif
131 
132 #include <boost/graph/adjacency_iterator.hpp>
133 #include <boost/graph/graph_traits.hpp>
134 #include <boost/graph/properties.hpp>
135 #include <boost/iterator/iterator_facade.hpp>
136 
137 // The functions and classes in this file allows the user to
138 // treat a vtkDirectedGraph or vtkUndirectedGraph object
139 // as a boost graph "as is".
140 
141 namespace boost
142 {
143 
145  : public iterator_facade<vtk_vertex_iterator, vtkIdType, bidirectional_traversal_tag,
146  const vtkIdType&, vtkIdType>
147 {
148 public:
150  : index(i)
151  {
152  }
153 
154 private:
155  const vtkIdType& dereference() const { return index; }
156 
157  bool equal(const vtk_vertex_iterator& other) const { return index == other.index; }
158 
159  void increment() { index++; }
160  void decrement() { index--; }
161 
162  vtkIdType index;
163 
164  friend class iterator_core_access;
165 };
166 
168  : public iterator_facade<vtk_edge_iterator, vtkEdgeType, forward_traversal_tag,
169  const vtkEdgeType&, vtkIdType>
170 {
171 public:
172  explicit vtk_edge_iterator(vtkGraph* g = nullptr, vtkIdType v = 0)
173  : directed(false)
174  , vertex(v)
175  , lastVertex(v)
176  , iter(nullptr)
177  , end(nullptr)
178  , graph(g)
179  {
180  if (graph)
181  {
182  lastVertex = graph->GetNumberOfVertices();
183  }
184 
185  vtkIdType myRank = -1;
186  vtkDistributedGraphHelper* helper =
187  this->graph ? this->graph->GetDistributedGraphHelper() : nullptr;
188  if (helper)
189  {
190  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
191  vertex = helper->MakeDistributedId(myRank, vertex);
192  lastVertex = helper->MakeDistributedId(myRank, lastVertex);
193  }
194 
195  if (graph != nullptr)
196  {
197  directed = (vtkDirectedGraph::SafeDownCast(graph) != nullptr);
198  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
199  {
200  ++vertex;
201  }
202 
203  if (vertex < lastVertex)
204  {
205  // Get the outgoing edges of the first vertex that has outgoing
206  // edges
207  vtkIdType nedges;
208  graph->GetOutEdges(vertex, iter, nedges);
209  if (iter)
210  {
211  end = iter + nedges;
212 
213  if (!directed)
214  {
215  while ( // Skip non-local edges
216  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
217  // Skip entirely-local edges where Source > Target
218  || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
219  vertex > iter->Target))
220  {
221  this->inc();
222  }
223  }
224  }
225  }
226  else
227  {
228  iter = nullptr;
229  }
230  }
231 
232  RecalculateEdge();
233  }
234 
235 private:
236  const vtkEdgeType& dereference() const
237  {
238  assert(iter);
239  return edge;
240  }
241 
242  bool equal(const vtk_edge_iterator& other) const
243  {
244  return vertex == other.vertex && iter == other.iter;
245  }
246 
247  void increment()
248  {
249  inc();
250  if (!directed)
251  {
252  vtkIdType myRank = -1;
253  vtkDistributedGraphHelper* helper =
254  this->graph ? this->graph->GetDistributedGraphHelper() : nullptr;
255  if (helper)
256  {
257  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
258  }
259 
260  while (iter != nullptr &&
261  ( // Skip non-local edges
262  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
263  // Skip entirely-local edges where Source > Target
264  || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
265  vertex > iter->Target)))
266  {
267  inc();
268  }
269  }
270  RecalculateEdge();
271  }
272 
273  void inc()
274  {
275  ++iter;
276  if (iter == end)
277  {
278  // Find a vertex with nonzero out degree.
279  ++vertex;
280  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
281  {
282  ++vertex;
283  }
284 
285  if (vertex < lastVertex)
286  {
287  vtkIdType nedges;
288  graph->GetOutEdges(vertex, iter, nedges);
289  end = iter + nedges;
290  }
291  else
292  {
293  iter = nullptr;
294  }
295  }
296  }
297 
298  void RecalculateEdge()
299  {
300  if (iter)
301  {
302  edge = vtkEdgeType(vertex, iter->Target, iter->Id);
303  }
304  }
305 
306  bool directed;
307  vtkIdType vertex;
308  vtkIdType lastVertex;
309  const vtkOutEdgeType* iter;
310  const vtkOutEdgeType* end;
311  vtkGraph* graph;
312  vtkEdgeType edge;
313 
314  friend class iterator_core_access;
315 };
316 
318  : public iterator_facade<vtk_out_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
319  const vtkEdgeType&, ptrdiff_t>
320 {
321 public:
322  explicit vtk_out_edge_pointer_iterator(vtkGraph* g = nullptr, vtkIdType v = 0, bool end = false)
323  : vertex(v)
324  , iter(nullptr)
325  {
326  if (g)
327  {
328  vtkIdType nedges;
329  g->GetOutEdges(vertex, iter, nedges);
330  if (end)
331  {
332  iter += nedges;
333  }
334  }
335  RecalculateEdge();
336  }
337 
338 private:
339  const vtkEdgeType& dereference() const
340  {
341  assert(iter);
342  return edge;
343  }
344 
345  bool equal(const vtk_out_edge_pointer_iterator& other) const { return iter == other.iter; }
346 
347  void increment()
348  {
349  iter++;
350  RecalculateEdge();
351  }
352 
353  void decrement()
354  {
355  iter--;
356  RecalculateEdge();
357  }
358 
359  void RecalculateEdge()
360  {
361  if (iter)
362  {
363  edge = vtkEdgeType(vertex, iter->Target, iter->Id);
364  }
365  }
366 
367  vtkIdType vertex;
368  const vtkOutEdgeType* iter;
369  vtkEdgeType edge;
370 
371  friend class iterator_core_access;
372 };
373 
375  : public iterator_facade<vtk_in_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
376  const vtkEdgeType&, ptrdiff_t>
377 {
378 public:
379  explicit vtk_in_edge_pointer_iterator(vtkGraph* g = nullptr, vtkIdType v = 0, bool end = false)
380  : vertex(v)
381  , iter(nullptr)
382  {
383  if (g)
384  {
385  vtkIdType nedges;
386  g->GetInEdges(vertex, iter, nedges);
387  if (end)
388  {
389  iter += nedges;
390  }
391  }
392  RecalculateEdge();
393  }
394 
395 private:
396  const vtkEdgeType& dereference() const
397  {
398  assert(iter);
399  return edge;
400  }
401 
402  bool equal(const vtk_in_edge_pointer_iterator& other) const { return iter == other.iter; }
403 
404  void increment()
405  {
406  iter++;
407  RecalculateEdge();
408  }
409 
410  void decrement()
411  {
412  iter--;
413  RecalculateEdge();
414  }
415 
416  void RecalculateEdge()
417  {
418  if (iter)
419  {
420  edge = vtkEdgeType(iter->Source, vertex, iter->Id);
421  }
422  }
423 
424  vtkIdType vertex;
425  const vtkInEdgeType* iter;
426  vtkEdgeType edge;
427 
428  friend class iterator_core_access;
429 };
430 
431 //===========================================================================
432 // vtkGraph
433 // VertexAndEdgeListGraphConcept
434 // BidirectionalGraphConcept
435 // AdjacencyGraphConcept
436 VTK_ABI_NAMESPACE_BEGIN
437 
439  : public virtual bidirectional_graph_tag
440  , public virtual edge_list_graph_tag
441  , public virtual vertex_list_graph_tag
442  , public virtual adjacency_graph_tag
443 {
444 };
445 
446 VTK_ABI_NAMESPACE_END
447 
448 template <>
449 struct graph_traits<vtkGraph*>
450 {
452  static vertex_descriptor null_vertex() { return -1; }
454  static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); }
457 
460 
461  typedef allow_parallel_edge_tag edge_parallel_category;
466 
469 };
470 
471 #if BOOST_VERSION >= 104500
472 template <>
473 struct graph_property_type<vtkGraph*>
474 {
475  typedef no_property type;
476 };
477 #endif
478 
479 template <>
480 struct vertex_property_type<vtkGraph*>
481 {
482  typedef no_property type;
483 };
484 
485 template <>
486 struct edge_property_type<vtkGraph*>
487 {
488  typedef no_property type;
489 };
490 
491 #if BOOST_VERSION >= 104500
492 template <>
493 struct graph_bundle_type<vtkGraph*>
494 {
495  typedef no_property type;
496 };
497 #endif
498 
499 template <>
500 struct vertex_bundle_type<vtkGraph*>
501 {
502  typedef no_property type;
503 };
504 
505 template <>
506 struct edge_bundle_type<vtkGraph*>
507 {
508  typedef no_property type;
509 };
510 
511 inline bool has_no_edges(vtkGraph* g)
512 {
513  return ((g->GetNumberOfEdges() > 0) ? false : true);
514 }
515 
517 {
519  {
521  }
523  {
525  }
526 }
527 
528 //===========================================================================
529 // vtkDirectedGraph
530 
531 template <>
533 {
534  typedef directed_tag directed_category;
535 };
536 
537 // The graph_traits for a const graph are the same as a non-const graph.
538 template <>
540 {
541 };
542 
543 // The graph_traits for a const graph are the same as a non-const graph.
544 template <>
546 {
547 };
548 
549 #if BOOST_VERSION >= 104500
550 // Internal graph properties
551 template <>
552 struct graph_property_type<vtkDirectedGraph*> : graph_property_type<vtkGraph*>
553 {
554 };
555 
556 // Internal graph properties
557 template <>
558 struct graph_property_type<vtkDirectedGraph* const> : graph_property_type<vtkGraph*>
559 {
560 };
561 #endif
562 
563 // Internal vertex properties
564 template <>
565 struct vertex_property_type<vtkDirectedGraph*> : vertex_property_type<vtkGraph*>
566 {
567 };
568 
569 // Internal vertex properties
570 template <>
571 struct vertex_property_type<vtkDirectedGraph* const> : vertex_property_type<vtkGraph*>
572 {
573 };
574 
575 // Internal edge properties
576 template <>
577 struct edge_property_type<vtkDirectedGraph*> : edge_property_type<vtkGraph*>
578 {
579 };
580 
581 // Internal edge properties
582 template <>
583 struct edge_property_type<vtkDirectedGraph* const> : edge_property_type<vtkGraph*>
584 {
585 };
586 
587 #if BOOST_VERSION >= 104500
588 // Internal graph properties
589 template <>
590 struct graph_bundle_type<vtkDirectedGraph*> : graph_bundle_type<vtkGraph*>
591 {
592 };
593 
594 // Internal graph properties
595 template <>
596 struct graph_bundle_type<vtkDirectedGraph* const> : graph_bundle_type<vtkGraph*>
597 {
598 };
599 #endif
600 
601 // Internal vertex properties
602 template <>
603 struct vertex_bundle_type<vtkDirectedGraph*> : vertex_bundle_type<vtkGraph*>
604 {
605 };
606 
607 // Internal vertex properties
608 template <>
609 struct vertex_bundle_type<vtkDirectedGraph* const> : vertex_bundle_type<vtkGraph*>
610 {
611 };
612 
613 // Internal edge properties
614 template <>
616 {
617 };
618 
619 // Internal edge properties
620 template <>
621 struct edge_bundle_type<vtkDirectedGraph* const> : edge_bundle_type<vtkGraph*>
622 {
623 };
624 
625 //===========================================================================
626 // vtkTree
627 
628 template <>
630 {
631 };
632 
633 // The graph_traits for a const graph are the same as a non-const graph.
634 template <>
635 struct graph_traits<const vtkTree*> : graph_traits<vtkTree*>
636 {
637 };
638 
639 // The graph_traits for a const graph are the same as a non-const graph.
640 template <>
641 struct graph_traits<vtkTree* const> : graph_traits<vtkTree*>
642 {
643 };
644 
645 //===========================================================================
646 // vtkUndirectedGraph
647 template <>
649 {
650  typedef undirected_tag directed_category;
651 };
652 
653 // The graph_traits for a const graph are the same as a non-const graph.
654 template <>
656 {
657 };
658 
659 // The graph_traits for a const graph are the same as a non-const graph.
660 template <>
662 {
663 };
664 
665 #if BOOST_VERSION >= 104500
666 // Internal graph properties
667 template <>
668 struct graph_property_type<vtkUndirectedGraph*> : graph_property_type<vtkGraph*>
669 {
670 };
671 
672 // Internal graph properties
673 template <>
674 struct graph_property_type<vtkUndirectedGraph* const> : graph_property_type<vtkGraph*>
675 {
676 };
677 #endif
678 
679 // Internal vertex properties
680 template <>
682 {
683 };
684 
685 // Internal vertex properties
686 template <>
687 struct vertex_property_type<vtkUndirectedGraph* const> : vertex_property_type<vtkGraph*>
688 {
689 };
690 
691 // Internal edge properties
692 template <>
694 {
695 };
696 
697 // Internal edge properties
698 template <>
699 struct edge_property_type<vtkUndirectedGraph* const> : edge_property_type<vtkGraph*>
700 {
701 };
702 
703 #if BOOST_VERSION >= 104500
704 // Internal graph properties
705 template <>
706 struct graph_bundle_type<vtkUndirectedGraph*> : graph_bundle_type<vtkGraph*>
707 {
708 };
709 
710 // Internal graph properties
711 template <>
712 struct graph_bundle_type<vtkUndirectedGraph* const> : graph_bundle_type<vtkGraph*>
713 {
714 };
715 #endif
716 
717 // Internal vertex properties
718 template <>
720 {
721 };
722 
723 // Internal vertex properties
724 template <>
725 struct vertex_bundle_type<vtkUndirectedGraph* const> : vertex_bundle_type<vtkGraph*>
726 {
727 };
728 
729 // Internal edge properties
730 template <>
732 {
733 };
734 
735 // Internal edge properties
736 template <>
737 struct edge_bundle_type<vtkUndirectedGraph* const> : edge_bundle_type<vtkGraph*>
738 {
739 };
740 
741 //===========================================================================
742 // vtkMutableDirectedGraph
743 
744 template <>
746 {
747 };
748 
749 // The graph_traits for a const graph are the same as a non-const graph.
750 template <>
752 {
753 };
754 
755 // The graph_traits for a const graph are the same as a non-const graph.
756 template <>
758 {
759 };
760 
761 #if BOOST_VERSION >= 104500
762 // Internal graph properties
763 template <>
764 struct graph_property_type<vtkMutableDirectedGraph*> : graph_property_type<vtkDirectedGraph*>
765 {
766 };
767 
768 // Internal graph properties
769 template <>
770 struct graph_property_type<vtkMutableDirectedGraph* const> : graph_property_type<vtkDirectedGraph*>
771 {
772 };
773 #endif
774 
775 // Internal vertex properties
776 template <>
778 {
779 };
780 
781 // Internal vertex properties
782 template <>
783 struct vertex_property_type<vtkMutableDirectedGraph* const>
785 {
786 };
787 
788 // Internal edge properties
789 template <>
791 {
792 };
793 
794 // Internal edge properties
795 template <>
797 {
798 };
799 
800 #if BOOST_VERSION >= 104500
801 // Internal graph properties
802 template <>
803 struct graph_bundle_type<vtkMutableDirectedGraph*> : graph_bundle_type<vtkDirectedGraph*>
804 {
805 };
806 
807 // Internal graph properties
808 template <>
809 struct graph_bundle_type<vtkMutableDirectedGraph* const> : graph_bundle_type<vtkDirectedGraph*>
810 {
811 };
812 #endif
813 
814 // Internal vertex properties
815 template <>
817 {
818 };
819 
820 // Internal vertex properties
821 template <>
823 {
824 };
825 
826 // Internal edge properties
827 template <>
829 {
830 };
831 
832 // Internal edge properties
833 template <>
835 {
836 };
837 
838 //===========================================================================
839 // vtkMutableUndirectedGraph
840 
841 template <>
843 {
844 };
845 
846 // The graph_traits for a const graph are the same as a non-const graph.
847 template <>
849 {
850 };
851 
852 // The graph_traits for a const graph are the same as a non-const graph.
853 template <>
855 {
856 };
857 
858 #if BOOST_VERSION >= 104500
859 // Internal graph properties
860 template <>
861 struct graph_property_type<vtkMutableUndirectedGraph*> : graph_property_type<vtkUndirectedGraph*>
862 {
863 };
864 
865 // Internal graph properties
866 template <>
867 struct graph_property_type<vtkMutableUndirectedGraph* const>
868  : graph_property_type<vtkUndirectedGraph*>
869 {
870 };
871 #endif
872 
873 // Internal vertex properties
874 template <>
876 {
877 };
878 
879 // Internal vertex properties
880 template <>
881 struct vertex_property_type<vtkMutableUndirectedGraph* const>
883 {
884 };
885 
886 // Internal edge properties
887 template <>
889 {
890 };
891 
892 // Internal edge properties
893 template <>
894 struct edge_property_type<vtkMutableUndirectedGraph* const>
896 {
897 };
898 
899 #if BOOST_VERSION >= 104500
900 // Internal graph properties
901 template <>
902 struct graph_bundle_type<vtkMutableUndirectedGraph*> : graph_bundle_type<vtkUndirectedGraph*>
903 {
904 };
905 
906 // Internal graph properties
907 template <>
908 struct graph_bundle_type<vtkMutableUndirectedGraph* const> : graph_bundle_type<vtkUndirectedGraph*>
909 {
910 };
911 #endif
912 
913 // Internal vertex properties
914 template <>
916 {
917 };
918 
919 // Internal vertex properties
920 template <>
921 struct vertex_bundle_type<vtkMutableUndirectedGraph* const>
923 {
924 };
925 
926 // Internal edge properties
927 template <>
929 {
930 };
931 
932 // Internal edge properties
933 template <>
935 {
936 };
937 
938 //===========================================================================
939 // API implementation
940 template <>
941 class vertex_property<vtkGraph*>
942 {
943 public:
944  typedef vtkIdType type;
945 };
946 
947 template <>
948 class edge_property<vtkGraph*>
949 {
950 public:
951  typedef vtkIdType type;
952 };
953 } // end namespace boost
954 
957 {
958  return e.Source;
959 }
960 
963 {
964  return e.Target;
965 }
966 
967 inline std::pair<boost::graph_traits<vtkGraph*>::vertex_iterator,
970 {
972  vtkIdType start = 0;
974  {
976  start = helper->MakeDistributedId(rank, start);
977  }
978 
979  return std::make_pair(Iter(start), Iter(start + g->GetNumberOfVertices()));
980 }
981 
982 inline std::pair<boost::graph_traits<vtkGraph*>::edge_iterator,
985 {
987  return std::make_pair(Iter(g), Iter(g, g->GetNumberOfVertices()));
988 }
989 
990 inline std::pair<boost::graph_traits<vtkGraph*>::out_edge_iterator,
993 {
995  std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
996  return p;
997 }
998 
999 inline std::pair<boost::graph_traits<vtkGraph*>::in_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*>::adjacency_iterator,
1011 {
1014  std::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g);
1015  return std::make_pair(Iter(out.first, &g), Iter(out.second, &g));
1016 }
1017 
1019 {
1020  return g->GetNumberOfVertices();
1021 }
1022 
1024 {
1025  return g->GetNumberOfEdges();
1026 }
1027 
1030 {
1031  return g->GetOutDegree(u);
1032 }
1033 
1036 {
1037  return g->GetInDegree(u);
1038 }
1039 
1042 {
1043  return g->GetDegree(u);
1044 }
1045 
1048 {
1049  return g->AddVertex();
1050 }
1051 
1052 inline std::pair<boost::graph_traits<vtkMutableDirectedGraph*>::edge_descriptor, bool> add_edge(
1055 {
1057  return std::make_pair(e, true);
1058 }
1059 
1062 {
1063  return g->AddVertex();
1064 }
1065 
1066 inline std::pair<boost::graph_traits<vtkMutableUndirectedGraph*>::edge_descriptor, bool> add_edge(
1070 {
1072  return std::make_pair(e, true);
1073 }
1074 
1075 namespace boost
1076 {
1077 VTK_ABI_NAMESPACE_BEGIN
1078 //===========================================================================
1079 // An edge map for vtkGraph.
1080 // This is a common input needed for algorithms.
1081 
1083 {
1084 };
1085 
1086 VTK_ABI_NAMESPACE_END
1087 
1088 template <>
1090 {
1094  typedef readable_property_map_tag category;
1095 };
1096 
1099 {
1100  return key.Id;
1101 }
1102 
1103 //===========================================================================
1104 // Helper for vtkGraph edge property maps
1105 // Automatically converts boost edge ids to vtkGraph edge ids.
1106 
1107 VTK_ABI_NAMESPACE_BEGIN
1108 template <typename PMap>
1110 {
1111 public:
1113  : pmap(m)
1114  {
1115  }
1116  PMap pmap;
1121 
1122  reference operator[](const key_type& key) const { return get(pmap, key.Id); }
1123 };
1124 VTK_ABI_NAMESPACE_END
1125 
1126 template <typename PMap>
1129 {
1130  return get(helper.pmap, key.Id);
1131 }
1132 
1133 template <typename PMap>
1135  const typename property_traits<PMap>::value_type& value)
1136 {
1137  put(helper.pmap, key.Id, value);
1138 }
1139 
1140 //===========================================================================
1141 // Helper for vtkGraph vertex property maps
1142 // Automatically converts boost vertex ids to vtkGraph vertex ids.
1143 
1144 VTK_ABI_NAMESPACE_BEGIN
1145 template <typename PMap>
1147 {
1148 public:
1150  : pmap(m)
1151  {
1152  }
1153  PMap pmap;
1158 
1159  reference operator[](const key_type& key) const { return get(pmap, key); }
1160 };
1161 VTK_ABI_NAMESPACE_END
1162 
1163 template <typename PMap>
1166 {
1167  return get(helper.pmap, key);
1168 }
1169 
1170 template <typename PMap>
1172  const typename property_traits<PMap>::value_type& value)
1173 {
1174  put(helper.pmap, key, value);
1175 }
1176 
1177 //===========================================================================
1178 // An index map for vtkGraph
1179 // This is a common input needed for algorithms
1180 
1181 VTK_ABI_NAMESPACE_BEGIN
1183 {
1184 };
1185 VTK_ABI_NAMESPACE_END
1186 
1187 template <>
1189 {
1193  typedef readable_property_map_tag category;
1194 };
1195 
1198 {
1199  return key;
1200 }
1201 
1202 //===========================================================================
1203 // Helper for vtkGraph property maps
1204 // Automatically multiplies the property value by some value (default 1)
1205 VTK_ABI_NAMESPACE_BEGIN
1206 template <typename PMap>
1208 {
1209 public:
1210  vtkGraphPropertyMapMultiplier(PMap m, float multi = 1)
1211  : pmap(m)
1212  , multiplier(multi)
1213  {
1214  }
1215  PMap pmap;
1216  float multiplier;
1221 };
1222 VTK_ABI_NAMESPACE_END
1223 
1224 template <typename PMap>
1227 {
1228  return multi.multiplier * get(multi.pmap, key);
1229 }
1230 
1231 template <typename PMap>
1233  const typename property_traits<PMap>::key_type& key,
1234  const typename property_traits<PMap>::value_type& value)
1235 {
1236  put(multi.pmap, key, value);
1237 }
1238 
1239 // Allow algorithms to automatically extract vtkGraphIndexMap from a
1240 // VTK graph
1241 template <>
1242 struct property_map<vtkGraph*, vertex_index_t>
1243 {
1246 };
1247 
1248 template <>
1249 struct property_map<vtkDirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1250 {
1251 };
1252 
1253 template <>
1254 struct property_map<vtkUndirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1255 {
1256 };
1257 
1258 inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*)
1259 {
1260  return vtkGraphIndexMap();
1261 }
1262 
1263 template <>
1264 struct property_map<vtkGraph*, edge_index_t>
1265 {
1268 };
1269 
1270 template <>
1271 struct property_map<vtkDirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1272 {
1273 };
1274 
1275 template <>
1276 struct property_map<vtkUndirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1277 {
1278 };
1279 
1280 inline vtkGraphIndexMap get(edge_index_t, vtkGraph*)
1281 {
1282  return vtkGraphIndexMap();
1283 }
1284 
1285 // property_map specializations for const-qualified graphs
1286 template <>
1287 struct property_map<vtkDirectedGraph* const, vertex_index_t>
1289 {
1290 };
1291 
1292 template <>
1293 struct property_map<vtkUndirectedGraph* const, vertex_index_t>
1295 {
1296 };
1297 
1298 template <>
1299 struct property_map<vtkDirectedGraph* const, edge_index_t>
1301 {
1302 };
1303 
1304 template <>
1305 struct property_map<vtkUndirectedGraph* const, edge_index_t>
1307 {
1308 };
1309 } // namespace boost
1310 
1311 #if BOOST_VERSION > 104000
1312 #include <boost/property_map/vector_property_map.hpp>
1313 #else
1314 #include <boost/vector_property_map.hpp>
1315 #endif
1316 
1317 #endif // vtkBoostGraphAdapter_h
1318 // 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
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)
vtkIdType AddVertex()
Adds a vertex to the graph and returns the index of the new vertex.
Forward declaration required for Boost serialization.
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)
virtual vtkIdType GetNumberOfVertices()
The number of vertices in the graph.
vtk_out_edge_pointer_iterator out_edge_iterator
property_traits< PMap >::reference reference
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:30
vtkIdType GetVertexOwner(vtkIdType v) const
Returns owner of vertex v, by extracting top ceil(log2 P) bits of v.
An undirected graph.
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)
dynamic, self-adjusting array of vtkIdType
property_traits< PMap >::key_type key_type
int vtkIdType
Definition: vtkType.h:315
std::pair< boost::graph_traits< vtkGraph * >::vertex_iterator, boost::graph_traits< vtkGraph * >::vertex_iterator > vertices(vtkGraph *g)
property_traits< PMap >::reference reference
boost::graph_traits< vtkGraph * >::edges_size_type num_edges(vtkGraph *g)
boost::graph_traits< vtkGraph * >::vertices_size_type num_vertices(vtkGraph *g)
vtk_edge_iterator(vtkGraph *g=nullptr, vtkIdType v=0)
A type representing the union of many types.
Definition: vtkVariant.h:52
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:280
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:34
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
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int Get(vtkInformationIntegerKey *key)
Get/Set an integer-valued entry.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
void put(vtkDataArray *arr, vtkIdType key, const double &value)
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)
An editable directed graph.
bool has_no_edges(vtkGraph *g)
boost::graph_traits< vtkMutableDirectedGraph * >::vertex_descriptor add_vertex(vtkMutableDirectedGraph *g)
vtkIdType Id
Definition: vtkGraph.h:242
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.
reference operator[](const key_type &key) const
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
virtual vtkIdType GetInDegree(vtkIdType v)
The number of incoming edges to vertex v.
vtkIdType Target
Definition: vtkGraph.h:253
property_traits< PMap >::value_type value_type
static vtkMutableDirectedGraph * SafeDownCast(vtkObjectBase *o)
vtk_in_edge_pointer_iterator(vtkGraph *g=nullptr, vtkIdType v=0, bool end=false)
vtkDistributedGraphHelper * GetDistributedGraphHelper()
Retrieves the distributed graph helper for this graph.
vtkIdType Source
Definition: vtkGraph.h:264
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)
reference operator[](const key_type &key) const
property_traits< PMap >::value_type value_type
vtkIdType AddVertex()
Adds a vertex to the graph and returns the index of the new vertex.
A rooted tree data structure.
Definition: vtkTree.h:45
virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator *it)
Initializes the out edge iterator to iterate over all outgoing edges of vertex v. ...
property_traits< PMap >::value_type value_type
void RemoveEdge(vtkIdType e)
Removes the edge from the graph.
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)
boost::graph_traits< vtkGraph * >::degree_size_type out_degree(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
boost::graph_traits< vtkGraph * >::degree_size_type degree(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
boost::graph_traits< vtkDirectedGraph * >::degree_size_type in_degree(boost::graph_traits< vtkDirectedGraph * >::vertex_descriptor u, vtkDirectedGraph *g)
vtk_out_edge_pointer_iterator(vtkGraph *g=nullptr, vtkIdType v=0, bool end=false)
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
virtual vtkIdType GetOutDegree(vtkIdType v)
The number of outgoing edges from vertex v.
vtkGraphIndexMap get(edge_index_t, vtkGraph *)
vtkPropertyMapMacro(vtkIntArray, int)