• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //=======================================================================
2 // Copyright 2012 David Doria
3 // Authors: David Doria
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //=======================================================================
9 
10 #include <iostream>
11 #include <boost/array.hpp>
12 #include <boost/graph/grid_graph.hpp>
13 
main(int argc,char * argv[])14 int main(int argc, char* argv[])
15 {
16     // A 2D grid graph
17     typedef boost::grid_graph< 2 > GraphType;
18 
19     // Create a 5x5 graph
20     const unsigned int dimension = 5;
21     boost::array< std::size_t, 2 > lengths = { { dimension, dimension } };
22     GraphType graph(lengths);
23 
24     // Get the index map of the grid graph
25     typedef boost::property_map< GraphType, boost::vertex_index_t >::const_type
26         indexMapType;
27     indexMapType indexMap(get(boost::vertex_index, graph));
28 
29     // Create a float for every node in the graph
30     boost::vector_property_map< float, indexMapType > dataMap(
31         num_vertices(graph), indexMap);
32 
33     // Associate the value 2.0 with the node at position (0,1) in the grid
34     boost::graph_traits< GraphType >::vertex_descriptor v = { { 0, 1 } };
35     put(dataMap, v, 2.0f);
36 
37     // Get the data at the node at position (0,1) in the grid
38     float retrieved = get(dataMap, v);
39     std::cout << "Retrieved value: " << retrieved << std::endl;
40 
41     return 0;
42 }
43