From 272526033415dd27426e87bac8c1f6d446bfb49c Mon Sep 17 00:00:00 2001 From: Fernando Cacciola Date: Thu, 19 Oct 2006 16:50:06 +0000 Subject: [PATCH] Partial fixes to make it work (unfinished) --- BGL/examples/BGL_polyhedron_3/kruskal.cpp | 46 +++++++++++++------ .../kruskal_with_stored_id.cpp | 29 ++++++------ 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/BGL/examples/BGL_polyhedron_3/kruskal.cpp b/BGL/examples/BGL_polyhedron_3/kruskal.cpp index ddd9f784c11..8492a4fe181 100644 --- a/BGL/examples/BGL_polyhedron_3/kruskal.cpp +++ b/BGL/examples/BGL_polyhedron_3/kruskal.cpp @@ -1,7 +1,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -15,18 +17,29 @@ typedef Kernel::Vector_3 Vector; typedef Kernel::Point_3 Point; typedef CGAL::Polyhedron_3 Polyhedron; -typedef boost::graph_traits::vertex_descriptor vertex_descriptor; -typedef boost::graph_traits::vertex_iterator vertex_iterator; -typedef boost::graph_traits::edge_descriptor edge_descriptor; - +typedef boost::graph_traits::vertex_descriptor vertex_const_descriptor; +typedef boost::graph_traits::vertex_iterator vertex_const_iterator; +typedef boost::graph_traits::edge_descriptor edge_const_descriptor; // The BGL makes heavy use of indices associated to the vertices -// We use a std::map to store the index -typedef std::map VertexIndexMap; +// We use a std::map to store the index + +namespace CGAL +{ + +// (but we define operator < for handles as is not predefined) +bool operator< ( vertex_const_descriptor const& x, vertex_const_descriptor const& y ) +{ + return &*x < &*y ; +} + +} + +typedef std::map VertexIndexMap; VertexIndexMap vertex_id_map; // A std::map is not a property map, because it is not lightweight -typedef boost::associative_property_map VertexIdPropertyMap; +typedef boost::const_associative_property_map VertexIdPropertyMap; VertexIdPropertyMap vertex_index_pmap(vertex_id_map); @@ -35,13 +48,13 @@ kruskal(const Polyhedron& P) { // associate indices to the vertices { - vertex_iterator vb, ve; + vertex_const_iterator vb, ve; int index = 0; // boost::tie assigns the first and second element of the std::pair // returned by boost::vertices to the variables vit and ve for(boost::tie(vb,ve)=boost::vertices(P); vb!=ve; ++vb ){ - vertex_descriptor vd = *vb; + vertex_const_descriptor vd = *vb; vertex_id_map[vd]= index++; } } @@ -50,12 +63,12 @@ kruskal(const Polyhedron& P) // This property map is defined in graph_traits_Polyhedron_3.h // In the function call you can see a named parameter: vertex_index_map - std::list mst; + std::list mst; boost::kruskal_minimum_spanning_tree(P, std::back_inserter(mst), vertex_index_map(vertex_index_pmap)); - vertex_iterator vb, ve; + vertex_const_iterator vb, ve; std::cout << "#VRML V2.0 utf8\n" "Shape {\n" @@ -74,9 +87,12 @@ kruskal(const Polyhedron& P) "}\n" "coordIndex [\n"; - for(std::list::iterator it = mst.begin(); it != mst.end(); ++it){ - std::cout << vertex_id_map[boost::source(*it,P)] - << ", " << vertex_id_map[boost::target(*it,P)] << ", -1\n"; + for(std::list::iterator it = mst.begin(); it != mst.end(); ++it) + { + edge_const_descriptor e = *it ; + vertex_const_descriptor s = boost::source(e,P); + vertex_const_descriptor t = boost::target(e,P); + std::cout << vertex_id_map[s] << ", " << vertex_id_map[t] << ", -1\n"; } std::cout << "]\n" diff --git a/BGL/examples/BGL_polyhedron_3/kruskal_with_stored_id.cpp b/BGL/examples/BGL_polyhedron_3/kruskal_with_stored_id.cpp index 41a6d40583e..f730f116f61 100644 --- a/BGL/examples/BGL_polyhedron_3/kruskal_with_stored_id.cpp +++ b/BGL/examples/BGL_polyhedron_3/kruskal_with_stored_id.cpp @@ -2,7 +2,8 @@ #include #include #include -#include +#include +#include #include #include @@ -11,14 +12,14 @@ #include -typedef CGAL::Cartesian Kernel; -typedef Kernel::Vector_3 Vector; -typedef Kernel::Point_3 Point; -typedef CGAL::Polyhedron_3 Polyhedron; +typedef CGAL::Cartesian Kernel; +typedef Kernel::Vector_3 Vector; +typedef Kernel::Point_3 Point; +typedef CGAL::Polyhedron_3 Polyhedron; -typedef boost::graph_traits::vertex_descriptor vertex_descriptor; -typedef boost::graph_traits::vertex_iterator vertex_iterator; -typedef boost::graph_traits::edge_descriptor edge_descriptor; +typedef boost::graph_traits::vertex_descriptor vertex_const_descriptor; +typedef boost::graph_traits::vertex_iterator vertex_const_iterator; +typedef boost::graph_traits::edge_descriptor edge_const_descriptor; void @@ -26,13 +27,13 @@ kruskal(const Polyhedron& P) { // associate indices to the vertices using the "id()" field of the vertex. { - vertex_iterator vb, ve; + vertex_const_iterator vb, ve; int index = 0; // boost::tie assigns the first and second element of the std::pair // returned by boost::vertices to the variables vit and ve for(boost::tie(vb,ve)=boost::vertices(P); vb!=ve; ++vb ){ - vertex_descriptor vd = *vb; + vertex_const_descriptor vd = *vb; vd->id() = index++; } } @@ -44,10 +45,10 @@ kruskal(const Polyhedron& P) // when ommitted defaults to "get(vertex_index,graph)". // That default works here because the vertex type supports the "id()" // field which is used by the vertex_index internal property. - std::list mst; + std::list mst; boost::kruskal_minimum_spanning_tree(P,std::back_inserter(mst)); - vertex_iterator vb, ve; + vertex_const_iterator vb, ve; std::cout << "#VRML V2.0 utf8\n" "Shape {\n" @@ -66,8 +67,8 @@ kruskal(const Polyhedron& P) "}\n" "coordIndex [\n"; - for(std::list::iterator it = mst.begin(); it != mst.end(); ++it){ - std::cout << vertex_id_map[boost::source(*it,P)] + for(std::list::iterator it = mst.begin(); it != mst.end(); ++it){ + std::cout << boost::source(*it,P)->id() << ", " << boost::target(*it,P)->id() << ", -1\n"; }