Skip to content

Commit

Permalink
Added: Timer class to time the computation of the approximation of co…
Browse files Browse the repository at this point in the history
…untry borders
  • Loading branch information
denizdiktas committed Jul 14, 2023
1 parent f7b1d16 commit 92c6c17
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 23 deletions.
1 change: 1 addition & 0 deletions Arrangement_on_surface_2/demo/earth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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} )
Expand Down
55 changes: 32 additions & 23 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Camera_manip_zoom.h"
#include "Kml_reader.h"
#include "Shapefile.h"
#include "Timer.h"
#include "Tools.h"


Expand Down Expand Up @@ -144,6 +145,8 @@ void Main_widget::init_problematic_nodes()
m_problematic_vertices = std::make_unique<Vertices>(prob_vertices);
}



void Main_widget::initializeGL()
{
// verify that the node (180.0, -84.71338) in Antarctica is redundant
Expand All @@ -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);
Expand Down Expand Up @@ -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<Line_strips>(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<Line_strips>(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);
Expand Down Expand Up @@ -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<Line_strips>(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<Line_strips>(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
Expand Down
2 changes: 2 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Main_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
55 changes: 55 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

#ifndef TIMER_H
#define TIMER_H

#include <chrono>
#include <iostream>
#include <string>


class Timer
{
public:
Timer()
{
reset();
}

void reset()
{
m_Start = std::chrono::high_resolution_clock::now();
}

float elapsed()
{
return std::chrono::duration_cast<std::chrono::nanoseconds>(
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<std::chrono::high_resolution_clock> 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

0 comments on commit 92c6c17

Please sign in to comment.