VTK  9.2.20230330
vtkBoostGraphAdapter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkBoostGraphAdapter.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16  Copyright 2008 Sandia Corporation.
17  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18  the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
69 #ifndef vtkBoostGraphAdapter_h
70 #define vtkBoostGraphAdapter_h
71 
72 #include "vtkAbstractArray.h"
73 #include "vtkDataArray.h"
74 #include "vtkDataObject.h"
75 #include "vtkDirectedGraph.h"
77 #include "vtkDoubleArray.h"
78 #include "vtkFloatArray.h"
79 #include "vtkIdTypeArray.h"
80 #include "vtkInformation.h"
81 #include "vtkIntArray.h"
84 #include "vtkTree.h"
85 #include "vtkUndirectedGraph.h"
86 #include "vtkVariant.h"
87 
88 #include <boost/version.hpp>
89 
90 namespace boost
91 {
92 //===========================================================================
93 // VTK arrays as property maps
94 // These need to be defined before including other boost stuff
95 
96 // Forward declarations are required here, so that we aren't forced
97 // to include boost/property_map.hpp.
98 template <typename>
100 struct read_write_property_map_tag;
101 
102 #define vtkPropertyMapMacro(T, V) \
103  template <> \
104  struct property_traits<T*> \
105  { \
106  typedef V value_type; \
107  typedef V reference; \
108  typedef vtkIdType key_type; \
109  typedef read_write_property_map_tag category; \
110  }; \
111  \
112  inline property_traits<T*>::reference get(T* const& arr, property_traits<T*>::key_type key) \
113  { \
114  return arr->GetValue(key); \
115  } \
116  \
117  inline void put( \
118  T* arr, property_traits<T*>::key_type key, const property_traits<T*>::value_type& value) \
119  { \
120  arr->InsertValue(key, value); \
121  }
122 
127 
128 // vtkDataArray
129 template <>
131 {
132  typedef double value_type;
133  typedef double reference;
135  typedef read_write_property_map_tag category;
136 };
137 
138 inline double get(vtkDataArray* const& arr, vtkIdType key)
139 {
140  return arr->GetTuple1(key);
141 }
142 
143 inline void put(vtkDataArray* arr, vtkIdType key, const double& value)
144 {
145  arr->SetTuple1(key, value);
146 }
147 
148 // vtkAbstractArray as a property map of vtkVariants
149 template <>
151 {
155  typedef read_write_property_map_tag category;
156 };
157 
159 {
160  return arr->GetVariantValue(key);
161 }
162 
163 inline void put(vtkAbstractArray* arr, vtkIdType key, const vtkVariant& value)
164 {
166 }
167 
168 #if defined(_MSC_VER)
169 namespace detail
170 {
173 }
174 #endif
175 }
176 
177 #include <utility> // STL Header
178 
179 #include <boost/config.hpp>
180 #include <boost/version.hpp>
181 
182 #if BOOST_VERSION > 107300 && BOOST_VERSION < 107600
183 #define BOOST_ALLOW_DEPRECATED_HEADERS
184 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
185 #endif
186 
187 #include <boost/graph/adjacency_iterator.hpp>
188 #include <boost/graph/graph_traits.hpp>
189 #include <boost/graph/properties.hpp>
190 #include <boost/iterator/iterator_facade.hpp>
191 
192 // The functions and classes in this file allows the user to
193 // treat a vtkDirectedGraph or vtkUndirectedGraph object
194 // as a boost graph "as is".
195 
196 namespace boost
197 {
198 
200  : public iterator_facade<vtk_vertex_iterator, vtkIdType, bidirectional_traversal_tag,
201  const vtkIdType&, vtkIdType>
202 {
203 public:
205  : index(i)
206  {
207  }
208 
209 private:
210  const vtkIdType& dereference() const { return index; }
211 
212  bool equal(const vtk_vertex_iterator& other) const { return index == other.index; }
213 
214  void increment() { index++; }
215  void decrement() { index--; }
216 
217  vtkIdType index;
218 
219  friend class iterator_core_access;
220 };
221 
223  : public iterator_facade<vtk_edge_iterator, vtkEdgeType, forward_traversal_tag,
224  const vtkEdgeType&, vtkIdType>
225 {
226 public:
227  explicit vtk_edge_iterator(vtkGraph* g = 0, vtkIdType v = 0)
228  : directed(false)
229  , vertex(v)
230  , lastVertex(v)
231  , iter(nullptr)
232  , end(nullptr)
233  , graph(g)
234  {
235  if (graph)
236  {
237  lastVertex = graph->GetNumberOfVertices();
238  }
239 
240  vtkIdType myRank = -1;
241  vtkDistributedGraphHelper* helper = this->graph ? this->graph->GetDistributedGraphHelper() : 0;
242  if (helper)
243  {
244  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
245  vertex = helper->MakeDistributedId(myRank, vertex);
246  lastVertex = helper->MakeDistributedId(myRank, lastVertex);
247  }
248 
249  if (graph != 0)
250  {
251  directed = (vtkDirectedGraph::SafeDownCast(graph) != 0);
252  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
253  {
254  ++vertex;
255  }
256 
257  if (vertex < lastVertex)
258  {
259  // Get the outgoing edges of the first vertex that has outgoing
260  // edges
261  vtkIdType nedges;
262  graph->GetOutEdges(vertex, iter, nedges);
263  if (iter)
264  {
265  end = iter + nedges;
266 
267  if (!directed)
268  {
269  while ( // Skip non-local edges
270  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
271  // Skip entirely-local edges where Source > Target
272  || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
273  vertex > iter->Target))
274  {
275  this->inc();
276  }
277  }
278  }
279  }
280  else
281  {
282  iter = nullptr;
283  }
284  }
285 
286  RecalculateEdge();
287  }
288 
289 private:
290  const vtkEdgeType& dereference() const
291  {
292  assert(iter);
293  return edge;
294  }
295 
296  bool equal(const vtk_edge_iterator& other) const
297  {
298  return vertex == other.vertex && iter == other.iter;
299  }
300 
301  void increment()
302  {
303  inc();
304  if (!directed)
305  {
306  vtkIdType myRank = -1;
307  vtkDistributedGraphHelper* helper =
308  this->graph ? this->graph->GetDistributedGraphHelper() : 0;
309  if (helper)
310  {
311  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
312  }
313 
314  while (iter != 0 &&
315  ( // Skip non-local edges
316  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
317  // Skip entirely-local edges where Source > Target
318  || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
319  vertex > iter->Target)))
320  {
321  inc();
322  }
323  }
324  RecalculateEdge();
325  }
326 
327  void inc()
328  {
329  ++iter;
330  if (iter == end)
331  {
332  // Find a vertex with nonzero out degree.
333  ++vertex;
334  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
335  {
336  ++vertex;
337  }
338 
339  if (vertex < lastVertex)
340  {
341  vtkIdType nedges;
342  graph->GetOutEdges(vertex, iter, nedges);
343  end = iter + nedges;
344  }
345  else
346  {
347  iter = nullptr;
348  }
349  }
350  }
351 
352  void RecalculateEdge()
353  {
354  if (iter)
355  {
356  edge = vtkEdgeType(vertex, iter->Target, iter->Id);
357  }
358  }
359 
360  bool directed;
361  vtkIdType vertex;
362  vtkIdType lastVertex;
363  const vtkOutEdgeType* iter;
364  const vtkOutEdgeType* end;
365  vtkGraph* graph;
366  vtkEdgeType edge;
367 
368  friend class iterator_core_access;
369 };
370 
372  : public iterator_facade<vtk_out_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
373  const vtkEdgeType&, ptrdiff_t>
374 {
375 public:
376  explicit vtk_out_edge_pointer_iterator(vtkGraph* g = 0, vtkIdType v = 0, bool end = false)
377  : vertex(v)
378  , iter(nullptr)
379  {
380  if (g)
381  {
382  vtkIdType nedges;
383  g->GetOutEdges(vertex, iter, nedges);
384  if (end)
385  {
386  iter += nedges;
387  }
388  }
389  RecalculateEdge();
390  }
391 
392 private:
393  const vtkEdgeType& dereference() const
394  {
395  assert(iter);
396  return edge;
397  }
398 
399  bool equal(const vtk_out_edge_pointer_iterator& other) const { return iter == other.iter; }
400 
401  void increment()
402  {
403  iter++;
404  RecalculateEdge();
405  }
406 
407  void decrement()
408  {
409  iter--;
410  RecalculateEdge();
411  }
412 
413  void RecalculateEdge()
414  {
415  if (iter)
416  {
417  edge = vtkEdgeType(vertex, iter->Target, iter->Id);
418  }
419  }
420 
421  vtkIdType vertex;
422  const vtkOutEdgeType* iter;
423  vtkEdgeType edge;
424 
425  friend class iterator_core_access;
426 };
427 
429  : public iterator_facade<vtk_in_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
430  const vtkEdgeType&, ptrdiff_t>
431 {
432 public:
433  explicit vtk_in_edge_pointer_iterator(vtkGraph* g = 0, vtkIdType v = 0, bool end = false)
434  : vertex(v)
435  , iter(nullptr)
436  {
437  if (g)
438  {
439  vtkIdType nedges;
440  g->GetInEdges(vertex, iter, nedges);
441  if (end)
442  {
443  iter += nedges;
444  }
445  }
446  RecalculateEdge();
447  }
448 
449 private:
450  const vtkEdgeType& dereference() const
451  {
452  assert(iter);
453  return edge;
454  }
455 
456  bool equal(const vtk_in_edge_pointer_iterator& other) const { return iter == other.iter; }
457 
458  void increment()
459  {
460  iter++;
461  RecalculateEdge();
462  }
463 
464  void decrement()
465  {
466  iter--;
467  RecalculateEdge();
468  }
469 
470  void RecalculateEdge()
471  {
472  if (iter)
473  {
474  edge = vtkEdgeType(iter->Source, vertex, iter->Id);
475  }
476  }
477 
478  vtkIdType vertex;
479  const vtkInEdgeType* iter;
480  vtkEdgeType edge;
481 
482  friend class iterator_core_access;
483 };
484 
485 //===========================================================================
486 // vtkGraph
487 // VertexAndEdgeListGraphConcept
488 // BidirectionalGraphConcept
489 // AdjacencyGraphConcept
490 VTK_ABI_NAMESPACE_BEGIN
491 
493  : public virtual bidirectional_graph_tag
494  , public virtual edge_list_graph_tag
495  , public virtual vertex_list_graph_tag
496  , public virtual adjacency_graph_tag
497 {
498 };
499 
500 VTK_ABI_NAMESPACE_END
501 
502 template <>
503 struct graph_traits<vtkGraph*>
504 {
506  static vertex_descriptor null_vertex() { return -1; }
508  static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); }
511 
514 
515  typedef allow_parallel_edge_tag edge_parallel_category;
520 
523 };
524 
525 #if BOOST_VERSION >= 104500
526 template <>
527 struct graph_property_type<vtkGraph*>
528 {
529  typedef no_property type;
530 };
531 #endif
532 
533 template <>
534 struct vertex_property_type<vtkGraph*>
535 {
536  typedef no_property type;
537 };
538 
539 template <>
540 struct edge_property_type<vtkGraph*>
541 {
542  typedef no_property type;
543 };
544 
545 #if BOOST_VERSION >= 104500
546 template <>
547 struct graph_bundle_type<vtkGraph*>
548 {
549  typedef no_property type;
550 };
551 #endif
552 
553 template <>
554 struct vertex_bundle_type<vtkGraph*>
555 {
556  typedef no_property type;
557 };
558 
559 template <>
560 struct edge_bundle_type<vtkGraph*>
561 {
562  typedef no_property type;
563 };
564 
565 inline bool has_no_edges(vtkGraph* g)
566 {
567  return ((g->GetNumberOfEdges() > 0) ? false : true);
568 }
569 
571 {
573  {
575  }
577  {
579  }
580 }
581 
582 //===========================================================================
583 // vtkDirectedGraph
584 
585 template <>
587 {
588  typedef directed_tag directed_category;
589 };
590 
591 // The graph_traits for a const graph are the same as a non-const graph.
592 template <>
594 {
595 };
596 
597 // The graph_traits for a const graph are the same as a non-const graph.
598 template <>
600 {
601 };
602 
603 #if BOOST_VERSION >= 104500
604 // Internal graph properties
605 template <>
606 struct graph_property_type<vtkDirectedGraph*> : graph_property_type<vtkGraph*>
607 {
608 };
609 
610 // Internal graph properties
611 template <>
612 struct graph_property_type<vtkDirectedGraph* const> : graph_property_type<vtkGraph*>
613 {
614 };
615 #endif
616 
617 // Internal vertex properties
618 template <>
619 struct vertex_property_type<vtkDirectedGraph*> : vertex_property_type<vtkGraph*>
620 {
621 };
622 
623 // Internal vertex properties
624 template <>
625 struct vertex_property_type<vtkDirectedGraph* const> : vertex_property_type<vtkGraph*>
626 {
627 };
628 
629 // Internal edge properties
630 template <>
631 struct edge_property_type<vtkDirectedGraph*> : edge_property_type<vtkGraph*>
632 {
633 };
634 
635 // Internal edge properties
636 template <>
637 struct edge_property_type<vtkDirectedGraph* const> : edge_property_type<vtkGraph*>
638 {
639 };
640 
641 #if BOOST_VERSION >= 104500
642 // Internal graph properties
643 template <>
644 struct graph_bundle_type<vtkDirectedGraph*> : graph_bundle_type<vtkGraph*>
645 {
646 };
647 
648 // Internal graph properties
649 template <>
650 struct graph_bundle_type<vtkDirectedGraph* const> : graph_bundle_type<vtkGraph*>
651 {
652 };
653 #endif
654 
655 // Internal vertex properties
656 template <>
657 struct vertex_bundle_type<vtkDirectedGraph*> : vertex_bundle_type<vtkGraph*>
658 {
659 };
660 
661 // Internal vertex properties
662 template <>
663 struct vertex_bundle_type<vtkDirectedGraph* const> : vertex_bundle_type<vtkGraph*>
664 {
665 };
666 
667 // Internal edge properties
668 template <>
670 {
671 };
672 
673 // Internal edge properties
674 template <>
675 struct edge_bundle_type<vtkDirectedGraph* const> : edge_bundle_type<vtkGraph*>
676 {
677 };
678 
679 //===========================================================================
680 // vtkTree
681 
682 template <>
684 {
685 };
686 
687 // The graph_traits for a const graph are the same as a non-const graph.
688 template <>
689 struct graph_traits<const vtkTree*> : graph_traits<vtkTree*>
690 {
691 };
692 
693 // The graph_traits for a const graph are the same as a non-const graph.
694 template <>
695 struct graph_traits<vtkTree* const> : graph_traits<vtkTree*>
696 {
697 };
698 
699 //===========================================================================
700 // vtkUndirectedGraph
701 template <>
703 {
704  typedef undirected_tag directed_category;
705 };
706 
707 // The graph_traits for a const graph are the same as a non-const graph.
708 template <>
710 {
711 };
712 
713 // The graph_traits for a const graph are the same as a non-const graph.
714 template <>
716 {
717 };
718 
719 #if BOOST_VERSION >= 104500
720 // Internal graph properties
721 template <>
722 struct graph_property_type<vtkUndirectedGraph*> : graph_property_type<vtkGraph*>
723 {
724 };
725 
726 // Internal graph properties
727 template <>
728 struct graph_property_type<vtkUndirectedGraph* const> : graph_property_type<vtkGraph*>
729 {
730 };
731 #endif
732 
733 // Internal vertex properties
734 template <>
736 {
737 };
738 
739 // Internal vertex properties
740 template <>
741 struct vertex_property_type<vtkUndirectedGraph* const> : vertex_property_type<vtkGraph*>
742 {
743 };
744 
745 // Internal edge properties
746 template <>
748 {
749 };
750 
751 // Internal edge properties
752 template <>
753 struct edge_property_type<vtkUndirectedGraph* const> : edge_property_type<vtkGraph*>
754 {
755 };
756 
757 #if BOOST_VERSION >= 104500
758 // Internal graph properties
759 template <>
760 struct graph_bundle_type<vtkUndirectedGraph*> : graph_bundle_type<vtkGraph*>
761 {
762 };
763 
764 // Internal graph properties
765 template <>
766 struct graph_bundle_type<vtkUndirectedGraph* const> : graph_bundle_type<vtkGraph*>
767 {
768 };
769 #endif
770 
771 // Internal vertex properties
772 template <>
774 {
775 };
776 
777 // Internal vertex properties
778 template <>
779 struct vertex_bundle_type<vtkUndirectedGraph* const> : vertex_bundle_type<vtkGraph*>
780 {
781 };
782 
783 // Internal edge properties
784 template <>
786 {
787 };
788 
789 // Internal edge properties
790 template <>
791 struct edge_bundle_type<vtkUndirectedGraph* const> : edge_bundle_type<vtkGraph*>
792 {
793 };
794 
795 //===========================================================================
796 // vtkMutableDirectedGraph
797 
798 template <>
800 {
801 };
802 
803 // The graph_traits for a const graph are the same as a non-const graph.
804 template <>
806 {
807 };
808 
809 // The graph_traits for a const graph are the same as a non-const graph.
810 template <>
812 {
813 };
814 
815 #if BOOST_VERSION >= 104500
816 // Internal graph properties
817 template <>
818 struct graph_property_type<vtkMutableDirectedGraph*> : graph_property_type<vtkDirectedGraph*>
819 {
820 };
821 
822 // Internal graph properties
823 template <>
824 struct graph_property_type<vtkMutableDirectedGraph* const> : graph_property_type<vtkDirectedGraph*>
825 {
826 };
827 #endif
828 
829 // Internal vertex properties
830 template <>
832 {
833 };
834 
835 // Internal vertex properties
836 template <>
837 struct vertex_property_type<vtkMutableDirectedGraph* const>
839 {
840 };
841 
842 // Internal edge properties
843 template <>
845 {
846 };
847 
848 // Internal edge properties
849 template <>
851 {
852 };
853 
854 #if BOOST_VERSION >= 104500
855 // Internal graph properties
856 template <>
857 struct graph_bundle_type<vtkMutableDirectedGraph*> : graph_bundle_type<vtkDirectedGraph*>
858 {
859 };
860 
861 // Internal graph properties
862 template <>
863 struct graph_bundle_type<vtkMutableDirectedGraph* const> : graph_bundle_type<vtkDirectedGraph*>
864 {
865 };
866 #endif
867 
868 // Internal vertex properties
869 template <>
871 {
872 };
873 
874 // Internal vertex properties
875 template <>
877 {
878 };
879 
880 // Internal edge properties
881 template <>
883 {
884 };
885 
886 // Internal edge properties
887 template <>
889 {
890 };
891 
892 //===========================================================================
893 // vtkMutableUndirectedGraph
894 
895 template <>
897 {
898 };
899 
900 // The graph_traits for a const graph are the same as a non-const graph.
901 template <>
903 {
904 };
905 
906 // The graph_traits for a const graph are the same as a non-const graph.
907 template <>
909 {
910 };
911 
912 #if BOOST_VERSION >= 104500
913 // Internal graph properties
914 template <>
915 struct graph_property_type<vtkMutableUndirectedGraph*> : graph_property_type<vtkUndirectedGraph*>
916 {
917 };
918 
919 // Internal graph properties
920 template <>
921 struct graph_property_type<vtkMutableUndirectedGraph* const>
922  : graph_property_type<vtkUndirectedGraph*>
923 {
924 };
925 #endif
926 
927 // Internal vertex properties
928 template <>
930 {
931 };
932 
933 // Internal vertex properties
934 template <>
935 struct vertex_property_type<vtkMutableUndirectedGraph* const>
937 {
938 };
939 
940 // Internal edge properties
941 template <>
943 {
944 };
945 
946 // Internal edge properties
947 template <>
948 struct edge_property_type<vtkMutableUndirectedGraph* const>
950 {
951 };
952 
953 #if BOOST_VERSION >= 104500
954 // Internal graph properties
955 template <>
956 struct graph_bundle_type<vtkMutableUndirectedGraph*> : graph_bundle_type<vtkUndirectedGraph*>
957 {
958 };
959 
960 // Internal graph properties
961 template <>
962 struct graph_bundle_type<vtkMutableUndirectedGraph* const> : graph_bundle_type<vtkUndirectedGraph*>
963 {
964 };
965 #endif
966 
967 // Internal vertex properties
968 template <>
970 {
971 };
972 
973 // Internal vertex properties
974 template <>
975 struct vertex_bundle_type<vtkMutableUndirectedGraph* const>
977 {
978 };
979 
980 // Internal edge properties
981 template <>
983 {
984 };
985 
986 // Internal edge properties
987 template <>
989 {
990 };
991 
992 //===========================================================================
993 // API implementation
994 template <>
995 class vertex_property<vtkGraph*>
996 {
997 public:
998  typedef vtkIdType type;
999 };
1000 
1001 template <>
1002 class edge_property<vtkGraph*>
1003 {
1004 public:
1005  typedef vtkIdType type;
1006 };
1007 } // end namespace boost
1008 
1011 {
1012  return e.Source;
1013 }
1014 
1017 {
1018  return e.Target;
1019 }
1020 
1021 inline std::pair<boost::graph_traits<vtkGraph*>::vertex_iterator,
1024 {
1026  vtkIdType start = 0;
1028  {
1030  start = helper->MakeDistributedId(rank, start);
1031  }
1032 
1033  return std::make_pair(Iter(start), Iter(start + g->GetNumberOfVertices()));
1034 }
1035 
1036 inline std::pair<boost::graph_traits<vtkGraph*>::edge_iterator,
1039 {
1041  return std::make_pair(Iter(g), Iter(g, g->GetNumberOfVertices()));
1042 }
1043 
1044 inline std::pair<boost::graph_traits<vtkGraph*>::out_edge_iterator,
1047 {
1049  std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
1050  return p;
1051 }
1052 
1053 inline std::pair<boost::graph_traits<vtkGraph*>::in_edge_iterator,
1056 {
1058  std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
1059  return p;
1060 }
1061 
1062 inline std::pair<boost::graph_traits<vtkGraph*>::adjacency_iterator,
1065 {
1068  std::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g);
1069  return std::make_pair(Iter(out.first, &g), Iter(out.second, &g));
1070 }
1071 
1073 {
1074  return g->GetNumberOfVertices();
1075 }
1076 
1078 {
1079  return g->GetNumberOfEdges();
1080 }
1081 
1084 {
1085  return g->GetOutDegree(u);
1086 }
1087 
1090 {
1091  return g->GetInDegree(u);
1092 }
1093 
1096 {
1097  return g->GetDegree(u);
1098 }
1099 
1102 {
1103  return g->AddVertex();
1104 }
1105 
1106 inline std::pair<boost::graph_traits<vtkMutableDirectedGraph*>::edge_descriptor, bool> add_edge(
1109 {
1111  return std::make_pair(e, true);
1112 }
1113 
1116 {
1117  return g->AddVertex();
1118 }
1119 
1120 inline std::pair<boost::graph_traits<vtkMutableUndirectedGraph*>::edge_descriptor, bool> add_edge(
1124 {
1126  return std::make_pair(e, true);
1127 }
1128 
1129 namespace boost
1130 {
1131 VTK_ABI_NAMESPACE_BEGIN
1132 //===========================================================================
1133 // An edge map for vtkGraph.
1134 // This is a common input needed for algorithms.
1135 
1137 {
1138 };
1139 
1140 VTK_ABI_NAMESPACE_END
1141 
1142 template <>
1144 {
1148  typedef readable_property_map_tag category;
1149 };
1150 
1153 {
1154  return key.Id;
1155 }
1156 
1157 //===========================================================================
1158 // Helper for vtkGraph edge property maps
1159 // Automatically converts boost edge ids to vtkGraph edge ids.
1160 
1161 VTK_ABI_NAMESPACE_BEGIN
1162 template <typename PMap>
1164 {
1165 public:
1167  : pmap(m)
1168  {
1169  }
1170  PMap pmap;
1175 
1176  reference operator[](const key_type& key) const { return get(pmap, key.Id); }
1177 };
1178 VTK_ABI_NAMESPACE_END
1179 
1180 template <typename PMap>
1183 {
1184  return get(helper.pmap, key.Id);
1185 }
1186 
1187 template <typename PMap>
1189  const typename property_traits<PMap>::value_type& value)
1190 {
1191  put(helper.pmap, key.Id, value);
1192 }
1193 
1194 //===========================================================================
1195 // Helper for vtkGraph vertex property maps
1196 // Automatically converts boost vertex ids to vtkGraph vertex ids.
1197 
1198 VTK_ABI_NAMESPACE_BEGIN
1199 template <typename PMap>
1201 {
1202 public:
1204  : pmap(m)
1205  {
1206  }
1207  PMap pmap;
1212 
1213  reference operator[](const key_type& key) const { return get(pmap, key); }
1214 };
1215 VTK_ABI_NAMESPACE_END
1216 
1217 template <typename PMap>
1220 {
1221  return get(helper.pmap, key);
1222 }
1223 
1224 template <typename PMap>
1226  const typename property_traits<PMap>::value_type& value)
1227 {
1228  put(helper.pmap, key, value);
1229 }
1230 
1231 //===========================================================================
1232 // An index map for vtkGraph
1233 // This is a common input needed for algorithms
1234 
1235 VTK_ABI_NAMESPACE_BEGIN
1237 {
1238 };
1239 VTK_ABI_NAMESPACE_END
1240 
1241 template <>
1243 {
1247  typedef readable_property_map_tag category;
1248 };
1249 
1252 {
1253  return key;
1254 }
1255 
1256 //===========================================================================
1257 // Helper for vtkGraph property maps
1258 // Automatically multiplies the property value by some value (default 1)
1259 VTK_ABI_NAMESPACE_BEGIN
1260 template <typename PMap>
1262 {
1263 public:
1264  vtkGraphPropertyMapMultiplier(PMap m, float multi = 1)
1265  : pmap(m)
1266  , multiplier(multi)
1267  {
1268  }
1269  PMap pmap;
1270  float multiplier;
1275 };
1276 VTK_ABI_NAMESPACE_END
1277 
1278 template <typename PMap>
1281 {
1282  return multi.multiplier * get(multi.pmap, key);
1283 }
1284 
1285 template <typename PMap>
1287  const typename property_traits<PMap>::key_type& key,
1288  const typename property_traits<PMap>::value_type& value)
1289 {
1290  put(multi.pmap, key, value);
1291 }
1292 
1293 // Allow algorithms to automatically extract vtkGraphIndexMap from a
1294 // VTK graph
1295 template <>
1296 struct property_map<vtkGraph*, vertex_index_t>
1297 {
1300 };
1301 
1302 template <>
1303 struct property_map<vtkDirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1304 {
1305 };
1306 
1307 template <>
1308 struct property_map<vtkUndirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1309 {
1310 };
1311 
1312 inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*)
1313 {
1314  return vtkGraphIndexMap();
1315 }
1316 
1317 template <>
1318 struct property_map<vtkGraph*, edge_index_t>
1319 {
1322 };
1323 
1324 template <>
1325 struct property_map<vtkDirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1326 {
1327 };
1328 
1329 template <>
1330 struct property_map<vtkUndirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1331 {
1332 };
1333 
1334 inline vtkGraphIndexMap get(edge_index_t, vtkGraph*)
1335 {
1336  return vtkGraphIndexMap();
1337 }
1338 
1339 // property_map specializations for const-qualified graphs
1340 template <>
1341 struct property_map<vtkDirectedGraph* const, vertex_index_t>
1343 {
1344 };
1345 
1346 template <>
1347 struct property_map<vtkUndirectedGraph* const, vertex_index_t>
1349 {
1350 };
1351 
1352 template <>
1353 struct property_map<vtkDirectedGraph* const, edge_index_t>
1355 {
1356 };
1357 
1358 template <>
1359 struct property_map<vtkUndirectedGraph* const, edge_index_t>
1361 {
1362 };
1363 } // namespace boost
1364 
1365 #if BOOST_VERSION > 104000
1366 #include <boost/property_map/vector_property_map.hpp>
1367 #else
1368 #include <boost/vector_property_map.hpp>
1369 #endif
1370 
1371 #endif // vtkBoostGraphAdapter_h
1372 // 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=0, vtkIdType v=0)
vtk_in_edge_pointer_iterator(vtkGraph *g=0, vtkIdType v=0, bool end=false)
vtk_out_edge_pointer_iterator(vtkGraph *g=0, 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:166
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:346
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:156
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:171
An undirected graph.
A atomic type representing the union of many types.
Definition: vtkVariant.h:150
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:269
@ value
Definition: vtkX3D.h:232
@ type
Definition: vtkX3D.h:528
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:307
vtkIdType Source
Definition: vtkGraph.h:329
vtkIdType Target
Definition: vtkGraph.h:318
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:327