Skip to content

Commit

Permalink
Rendering countries one by one
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Jun 30, 2023
1 parent 03e2234 commit e29175b
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 22 deletions.
8 changes: 8 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Aos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ std::vector<QVector3D> Aos::ext_check(const Kml::Placemarks& placemarks)
QVector3D new_vertex(ap.dx(), ap.dy(), ap.dz());
std::cout << new_vertex << std::endl;
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);

}
}
std::cout << "*** num created vertices = " << num_created_vertices << std::endl;
Expand Down
10 changes: 10 additions & 0 deletions Arrangement_on_surface_2/demo/earth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ endif()

set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/opengl/earth")

#find_package(shapelib REQUIRED)
find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets Xml)
add_definitions(-DQT_NO_VERSION_TAGGING)

Expand All @@ -36,6 +37,14 @@ if ( NOT Boost_FOUND )
endif()


set(SHAPELIB_INCLUDE_DIR "" CACHE PATH "DEFINE ME!!!")
#target_include_directories(earth PRIVATE ${SHAPELIB_INCLUDE_DIR})
include_directories(${SHAPELIB_INCLUDE_DIR})
set(SHAPELIB_LIB_DIR "" CACHE PATH "DEFINE ME!!!")
#target_link_directories(earth PRIVATE ${SHAPELIB_LIB_DIR})
link_directories(earth PRIVATE ${SHAPELIB_LIB_DIR})


file(GLOB source_files_geometry
Line_strips.h Line_strips.cpp
Sphere.h Sphere.cpp
Expand Down Expand Up @@ -78,6 +87,7 @@ target_link_libraries(earth PRIVATE
Qt6::Widgets
Qt6::Xml
CGAL::CGAL
shp
)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/shaders
Expand Down
62 changes: 50 additions & 12 deletions Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,63 @@ Geodesic_arcs::Approx_arcs Geodesic_arcs::get_approx_arcs(double error)
}


