Skip to content

Commit

Permalink
modified the arr-saving function
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Aug 1, 2023
1 parent 47df8a8 commit 16863d7
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 39 deletions.
98 changes: 65 additions & 33 deletions Arrangement_on_surface_2/demo/earth/Aos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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_handle, int> 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;


////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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::string>() << std::endl;
Expand Down
10 changes: 10 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Kml_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Kml_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class Kml
};
using Placemarks = std::vector<Placemark>;

static int get_number_of_polygons(Placemarks& placemarks);


static Placemarks read(const std::string& file_name);

Expand Down
13 changes: 7 additions & 6 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ std::unique_ptr<Line_strips> 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();

Expand All @@ -173,21 +173,22 @@ 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);
new_faces = std::make_unique<Line_strips>(created_faces);
}

{
//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
Expand Down

0 comments on commit 16863d7

Please sign in to comment.