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