From 92c6c1794f6009f570de1d7b2079e5276973261d Mon Sep 17 00:00:00 2001 From: denizdiktas Date: Fri, 14 Jul 2023 12:30:46 +0300 Subject: [PATCH] Added: Timer class to time the computation of the approximation of country borders --- .../demo/earth/CMakeLists.txt | 1 + .../demo/earth/Main_widget.cpp | 55 +++++++++++-------- .../demo/earth/Main_widget.h | 2 + Arrangement_on_surface_2/demo/earth/Timer.h | 55 +++++++++++++++++++ 4 files changed, 90 insertions(+), 23 deletions(-) create mode 100644 Arrangement_on_surface_2/demo/earth/Timer.h diff --git a/Arrangement_on_surface_2/demo/earth/CMakeLists.txt b/Arrangement_on_surface_2/demo/earth/CMakeLists.txt index a0ddf25d894..839ae6a3f0b 100644 --- a/Arrangement_on_surface_2/demo/earth/CMakeLists.txt +++ b/Arrangement_on_surface_2/demo/earth/CMakeLists.txt @@ -91,6 +91,7 @@ file(GLOB source_files Common_defs.h main.cpp Main_widget.h Main_widget.cpp + Timer.h Tools.h Tools.cpp ) source_group( "Source Files" FILES ${source_files} ) diff --git a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp index 0bb5bf07bf1..6539c65c314 100644 --- a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp +++ b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp @@ -13,6 +13,7 @@ #include "Camera_manip_zoom.h" #include "Kml_reader.h" #include "Shapefile.h" +#include "Timer.h" #include "Tools.h" @@ -144,6 +145,8 @@ void Main_widget::init_problematic_nodes() m_problematic_vertices = std::make_unique(prob_vertices); } + + void Main_widget::initializeGL() { // verify that the node (180.0, -84.71338) in Antarctica is redundant @@ -158,8 +161,8 @@ 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); @@ -190,27 +193,8 @@ void Main_widget::initializeGL() init_shader_programs(); { - // 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! - //Geodesic_arcs ga; - const double error = 0.001; // calculate this from cam parameters! - //auto lsa = Aos::get_approx_arcs(countries, error); - //auto lsa = Aos::get_approx_arcs(error); - //m_geodesic_arcs = std::make_unique(lsa); - for (const auto& country : m_countries) - { - m_country_names.push_back(country.name); - auto approx_arcs = Aos::get_approx_arcs(country, error); - auto country_border = std::make_unique(approx_arcs); - m_country_borders.push_back(std::move(country_border)); - } - m_selected_country_index = 0; - //m_selected_country_index = 159; // ANTARCTICA - m_selected_country = &m_countries[m_selected_country_index]; - m_selected_country_nodes = m_selected_country->get_all_nodes(); - m_selected_country_arcs = m_selected_country->get_all_arcs(); - m_selected_arc_index = 0; + ScopedTimer("init_country_borders"); + init_country_borders(); } glClearColor(0, 0, 0, 1); @@ -255,6 +239,31 @@ void Main_widget::init_shader_programs() m_sp_arc.init_with_vs_fs("arc"); } +void Main_widget::init_country_borders() +{ + // 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! + //Geodesic_arcs ga; + const double error = 0.001; // calculate this from cam parameters! + //auto lsa = Aos::get_approx_arcs(countries, error); + //auto lsa = Aos::get_approx_arcs(error); + //m_geodesic_arcs = std::make_unique(lsa); + for (const auto& country : m_countries) + { + m_country_names.push_back(country.name); + auto approx_arcs = Aos::get_approx_arcs(country, error); + auto country_border = std::make_unique(approx_arcs); + m_country_borders.push_back(std::move(country_border)); + } + m_selected_country_index = 0; + //m_selected_country_index = 159; // ANTARCTICA + m_selected_country = &m_countries[m_selected_country_index]; + m_selected_country_nodes = m_selected_country->get_all_nodes(); + m_selected_country_arcs = m_selected_country->get_all_arcs(); + m_selected_arc_index = 0; +} + float Main_widget::compute_backprojected_error(float pixel_error) { // compute the back-projected error diff --git a/Arrangement_on_surface_2/demo/earth/Main_widget.h b/Arrangement_on_surface_2/demo/earth/Main_widget.h index 7697e07bfc8..eac03e86cd0 100644 --- a/Arrangement_on_surface_2/demo/earth/Main_widget.h +++ b/Arrangement_on_surface_2/demo/earth/Main_widget.h @@ -49,6 +49,8 @@ class Main_widget : public QOpenGLWidget, protected OpenGLFunctionsBase void init_camera(); void init_geometry(); void init_shader_programs(); + + void init_country_borders(); float compute_backprojected_error(float pixel_error); diff --git a/Arrangement_on_surface_2/demo/earth/Timer.h b/Arrangement_on_surface_2/demo/earth/Timer.h new file mode 100644 index 00000000000..d1f5e29693d --- /dev/null +++ b/Arrangement_on_surface_2/demo/earth/Timer.h @@ -0,0 +1,55 @@ + +#ifndef TIMER_H +#define TIMER_H + +#include +#include +#include + + +class Timer +{ +public: + Timer() + { + reset(); + } + + void reset() + { + m_Start = std::chrono::high_resolution_clock::now(); + } + + float elapsed() + { + return std::chrono::duration_cast( + std::chrono::high_resolution_clock::now() - m_Start).count() + * 0.001f * 0.001f * 0.001f; + } + + float elapsed_millis() + { + return elapsed() * 1000.0f; + } + +private: + std::chrono::time_point m_Start; +}; + +class ScopedTimer +{ +public: + ScopedTimer(const std::string& name) + : m_Name(name) {} + ~ScopedTimer() + { + float time = m_Timer.elapsed_millis(); + std::cout << "[TIMER] " << m_Name << " - " << time << "ms\n"; + } +private: + std::string m_Name; + Timer m_Timer; +}; + + +#endif