From 1995b8b61f4efece38918a71dc4e9a5a95f32bbb Mon Sep 17 00:00:00 2001 From: denizdiktas Date: Fri, 28 Jul 2023 13:24:42 +0300 Subject: [PATCH] corrections for saving the json file --- Arrangement_on_surface_2/demo/earth/Aos.cpp | 67 ++++++++++++++++--- Arrangement_on_surface_2/demo/earth/Aos.h | 3 + .../demo/earth/Main_widget.cpp | 33 +-------- 3 files changed, 63 insertions(+), 40 deletions(-) diff --git a/Arrangement_on_surface_2/demo/earth/Aos.cpp b/Arrangement_on_surface_2/demo/earth/Aos.cpp index ae2f9caee40..e58edc4b9e2 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 +using json = nlohmann::ordered_json; #include #include @@ -24,7 +25,14 @@ #include "Tools.h" namespace { +//#define USE_EPIC + +#ifdef USE_EPIC + using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; +#else using Kernel = CGAL::Exact_predicates_exact_constructions_kernel; +#endif + using Geom_traits = CGAL::Arr_geodesic_arc_on_sphere_traits_2; using Point = Geom_traits::Point_2; using Curve = Geom_traits::Curve_2; @@ -328,7 +336,7 @@ void Aos::check(const Kml::Placemarks& placemarks) arr.number_of_vertices() << std::endl; // add arcs for(auto xcv : xcvs) - CGAL::insert_curve(arr, xcv); + CGAL::insert(arr, xcv); std::cout << "-------------------------------\n"; std::cout << "num nodes = " << num_counted_nodes << std::endl; @@ -367,7 +375,7 @@ std::vector Aos::ext_check(const Kml::Placemarks& placemarks) // add arcs for (auto& xcv : xcvs) - CGAL::insert_curve(arr, xcv); + CGAL::insert(arr, xcv); // extract all vertices that are ADDED when inserting the arcs! int num_created_vertices = 0; @@ -825,8 +833,6 @@ void Aos::save_arr(Kml::Placemarks& placemarks, const std::string& file_name) } // DEFINE JSON OBJECT - //using json = nlohmann::json; - using json = nlohmann::ordered_json; json js; auto& js_points = js["points"] = json::array(); @@ -876,7 +882,7 @@ void Aos::save_arr(Kml::Placemarks& placemarks, const std::string& file_name) auto dz = p.dz().exact(); json jv; - jv["location"] = std::to_string(p.location()); + jv["location"] = p.location(); set_num_denum(dx, jv["dx"]); set_num_denum(dy, jv["dy"]); set_num_denum(dz, jv["dz"]); @@ -905,9 +911,8 @@ void Aos::save_arr(Kml::Placemarks& placemarks, const std::string& file_name) json je; auto svp = vertex_pos_map[eh->source()]; auto tvp = vertex_pos_map[eh->target()]; - je["source"] = std::to_string(svp); - je["target"] = std::to_string(tvp); - je["location"] = ""; + je["source"] = svp; + je["target"] = tvp; auto& je_normal = je["normal"]; // write the vertex-data to JSON object @@ -1095,3 +1100,49 @@ void Aos::save_arr(Kml::Placemarks& placemarks, const std::string& file_name) ofile << js.dump(2); ofile.close(); } + + +Aos::Approx_arcs Aos::load_arr(const std::string& file_name) +{ + auto js_txt = read_file(file_name); + auto js = json::parse(js_txt.begin(), js_txt.end()); + + Geom_traits traits; + Ext_aos arr(&traits); + auto ctr_p = traits.construct_point_2_object(); + auto ctr_cv = traits.construct_curve_2_object(); + + //////////////////////////////////////////////////////////////////////////// + // POINTS + std::vector points; + auto get_double_from_json = [&](json& js_val) + { + auto num = js_val["num"].get(); + auto den = js_val["den"].get(); + CGAL::Gmpq rat_x(num, den); + return CGAL::to_double(rat_x); + }; + auto& js_points = js["points"]; + for (auto it = js_points.begin(); it != js_points.end(); ++it) + { + auto& js_point = *it; + auto loc = js_point["location"].get(); + auto dx = get_double_from_json(js_point["dx"]); + auto dy = get_double_from_json(js_point["dy"]); + auto dz = get_double_from_json(js_point["dz"]); + auto p = ctr_p(dx, dy, dz); + p.set_location(static_cast(loc)); + points.push_back(p); + } + std::cout << "num points = " << points.size() << std::endl; + + //////////////////////////////////////////////////////////////////////////// + // CURVES + std::vector curves; + auto& js_curves = js["curves"]; + for (auto it = js_curves.begin(); it != js_curves.end(); ++it) + { + auto& js_curve = *it; + //js_curve[] + } +} \ No newline at end of file diff --git a/Arrangement_on_surface_2/demo/earth/Aos.h b/Arrangement_on_surface_2/demo/earth/Aos.h index a12140de954..6f588abe898 100644 --- a/Arrangement_on_surface_2/demo/earth/Aos.h +++ b/Arrangement_on_surface_2/demo/earth/Aos.h @@ -50,6 +50,9 @@ public: // save the arrangement created with EPEC static void save_arr(Kml::Placemarks& placemarks, const std::string& file_name); + + // save the arrangement created with EPEC + static Approx_arcs load_arr(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 29425a57ce3..2ff7d9fc3ea 100644 --- a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp +++ b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp @@ -159,40 +159,8 @@ void Main_widget::init_problematic_nodes() std::unique_ptr new_faces; -#include -using json = nlohmann::ordered_json; - void Main_widget::initializeGL() { - json js; - auto& ja = js["vertices"] = json::array(); - json json_v1 = R"( - { - "location": "0", - "dx": {"num": "123","den": "1"}, - "dy": {"num": "456","den": "5"}, - "dz": {"num": "789","den": "9"} - } - )"_json; - json json_v2 = R"( - { - "location": "0", - "dx": {"num": "111","den": "2"}, - "dy": {"num": "333","den": "4"}, - "dz": {"num": "555","den": "6"} - } - )"_json; - json jv2; - jv2["location"] = "0"; - jv2["dx"]["num"] = "111"; jv2["dx"]["den"] = "2"; - jv2["dy"]["num"] = "333"; jv2["dy"]["den"] = "4"; - jv2["dz"]["num"] = "555"; jv2["dz"]["den"] = "6"; - - ja.push_back(json_v1); - ja.push_back(std::move(jv2)); - ja.size(); - std::cout << js << std::endl; - // verify that the node (180.0, -84.71338) in Antarctica is redundant verify_antarctica_node_is_redundant(); @@ -219,6 +187,7 @@ void Main_widget::initializeGL() { Aos::save_arr(m_countries, "C:/work/gsoc2023/deneme.json"); + //Aos::load_arr("C:/work/gsoc2023/deneme.json"); } // initialize rendering of DUPLICATE VERTICES