Difference between revisions of "CPP/Boost/BGL/GridGraphProperties"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with 'Grid graphs must use "exterior properties". Here is how: ==GridGraphProperties.cpp== <source lang="cpp"> #include <iostream> #include <boost/array.hpp> #include <boost/graph/gri…') |
(No difference)
|
Latest revision as of 16:03, 23 January 2012
Grid graphs must use "exterior properties". Here is how:
GridGraphProperties.cpp
#include <iostream> #include <boost/array.hpp> #include <boost/graph/grid_graph.hpp> int main(int argc, char* argv[]) { typedef boost::grid_graph<2> GraphType; const unsigned int dimension = 5; boost::array<std::size_t, 2> lengths = { { dimension, dimension } }; GraphType graph(lengths); boost::graph_traits<GraphType>::vertex_descriptor v = { { 0, 1 } }; std::vector<float> vertexData(dimension * dimension, 3); typedef boost::property_map<GraphType, boost::vertex_index_t>::const_type indexMapType; indexMapType indexMap(get(boost::vertex_index, graph)); boost::iterator_property_map<std::vector<float>::iterator, indexMapType> myMap(vertexData.begin(), indexMap); float retrieved = get(myMap, v); std::cout << "Retrieved: " << retrieved << std::endl; return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) Project(GridGraphProperties) set(Boost_USE_MULTITHREADED ON) FIND_PACKAGE(Boost 1.38 COMPONENTS required) INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${Boost_INCLUDE_DIRS}) LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS}) ADD_EXECUTABLE(GridGraphProperties GridGraphProperties.cpp)