mirror of https://github.com/CGAL/cgal
corrections for saving the json file
This commit is contained in:
parent
ddaa233443
commit
1995b8b61f
|
|
@ -11,6 +11,7 @@
|
||||||
#include <qvector3d.h>
|
#include <qvector3d.h>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
using json = nlohmann::ordered_json;
|
||||||
|
|
||||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||||
|
|
@ -24,7 +25,14 @@
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
//#define USE_EPIC
|
||||||
|
|
||||||
|
#ifdef USE_EPIC
|
||||||
|
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
|
||||||
|
#else
|
||||||
using Kernel = CGAL::Exact_predicates_exact_constructions_kernel;
|
using Kernel = CGAL::Exact_predicates_exact_constructions_kernel;
|
||||||
|
#endif
|
||||||
|
|
||||||
using Geom_traits = CGAL::Arr_geodesic_arc_on_sphere_traits_2<Kernel>;
|
using Geom_traits = CGAL::Arr_geodesic_arc_on_sphere_traits_2<Kernel>;
|
||||||
using Point = Geom_traits::Point_2;
|
using Point = Geom_traits::Point_2;
|
||||||
using Curve = Geom_traits::Curve_2;
|
using Curve = Geom_traits::Curve_2;
|
||||||
|
|
@ -328,7 +336,7 @@ void Aos::check(const Kml::Placemarks& placemarks)
|
||||||
arr.number_of_vertices() << std::endl;
|
arr.number_of_vertices() << std::endl;
|
||||||
// add arcs
|
// add arcs
|
||||||
for(auto xcv : xcvs)
|
for(auto xcv : xcvs)
|
||||||
CGAL::insert_curve(arr, xcv);
|
CGAL::insert(arr, xcv);
|
||||||
|
|
||||||
std::cout << "-------------------------------\n";
|
std::cout << "-------------------------------\n";
|
||||||
std::cout << "num nodes = " << num_counted_nodes << std::endl;
|
std::cout << "num nodes = " << num_counted_nodes << std::endl;
|
||||||
|
|
@ -367,7 +375,7 @@ std::vector<QVector3D> Aos::ext_check(const Kml::Placemarks& placemarks)
|
||||||
|
|
||||||
// add arcs
|
// add arcs
|
||||||
for (auto& xcv : xcvs)
|
for (auto& xcv : xcvs)
|
||||||
CGAL::insert_curve(arr, xcv);
|
CGAL::insert(arr, xcv);
|
||||||
|
|
||||||
// extract all vertices that are ADDED when inserting the arcs!
|
// extract all vertices that are ADDED when inserting the arcs!
|
||||||
int num_created_vertices = 0;
|
int num_created_vertices = 0;
|
||||||
|
|
@ -825,8 +833,6 @@ void Aos::save_arr(Kml::Placemarks& placemarks, const std::string& file_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEFINE JSON OBJECT
|
// DEFINE JSON OBJECT
|
||||||
//using json = nlohmann::json;
|
|
||||||
using json = nlohmann::ordered_json;
|
|
||||||
json js;
|
json js;
|
||||||
auto& js_points = js["points"] = json::array();
|
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();
|
auto dz = p.dz().exact();
|
||||||
|
|
||||||
json jv;
|
json jv;
|
||||||
jv["location"] = std::to_string(p.location());
|
jv["location"] = p.location();
|
||||||
set_num_denum(dx, jv["dx"]);
|
set_num_denum(dx, jv["dx"]);
|
||||||
set_num_denum(dy, jv["dy"]);
|
set_num_denum(dy, jv["dy"]);
|
||||||
set_num_denum(dz, jv["dz"]);
|
set_num_denum(dz, jv["dz"]);
|
||||||
|
|
@ -905,9 +911,8 @@ void Aos::save_arr(Kml::Placemarks& placemarks, const std::string& file_name)
|
||||||
json je;
|
json je;
|
||||||
auto svp = vertex_pos_map[eh->source()];
|
auto svp = vertex_pos_map[eh->source()];
|
||||||
auto tvp = vertex_pos_map[eh->target()];
|
auto tvp = vertex_pos_map[eh->target()];
|
||||||
je["source"] = std::to_string(svp);
|
je["source"] = svp;
|
||||||
je["target"] = std::to_string(tvp);
|
je["target"] = tvp;
|
||||||
je["location"] = "";
|
|
||||||
auto& je_normal = je["normal"];
|
auto& je_normal = je["normal"];
|
||||||
|
|
||||||
// write the vertex-data to JSON object
|
// 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 << js.dump(2);
|
||||||
ofile.close();
|
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<Point> points;
|
||||||
|
auto get_double_from_json = [&](json& js_val)
|
||||||
|
{
|
||||||
|
auto num = js_val["num"].get<std::string>();
|
||||||
|
auto den = js_val["den"].get<std::string>();
|
||||||
|
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<int>();
|
||||||
|
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<Point::Location_type>(loc));
|
||||||
|
points.push_back(p);
|
||||||
|
}
|
||||||
|
std::cout << "num points = " << points.size() << std::endl;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CURVES
|
||||||
|
std::vector<Curve> curves;
|
||||||
|
auto& js_curves = js["curves"];
|
||||||
|
for (auto it = js_curves.begin(); it != js_curves.end(); ++it)
|
||||||
|
{
|
||||||
|
auto& js_curve = *it;
|
||||||
|
//js_curve[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -50,6 +50,9 @@ public:
|
||||||
// save the arrangement created with EPEC
|
// save the arrangement created with EPEC
|
||||||
static void save_arr(Kml::Placemarks& placemarks,
|
static void save_arr(Kml::Placemarks& placemarks,
|
||||||
const std::string& file_name);
|
const std::string& file_name);
|
||||||
|
|
||||||
|
// save the arrangement created with EPEC
|
||||||
|
static Approx_arcs load_arr(const std::string& file_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,40 +159,8 @@ void Main_widget::init_problematic_nodes()
|
||||||
|
|
||||||
std::unique_ptr<Line_strips> new_faces;
|
std::unique_ptr<Line_strips> new_faces;
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
using json = nlohmann::ordered_json;
|
|
||||||
|
|
||||||
void Main_widget::initializeGL()
|
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 that the node (180.0, -84.71338) in Antarctica is redundant
|
||||||
verify_antarctica_node_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::save_arr(m_countries, "C:/work/gsoc2023/deneme.json");
|
||||||
|
//Aos::load_arr("C:/work/gsoc2023/deneme.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize rendering of DUPLICATE VERTICES
|
// initialize rendering of DUPLICATE VERTICES
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue