Skip to content

Commit

Permalink
Added: code to check for problematic nodes in Africa region and verif…
Browse files Browse the repository at this point in the history
…y the redundant node in Antarctica
  • Loading branch information
denizdiktas committed Jul 11, 2023
1 parent 824d989 commit 2d2174d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 12 deletions.
32 changes: 25 additions & 7 deletions Arrangement_on_surface_2/demo/earth/Aos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <vector>

#include <qmath.h>
Expand Down Expand Up @@ -131,6 +133,8 @@ namespace {
int num_counted_nodes = 0;
int num_counted_arcs = 0;
int num_counted_polygons = 0;
std::map<Ext_aos::Vertex_handle, Kml::Node> vertex_node_map;

template<typename Arr_type>
Curves get_arcs(const Kml::Placemarks& placemarks, Arr_type& arr)
{
Expand Down Expand Up @@ -166,7 +170,11 @@ namespace {
const auto p = node.get_coords_3d();
Approximate_Vector_3 v(p.x, p.y, p.z);
sphere_points.push_back(v);
CGAL::insert_point(arr, ctr_p(p.x, p.y, p.z));
auto vh = CGAL::insert_point(arr, ctr_p(p.x, p.y, p.z));
if constexpr (std::is_same<Arr_type, Ext_aos>::value)
{
vertex_node_map.insert(std::make_pair(vh, node));
}
}

// add curves
Expand Down Expand Up @@ -359,12 +367,22 @@ std::vector<QVector3D> Aos::ext_check(const Kml::Placemarks& placemarks)

created_vertices.push_back(new_vertex);

// find the arcs that are adjacent to this vertex
const auto first = vit->incident_halfedges();
auto curr = first;
do {

} while (++curr != first);
// find the arcs that are adjacent to the vertex of degree 4
if(4 == vit->degree())
{
std::cout << "**************************\n DEGREE 4 VERTEX: \n";
const auto first = vit->incident_halfedges();
auto curr = first;
do {
auto tvh = curr->twin()->target();
//std::cout << std::boolalpha << svh->data().v << " - " << tvh->data().v << std::endl;
auto it = vertex_node_map.find(tvh);
if (it != vertex_node_map.end())
std::cout << std::setprecision(16) << it->second << std::endl;
else
std::cout << "NOT FOUND!!\n";
} while (++curr != first);
}

std::cout << "\n";
}
Expand Down
54 changes: 50 additions & 4 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void Main_widget::mouseMoveEvent(QMouseEvent* e)
}
else if(m_middle_mouse_button_down)
{
const float zoom_scale_factor = 0.01f;
const float zoom_scale_factor = 0.001f;
const auto distance = zoom_scale_factor * diff.y();
m_camera.move_forward(distance);
}
Expand Down Expand Up @@ -206,10 +206,36 @@ void readShapefile(const std::string& filename) {

void Main_widget::initializeGL()
{
// verify that the node (180.0, -84.71338) in Antarctica is redundant
{
Kml::Node n1(178.277211542064, -84.4725179992025),
n2(180.0, -84.71338),
n3(-179.942499356179, -84.7214433735525);

// 1) check if it is collinear with its neighboring nodes:
// all of the vectors in 3D must lie in the same plane
auto v1 = n1.get_coords_3f();
auto v2 = n2.get_coords_3f();
auto v3 = n3.get_coords_3f();
auto n = QVector3D::crossProduct(v1, v3);
n.normalize();
std::cout << "*** DOT PRODUCT = " << QVector3D::dotProduct(n, v2) << std::endl;

// 2) check if it is between its neighbors (check if r,s > 0)
auto det = [](float ax, float ay, float bx, float by) { return ax * by - ay * bx; };
auto D = det(v1.x(), v1.y(), v3.x(), v3.y());
auto Dr = det(v2.x(), v2.y(), v3.x(), v3.y());
auto Ds = det(v1.x(), v1.y(), v2.x(), v2.y());
auto r = Dr / D;
auto s = Ds / D;
std::cout << "r = " << r << "\ns=" << s << std::endl;
}

//readShapefile("C:/work/gsoc2023/data/ne_110m_admin_0_countries/ne_110m_admin_0_countries.shp");

//const auto file_name = "C:/work/gsoc2023/data/world_countries.kml";
const auto file_name = "C:/work/gsoc2023/data/ne_110m_admin_0_countries.kml";
//const auto file_name = "C:/work/gsoc2023/data/ne_110m_admin_0_countries.kml";
const auto file_name = "C:/work/gsoc2023/data/ne_110m_admin_0_countries_africa.kml";
m_countries = Kml::read(file_name);
auto dup_nodes = Kml::get_duplicates(m_countries);

Expand All @@ -233,6 +259,20 @@ void Main_widget::initializeGL()
m_vertices = std::make_unique<Vertices>(created_vertices);
}

// init problematic vertices: these are the vertices incident to deg-4 vertex
{
Kml::Nodes prob_nodes = {
{23.8058134294668,8.66631887454253},
{24.1940677211877,8.7286964724039 },
{24.5673690121521,8.22918793378547},
{23.8869795808607,8.61972971293307}
};
std::vector<QVector3D> prob_vertices;
for (const auto& node : prob_nodes)
prob_vertices.push_back(node.get_coords_3f());
m_problematic_vertices = std::make_unique<Vertices>(prob_vertices);
}


initializeOpenGLFunctions();

Expand All @@ -256,7 +296,8 @@ void Main_widget::initializeGL()
auto country_border = std::make_unique<Line_strips>(approx_arcs);
m_country_borders.push_back(std::move(country_border));
}
m_selected_country_index = 159; // ANTARCTICA
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();
Expand Down Expand Up @@ -505,9 +546,14 @@ void Main_widget::paintGL()

const QVector4D vertex_color(1, 0, 0, 1);
sp.set_uniform("u_color", vertex_color);
glPointSize(5);
glPointSize(3);
m_vertices->draw();

sp.set_uniform("u_color", QVector4D(0,1,0,1));
glPointSize(2);
m_problematic_vertices->draw();


sp.unuse();
}
}
2 changes: 1 addition & 1 deletion Arrangement_on_surface_2/demo/earth/Main_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Main_widget : public QOpenGLWidget, protected OpenGLFunctionsBase
std::unique_ptr<Sphere> m_sphere;
std::unique_ptr<World_coord_axes> m_world_coord_axes;
std::unique_ptr<Line_strips> m_geodesic_arcs;
std::unique_ptr<Vertices> m_vertices;
std::unique_ptr<Vertices> m_vertices, m_problematic_vertices;
std::unique_ptr<Line_strips> m_identification_curve;

// COUNTRY DATA
Expand Down

0 comments on commit 2d2174d

Please sign in to comment.