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
51namespace 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.
59template <typename>
61struct 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
90template <>
92{
93 typedef double value_type;
94 typedef double reference;
96 typedef read_write_property_map_tag category;
97};
98
99inline double get(vtkDataArray* const& arr, vtkIdType key)
100{
101 return arr->GetTuple1(key);
102}
103
104inline 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
110template <>
112{
116 typedef read_write_property_map_tag category;
117};
118
119inline vtkVariant get(vtkAbstractArray* const& arr, vtkIdType key)
120{
121 return arr->GetVariantValue(key);
122}
123
124inline void put(vtkAbstractArray* arr, vtkIdType key, const vtkVariant& value)
125{
126 arr->InsertVariantValue(key, value);
127}
128#if defined(_MSC_VER)
129namespace detail
130{
131using ::boost::get;
132using ::boost::put;
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
156namespace boost
157{
158
160 : public iterator_facade<vtk_vertex_iterator, vtkIdType, bidirectional_traversal_tag,
161 const vtkIdType&, vtkIdType>
162{
163public:
165 : index(i)
166 {
167 }
168
169private:
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
180};
181
183 : public iterator_facade<vtk_edge_iterator, vtkEdgeType, forward_traversal_tag,
184 const vtkEdgeType&, vtkIdType>
185{
186public:
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
249private:
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;
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
329};
330
332 : public iterator_facade<vtk_out_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
333 const vtkEdgeType&, ptrdiff_t>
334{
335public:
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
352private:
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
386};
387
389 : public iterator_facade<vtk_in_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
390 const vtkEdgeType&, ptrdiff_t>
391{
392public:
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
409private:
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
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
459template <>
460struct 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
478 typedef adjacency_iterator_generator<vtkGraph*, vertex_descriptor, out_edge_iterator>::type
480};
481
482#if BOOST_VERSION >= 104500
483template <>
484struct graph_property_type<vtkGraph*>
485{
486 typedef no_property type;
487};
488#endif
489
490template <>
491struct vertex_property_type<vtkGraph*>
492{
493 typedef no_property type;
494};
495
496template <>
497struct edge_property_type<vtkGraph*>
498{
499 typedef no_property type;
500};
501
502#if BOOST_VERSION >= 104500
503template <>
504struct graph_bundle_type<vtkGraph*>
505{
506 typedef no_property type;
507};
508#endif
509
510template <>
511struct vertex_bundle_type<vtkGraph*>
512{
513 typedef no_property type;
514};
515
516template <>
517struct edge_bundle_type<vtkGraph*>
518{
519 typedef no_property type;
520};
521
522inline bool has_no_edges(vtkGraph* g)
523{
524 return ((g->GetNumberOfEdges() > 0) ? false : true);
525}
526
538
539//===========================================================================
540// vtkDirectedGraph
541
542template <>
543struct graph_traits<vtkDirectedGraph*> : graph_traits<vtkGraph*>
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.
549template <>
550struct graph_traits<const vtkDirectedGraph*> : graph_traits<vtkDirectedGraph*>
551{
552};
553
554// The graph_traits for a const graph are the same as a non-const graph.
555template <>
556struct graph_traits<vtkDirectedGraph* const> : graph_traits<vtkDirectedGraph*>
557{
558};
559
560#if BOOST_VERSION >= 104500
561// Internal graph properties
562template <>
563struct graph_property_type<vtkDirectedGraph*> : graph_property_type<vtkGraph*>
564{
565};
566
567// Internal graph properties
568template <>
569struct graph_property_type<vtkDirectedGraph* const> : graph_property_type<vtkGraph*>
570{
571};
572#endif
573
574// Internal vertex properties
575template <>
576struct vertex_property_type<vtkDirectedGraph*> : vertex_property_type<vtkGraph*>
577{
578};
579
580// Internal vertex properties
581template <>
582struct vertex_property_type<vtkDirectedGraph* const> : vertex_property_type<vtkGraph*>
583{
584};
585
586// Internal edge properties
587template <>
588struct edge_property_type<vtkDirectedGraph*> : edge_property_type<vtkGraph*>
589{
590};
591
592// Internal edge properties
593template <>
594struct edge_property_type<vtkDirectedGraph* const> : edge_property_type<vtkGraph*>
595{
596};
597
598#if BOOST_VERSION >= 104500
599// Internal graph properties
600template <>
601struct graph_bundle_type<vtkDirectedGraph*> : graph_bundle_type<vtkGraph*>
602{
603};
604
605// Internal graph properties
606template <>
607struct graph_bundle_type<vtkDirectedGraph* const> : graph_bundle_type<vtkGraph*>
608{
609};
610#endif
611
612// Internal vertex properties
613template <>
614struct vertex_bundle_type<vtkDirectedGraph*> : vertex_bundle_type<vtkGraph*>
615{
616};
617
618// Internal vertex properties
619template <>
620struct vertex_bundle_type<vtkDirectedGraph* const> : vertex_bundle_type<vtkGraph*>
621{
622};
623
624// Internal edge properties
625template <>
626struct edge_bundle_type<vtkDirectedGraph*> : edge_bundle_type<vtkGraph*>
627{
628};
629
630// Internal edge properties
631template <>
632struct edge_bundle_type<vtkDirectedGraph* const> : edge_bundle_type<vtkGraph*>
633{
634};
635
636//===========================================================================
637// vtkTree
638
639template <>
640struct graph_traits<vtkTree*> : graph_traits<vtkDirectedGraph*>
641{
642};
643
644// The graph_traits for a const graph are the same as a non-const graph.
645template <>
646struct 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.
651template <>
652struct graph_traits<vtkTree* const> : graph_traits<vtkTree*>
653{
654};
655
656//===========================================================================
657// vtkUndirectedGraph
658template <>
659struct graph_traits<vtkUndirectedGraph*> : graph_traits<vtkGraph*>
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.
665template <>
666struct graph_traits<const vtkUndirectedGraph*> : graph_traits<vtkUndirectedGraph*>
667{
668};
669
670// The graph_traits for a const graph are the same as a non-const graph.
671template <>
672struct graph_traits<vtkUndirectedGraph* const> : graph_traits<vtkUndirectedGraph*>
673{
674};
675
676#if BOOST_VERSION >= 104500
677// Internal graph properties
678template <>
679struct graph_property_type<vtkUndirectedGraph*> : graph_property_type<vtkGraph*>
680{
681};
682
683// Internal graph properties
684template <>
685struct graph_property_type<vtkUndirectedGraph* const> : graph_property_type<vtkGraph*>
686{
687};
688#endif
689
690// Internal vertex properties
691template <>
692struct vertex_property_type<vtkUndirectedGraph*> : vertex_property_type<vtkGraph*>
693{
694};
695
696// Internal vertex properties
697template <>
698struct vertex_property_type<vtkUndirectedGraph* const> : vertex_property_type<vtkGraph*>
699{
700};
701
702// Internal edge properties
703template <>
704struct edge_property_type<vtkUndirectedGraph*> : edge_property_type<vtkGraph*>
705{
706};
707
708// Internal edge properties
709template <>
710struct edge_property_type<vtkUndirectedGraph* const> : edge_property_type<vtkGraph*>
711{
712};
713
714#if BOOST_VERSION >= 104500
715// Internal graph properties
716template <>
717struct graph_bundle_type<vtkUndirectedGraph*> : graph_bundle_type<vtkGraph*>
718{
719};
720
721// Internal graph properties
722template <>
723struct graph_bundle_type<vtkUndirectedGraph* const> : graph_bundle_type<vtkGraph*>
724{
725};
726#endif
727
728// Internal vertex properties
729template <>
730struct vertex_bundle_type<vtkUndirectedGraph*> : vertex_bundle_type<vtkGraph*>
731{
732};
733
734// Internal vertex properties
735template <>
736struct vertex_bundle_type<vtkUndirectedGraph* const> : vertex_bundle_type<vtkGraph*>
737{
738};
739
740// Internal edge properties
741template <>
742struct edge_bundle_type<vtkUndirectedGraph*> : edge_bundle_type<vtkGraph*>
743{
744};
745
746// Internal edge properties
747template <>
748struct edge_bundle_type<vtkUndirectedGraph* const> : edge_bundle_type<vtkGraph*>
749{
750};
751
752//===========================================================================
753// vtkMutableDirectedGraph
754
755template <>
756struct graph_traits<vtkMutableDirectedGraph*> : graph_traits<vtkDirectedGraph*>
757{
758};
759
760// The graph_traits for a const graph are the same as a non-const graph.
761template <>
762struct graph_traits<const vtkMutableDirectedGraph*> : graph_traits<vtkMutableDirectedGraph*>
763{
764};
765
766// The graph_traits for a const graph are the same as a non-const graph.
767template <>
768struct graph_traits<vtkMutableDirectedGraph* const> : graph_traits<vtkMutableDirectedGraph*>
769{
770};
771
772#if BOOST_VERSION >= 104500
773// Internal graph properties
774template <>
775struct graph_property_type<vtkMutableDirectedGraph*> : graph_property_type<vtkDirectedGraph*>
776{
777};
778
779// Internal graph properties
780template <>
781struct graph_property_type<vtkMutableDirectedGraph* const> : graph_property_type<vtkDirectedGraph*>
782{
783};
784#endif
785
786// Internal vertex properties
787template <>
788struct vertex_property_type<vtkMutableDirectedGraph*> : vertex_property_type<vtkDirectedGraph*>
789{
790};
791
792// Internal vertex properties
793template <>
794struct vertex_property_type<vtkMutableDirectedGraph* const>
795 : vertex_property_type<vtkDirectedGraph*>
796{
797};
798
799// Internal edge properties
800template <>
801struct edge_property_type<vtkMutableDirectedGraph*> : edge_property_type<vtkDirectedGraph*>
802{
803};
804
805// Internal edge properties
806template <>
807struct edge_property_type<vtkMutableDirectedGraph* const> : edge_property_type<vtkDirectedGraph*>
808{
809};
810
811#if BOOST_VERSION >= 104500
812// Internal graph properties
813template <>
814struct graph_bundle_type<vtkMutableDirectedGraph*> : graph_bundle_type<vtkDirectedGraph*>
815{
816};
817
818// Internal graph properties
819template <>
820struct graph_bundle_type<vtkMutableDirectedGraph* const> : graph_bundle_type<vtkDirectedGraph*>
821{
822};
823#endif
824
825// Internal vertex properties
826template <>
827struct vertex_bundle_type<vtkMutableDirectedGraph*> : vertex_bundle_type<vtkDirectedGraph*>
828{
829};
830
831// Internal vertex properties
832template <>
833struct vertex_bundle_type<vtkMutableDirectedGraph* const> : vertex_bundle_type<vtkDirectedGraph*>
834{
835};
836
837// Internal edge properties
838template <>
839struct edge_bundle_type<vtkMutableDirectedGraph*> : edge_bundle_type<vtkDirectedGraph*>
840{
841};
842
843// Internal edge properties
844template <>
845struct edge_bundle_type<vtkMutableDirectedGraph* const> : edge_bundle_type<vtkDirectedGraph*>
846{
847};
848
849//===========================================================================
850// vtkMutableUndirectedGraph
851
852template <>
853struct graph_traits<vtkMutableUndirectedGraph*> : graph_traits<vtkUndirectedGraph*>
854{
855};
856
857// The graph_traits for a const graph are the same as a non-const graph.
858template <>
859struct graph_traits<const vtkMutableUndirectedGraph*> : graph_traits<vtkMutableUndirectedGraph*>
860{
861};
862
863// The graph_traits for a const graph are the same as a non-const graph.
864template <>
865struct graph_traits<vtkMutableUndirectedGraph* const> : graph_traits<vtkMutableUndirectedGraph*>
866{
867};
868
869#if BOOST_VERSION >= 104500
870// Internal graph properties
871template <>
872struct graph_property_type<vtkMutableUndirectedGraph*> : graph_property_type<vtkUndirectedGraph*>
873{
874};
875
876// Internal graph properties
877template <>
878struct graph_property_type<vtkMutableUndirectedGraph* const>
879 : graph_property_type<vtkUndirectedGraph*>
880{
881};
882#endif
883
884// Internal vertex properties
885template <>
886struct vertex_property_type<vtkMutableUndirectedGraph*> : vertex_property_type<vtkUndirectedGraph*>
887{
888};
889
890// Internal vertex properties
891template <>
892struct vertex_property_type<vtkMutableUndirectedGraph* const>
893 : vertex_property_type<vtkUndirectedGraph*>
894{
895};
896
897// Internal edge properties
898template <>
899struct edge_property_type<vtkMutableUndirectedGraph*> : edge_property_type<vtkUndirectedGraph*>
900{
901};
902
903// Internal edge properties
904template <>
905struct edge_property_type<vtkMutableUndirectedGraph* const>
906 : edge_property_type<vtkUndirectedGraph*>
907{
908};
909
910#if BOOST_VERSION >= 104500
911// Internal graph properties
912template <>
913struct graph_bundle_type<vtkMutableUndirectedGraph*> : graph_bundle_type<vtkUndirectedGraph*>
914{
915};
916
917// Internal graph properties
918template <>
919struct graph_bundle_type<vtkMutableUndirectedGraph* const> : graph_bundle_type<vtkUndirectedGraph*>
920{
921};
922#endif
923
924// Internal vertex properties
925template <>
926struct vertex_bundle_type<vtkMutableUndirectedGraph*> : vertex_bundle_type<vtkUndirectedGraph*>
927{
928};
929
930// Internal vertex properties
931template <>
932struct vertex_bundle_type<vtkMutableUndirectedGraph* const>
933 : vertex_bundle_type<vtkUndirectedGraph*>
934{
935};
936
937// Internal edge properties
938template <>
939struct edge_bundle_type<vtkMutableUndirectedGraph*> : edge_bundle_type<vtkUndirectedGraph*>
940{
941};
942
943// Internal edge properties
944template <>
945struct edge_bundle_type<vtkMutableUndirectedGraph* const> : edge_bundle_type<vtkUndirectedGraph*>
946{
947};
948
949//===========================================================================
950// API implementation
951template <>
952class vertex_property<vtkGraph*>
953{
954public:
956};
957
958template <>
959class edge_property<vtkGraph*>
960{
961public:
963};
964} // end namespace boost
965
971
977
978inline 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
993inline std::pair<boost::graph_traits<vtkGraph*>::edge_iterator,
996{
998 return std::make_pair(Iter(g), Iter(g, g->GetNumberOfVertices()));
999}
1000
1001inline 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
1010inline 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
1019inline 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
1033
1038
1044
1050
1056
1062
1063inline std::pair<boost::graph_traits<vtkMutableDirectedGraph*>::edge_descriptor, bool> add_edge(
1066{
1068 return std::make_pair(e, true);
1069}
1070
1076
1077inline std::pair<boost::graph_traits<vtkMutableUndirectedGraph*>::edge_descriptor, bool> add_edge(
1081{
1083 return std::make_pair(e, true);
1084}
1085
1086namespace boost
1087{
1088//===========================================================================
1089// An edge map for vtkGraph.
1090// This is a common input needed for algorithms.
1091
1093{
1094};
1095
1096template <>
1098{
1102 typedef readable_property_map_tag category;
1103};
1104
1110
1111//===========================================================================
1112// Helper for vtkGraph edge property maps
1113// Automatically converts boost edge ids to vtkGraph edge ids.
1114
1115template <typename PMap>
1117{
1118public:
1120 : pmap(m)
1121 {
1122 }
1123 PMap pmap;
1128
1129 reference operator[](const key_type& key) const { return get(pmap, key.Id); }
1130};
1131
1132template <typename PMap>
1135{
1136 return get(helper.pmap, key.Id);
1137}
1138
1139template <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
1150template <typename PMap>
1152{
1153public:
1155 : pmap(m)
1156 {
1157 }
1158 PMap pmap;
1163
1164 reference operator[](const key_type& key) const { return get(pmap, key); }
1165};
1166
1167template <typename PMap>
1170{
1171 return get(helper.pmap, key);
1172}
1173
1174template <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
1189template <>
1191{
1195 typedef readable_property_map_tag category;
1196};
1197
1203
1204//===========================================================================
1205// Helper for vtkGraph property maps
1206// Automatically multiplies the property value by some value (default 1)
1207template <typename PMap>
1209{
1210public:
1211 vtkGraphPropertyMapMultiplier(PMap m, float multi = 1)
1212 : pmap(m)
1213 , multiplier(multi)
1214 {
1215 }
1216 PMap pmap;
1222};
1223
1224template <typename PMap>
1227{
1228 return multi.multiplier * get(multi.pmap, key);
1229}
1230
1231template <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
1241template <>
1242struct property_map<vtkGraph*, vertex_index_t>
1243{
1246};
1247
1248template <>
1249struct property_map<vtkDirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1250{
1251};
1252
1253template <>
1254struct property_map<vtkUndirectedGraph*, vertex_index_t> : property_map<vtkGraph*, vertex_index_t>
1255{
1256};
1257
1258inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*)
1259{
1260 return vtkGraphIndexMap();
1261}
1262
1263template <>
1264struct property_map<vtkGraph*, edge_index_t>
1265{
1268};
1269
1270template <>
1271struct property_map<vtkDirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1272{
1273};
1274
1275template <>
1276struct property_map<vtkUndirectedGraph*, edge_index_t> : property_map<vtkGraph*, edge_index_t>
1277{
1278};
1279
1280inline vtkGraphIndexMap get(edge_index_t, vtkGraph*)
1281{
1282 return vtkGraphIndexMap();
1283}
1284
1285// property_map specializations for const-qualified graphs
1286template <>
1287struct property_map<vtkDirectedGraph* const, vertex_index_t>
1288 : property_map<vtkDirectedGraph*, vertex_index_t>
1289{
1290};
1291
1292template <>
1293struct property_map<vtkUndirectedGraph* const, vertex_index_t>
1294 : property_map<vtkUndirectedGraph*, vertex_index_t>
1295{
1296};
1297
1298template <>
1299struct property_map<vtkDirectedGraph* const, edge_index_t>
1300 : property_map<vtkDirectedGraph*, edge_index_t>
1301{
1302};
1303
1304template <>
1305struct property_map<vtkUndirectedGraph* const, edge_index_t>
1306 : property_map<vtkUndirectedGraph*, 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
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
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.
virtual vtkInformation * GetInformation()
Set/Get the information object associated with this data object.
static vtkInformationIntegerKey * DATA_PIECE_NUMBER()
A directed graph.
static vtkDirectedGraph * SafeDownCast(vtkObjectBase *o)
helper for the vtkGraph class that allows the graph to be distributed across multiple memory spaces.
vtkIdType GetEdgeOwner(vtkIdType e_id) const
Returns owner of edge with ID e_id, by extracting top ceil(log2 P) bits of e_id.
vtkIdType MakeDistributedId(int owner, vtkIdType local)
Builds a distributed ID consisting of the given owner and the local ID.
vtkIdType GetVertexOwner(vtkIdType v) const
Returns owner of vertex v, by extracting top ceil(log2 P) bits of v.
dynamic, self-adjusting array of double
dynamic, self-adjusting array of float
Base class for graph data types.
Definition vtkGraph.h:296
virtual vtkIdType GetOutDegree(vtkIdType v)
The number of outgoing edges from vertex v.
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.
vtkDistributedGraphHelper * GetDistributedGraphHelper()
Retrieves the distributed graph helper for this graph.
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:46
An editable directed graph.
void RemoveEdge(vtkIdType e)
Removes the edge from the graph.
static vtkMutableDirectedGraph * SafeDownCast(vtkObjectBase *o)
vtkIdType AddVertex()
Adds a vertex to the graph and returns the index of the new vertex.
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:61
An undirected graph.
A atomic type representing the union of many types.
Definition vtkVariant.h:70
Forward declaration required for Boost serialization.
bool has_no_edges(vtkGraph *g)
void remove_edge(graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *g)
double get(vtkDataArray *const &arr, vtkIdType key)
void put(vtkDataArray *arr, vtkIdType key, const double &value)
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:257
vtkIdType Source
Definition vtkGraph.h:279
vtkIdType Target
Definition vtkGraph.h:268
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)
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< vtkGraph * >::vertices_size_type num_vertices(vtkGraph *g)
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define vtkPropertyMapMacro(T, V)
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< vtkMutableDirectedGraph * >::vertex_descriptor add_vertex(vtkMutableDirectedGraph *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)
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 * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
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< vtkGraph * >::edges_size_type num_edges(vtkGraph *g)
int vtkIdType
Definition vtkType.h:332