VTK  9.3.0
vtkBoostGraphAdapter.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-FileCopyrightText: Copyright 2008 Sandia Corporation
3// SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
14#ifndef vtkBoostGraphAdapter_h
15#define vtkBoostGraphAdapter_h
16
17#include "vtkAbstractArray.h"
18#include "vtkDataArray.h"
19#include "vtkDataObject.h"
20#include "vtkDirectedGraph.h"
22#include "vtkDoubleArray.h"
23#include "vtkFloatArray.h"
24#include "vtkIdTypeArray.h"
25#include "vtkInformation.h"
26#include "vtkIntArray.h"
29#include "vtkTree.h"
30#include "vtkUndirectedGraph.h"
31#include "vtkVariant.h"
32
33#include <boost/version.hpp>
34
35namespace boost
36{
37//===========================================================================
38// VTK arrays as property maps
39// These need to be defined before including other boost stuff
40
41// Forward declarations are required here, so that we aren't forced
42// to include boost/property_map.hpp.
43template <typename>
45struct read_write_property_map_tag;
46
47#define vtkPropertyMapMacro(T, V) \
48 template <> \
49 struct property_traits<T*> \
50 { \
51 typedef V value_type; \
52 typedef V reference; \
53 typedef vtkIdType key_type; \
54 typedef read_write_property_map_tag category; \
55 }; \
56 \
57 inline property_traits<T*>::reference get(T* const& arr, property_traits<T*>::key_type key) \
58 { \
59 return arr->GetValue(key); \
60 } \
61 \
62 inline void put( \
63 T* arr, property_traits<T*>::key_type key, const property_traits<T*>::value_type& value) \
64 { \
65 arr->InsertValue(key, value); \
66 }
67
72
73// vtkDataArray
74template <>
76{
77 typedef double value_type;
78 typedef double reference;
80 typedef read_write_property_map_tag category;
81};
82
83inline double get(vtkDataArray* const& arr, vtkIdType key)
84{
85 return arr->GetTuple1(key);
86}
87
88inline void put(vtkDataArray* arr, vtkIdType key, const double& value)
89{
90 arr->SetTuple1(key, value);
91}
92
93// vtkAbstractArray as a property map of vtkVariants
94template <>
96{
100 typedef read_write_property_map_tag category;
101};
102
103inline vtkVariant get(vtkAbstractArray* const& arr, vtkIdType key)
104{
105 return arr->GetVariantValue(key);
106}
107
108inline void put(vtkAbstractArray* arr, vtkIdType key, const vtkVariant& value)
109{
110 arr->InsertVariantValue(key, value);
111}
112
113#if defined(_MSC_VER)
114namespace detail
115{
116using ::boost::get;
117using ::boost::put;
118}
119#endif
120}
121
122#include <utility> // STL Header
123
124#include <boost/config.hpp>
125#include <boost/version.hpp>
126
127#if BOOST_VERSION > 107300 && BOOST_VERSION < 107600
128#define BOOST_ALLOW_DEPRECATED_HEADERS
129#define BOOST_BIND_GLOBAL_PLACEHOLDERS
130#endif
131
132#include <boost/graph/adjacency_iterator.hpp>
133#include <boost/graph/graph_traits.hpp>
134#include <boost/graph/properties.hpp>
135#include <boost/iterator/iterator_facade.hpp>
136
137// The functions and classes in this file allows the user to
138// treat a vtkDirectedGraph or vtkUndirectedGraph object
139// as a boost graph "as is".
140
141namespace boost
142{
143
145 : public iterator_facade<vtk_vertex_iterator, vtkIdType, bidirectional_traversal_tag,
146 const vtkIdType&, vtkIdType>
147{
148public:
150 : index(i)
151 {
152 }
153
154private:
155 const vtkIdType& dereference() const { return index; }
156
157 bool equal(const vtk_vertex_iterator& other) const { return index == other.index; }
158
159 void increment() { index++; }
160 void decrement() { index--; }
161
162 vtkIdType index;
163
165};
166
168 : public iterator_facade<vtk_edge_iterator, vtkEdgeType, forward_traversal_tag,
169 const vtkEdgeType&, vtkIdType>
170{
171public:
172 explicit vtk_edge_iterator(vtkGraph* g = nullptr, vtkIdType v = 0)
173 : directed(false)
174 , vertex(v)
175 , lastVertex(v)
176 , iter(nullptr)
177 , end(nullptr)
178 , graph(g)
179 {
180 if (graph)
181 {
182 lastVertex = graph->GetNumberOfVertices();
183 }
184
185 vtkIdType myRank = -1;
187 this->graph ? this->graph->GetDistributedGraphHelper() : nullptr;
188 if (helper)
189 {
190 myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
191 vertex = helper->MakeDistributedId(myRank, vertex);
192 lastVertex = helper->MakeDistributedId(myRank, lastVertex);
193 }
194
195 if (graph != nullptr)
196 {
197 directed = (vtkDirectedGraph::SafeDownCast(graph) != nullptr);
198 while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
199 {
200 ++vertex;
201 }
202
203 if (vertex < lastVertex)
204 {
205 // Get the outgoing edges of the first vertex that has outgoing
206 // edges
207 vtkIdType nedges;
208 graph->GetOutEdges(vertex, iter, nedges);
209 if (iter)
210 {
211 end = iter + nedges;
212
213 if (!directed)
214 {
215 while ( // Skip non-local edges
216 (helper && helper->GetEdgeOwner(iter->Id) != myRank)
217 // Skip entirely-local edges where Source > Target
218 || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
219 vertex > iter->Target))
220 {
221 this->inc();
222 }
223 }
224 }
225 }
226 else
227 {
228 iter = nullptr;
229 }
230 }
231
232 RecalculateEdge();
233 }
234
235private:
236 const vtkEdgeType& dereference() const
237 {
238 assert(iter);
239 return edge;
240 }
241
242 bool equal(const vtk_edge_iterator& other) const
243 {
244 return vertex == other.vertex && iter == other.iter;
245 }
246
247 void increment()
248 {
249 inc();
250 if (!directed)
251 {
252 vtkIdType myRank = -1;
254 this->graph ? this->graph->GetDistributedGraphHelper() : nullptr;
255 if (helper)
256 {
257 myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
258 }
259
260 while (iter != nullptr &&
261 ( // Skip non-local edges
262 (helper && helper->GetEdgeOwner(iter->Id) != myRank)
263 // Skip entirely-local edges where Source > Target
264 || (((helper && myRank == helper->GetVertexOwner(iter->Target)) || !helper) &&
265 vertex > iter->Target)))
266 {
267 inc();
268 }
269 }
270 RecalculateEdge();
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 = nullptr;
294 }
295 }
296 }
297
298 void RecalculateEdge()
299 {
300 if (iter)
301 {
302 edge = vtkEdgeType(vertex, iter->Target, iter->Id);
303 }
304 }
305
306 bool directed;
307 vtkIdType vertex;
308 vtkIdType lastVertex;
309 const vtkOutEdgeType* iter;
310 const vtkOutEdgeType* end;
311 vtkGraph* graph;
312 vtkEdgeType edge;
313
315};
316
318 : public iterator_facade<vtk_out_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
319 const vtkEdgeType&, ptrdiff_t>
320{
321public:
322 explicit vtk_out_edge_pointer_iterator(vtkGraph* g = nullptr, vtkIdType v = 0, bool end = false)
323 : vertex(v)
324 , iter(nullptr)
325 {
326 if (g)
327 {
328 vtkIdType nedges;
329 g->GetOutEdges(vertex, iter, nedges);
330 if (end)
331 {
332 iter += nedges;
333 }
334 }
335 RecalculateEdge();
336 }
337
338private:
339 const vtkEdgeType& dereference() const
340 {
341 assert(iter);
342 return edge;
343 }
344
345 bool equal(const vtk_out_edge_pointer_iterator& other) const { return iter == other.iter; }
346
347 void increment()
348 {
349 iter++;
350 RecalculateEdge();
351 }
352
353 void decrement()
354 {
355 iter--;
356 RecalculateEdge();
357 }
358
359 void RecalculateEdge()
360 {
361 if (iter)
362 {
363 edge = vtkEdgeType(vertex, iter->Target, iter->Id);
364 }
365 }
366
367 vtkIdType vertex;
368 const vtkOutEdgeType* iter;
369 vtkEdgeType edge;
370
372};
373
375 : public iterator_facade<vtk_in_edge_pointer_iterator, vtkEdgeType, bidirectional_traversal_tag,
376 const vtkEdgeType&, ptrdiff_t>
377{
378public:
379 explicit vtk_in_edge_pointer_iterator(vtkGraph* g = nullptr, vtkIdType v = 0, bool end = false)
380 : vertex(v)
381 , iter(nullptr)
382 {
383 if (g)
384 {
385 vtkIdType nedges;
386 g->GetInEdges(vertex, iter, nedges);
387 if (end)
388 {
389 iter += nedges;
390 }
391 }
392 RecalculateEdge();
393 }
394
395private:
396 const vtkEdgeType& dereference() const
397 {
398 assert(iter);
399 return edge;
400 }
401
402 bool equal(const vtk_in_edge_pointer_iterator& other) const { return iter == other.iter; }
403
404 void increment()
405 {
406 iter++;
407 RecalculateEdge();
408 }
409
410 void decrement()
411 {
412 iter--;
413 RecalculateEdge();
414 }
415
416 void RecalculateEdge()
417 {
418 if (iter)
419 {
420 edge = vtkEdgeType(iter->Source, vertex, iter->Id);
421 }
422 }
423
424 vtkIdType vertex;
425 const vtkInEdgeType* iter;
426 vtkEdgeType edge;
427
429};
430
431//===========================================================================
432// vtkGraph
433// VertexAndEdgeListGraphConcept
434// BidirectionalGraphConcept
435// AdjacencyGraphConcept
436VTK_ABI_NAMESPACE_BEGIN
437
439 : public virtual bidirectional_graph_tag
440 , public virtual edge_list_graph_tag
441 , public virtual vertex_list_graph_tag
442 , public virtual adjacency_graph_tag
443{
444};
445
446VTK_ABI_NAMESPACE_END
447
448template <>
449struct graph_traits<vtkGraph*>
450{
452 static vertex_descriptor null_vertex() { return -1; }
454 static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); }
457
460
461 typedef allow_parallel_edge_tag edge_parallel_category;
466
467 typedef adjacency_iterator_generator<vtkGraph*, vertex_descriptor, out_edge_iterator>::type
469};
470
471#if BOOST_VERSION >= 104500
472template <>
473struct graph_property_type<vtkGraph*>
474{
475 typedef no_property type;
476};
477#endif
478
479template <>
480struct vertex_property_type<vtkGraph*>
481{
482 typedef no_property type;
483};
484
485template <>
486struct edge_property_type<vtkGraph*>
487{
488 typedef no_property type;
489};
490
491#if BOOST_VERSION >= 104500
492template <>
493struct graph_bundle_type<vtkGraph*>
494{
495 typedef no_property type;
496};
497#endif
498
499template <>
500struct vertex_bundle_type<vtkGraph*>
501{
502 typedef no_property type;
503};
504
505template <>
506struct edge_bundle_type<vtkGraph*>
507{
508 typedef no_property type;
509};
510
511inline bool has_no_edges(vtkGraph* g)
512{
513 return ((g->GetNumberOfEdges() > 0) ? false : true);
514}
515
516inline void remove_edge(graph_traits<vtkGraph*>::edge_descriptor e, vtkGraph* g)
517{
519 {
521 }
523 {
525 }
526}
527
528//===========================================================================
529// vtkDirectedGraph
530
531template <>
532struct graph_traits<vtkDirectedGraph*> : graph_traits<vtkGraph*>
533{
534 typedef directed_tag directed_category;
535};
536
537// The graph_traits for a const graph are the same as a non-const graph.
538template <>
539struct graph_traits<const vtkDirectedGraph*> : graph_traits<vtkDirectedGraph*>
540{
541};
542
543// The graph_traits for a const graph are the same as a non-const graph.
544template <>
545struct graph_traits<vtkDirectedGraph* const> : graph_traits<vtkDirectedGraph*>
546{
547};
548
549#if BOOST_VERSION >= 104500
550// Internal graph properties
551template <>
552struct graph_property_type<vtkDirectedGraph*> : graph_property_type<vtkGraph*>
553{
554};
555
556// Internal graph properties
557template <>
558struct graph_property_type<vtkDirectedGraph* const> : graph_property_type<vtkGraph*>
559{
560};
561#endif
562
563// Internal vertex properties
564template <>
565struct vertex_property_type<vtkDirectedGraph*> : vertex_property_type<vtkGraph*>
566{
567};
568
569// Internal vertex properties
570template <>
571struct vertex_property_type<vtkDirectedGraph* const> : vertex_property_type<vtkGraph*>
572{
573};
574
575// Internal edge properties
576template <>
577struct edge_property_type<vtkDirectedGraph*> : edge_property_type<vtkGraph*>
578{
579};
580
581// Internal edge properties
582template <>
583struct edge_property_type<vtkDirectedGraph* const> : edge_property_type<vtkGraph*>
584{
585};
586
587#if BOOST_VERSION >= 104500
588// Internal graph properties
589template <>
590struct graph_bundle_type<vtkDirectedGraph*> : graph_bundle_type<vtkGraph*>
591{
592};
593
594// Internal graph properties
595template <>
596struct graph_bundle_type<vtkDirectedGraph* const> : graph_bundle_type<vtkGraph*>
597{
598};
599#endif
600
601// Internal vertex properties
602template <>
603struct vertex_bundle_type<vtkDirectedGraph*> : vertex_bundle_type<vtkGraph*>
604{
605};
606
607// Internal vertex properties
608template <>
609struct vertex_bundle_type<vtkDirectedGraph* const> : vertex_bundle_type<vtkGraph*>
610{
611};
612
613// Internal edge properties
614template <>
615struct edge_bundle_type<vtkDirectedGraph*> : edge_bundle_type<vtkGraph*>
616{
617};
618
619// Internal edge properties
620template <>
621struct edge_bundle_type<vtkDirectedGraph* const> : edge_bundle_type<vtkGraph*>
622{
623};
624
625//===========================================================================
626// vtkTree
627
628template <>
629struct graph_traits<vtkTree*> : graph_traits<vtkDirectedGraph*>
630{
631};
632
633// The graph_traits for a const graph are the same as a non-const graph.
634template <>
635struct graph_traits<const vtkTree*> : graph_traits<vtkTree*>
636{
637};
638
639// The graph_traits for a const graph are the same as a non-const graph.
640template <>
641struct graph_traits<vtkTree* const> : graph_traits<vtkTree*>
642{
643};
644
645//===========================================================================
646// vtkUndirectedGraph
647template <>
648struct graph_traits<vtkUndirectedGraph*> : graph_traits<vtkGraph*>
649{
650 typedef undirected_tag directed_category;
651};
652
653// The graph_traits for a const graph are the same as a non-const graph.
654template <>
655struct graph_traits<const vtkUndirectedGraph*> : graph_traits<vtkUndirectedGraph*>
656{
657};
658
659// The graph_traits for a const graph are the same as a non-const graph.
660template <>
661struct graph_traits<vtkUndirectedGraph* const> : graph_traits<vtkUndirectedGraph*>
662{
663};
664
665#if BOOST_VERSION >= 104500
666// Internal graph properties
667template <>
668struct graph_property_type<vtkUndirectedGraph*> : graph_property_type<vtkGraph*>
669{
670};
671
672// Internal graph properties
673template <>
674struct graph_property_type<vtkUndirectedGraph* const> : graph_property_type<vtkGraph*>
675{
676};
677#endif
678
679// Internal vertex properties
680template <>
681struct vertex_property_type<vtkUndirectedGraph*> : vertex_property_type<vtkGraph*>
682{
683};
684
685// Internal vertex properties
686template <>
687struct vertex_property_type<vtkUndirectedGraph* const> : vertex_property_type<vtkGraph*>
688{
689};
690
691// Internal edge properties
692template <>
693struct edge_property_type<vtkUndirectedGraph*> : edge_property_type<vtkGraph*>
694{
695};
696
697// Internal edge properties
698template <>
699struct edge_property_type<vtkUndirectedGraph* const> : edge_property_type<vtkGraph*>
700{
701};
702
703#if BOOST_VERSION >= 104500
704// Internal graph properties
705template <>
706struct graph_bundle_type<vtkUndirectedGraph*> : graph_bundle_type<vtkGraph*>
707{
708};
709
710// Internal graph properties
711template <>
712struct graph_bundle_type<vtkUndirectedGraph* const> : graph_bundle_type<vtkGraph*>
713{
714};
715#endif
716
717// Internal vertex properties
718template <>
719struct vertex_bundle_type<vtkUndirectedGraph*> : vertex_bundle_type<vtkGraph*>
720{
721};
722
723// Internal vertex properties
724template <>
725struct vertex_bundle_type<vtkUndirectedGraph* const> : vertex_bundle_type<vtkGraph*>
726{
727};
728
729// Internal edge properties
730template <>
731struct edge_bundle_type<vtkUndirectedGraph*> : edge_bundle_type<vtkGraph*>
732{
733};
734
735// Internal edge properties
736template <>
737struct edge_bundle_type<vtkUndirectedGraph* const> : edge_bundle_type<vtkGraph*>
738{
739};
740
741//===========================================================================
742// vtkMutableDirectedGraph
743
744template <>
745struct graph_traits<vtkMutableDirectedGraph*> : graph_traits<vtkDirectedGraph*>
746{
747};
748
749// The graph_traits for a const graph are the same as a non-const graph.
750template <>
751struct graph_traits<const vtkMutableDirectedGraph*> : graph_traits<vtkMutableDirectedGraph*>
752{
753};
754
755// The graph_traits for a const graph are the same as a non-const graph.
756template <>
757struct graph_traits<vtkMutableDirectedGraph* const> : graph_traits<vtkMutableDirectedGraph*>
758{
759};
760
761#if BOOST_VERSION >= 104500
762// Internal graph properties
763template <>
764struct graph_property_type<vtkMutableDirectedGraph*> : graph_property_type<vtkDirectedGraph*>
765{
766};
767
768// Internal graph properties
769template <>
770struct graph_property_type<vtkMutableDirectedGraph* const> : graph_property_type<vtkDirectedGraph*>
771{
772};
773#endif
774
775// Internal vertex properties
776template <>
777struct vertex_property_type<vtkMutableDirectedGraph*> : vertex_property_type<vtkDirectedGraph*>
778{
779};
780
781// Internal vertex properties
782template <>
783struct vertex_property_type<vtkMutableDirectedGraph* const>
784 : vertex_property_type<vtkDirectedGraph*>
785{
786};
787
788// Internal edge properties
789template <>
790struct edge_property_type<vtkMutableDirectedGraph*> : edge_property_type<vtkDirectedGraph*>
791{
792};
793
794// Internal edge properties
795template <>
796struct edge_property_type<vtkMutableDirectedGraph* const> : edge_property_type<vtkDirectedGraph*>
797{
798};
799
800#if BOOST_VERSION >= 104500
801// Internal graph properties
802template <>
803struct graph_bundle_type<vtkMutableDirectedGraph*> : graph_bundle_type<vtkDirectedGraph*>
804{
805};
806
807// Internal graph properties
808template <>
809struct graph_bundle_type<vtkMutableDirectedGraph* const> : graph_bundle_type<vtkDirectedGraph*>
810{
811};
812#endif
813
814// Internal vertex properties
815template <>
816struct vertex_bundle_type<vtkMutableDirectedGraph*> : vertex_bundle_type<vtkDirectedGraph*>
817{
818};
819
820// Internal vertex properties
821template <>
822struct vertex_bundle_type<vtkMutableDirectedGraph* const> : vertex_bundle_type<vtkDirectedGraph*>
823{
824};
825
826// Internal edge properties
827template <>
828struct edge_bundle_type<vtkMutableDirectedGraph*> : edge_bundle_type<vtkDirectedGraph*>
829{
830};
831
832// Internal edge properties
833template <>
834struct edge_bundle_type<vtkMutableDirectedGraph* const> : edge_bundle_type<vtkDirectedGraph*>
835{
836};
837
838//===========================================================================
839// vtkMutableUndirectedGraph
840
841template <>
842struct graph_traits<vtkMutableUndirectedGraph*> : graph_traits<vtkUndirectedGraph*>
843{
844};
845
846// The graph_traits for a const graph are the same as a non-const graph.
847template <>
848struct graph_traits<const vtkMutableUndirectedGraph*> : graph_traits<vtkMutableUndirectedGraph*>
849{
850};
851
852// The graph_traits for a const graph are the same as a non-const graph.
853template <>
854struct graph_traits<vtkMutableUndirectedGraph* const> : graph_traits<vtkMutableUndirectedGraph*>
855{
856};
857
858#if BOOST_VERSION >= 104500
859// Internal graph properties
860template <>
861struct graph_property_type<vtkMutableUndirectedGraph*> : graph_property_type<vtkUndirectedGraph*>
862{
863};
864
865// Internal graph properties
866template <>
867struct graph_property_type<vtkMutableUndirectedGraph* const>
868 : graph_property_type<vtkUndirectedGraph*>
869{
870};
871#endif
872
873// Internal vertex properties
874template <>
875struct vertex_property_type<vtkMutableUndirectedGraph*> : vertex_property_type<vtkUndirectedGraph*>
876{
877};
878
879// Internal vertex properties
880template <>
881struct vertex_property_type<vtkMutableUndirectedGraph* const>
882 : vertex_property_type<vtkUndirectedGraph*>
883{
884};
885
886// Internal edge properties
887template <>
888struct edge_property_type<vtkMutableUndirectedGraph*> : edge_property_type<vtkUndirectedGraph*>
889{
890};
891
892// Internal edge properties
893template <>
894struct edge_property_type<vtkMutableUndirectedGraph* const>
895 : edge_property_type<vtkUndirectedGraph*>
896{
897};
898
899#if BOOST_VERSION >= 104500
900// Internal graph properties
901template <>
902struct graph_bundle_type<vtkMutableUndirectedGraph*> : graph_bundle_type<vtkUndirectedGraph*>
903{
904};
905
906// Internal graph properties
907template <>
908struct graph_bundle_type<vtkMutableUndirectedGraph* const> : graph_bundle_type<vtkUndirectedGraph*>
909{
910};
911#endif
912
913// Internal vertex properties
914template <>
915struct vertex_bundle_type<vtkMutableUndirectedGraph*> : vertex_bundle_type<vtkUndirectedGraph*>
916{
917};
918
919// Internal vertex properties
920template <>
921struct vertex_bundle_type<vtkMutableUndirectedGraph* const>
922 : vertex_bundle_type<vtkUndirectedGraph*>
923{
924};
925
926// Internal edge properties
927template <>
928struct edge_bundle_type<vtkMutableUndirectedGraph*> : edge_bundle_type<vtkUndirectedGraph*>
929{
930};
931
932// Internal edge properties
933template <>
934struct edge_bundle_type<vtkMutableUndirectedGraph* const> : edge_bundle_type<vtkUndirectedGraph*>
935{
936};
937
938//===========================================================================
939// API implementation
940template <>
941class vertex_property<vtkGraph*>
942{
943public:
945};
946
947template <>
948class edge_property<vtkGraph*>
949{
950public:
952};
953} // end namespace boost
954
955inline boost::graph_traits<vtkGraph*>::vertex_descriptor source(
956 boost::graph_traits<vtkGraph*>::edge_descriptor e, vtkGraph*)
957{
958 return e.Source;
959}
960
961inline boost::graph_traits<vtkGraph*>::vertex_descriptor target(
962 boost::graph_traits<vtkGraph*>::edge_descriptor e, vtkGraph*)
963{
964 return e.Target;
965}
966
967inline std::pair<boost::graph_traits<vtkGraph*>::vertex_iterator,
968 boost::graph_traits<vtkGraph*>::vertex_iterator>
970{
971 typedef boost::graph_traits<vtkGraph*>::vertex_iterator Iter;
972 vtkIdType start = 0;
974 {
976 start = helper->MakeDistributedId(rank, start);
977 }
978
979 return std::make_pair(Iter(start), Iter(start + g->GetNumberOfVertices()));
980}
981
982inline std::pair<boost::graph_traits<vtkGraph*>::edge_iterator,
983 boost::graph_traits<vtkGraph*>::edge_iterator>
985{
986 typedef boost::graph_traits<vtkGraph*>::edge_iterator Iter;
987 return std::make_pair(Iter(g), Iter(g, g->GetNumberOfVertices()));
988}
989
990inline std::pair<boost::graph_traits<vtkGraph*>::out_edge_iterator,
991 boost::graph_traits<vtkGraph*>::out_edge_iterator>
992out_edges(boost::graph_traits<vtkGraph*>::vertex_descriptor u, vtkGraph* g)
993{
994 typedef boost::graph_traits<vtkGraph*>::out_edge_iterator Iter;
995 std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
996 return p;
997}
998
999inline std::pair<boost::graph_traits<vtkGraph*>::in_edge_iterator,
1000 boost::graph_traits<vtkGraph*>::in_edge_iterator>
1001in_edges(boost::graph_traits<vtkGraph*>::vertex_descriptor u, vtkGraph* g)
1002{
1003 typedef boost::graph_traits<vtkGraph*>::in_edge_iterator Iter;
1004 std::pair<Iter, Iter> p = std::make_pair(Iter(g, u), Iter(g, u, true));
1005 return p;
1006}
1007
1008inline std::pair<boost::graph_traits<vtkGraph*>::adjacency_iterator,
1009 boost::graph_traits<vtkGraph*>::adjacency_iterator>
1010adjacent_vertices(boost::graph_traits<vtkGraph*>::vertex_descriptor u, vtkGraph* g)
1011{
1012 typedef boost::graph_traits<vtkGraph*>::adjacency_iterator Iter;
1013 typedef boost::graph_traits<vtkGraph*>::out_edge_iterator OutEdgeIter;
1014 std::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g);
1015 return std::make_pair(Iter(out.first, &g), Iter(out.second, &g));
1016}
1017
1018inline boost::graph_traits<vtkGraph*>::vertices_size_type num_vertices(vtkGraph* g)
1019{
1020 return g->GetNumberOfVertices();
1021}
1022
1023inline boost::graph_traits<vtkGraph*>::edges_size_type num_edges(vtkGraph* g)
1024{
1025 return g->GetNumberOfEdges();
1026}
1027
1028inline boost::graph_traits<vtkGraph*>::degree_size_type out_degree(
1029 boost::graph_traits<vtkGraph*>::vertex_descriptor u, vtkGraph* g)
1030{
1031 return g->GetOutDegree(u);
1032}
1033
1034inline boost::graph_traits<vtkDirectedGraph*>::degree_size_type in_degree(
1035 boost::graph_traits<vtkDirectedGraph*>::vertex_descriptor u, vtkDirectedGraph* g)
1036{
1037 return g->GetInDegree(u);
1038}
1039
1040inline boost::graph_traits<vtkGraph*>::degree_size_type degree(
1041 boost::graph_traits<vtkGraph*>::vertex_descriptor u, vtkGraph* g)
1042{
1043 return g->GetDegree(u);
1044}
1045
1046inline boost::graph_traits<vtkMutableDirectedGraph*>::vertex_descriptor add_vertex(
1048{
1049 return g->AddVertex();
1050}
1051
1052inline std::pair<boost::graph_traits<vtkMutableDirectedGraph*>::edge_descriptor, bool> add_edge(
1053 boost::graph_traits<vtkMutableDirectedGraph*>::vertex_descriptor u,
1054 boost::graph_traits<vtkMutableDirectedGraph*>::vertex_descriptor v, vtkMutableDirectedGraph* g)
1055{
1056 boost::graph_traits<vtkMutableDirectedGraph*>::edge_descriptor e = g->AddEdge(u, v);
1057 return std::make_pair(e, true);
1058}
1059
1060inline boost::graph_traits<vtkMutableUndirectedGraph*>::vertex_descriptor add_vertex(
1062{
1063 return g->AddVertex();
1064}
1065
1066inline std::pair<boost::graph_traits<vtkMutableUndirectedGraph*>::edge_descriptor, bool> add_edge(
1067 boost::graph_traits<vtkMutableUndirectedGraph*>::vertex_descriptor u,
1068 boost::graph_traits<vtkMutableUndirectedGraph*>::vertex_descriptor v,
1070{
1071 boost::graph_traits<vtkMutableUndirectedGraph*>::edge_descriptor e = g->AddEdge(u, v);
1072 return std::make_pair(e, true);
1073}
1074
1075namespace boost
1076{
1077VTK_ABI_NAMESPACE_BEGIN
1078//===========================================================================
1079// An edge map for vtkGraph.
1080// This is a common input needed for algorithms.
1081
1083{
1084};
1085
1086VTK_ABI_NAMESPACE_END
1087
1088template <>
1090{
1094 typedef readable_property_map_tag category;
1095};
1096
1099{
1100 return key.Id;
1101}
1102
1103//===========================================================================
1104// Helper for vtkGraph edge property maps
1105// Automatically converts boost edge ids to vtkGraph edge ids.
1106
1107VTK_ABI_NAMESPACE_BEGIN
1108template <typename PMap>
1110{
1111public:
1113 : pmap(m)
1114 {
1115 }
1116 PMap pmap;
1121
1122 reference operator[](const key_type& key) const { return get(pmap, key.Id); }
1123};
1124VTK_ABI_NAMESPACE_END
1125
1126template <typename PMap>
1129{
1130 return get(helper.pmap, key.Id);
1131}
1132
1133template <typename PMap>
1135 const typename property_traits<PMap>::value_type& value)
1136{
1137 put(helper.pmap, key.Id, value);
1138}
1139
1140//===========================================================================
1141// Helper for vtkGraph vertex property maps
1142// Automatically converts boost vertex ids to vtkGraph vertex ids.
1143
1144VTK_ABI_NAMESPACE_BEGIN
1145template <typename PMap>
1147{
1148public:
1150 : pmap(m)
1151 {
1152 }
1153 PMap pmap;
1158
1159 reference operator[](const key_type& key) const { return get(pmap, key); }
1160};
1161VTK_ABI_NAMESPACE_END
1162
1163template <typename PMap>
1166{
1167 return get(helper.pmap, key);
1168}
1169
1170template <typename PMap>
1172 const typename property_traits<PMap>::value_type& value)
1173{
1174 put(helper.pmap, key, value);
1175}
1176
1177//===========================================================================
1178// An index map for vtkGraph
1179// This is a common input needed for algorithms
1180
1181VTK_ABI_NAMESPACE_BEGIN
1183{
1184};
1185VTK_ABI_NAMESPACE_END
1186
1187template <>
1189{
1193 typedef readable_property_map_tag category;
1194};
1195
1198{
1199 return key;
1200}
1201
1202//===========================================================================
1203// Helper for vtkGraph property maps
1204// Automatically multiplies the property value by some value (default 1)
1205VTK_ABI_NAMESPACE_BEGIN
1206template <typename PMap>
1208{
1209public:
1210 vtkGraphPropertyMapMultiplier(PMap m, float multi = 1)
1211 : pmap(m)
1212 , multiplier(multi)
1213 {
1214 }
1215 PMap pmap;
1221};
1222VTK_ABI_NAMESPACE_END
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=nullptr, vtkIdType v=0)
vtk_in_edge_pointer_iterator(vtkGraph *g=nullptr, vtkIdType v=0, bool end=false)
vtk_out_edge_pointer_iterator(vtkGraph *g=nullptr, 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:281
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:35
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:46
An undirected graph.
A type representing the union of many types.
Definition vtkVariant.h:53
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:242
vtkIdType Source
Definition vtkGraph.h:264
vtkIdType Target
Definition vtkGraph.h:253
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:315