diff --git a/Triangulation_on_sphere_2/test/test_mesh.cpp b/Triangulation_on_sphere_2/test/test_mesh.cpp index 43ffb469c0c..17ee5f7ce3a 100644 --- a/Triangulation_on_sphere_2/test/test_mesh.cpp +++ b/Triangulation_on_sphere_2/test/test_mesh.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -12,6 +12,14 @@ +//Mesh_2 + +#include +#include +#include +#include + + typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Delaunay_triangulation_sphere_traits_2 Gt; typedef CGAL::Delaunay_mesh_sphere_traits_2 Mgt; @@ -23,10 +31,67 @@ typedef CGAL::Triangulation_data_structure_2 Tds; typedef CGAL::Constrained_Delaunay_triangulation_sphere_2 CDTS; -typedef CGAL::Delaunay_mesh_size_criteria_2 Criteria; +typedef CGAL::Delaunay_mesh_sphere_size_criteria_2 Criteria; typedef CDTS::Vertex_handle Vertex_handle; typedef CDTS::Point Point; + +template +void read_points(const char* file_path,Output_iterator out){ + int nb; + double Long, lat; + + std::ifstream input(file_path); + if (!input){ + std::cerr << "Error while reading " << file_path << std::endl; + exit(EXIT_FAILURE); + } + + input >> nb; + + for (int i=0;i> Long; + input >> lat; + Long=Long/180.*M_PI; + lat=lat/180.*M_PI; + *out++= Point(100*cos(Long) * cos (lat), 100*sin(Long) * cos (lat),100*sin(lat)); + + + } +} + + +template +void read_points2(const char* file_path,Output_iterator out){ + int nb; + double Long, lat; + + std::ifstream input(file_path); + if (!input){ + std::cerr << "Error while reading " << file_path << std::endl; + exit(EXIT_FAILURE); + } + + input >> nb; + + for (int i=0;i> Long; + input >> lat; + /*Long=Long/180.*M_PI; + lat=lat/180.*M_PI; + *out++= Point(100*cos(Long) * cos (lat), 100*sin(Long) * cos (lat),100*sin(lat)); */ + *out++=K::Point_2(Long,lat); + + + } +} + + + + + void test1(double radius){ @@ -51,7 +116,7 @@ void test1(double radius){ cdt.insert_constraint(vd, va); cdt.is_valid(); - CGAL::refine_Delaunay_mesh_2(cdt, Criteria(0.125, 0.5),false); + CGAL::refine_Delaunay_mesh_2(cdt, Criteria(1.25, 0.5,cdt.geom_traits()),false); cdt.is_valid(); } @@ -61,8 +126,6 @@ void test2(double radius){ CDTS cdt; double r = radius; double a = r/sqrt(3); - //double a = 0.57735026918962584; - //double b = 0.707106781187; double b = r/sqrt(2); cdt.set_radius(r); @@ -81,7 +144,7 @@ void test2(double radius){ cdt.insert_constraint(vd, va); cdt.is_valid(); - CGAL::refine_Delaunay_mesh_2(cdt, Criteria(0.125, 0.5),false); + CGAL::refine_Delaunay_mesh_2(cdt, Criteria(0.125, 0.5,cdt.geom_traits()),false); std::cout<<"number of vertices: "< lst_pt; + char* filename = "/Users/cwerner/CGAL-git/Triangulation_on_sphere_2/test/norway.poly"; + read_points(filename, + std::back_inserter(lst_pt)); - - Vertex_handle va = cdt.insert(Point(b,b,0)); - Vertex_handle vb = cdt.insert(Point(b,-b,0)); - Vertex_handle vc =cdt.insert(Point(0,b,b)); - - - Vertex_handle vd = cdt.insert(Point(-b,-b,0)); - Vertex_handle ve= cdt.insert(Point(-b,b,0)); - Vertex_handle vf = cdt.insert(Point(0,-b,b)); - - - - - cdt.insert_constraint(va, vb); - cdt.insert_constraint(vb, vc); - cdt.insert_constraint(va, vc); - - cdt.insert_constraint(vd, ve); - cdt.insert_constraint(ve, vf); - cdt.insert_constraint(vd, vf); - - + Vertex_handle v; + cdt.set_radius(100); + std::vector vertices; + for(int i=0;i< lst_pt.size(); i++){ + Point p = lst_pt.at(i); + double x = p.x(); + double y= p.y(); + double z = p.z(); + //std::cout< Vb2; + typedef CGAL::Delaunay_mesh_face_base_2 Fb2; + typedef CGAL::Triangulation_data_structure_2 Tds; + typedef CGAL::Constrained_Delaunay_triangulation_2 CDT2; + typedef CGAL::Delaunay_mesh_size_criteria_2 Criteria; + + typedef CDT2::Vertex_handle Vertex_handle; + typedef CDT2::Point Point; + + + CDT2 cdt; + std::vector lst_pt; + char* filename = "/Users/cwerner/CGAL-git/Triangulation_on_sphere_2/test/norway.poly"; + read_points2(filename, + std::back_inserter(lst_pt)); + + + Vertex_handle v; + + std::vector vertices; + for(int i=0;i< lst_pt.size(); i++){ + Point p = lst_pt.at(i); + v =cdt.insert(lst_pt.at(i)); + vertices.push_back(v); + } + int n=lst_pt.size(); + cdt.insert_constraint(vertices.at(n-1), vertices.at(0)); + int number_vert= cdt.number_of_vertices(); + for (int i=1; i