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