VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 -------------------------------------------------------------------------*/
29 #ifndef __vtkBoostGraphAdapter_h
30 #define __vtkBoostGraphAdapter_h
31 
32 #include "vtkAbstractArray.h"
33 #include "vtkDirectedGraph.h"
34 #include "vtkDistributedGraphHelper.h"
35 #include "vtkDataObject.h"
36 #include "vtkDataArray.h"
37 #include "vtkDoubleArray.h"
38 #include "vtkFloatArray.h"
39 #include "vtkIdTypeArray.h"
40 #include "vtkInformation.h"
41 #include "vtkIntArray.h"
44 #include "vtkTree.h"
45 #include "vtkUndirectedGraph.h"
46 #include "vtkVariant.h"
47 
48 #include <boost/version.hpp>
49 
50 namespace boost {
51  //===========================================================================
52  // VTK arrays as property maps
53  // These need to be defined before including other boost stuff
54 
55  // Forward declarations are required here, so that we aren't forced
56  // to include boost/property_map.hpp.
57  template<typename> struct property_traits;
58  struct read_write_property_map_tag;
59 
60 #define vtkPropertyMapMacro(T, V) \
61  template <> \
62  struct property_traits<T*> \
63  { \
64  typedef V value_type; \
65  typedef V reference; \
66  typedef vtkIdType key_type; \
67  typedef read_write_property_map_tag category; \
68  }; \
69  \
70  inline property_traits<T*>::reference \
71  get( \
72  T* const & arr, \
73  property_traits<T*>::key_type key) \
74  { \
75  return arr->GetValue(key); \
76  } \
77  \
78  inline void \
79  put( \
80  T* arr, \
81  property_traits<T*>::key_type key, \
82  const property_traits<T*>::value_type & value) \
83  { \
84  arr->InsertValue(key, value); \
85  }
86 
87  vtkPropertyMapMacro(vtkIntArray, int)
88  vtkPropertyMapMacro(vtkIdTypeArray, vtkIdType)
89  vtkPropertyMapMacro(vtkDoubleArray, double)
90  vtkPropertyMapMacro(vtkFloatArray, float)
91 
92  // vtkDataArray
93  template<>
94  struct property_traits<vtkDataArray*>
95  {
96  typedef double value_type;
97  typedef double reference;
98  typedef vtkIdType key_type;
99  typedef read_write_property_map_tag category;
100  };
101 
102  inline double
103  get(vtkDataArray * const& arr, vtkIdType key)
104  {
105  return arr->GetTuple1(key);
106  }
107 
108  inline void
109  put(vtkDataArray *arr, vtkIdType key, const double& value)
110  {
111  arr->SetTuple1(key, value);
112  }
113 
114  // vtkAbstractArray as a property map of vtkVariants
115  template<>
116  struct property_traits<vtkAbstractArray*>
117  {
118  typedef vtkVariant value_type;
119  typedef vtkVariant reference;
120  typedef vtkIdType key_type;
121  typedef read_write_property_map_tag category;
122  };
123 
124  inline vtkVariant
125  get(vtkAbstractArray * const& arr, vtkIdType key)
126  {
127  return arr->GetVariantValue(key);
128  }
129 
130  inline void
131  put(vtkAbstractArray *arr, vtkIdType key, const vtkVariant& value)
132  {
133  arr->InsertVariantValue(key, value);
134  }
135 }
136 
137 #include <vtksys/stl/utility> // STL Header
138 
139 #include <boost/config.hpp>
140 #include <boost/iterator/iterator_facade.hpp>
141 #include <boost/graph/graph_traits.hpp>
142 #include <boost/graph/properties.hpp>
143 #include <boost/graph/adjacency_iterator.hpp>
144 
145 // The functions and classes in this file allows the user to
146 // treat a vtkDirectedGraph or vtkUndirectedGraph object
147 // as a boost graph "as is".
148 
149 namespace boost {
150 
152  public iterator_facade<vtk_vertex_iterator,
153  vtkIdType,
154  bidirectional_traversal_tag,
155  vtkIdType,
156  vtkIdType>
157  {
158  public:
159  explicit vtk_vertex_iterator(vtkIdType i = 0) : index(i) {}
160 
161  private:
162  vtkIdType dereference() const { return index; }
163 
164  bool equal(const vtk_vertex_iterator& other) const
165  { return index == other.index; }
166 
167  void increment() { index++; }
168  void decrement() { index--; }
169 
170  vtkIdType index;
171 
172  friend class iterator_core_access;
173  };
174 
176  public iterator_facade<vtk_edge_iterator,
177  vtkEdgeType,
178  forward_traversal_tag,
179  vtkEdgeType,
180  vtkIdType>
181  {
182  public:
183  explicit vtk_edge_iterator(vtkGraph *g = 0, vtkIdType v = 0) :
184  directed(false), vertex(v), lastVertex(v), iter(0), end(0), graph(g)
185  {
186  if (graph)
187  {
188  lastVertex = graph->GetNumberOfVertices();
189  }
190 
191  vtkIdType myRank = -1;
192  vtkDistributedGraphHelper *helper
193  = this->graph? this->graph->GetDistributedGraphHelper() : 0;
194  if (helper)
195  {
196  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
197  vertex = helper->MakeDistributedId(myRank, vertex);
198  lastVertex = helper->MakeDistributedId(myRank, lastVertex);
199  }
200 
201  if (graph != 0)
202  {
203  directed = (vtkDirectedGraph::SafeDownCast(graph) != 0);
204  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
205  {
206  ++vertex;
207  }
208 
209  if (vertex < lastVertex)
210  {
211  // Get the outgoing edges of the first vertex that has outgoing
212  // edges
213  vtkIdType nedges;
214  graph->GetOutEdges(vertex, iter, nedges);
215  end = iter + nedges;
216 
217  if (!directed)
218  {
219  while(iter != 0
220  && (// Skip non-local edges
221  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
222  // Skip entirely-local edges where Source > Target
223  || (((helper
224  && myRank == helper->GetVertexOwner(iter->Target))
225  || !helper)
226  && vertex > iter->Target)))
227  {
228  this->inc();
229  }
230  }
231  }
232  else
233  {
234  iter = 0;
235  }
236  }
237  }
238 
239  private:
240  vtkEdgeType dereference() const
241  { return vtkEdgeType(vertex, iter->Target, iter->Id); }
242 
243  bool equal(const vtk_edge_iterator& other) const
244  { return vertex == other.vertex && iter == other.iter; }
245 
246  void increment()
247  {
248  inc();
249  if (!directed)
250  {
251  vtkIdType myRank = -1;
252  vtkDistributedGraphHelper *helper
253  = this->graph? this->graph->GetDistributedGraphHelper() : 0;
254  if (helper)
255  {
256  myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
257  }
258 
259  while (iter != 0
260  && (// Skip non-local edges
261  (helper && helper->GetEdgeOwner(iter->Id) != myRank)
262  // Skip entirely-local edges where Source > Target
263  || (((helper
264  && myRank == helper->GetVertexOwner(iter->Target))
265  || !helper)
266  && vertex > iter->Target)))
267  {
268  inc();
269  }
270  }
271  }
272 
273  void inc()
274  {
275  ++iter;
276  if (iter == end)
277  {
278  // Find a vertex with nonzero out degree.
279  ++vertex;
280  while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
281  {
282  ++vertex;
283  }
284 
285  if (vertex < lastVertex)
286  {
287  vtkIdType nedges;
288  graph->GetOutEdges(vertex, iter, nedges);
289  end = iter + nedges;
290  }
291  else
292  {
293  iter = 0;
294  }
295  }
296  }
297 
298  bool directed;
299  vtkIdType vertex;
300  vtkIdType lastVertex;
301  const vtkOutEdgeType * iter;
302  const vtkOutEdgeType * end;
303  vtkGraph *graph;
304 
305  friend class iterator_core_access;
306  };
307 
309  public iterator_facade<vtk_out_edge_pointer_iterator,
310  vtkEdgeType,
311  bidirectional_traversal_tag,
312  vtkEdgeType,
313  ptrdiff_t>
314  {
315  public:
316  explicit vtk_out_edge_pointer_iterator(vtkGraph *g = 0, vtkIdType v = 0, bool end = false) :
317  vertex(v)
318  {
319  if (g)
320  {
321  vtkIdType nedges;
322  g->GetOutEdges(vertex, iter, nedges);
323  if (end)
324  {
325  iter += nedges;
326  }
327  }
328  }
329 
330  private:
331  vtkEdgeType dereference() const { return vtkEdgeType(vertex, iter->Target, iter->Id); }
332 
333  bool equal(const vtk_out_edge_pointer_iterator& other) const
334  { return iter == other.iter; }
335 
336  void increment() { iter++; }
337  void decrement() { iter--; }
338 
339  vtkIdType vertex;
340  const vtkOutEdgeType *iter;
341 
342  friend class iterator_core_access;
343  };
344 
346  public iterator_facade<vtk_in_edge_pointer_iterator,
347  vtkEdgeType,
348  bidirectional_traversal_tag,
349  vtkEdgeType,
350  ptrdiff_t>
351  {
352  public:
353  explicit vtk_in_edge_pointer_iterator(vtkGraph *g = 0, vtkIdType v = 0, bool end = false) :
354  vertex(v)
355  {
356  if (g)
357  {
358  vtkIdType nedges;
359  g->GetInEdges(vertex, iter, nedges);
360  if (end)
361  {
362  iter += nedges;
363  }
364  }
365  }
366 
367  private:
368  vtkEdgeType dereference() const { return vtkEdgeType(iter->Source, vertex, iter->Id); }
369 
370  bool equal(const vtk_in_edge_pointer_iterator& other) const
371  { return iter == other.iter; }
372 
373  void increment() { iter++; }
374  void decrement() { iter--; }
375 
376  vtkIdType vertex;
377  const vtkInEdgeType *iter;
378 
379  friend class iterator_core_access;
380  };
381 
382  //===========================================================================
383  // vtkGraph
384  // VertexAndEdgeListGraphConcept
385  // BidirectionalGraphConcept
386  // AdjacencyGraphConcept
387 
389  public virtual bidirectional_graph_tag,
390  public virtual edge_list_graph_tag,
391  public virtual vertex_list_graph_tag,
392  public virtual adjacency_graph_tag { };
393 
394  template <>
395  struct graph_traits<vtkGraph*> {
396  typedef vtkIdType vertex_descriptor;
397  static vertex_descriptor null_vertex() { return -1; }
399  static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); }
402 
405 
406  typedef allow_parallel_edge_tag edge_parallel_category;
408  typedef vtkIdType vertices_size_type;
409  typedef vtkIdType edges_size_type;
410  typedef vtkIdType degree_size_type;
411 
412  typedef adjacency_iterator_generator<vtkGraph*,
413  vertex_descriptor, out_edge_iterator>::type adjacency_iterator;
414  };
415 
416 #if BOOST_VERSION >= 104500
417  template<>
418  struct graph_property_type< vtkGraph* > {
419  typedef no_property type;
420  };
421 #endif
422 
423  template<>
424  struct vertex_property_type< vtkGraph* > {
425  typedef no_property type;
426  };
427 
428  template<>
429  struct edge_property_type< vtkGraph* > {
430  typedef no_property type;
431  };
432 
433 #if BOOST_VERSION >= 104500
434  template<>
435  struct graph_bundle_type< vtkGraph* > {
436  typedef no_property type;
437  };
438 #endif
439 
440  template<>
441  struct vertex_bundle_type< vtkGraph* > {
442  typedef no_property type;
443  };
444 
445  template<>
446  struct edge_bundle_type< vtkGraph* > {
447  typedef no_property type;
448  };
449 
450  inline bool has_no_edges(vtkGraph* g)
451  {
452  return ((g->GetNumberOfEdges() > 0) ? false : true);
453  }
454 
456  vtkGraph* g)
457  {
459  {
461  }
463  {
465  }
466  }
467 
468  //===========================================================================
469  // vtkDirectedGraph
470 
471  template <>
473  {
474  typedef directed_tag directed_category;
475  };
476 
477  // The graph_traits for a const graph are the same as a non-const graph.
478  template <>
479  struct graph_traits<const vtkDirectedGraph*> : graph_traits<vtkDirectedGraph*> { };
480 
481  // The graph_traits for a const graph are the same as a non-const graph.
482  template <>
483  struct graph_traits<vtkDirectedGraph* const> : graph_traits<vtkDirectedGraph*> { };
484 
485 #if BOOST_VERSION >= 104500
486  // Internal graph properties
487  template<>
488  struct graph_property_type< vtkDirectedGraph* >
489  : graph_property_type< vtkGraph* > { };
490 
491  // Internal graph properties
492  template<>
493  struct graph_property_type< vtkDirectedGraph* const >
494  : graph_property_type< vtkGraph* > { };
495 #endif
496 
497  // Internal vertex properties
498  template<>
499  struct vertex_property_type< vtkDirectedGraph* >
501 
502  // Internal vertex properties
503  template<>
504  struct vertex_property_type< vtkDirectedGraph* const >
506 
507  // Internal edge properties
508  template<>
509  struct edge_property_type< vtkDirectedGraph* >
511 
512  // Internal edge properties
513  template<>
514  struct edge_property_type< vtkDirectedGraph* const >
516 
517 #if BOOST_VERSION >= 104500
518  // Internal graph properties
519  template<>
520  struct graph_bundle_type< vtkDirectedGraph* >
521  : graph_bundle_type< vtkGraph* > { };
522 
523  // Internal graph properties
524  template<>
525  struct graph_bundle_type< vtkDirectedGraph* const >
526  : graph_bundle_type< vtkGraph* > { };
527 #endif
528 
529  // Internal vertex properties
530  template<>
531  struct vertex_bundle_type< vtkDirectedGraph* >
533 
534  // Internal vertex properties
535  template<>
536  struct vertex_bundle_type< vtkDirectedGraph* const >
538 
539  // Internal edge properties
540  template<>
541  struct edge_bundle_type< vtkDirectedGraph* >
543 
544  // Internal edge properties
545  template<>
546  struct edge_bundle_type< vtkDirectedGraph* const >
548 
549  //===========================================================================
550  // vtkTree
551 
552  template <>
553  struct graph_traits<vtkTree*> : graph_traits<vtkDirectedGraph*> { };
554 
555  // The graph_traits for a const graph are the same as a non-const graph.
556  template <>
557  struct graph_traits<const vtkTree*> : graph_traits<vtkTree*> { };
558 
559  // The graph_traits for a const graph are the same as a non-const graph.
560  template <>
561  struct graph_traits<vtkTree* const> : graph_traits<vtkTree*> { };
562 
563  //===========================================================================
564  // vtkUndirectedGraph
565  template <>
567  {
568  typedef undirected_tag directed_category;
569  };
570 
571  // The graph_traits for a const graph are the same as a non-const graph.
572  template <>
573  struct graph_traits<const vtkUndirectedGraph*> : graph_traits<vtkUndirectedGraph*> { };
574 
575  // The graph_traits for a const graph are the same as a non-const graph.
576  template <>
577  struct graph_traits<vtkUndirectedGraph* const> : graph_traits<vtkUndirectedGraph*> { };
578 
579 #if BOOST_VERSION >= 104500
580  // Internal graph properties
581  template<>
582  struct graph_property_type< vtkUndirectedGraph* >
583  : graph_property_type< vtkGraph* > { };
584 
585  // Internal graph properties
586  template<>
587  struct graph_property_type< vtkUndirectedGraph* const >
588  : graph_property_type< vtkGraph* > { };
589 #endif
590 
591  // Internal vertex properties
592  template<>
593  struct vertex_property_type< vtkUndirectedGraph* >
595 
596  // Internal vertex properties
597  template<>
598  struct vertex_property_type< vtkUndirectedGraph* const >
600 
601  // Internal edge properties
602  template<>
603  struct edge_property_type< vtkUndirectedGraph* >
605 
606  // Internal edge properties
607  template<>
608  struct edge_property_type< vtkUndirectedGraph* const >
610 
611 #if BOOST_VERSION >= 104500
612  // Internal graph properties
613  template<>
614  struct graph_bundle_type< vtkUndirectedGraph* >
615  : graph_bundle_type< vtkGraph* > { };
616 
617  // Internal graph properties
618  template<>
619  struct graph_bundle_type< vtkUndirectedGraph* const >
620  : graph_bundle_type< vtkGraph* > { };
621 #endif
622 
623  // Internal vertex properties
624  template<>
625  struct vertex_bundle_type< vtkUndirectedGraph* >
627 
628  // Internal vertex properties
629  template<>
630  struct vertex_bundle_type< vtkUndirectedGraph* const >
632 
633  // Internal edge properties
634  template<>
635  struct edge_bundle_type< vtkUndirectedGraph* >
637 
638  // Internal edge properties
639  template<>
640  struct edge_bundle_type< vtkUndirectedGraph* const >
642 
643  //===========================================================================
644  // vtkMutableDirectedGraph
645 
646  template <>
648 
649  // The graph_traits for a const graph are the same as a non-const graph.
650  template <>
652 
653  // The graph_traits for a const graph are the same as a non-const graph.
654  template <>
656 
657 #if BOOST_VERSION >= 104500
658  // Internal graph properties
659  template<>
660  struct graph_property_type< vtkMutableDirectedGraph* >
661  : graph_property_type< vtkDirectedGraph* > { };
662 
663  // Internal graph properties
664  template<>
665  struct graph_property_type< vtkMutableDirectedGraph* const >
666  : graph_property_type< vtkDirectedGraph* > { };
667 #endif
668 
669  // Internal vertex properties
670  template<>
671  struct vertex_property_type< vtkMutableDirectedGraph* >
673 
674  // Internal vertex properties
675  template<>
676  struct vertex_property_type< vtkMutableDirectedGraph* const >
678 
679  // Internal edge properties
680  template<>
681  struct edge_property_type< vtkMutableDirectedGraph* >
683 
684  // Internal edge properties
685  template<>
686  struct edge_property_type< vtkMutableDirectedGraph* const >
688 
689 #if BOOST_VERSION >= 104500
690  // Internal graph properties
691  template<>
692  struct graph_bundle_type< vtkMutableDirectedGraph* >
693  : graph_bundle_type< vtkDirectedGraph* > { };
694 
695  // Internal graph properties
696  template<>
697  struct graph_bundle_type< vtkMutableDirectedGraph* const >
698  : graph_bundle_type< vtkDirectedGraph* > { };
699 #endif
700 
701  // Internal vertex properties
702  template<>
703  struct vertex_bundle_type< vtkMutableDirectedGraph* >
705 
706  // Internal vertex properties
707  template<>
708  struct vertex_bundle_type< vtkMutableDirectedGraph* const >
710 
711  // Internal edge properties
712  template<>
713  struct edge_bundle_type< vtkMutableDirectedGraph* >
715 
716  // Internal edge properties
717  template<>
718  struct edge_bundle_type< vtkMutableDirectedGraph* const >
720 
721  //===========================================================================
722  // vtkMutableUndirectedGraph
723 
724  template <>
726 
727  // The graph_traits for a const graph are the same as a non-const graph.
728  template <>
730 
731  // The graph_traits for a const graph are the same as a non-const graph.
732  template <>
734 
735 #if BOOST_VERSION >= 104500
736  // Internal graph properties
737  template<>
738  struct graph_property_type< vtkMutableUndirectedGraph* >
739  : graph_property_type< vtkUndirectedGraph* > { };
740 
741  // Internal graph properties
742  template<>
743  struct graph_property_type< vtkMutableUndirectedGraph* const >
744  : graph_property_type< vtkUndirectedGraph* > { };
745 #endif
746 
747  // Internal vertex properties
748  template<>
749  struct vertex_property_type< vtkMutableUndirectedGraph* >
751 
752  // Internal vertex properties
753  template<>
754  struct vertex_property_type< vtkMutableUndirectedGraph* const >
756 
757  // Internal edge properties
758  template<>
759  struct edge_property_type< vtkMutableUndirectedGraph* >
761 
762  // Internal edge properties
763  template<>
764  struct edge_property_type< vtkMutableUndirectedGraph* const >
766 
767 #if BOOST_VERSION >= 104500
768  // Internal graph properties
769  template<>
770  struct graph_bundle_type< vtkMutableUndirectedGraph* >
771  : graph_bundle_type< vtkUndirectedGraph* > { };
772 
773  // Internal graph properties
774  template<>
775  struct graph_bundle_type< vtkMutableUndirectedGraph* const >
776  : graph_bundle_type< vtkUndirectedGraph* > { };
777 #endif
778 
779  // Internal vertex properties
780  template<>
781  struct vertex_bundle_type< vtkMutableUndirectedGraph* >
783 
784  // Internal vertex properties
785  template<>
786  struct vertex_bundle_type< vtkMutableUndirectedGraph* const >
788 
789  // Internal edge properties
790  template<>
791  struct edge_bundle_type< vtkMutableUndirectedGraph* >
793 
794  // Internal edge properties
795  template<>
796  struct edge_bundle_type< vtkMutableUndirectedGraph* const >
798 
799  //===========================================================================
800  // API implementation
801  template <>
802  class vertex_property< vtkGraph* > {
803  public:
804  typedef vtkIdType type;
805  };
806 
807  template <>
808  class edge_property< vtkGraph* > {
809  public:
810  typedef vtkIdType type;
811  };
812 } // end namespace boost
813 
816  vtkGraph *)
817 {
818  return e.Source;
819 }
820 
823  vtkGraph *)
824 {
825  return e.Target;
826 }
827 
828 inline vtksys_stl::pair<
830  boost::graph_traits< vtkGraph* >::vertex_iterator >
832 {
833  typedef boost::graph_traits< vtkGraph* >::vertex_iterator Iter;
834  vtkIdType start = 0;
835  if (vtkDistributedGraphHelper *helper = g->GetDistributedGraphHelper())
836  {
837  int rank =
839  start = helper->MakeDistributedId(rank, start);
840  }
841 
842  return vtksys_stl::make_pair( Iter(start),
843  Iter(start + g->GetNumberOfVertices()) );
844 }
845 
846 inline vtksys_stl::pair<
848  boost::graph_traits< vtkGraph* >::edge_iterator >
850 {
851  typedef boost::graph_traits< vtkGraph* >::edge_iterator Iter;
852  return vtksys_stl::make_pair( Iter(g), Iter(g, g->GetNumberOfVertices()) );
853 }
854 
855 inline vtksys_stl::pair<
857  boost::graph_traits< vtkGraph* >::out_edge_iterator >
860  vtkGraph *g)
861 {
862  typedef boost::graph_traits< vtkGraph* >::out_edge_iterator Iter;
863  vtksys_stl::pair<Iter, Iter> p = vtksys_stl::make_pair( Iter(g, u), Iter(g, u, true) );
864  return p;
865 }
866 
867 inline vtksys_stl::pair<
869  boost::graph_traits< vtkGraph* >::in_edge_iterator >
872  vtkGraph *g)
873 {
874  typedef boost::graph_traits< vtkGraph* >::in_edge_iterator Iter;
875  vtksys_stl::pair<Iter, Iter> p = vtksys_stl::make_pair( Iter(g, u), Iter(g, u, true) );
876  return p;
877 }
878 
879 inline vtksys_stl::pair<
881  boost::graph_traits< vtkGraph* >::adjacency_iterator >
884  vtkGraph *g)
885 {
886  typedef boost::graph_traits< vtkGraph* >::adjacency_iterator Iter;
887  typedef boost::graph_traits< vtkGraph* >::out_edge_iterator OutEdgeIter;
888  vtksys_stl::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g);
889  return vtksys_stl::make_pair( Iter(out.first, &g), Iter(out.second, &g) );
890 }
891 
894 {
895  return g->GetNumberOfVertices();
896 }
897 
900 {
901  return g->GetNumberOfEdges();
902 }
903 
907  vtkGraph *g)
908 {
909  return g->GetOutDegree(u);
910 }
911 
915  vtkDirectedGraph *g)
916 {
917  return g->GetInDegree(u);
918 }
919 
923  vtkGraph *g)
924 {
925  return g->GetDegree(u);
926 }
927 
930 {
931  return g->AddVertex();
932 }
933 
934 inline vtksys_stl::pair<
936  bool>
941 {
942  boost::graph_traits< vtkMutableDirectedGraph* >::edge_descriptor e = g->AddEdge(u, v);
943  return vtksys_stl::make_pair(e, true);
944 }
945 
948 {
949  return g->AddVertex();
950 }
951 
952 inline vtksys_stl::pair<
954  bool>
959 {
960  boost::graph_traits< vtkMutableUndirectedGraph* >::edge_descriptor e = g->AddEdge(u, v);
961  return vtksys_stl::make_pair(e, true);
962 }
963 
964 namespace boost {
965  //===========================================================================
966  // An edge map for vtkGraph.
967  // This is a common input needed for algorithms.
968 
969  struct vtkGraphEdgeMap { };
970 
971  template <>
973  {
974  typedef vtkIdType value_type;
975  typedef vtkIdType reference;
977  typedef readable_property_map_tag category;
978  };
979 
981  get(
982  vtkGraphEdgeMap vtkNotUsed(arr),
984  {
985  return key.Id;
986  }
987 
988  //===========================================================================
989  // Helper for vtkGraph edge property maps
990  // Automatically converts boost edge ids to vtkGraph edge ids.
991 
992  template<typename PMap>
994  {
995  public:
997  PMap pmap;
1002  };
1003 
1004  template<typename PMap>
1005  inline typename property_traits<PMap>::reference
1006  get(
1008  vtkEdgeType key)
1009  {
1010  return get(helper.pmap, key.Id);
1011  }
1012 
1013  template<typename PMap>
1014  inline void
1017  vtkEdgeType key,
1018  const typename property_traits<PMap>::value_type & value)
1019  {
1020  put(helper.pmap, key.Id, value);
1021  }
1022 
1023  //===========================================================================
1024  // An index map for vtkGraph
1025  // This is a common input needed for algorithms
1026 
1027  struct vtkGraphIndexMap { };
1028 
1029  template <>
1031  {
1032  typedef vtkIdType value_type;
1033  typedef vtkIdType reference;
1034  typedef vtkIdType key_type;
1035  typedef readable_property_map_tag category;
1036  };
1037 
1039  get(
1040  vtkGraphIndexMap vtkNotUsed(arr),
1042  {
1043  return key;
1044  }
1045 
1046  //===========================================================================
1047  // Helper for vtkGraph property maps
1048  // Automatically multiplies the property value by some value (default 1)
1049  template<typename PMap>
1051  {
1052  public:
1053  vtkGraphPropertyMapMultiplier(PMap m, float multi=1) : pmap(m),multiplier(multi){}
1054  PMap pmap;
1055  float multiplier;
1060  };
1061 
1062  template<typename PMap>
1063  inline typename property_traits<PMap>::reference
1064  get(
1066  const typename property_traits<PMap>::key_type key)
1067  {
1068  return multi.multiplier * get(multi.pmap, key);
1069  }
1070 
1071  template<typename PMap>
1072  inline void
1075  const typename property_traits<PMap>::key_type key,
1076  const typename property_traits<PMap>::value_type & value)
1077  {
1078  put(multi.pmap, key, value);
1079  }
1080 
1081  // Allow algorithms to automatically extract vtkGraphIndexMap from a
1082  // VTK graph
1083  template<>
1084  struct property_map<vtkGraph*, vertex_index_t>
1085  {
1088  };
1089 
1090  template<>
1091  struct property_map<vtkDirectedGraph*, vertex_index_t>
1093 
1094  template<>
1095  struct property_map<vtkUndirectedGraph*, vertex_index_t>
1097 
1098  inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*) { return vtkGraphIndexMap(); }
1099 
1100  template<>
1101  struct property_map<vtkGraph*, edge_index_t>
1102  {
1105  };
1106 
1107  template<>
1108  struct property_map<vtkDirectedGraph*, edge_index_t>
1110 
1111  template<>
1112  struct property_map<vtkUndirectedGraph*, edge_index_t>
1114 
1115  inline vtkGraphIndexMap get(edge_index_t, vtkGraph*) { return vtkGraphIndexMap(); }
1116 
1117  // property_map specializations for const-qualified graphs
1118  template<>
1119  struct property_map<vtkDirectedGraph* const, vertex_index_t>
1121 
1122  template<>
1123  struct property_map<vtkUndirectedGraph* const, vertex_index_t>
1125 
1126  template<>
1127  struct property_map<vtkDirectedGraph* const, edge_index_t>
1129 
1130  template<>
1131  struct property_map<vtkUndirectedGraph* const, edge_index_t>
1133 } // namespace boost
1134 
1135 #if BOOST_VERSION > 104000
1136 #include <boost/property_map/vector_property_map.hpp>
1137 #else
1138 #include <boost/vector_property_map.hpp>
1139 #endif
1140 
1141 
1142 #endif // __vtkBoostGraphAdapter_h
1143 // VTK-HeaderTest-Exclude: vtkBoostGraphAdapter.h
static vtkDirectedGraph * SafeDownCast(vtkObjectBase *o)
virtual vtkIdType GetNumberOfEdges()
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)
virtual vtkInformation * GetInformation()
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
virtual vtkIdType GetNumberOfVertices()
vtksys_stl::pair< boost::graph_traits< vtkGraph * >::vertex_iterator, boost::graph_traits< vtkGraph * >::vertex_iterator > vertices(vtkGraph *g)
vtk_out_edge_pointer_iterator out_edge_iterator
vtksys_stl::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
property_traits< PMap >::reference reference
vtkPropertyMapMacro(vtkIntArray, int) vtkPropertyMapMacro(vtkIdTypeArray
vtkGraphPropertyMapMultiplier(PMap m, float multi=1)
vtkGraph_traversal_category traversal_category
vtksys_stl::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)
vtk_in_edge_pointer_iterator in_edge_iterator
An undirected graph.
vtksys_stl::pair< boost::graph_traits< vtkGraph * >::adjacency_iterator, boost::graph_traits< vtkGraph * >::adjacency_iterator > adjacent_vertices(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
property_traits< PMap >::key_type key_type
boost::graph_traits< vtkGraph * >::edges_size_type num_edges(vtkGraph *g)
boost::graph_traits< vtkMutableDirectedGraph * >::vertex_descriptor add_vertex(vtkMutableDirectedGraph *g)
boost::graph_traits< vtkDirectedGraph * >::degree_size_type in_degree(boost::graph_traits< vtkDirectedGraph * >::vertex_descriptor u, vtkDirectedGraph *g)
void remove_edge(graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *g)
A directed graph.
Base class for graph data types.
Definition: vtkGraph.h:288
static vtkInformationIntegerKey * DATA_PIECE_NUMBER()
adjacency_iterator_generator< vtkGraph *, vertex_descriptor, out_edge_iterator >::type adjacency_iterator
vtksys_stl::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)
vtkEdgeType AddEdge(vtkIdType u, vtkIdType v)
virtual vtkIdType GetDegree(vtkIdType v)
static vertex_descriptor null_vertex()
allow_parallel_edge_tag edge_parallel_category
property_traits< PMap >::category category
void put(vtkDataArray *arr, vtkIdType key, const double &value)
An editable directed graph.
bool has_no_edges(vtkGraph *g)
vtkIdType Id
Definition: vtkGraph.h:255
An editable undirected graph.
virtual vtkIdType GetInDegree(vtkIdType v)
vtkIdType Target
Definition: vtkGraph.h:264
property_traits< PMap >::value_type value_type
boost::graph_traits< vtkGraph * >::vertices_size_type num_vertices(vtkGraph *g)
static vtkMutableDirectedGraph * SafeDownCast(vtkObjectBase *o)
vtkDistributedGraphHelper * GetDistributedGraphHelper()
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtkIdType Source
Definition: vtkGraph.h:273
vtk_in_edge_pointer_iterator(vtkGraph *g=0, vtkIdType v=0, bool end=false)
vtk_edge_iterator(vtkGraph *g=0, vtkIdType v=0)
boost::graph_traits< vtkGraph * >::degree_size_type degree(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
vtksys_stl::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)
virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator *it)
property_traits< PMap >::value_type value_type
void RemoveEdge(vtkIdType e)
boost::graph_traits< vtkGraph * >::degree_size_type out_degree(boost::graph_traits< vtkGraph * >::vertex_descriptor u, vtkGraph *g)
void RemoveEdge(vtkIdType e)
static vtkMutableUndirectedGraph * SafeDownCast(vtkObjectBase *o)
virtual vtkIdType GetOutDegree(vtkIdType v)