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