Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Jul 7, 2023
1 parent 7ba83df commit daf548c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
55 changes: 55 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Kml_reader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include "Kml_reader.h"

#include <algorithm>
#include <iostream>
#include <unordered_map>

Expand Down Expand Up @@ -212,6 +213,51 @@ Kml::Nodes Kml::get_duplicates(const Placemarks& placemarks)
return duplicate_nodes;
}


Kml::Nodes Kml::generate_ids(Placemarks& placemarks)
{
// collect all nodes into a single vector
int polygon_count = 0;
std::vector<Node> nodes;
for (auto& pm : placemarks)
{
for (auto& polygon : pm.polygons)
{
polygon_count++;

std::vector<LinearRing*> linear_rings;
linear_rings.push_back(&polygon.outer_boundary);
for (auto& inner_boundary : polygon.inner_boundaries)
linear_rings.push_back(&inner_boundary);

for (auto* lring : linear_rings)
{
for (const auto& node : lring->nodes)
{
// check if the node is in the nodes
auto it = std::find(nodes.begin(), nodes.end(), node);
if (nodes.end() == it)
{
// insert new node
nodes.push_back(node);
const int node_id = nodes.size() - 1;
lring->ids.push_back(node_id);
}
else
{
// get the existing node
const int node_id = std::distance(nodes.begin(), it);
lring->ids.push_back(node_id);
}
}
}
}
}

return nodes;
}


Kml::Nodes Kml::Polygon::get_all_nodes() const
{
Nodes all_nodes;
Expand All @@ -228,6 +274,15 @@ Kml::Nodes Kml::Polygon::get_all_nodes() const

return all_nodes;
}
std::vector<Kml::LinearRing*> Kml::Polygon::get_all_boundaries()
{
std::vector<LinearRing*> linear_rings;
linear_rings.push_back(&outer_boundary);
for (auto& inner_boundary : inner_boundaries)
linear_rings.push_back(&inner_boundary);

return linear_rings;
}

Kml::Nodes Kml::Placemark::get_all_nodes() const
{
Expand Down
8 changes: 8 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Kml_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Kml
struct LinearRing
{
std::vector<Node> nodes;
std::vector<int> ids;

Arcs get_arcs() const;
void get_arcs(Arcs& arcs) const;
Expand All @@ -53,6 +54,8 @@ class Kml
// when collecting nodes start from the outer boundary and then get nodes
// from individual inner boundaries in the order
Nodes get_all_nodes() const;

std::vector<LinearRing*> get_all_boundaries();
};


Expand All @@ -72,6 +75,11 @@ class Kml
static Placemarks read(const std::string& file_name);

static Nodes get_duplicates(const Placemarks& placemarks);


// Outputs all used nodes without duplications!
// NOTE: this function modifies Placemarks data-structure!
static Nodes generate_ids(Placemarks& placemarks);
};


Expand Down
4 changes: 3 additions & 1 deletion Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ void Main_widget::initializeGL()
const auto file_name = "C:/work/gsoc2023/data/ne_110m_admin_0_countries.kml";
m_countries = Kml::read(file_name);
auto dup_nodes = Kml::get_duplicates(m_countries);

auto all_nodes = Kml::generate_ids(m_countries);

// initialize rendering of DUPLICATE VERTICES
if(0)
if(1)
{
std::vector<QVector3D> vertices;
for (const auto& node : dup_nodes)
Expand Down

0 comments on commit daf548c

Please sign in to comment.