VTK  9.2.6
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 -------------------------------------------------------------------------*/
39 #ifndef vtkBoostGraphAdapter_h
40 #define vtkBoostGraphAdapter_h
41 
42 #include "vtkAbstractArray.h"
43 #include "vtkDataArray.h"
44 #include "vtkDataObject.h"
45 #include "vtkDirectedGraph.h"
47 #include "vtkDoubleArray.h"
48 #include "vtkFloatArray.h"
49 #include "vtkIdTypeArray.h"
50 #include "vtkInformation.h"
51 #include "vtkIntArray.h"
54 #include "vtkTree.h"
55 #include "vtkUndirectedGraph.h"
56 #include "vtkVariant.h"
57 
58 #include <boost/version.hpp>
59 
60 namespace boost
61 {
62 //===========================================================================
63 // VTK arrays as property maps
64 // These need to be defined before including other boost stuff
65 
66 // Forward declarations are required here, so that we aren't forced
67 // to include boost/property_map.hpp.
68 template <typename>
70 struct read_write_property_map_tag;
71 
72 #define vtkPropertyMapMacro(T, V) \
73  template <> \
74  struct property_traits<T*> \
75  { \
76  typedef V value_type; \
77  typedef V reference; \
78  typedef vtkIdType key_type; \
79  typedef read_write_property_map_tag category; \
80  }; \
81  \
82  inline property_traits<T*>::reference get(T* const& arr, property_traits<T*>::key_type key) \
83  { \
84  return arr->GetValue(key); \
85  } \
86  \
87  inline void put( \
88  T* arr, property_traits<T*>::key_type key, const property_traits<T*>::value_type& value) \
89  { \
90  arr->InsertValue(key, value); \
91  }
92 
97 
98 // vtkDataArray
99 template <>
101 {
102  typedef double value_type;
103  typedef double reference;
105  typedef read_write_property_map_tag category;
106 };
107 
108 inline double get(vtkDataArray* const& arr, vtkIdType key)
109 {
110  return arr->GetTuple1(key);
111 }
112 
113 inline void put(vtkDataArray* arr, vtkIdType key, const double& value)
114 {
115  arr->SetTuple1(key, value);
116 }
117 
118 // vtkAbstractArray as a property map of vtkVariants
119 template <>
121 {
125  typedef read_write_property_map_tag category;
126 };
127 
129 {
130  return arr->GetVariantValue(key);
131 }
132 
133 inline void put(vtkAbstractArray* arr, vtkIdType key, const vtkVariant& value)
134 {
136 }
137 #if defined(_MSC_VER)
138 namespace detail
139 {
142 }
143 #endif
144 }
145 
146 #include <utility> // STL Header
147 
148 #include <boost/config.hpp>
149 #include <boost/version.hpp>
150 
151 #if BOOST_VERSION > 107300 && BOOST_VERSION < 107600
152 #define BOOST_ALLOW_DEPRECATED_HEADERS
153 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
154 #endif
155 
156 #include <boost/graph/adjacency_iterator.hpp>
157 #include <boost/graph/graph_traits.hpp>
158 #include <boost/graph/properties.hpp>
159 #include <boost/iterator/iterator_facade.hpp>
160 
161 // The functions and classes in this file allows the user to
162 // treat a vtkDirectedGraph or vtkUndirectedGraph object
163 // as a boost graph "as is".
164 
165 namespace boost
166 {
167 
169  : public iterator_facade<vtk_vertex_iterator, vtkIdType, bidirectional_traversal_tag,
170  const vtkIdType&, vtkIdType>
171 {
172 public:
174  : index(i)
175  {
176  }
177 
178 private:
179  const vtkIdType& dereference() const { return index; }
180 
181  bool equal(const vtk_vertex_iterator& other) const { return index == other.index; }
182 
183  void increment() { index++; }
184  void decrement() { index--; }
185 
186  vtkIdType index;
187 
188  friend class iterator_core_access;
189 };
190 
192  : public iterator_facade<vtk_edge_iterator, vtkEdgeType, forward_traversal_tag,
193  const vtkEdgeType&, vtkIdType>
194 {
195 public:
196  explicit vtk_edge_iterator(vtkGraph* g = 0, vtkIdType v = 0)
197  : directed(false)
198  , vertex(v)
199  , lastVertex(v)
200  , iter(nullptr)
201  , end(nullptr)
202  , graph(g)
203  {
204  if (graph)
205  {
206  lastVertex = graph->GetNumberOfVertices();
207  }
208 
209  vtkIdType myRank = -1;
210  vtkDistributedGraphHelper* helper = this->graph ? this->graph->GetDistributedGraphHelper() : 0;
211  if (helper)
212  {
213  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
214  vertex = helper->MakeDistributedId(myRank, vertex);
215  lastVertex = helper->MakeDistributedId(myRank, lastVertex);
216  }
217 
218  if (graph != 0)
219  {
220  directed = (vtkDirectedGraph::SafeDownCast(graph) != 0);
221  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
222  {
223  ++vertex;
224  }
225 
226  if (vertex < lastVertex)
227  {
228  // Get the outgoing edges of the first vertex that has outgoing
229  // edges
230  vtkIdType nedges;
231  graph->GetOutEdges(vertex, iter, nedges);
232  if (iter)
233  {
234  end = iter + nedges;
235 
236  if (!directed)
237  {
238  while ( // Skip non-local edges
239  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
240  // Skip entirely-local edges where Source > Target
241  || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
242  vertex > iter->Target))
243  {
244  this->inc();
245  }
246  }
247  }
248  }
249  else
250  {
251  iter = nullptr;
252  }
253  }
254 
255  RecalculateEdge();
256  }
257 
258 private:
259  const vtkEdgeType& dereference() const
260  {
261  assert(iter);
262  return edge;
263  }
264 
265  bool equal(const vtk_edge_iterator& other) const
266  {
267  return vertex == other.vertex && iter == other.iter;
268  }
269 
270  void increment()
271  {
272  inc();
273  if (!directed)
274  {
275  vtkIdType myRank = -1;
276  vtkDistributedGraphHelper* helper =
277  this->graph ? this->graph->GetDistributedGraphHelper() : 0;
278  if (helper)
279  {
280  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
281  }
282 
283  while (iter != 0 &&
284  ( // Skip non-local edges
285  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
286  // Skip entirely-local edges where Source > Target
287  || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
288  vertex > iter->Target)))
289  {
290  inc();
291  }
292  }
293  RecalculateEdge();
294  }
295 
296  void inc()
297  {
298  ++iter;
299  if (iter == end)
300  {
301  // Find a vertex with nonzero out degree.
302  ++vertex;
303  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
304  {
305  ++vertex;
306  }
307 
308  if (vertex < lastVertex)
309  {
310  vtkIdType nedges;
311  graph->GetOutEdges(vertex, iter, nedges);
312  end = iter + nedges;
313  }
314  else
315  {
316  iter = nullptr;
317  }
318  }
319  }
320 
321  void RecalculateEdge()
322  {
323  if (iter)
324  {
325  edge = vtkEdgeType(vertex, iter->Target, iter->Id);
326  }
327  }
328 
329  bool directed;
330  vtkIdType vertex;
331  vtkIdType lastVertex;
332  const vtkOutEdgeType* iter;
333  const vtkOutEdgeType* end;
334  vtkGraph* graph;
335  vtkEdgeType edge;
336 
337  friend class iterator_core_access;
338 };
339 
341  : public iterator_facade<vtk_out_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
342  const vtkEdgeType&, ptrdiff_t>
343 {
344 public:
345  explicit vtk_out_edge_pointer_iterator(vtkGraph* g = 0, vtkIdType v = 0, bool end = false)
346  : vertex(v)
347  , iter(nullptr)
348  {
349  if (g)
350  {
351  vtkIdType nedges;
352  g->GetOutEdges(vertex, iter, nedges);
353  if (end)
354  {
355  iter += nedges;
356  }
357  }
358  RecalculateEdge();
359  }
360 
361 private:
362  const vtkEdgeType& dereference() const
363  {
364  assert(iter);
365  return edge;
366  }
367 
368  bool equal(const vtk_out_edge_pointer_iterator& other) const { return iter == other.iter; }
369 
370  void increment()
371  {
372  iter++;
373  RecalculateEdge();
374  }
375 
376  void decrement()
377  {
378  iter--;
379  RecalculateEdge();
380  }
381 
382  void RecalculateEdge()
383  {
384  if (iter)
385  {
386  edge = vtkEdgeType(vertex, iter->Target, iter->Id);
387  }
388  }
389 
390  vtkIdType vertex;
391  const vtkOutEdgeType* iter;
392  vtkEdgeType edge;
393 
394  friend class iterator_core_access;
395 };
396 
398  : public iterator_facade<vtk_in_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
399  const vtkEdgeType&, ptrdiff_t>
400 {
401 public:
402  explicit vtk_in_edge_pointer_iterator(vtkGraph* g = 0, vtkIdType v = 0, bool end = false)
403  : vertex(v)
404  , iter(nullptr)
405  {
406  if (g)
407  {
408  vtkIdType nedges;
409  g->GetInEdges(vertex, iter, nedges);
410  if (end)
411  {
412  iter += nedges;
413  }
414  }
415  RecalculateEdge();
416  }
417 
418 private:
419  const vtkEdgeType& dereference() const
420  {
421  assert(iter);
422  return edge;
423  }
424 
425  bool equal(const vtk_in_edge_pointer_iterator& other) const { return iter == other.iter; }
426 
427  void increment()
428  {
429  iter++;
430  RecalculateEdge();
431  }
432 
433  void decrement()
434  {
435  iter--;
436  RecalculateEdge();
437  }
438 
439  void RecalculateEdge()
440  {
441  if (iter)
442  {
443  edge = vtkEdgeType(iter->Source, vertex, iter->Id);
444  }
445  }
446 
447  vtkIdType vertex;
448  const vtkInEdgeType* iter;
449  vtkEdgeType edge;
450 
451  friend class iterator_core_access;
452 };
453 
454 //===========================================================================
455 // vtkGraph
456 // VertexAndEdgeListGraphConcept
457 // BidirectionalGraphConcept
458 // AdjacencyGraphConcept
459 
461  : public virtual bidirectional_graph_tag
462  , public virtual edge_list_graph_tag
463  , public virtual vertex_list_graph_tag
464  , public virtual adjacency_graph_tag
465 {
466 };
467 
468 template <>
469 struct graph_traits<vtkGraph*>
470 {
472  static vertex_descriptor null_vertex() { return -1; }
474  static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); }
477 
480 
481  typedef allow_parallel_edge_tag edge_parallel_category;
486 
489 };
490 
491 #if BOOST_VERSION >= 104500
492 template <>
493 struct graph_property_type<vtkGraph*>
494 {
495  typedef no_property type;
496 };
497 #endif
498 
499 template <>
500 struct vertex_property_type<vtkGraph*>
501 {
502  typedef no_property type;
503 };
504 
505 template <>
506 struct edge_property_type<vtkGraph*>
507 {
508  typedef no_property type;
509 };
510 
511 #if BOOST_VERSION >= 104500
512 template <>
513 struct graph_bundle_type<vtkGraph*>
514 {
515  typedef no_property type;
516 };
517 #endif
518 
519 template <>
520 struct vertex_bundle_type<vtkGraph*>
521 {
522  typedef no_property type;
523 };
524 
525 template <>
526 struct edge_bundle_type<vtkGraph*>
527 {
528  typedef no_property type;
529 };
530 
531 inline bool has_no_edges(vtkGraph* g)
532 {
533  return ((g->GetNumberOfEdges() > 0) ? false : true);
534 }
535 
537 {
539  {
541  }
543  {
545  }
546 }
547 
548 //===========================================================================
549 // vtkDirectedGraph
550 
551 template <>
553 {
554  typedef directed_tag directed_category;
555 };
556 
557 // The graph_traits for a const graph are the same as a non-const graph.
558 template <>
560 {
561 };
562 
563 // The graph_traits for a const graph are the same as a non-const graph.
564 template <>
566 {
567 };
568 
569 #if BOOST_VERSION >= 104500
570 // Internal graph properties
571 template <>
572 struct graph_property_type<vtkDirectedGraph*> : graph_property_type<vtkGraph*>
573 {
574 };
575 
576 // Internal graph properties
577 template <>
578 struct graph_property_type<vtkDirectedGraph* const> : graph_property_type<vtkGraph*>
579 {
580 };
581 #endif
582 
583 // Internal vertex properties
584 template <>
585 struct vertex_property_type<vtkDirectedGraph*> : vertex_property_type<vtkGraph*>
586 {
587 };
588 
589 // Internal vertex properties
590 template <>
591 struct vertex_property_type<vtkDirectedGraph* const> : vertex_property_type<vtkGraph*>
592 {
593 };
594 
595 // Internal edge properties
596 template <>
597 struct edge_property_type<vtkDirectedGraph*> : edge_property_type<vtkGraph*>
598 {
599 };
600 
601 // Internal edge properties
602 template <>
603 struct edge_property_type<vtkDirectedGraph* const> : edge_property_type<vtkGraph*>
604 {
605 };
606 
607 #if BOOST_VERSION >= 104500
608 // Internal graph properties
609 template <>
610 struct graph_bundle_type<vtkDirectedGraph*> : graph_bundle_type<vtkGraph*>
611 {
612 };
613 
614 // Internal graph properties
615 template <>
616 struct graph_bundle_type<vtkDirectedGraph* const> : graph_bundle_type<vtkGraph*>
617 {
618 };
619 #endif
620 
621 // Internal vertex properties
622 template <>
623 struct vertex_bundle_type<vtkDirectedGraph*> : vertex_bundle_type<vtkGraph*>
624 {
625 };
626 
627 // Internal vertex properties
628 template <>
629 struct vertex_bundle_type<vtkDirectedGraph* const> : vertex_bundle_type<vtkGraph*>
630 {
631 };
632 
633 // Internal edge properties
634 template <>
636 {
637 };
638 
639 // Internal edge properties
640 template <>
641 struct edge_bundle_type<vtkDirectedGraph* const> : edge_bundle_type<vtkGraph*>
642 {
643 };
644 
645 //===========================================================================
646 // vtkTree
647 
648 template <>
650 {
651 };
652 
653 // The graph_traits for a const graph are the same as a non-const graph.
654 template <>
655 struct graph_traits<const vtkTree*> : graph_traits<vtkTree*>
656 {
657 };
658 
659 // The graph_traits for a const graph are the same as a non-const graph.
660 template <>
661 struct graph_traits<vtkTree* const> : graph_traits<vtkTree*>
662 {
663 };
664 
665 //===========================================================================
666 // vtkUndirectedGraph
667 template <>
669 {
670  typedef undirected_tag directed_category;
671 };
672 
673 // The graph_traits for a const graph are the same as a non-const graph.
674 template <>
676 {
677 };
678 
679 // The graph_traits for a const graph are the same as a non-const graph.
680 template <>
682 {
683 };
684 
685 #if BOOST_VERSION >= 104500
686 // Internal graph properties
687 template <>
688 struct graph_property_type<vtkUndirectedGraph*> : graph_property_type<vtkGraph*>
689 {
690 };
691 
692 // Internal graph properties
693 template <>
694 struct graph_property_type<vtkUndirectedGraph* const> : graph_property_type<vtkGraph*>
695 {
696 };
697 #endif
698 
699 // Internal vertex properties
700 template <>
702 {
703 };
704 
705 // Internal vertex properties
706 template <>
707 struct vertex_property_type<vtkUndirectedGraph* const> : vertex_property_type<vtkGraph*>
708 {
709 };
710 
711 // Internal edge properties
712 template <>
714 {
715 };
716 
717 // Internal edge properties
718 template <>
719 struct edge_property_type<vtkUndirectedGraph* const> : edge_property_type<vtkGraph*>
720 {
721 };
722 
723 #if BOOST_VERSION >= 104500
724 // Internal graph properties
725 template <>
726 struct graph_bundle_type<vtkUndirectedGraph*> : graph_bundle_type<vtkGraph*>
727 {
728 };
729 
730 // Internal graph properties
731 template <>
732 struct graph_bundle_type<vtkUndirectedGraph* const> : graph_bundle_type<vtkGraph*>
733 {
734 };
735 #endif
736 
737 // Internal vertex properties
738 template <>
740 {
741 };
742 
743 // Internal vertex properties
744 template <>
745 struct vertex_bundle_type<vtkUndirectedGraph* const> : vertex_bundle_type<vtkGraph*>
746 {
747 };
748 
749 // Internal edge properties
750 template <>
752 {
753 };
754 
755 // Internal edge properties
756 template <>
757 struct edge_bundle_type<vtkUndirectedGraph* const> : edge_bundle_type<vtkGraph*>
758 {
759 };
760 
761 //===========================================================================
762 // vtkMutableDirectedGraph
763 
764 template <>
766 {
767 };
768 
769 // The graph_traits for a const graph are the same as a non-const graph.
770 template <>
772 {
773 };
774 
775 // The graph_traits for a const graph are the same as a non-const graph.
776 template <>
778 {
779 };
780 
781 #if BOOST_VERSION >= 104500
782 // Internal graph properties
783 template <>
784 struct graph_property_type<vtkMutableDirectedGraph*> : graph_property_type<vtkDirectedGraph*>
785 {
786 };
787 
788 // Internal graph properties
789 template <>
790 struct graph_property_type<vtkMutableDirectedGraph* const> : graph_property_type<vtkDirectedGraph*>
791 {
792 };
793 #endif
794 
795 // Internal vertex properties
796 template <>
798 {
799 };
800 
801 // Internal vertex properties
802 template <>
803 struct vertex_property_type<vtkMutableDirectedGraph* const>
805 {
806 };
807 
808 // Internal edge properties
809 template <>
811 {
812 };
813 
814 // Internal edge properties
815 template <>
817 {
818 };
819 
820 #if BOOST_VERSION >= 104500
821 // Internal graph properties
822 template <>
823 struct graph_bundle_type<vtkMutableDirectedGraph*> : graph_bundle_type<vtkDirectedGraph*>
824 {
825 };
826 
827 // Internal graph properties
828 template <>
829 struct graph_bundle_type<vtkMutableDirectedGraph* const> : graph_bundle_type<vtkDirectedGraph*>
830 {
831 };
832 #endif
833 
834 // Internal vertex properties
835 template <>
837 {
838 };
839 
840 // Internal vertex properties
841 template <>
843 {
844 };
845 
846 // Internal edge properties
847 template <>
849 {
850 };
851 
852 // Internal edge properties
853 template <>
855 {
856 };
857 
858 //===========================================================================
859 // vtkMutableUndirectedGraph
860 
861 template <>
863 {
864 };
865 
866 // The graph_traits for a const graph are the same as a non-const graph.
867 template <>
869 {
870 };
871 
872 // The graph_traits for a const graph are the same as a non-const graph.
873 template <>
875 {
876 };
877 
878 #if BOOST_VERSION >= 104500
879 // Internal graph properties
880 template <>
881 struct graph_property_type<vtkMutableUndirectedGraph*> : graph_property_type<vtkUndirectedGraph*>
882 {
883 };
884 
885 // Internal graph properties
886 template <>
887 struct graph_property_type<vtkMutableUndirectedGraph* const>
888  : graph_property_type<vtkUndirectedGraph*>
889 {
890 };
891 #endif
892 
893 // Internal vertex properties
894 template <>
896 {
897 };
898 
899 // Internal vertex properties
900 template <>
901 struct vertex_property_type<vtkMutableUndirectedGraph* const>
903 {
904 };
905 
906 // Internal edge properties
907 template <>
909 {
910 };
911 
912 // Internal edge properties
913 template <>
914 struct edge_property_type<vtkMutableUndirectedGraph* const>
916 {
917 };
918 
919 #if BOOST_VERSION >= 104500
920 // Internal graph properties
921 template <>
922 struct graph_bundle_type<vtkMutableUndirectedGraph*> : graph_bundle_type<vtkUndirectedGraph*>
923 {
924 };
925 
926 // Internal graph properties
927 template <>
928 struct graph_bundle_type<vtkMutableUndirectedGraph* const> : graph_bundle_type<vtkUndirectedGraph*>
929 {
930 };
931 #endif
932 
933 // Internal vertex properties
934 template <>
936 {
937 };
938 
939 // Internal vertex properties
940 template <>
941 struct vertex_bundle_type<vtkMutableUndirectedGraph* const>
943 {
944 };
945 
946 // Internal edge properties
947 template <>
949 {
950 };
951 
952 // Internal edge properties
953 template <>
955 {
956 };
957 
958 //===========================================================================
959 // API implementation
960 template <>
961 class vertex_property<vtkGraph*>
962 {
963 public:
964  typedef vtkIdType type;
965 };
966 
967 template <>
968 class edge_property<vtkGraph*>
969 {
970 public:
971  typedef vtkIdType type;
972 };
973 } // end namespace boost
974 
977 {
978  return e.Source;
979 }
980 
983 {
984  return e.Target;
985 }
986 
987 inline std::pair<boost::graph_traits<vtkGraph*>::vertex_iterator,
990 {
992  vtkIdType start = 0;
994  {
996  start = helper->MakeDistributedId(rank, start);
997  }
998 
999  return std::make_pair(Iter(start), Iter(start + g->GetNumberOfVertices()));
1000 }
1001 
1002 inline std::pair<boost::graph_traits<vtkGraph*>::edge_iterator,
1005 {
1007  return std::make_pair(Iter(g), Iter(g, g->GetNumberOfVertices()));
1008 }
1009 
1010 inline std::pair<boost::graph_traits<vtkGraph*>::out_edge_iterator,
1013 {
1015  std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
1016  return p;
1017 }
1018 
1019 inline std::pair<boost::graph_traits<vtkGraph*>::in_edge_iterator,
1022 {
1024  std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
1025  return p;
1026 }
1027 
1028 inline std::pair<boost::graph_traits<vtkGraph*>::adjacency_iterator,
1031 {
1034  std::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g);
1035  return std::make_pair(Iter(out.first, &g), Iter(out.second, &g));
1036 }
1037 
1039 {
1040  return g->GetNumberOfVertices();
1041 }
1042 
1044 {
1045  return g->GetNumberOfEdges();
1046 }
1047 
1050 {
1051  return g->GetOutDegree(u);
1052 }
1053 
1056 {
1057  return g->GetInDegree(u);
1058 }
1059 
1062 {
1063  return g->GetDegree(u);
1064 }
1065 
1068 {
1069  return g->AddVertex();
1070 }
1071 
1072 inline std::pair<boost::graph_traits<vtkMutableDirectedGraph*>::edge_descriptor, bool> add_edge(
1075 {
1077  return std::make_pair(e, true);
1078 }
1079 
1082 {
1083  return g->AddVertex();
1084 }
1085 
1086 inline std::pair<boost::graph_traits<vtkMutableUndirectedGraph*>::edge_descriptor, bool> add_edge(
1090 {
1092  return std::make_pair(e, true);
1093 }
1094 
1095 namespace boost
1096 {
1097 //===========================================================================
1098 // An edge map for vtkGraph.
1099 // This is a common input needed for algorithms.
1100 
1102 {
1103 };
1104 
1105 template <>
1107 {
1111  typedef readable_property_map_tag category;
1112 };
1113 
1116 {
1117  return key.Id;
1118 }
1119 
1120 //===========================================================================
1121 // Helper for vtkGraph edge property maps
1122 // Automatically converts boost edge ids to vtkGraph edge ids.
1123 
1124 template <typename PMap>
1126 {
1127 public:
1129  : pmap(m)
1130  {
1131  }
1132  PMap pmap;
1137 
1138  reference operator[](const key_type& key) const { return get(pmap, key.Id); }
1139 };
1140 
1141 template <typename PMap>
1144 {
1145  return get(helper.pmap, key.Id);
1146 }
1147 
1148 template <typename PMap>
1150  const typename property_traits<PMap>::value_type& value)
1151 {
1152  put(helper.pmap, key.Id, value);
1153 }
1154 
1155 //===========================================================================
1156 // Helper for vtkGraph vertex property maps
1157 // Automatically converts boost vertex ids to vtkGraph vertex ids.
1158 
1159 template <typename PMap>
1161 {
1162 public:
1164  : pmap(m)
1165  {
1166  }
1167  PMap pmap;
1172 
1173  reference operator[](const key_type& key) const { return get(pmap, key); }
1174 };
1175 
1176 template <typename PMap>
1179 {
1180  return get(helper.pmap, key);
1181 }
1182 
1183 template <typename PMap>
1185  const typename property_traits<PMap>::value_type& value)
1186 {
1187  put(helper.pmap, key, value);
1188 }
1189 
1190 //===========================================================================
1191 // An index map for vtkGraph
1192 // This is a common input needed for algorithms
1193 
1195 {
1196 };
1197 
1198 template <>
1200 {
1204  typedef readable_property_map_tag category;
1205 };
1206 
1209 {
1210  return key;
1211 }
1212 
1213 //===========================================================================
1214 // Helper for vtkGraph property maps
1215 // Automatically multiplies the property value by some value (default 1)
1216 template <typename PMap>
1218 {
1219 public:
1220  vtkGraphPropertyMapMultiplier(PMap m, float multi = 1)
1221  : pmap(m)
1222  , multiplier(multi)
1223  {
1224  }
1225  PMap pmap;
1226  float multiplier;
1231 };
1232 
1233 template <typename PMap>
1236 {
1237  return multi.multiplier * get(multi.pmap, key);
1238 }
1239 
1240 template <typename PMap>
1242  const typename property_traits<PMap>::key_type& key,
1243  const typename property_traits<PMap>::value_type& value)
1244 {
1245  put(multi.pmap, key, value);
1246 }
1247 
1248 // Allow algorithms to automatically extract vtkGraphIndexMap from a
1249 // VTK graph
1250 template <>
1251 struct property_map<vtkGraph*, vertex_index_t>
1252 {
1255 };
1256 
1257 template <>
1258 struct property_map<vtkDirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1259 {
1260 };
1261 
1262 template <>
1263 struct property_map<vtkUndirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1264 {
1265 };
1266 
1267 inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*)
1268 {
1269  return vtkGraphIndexMap();
1270 }
1271 
1272 template <>
1273 struct property_map<vtkGraph*, edge_index_t>
1274 {
1277 };
1278 
1279 template <>
1280 struct property_map<vtkDirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1281 {
1282 };
1283 
1284 template <>
1285 struct property_map<vtkUndirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1286 {
1287 };
1288 
1289 inline vtkGraphIndexMap get(edge_index_t, vtkGraph*)
1290 {
1291  return vtkGraphIndexMap();
1292 }
1293 
1294 // property_map specializations for const-qualified graphs
1295 template <>
1296 struct property_map<vtkDirectedGraph* const, vertex_index_t>
1298 {
1299 };
1300 
1301 template <>
1302 struct property_map<vtkUndirectedGraph* const, vertex_index_t>
1304 {
1305 };
1306 
1307 template <>
1308 struct property_map<vtkDirectedGraph* const, edge_index_t>
1310 {
1311 };
1312 
1313 template <>
1314 struct property_map<vtkUndirectedGraph* const, edge_index_t>
1316 {
1317 };
1318 } // namespace boost
1319 
1320 #if BOOST_VERSION > 104000
1321 #include <boost/property_map/vector_property_map.hpp>
1322 #else
1323 #include <boost/vector_property_map.hpp>
1324 #endif
1325 
1326 #endif // vtkBoostGraphAdapter_h
1327 // VTK-HeaderTest-Exclude: vtkBoostGraphAdapter.h
property_traits< PMap >::reference reference
property_traits< PMap >::category category
property_traits< PMap >::value_type value_type
reference operator[](const key_type &key) const
vtkGraphPropertyMapMultiplier(PMap m, float multi=1)
property_traits< PMap >::value_type value_type
property_traits< PMap >::reference reference
property_traits< PMap >::key_type key_type
property_traits< PMap >::category category
property_traits< PMap >::reference reference
property_traits< PMap >::value_type value_type
reference operator[](const key_type &key) const
property_traits< PMap >::category category
vtk_edge_iterator(vtkGraph *g=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:65
void SetTuple1(vtkIdType tupleIdx, double value)
These methods are included as convenience for the wrappers.
double GetTuple1(vtkIdType tupleIdx)
These methods are included as convenience for the wrappers.
static vtkInformationIntegerKey * DATA_PIECE_NUMBER()
virtual vtkInformation * GetInformation()
Set/Get the information object associated with this data object.
A directed graph.
static vtkDirectedGraph * SafeDownCast(vtkObjectBase *o)
helper for the vtkGraph class that allows the graph to be distributed across multiple memory spaces.
vtkIdType GetEdgeOwner(vtkIdType e_id) const
Returns owner of edge with ID e_id, by extracting top ceil(log2 P) bits of e_id.
vtkIdType MakeDistributedId(int owner, vtkIdType local)
Builds a distributed ID consisting of the given owner and the local ID.
vtkIdType GetVertexOwner(vtkIdType v) const
Returns owner of vertex v, by extracting top ceil(log2 P) bits of v.
dynamic, self-adjusting array of double
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:51
Base class for graph data types.
Definition: vtkGraph.h:305
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:55
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:70
An undirected graph.
A atomic type representing the union of many types.
Definition: vtkVariant.h:79
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:266
vtkIdType Source
Definition: vtkGraph.h:288
vtkIdType Target
Definition: vtkGraph.h:277
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