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