Geodesic_arcs::Approx_arcs Geodesic_arcs::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& lring : placemark.polygons)
{
// convert the nodes to points on unit-sphere
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 curves
int num_points = sphere_points.size();
for (int i = 0; i < sphere_points.size(); i++)
{
const auto p1 = sphere_points[i];
const auto p2 = sphere_points[(i + 1) % num_points];
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;
}

Geodesic_arcs::Approx_arcs Geodesic_arcs::get_approx_arcs(
const Kml::Placemarks& placemarks, 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;
for (const auto& pm : placemarks)
{
Expand All @@ -131,15 +177,7 @@ Geodesic_arcs::Approx_arcs Geodesic_arcs::get_approx_arcs(
}
}

//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)
{
Expand Down
1 change: 1 addition & 0 deletions Arrangement_on_surface_2/demo/earth/Geodesic_arcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Geodesic_arcs
Approx_arcs get_approx_arcs(double error);

// generate approximate arcs from KML data
Approx_arcs get_approx_arcs(const Kml::Placemark& placemark, double error);
Approx_arcs get_approx_arcs(const Kml::Placemarks& placemarks, double error);
};

Expand Down
6 changes: 5 additions & 1 deletion Arrangement_on_surface_2/demo/earth/Kml_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <qxmlstream.h>


bool Kml::Node::operator == (const Node& r) const
{
return (lon == r.lon) && (lat == r.lat);
}
Kml::Vec3d Kml::Node::get_coords_3d(const double r) const
{
const auto phi = qDegreesToRadians(lat);
Expand Down Expand Up @@ -80,7 +84,7 @@ Kml::Placemarks Kml::read(const std::string& file_name)
auto attributes = xmlReader.attributes();
auto attr_name = attributes[0].name().toString();
auto attr_value = attributes[0].value().toString();
if ((attr_name == "name") && (attr_value == "name"))
if ((attr_name == "name") && (attr_value == "ADMIN"))
{
xmlReader.readNext();
placemark.name = xmlReader.text().toString().toStdString();;
Expand Down
7 changes: 2 additions & 5 deletions Arrangement_on_surface_2/demo/earth/Kml_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <qvector3d.h>


class Kml
{
public:
Expand All @@ -20,11 +21,7 @@ class Kml
{
double lon, lat;

bool operator == (const Node& r) const
{
return (lon == r.lon) && (lat == r.lat);
}

bool operator == (const Node& r) const;
Vec3d get_coords_3d(const double r = 1.0) const;
QVector3D get_coords_3f(const double r=1.0) const;
};
Expand Down
42 changes: 42 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Line_strips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,48 @@
#include "Line_strips.h"


Line_strips::Line_strips(std::vector<QVector3D>& line_strip_points)
{
initializeOpenGLFunctions();

std::vector<QVector3D> vertex_data;
m_offsets.push_back(0);
for (const auto& p : line_strip_points)
vertex_data.push_back(p);

const auto end_of_current_arc_points = vertex_data.size();
m_offsets.push_back(end_of_current_arc_points);


// DEFINE OPENGL BUFFERS
glGenVertexArrays(1, &m_vao);
glBindVertexArray(m_vao);

// Vertex Buffer
glGenBuffers(1, &m_vbo);
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
auto vertex_buffer_size = sizeof(QVector3D) * vertex_data.size();
auto vertex_buffer_data = reinterpret_cast<const void*>(vertex_data.data());
glBufferData(GL_ARRAY_BUFFER,
vertex_buffer_size,
vertex_buffer_data,
GL_STATIC_DRAW);

// Position Vertex-Attribute
GLint position_attrib_index = 0;
const void* position_offset = 0;
GLsizei stride = 0;
glVertexAttribPointer(position_attrib_index,
3,
GL_FLOAT, GL_FALSE,
stride,
position_offset);
glEnableVertexAttribArray(position_attrib_index);

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}

Line_strips::Line_strips(std::vector<std::vector<QVector3D>>& arcs)
{
initializeOpenGLFunctions();
Expand Down
1 change: 1 addition & 0 deletions Arrangement_on_surface_2/demo/earth/Line_strips.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class Line_strips : protected OpenGLFunctionsBase
{
public:
Line_strips(std::vector<QVector3D>& line_strip_points);
Line_strips(std::vector<std::vector<QVector3D>>& arcs);

void draw();
Expand Down
32 changes: 28 additions & 4 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ void Main_widget::keyPressEvent(QKeyEvent* event)
case Qt::Key_S:
show_map = true;
break;

case Qt::Key_Up:
std::cout << "UP \n";
//m_selected_country++;
//if (m_selected_country == m_country_names.size())
// m_selected_country--;
//std::cout << m_country_names[m_selected_country] << std::endl;
break;

case Qt::Key_Down:
std::cout << "DOWN \n";

break;


}
}

Expand Down Expand Up @@ -160,7 +175,15 @@ void Main_widget::initializeGL()
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);
// 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 country_border = std::make_unique<Line_strips>(approx_arcs);
m_country_borders.push_back(std::move(country_border));
}
m_selected_country = 0;
}

glClearColor(0, 0, 0, 1);
Expand Down Expand Up @@ -379,13 +402,14 @@ void Main_widget::paintGL()
glLineWidth(5);
sp.set_uniform("u_color", arc_color);
sp.set_uniform("u_plane", plane);
if(show_map)
m_geodesic_arcs->draw();
if (show_map)
m_country_borders[m_selected_country]->draw();
//m_geodesic_arcs->draw();

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
5 changes: 5 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Main_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class Main_widget : public QOpenGLWidget, protected OpenGLFunctionsBase
std::unique_ptr<Line_strips> m_geodesic_arcs;
std::unique_ptr<Vertices> m_vertices;

// now we draw boundary-arcs by country
int m_selected_country;
std::vector<std::string> m_country_names;
std::vector<std::unique_ptr<Line_strips>> m_country_borders;

// Shaders
Shader_program m_sp_smooth;
Shader_program m_sp_per_vertex_color;
Expand Down

0 comments on commit e29175b

Please sign in to comment.