grid_graph vertex properties
Since there is no VertexProperties template parameter on grid_graph, is it correct that you cannot use interior properties, but must use exterior properties? Thanks, David
On Mon, 23 Jan 2012, David Doria wrote:
Since there is no VertexProperties template parameter on grid_graph, is it correct that you cannot use interior properties, but must use exterior properties?
Yes, that is correct. Both vertex and edge index maps exist, though, so it is easy to use external properties for both of those (unlike edge properties for adjacency_list). -- Jeremiah Willcock
Yes, that is correct. Both vertex and edge index maps exist, though, so it is easy to use external properties for both of those (unlike edge properties for adjacency_list).
Hm, I've been playing with this for a while now and I don't seem to understand how to add something to the vertex index map. This compiles, but I think it is creating a new map: #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, 0); boost::grid_graph_index_map<GraphType, boost::graph_traits<GraphType>::vertex_descriptor, float> myMap(graph); float retrieved = get(myMap, v); std::cout << "Retrieved: " << retrieved << std::endl; } Could you demonstrate how to do this? We should really add this to the grid_graph documentation :) Thanks, David
On Mon, 23 Jan 2012, David Doria wrote:
Yes, that is correct. Both vertex and edge index maps exist, though, so it is easy to use external properties for both of those (unlike edge properties for adjacency_list).
Hm, I've been playing with this for a while now and I don't seem to understand how to add something to the vertex index map.
This compiles, but I think it is creating a new map:
#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, 0);
boost::grid_graph_index_map<GraphType, boost::graph_traits<GraphType>::vertex_descriptor, float> myMap(graph);
This should just be (something like): 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); // grid_graph_index_map is internal
float retrieved = get(myMap, v); std::cout << "Retrieved: " << retrieved << std::endl;
}
Could you demonstrate how to do this? We should really add this to the grid_graph documentation :)
-- Jeremiah Willcock
This should just be (something like):
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);
// grid_graph_index_map is internal
Thanks, that seems to do it. For posterity: http://programmingexamples.net/wiki/CPP/Boost/BGL/GridGraphProperties David
On Mon, 23 Jan 2012, David Doria wrote:
This should just be (something like):
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);
// grid_graph_index_map is internal
Thanks, that seems to do it.
For posterity: http://programmingexamples.net/wiki/CPP/Boost/BGL/GridGraphProperties
For future reference, that is the approach to build external property maps for all types of graphs, not just grid graphs. -- Jeremiah Willcock
participants (2)
-
David Doria
-
Jeremiah Willcock