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