diff --git a/Arrangement_on_surface_2/demo/earth/Aos.cpp b/Arrangement_on_surface_2/demo/earth/Aos.cpp index b65b665564f..3e572107014 100644 --- a/Arrangement_on_surface_2/demo/earth/Aos.cpp +++ b/Arrangement_on_surface_2/demo/earth/Aos.cpp @@ -69,6 +69,117 @@ namespace { //os << v.hx() << ", " << v.hy() << ", " << v.hz() << ", " << v.hw(); return os; } + + + //--------------------------------------------------------------------------- + // below are the helper functions used to construct the arcs from KML data + // TODO: Revisit handling of INNER & OUTER boundaries + using Curves = std::vector; + + // get curves for the given kml placemark + // NOTE: this is defined here to keep the definitions local to this cpp file + Curves get_arcs(const Kml::Placemark& placemark) + { + Geom_traits traits; + auto ctr_p = traits.construct_point_2_object(); + auto ctr_cv = traits.construct_curve_2_object(); + + std::vector xcvs; + for (const auto& polygon : placemark.polygons) + { + // colect all rings into a single list (FOR NOW!!!) + // TO-DO: PROCESS OUTER & INNER BOUNDARIES SEPARATELY!!! + Kml::LinearRings linear_rings; + linear_rings.push_back(polygon.outer_boundary); + for (const auto& inner_boundary : polygon.inner_boundaries) + linear_rings.push_back(inner_boundary); + + + // convert the nodes to points on unit-sphere + for (const auto& lring : linear_rings) + { + std::vector sphere_points; + for (const auto& node : lring.nodes) + { + const auto p = node.get_coords_3d(); + Approximate_Vector_3 v(p.x, p.y, p.z); + sphere_points.push_back(v); + } + + // add geodesic arcs for the current LinearRing + int num_points = sphere_points.size(); + for (int i = 0; i < num_points - 1; i++) + { + const auto p1 = sphere_points[i]; + const auto p2 = sphere_points[i + 1]; + xcvs.push_back(ctr_cv(ctr_p(p1.x(), p1.y(), p1.z()), + ctr_p(p2.x(), p2.y(), p2.z()))); + } + } + } + + return xcvs; + } + + + // this one is used by the Aos::check and Aos::ext_check functions + int num_counted_nodes = 0; + int num_counted_arcs = 0; + int num_counted_polygons = 0; + template + Curves get_arcs(const Kml::Placemarks& placemarks, Arr_type& arr) + { + Geom_traits traits; + auto ctr_p = traits.construct_point_2_object(); + auto ctr_cv = traits.construct_curve_2_object(); + + num_counted_nodes = 0; + num_counted_arcs = 0; + num_counted_polygons = 0; + std::vector xcvs; + for (const auto& pm : placemarks) + { + for (const auto& polygon : pm.polygons) + { + num_counted_polygons++; + + // colect all rings into a single list (FOR NOW!!!) + // TO-DO: PROCESS OUTER & INNER BOUNDARIES SEPARATELY!!! + Kml::LinearRings linear_rings; + linear_rings.push_back(polygon.outer_boundary); + for (const auto& inner_boundary : polygon.inner_boundaries) + linear_rings.push_back(inner_boundary); + + // loop on outer and inner boundaries + for (const auto& lring : linear_rings) + { + // convert the nodes to points on unit-sphere + std::vector sphere_points; + for (const auto& node : lring.nodes) + { + num_counted_nodes++; + const auto p = node.get_coords_3d(); + Approximate_Vector_3 v(p.x, p.y, p.z); + sphere_points.push_back(v); + CGAL::insert_point(arr, ctr_p(p.x, p.y, p.z)); + } + + // add curves + int num_points = sphere_points.size(); + for (int i = 0; i < num_points - 1; i++) + { + num_counted_arcs++; + const auto p1 = sphere_points[i]; + const auto p2 = sphere_points[i + 1]; + auto xcv = ctr_cv(ctr_p(p1.x(), p1.y(), p1.z()), + ctr_p(p2.x(), p2.y(), p2.z())); + xcvs.push_back(xcv); + } + } + } + } + return xcvs; + } } @@ -110,46 +221,13 @@ Aos::Approx_arcs Aos::get_approx_arcs(double error) return arcs; } - Aos::Approx_arcs Aos::get_approx_arcs(const Kml::Placemark& placemark, double error) { Geom_traits traits; auto ctr_p = traits.construct_point_2_object(); auto ctr_cv = traits.construct_curve_2_object(); - std::vector xcvs; - for (const auto& polygon : placemark.polygons) - { - // colect all rings into a single list (FOR NOW!!!) - // TO-DO: PROCESS OUTER & INNER BOUNDARIES SEPARATELY!!! - Kml::LinearRings linear_rings; - linear_rings.push_back(polygon.outer_boundary); - for (const auto& inner_boundary : polygon.inner_boundaries) - linear_rings.push_back(inner_boundary); - - - // convert the nodes to points on unit-sphere - for (const auto& lring : linear_rings) - { - std::vector sphere_points; - for (const auto& node : lring.nodes) - { - const auto p = node.get_coords_3d(); - Approximate_Vector_3 v(p.x, p.y, p.z); - sphere_points.push_back(v); - } - - // add geodesic arcs for the current LinearRing - int num_points = sphere_points.size(); - for (int i = 0; i < num_points - 1; i++) - { - const auto p1 = sphere_points[i]; - const auto p2 = sphere_points[i + 1]; - xcvs.push_back(ctr_cv(ctr_p(p1.x(), p1.y(), p1.z()), - ctr_p(p2.x(), p2.y(), p2.z()))); - } - } - } + auto xcvs = get_arcs(placemark); auto approx = traits.approximate_2_object(); std::vector> arcs; @@ -173,63 +251,13 @@ Aos::Approx_arcs Aos::get_approx_arcs(const Kml::Placemark& placemark, double er void Aos::check(const Kml::Placemarks& placemarks) { - // Construct the arrangement from 12 geodesic arcs. Geom_traits traits; Arrangement arr(&traits); - auto ctr_p = traits.construct_point_2_object(); - auto ctr_cv = traits.construct_curve_2_object(); - - int num_counted_nodes = 0; - int num_counted_arcs = 0; - int num_counted_polygons = 0; - std::vector xcvs; - for (const auto& pm : placemarks) - { - for (const auto& polygon : pm.polygons) - { - num_counted_polygons++; - - // colect all rings into a single list (FOR NOW!!!) - // TO-DO: PROCESS OUTER & INNER BOUNDARIES SEPARATELY!!! - Kml::LinearRings linear_rings; - linear_rings.push_back(polygon.outer_boundary); - for (const auto& inner_boundary : polygon.inner_boundaries) - linear_rings.push_back(inner_boundary); - - // loop on outer and inner boundaries - for(const auto& lring : linear_rings) - { - // convert the nodes to points on unit-sphere - std::vector sphere_points; - for (const auto& node : lring.nodes) - { - num_counted_nodes++; - const auto p = node.get_coords_3d(); - Approximate_Vector_3 v(p.x, p.y, p.z); - sphere_points.push_back(v); - CGAL::insert_point(arr, ctr_p(p.x, p.y, p.z)); - } - - // add curves - int num_points = sphere_points.size(); - for (int i = 0; i < num_points - 1; i++) - { - num_counted_arcs++; - const auto p1 = sphere_points[i]; - const auto p2 = sphere_points[i + 1]; - auto xcv = ctr_cv(ctr_p(p1.x(), p1.y(), p1.z()), - ctr_p(p2.x(), p2.y(), p2.z())); - xcvs.push_back(xcv); - } - } - } - } - + auto xcvs = get_arcs(placemarks, arr); std::cout << "-------------------------------\n"; std::cout << "num arr vertices (before adding arcs) = " << arr.number_of_vertices() << std::endl; - // add arcs for(auto xcv : xcvs) CGAL::insert_curve(arr, xcv); @@ -253,54 +281,7 @@ std::vector Aos::ext_check(const Kml::Placemarks& placemarks) Geom_traits traits; Ext_aos arr(&traits); - auto ctr_p = traits.construct_point_2_object(); - auto ctr_cv = traits.construct_curve_2_object(); - - int num_counted_nodes = 0; - int num_counted_arcs = 0; - int num_counted_polygons = 0; - std::vector xcvs; - for (const auto& pm : placemarks) - { - for (const auto& polygon : pm.polygons) - { - num_counted_polygons++; - - // colect all rings into a single list (FOR NOW!!!) - // TO-DO: PROCESS OUTER & INNER BOUNDARIES SEPARATELY!!! - Kml::LinearRings linear_rings; - linear_rings.push_back(polygon.outer_boundary); - for (const auto& inner_boundary : polygon.inner_boundaries) - linear_rings.push_back(inner_boundary); - - // loop on all linear-rings (outer and inner rings) - for (const auto& lring : linear_rings) - { - // convert the nodes to points on unit-sphere - std::vector sphere_points; - for (const auto& node : lring.nodes) - { - num_counted_nodes++; - const auto p = node.get_coords_3d(); - Approximate_Vector_3 v(p.x, p.y, p.z); - sphere_points.push_back(v); - CGAL::insert_point(arr, ctr_p(p.x, p.y, p.z)); - } - - // add curves - int num_points = sphere_points.size(); - for (int i = 0; i < num_points - 1; ++i) - { - num_counted_arcs++; - const auto p1 = sphere_points[i]; - const auto p2 = sphere_points[i + 1]; - auto xcv = ctr_cv(ctr_p(p1.x(), p1.y(), p1.z()), - ctr_p(p2.x(), p2.y(), p2.z())); - xcvs.push_back(xcv); - } - } - } - } + auto xcvs = get_arcs(placemarks, arr); // MARK all vertices as true for (auto vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) @@ -313,7 +294,7 @@ std::vector Aos::ext_check(const Kml::Placemarks& placemarks) arr.number_of_vertices() << std::endl; // add arcs - for (auto xcv : xcvs) + for (auto& xcv : xcvs) CGAL::insert_curve(arr, xcv); // extract all vertices that are ADDED when inserting the arcs! diff --git a/Arrangement_on_surface_2/demo/earth/CMakeLists.txt b/Arrangement_on_surface_2/demo/earth/CMakeLists.txt index 4e011f25ef5..79a252d1e0f 100644 --- a/Arrangement_on_surface_2/demo/earth/CMakeLists.txt +++ b/Arrangement_on_surface_2/demo/earth/CMakeLists.txt @@ -48,7 +48,6 @@ link_directories(earth PRIVATE ${SHAPELIB_LIB_DIR}) # AOS file(GLOB source_files_aos Aos.h Aos.cpp - Geodesic_arcs.h Geodesic_arcs.cpp ) source_group( "Aos" FILES ${source_files_aos} ) diff --git a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp index 74348d8fd45..1d0f2700e59 100644 --- a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp +++ b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp @@ -9,7 +9,6 @@ #include "Aos.h" #include "Kml_reader.h" -//#include "Geodesic_arcs.h" #include "Tools.h" @@ -196,7 +195,7 @@ void Main_widget::initializeGL() auto dup_nodes = Kml::get_duplicates(countries); // initialize rendering of DUPLICATE VERTICES - if(1) + if(0) { std::vector vertices; for (const auto& node : dup_nodes) @@ -466,7 +465,7 @@ void Main_widget::paintGL() const QVector4D vertex_color(1, 0, 0, 1); sp.set_uniform("u_color", vertex_color); glPointSize(5); - //m_vertices->draw(); + m_vertices->draw(); sp.unuse(); }