From 10e7154607a5b83e011ff29cde24ea6b9fba2af0 Mon Sep 17 00:00:00 2001 From: denizdiktas Date: Wed, 28 Jun 2023 18:14:58 +0300 Subject: [PATCH] Added: check with extended DCEL --- Arrangement_on_surface_2/demo/earth/Aos.cpp | 113 ++++++++++++++++-- Arrangement_on_surface_2/demo/earth/Aos.h | 6 + .../demo/earth/Main_widget.cpp | 10 +- 3 files changed, 111 insertions(+), 18 deletions(-) diff --git a/Arrangement_on_surface_2/demo/earth/Aos.cpp b/Arrangement_on_surface_2/demo/earth/Aos.cpp index f2ba03b1567..78c89a9dda9 100644 --- a/Arrangement_on_surface_2/demo/earth/Aos.cpp +++ b/Arrangement_on_surface_2/demo/earth/Aos.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,20 @@ namespace { using Topol_traits = CGAL::Arr_spherical_topology_traits_2; using Arrangement = CGAL::Arrangement_on_surface_2; + // Extended DCEL & Arrangement + struct Flag + { + bool v; + Flag() : v{ false } {} + Flag(bool init) : v{ init } {} + }; + + using Ext_dcel = CGAL::Arr_extended_dcel; + using Ext_topol_traits = CGAL::Arr_spherical_topology_traits_2; + using Ext_aos = CGAL::Arrangement_on_surface_2; + + using Dir3 = Kernel::Direction_3; std::ostream& operator << (std::ostream& os, const Dir3& d) @@ -55,6 +70,7 @@ namespace { } } + void Aos::check(const Kml::Placemarks& placemarks) { // Construct the arrangement from 12 geodesic arcs. @@ -79,17 +95,9 @@ void Aos::check(const Kml::Placemarks& placemarks) for (const auto& node : lring.nodes) { num_counted_nodes++; - const auto p = node.get_coords_3d(); - //const auto phi = qDegreesToRadians(node.lat); - //const auto theta = qDegreesToRadians(node.lon); - //const auto z = std::sin(phi); - //const auto rxy = std::cos(phi); - //const auto x = rxy * std::cos(theta); - //const auto y = rxy * std::sin(theta); 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)); } @@ -126,4 +134,91 @@ void Aos::check(const Kml::Placemarks& placemarks) std::cout << "-------------------------------\n"; std::cout << "num polygons = " << num_counted_polygons << std::endl; std::cout << "num arr faces = " << arr.number_of_faces() << std::endl; -} \ No newline at end of file +} + +void Aos::ext_check(const Kml::Placemarks& placemarks) +{ + // Construct the arrangement from 12 geodesic arcs. + 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& lring : pm.polygons) + { + num_counted_polygons++; + + // 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 < sphere_points.size() - 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); + } + } + } + + // MARK all vertices as true + for (auto vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) + { + vit->set_data(Flag(true)); + } + + 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); + + // extract all vertices that are ADDED when inserting the arcs! + int num_created_vertices = 0; + for (auto vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) + { + auto& d = vit->data(); + if (vit->data().v == false) + { + num_created_vertices++; + auto p = vit->point(); + const auto x = CGAL::to_double(p.dx()); + const auto y = CGAL::to_double(p.dy()); + const auto z = CGAL::to_double(p.dz()); + } + } + std::cout << "*** num created vertices = " << num_created_vertices << std::endl; + + std::cout << "-------------------------------\n"; + std::cout << "num nodes = " << num_counted_nodes << std::endl; + std::cout << "num arr vertices = " << arr.number_of_vertices() << std::endl; + + std::cout << "-------------------------------\n"; + std::cout << "num counted arcs = " << num_counted_arcs << std::endl; + std::cout << "num arr edges = " << arr.number_of_edges() << std::endl; + + std::cout << "-------------------------------\n"; + std::cout << "num polygons = " << num_counted_polygons << std::endl; + std::cout << "num arr faces = " << arr.number_of_faces() << std::endl; +} diff --git a/Arrangement_on_surface_2/demo/earth/Aos.h b/Arrangement_on_surface_2/demo/earth/Aos.h index 7a081f1fe54..9a84b52774e 100644 --- a/Arrangement_on_surface_2/demo/earth/Aos.h +++ b/Arrangement_on_surface_2/demo/earth/Aos.h @@ -13,6 +13,12 @@ class Aos public: static void check(const Kml::Placemarks& placemarks); + + // Extended check: here we use the extended version of the DCEL to understand + // what is going on with the additional vertices and faces. + // INPUT: GIS data + // OUTPUT: vertices created during arrangement construction + static void ext_check(const Kml::Placemarks& placemarks); }; diff --git a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp index 7c337ee83e9..136c1dbbebd 100644 --- a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp +++ b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp @@ -108,16 +108,8 @@ void Main_widget::timerEvent(QTimerEvent*) } -auto func() -{ - double x, y, z; - return std::make_tuple(x,y,z); -} - void Main_widget::initializeGL() { - auto [x, y, z] = func(); - //const auto file_name = "C:/work/gsoc2023/data/world_countries.kml"; const auto file_name = "C:/work/gsoc2023/data/ne_110m_admin_0_countries.kml"; auto countries = Kml::read(file_name); @@ -137,7 +129,7 @@ void Main_widget::initializeGL() // check the arrangement constructed from the GIS data-set { - Aos::check(countries); + Aos::ext_check(countries); }