From c97223b933677b58fa12ffb80c6cabafeb241df0 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 31 Mar 2017 11:20:47 +0200 Subject: [PATCH] Add an example for a triangulation hierarchy of a constrained Delaunay triangulation plus --- BGL/doc/BGL/examples.txt | 1 + .../emst_cdt_plus_hierarchy.cpp | 112 ++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 BGL/examples/BGL_triangulation_2/emst_cdt_plus_hierarchy.cpp diff --git a/BGL/doc/BGL/examples.txt b/BGL/doc/BGL/examples.txt index f5260c52f1a..8eca963b8ab 100644 --- a/BGL/doc/BGL/examples.txt +++ b/BGL/doc/BGL/examples.txt @@ -12,6 +12,7 @@ \example BGL_triangulation_2/dijkstra.cpp \example BGL_triangulation_2/dijkstra_with_internal_properties.cpp \example BGL_triangulation_2/emst.cpp +\example BGL_triangulation_2/emst/emst_cdt_plus_hierarchy.cpp \example BGL_surface_mesh/prim.cpp \example BGL_surface_mesh/surface_mesh_dual.cpp \example Surface_mesh_skeletonization/simple_mcfskel_example.cpp diff --git a/BGL/examples/BGL_triangulation_2/emst_cdt_plus_hierarchy.cpp b/BGL/examples/BGL_triangulation_2/emst_cdt_plus_hierarchy.cpp new file mode 100644 index 00000000000..acac3a76a68 --- /dev/null +++ b/BGL/examples/BGL_triangulation_2/emst_cdt_plus_hierarchy.cpp @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef K::Point_2 Point; + +typedef CGAL::Triangulation_vertex_base_2 Vbb; +typedef CGAL::Triangulation_hierarchy_vertex_base_2 Vb; +typedef CGAL::Constrained_triangulation_face_base_2 Fb; +typedef CGAL::Triangulation_data_structure_2 TDS; +typedef CGAL::Exact_predicates_tag Itag; +typedef CGAL::Constrained_Delaunay_triangulation_2 CDT; +typedef CGAL::Triangulation_hierarchy_2 CDTH; +typedef CGAL::Constrained_triangulation_plus_2 Triangulation; + + +// As we only consider finite vertices and edges +// we need the following filter + +template +struct Is_finite { + + const T* t_; + + Is_finite() + : t_(NULL) + {} + + Is_finite(const T& t) + : t_(&t) + { } + + template + bool operator()(const VertexOrEdge& voe) const { + return ! t_->is_infinite(voe); + } +}; + +typedef Is_finite Filter; +typedef boost::filtered_graph Finite_triangulation; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::vertex_iterator vertex_iterator; +typedef boost::graph_traits::edge_descriptor edge_descriptor; + +// The BGL makes use of indices associated to the vertices +// We use a std::map to store the index +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; +VertexIdPropertyMap vertex_index_pmap(vertex_id_map); + +int +main(int argc,char* argv[]) +{ + const char* filename = (argc > 1) ? argv[1] : "data/points.xy"; + std::ifstream input(filename); + Triangulation t; + Filter is_finite(t); + Finite_triangulation ft(t, is_finite, is_finite); + + Point p ; + while(input >> p){ + t.insert(p); + } + + vertex_iterator vit, ve; + // Associate indices to the vertices + 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(vit,ve)=boost::vertices(ft); vit!=ve; ++vit ){ + vertex_descriptor vd = *vit; + vertex_id_map[vd]= index++; + } + + + // We use the default edge weight which is the squared length of the edge + // This property map is defined in graph_traits_Triangulation_2.h + + // In the function call you can see a named parameter: vertex_index_map + std::list mst; + boost::kruskal_minimum_spanning_tree(ft, + std::back_inserter(mst), + vertex_index_map(vertex_index_pmap)); + + + std::cout << "The edges of the Euclidean mimimum spanning tree:" << std::endl; + + for(std::list::iterator it = mst.begin(); it != mst.end(); ++it){ + edge_descriptor ed = *it; + vertex_descriptor svd = source(ed,t); + vertex_descriptor tvd = target(ed,t); + Triangulation::Vertex_handle sv = svd; + Triangulation::Vertex_handle tv = tvd; + std::cout << "[ " << sv->point() << " | " << tv->point() << " ] " << std::endl; + } + + return 0; +}