VTK  9.1.20220518
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 #if defined(_MSC_VER)
168 namespace detail
169 {
172 }
173 #endif
174 }
175 
176 #include <utility> // STL Header
177 
178 #include <boost/config.hpp>
179 #include <boost/version.hpp>
180 
181 #if BOOST_VERSION > 107300 && BOOST_VERSION < 107600
182 #define BOOST_ALLOW_DEPRECATED_HEADERS
183 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
184 #endif
185 
186 #include <boost/graph/adjacency_iterator.hpp>
187 #include <boost/graph/graph_traits.hpp>
188 #include <boost/graph/properties.hpp>
189 #include <boost/iterator/iterator_facade.hpp>
190 
191 // The functions and classes in this file allows the user to
192 // treat a vtkDirectedGraph or vtkUndirectedGraph object
193 // as a boost graph "as is".
194 
195 namespace boost
196 {
197 
199  : public iterator_facade<vtk_vertex_iterator, vtkIdType, bidirectional_traversal_tag,
200  const vtkIdType&, vtkIdType>
201 {
202 public:
204  : index(i)
205  {
206  }
207 
208 private:
209  const vtkIdType& dereference() const { return index; }
210 
211  bool equal(const vtk_vertex_iterator& other) const { return index == other.index; }
212 
213  void increment() { index++; }
214  void decrement() { index--; }
215 
216  vtkIdType index;
217 
218  friend class iterator_core_access;
219 };
220 
222  : public iterator_facade<vtk_edge_iterator, vtkEdgeType, forward_traversal_tag,
223  const vtkEdgeType&, vtkIdType>
224 {
225 public:
226  explicit vtk_edge_iterator(vtkGraph* g = 0, vtkIdType v = 0)
227  : directed(false)
228  , vertex(v)
229  , lastVertex(v)
230  , iter(nullptr)
231  , end(nullptr)
232  , graph(g)
233  {
234  if (graph)
235  {
236  lastVertex = graph->GetNumberOfVertices();
237  }
238 
239  vtkIdType myRank = -1;
240  vtkDistributedGraphHelper* helper = this->graph ? this->graph->GetDistributedGraphHelper() : 0;
241  if (helper)
242  {
243  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
244  vertex = helper->MakeDistributedId(myRank, vertex);
245  lastVertex = helper->MakeDistributedId(myRank, lastVertex);
246  }
247 
248  if (graph != 0)
249  {
250  directed = (vtkDirectedGraph::SafeDownCast(graph) != 0);
251  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
252  {
253  ++vertex;
254  }
255 
256  if (vertex < lastVertex)
257  {
258  // Get the outgoing edges of the first vertex that has outgoing
259  // edges
260  vtkIdType nedges;
261  graph->GetOutEdges(vertex, iter, nedges);
262  if (iter)
263  {
264  end = iter + nedges;
265 
266  if (!directed)
267  {
268  while ( // Skip non-local edges
269  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
270  // Skip entirely-local edges where Source > Target
271  || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
272  vertex > iter->Target))
273  {
274  this->inc();
275  }
276  }
277  }
278  }
279  else
280  {
281  iter = nullptr;
282  }
283  }
284 
285  RecalculateEdge();
286  }
287 
288 private:
289  const vtkEdgeType& dereference() const
290  {
291  assert(iter);
292  return edge;
293  }
294 
295  bool equal(const vtk_edge_iterator& other) const
296  {
297  return vertex == other.vertex && iter == other.iter;
298  }
299 
300  void increment()
301  {
302  inc();
303  if (!directed)
304  {
305  vtkIdType myRank = -1;
306  vtkDistributedGraphHelper* helper =
307  this->graph ? this->graph->GetDistributedGraphHelper() : 0;
308  if (helper)
309  {
310  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
311  }
312 
313  while (iter != 0 &&
314  ( // Skip non-local edges
315  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
316  // Skip entirely-local edges where Source > Target
317  || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
318  vertex > iter->Target)))
319  {
320  inc();
321  }
322  }
323  RecalculateEdge();
324  }
325 
326  void inc()
327  {
328  ++iter;
329  if (iter == end)
330  {
331  // Find a vertex with nonzero out degree.
332  ++vertex;
333  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
334  {
335  ++vertex;
336  }
337 
338  if (vertex < lastVertex)
339  {
340  vtkIdType nedges;
341  graph->GetOutEdges(vertex, iter, nedges);
342  end = iter + nedges;
343  }
344  else
345  {
346  iter = nullptr;
347  }
348  }
349  }
350 
351  void RecalculateEdge()
352  {
353  if (iter)
354  {
355  edge = vtkEdgeType(vertex, iter->Target, iter->Id);
356  }
357  }
358 
359  bool directed;
360  vtkIdType vertex;
361  vtkIdType lastVertex;
362  const vtkOutEdgeType* iter;
363  const vtkOutEdgeType* end;
364  vtkGraph* graph;
365  vtkEdgeType edge;
366 
367  friend class iterator_core_access;
368 };
369 
371  : public iterator_facade<vtk_out_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
372  const vtkEdgeType&, ptrdiff_t>
373 {
374 public:
375  explicit vtk_out_edge_pointer_iterator(vtkGraph* g = 0, vtkIdType v = 0, bool end = false)
376  : vertex(v)
377  , iter(nullptr)
378  {
379  if (g)
380  {
381  vtkIdType nedges;
382  g->GetOutEdges(vertex, iter, nedges);
383  if (end)
384  {
385  iter += nedges;
386  }
387  }
388  RecalculateEdge();
389  }
390 
391 private:
392  const vtkEdgeType& dereference() const
393  {
394  assert(iter);
395  return edge;
396  }
397 
398  bool equal(const vtk_out_edge_pointer_iterator& other) const { return iter == other.iter; }
399 
400  void increment()
401  {
402  iter++;
403  RecalculateEdge();
404  }
405 
406  void decrement()
407  {
408  iter--;
409  RecalculateEdge();
410  }
411 
412  void RecalculateEdge()
413  {
414  if (iter)
415  {
416  edge = vtkEdgeType(vertex, iter->Target, iter->Id);
417  }
418  }
419 
420  vtkIdType vertex;
421  const vtkOutEdgeType* iter;
422  vtkEdgeType edge;
423 
424  friend class iterator_core_access;
425 };
426 
428  : public iterator_facade<vtk_in_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
429  const vtkEdgeType&, ptrdiff_t>
430 {
431 public:
432  explicit vtk_in_edge_pointer_iterator(vtkGraph* g = 0, vtkIdType v = 0, bool end = false)
433  : vertex(v)
434  , iter(nullptr)
435  {
436  if (g)
437  {
438  vtkIdType nedges;
439  g->GetInEdges(vertex, iter, nedges);
440  if (end)
441  {
442  iter += nedges;
443  }
444  }
445  RecalculateEdge();
446  }
447 
448 private:
449  const vtkEdgeType& dereference() const
450  {
451  assert(iter);
452  return edge;
453  }
454 
455  bool equal(const vtk_in_edge_pointer_iterator& other) const { return iter == other.iter; }
456 
457  void increment()
458  {
459  iter++;
460  RecalculateEdge();
461  }
462 
463  void decrement()
464  {
465  iter--;
466  RecalculateEdge();
467  }
468 
469  void RecalculateEdge()
470  {
471  if (iter)
472  {
473  edge = vtkEdgeType(iter->Source, vertex, iter->Id);
474  }
475  }
476 
477  vtkIdType vertex;
478  const vtkInEdgeType* iter;
479  vtkEdgeType edge;
480 
481  friend class iterator_core_access;
482 };
483 
484 //===========================================================================
485 // vtkGraph
486 // VertexAndEdgeListGraphConcept
487 // BidirectionalGraphConcept
488 // AdjacencyGraphConcept
489 
491  : public virtual bidirectional_graph_tag
492  , public virtual edge_list_graph_tag
493  , public virtual vertex_list_graph_tag
494  , public virtual adjacency_graph_tag
495 {
496 };
497 
498 template <>
499 struct graph_traits<vtkGraph*>
500 {
502  static vertex_descriptor null_vertex() { return -1; }
504  static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); }
507 
510 
511  typedef allow_parallel_edge_tag edge_parallel_category;
516 
519 };
520 
521 #if BOOST_VERSION >= 104500
522 template <>
523 struct graph_property_type<vtkGraph*>
524 {
525  typedef no_property type;
526 };
527 #endif
528 
529 template <>
530 struct vertex_property_type<vtkGraph*>
531 {
532  typedef no_property type;
533 };
534 
535 template <>
536 struct edge_property_type<vtkGraph*>
537 {
538  typedef no_property type;
539 };
540 
541 #if BOOST_VERSION >= 104500
542 template <>
543 struct graph_bundle_type<vtkGraph*>
544 {
545  typedef no_property type;
546 };
547 #endif
548 
549 template <>
550 struct vertex_bundle_type<vtkGraph*>
551 {
552  typedef no_property type;
553 };
554 
555 template <>
556 struct edge_bundle_type<vtkGraph*>
557 {
558  typedef no_property type;
559 };
560 
561 inline bool has_no_edges(vtkGraph* g)
562 {
563  return ((g->GetNumberOfEdges() > 0) ? false : true);
564 }
565 
567 {
569  {
571  }
573  {
575  }
576 }
577 
578 //===========================================================================
579 // vtkDirectedGraph
580 
581 template <>
583 {
584  typedef directed_tag directed_category;
585 };
586 
587 // The graph_traits for a const graph are the same as a non-const graph.
588 template <>
590 {
591 };
592 
593 // The graph_traits for a const graph are the same as a non-const graph.
594 template <>
596 {
597 };
598 
599 #if BOOST_VERSION >= 104500
600 // Internal graph properties
601 template <>
602 struct graph_property_type<vtkDirectedGraph*> : graph_property_type<vtkGraph*>
603 {
604 };
605 
606 // Internal graph properties
607 template <>
608 struct graph_property_type<vtkDirectedGraph* const> : graph_property_type<vtkGraph*>
609 {
610 };
611 #endif
612 
613 // Internal vertex properties
614 template <>
615 struct vertex_property_type<vtkDirectedGraph*> : vertex_property_type<vtkGraph*>
616 {
617 };
618 
619 // Internal vertex properties
620 template <>
621 struct vertex_property_type<vtkDirectedGraph* const> : vertex_property_type<vtkGraph*>
622 {
623 };
624 
625 // Internal edge properties
626 template <>
627 struct edge_property_type<vtkDirectedGraph*> : edge_property_type<vtkGraph*>
628 {
629 };
630 
631 // Internal edge properties
632 template <>
633 struct edge_property_type<vtkDirectedGraph* const> : edge_property_type<vtkGraph*>
634 {
635 };
636 
637 #if BOOST_VERSION >= 104500
638 // Internal graph properties
639 template <>
640 struct graph_bundle_type<vtkDirectedGraph*> : graph_bundle_type<vtkGraph*>
641 {
642 };
643 
644 // Internal graph properties
645 template <>
646 struct graph_bundle_type<vtkDirectedGraph* const> : graph_bundle_type<vtkGraph*>
647 {
648 };
649 #endif
650 
651 // Internal vertex properties
652 template <>
653 struct vertex_bundle_type<vtkDirectedGraph*> : vertex_bundle_type<vtkGraph*>
654 {
655 };
656 
657 // Internal vertex properties
658 template <>
659 struct vertex_bundle_type<vtkDirectedGraph* const> : vertex_bundle_type<vtkGraph*>
660 {
661 };
662 
663 // Internal edge properties
664 template <>
666 {
667 };
668 
669 // Internal edge properties
670 template <>
671 struct edge_bundle_type<vtkDirectedGraph* const> : edge_bundle_type<vtkGraph*>
672 {
673 };
674 
675 //===========================================================================
676 // vtkTree
677 
678 template <>
680 {
681 };
682 
683 // The graph_traits for a const graph are the same as a non-const graph.
684 template <>
685 struct graph_traits<const vtkTree*> : graph_traits<vtkTree*>
686 {
687 };
688 
689 // The graph_traits for a const graph are the same as a non-const graph.
690 template <>
691 struct graph_traits<vtkTree* const> : graph_traits<vtkTree*>
692 {
693 };
694 
695 //===========================================================================
696 // vtkUndirectedGraph
697 template <>
699 {
700  typedef undirected_tag directed_category;
701 };
702 
703 // The graph_traits for a const graph are the same as a non-const graph.
704 template <>
706 {
707 };
708 
709 // The graph_traits for a const graph are the same as a non-const graph.
710 template <>
712 {
713 };
714 
715 #if BOOST_VERSION >= 104500
716 // Internal graph properties
717 template <>
718 struct graph_property_type<vtkUndirectedGraph*> : graph_property_type<vtkGraph*>
719 {
720 };
721 
722 // Internal graph properties
723 template <>
724 struct graph_property_type<vtkUndirectedGraph* const> : graph_property_type<vtkGraph*>
725 {
726 };
727 #endif
728 
729 // Internal vertex properties
730 template <>
732 {
733 };
734 
735 // Internal vertex properties
736 template <>
737 struct vertex_property_type<vtkUndirectedGraph* const> : vertex_property_type<vtkGraph*>
738 {
739 };
740 
741 // Internal edge properties
742 template <>
744 {
745 };
746 
747 // Internal edge properties
748 template <>
749 struct edge_property_type<vtkUndirectedGraph* const> : edge_property_type<vtkGraph*>
750 {
751 };
752 
753 #if BOOST_VERSION >= 104500
754 // Internal graph properties
755 template <>
756 struct graph_bundle_type<vtkUndirectedGraph*> : graph_bundle_type<vtkGraph*>
757 {
758 };
759 
760 // Internal graph properties
761 template <>
762 struct graph_bundle_type<vtkUndirectedGraph* const> : graph_bundle_type<vtkGraph*>
763 {
764 };
765 #endif
766 
767 // Internal vertex properties
768 template <>
770 {
771 };
772 
773 // Internal vertex properties
774 template <>
775 struct vertex_bundle_type<vtkUndirectedGraph* const> : vertex_bundle_type<vtkGraph*>
776 {
777 };
778 
779 // Internal edge properties
780 template <>
782 {
783 };
784 
785 // Internal edge properties
786 template <>
787 struct edge_bundle_type<vtkUndirectedGraph* const> : edge_bundle_type<vtkGraph*>
788 {
789 };
790 
791 //===========================================================================
792 // vtkMutableDirectedGraph
793 
794 template <>
796 {
797 };
798 
799 // The graph_traits for a const graph are the same as a non-const graph.
800 template <>
802 {
803 };
804 
805 // The graph_traits for a const graph are the same as a non-const graph.
806 template <>
808 {
809 };
810 
811 #if BOOST_VERSION >= 104500
812 // Internal graph properties
813 template <>
814 struct graph_property_type<vtkMutableDirectedGraph*> : graph_property_type<vtkDirectedGraph*>
815 {
816 };
817 
818 // Internal graph properties
819 template <>
820 struct graph_property_type<vtkMutableDirectedGraph* const> : graph_property_type<vtkDirectedGraph*>
821 {
822 };
823 #endif
824 
825 // Internal vertex properties
826 template <>
828 {
829 };
830 
831 // Internal vertex properties
832 template <>
833 struct vertex_property_type<vtkMutableDirectedGraph* const>
835 {
836 };
837 
838 // Internal edge properties
839 template <>
841 {
842 };
843 
844 // Internal edge properties
845 template <>
847 {
848 };
849 
850 #if BOOST_VERSION >= 104500
851 // Internal graph properties
852 template <>
853 struct graph_bundle_type<vtkMutableDirectedGraph*> : graph_bundle_type<vtkDirectedGraph*>
854 {
855 };
856 
857 // Internal graph properties
858 template <>
859 struct graph_bundle_type<vtkMutableDirectedGraph* const> : graph_bundle_type<vtkDirectedGraph*>
860 {
861 };
862 #endif
863 
864 // Internal vertex properties
865 template <>
867 {
868 };
869 
870 // Internal vertex properties
871 template <>
873 {
874 };
875 
876 // Internal edge properties
877 template <>
879 {
880 };
881 
882 // Internal edge properties
883 template <>
885 {
886 };
887 
888 //===========================================================================
889 // vtkMutableUndirectedGraph
890 
891 template <>
893 {
894 };
895 
896 // The graph_traits for a const graph are the same as a non-const graph.
897 template <>
899 {
900 };
901 
902 // The graph_traits for a const graph are the same as a non-const graph.
903 template <>
905 {
906 };
907 
908 #if BOOST_VERSION >= 104500
909 // Internal graph properties
910 template <>
911 struct graph_property_type<vtkMutableUndirectedGraph*> : graph_property_type<vtkUndirectedGraph*>
912 {
913 };
914 
915 // Internal graph properties
916 template <>
917 struct graph_property_type<vtkMutableUndirectedGraph* const>
918  : graph_property_type<vtkUndirectedGraph*>
919 {
920 };
921 #endif
922 
923 // Internal vertex properties
924 template <>
926 {
927 };
928 
929 // Internal vertex properties
930 template <>
931 struct vertex_property_type<vtkMutableUndirectedGraph* const>
933 {
934 };
935 
936 // Internal edge properties
937 template <>
939 {
940 };
941 
942 // Internal edge properties
943 template <>
944 struct edge_property_type<vtkMutableUndirectedGraph* const>
946 {
947 };
948 
949 #if BOOST_VERSION >= 104500
950 // Internal graph properties
951 template <>
952 struct graph_bundle_type<vtkMutableUndirectedGraph*> : graph_bundle_type<vtkUndirectedGraph*>
953 {
954 };
955 
956 // Internal graph properties
957 template <>
958 struct graph_bundle_type<vtkMutableUndirectedGraph* const> : graph_bundle_type<vtkUndirectedGraph*>
959 {
960 };
961 #endif
962 
963 // Internal vertex properties
964 template <>
966 {
967 };
968 
969 // Internal vertex properties
970 template <>
971 struct vertex_bundle_type<vtkMutableUndirectedGraph* const>
973 {
974 };
975 
976 // Internal edge properties
977 template <>
979 {
980 };
981 
982 // Internal edge properties
983 template <>
985 {
986 };
987 
988 //===========================================================================
989 // API implementation
990 template <>
991 class vertex_property<vtkGraph*>
992 {
993 public:
994  typedef vtkIdType type;
995 };
996 
997 template <>
998 class edge_property<vtkGraph*>
999 {
1000 public:
1001  typedef vtkIdType type;
1002 };
1003 } // end namespace boost
1004 
1007 {
1008  return e.Source;
1009 }
1010 
1013 {
1014  return e.Target;
1015 }
1016 
1017 inline std::pair<boost::graph_traits<vtkGraph*>::vertex_iterator,
1020 {
1022  vtkIdType start = 0;
1024  {
1026  start = helper->MakeDistributedId(rank, start);
1027  }
1028 
1029  return std::make_pair(Iter(start), Iter(start + g->GetNumberOfVertices()));
1030 }
1031 
1032 inline std::pair<boost::graph_traits<vtkGraph*>::edge_iterator,
1035 {
1037  return std::make_pair(Iter(g), Iter(g, g->GetNumberOfVertices()));
1038 }
1039 
1040 inline std::pair<boost::graph_traits<vtkGraph*>::out_edge_iterator,
1043 {
1045  std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
1046  return p;
1047 }
1048 
1049 inline std::pair<boost::graph_traits<vtkGraph*>::in_edge_iterator,
1052 {
1054  std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
1055  return p;
1056 }
1057 
1058 inline std::pair<boost::graph_traits<vtkGraph*>::adjacency_iterator,
1061 {
1064  std::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g);
1065  return std::make_pair(Iter(out.first, &g), Iter(out.second, &g));
1066 }
1067 
1069 {
1070  return g->GetNumberOfVertices();
1071 }
1072 
1074 {
1075  return g->GetNumberOfEdges();
1076 }
1077 
1080 {
1081  return g->GetOutDegree(u);
1082 }
1083 
1086 {
1087  return g->GetInDegree(u);
1088 }
1089 
1092 {
1093  return g->GetDegree(u);
1094 }
1095 
1098 {
1099  return g->AddVertex();
1100 }
1101 
1102 inline std::pair<boost::graph_traits<vtkMutableDirectedGraph*>::edge_descriptor, bool> add_edge(
1105 {
1107  return std::make_pair(e, true);
1108 }
1109 
1112 {
1113  return g->AddVertex();
1114 }
1115 
1116 inline std::pair<boost::graph_traits<vtkMutableUndirectedGraph*>::edge_descriptor, bool> add_edge(
1120 {
1122  return std::make_pair(e, true);
1123 }
1124 
1125 namespace boost
1126 {
1127 //===========================================================================
1128 // An edge map for vtkGraph.
1129 // This is a common input needed for algorithms.
1130 
1132 {
1133 };
1134 
1135 template <>
1137 {
1141  typedef readable_property_map_tag category;
1142 };
1143 
1146 {
1147  return key.Id;
1148 }
1149 
1150 //===========================================================================
1151 // Helper for vtkGraph edge property maps
1152 // Automatically converts boost edge ids to vtkGraph edge ids.
1153 
1154 template <typename PMap>
1156 {
1157 public:
1159  : pmap(m)
1160  {
1161  }
1162  PMap pmap;
1167 
1168  reference operator[](const key_type& key) const { return get(pmap, key.Id); }
1169 };
1170 
1171 template <typename PMap>
1174 {
1175  return get(helper.pmap, key.Id);
1176 }
1177 
1178 template <typename PMap>
1180  const typename property_traits<PMap>::value_type& value)
1181 {
1182  put(helper.pmap, key.Id, value);
1183 }
1184 
1185 //===========================================================================
1186 // Helper for vtkGraph vertex property maps
1187 // Automatically converts boost vertex ids to vtkGraph vertex ids.
1188 
1189 template <typename PMap>
1191 {
1192 public:
1194  : pmap(m)
1195  {
1196  }
1197  PMap pmap;
1202 
1203  reference operator[](const key_type& key) const { return get(pmap, key); }
1204 };
1205 
1206 template <typename PMap>
1209 {
1210  return get(helper.pmap, key);
1211 }
1212 
1213 template <typename PMap>
1215  const typename property_traits<PMap>::value_type& value)
1216 {
1217  put(helper.pmap, key, value);
1218 }
1219 
1220 //===========================================================================
1221 // An index map for vtkGraph
1222 // This is a common input needed for algorithms
1223 
1225 {
1226 };
1227 
1228 template <>
1230 {
1234  typedef readable_property_map_tag category;
1235 };
1236 
1239 {
1240  return key;
1241 }
1242 
1243 //===========================================================================
1244 // Helper for vtkGraph property maps
1245 // Automatically multiplies the property value by some value (default 1)
1246 template <typename PMap>
1248 {
1249 public:
1250  vtkGraphPropertyMapMultiplier(PMap m, float multi = 1)
1251  : pmap(m)
1252  , multiplier(multi)
1253  {
1254  }
1255  PMap pmap;
1256  float multiplier;
1261 };
1262 
1263 template <typename PMap>
1266 {
1267  return multi.multiplier * get(multi.pmap, key);
1268 }
1269 
1270 template <typename PMap>
1272  const typename property_traits<PMap>::key_type& key,
1273  const typename property_traits<PMap>::value_type& value)
1274 {
1275  put(multi.pmap, key, value);
1276 }
1277 
1278 // Allow algorithms to automatically extract vtkGraphIndexMap from a
1279 // VTK graph
1280 template <>
1281 struct property_map<vtkGraph*, vertex_index_t>
1282 {
1285 };
1286 
1287 template <>
1288 struct property_map<vtkDirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1289 {
1290 };
1291 
1292 template <>
1293 struct property_map<vtkUndirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1294 {
1295 };
1296 
1297 inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*)
1298 {
1299  return vtkGraphIndexMap();
1300 }
1301 
1302 template <>
1303 struct property_map<vtkGraph*, edge_index_t>
1304 {
1307 };
1308 
1309 template <>
1310 struct property_map<vtkDirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1311 {
1312 };
1313 
1314 template <>
1315 struct property_map<vtkUndirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1316 {
1317 };
1318 
1319 inline vtkGraphIndexMap get(edge_index_t, vtkGraph*)
1320 {
1321  return vtkGraphIndexMap();
1322 }
1323 
1324 // property_map specializations for const-qualified graphs
1325 template <>
1326 struct property_map<vtkDirectedGraph* const, vertex_index_t>
1328 {
1329 };
1330 
1331 template <>
1332 struct property_map<vtkUndirectedGraph* const, vertex_index_t>
1334 {
1335 };
1336 
1337 template <>
1338 struct property_map<vtkDirectedGraph* const, edge_index_t>
1340 {
1341 };
1342 
1343 template <>
1344 struct property_map<vtkUndirectedGraph* const, edge_index_t>
1346 {
1347 };
1348 } // namespace boost
1349 
1350 #if BOOST_VERSION > 104000
1351 #include <boost/property_map/vector_property_map.hpp>
1352 #else
1353 #include <boost/vector_property_map.hpp>
1354 #endif
1355 
1356 #endif // vtkBoostGraphAdapter_h
1357 // 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:165
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:345
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:155
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:170
An undirected graph.
A atomic type representing the union of many types.
Definition: vtkVariant.h:159
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:263
@ value
Definition: vtkX3D.h:226
@ type
Definition: vtkX3D.h:522
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:306
vtkIdType Source
Definition: vtkGraph.h:328
vtkIdType Target
Definition: vtkGraph.h:317
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:332