grid_graph_properties.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #include <iostream>
  10. #include <boost/array.hpp>
  11. #include <boost/graph/grid_graph.hpp>
  12. int main(int argc, char* argv[])
  13. {
  14. // A 2D grid graph
  15. typedef boost::grid_graph<2> GraphType;
  16. // Create a 5x5 graph
  17. const unsigned int dimension = 5;
  18. boost::array<std::size_t, 2> lengths = { { dimension, dimension } };
  19. GraphType graph(lengths);
  20. // Get the index map of the grid graph
  21. typedef boost::property_map<GraphType, boost::vertex_index_t>::const_type indexMapType;
  22. indexMapType indexMap(get(boost::vertex_index, graph));
  23. // Create a float for every node in the graph
  24. boost::vector_property_map<float, indexMapType> dataMap(num_vertices(graph), indexMap);
  25. // Associate the value 2.0 with the node at position (0,1) in the grid
  26. boost::graph_traits<GraphType>::vertex_descriptor v = { { 0, 1 } };
  27. put(dataMap, v, 2.0f);
  28. // Get the data at the node at position (0,1) in the grid
  29. float retrieved = get(dataMap, v);
  30. std::cout << "Retrieved value: " << retrieved << std::endl;
  31. return 0;
  32. }