From 0a10e28440b32747c5219a9b458a474a75b1d1e0 Mon Sep 17 00:00:00 2001 From: denizdiktas Date: Thu, 17 Aug 2023 21:18:17 +0300 Subject: [PATCH] the outlines of the faces are drawn from the arrangement data itself now (no KML needed) --- Arrangement_on_surface_2/demo/earth/Aos.cpp | 44 +++++++------------ Arrangement_on_surface_2/demo/earth/Aos.h | 5 +++ .../demo/earth/Main_widget.cpp | 21 ++++++--- .../demo/earth/Main_widget.h | 1 + 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/Arrangement_on_surface_2/demo/earth/Aos.cpp b/Arrangement_on_surface_2/demo/earth/Aos.cpp index f38e7b9ae06..2e8a3dc2670 100644 --- a/Arrangement_on_surface_2/demo/earth/Aos.cpp +++ b/Arrangement_on_surface_2/demo/earth/Aos.cpp @@ -297,9 +297,6 @@ Aos::Approx_arc Aos::get_approx_identification_curve(double error) Aos::Approx_arcs Aos::get_approx_arcs(double error) { - //Geom_traits traits; - Arrangement arr(&s_traits); - auto ctr_p = s_traits.construct_point_2_object(); auto ctr_cv = s_traits.construct_curve_2_object(); @@ -310,36 +307,13 @@ Aos::Approx_arcs Aos::get_approx_arcs(double error) //xcvs.push_back(ctr_cv(ctr_p(1, 0, 0), ctr_p(0, 1, 0), Dir3(0, 0, -1))); //xcvs.push_back(ctr_cv(Dir3(0, 0, -1))); - auto approx = s_traits.approximate_2_object(); - auto approx_arcs = get_approx_curves(xcvs, error); - //std::vector> arcs; - //for (const auto& xcv : xcvs) - //{ - // std::vector v; - // auto oi2 = approx(xcv, error, std::back_insert_iterator(v)); - // - // std::vector arc_points; - // for (const auto& p : v) - // { - // const QVector3D arc_point(p.dx(), p.dy(), p.dz()); - // arc_points.push_back(arc_point); - // } - // arcs.push_back(std::move(arc_points)); - //} - //std::cout << "offset count = " << m_arc_offsets.size() << std::endl; - return approx_arcs; } Aos::Approx_arcs Aos::get_approx_arcs(const Kml::Placemark& placemark, double error) { - //Geom_traits traits; - auto ctr_p = s_traits.construct_point_2_object(); - auto ctr_cv = s_traits.construct_curve_2_object(); - auto xcvs = get_arcs(placemark); auto arcs = ::get_approx_curves(xcvs, error); - return arcs; } @@ -1936,4 +1910,20 @@ std::string Aos::locate_country(Arr_handle arrh, const QVector3D& point) //else CGAL_error_msg("Invalid object."); return ""; -} \ No newline at end of file +} + +Aos::Approx_arcs Aos::get_approx_arcs_from_faces_edges(Arr_handle arrh, + float error) +{ + auto& arr = *reinterpret_cast(arrh.get()); + auto ctr_cv = s_traits.construct_curve_2_object(); + Curves xcvs; + for (auto eit = arr.halfedges_begin(); eit != arr.halfedges_end(); ++eit) + { + auto& s = eit->curve(); + xcvs.push_back( ctr_cv(s.source(), s.target()) ); + } + + auto arcs = ::get_approx_curves(xcvs, error); + return arcs; +} diff --git a/Arrangement_on_surface_2/demo/earth/Aos.h b/Arrangement_on_surface_2/demo/earth/Aos.h index 8a0bd6fb253..bf2d159c47d 100644 --- a/Arrangement_on_surface_2/demo/earth/Aos.h +++ b/Arrangement_on_surface_2/demo/earth/Aos.h @@ -76,6 +76,11 @@ class Aos static Country_color_map get_color_mapping(Arr_handle arrh); static std::string locate_country(Arr_handle arrh, const QVector3D& point); + + // this will get the approximate arcs of face-edges from the arrangement + // NOTE: this is similar to "get_approx_arcs(KML::Placemarks&, float)" above! + static Approx_arcs get_approx_arcs_from_faces_edges(Arr_handle arrh, + float error); }; diff --git a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp index e6444c0cec3..39def9d6177 100644 --- a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp +++ b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp @@ -277,9 +277,9 @@ 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.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_equatorial_guinea.kml"; + const auto file_name = data_path + "ne_110m_admin_0_countries_equatorial_guinea.kml"; m_countries = Kml::read(file_name); // find the country with the least number of nodes @@ -326,7 +326,7 @@ void Main_widget::initializeGL() // triangulation { - qDebug() << "constructiong arr.."; + qDebug() << "loading arr.."; //auto arrh = Aos::construct(m_countries); m_arrh = Aos::load_arr("C:/work/gsoc2023/ne_110m_admin_0_countries.json"); if (m_arrh == nullptr) @@ -456,6 +456,16 @@ void Main_widget::init_shader_programs() void Main_widget::init_country_borders(float error) { + // this part does the same as the code below but using arrangement! + // NOTE: the old code interferes with some logic (NEEDS REFACTORING!!!) + { + m_country_borders.clear(); + qDebug() << "approximating the arcs of each edge of all faces.."; + auto all_approx_arcs = Aos::get_approx_arcs_from_faces_edges(m_arrh, error); + m_gr_all_approx_arcs = std::make_unique(all_approx_arcs); + return; + } + // TO-DO: move this code to resizeGL (when viewport is initialized) // has to be defined after camera has been defined: // because we want to compute the error based on camera parameters! @@ -637,8 +647,9 @@ void Main_widget::paintGL() // draw all countries float a = 0.0; sp.set_uniform("u_color", QVector4D(a, a, a, 1)); - for(auto& country_border : m_country_borders) - country_border->draw(); + //for(auto& country_border : m_country_borders) + // country_border->draw(); + m_gr_all_approx_arcs->draw(); //// draw the SELECTED COUNTRY in BLUE //auto& selected_country = m_country_borders[m_selected_country_index]; diff --git a/Arrangement_on_surface_2/demo/earth/Main_widget.h b/Arrangement_on_surface_2/demo/earth/Main_widget.h index 781b4b9a4da..86cf1eadec9 100644 --- a/Arrangement_on_surface_2/demo/earth/Main_widget.h +++ b/Arrangement_on_surface_2/demo/earth/Main_widget.h @@ -88,6 +88,7 @@ class Main_widget : public QOpenGLWidget, protected OpenGLFunctionsBase private: // ARRANGEMENT Aos::Arr_handle m_arrh; + std::unique_ptr m_gr_all_approx_arcs; // GUI: event handler for picking with right mouse button std::unique_ptr m_pick_handler;