Skip to content

Commit

Permalink
Moved arc construction into Aos as static (make it non-static member …
Browse files Browse the repository at this point in the history
…function?)
  • Loading branch information
denizdiktas committed Jul 4, 2023
1 parent 1c934d7 commit 434c219
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 8 deletions.
99 changes: 99 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Aos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,105 @@ namespace {
}


Aos::Approx_arcs Aos::get_approx_arcs(double error)
{
// Construct the arrangement from 12 geodesic arcs.
Geom_traits traits;
Arrangement arr(&traits);

auto ctr_p = traits.construct_point_2_object();
auto ctr_cv = traits.construct_curve_2_object();


std::vector<Curve> xcvs;
xcvs.push_back(ctr_cv(ctr_p(1, 0, 0), ctr_p(0, 1, 0)));
xcvs.push_back(ctr_cv(ctr_p(1, 0, 0), ctr_p(0, 0, 1)));
xcvs.push_back(ctr_cv(ctr_p(0, 1, 0), ctr_p(0, 0, 1)));
//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 = traits.approximate_2_object();


std::vector<std::vector<QVector3D>> arcs;
for (const auto& xcv : xcvs)
{
std::vector<Approximate_point_2> v;
auto oi2 = approx(xcv, error, std::back_insert_iterator(v));

std::vector<QVector3D> 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 arcs;
}

Aos::Approx_arcs Aos::get_approx_arcs(const Kml::Placemark& placemark, double error)
{
Geom_traits traits;
auto ctr_p = traits.construct_point_2_object();
auto ctr_cv = traits.construct_curve_2_object();

std::vector<Curve> xcvs;
for (const auto& polygon : placemark.polygons)
{
// colect all rings into a single list (FOR NOW!!!)
// TO-DO: PROCESS OUTER & INNER BOUNDARIES SEPARATELY!!!
Kml::LinearRings linear_rings;
linear_rings.push_back(polygon.outer_boundary);
for (const auto& inner_boundary : polygon.inner_boundaries)
linear_rings.push_back(inner_boundary);


// convert the nodes to points on unit-sphere
for (const auto& lring : linear_rings)
{
std::vector<Approximate_Vector_3> sphere_points;
for (const auto& node : lring.nodes)
{
const auto p = node.get_coords_3d();
Approximate_Vector_3 v(p.x, p.y, p.z);
sphere_points.push_back(v);
}

// add geodesic arcs for the current LinearRing
int num_points = sphere_points.size();
for (int i = 0; i < num_points - 1; i++)
{
const auto p1 = sphere_points[i];
const auto p2 = sphere_points[i + 1];
xcvs.push_back(ctr_cv(ctr_p(p1.x(), p1.y(), p1.z()),
ctr_p(p2.x(), p2.y(), p2.z())));
}
}
}

auto approx = traits.approximate_2_object();
std::vector<std::vector<QVector3D>> arcs;
for (const auto& xcv : xcvs)
{
std::vector<Approximate_point_2> v;
auto oi2 = approx(xcv, error, std::back_insert_iterator(v));

std::vector<QVector3D> 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 arcs;
}

void Aos::check(const Kml::Placemarks& placemarks)
{
// Construct the arrangement from 12 geodesic arcs.
Expand Down
10 changes: 10 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Aos.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
class Aos
{
public:
using Approx_arcs = std::vector<std::vector<QVector3D>>;

// this constructs some sample arcs manually (used to check the visual output)
static Approx_arcs get_approx_arcs(double error);

// this is used to construct approximate arcs from KML-Placemark data
static Approx_arcs get_approx_arcs(const Kml::Placemark& placemark, double error);


static void get_curves();

static void check(const Kml::Placemarks& placemarks);

Expand Down
16 changes: 8 additions & 8 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "Aos.h"
#include "Kml_reader.h"
#include "Geodesic_arcs.h"
//#include "Geodesic_arcs.h"
#include "Tools.h"


Expand Down Expand Up @@ -196,7 +196,7 @@ void Main_widget::initializeGL()
auto dup_nodes = Kml::get_duplicates(countries);

// initialize rendering of DUPLICATE VERTICES
if(0)
if(1)
{
std::vector<QVector3D> vertices;
for (const auto& node : dup_nodes)
Expand All @@ -222,15 +222,15 @@ void Main_widget::initializeGL()
// 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;
//Geodesic_arcs ga;
const double error = 0.001; // calculate this from cam parameters!
//auto lsa = ga.get_approx_arcs(countries, error);
//auto lsa = ga.get_approx_arcs(error);
// m_geodesic_arcs = std::make_unique<Line_strips>(lsa);
//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 : countries)
{
m_country_names.push_back(country.name);
auto approx_arcs = ga.get_approx_arcs(country, error);
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));
}
Expand Down Expand Up @@ -466,7 +466,7 @@ void Main_widget::paintGL()
const QVector4D vertex_color(1, 0, 0, 1);
sp.set_uniform("u_color", vertex_color);
glPointSize(5);
m_vertices->draw();
//m_vertices->draw();

sp.unuse();
}
Expand Down

0 comments on commit 434c219

Please sign in to comment.