VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkBoostGraphAdapter.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 /*------------------------------------------------------------------------- 00016 Copyright 2008 Sandia Corporation. 00017 Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00018 the U.S. Government retains certain rights in this software. 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 00048 #include <boost/version.hpp> 00049 00050 namespace boost { 00051 //=========================================================================== 00052 // VTK arrays as property maps 00053 // These need to be defined before including other boost stuff 00054 00055 // Forward declarations are required here, so that we aren't forced 00056 // to include boost/property_map.hpp. 00057 template<typename> struct property_traits; 00058 struct read_write_property_map_tag; 00059 00060 #define vtkPropertyMapMacro(T, V) \ 00061 template <> \ 00062 struct property_traits<T*> \ 00063 { \ 00064 typedef V value_type; \ 00065 typedef V reference; \ 00066 typedef vtkIdType key_type; \ 00067 typedef read_write_property_map_tag category; \ 00068 }; \ 00069 \ 00070 inline property_traits<T*>::reference \ 00071 get( \ 00072 T* const & arr, \ 00073 property_traits<T*>::key_type key) \ 00074 { \ 00075 return arr->GetValue(key); \ 00076 } \ 00077 \ 00078 inline void \ 00079 put( \ 00080 T* arr, \ 00081 property_traits<T*>::key_type key, \ 00082 const property_traits<T*>::value_type & value) \ 00083 { \ 00084 arr->InsertValue(key, value); \ 00085 } 00086 00087 vtkPropertyMapMacro(vtkIntArray, int) 00088 vtkPropertyMapMacro(vtkIdTypeArray, vtkIdType) 00089 vtkPropertyMapMacro(vtkDoubleArray, double) 00090 vtkPropertyMapMacro(vtkFloatArray, float) 00091 00092 // vtkDataArray 00093 template<> 00094 struct property_traits<vtkDataArray*> 00095 { 00096 typedef double value_type; 00097 typedef double reference; 00098 typedef vtkIdType key_type; 00099 typedef read_write_property_map_tag category; 00100 }; 00101 00102 inline double 00103 get(vtkDataArray * const& arr, vtkIdType key) 00104 { 00105 return arr->GetTuple1(key); 00106 } 00107 00108 inline void 00109 put(vtkDataArray *arr, vtkIdType key, const double& value) 00110 { 00111 arr->SetTuple1(key, value); 00112 } 00113 00114 // vtkAbstractArray as a property map of vtkVariants 00115 template<> 00116 struct property_traits<vtkAbstractArray*> 00117 { 00118 typedef vtkVariant value_type; 00119 typedef vtkVariant reference; 00120 typedef vtkIdType key_type; 00121 typedef read_write_property_map_tag category; 00122 }; 00123 00124 inline vtkVariant 00125 get(vtkAbstractArray * const& arr, vtkIdType key) 00126 { 00127 return arr->GetVariantValue(key); 00128 } 00129 00130 inline void 00131 put(vtkAbstractArray *arr, vtkIdType key, const vtkVariant& value) 00132 { 00133 arr->InsertVariantValue(key, value); 00134 } 00135 #if defined(_MSC_VER) 00136 namespace detail { 00137 using ::boost::get; 00138 using ::boost::put; 00139 } 00140 #endif 00141 } 00142 00143 #include <vtksys/stl/utility> // STL Header 00144 00145 #include <boost/config.hpp> 00146 #include <boost/iterator/iterator_facade.hpp> 00147 #include <boost/graph/graph_traits.hpp> 00148 #include <boost/graph/properties.hpp> 00149 #include <boost/graph/adjacency_iterator.hpp> 00150 00151 // The functions and classes in this file allows the user to 00152 // treat a vtkDirectedGraph or vtkUndirectedGraph object 00153 // as a boost graph "as is". 00154 00155 namespace boost { 00156 00157 class vtk_vertex_iterator : 00158 public iterator_facade<vtk_vertex_iterator, 00159 vtkIdType, 00160 bidirectional_traversal_tag, 00161 vtkIdType, 00162 vtkIdType> 00163 { 00164 public: 00165 explicit vtk_vertex_iterator(vtkIdType i = 0) : index(i) {} 00166 00167 private: 00168 vtkIdType dereference() const { return index; } 00169 00170 bool equal(const vtk_vertex_iterator& other) const 00171 { return index == other.index; } 00172 00173 void increment() { index++; } 00174 void decrement() { index--; } 00175 00176 vtkIdType index; 00177 00178 friend class iterator_core_access; 00179 }; 00180 00181 class vtk_edge_iterator : 00182 public iterator_facade<vtk_edge_iterator, 00183 vtkEdgeType, 00184 forward_traversal_tag, 00185 vtkEdgeType, 00186 vtkIdType> 00187 { 00188 public: 00189 explicit vtk_edge_iterator(vtkGraph *g = 0, vtkIdType v = 0) : 00190 directed(false), vertex(v), lastVertex(v), iter(0), end(0), graph(g) 00191 { 00192 if (graph) 00193 { 00194 lastVertex = graph->GetNumberOfVertices(); 00195 } 00196 00197 vtkIdType myRank = -1; 00198 vtkDistributedGraphHelper *helper 00199 = this->graph? this->graph->GetDistributedGraphHelper() : 0; 00200 if (helper) 00201 { 00202 myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER()); 00203 vertex = helper->MakeDistributedId(myRank, vertex); 00204 lastVertex = helper->MakeDistributedId(myRank, lastVertex); 00205 } 00206 00207 if (graph != 0) 00208 { 00209 directed = (vtkDirectedGraph::SafeDownCast(graph) != 0); 00210 while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0) 00211 { 00212 ++vertex; 00213 } 00214 00215 if (vertex < lastVertex) 00216 { 00217 // Get the outgoing edges of the first vertex that has outgoing 00218 // edges 00219 vtkIdType nedges; 00220 graph->GetOutEdges(vertex, iter, nedges); 00221 end = iter + nedges; 00222 00223 if (!directed) 00224 { 00225 while(iter != 0 00226 && (// Skip non-local edges 00227 (helper && helper->GetEdgeOwner(iter->Id) != myRank) 00228 // Skip entirely-local edges where Source > Target 00229 || (((helper 00230 && myRank == helper->GetVertexOwner(iter->Target)) 00231 || !helper) 00232 && vertex > iter->Target))) 00233 { 00234 this->inc(); 00235 } 00236 } 00237 } 00238 else 00239 { 00240 iter = 0; 00241 } 00242 } 00243 } 00244 00245 private: 00246 vtkEdgeType dereference() const 00247 { return vtkEdgeType(vertex, iter->Target, iter->Id); } 00248 00249 bool equal(const vtk_edge_iterator& other) const 00250 { return vertex == other.vertex && iter == other.iter; } 00251 00252 void increment() 00253 { 00254 inc(); 00255 if (!directed) 00256 { 00257 vtkIdType myRank = -1; 00258 vtkDistributedGraphHelper *helper 00259 = this->graph? this->graph->GetDistributedGraphHelper() : 0; 00260 if (helper) 00261 { 00262 myRank = this->graph->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER()); 00263 } 00264 00265 while (iter != 0 00266 && (// Skip non-local edges 00267 (helper && helper->GetEdgeOwner(iter->Id) != myRank) 00268 // Skip entirely-local edges where Source > Target 00269 || (((helper 00270 && myRank == helper->GetVertexOwner(iter->Target)) 00271 || !helper) 00272 && vertex > iter->Target))) 00273 { 00274 inc(); 00275 } 00276 } 00277 } 00278 00279 void inc() 00280 { 00281 ++iter; 00282 if (iter == end) 00283 { 00284 // Find a vertex with nonzero out degree. 00285 ++vertex; 00286 while (vertex < lastVertex && this->graph->GetOutDegree(vertex) == 0) 00287 { 00288 ++vertex; 00289 } 00290 00291 if (vertex < lastVertex) 00292 { 00293 vtkIdType nedges; 00294 graph->GetOutEdges(vertex, iter, nedges); 00295 end = iter + nedges; 00296 } 00297 else 00298 { 00299 iter = 0; 00300 } 00301 } 00302 } 00303 00304 bool directed; 00305 vtkIdType vertex; 00306 vtkIdType lastVertex; 00307 const vtkOutEdgeType * iter; 00308 const vtkOutEdgeType * end; 00309 vtkGraph *graph; 00310 00311 friend class iterator_core_access; 00312 }; 00313 00314 class vtk_out_edge_pointer_iterator : 00315 public iterator_facade<vtk_out_edge_pointer_iterator, 00316 vtkEdgeType, 00317 bidirectional_traversal_tag, 00318 vtkEdgeType, 00319 ptrdiff_t> 00320 { 00321 public: 00322 explicit vtk_out_edge_pointer_iterator(vtkGraph *g = 0, vtkIdType v = 0, bool end = false) : 00323 vertex(v) 00324 { 00325 if (g) 00326 { 00327 vtkIdType nedges; 00328 g->GetOutEdges(vertex, iter, nedges); 00329 if (end) 00330 { 00331 iter += nedges; 00332 } 00333 } 00334 } 00335 00336 private: 00337 vtkEdgeType dereference() const { return vtkEdgeType(vertex, iter->Target, iter->Id); } 00338 00339 bool equal(const vtk_out_edge_pointer_iterator& other) const 00340 { return iter == other.iter; } 00341 00342 void increment() { iter++; } 00343 void decrement() { iter--; } 00344 00345 vtkIdType vertex; 00346 const vtkOutEdgeType *iter; 00347 00348 friend class iterator_core_access; 00349 }; 00350 00351 class vtk_in_edge_pointer_iterator : 00352 public iterator_facade<vtk_in_edge_pointer_iterator, 00353 vtkEdgeType, 00354 bidirectional_traversal_tag, 00355 vtkEdgeType, 00356 ptrdiff_t> 00357 { 00358 public: 00359 explicit vtk_in_edge_pointer_iterator(vtkGraph *g = 0, vtkIdType v = 0, bool end = false) : 00360 vertex(v) 00361 { 00362 if (g) 00363 { 00364 vtkIdType nedges; 00365 g->GetInEdges(vertex, iter, nedges); 00366 if (end) 00367 { 00368 iter += nedges; 00369 } 00370 } 00371 } 00372 00373 private: 00374 vtkEdgeType dereference() const { return vtkEdgeType(iter->Source, vertex, iter->Id); } 00375 00376 bool equal(const vtk_in_edge_pointer_iterator& other) const 00377 { return iter == other.iter; } 00378 00379 void increment() { iter++; } 00380 void decrement() { iter--; } 00381 00382 vtkIdType vertex; 00383 const vtkInEdgeType *iter; 00384 00385 friend class iterator_core_access; 00386 }; 00387 00388 //=========================================================================== 00389 // vtkGraph 00390 // VertexAndEdgeListGraphConcept 00391 // BidirectionalGraphConcept 00392 // AdjacencyGraphConcept 00393 00394 struct vtkGraph_traversal_category : 00395 public virtual bidirectional_graph_tag, 00396 public virtual edge_list_graph_tag, 00397 public virtual vertex_list_graph_tag, 00398 public virtual adjacency_graph_tag { }; 00399 00400 template <> 00401 struct graph_traits<vtkGraph*> { 00402 typedef vtkIdType vertex_descriptor; 00403 static vertex_descriptor null_vertex() { return -1; } 00404 typedef vtkEdgeType edge_descriptor; 00405 static edge_descriptor null_edge() { return vtkEdgeType(-1, -1, -1); } 00406 typedef vtk_out_edge_pointer_iterator out_edge_iterator; 00407 typedef vtk_in_edge_pointer_iterator in_edge_iterator; 00408 00409 typedef vtk_vertex_iterator vertex_iterator; 00410 typedef vtk_edge_iterator edge_iterator; 00411 00412 typedef allow_parallel_edge_tag edge_parallel_category; 00413 typedef vtkGraph_traversal_category traversal_category; 00414 typedef vtkIdType vertices_size_type; 00415 typedef vtkIdType edges_size_type; 00416 typedef vtkIdType degree_size_type; 00417 00418 typedef adjacency_iterator_generator<vtkGraph*, 00419 vertex_descriptor, out_edge_iterator>::type adjacency_iterator; 00420 }; 00421 00422 #if BOOST_VERSION >= 104500 00423 template<> 00424 struct graph_property_type< vtkGraph* > { 00425 typedef no_property type; 00426 }; 00427 #endif 00428 00429 template<> 00430 struct vertex_property_type< vtkGraph* > { 00431 typedef no_property type; 00432 }; 00433 00434 template<> 00435 struct edge_property_type< vtkGraph* > { 00436 typedef no_property type; 00437 }; 00438 00439 #if BOOST_VERSION >= 104500 00440 template<> 00441 struct graph_bundle_type< vtkGraph* > { 00442 typedef no_property type; 00443 }; 00444 #endif 00445 00446 template<> 00447 struct vertex_bundle_type< vtkGraph* > { 00448 typedef no_property type; 00449 }; 00450 00451 template<> 00452 struct edge_bundle_type< vtkGraph* > { 00453 typedef no_property type; 00454 }; 00455 00456 inline bool has_no_edges(vtkGraph* g) 00457 { 00458 return ((g->GetNumberOfEdges() > 0) ? false : true); 00459 } 00460 00461 inline void remove_edge(graph_traits<vtkGraph*>::edge_descriptor e, 00462 vtkGraph* g) 00463 { 00464 if(vtkMutableDirectedGraph::SafeDownCast(g)) 00465 { 00466 vtkMutableDirectedGraph::SafeDownCast(g)->RemoveEdge(e.Id); 00467 } 00468 else if(vtkMutableUndirectedGraph::SafeDownCast(g)) 00469 { 00470 vtkMutableUndirectedGraph::SafeDownCast(g)->RemoveEdge(e.Id); 00471 } 00472 } 00473 00474 //=========================================================================== 00475 // vtkDirectedGraph 00476 00477 template <> 00478 struct graph_traits<vtkDirectedGraph*> : graph_traits<vtkGraph*> 00479 { 00480 typedef directed_tag directed_category; 00481 }; 00482 00483 // The graph_traits for a const graph are the same as a non-const graph. 00484 template <> 00485 struct graph_traits<const vtkDirectedGraph*> : graph_traits<vtkDirectedGraph*> { }; 00486 00487 // The graph_traits for a const graph are the same as a non-const graph. 00488 template <> 00489 struct graph_traits<vtkDirectedGraph* const> : graph_traits<vtkDirectedGraph*> { }; 00490 00491 #if BOOST_VERSION >= 104500 00492 // Internal graph properties 00493 template<> 00494 struct graph_property_type< vtkDirectedGraph* > 00495 : graph_property_type< vtkGraph* > { }; 00496 00497 // Internal graph properties 00498 template<> 00499 struct graph_property_type< vtkDirectedGraph* const > 00500 : graph_property_type< vtkGraph* > { }; 00501 #endif 00502 00503 // Internal vertex properties 00504 template<> 00505 struct vertex_property_type< vtkDirectedGraph* > 00506 : vertex_property_type< vtkGraph* > { }; 00507 00508 // Internal vertex properties 00509 template<> 00510 struct vertex_property_type< vtkDirectedGraph* const > 00511 : vertex_property_type< vtkGraph* > { }; 00512 00513 // Internal edge properties 00514 template<> 00515 struct edge_property_type< vtkDirectedGraph* > 00516 : edge_property_type< vtkGraph* > { }; 00517 00518 // Internal edge properties 00519 template<> 00520 struct edge_property_type< vtkDirectedGraph* const > 00521 : edge_property_type< vtkGraph* > { }; 00522 00523 #if BOOST_VERSION >= 104500 00524 // Internal graph properties 00525 template<> 00526 struct graph_bundle_type< vtkDirectedGraph* > 00527 : graph_bundle_type< vtkGraph* > { }; 00528 00529 // Internal graph properties 00530 template<> 00531 struct graph_bundle_type< vtkDirectedGraph* const > 00532 : graph_bundle_type< vtkGraph* > { }; 00533 #endif 00534 00535 // Internal vertex properties 00536 template<> 00537 struct vertex_bundle_type< vtkDirectedGraph* > 00538 : vertex_bundle_type< vtkGraph* > { }; 00539 00540 // Internal vertex properties 00541 template<> 00542 struct vertex_bundle_type< vtkDirectedGraph* const > 00543 : vertex_bundle_type< vtkGraph* > { }; 00544 00545 // Internal edge properties 00546 template<> 00547 struct edge_bundle_type< vtkDirectedGraph* > 00548 : edge_bundle_type< vtkGraph* > { }; 00549 00550 // Internal edge properties 00551 template<> 00552 struct edge_bundle_type< vtkDirectedGraph* const > 00553 : edge_bundle_type< vtkGraph* > { }; 00554 00555 //=========================================================================== 00556 // vtkTree 00557 00558 template <> 00559 struct graph_traits<vtkTree*> : graph_traits<vtkDirectedGraph*> { }; 00560 00561 // The graph_traits for a const graph are the same as a non-const graph. 00562 template <> 00563 struct graph_traits<const vtkTree*> : graph_traits<vtkTree*> { }; 00564 00565 // The graph_traits for a const graph are the same as a non-const graph. 00566 template <> 00567 struct graph_traits<vtkTree* const> : graph_traits<vtkTree*> { }; 00568 00569 //=========================================================================== 00570 // vtkUndirectedGraph 00571 template <> 00572 struct graph_traits<vtkUndirectedGraph*> : graph_traits<vtkGraph*> 00573 { 00574 typedef undirected_tag directed_category; 00575 }; 00576 00577 // The graph_traits for a const graph are the same as a non-const graph. 00578 template <> 00579 struct graph_traits<const vtkUndirectedGraph*> : graph_traits<vtkUndirectedGraph*> { }; 00580 00581 // The graph_traits for a const graph are the same as a non-const graph. 00582 template <> 00583 struct graph_traits<vtkUndirectedGraph* const> : graph_traits<vtkUndirectedGraph*> { }; 00584 00585 #if BOOST_VERSION >= 104500 00586 // Internal graph properties 00587 template<> 00588 struct graph_property_type< vtkUndirectedGraph* > 00589 : graph_property_type< vtkGraph* > { }; 00590 00591 // Internal graph properties 00592 template<> 00593 struct graph_property_type< vtkUndirectedGraph* const > 00594 : graph_property_type< vtkGraph* > { }; 00595 #endif 00596 00597 // Internal vertex properties 00598 template<> 00599 struct vertex_property_type< vtkUndirectedGraph* > 00600 : vertex_property_type< vtkGraph* > { }; 00601 00602 // Internal vertex properties 00603 template<> 00604 struct vertex_property_type< vtkUndirectedGraph* const > 00605 : vertex_property_type< vtkGraph* > { }; 00606 00607 // Internal edge properties 00608 template<> 00609 struct edge_property_type< vtkUndirectedGraph* > 00610 : edge_property_type< vtkGraph* > { }; 00611 00612 // Internal edge properties 00613 template<> 00614 struct edge_property_type< vtkUndirectedGraph* const > 00615 : edge_property_type< vtkGraph* > { }; 00616 00617 #if BOOST_VERSION >= 104500 00618 // Internal graph properties 00619 template<> 00620 struct graph_bundle_type< vtkUndirectedGraph* > 00621 : graph_bundle_type< vtkGraph* > { }; 00622 00623 // Internal graph properties 00624 template<> 00625 struct graph_bundle_type< vtkUndirectedGraph* const > 00626 : graph_bundle_type< vtkGraph* > { }; 00627 #endif 00628 00629 // Internal vertex properties 00630 template<> 00631 struct vertex_bundle_type< vtkUndirectedGraph* > 00632 : vertex_bundle_type< vtkGraph* > { }; 00633 00634 // Internal vertex properties 00635 template<> 00636 struct vertex_bundle_type< vtkUndirectedGraph* const > 00637 : vertex_bundle_type< vtkGraph* > { }; 00638 00639 // Internal edge properties 00640 template<> 00641 struct edge_bundle_type< vtkUndirectedGraph* > 00642 : edge_bundle_type< vtkGraph* > { }; 00643 00644 // Internal edge properties 00645 template<> 00646 struct edge_bundle_type< vtkUndirectedGraph* const > 00647 : edge_bundle_type< vtkGraph* > { }; 00648 00649 //=========================================================================== 00650 // vtkMutableDirectedGraph 00651 00652 template <> 00653 struct graph_traits<vtkMutableDirectedGraph*> : graph_traits<vtkDirectedGraph*> { }; 00654 00655 // The graph_traits for a const graph are the same as a non-const graph. 00656 template <> 00657 struct graph_traits<const vtkMutableDirectedGraph*> : graph_traits<vtkMutableDirectedGraph*> { }; 00658 00659 // The graph_traits for a const graph are the same as a non-const graph. 00660 template <> 00661 struct graph_traits<vtkMutableDirectedGraph* const> : graph_traits<vtkMutableDirectedGraph*> { }; 00662 00663 #if BOOST_VERSION >= 104500 00664 // Internal graph properties 00665 template<> 00666 struct graph_property_type< vtkMutableDirectedGraph* > 00667 : graph_property_type< vtkDirectedGraph* > { }; 00668 00669 // Internal graph properties 00670 template<> 00671 struct graph_property_type< vtkMutableDirectedGraph* const > 00672 : graph_property_type< vtkDirectedGraph* > { }; 00673 #endif 00674 00675 // Internal vertex properties 00676 template<> 00677 struct vertex_property_type< vtkMutableDirectedGraph* > 00678 : vertex_property_type< vtkDirectedGraph* > { }; 00679 00680 // Internal vertex properties 00681 template<> 00682 struct vertex_property_type< vtkMutableDirectedGraph* const > 00683 : vertex_property_type< vtkDirectedGraph* > { }; 00684 00685 // Internal edge properties 00686 template<> 00687 struct edge_property_type< vtkMutableDirectedGraph* > 00688 : edge_property_type< vtkDirectedGraph* > { }; 00689 00690 // Internal edge properties 00691 template<> 00692 struct edge_property_type< vtkMutableDirectedGraph* const > 00693 : edge_property_type< vtkDirectedGraph* > { }; 00694 00695 #if BOOST_VERSION >= 104500 00696 // Internal graph properties 00697 template<> 00698 struct graph_bundle_type< vtkMutableDirectedGraph* > 00699 : graph_bundle_type< vtkDirectedGraph* > { }; 00700 00701 // Internal graph properties 00702 template<> 00703 struct graph_bundle_type< vtkMutableDirectedGraph* const > 00704 : graph_bundle_type< vtkDirectedGraph* > { }; 00705 #endif 00706 00707 // Internal vertex properties 00708 template<> 00709 struct vertex_bundle_type< vtkMutableDirectedGraph* > 00710 : vertex_bundle_type< vtkDirectedGraph* > { }; 00711 00712 // Internal vertex properties 00713 template<> 00714 struct vertex_bundle_type< vtkMutableDirectedGraph* const > 00715 : vertex_bundle_type< vtkDirectedGraph* > { }; 00716 00717 // Internal edge properties 00718 template<> 00719 struct edge_bundle_type< vtkMutableDirectedGraph* > 00720 : edge_bundle_type< vtkDirectedGraph* > { }; 00721 00722 // Internal edge properties 00723 template<> 00724 struct edge_bundle_type< vtkMutableDirectedGraph* const > 00725 : edge_bundle_type< vtkDirectedGraph* > { }; 00726 00727 //=========================================================================== 00728 // vtkMutableUndirectedGraph 00729 00730 template <> 00731 struct graph_traits<vtkMutableUndirectedGraph*> : graph_traits<vtkUndirectedGraph*> { }; 00732 00733 // The graph_traits for a const graph are the same as a non-const graph. 00734 template <> 00735 struct graph_traits<const vtkMutableUndirectedGraph*> : graph_traits<vtkMutableUndirectedGraph*> { }; 00736 00737 // The graph_traits for a const graph are the same as a non-const graph. 00738 template <> 00739 struct graph_traits<vtkMutableUndirectedGraph* const> : graph_traits<vtkMutableUndirectedGraph*> { }; 00740 00741 #if BOOST_VERSION >= 104500 00742 // Internal graph properties 00743 template<> 00744 struct graph_property_type< vtkMutableUndirectedGraph* > 00745 : graph_property_type< vtkUndirectedGraph* > { }; 00746 00747 // Internal graph properties 00748 template<> 00749 struct graph_property_type< vtkMutableUndirectedGraph* const > 00750 : graph_property_type< vtkUndirectedGraph* > { }; 00751 #endif 00752 00753 // Internal vertex properties 00754 template<> 00755 struct vertex_property_type< vtkMutableUndirectedGraph* > 00756 : vertex_property_type< vtkUndirectedGraph* > { }; 00757 00758 // Internal vertex properties 00759 template<> 00760 struct vertex_property_type< vtkMutableUndirectedGraph* const > 00761 : vertex_property_type< vtkUndirectedGraph* > { }; 00762 00763 // Internal edge properties 00764 template<> 00765 struct edge_property_type< vtkMutableUndirectedGraph* > 00766 : edge_property_type< vtkUndirectedGraph* > { }; 00767 00768 // Internal edge properties 00769 template<> 00770 struct edge_property_type< vtkMutableUndirectedGraph* const > 00771 : edge_property_type< vtkUndirectedGraph* > { }; 00772 00773 #if BOOST_VERSION >= 104500 00774 // Internal graph properties 00775 template<> 00776 struct graph_bundle_type< vtkMutableUndirectedGraph* > 00777 : graph_bundle_type< vtkUndirectedGraph* > { }; 00778 00779 // Internal graph properties 00780 template<> 00781 struct graph_bundle_type< vtkMutableUndirectedGraph* const > 00782 : graph_bundle_type< vtkUndirectedGraph* > { }; 00783 #endif 00784 00785 // Internal vertex properties 00786 template<> 00787 struct vertex_bundle_type< vtkMutableUndirectedGraph* > 00788 : vertex_bundle_type< vtkUndirectedGraph* > { }; 00789 00790 // Internal vertex properties 00791 template<> 00792 struct vertex_bundle_type< vtkMutableUndirectedGraph* const > 00793 : vertex_bundle_type< vtkUndirectedGraph* > { }; 00794 00795 // Internal edge properties 00796 template<> 00797 struct edge_bundle_type< vtkMutableUndirectedGraph* > 00798 : edge_bundle_type< vtkUndirectedGraph* > { }; 00799 00800 // Internal edge properties 00801 template<> 00802 struct edge_bundle_type< vtkMutableUndirectedGraph* const > 00803 : edge_bundle_type< vtkUndirectedGraph* > { }; 00804 00805 //=========================================================================== 00806 // API implementation 00807 template <> 00808 class vertex_property< vtkGraph* > { 00809 public: 00810 typedef vtkIdType type; 00811 }; 00812 00813 template <> 00814 class edge_property< vtkGraph* > { 00815 public: 00816 typedef vtkIdType type; 00817 }; 00818 } // end namespace boost 00819 00820 inline boost::graph_traits< vtkGraph* >::vertex_descriptor 00821 source(boost::graph_traits< vtkGraph* >::edge_descriptor e, 00822 vtkGraph *) 00823 { 00824 return e.Source; 00825 } 00826 00827 inline boost::graph_traits< vtkGraph* >::vertex_descriptor 00828 target(boost::graph_traits< vtkGraph* >::edge_descriptor e, 00829 vtkGraph *) 00830 { 00831 return e.Target; 00832 } 00833 00834 inline vtksys_stl::pair< 00835 boost::graph_traits< vtkGraph* >::vertex_iterator, 00836 boost::graph_traits< vtkGraph* >::vertex_iterator > 00837 vertices(vtkGraph *g) 00838 { 00839 typedef boost::graph_traits< vtkGraph* >::vertex_iterator Iter; 00840 vtkIdType start = 0; 00841 if (vtkDistributedGraphHelper *helper = g->GetDistributedGraphHelper()) 00842 { 00843 int rank = 00844 g->GetInformation()->Get(vtkDataObject::DATA_PIECE_NUMBER()); 00845 start = helper->MakeDistributedId(rank, start); 00846 } 00847 00848 return vtksys_stl::make_pair( Iter(start), 00849 Iter(start + g->GetNumberOfVertices()) ); 00850 } 00851 00852 inline vtksys_stl::pair< 00853 boost::graph_traits< vtkGraph* >::edge_iterator, 00854 boost::graph_traits< vtkGraph* >::edge_iterator > 00855 edges(vtkGraph *g) 00856 { 00857 typedef boost::graph_traits< vtkGraph* >::edge_iterator Iter; 00858 return vtksys_stl::make_pair( Iter(g), Iter(g, g->GetNumberOfVertices()) ); 00859 } 00860 00861 inline vtksys_stl::pair< 00862 boost::graph_traits< vtkGraph* >::out_edge_iterator, 00863 boost::graph_traits< vtkGraph* >::out_edge_iterator > 00864 out_edges( 00865 boost::graph_traits< vtkGraph* >::vertex_descriptor u, 00866 vtkGraph *g) 00867 { 00868 typedef boost::graph_traits< vtkGraph* >::out_edge_iterator Iter; 00869 vtksys_stl::pair<Iter, Iter> p = vtksys_stl::make_pair( Iter(g, u), Iter(g, u, true) ); 00870 return p; 00871 } 00872 00873 inline vtksys_stl::pair< 00874 boost::graph_traits< vtkGraph* >::in_edge_iterator, 00875 boost::graph_traits< vtkGraph* >::in_edge_iterator > 00876 in_edges( 00877 boost::graph_traits< vtkGraph* >::vertex_descriptor u, 00878 vtkGraph *g) 00879 { 00880 typedef boost::graph_traits< vtkGraph* >::in_edge_iterator Iter; 00881 vtksys_stl::pair<Iter, Iter> p = vtksys_stl::make_pair( Iter(g, u), Iter(g, u, true) ); 00882 return p; 00883 } 00884 00885 inline vtksys_stl::pair< 00886 boost::graph_traits< vtkGraph* >::adjacency_iterator, 00887 boost::graph_traits< vtkGraph* >::adjacency_iterator > 00888 adjacent_vertices( 00889 boost::graph_traits< vtkGraph* >::vertex_descriptor u, 00890 vtkGraph *g) 00891 { 00892 typedef boost::graph_traits< vtkGraph* >::adjacency_iterator Iter; 00893 typedef boost::graph_traits< vtkGraph* >::out_edge_iterator OutEdgeIter; 00894 vtksys_stl::pair<OutEdgeIter, OutEdgeIter> out = out_edges(u, g); 00895 return vtksys_stl::make_pair( Iter(out.first, &g), Iter(out.second, &g) ); 00896 } 00897 00898 inline boost::graph_traits< vtkGraph* >::vertices_size_type 00899 num_vertices(vtkGraph *g) 00900 { 00901 return g->GetNumberOfVertices(); 00902 } 00903 00904 inline boost::graph_traits< vtkGraph* >::edges_size_type 00905 num_edges(vtkGraph *g) 00906 { 00907 return g->GetNumberOfEdges(); 00908 } 00909 00910 inline boost::graph_traits< vtkGraph* >::degree_size_type 00911 out_degree( 00912 boost::graph_traits< vtkGraph* >::vertex_descriptor u, 00913 vtkGraph *g) 00914 { 00915 return g->GetOutDegree(u); 00916 } 00917 00918 inline boost::graph_traits< vtkDirectedGraph* >::degree_size_type 00919 in_degree( 00920 boost::graph_traits< vtkDirectedGraph* >::vertex_descriptor u, 00921 vtkDirectedGraph *g) 00922 { 00923 return g->GetInDegree(u); 00924 } 00925 00926 inline boost::graph_traits< vtkGraph* >::degree_size_type 00927 degree( 00928 boost::graph_traits< vtkGraph* >::vertex_descriptor u, 00929 vtkGraph *g) 00930 { 00931 return g->GetDegree(u); 00932 } 00933 00934 inline boost::graph_traits< vtkMutableDirectedGraph* >::vertex_descriptor 00935 add_vertex(vtkMutableDirectedGraph *g) 00936 { 00937 return g->AddVertex(); 00938 } 00939 00940 inline vtksys_stl::pair< 00941 boost::graph_traits< vtkMutableDirectedGraph* >::edge_descriptor, 00942 bool> 00943 add_edge( 00944 boost::graph_traits< vtkMutableDirectedGraph* >::vertex_descriptor u, 00945 boost::graph_traits< vtkMutableDirectedGraph* >::vertex_descriptor v, 00946 vtkMutableDirectedGraph *g) 00947 { 00948 boost::graph_traits< vtkMutableDirectedGraph* >::edge_descriptor e = g->AddEdge(u, v); 00949 return vtksys_stl::make_pair(e, true); 00950 } 00951 00952 inline boost::graph_traits< vtkMutableUndirectedGraph* >::vertex_descriptor 00953 add_vertex(vtkMutableUndirectedGraph *g) 00954 { 00955 return g->AddVertex(); 00956 } 00957 00958 inline vtksys_stl::pair< 00959 boost::graph_traits< vtkMutableUndirectedGraph* >::edge_descriptor, 00960 bool> 00961 add_edge( 00962 boost::graph_traits< vtkMutableUndirectedGraph* >::vertex_descriptor u, 00963 boost::graph_traits< vtkMutableUndirectedGraph* >::vertex_descriptor v, 00964 vtkMutableUndirectedGraph *g) 00965 { 00966 boost::graph_traits< vtkMutableUndirectedGraph* >::edge_descriptor e = g->AddEdge(u, v); 00967 return vtksys_stl::make_pair(e, true); 00968 } 00969 00970 namespace boost { 00971 //=========================================================================== 00972 // An edge map for vtkGraph. 00973 // This is a common input needed for algorithms. 00974 00975 struct vtkGraphEdgeMap { }; 00976 00977 template <> 00978 struct property_traits<vtkGraphEdgeMap> 00979 { 00980 typedef vtkIdType value_type; 00981 typedef vtkIdType reference; 00982 typedef vtkEdgeType key_type; 00983 typedef readable_property_map_tag category; 00984 }; 00985 00986 inline property_traits<vtkGraphEdgeMap>::reference 00987 get( 00988 vtkGraphEdgeMap vtkNotUsed(arr), 00989 property_traits<vtkGraphEdgeMap>::key_type key) 00990 { 00991 return key.Id; 00992 } 00993 00994 //=========================================================================== 00995 // Helper for vtkGraph edge property maps 00996 // Automatically converts boost edge ids to vtkGraph edge ids. 00997 00998 template<typename PMap> 00999 class vtkGraphEdgePropertyMapHelper 01000 { 01001 public: 01002 vtkGraphEdgePropertyMapHelper(PMap m) : pmap(m) { } 01003 PMap pmap; 01004 typedef typename property_traits<PMap>::value_type value_type; 01005 typedef typename property_traits<PMap>::reference reference; 01006 typedef vtkEdgeType key_type; 01007 typedef typename property_traits<PMap>::category category; 01008 }; 01009 01010 template<typename PMap> 01011 inline typename property_traits<PMap>::reference 01012 get( 01013 vtkGraphEdgePropertyMapHelper<PMap> helper, 01014 vtkEdgeType key) 01015 { 01016 return get(helper.pmap, key.Id); 01017 } 01018 01019 template<typename PMap> 01020 inline void 01021 put( 01022 vtkGraphEdgePropertyMapHelper<PMap> helper, 01023 vtkEdgeType key, 01024 const typename property_traits<PMap>::value_type & value) 01025 { 01026 put(helper.pmap, key.Id, value); 01027 } 01028 01029 //=========================================================================== 01030 // An index map for vtkGraph 01031 // This is a common input needed for algorithms 01032 01033 struct vtkGraphIndexMap { }; 01034 01035 template <> 01036 struct property_traits<vtkGraphIndexMap> 01037 { 01038 typedef vtkIdType value_type; 01039 typedef vtkIdType reference; 01040 typedef vtkIdType key_type; 01041 typedef readable_property_map_tag category; 01042 }; 01043 01044 inline property_traits<vtkGraphIndexMap>::reference 01045 get( 01046 vtkGraphIndexMap vtkNotUsed(arr), 01047 property_traits<vtkGraphIndexMap>::key_type key) 01048 { 01049 return key; 01050 } 01051 01052 //=========================================================================== 01053 // Helper for vtkGraph property maps 01054 // Automatically multiplies the property value by some value (default 1) 01055 template<typename PMap> 01056 class vtkGraphPropertyMapMultiplier 01057 { 01058 public: 01059 vtkGraphPropertyMapMultiplier(PMap m, float multi=1) : pmap(m),multiplier(multi){} 01060 PMap pmap; 01061 float multiplier; 01062 typedef typename property_traits<PMap>::value_type value_type; 01063 typedef typename property_traits<PMap>::reference reference; 01064 typedef typename property_traits<PMap>::key_type key_type; 01065 typedef typename property_traits<PMap>::category category; 01066 }; 01067 01068 template<typename PMap> 01069 inline typename property_traits<PMap>::reference 01070 get( 01071 vtkGraphPropertyMapMultiplier<PMap> multi, 01072 const typename property_traits<PMap>::key_type key) 01073 { 01074 return multi.multiplier * get(multi.pmap, key); 01075 } 01076 01077 template<typename PMap> 01078 inline void 01079 put( 01080 vtkGraphPropertyMapMultiplier<PMap> multi, 01081 const typename property_traits<PMap>::key_type key, 01082 const typename property_traits<PMap>::value_type & value) 01083 { 01084 put(multi.pmap, key, value); 01085 } 01086 01087 // Allow algorithms to automatically extract vtkGraphIndexMap from a 01088 // VTK graph 01089 template<> 01090 struct property_map<vtkGraph*, vertex_index_t> 01091 { 01092 typedef vtkGraphIndexMap type; 01093 typedef vtkGraphIndexMap const_type; 01094 }; 01095 01096 template<> 01097 struct property_map<vtkDirectedGraph*, vertex_index_t> 01098 : property_map<vtkGraph*, vertex_index_t> { }; 01099 01100 template<> 01101 struct property_map<vtkUndirectedGraph*, vertex_index_t> 01102 : property_map<vtkGraph*, vertex_index_t> { }; 01103 01104 inline vtkGraphIndexMap get(vertex_index_t, vtkGraph*) { return vtkGraphIndexMap(); } 01105 01106 template<> 01107 struct property_map<vtkGraph*, edge_index_t> 01108 { 01109 typedef vtkGraphIndexMap type; 01110 typedef vtkGraphIndexMap const_type; 01111 }; 01112 01113 template<> 01114 struct property_map<vtkDirectedGraph*, edge_index_t> 01115 : property_map<vtkGraph*, edge_index_t> { }; 01116 01117 template<> 01118 struct property_map<vtkUndirectedGraph*, edge_index_t> 01119 : property_map<vtkGraph*, edge_index_t> { }; 01120 01121 inline vtkGraphIndexMap get(edge_index_t, vtkGraph*) { return vtkGraphIndexMap(); } 01122 01123 // property_map specializations for const-qualified graphs 01124 template<> 01125 struct property_map<vtkDirectedGraph* const, vertex_index_t> 01126 : property_map<vtkDirectedGraph*, vertex_index_t> { }; 01127 01128 template<> 01129 struct property_map<vtkUndirectedGraph* const, vertex_index_t> 01130 : property_map<vtkUndirectedGraph*, vertex_index_t> { }; 01131 01132 template<> 01133 struct property_map<vtkDirectedGraph* const, edge_index_t> 01134 : property_map<vtkDirectedGraph*, edge_index_t> { }; 01135 01136 template<> 01137 struct property_map<vtkUndirectedGraph* const, edge_index_t> 01138 : property_map<vtkUndirectedGraph*, edge_index_t> { }; 01139 } // namespace boost 01140 01141 #if BOOST_VERSION > 104000 01142 #include <boost/property_map/vector_property_map.hpp> 01143 #else 01144 #include <boost/vector_property_map.hpp> 01145 #endif 01146 01147 01148 #endif // __vtkBoostGraphAdapter_h 01149 // VTK-HeaderTest-Exclude: vtkBoostGraphAdapter.h