00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00029 #ifndef __vtkBoostGraphAdapter_h
00030 #define __vtkBoostGraphAdapter_h
00031
00032 #include "vtkAbstractArray.h"
00033 #include "vtkDirectedGraph.h"
00034 #include "vtkDistributedGraphHelper.h"
00035 #include "vtkDataObject.h"
00036 #include "vtkDataArray.h"
00037 #include "vtkDoubleArray.h"
00038 #include "vtkFloatArray.h"
00039 #include "vtkIdTypeArray.h"
00040 #include "vtkInformation.h"
00041 #include "vtkIntArray.h"
00042 #include "vtkMutableDirectedGraph.h"
00043 #include "vtkMutableUndirectedGraph.h"
00044 #include "vtkTree.h"
00045 #include "vtkUndirectedGraph.h"
00046 #include "vtkVariant.h"
00047 #include <stddef.h>
00048
00049 namespace boost {
00050
00051
00052
00053
00054
00055
00056 template<typename> class property_traits;
00057 class read_write_property_map_tag;
00058
00059 #define vtkPropertyMapMacro(T, V) \
00060 template <> \
00061 struct property_traits<T*> \
00062 { \
00063 typedef V value_type; \
00064 typedef V reference; \
00065 typedef vtkIdType key_type; \
00066 typedef read_write_property_map_tag category; \
00067 }; \
00068 \
00069 inline property_traits<T*>::reference \
00070 get( \
00071 T* const & arr, \
00072 property_traits<T*>::key_type key) \
00073 { \
00074 return arr->GetValue(key); \
00075 } \
00076 \
00077 inline void \
00078 put( \
00079 T* arr, \
00080 property_traits<T*>::key_type key, \
00081 const property_traits<T*>::value_type & value) \
00082 { \
00083 arr->InsertValue(key, value); \
00084 }
00085
00086 vtkPropertyMapMacro(vtkIntArray, int)
00087 vtkPropertyMapMacro(vtkIdTypeArray, vtkIdType)
00088 vtkPropertyMapMacro(vtkDoubleArray, double)
00089 vtkPropertyMapMacro(vtkFloatArray, float)
00090
00091
00092 template<>
00093 struct property_traits<vtkDataArray*>
00094 {
00095 typedef double value_type;
00096 typedef double reference;
00097 typedef vtkIdType key_type;
00098 typedef read_write_property_map_tag category;
00099 };
00100
00101 inline double
00102 get(vtkDataArray * const& arr, vtkIdType key)
00103 {
00104 return arr->GetTuple1(key);
00105 }
00106
00107 inline void
00108 put(vtkDataArray *arr, vtkIdType key, const double& value)
00109 {
00110 arr->SetTuple1(key, value);
00111 }
00112
00113
00114 template<>
00115 struct property_traits<vtkAbstractArray*>
00116 {
00117 typedef vtkVariant value_type;
00118 typedef vtkVariant reference;
00119 typedef vtkIdType key_type;
00120 typedef read_write_property_map_tag category;
00121 };
00122
00123 inline vtkVariant
00124 get(vtkAbstractArray * const& arr, vtkIdType key)
00125 {
00126 return arr->GetVariantValue(key);
00127 }
00128
00129 inline void
00130 put(vtkAbstractArray *arr, vtkIdType key, const vtkVariant& value)
00131 {
00132 arr->InsertVariantValue(key, value);
00133 }
00134 }
00135
00136 #include <vtksys/stl/utility>
00137
00138 #include <boost/config.hpp>
00139 #include <boost/iterator/iterator_facade.hpp>
00140 #include <boost/graph/graph_traits.hpp>
00141 #include <boost/graph/properties.hpp>
00142 #include <boost/graph/adjacency_iterator.hpp>
00143
00144
00145
00146
00147
00148 namespace boost {
00149
00150 class vtk_vertex_iterator :
00151 public iterator_facade<vtk_vertex_iterator,
00152 vtkIdType,
00153 bidirectional_traversal_tag,
00154 vtkIdType,
00155 vtkIdType>
00156 {
00157 public:
00158 explicit vtk_vertex_iterator(vtkIdType i = 0) : index(i) {}
00159
00160 private:
00161 vtkIdType dereference() const { return index; }
00162
00163 bool equal(const vtk_vertex_iterator& other) const
00164 { return index == other.index; }
00165
00166 void increment() { index++; }
00167 void decrement() { index--; }
00168
00169 vtkIdType index;
00170
00171 friend class iterator_core_access;
00172 };
00173
00174 class vtk_edge_iterator :
00175 public iterator_facade<vtk_edge_iterator,
00176 vtkEdgeType,
00177 forward_traversal_tag,
00178 vtkEdgeType,
00179 vtkIdType>
00180 {
00181 public:
00182 explicit vtk_edge_iterator(vtkGraph *g = 0, vtkIdType v = 0) :
00183 directed(false), vertex(v), lastVertex(v), iter(0), end(0), graph(g)
00184 {
00185 if (graph)
00186 {
00187 lastVertex = graph->GetNumberOfVertices();
00188 }
00189
00190 vtkIdType myRank = -1;
00191 vtkDistributedGraphHelper *helper
00192 = this->graph? this->graph->GetDistributedGraphHelper() : 0;
00193 if (helper)
00194 {
00195 myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
00196 vertex = helper->MakeDistributedId(myRank, vertex);
00197 lastVertex = helper->MakeDistributedId(myRank, lastVertex);
00198 }
00199
00200 if (graph != 0)
00201 {
00202 directed = (vtkDirectedGraph::SafeDownCast(graph) != 0);
00203 while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
00204 {
00205 ++vertex;
00206 }
00207
00208 if (vertex < lastVertex)
00209 {
00210
00211
00212 vtkIdType nedges;
00213 graph->GetOutEdges(vertex, iter, nedges);
00214 end = iter + nedges;
00215
00216 if (!directed)
00217 {
00218 while(iter != 0
00219 && (
00220 (helper && helper->GetEdgeOwner(iter->Id) != myRank)
00221
00222 || (((helper
00223 && myRank == helper->GetVertexOwner(iter->Target))
00224 || !helper)
00225 && vertex > iter->Target)))
00226 {
00227 this->inc();
00228 }
00229 }
00230 }
00231 else
00232 {
00233 iter = 0;
00234 }
00235 }
00236 }
00237
00238 private:
00239 vtkEdgeType dereference() const
00240 { return vtkEdgeType(vertex, iter->Target, iter->Id); }
00241
00242 bool equal(const vtk_edge_iterator& other) const
00243 { return vertex == other.vertex && iter == other.iter; }
00244
00245 void increment()
00246 {
00247 inc();
00248 if (!directed)
00249 {
00250 vtkIdType myRank = -1;
00251 vtkDistributedGraphHelper *helper
00252 = this->graph? this->graph->GetDistributedGraphHelper() : 0;
00253 if (helper)
00254 {
00255 myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
00256 }
00257
00258 while (iter != 0
00259 && (
00260 (helper && helper->GetEdgeOwner(iter->Id) != myRank)
00261
00262 || (((helper
00263 && myRank == helper->GetVertexOwner(iter->Target))
00264 || !helper)
00265 && vertex > iter->Target)))
00266 {
00267 inc();
00268 }
00269 }
00270 }
00271
00272 void inc()
00273 {
00274 ++iter;
00275 if (iter == end)
00276 {
00277
00278 ++vertex;
00279 while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0)
00280 {
00281 ++vertex;
00282 }
00283
00284 if (vertex < lastVertex)
00285 {
00286 vtkIdType nedges;
00287 graph->GetOutEdges(vertex, iter, nedges);
00288 end = iter + nedges;
00289 }
00290 else
00291 {
00292 iter = 0;
00293 }
00294 }
00295 }
00296
00297 bool directed;
00298 vtkIdType vertex;
00299 vtkIdType lastVertex;
00300 const vtkOutEdgeType * iter;
00301 const vtkOutEdgeType * end;
00302 vtkGraph *graph;
00303
00304 friend class iterator_core_access;
00305 };
00306
00307 class vtk_out_edge_pointer_iterator :
00308 public iterator_facade<vtk_out_edge_pointer_iterator,
00309 vtkEdgeType,
00310 bidirectional_traversal_tag,
00311 vtkEdgeType,
00312 ptrdiff_t>
00313 {
00314 public:
00315 explicit vtk_out_edge_pointer_iterator(vtkGraph *g = 0, vtkIdType v = 0, bool end = false) :
00316 vertex(v)
00317 {
00318 if (g)
00319 {
00320 vtkIdType nedges;
00321 g->GetOutEdges(vertex, iter, nedges);
00322 if (end)
00323 {
00324 iter += nedges;
00325 }
00326 }
00327 }
00328
00329 private:
00330 vtkEdgeType dereference() const { return vtkEdgeType(vertex, iter->Target, iter->Id); }
00331
00332 bool equal(const vtk_out_edge_pointer_iterator& other) const
00333 { return iter == other.iter; }
00334
00335 void increment() { iter++; }
00336 void decrement() { iter--; }
00337
00338 vtkIdType vertex;
00339 const vtkOutEdgeType *iter;
00340
00341 friend class iterator_core_access;
00342 };
00343
00344 class vtk_in_edge_pointer_iterator :
00345 public iterator_facade<vtk_in_edge_pointer_iterator,
00346 vtkEdgeType,
00347 bidirectional_traversal_tag,
00348 vtkEdgeType,
00349 ptrdiff_t>
00350 {
00351 public:
00352 explicit vtk_in_edge_pointer_iterator(vtkGraph *g = 0, vtkIdType v = 0, bool end = false) :
00353 vertex(v)
00354 {
00355 if (g)
00356 {
00357 vtkIdType nedges;
00358 g->GetInEdges(vertex, iter, nedges);
00359 if (end)
00360 {
00361 iter += nedges;
00362 }
00363 }
00364 }
00365
00366 private:
00367 vtkEdgeType dereference() const { return vtkEdgeType(iter->Source, vertex, iter->Id); }
00368
00369 bool equal(const vtk_in_edge_pointer_iterator& other) const
00370 { return iter == other.iter; }
00371
00372 void increment() { iter++; }
00373 void decrement() { iter--; }
00374
00375 vtkIdType vertex;
00376 const vtkInEdgeType *iter;
00377
00378 friend class iterator_core_access;
00379 };
00380
00381
00382
00383
00384
00385
00386
00387 struct vtkGraph_traversal_category :
00388 public virtual bidirectional_graph_tag,
00389 public virtual edge_list_graph_tag,
00390 public virtual vertex_list_graph_tag,
00391 public virtual adjacency_graph_tag { };
00392
00393 template <>
00394 struct graph_traits<vtkGraph*> {
00395 typedef vtkIdType vertex_descriptor;
00396 static vertex_descriptor null_vertex() { return -1; }
00397 typedef vtkEdgeType edge_descriptor;
00398 static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); }
00399 typedef vtk_out_edge_pointer_iterator out_edge_iterator;
00400 typedef vtk_in_edge_pointer_iterator in_edge_iterator;
00401
00402 typedef vtk_vertex_iterator vertex_iterator;
00403 typedef vtk_edge_iterator edge_iterator;
00404
00405 typedef allow_parallel_edge_tag edge_parallel_category;
00406 typedef vtkGraph_traversal_category traversal_category;
00407 typedef vtkIdType vertices_size_type;
00408 typedef vtkIdType edges_size_type;
00409 typedef vtkIdType degree_size_type;
00410
00411 typedef adjacency_iterator_generator<vtkGraph*,
00412 vertex_descriptor, out_edge_iterator>::type adjacency_iterator;
00413 };
00414
00415 template<>
00416 struct vertex_property_type< vtkGraph* > {
00417 typedef no_property type;
00418 };
00419
00420 template<>
00421 struct edge_property_type< vtkGraph* > {
00422 typedef no_property type;
00423 };
00424
00425
00426
00427
00428 template <>
00429 struct graph_traits<vtkDirectedGraph*> : graph_traits<vtkGraph*>
00430 {
00431 typedef directed_tag directed_category;
00432 };
00433
00434
00435 template <>
00436 struct graph_traits<const vtkDirectedGraph*> : graph_traits<vtkDirectedGraph*> { };
00437
00438
00439 template <>
00440 struct graph_traits<vtkDirectedGraph* const> : graph_traits<vtkDirectedGraph*> { };
00441
00442
00443 template<>
00444 struct vertex_property_type< vtkDirectedGraph* >
00445 : vertex_property_type< vtkGraph* > { };
00446
00447
00448 template<>
00449 struct vertex_property_type< vtkDirectedGraph* const >
00450 : vertex_property_type< vtkGraph* > { };
00451
00452
00453 template<>
00454 struct edge_property_type< vtkDirectedGraph* >
00455 : edge_property_type< vtkGraph* > { };
00456
00457
00458 template<>
00459 struct edge_property_type< vtkDirectedGraph* const >
00460 : edge_property_type< vtkGraph* > { };
00461
00462
00463
00464
00465 template <>
00466 struct graph_traits<vtkTree*> : graph_traits<vtkDirectedGraph*> { };
00467
00468
00469 template <>
00470 struct graph_traits<const vtkTree*> : graph_traits<vtkTree*> { };
00471
00472
00473 template <>
00474 struct graph_traits<vtkTree* const> : graph_traits<vtkTree*> { };
00475
00476
00477
00478 template <>
00479 struct graph_traits<vtkUndirectedGraph*> : graph_traits<vtkGraph*>
00480 {
00481 typedef undirected_tag directed_category;
00482 };
00483
00484
00485 template <>
00486 struct graph_traits<const vtkUndirectedGraph*> : graph_traits<vtkUndirectedGraph*> { };
00487
00488
00489 template <>
00490 struct graph_traits<vtkUndirectedGraph* const> : graph_traits<vtkUndirectedGraph*> { };
00491
00492
00493 template<>
00494 struct vertex_property_type< vtkUndirectedGraph* >
00495 : vertex_property_type< vtkGraph* > { };
00496
00497
00498 template<>
00499 struct vertex_property_type< vtkUndirectedGraph* const >
00500 : vertex_property_type< vtkGraph* > { };
00501
00502
00503 template<>
00504 struct edge_property_type< vtkUndirectedGraph* >
00505 : edge_property_type< vtkGraph* > { };
00506
00507
00508 template<>
00509 struct edge_property_type< vtkUndirectedGraph* const >
00510 : edge_property_type< vtkGraph* > { };
00511
00512
00513
00514
00515 template <>
00516 struct graph_traits<vtkMutableDirectedGraph*> : graph_traits<vtkDirectedGraph*> { };
00517
00518
00519 template <>
00520 struct graph_traits<const vtkMutableDirectedGraph*> : graph_traits<vtkMutableDirectedGraph*> { };
00521
00522
00523 template <>
00524 struct graph_traits<vtkMutableDirectedGraph* const> : graph_traits<vtkMutableDirectedGraph*> { };
00525
00526
00527 template<>
00528 struct vertex_property_type< vtkMutableDirectedGraph* >
00529 : vertex_property_type< vtkDirectedGraph* > { };
00530
00531
00532 template<>
00533 struct vertex_property_type< vtkMutableDirectedGraph* const >
00534 : vertex_property_type< vtkDirectedGraph* > { };
00535
00536
00537 template<>
00538 struct edge_property_type< vtkMutableDirectedGraph* >
00539 : edge_property_type< vtkDirectedGraph* > { };
00540
00541
00542 template<>
00543 struct edge_property_type< vtkMutableDirectedGraph* const >
00544 : edge_property_type< vtkDirectedGraph* > { };
00545
00546
00547
00548
00549 template <>
00550 struct graph_traits<vtkMutableUndirectedGraph*> : graph_traits<vtkUndirectedGraph*> { };
00551
00552
00553 template <>
00554 struct graph_traits<const vtkMutableUndirectedGraph*> : graph_traits<vtkMutableUndirectedGraph*> { };
00555
00556
00557 template <>
00558 struct graph_traits<vtkMutableUndirectedGraph* const> : graph_traits<vtkMutableUndirectedGraph*> { };
00559
00560
00561 template<>
00562 struct vertex_property_type< vtkMutableUndirectedGraph* >
00563 : vertex_property_type< vtkUndirectedGraph* > { };
00564
00565
00566 template<>
00567 struct vertex_property_type< vtkMutableUndirectedGraph* const >
00568 : vertex_property_type< vtkUndirectedGraph* > { };
00569
00570
00571 template<>
00572 struct edge_property_type< vtkMutableUndirectedGraph* >
00573 : edge_property_type< vtkUndirectedGraph* > { };
00574
00575
00576 template<>
00577 struct edge_property_type< vtkMutableUndirectedGraph* const >
00578 : edge_property_type< vtkUndirectedGraph* > { };
00579
00580
00581
00582 template <>
00583 class vertex_property< vtkGraph* > {
00584 public:
00585 typedef vtkIdType type;
00586 };
00587
00588 template <>
00589 class edge_property< vtkGraph* > {
00590 public:
00591 typedef vtkIdType type;
00592 };
00593 }
00594
00595 inline boost::graph_traits< vtkGraph* >::vertex_descriptor
00596 source(boost::graph_traits< vtkGraph* >::edge_descriptor e,
00597 vtkGraph *)
00598 {
00599 return e.Source;
00600 }
00601
00602 inline boost::graph_traits< vtkGraph* >::vertex_descriptor
00603 target(boost::graph_traits< vtkGraph* >::edge_descriptor e,
00604 vtkGraph *)
00605 {
00606 return e.Target;
00607 }
00608
00609 inline vtksys_stl::pair<
00610 boost::graph_traits< vtkGraph* >::vertex_iterator,
00611 boost::graph_traits< vtkGraph* >::vertex_iterator >
00612 vertices(vtkGraph *g)
00613 {
00614 typedef boost::graph_traits< vtkGraph* >::vertex_iterator Iter;
00615 vtkIdType start = 0;
00616 if (vtkDistributedGraphHelper *helper = g->GetDistributedGraphHelper())
00617 {
00618 int rank =
00619 g->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER());
00620 start = helper->MakeDistributedId(rank, start);
00621 }
00622
00623 return vtksys_stl::make_pair( Iter(start),
00624 Iter(start + g->GetNumberOfVertices()) );
00625 }
00626
00627 inline vtksys_stl::pair<
00628 boost::graph_traits< vtkGraph* >::edge_iterator,
00629 boost::graph_traits< vtkGraph* >::edge_iterator >
00630 edges(vtkGraph *g)
00631 {
00632 typedef boost::graph_traits< vtkGraph* >::edge_iterator Iter;
00633 return vtksys_stl::make_pair( Iter(g), Iter(g, g->GetNumberOfVertices()) );
00634 }
00635
00636 inline vtksys_stl::pair<
00637 boost::graph_traits< vtkGraph* >::out_edge_iterator,
00638 boost::graph_traits< vtkGraph* >::out_edge_iterator >
00639 out_edges(
00640 boost::graph_traits< vtkGraph* >::vertex_descriptor u,
00641 vtkGraph *g)
00642 {
00643 typedef boost::graph_traits< vtkGraph* >::out_edge_iterator Iter;
00644 vtksys_stl::pair<Iter, Iter> p = vtksys_stl::make_pair( Iter(g, u), Iter(g, u, true) );
00645 return p;
00646 }
00647
00648 inline vtksys_stl::pair<
00649 boost::graph_traits< vtkGraph* >::in_edge_iterator,
00650 boost::graph_traits< vtkGraph* >::in_edge_iterator >
00651 in_edges(
00652 boost::graph_traits< vtkGraph* >::vertex_descriptor u,
00653 vtkGraph *g)
00654 {
00655 typedef boost::graph_traits< vtkGraph* >::in_edge_iterator Iter;
00656 vtksys_stl::pair<Iter, Iter> p = vtksys_stl::make_pair( Iter(g, u), Iter(g, u, true) );
00657 return p;
00658 }
00659
00660 inline vtksys_stl::pair<
00661 boost::graph_traits< vtkGraph* >::adjacency_iterator,
00662 boost::graph_traits< vtkGraph* >::adjacency_iterator >
00663 adjacent_vertices(
00664 boost::graph_traits< vtkGraph* >::vertex_descriptor u,
00665 vtkGraph *g)
00666 {
00667 typedef boost::graph_traits< vtkGraph* >::adjacency_iterator Iter;
00668 typedef boost::graph_traits< vtkGraph* >::out_edge_iterator OutEdgeIter;
00669 vtksys_stl::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g);
00670 return vtksys_stl::make_pair( Iter(out.first, &g), Iter(out.second, &g) );
00671 }
00672
00673 inline boost::graph_traits< vtkGraph* >::vertices_size_type
00674 num_vertices(vtkGraph *g)
00675 {
00676 return g->GetNumberOfVertices();
00677 }
00678
00679 inline boost::graph_traits< vtkGraph* >::edges_size_type
00680 num_edges(vtkGraph *g)
00681 {
00682 return g->GetNumberOfEdges();
00683 }
00684
00685 inline boost::graph_traits< vtkGraph* >::degree_size_type
00686 out_degree(
00687 boost::graph_traits< vtkGraph* >::vertex_descriptor u,
00688 vtkGraph *g)
00689 {
00690 return g->GetOutDegree(u);
00691 }
00692
00693 inline boost::graph_traits< vtkDirectedGraph* >::degree_size_type
00694 in_degree(
00695 boost::graph_traits< vtkDirectedGraph* >::vertex_descriptor u,
00696 vtkDirectedGraph *g)
00697 {
00698 return g->GetInDegree(u);
00699 }
00700
00701 inline boost::graph_traits< vtkGraph* >::degree_size_type
00702 degree(
00703 boost::graph_traits< vtkGraph* >::vertex_descriptor u,
00704 vtkGraph *g)
00705 {
00706 return g->GetDegree(u);
00707 }
00708
00709 inline boost::graph_traits< vtkMutableDirectedGraph* >::vertex_descriptor
00710 add_vertex(vtkMutableDirectedGraph *g)
00711 {
00712 return g->AddVertex();
00713 }
00714
00715 inline vtksys_stl::pair<
00716 boost::graph_traits< vtkMutableDirectedGraph* >::edge_descriptor,
00717 bool>
00718 add_edge(
00719 boost::graph_traits< vtkMutableDirectedGraph* >::vertex_descriptor u,
00720 boost::graph_traits< vtkMutableDirectedGraph* >::vertex_descriptor v,
00721 vtkMutableDirectedGraph *g)
00722 {
00723 boost::graph_traits< vtkMutableDirectedGraph* >::edge_descriptor e = g->AddEdge(u, v);
00724 return vtksys_stl::make_pair(e, true);
00725 }
00726
00727 inline boost::graph_traits< vtkMutableUndirectedGraph* >::vertex_descriptor
00728 add_vertex(vtkMutableUndirectedGraph *g)
00729 {
00730 return g->AddVertex();
00731 }
00732
00733 inline vtksys_stl::pair<
00734 boost::graph_traits< vtkMutableUndirectedGraph* >::edge_descriptor,
00735 bool>
00736 add_edge(
00737 boost::graph_traits< vtkMutableUndirectedGraph* >::vertex_descriptor u,
00738 boost::graph_traits< vtkMutableUndirectedGraph* >::vertex_descriptor v,
00739 vtkMutableUndirectedGraph *g)
00740 {
00741 boost::graph_traits< vtkMutableUndirectedGraph* >::edge_descriptor e = g->AddEdge(u, v);
00742 return vtksys_stl::make_pair(e, true);
00743 }
00744
00745 namespace boost {
00746
00747
00748
00749
00750 struct vtkGraphEdgeMap { };
00751
00752 template <>
00753 struct property_traits<vtkGraphEdgeMap>
00754 {
00755 typedef vtkIdType value_type;
00756 typedef vtkIdType reference;
00757 typedef vtkEdgeType key_type;
00758 typedef readable_property_map_tag category;
00759 };
00760
00761 inline property_traits<vtkGraphEdgeMap>::reference
00762 get(
00763 vtkGraphEdgeMap vtkNotUsed(arr),
00764 property_traits<vtkGraphEdgeMap>::key_type key)
00765 {
00766 return key.Id;
00767 }
00768
00769
00770
00771
00772
00773 template<typename PMap>
00774 class vtkGraphEdgePropertyMapHelper
00775 {
00776 public:
00777 vtkGraphEdgePropertyMapHelper(PMap m) : pmap(m) { }
00778 PMap pmap;
00779 typedef typename property_traits<PMap>::value_type value_type;
00780 typedef typename property_traits<PMap>::reference reference;
00781 typedef vtkEdgeType key_type;
00782 typedef typename property_traits<PMap>::category category;
00783 };
00784
00785 template<typename PMap>
00786 inline typename property_traits<PMap>::reference
00787 get(
00788 vtkGraphEdgePropertyMapHelper<PMap> helper,
00789 vtkEdgeType key)
00790 {
00791 return get(helper.pmap, key.Id);
00792 }
00793
00794 template<typename PMap>
00795 inline void
00796 put(
00797 vtkGraphEdgePropertyMapHelper<PMap> helper,
00798 vtkEdgeType key,
00799 const typename property_traits<PMap>::value_type & value)
00800 {
00801 put(helper.pmap, key.Id, value);
00802 }
00803
00804
00805
00806
00807
00808 struct vtkGraphIndexMap { };
00809
00810 template <>
00811 struct property_traits<vtkGraphIndexMap>
00812 {
00813 typedef vtkIdType value_type;
00814 typedef vtkIdType reference;
00815 typedef vtkIdType key_type;
00816 typedef readable_property_map_tag category;
00817 };
00818
00819 inline property_traits<vtkGraphIndexMap>::reference
00820 get(
00821 vtkGraphIndexMap vtkNotUsed(arr),
00822 property_traits<vtkGraphIndexMap>::key_type key)
00823 {
00824 return key;
00825 }
00826
00827
00828
00829
00830 template<typename PMap>
00831 class vtkGraphPropertyMapMultiplier
00832 {
00833 public:
00834 vtkGraphPropertyMapMultiplier(PMap m, float multi=1) : pmap(m),multiplier(multi){}
00835 PMap pmap;
00836 float multiplier;
00837 typedef typename property_traits<PMap>::value_type value_type;
00838 typedef typename property_traits<PMap>::reference reference;
00839 typedef typename property_traits<PMap>::key_type key_type;
00840 typedef typename property_traits<PMap>::category category;
00841 };
00842
00843 template<typename PMap>
00844 inline typename property_traits<PMap>::reference
00845 get(
00846 vtkGraphPropertyMapMultiplier<PMap> multi,
00847 const typename property_traits<PMap>::key_type key)
00848 {
00849 return multi.multiplier * get(multi.pmap, key);
00850 }
00851
00852 template<typename PMap>
00853 inline void
00854 put(
00855 vtkGraphPropertyMapMultiplier<PMap> multi,
00856 const typename property_traits<PMap>::key_type key,
00857 const typename property_traits<PMap>::value_type & value)
00858 {
00859 put(multi.pmap, key, value);
00860 }
00861
00862
00863
00864 template<>
00865 struct property_map<vtkGraph*, vertex_index_t>
00866 {
00867 typedef vtkGraphIndexMap type;
00868 typedef vtkGraphIndexMap const_type;
00869 };
00870
00871 template<>
00872 struct property_map<vtkDirectedGraph*, vertex_index_t>
00873 : property_map<vtkGraph*, vertex_index_t> { };
00874
00875 template<>
00876 struct property_map<vtkUndirectedGraph*, vertex_index_t>
00877 : property_map<vtkGraph*, vertex_index_t> { };
00878
00879 inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*) { return vtkGraphIndexMap(); }
00880
00881 template<>
00882 struct property_map<vtkGraph*, edge_index_t>
00883 {
00884 typedef vtkGraphIndexMap type;
00885 typedef vtkGraphIndexMap const_type;
00886 };
00887
00888 template<>
00889 struct property_map<vtkDirectedGraph*, edge_index_t>
00890 : property_map<vtkGraph*, edge_index_t> { };
00891
00892 template<>
00893 struct property_map<vtkUndirectedGraph*, edge_index_t>
00894 : property_map<vtkGraph*, edge_index_t> { };
00895
00896 inline vtkGraphIndexMap get(edge_index_t, vtkGraph*) { return vtkGraphIndexMap(); }
00897
00898
00899 template<>
00900 struct property_map<vtkDirectedGraph* const, vertex_index_t>
00901 : property_map<vtkDirectedGraph*, vertex_index_t> { };
00902
00903 template<>
00904 struct property_map<vtkUndirectedGraph* const, vertex_index_t>
00905 : property_map<vtkUndirectedGraph*, vertex_index_t> { };
00906
00907 template<>
00908 struct property_map<vtkDirectedGraph* const, edge_index_t>
00909 : property_map<vtkDirectedGraph*, edge_index_t> { };
00910
00911 template<>
00912 struct property_map<vtkUndirectedGraph* const, edge_index_t>
00913 : property_map<vtkUndirectedGraph*, edge_index_t> { };
00914
00915 }
00916
00917
00918 #endif // __vtkBoostGraphAdapter_h