From 16863d714847ff1641ef3a31cb0ba902bc1273a1 Mon Sep 17 00:00:00 2001 From: denizdiktas Date: Tue, 1 Aug 2023 13:18:55 +0300 Subject: [PATCH 1/2] modified the arr-saving function --- Arrangement_on_surface_2/demo/earth/Aos.cpp | 98 ++++++++++++------- .../demo/earth/Kml_reader.cpp | 10 ++ .../demo/earth/Kml_reader.h | 2 + .../demo/earth/Main_widget.cpp | 13 +-- 4 files changed, 84 insertions(+), 39 deletions(-) diff --git a/Arrangement_on_surface_2/demo/earth/Aos.cpp b/Arrangement_on_surface_2/demo/earth/Aos.cpp index 4d91cb5ddf6..ccdae2f58b3 100644 --- a/Arrangement_on_surface_2/demo/earth/Aos.cpp +++ b/Arrangement_on_surface_2/demo/earth/Aos.cpp @@ -25,7 +25,7 @@ using json = nlohmann::ordered_json; #include "Tools.h" namespace { -#define USE_EPIC +//#define USE_EPIC #ifdef USE_EPIC using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; @@ -833,6 +833,10 @@ void Aos::save_arr(Kml::Placemarks& placemarks, const std::string& file_name) } } + std::cout << "*** arr.number_of_faces = " << arr.number_of_faces() << std::endl; + std::cout << "*** arr.number_of_halfedges = " << arr.number_of_halfedges() << std::endl; + std::cout << "*** arr.number_of_vertices = " << arr.number_of_vertices() << std::endl; + // DEFINE JSON OBJECT json js; auto& js_points = js["points"] = json::array(); @@ -950,43 +954,70 @@ void Aos::save_arr(Kml::Placemarks& placemarks, const std::string& file_name) int num_half_edges = 0; auto& js_halfedges = js["halfedges"] = json::array(); std::map halfedge_pos_map; - auto write_half_edges = [&](Ext_aos::Ccb_halfedge_circulator first) + //auto write_half_edges = [&](Ext_aos::Ccb_halfedge_circulator first) + //{ + // auto curr = first; + // do { + // num_half_edges++; + // auto& he = *curr; + // auto it = halfedge_pos_map.find(&he); + // if (it == halfedge_pos_map.end()) + // { + // auto new_he_pos = halfedge_pos_map.size(); + // halfedge_pos_map[&he] = new_he_pos; + // } + // auto svh = he.source(); + // auto tvh = he.target(); + // auto& xcv = he.curve(); + // auto svp = vertex_pos_map[svh]; + // auto tvp = vertex_pos_map[tvh]; + // auto xcvp = curve_pos_map[&xcv]; + // json js_he; + // js_he["source"] = svp; + // js_he["target"] = tvp; + // js_he["curve"] = xcvp; + // js_halfedges.push_back(std::move(js_he)); + // } while (++curr != first); + //}; + auto write_half_edge = [&](auto& he) { - auto curr = first; - do { - num_half_edges++; - auto& he = *curr; - auto it = halfedge_pos_map.find(&he); - if (it == halfedge_pos_map.end()) - { - auto new_he_pos = halfedge_pos_map.size(); - halfedge_pos_map[&he] = new_he_pos; - } - auto svh = he.source(); - auto tvh = he.target(); - auto& xcv = he.curve(); - auto svp = vertex_pos_map[svh]; - auto tvp = vertex_pos_map[tvh]; - auto xcvp = curve_pos_map[&xcv]; - json js_he; - js_he["source"] = svp; - js_he["target"] = tvp; - js_he["curve"] = xcvp; - js_halfedges.push_back(std::move(js_he)); - } while (++curr != first); + auto it = halfedge_pos_map.find(&he); + if (it == halfedge_pos_map.end()) + { + auto new_he_pos = halfedge_pos_map.size(); + halfedge_pos_map[&he] = new_he_pos; + } + auto svh = he.source(); + auto tvh = he.target(); + auto& xcv = he.curve(); + auto svp = vertex_pos_map[svh]; + auto tvp = vertex_pos_map[tvh]; + auto xcvp = curve_pos_map[&xcv]; + json js_he; + js_he["source"] = svp; + js_he["target"] = tvp; + js_he["curve"] = xcvp; + js_halfedges.push_back(std::move(js_he)); }; - for (auto fh = arr.faces_begin(); fh != arr.faces_end(); ++fh) + for (auto it = arr.halfedges_begin(); it != arr.halfedges_end(); ++it) { - auto it = fh->outer_ccb(); - for (auto ccb = fh->outer_ccbs_begin(); ccb != fh->outer_ccbs_end(); ++ccb) - write_half_edges(*ccb); - - for (auto ccb = fh->inner_ccbs_begin(); ccb != fh->inner_ccbs_end(); ++ccb) - write_half_edges(*ccb); + auto& he = *it; + write_half_edge(he); + num_half_edges++; } - std::cout << "*** num total half-edges = " << num_half_edges << std::endl; - std::cout << "*** halfedge-pos-map size = " << halfedge_pos_map.size() << std::endl; + //for (auto fh = arr.faces_begin(); fh != arr.faces_end(); ++fh) + //{ + // auto it = fh->outer_ccb(); + // for (auto ccb = fh->outer_ccbs_begin(); ccb != fh->outer_ccbs_end(); ++ccb) + // write_half_edges(*ccb); + + // for (auto ccb = fh->inner_ccbs_begin(); ccb != fh->inner_ccbs_end(); ++ccb) + // write_half_edges(*ccb); + //} + std::cout << "HALF-EDGE CHECKS:\n"; + std::cout << " *** num total half-edges = " << num_half_edges << std::endl; + std::cout << " *** halfedge-pos-map size = " << halfedge_pos_map.size() << std::endl; //////////////////////////////////////////////////////////////////////////// @@ -1225,6 +1256,7 @@ Aos::Approx_arcs Aos::load_arr(const std::string& file_name) auto& js_name = js_face["name"]; auto& js_outer_ccbs = js_face["outer_ccbs"]; //auto& js_inner_ccbs = js_face["inner_ccbs"]; + if(0) { std::cout << std::boolalpha << "is name string = " << js_name.is_string() << std::endl; std::cout << "name = " << js_name.get() << std::endl; diff --git a/Arrangement_on_surface_2/demo/earth/Kml_reader.cpp b/Arrangement_on_surface_2/demo/earth/Kml_reader.cpp index 61ed47aed80..a705970ece6 100644 --- a/Arrangement_on_surface_2/demo/earth/Kml_reader.cpp +++ b/Arrangement_on_surface_2/demo/earth/Kml_reader.cpp @@ -44,6 +44,16 @@ std::ostream& operator << (std::ostream& os, const Kml::Node& n) } +int Kml::get_number_of_polygons(Placemarks& placemarks) +{ + int total_number_of_polygons = 0; + for (auto& placemark : placemarks) + { + total_number_of_polygons += placemark.polygons.size(); + } + return total_number_of_polygons; +} + Kml::Placemarks Kml::read(const std::string& file_name) { LinearRing lring; diff --git a/Arrangement_on_surface_2/demo/earth/Kml_reader.h b/Arrangement_on_surface_2/demo/earth/Kml_reader.h index 2a14fede675..2c36f9a5470 100644 --- a/Arrangement_on_surface_2/demo/earth/Kml_reader.h +++ b/Arrangement_on_surface_2/demo/earth/Kml_reader.h @@ -82,6 +82,8 @@ class Kml }; using Placemarks = std::vector; + static int get_number_of_polygons(Placemarks& placemarks); + static Placemarks read(const std::string& file_name); diff --git a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp index 58245abc91b..ac6db8fe34e 100644 --- a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp +++ b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp @@ -162,7 +162,7 @@ std::unique_ptr new_faces; void Main_widget::initializeGL() { // verify that the node (180.0, -84.71338) in Antarctica is redundant - verify_antarctica_node_is_redundant(); + //verify_antarctica_node_is_redundant(); //init_problematic_nodes(); @@ -173,12 +173,13 @@ void Main_widget::initializeGL() //Shapefile::read(shape_file_name); //const auto file_name = data_path + "world_countries.kml"; - //const auto file_name = data_path + "ne_110m_admin_0_countries.kml"; - const auto file_name = data_path + "ne_110m_admin_0_countries_africa.kml"; + const auto file_name = data_path + "ne_110m_admin_0_countries.kml"; + //const auto file_name = data_path + "ne_110m_admin_0_countries_africa.kml"; m_countries = Kml::read(file_name); auto dup_nodes = Kml::get_duplicates(m_countries); //auto all_nodes = Kml::generate_ids(m_countries); - + qDebug() << "*** KML number of polygons = " << + Kml::get_number_of_polygons(m_countries); if(0) { auto created_faces = Aos::find_new_faces(m_countries); @@ -186,8 +187,8 @@ void Main_widget::initializeGL() } { - //Aos::save_arr(m_countries, "C:/work/gsoc2023/deneme.json"); - Aos::load_arr("C:/work/gsoc2023/deneme.json"); + Aos::save_arr(m_countries, "C:/work/gsoc2023/ne_110m_admin_0_countries.json"); + //Aos::load_arr("C:/work/gsoc2023/ne_110m_admin_0_countries.json"); } // initialize rendering of DUPLICATE VERTICES From 1db9651e6f06b2f28a624e896e4d1692adad239a Mon Sep 17 00:00:00 2001 From: denizdiktas Date: Tue, 1 Aug 2023 15:10:20 +0300 Subject: [PATCH 2/2] not skipping the spherical face --- Arrangement_on_surface_2/demo/earth/Aos.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Arrangement_on_surface_2/demo/earth/Aos.cpp b/Arrangement_on_surface_2/demo/earth/Aos.cpp index ccdae2f58b3..c047e5f8b8e 100644 --- a/Arrangement_on_surface_2/demo/earth/Aos.cpp +++ b/Arrangement_on_surface_2/demo/earth/Aos.cpp @@ -1095,9 +1095,9 @@ void Aos::save_arr(Kml::Placemarks& placemarks, const std::string& file_name) int total_num_half_edges = 0; for (auto fh = arr.faces_begin(); fh != arr.faces_end(); ++fh) { - // skip the spherical face - if (fh->number_of_outer_ccbs() == 0) - continue; + //// skip the spherical face + //if (fh->number_of_outer_ccbs() == 0) + // continue; // json object for the current face json js_face;