Skip to content

Commit

Permalink
Implemented: rendering individual arcs to see the problem with the GI…
Browse files Browse the repository at this point in the history
…S data-set
  • Loading branch information
denizdiktas committed Jul 3, 2023
1 parent e29175b commit 7571f9a
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 73 deletions.
110 changes: 55 additions & 55 deletions Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ Geodesic_arcs::Approx_arcs Geodesic_arcs::get_approx_arcs(const Kml::Placemark&

// add curves
int num_points = sphere_points.size();
for (int i = 0; i < sphere_points.size(); i++)
for (int i = 0; i < num_points - 1; i++)
{
const auto p1 = sphere_points[i];
const auto p2 = sphere_points[(i + 1) % num_points];
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())));
ctr_p(p2.x(), p2.y(), p2.z())));
}
}

Expand All @@ -144,55 +144,55 @@ Geodesic_arcs::Approx_arcs Geodesic_arcs::get_approx_arcs(const Kml::Placemark&
return arcs;
}

Geodesic_arcs::Approx_arcs Geodesic_arcs::get_approx_arcs(
const Kml::Placemarks& placemarks, 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& pm : placemarks)
{
for (const auto& lring : pm.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)
//{
// 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& pm : placemarks)
// {
// for (const auto& lring : pm.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;
//}
17 changes: 17 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Line_strips.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

#include "Line_strips.h"

#include <iostream>


Line_strips::Line_strips(std::vector<QVector3D>& line_strip_points)
{
Expand Down Expand Up @@ -90,6 +92,21 @@ Line_strips::Line_strips(std::vector<std::vector<QVector3D>>& arcs)
glBindVertexArray(0);
}

int Line_strips::get_num_line_strips() const
{
return m_offsets.size() - 1;
}

void Line_strips::draw(int line_strip_index)
{
glBindVertexArray(m_vao);
const auto first = m_offsets[line_strip_index];
const auto count = m_offsets[line_strip_index + 1] - first;
glDrawArrays(GL_LINE_STRIP, first, count);
glBindVertexArray(0);
}


void Line_strips::draw()
{
glBindVertexArray(m_vao);
Expand Down
4 changes: 4 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Line_strips.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class Line_strips : protected OpenGLFunctionsBase
Line_strips(std::vector<QVector3D>& line_strip_points);
Line_strips(std::vector<std::vector<QVector3D>>& arcs);

int get_num_line_strips() const;
void draw(int line_strip_index);

void draw();


private:
GLuint m_vao, m_vbo;
Expand Down
91 changes: 74 additions & 17 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,33 +112,84 @@ void Main_widget::keyPressEvent(QKeyEvent* event)
{
switch (event->key())
{
case Qt::Key_A:
show_map = false;
case Qt::Key_Q:
{
auto num_arcs = m_country_borders[m_selected_country]->get_num_line_strips();
if (++m_selected_arc == num_arcs)
m_selected_arc--;
std::cout << "selected arc = " << m_selected_arc << std::endl;
}
break;
case Qt::Key_S:
show_map = true;
case Qt::Key_A:
{
auto num_arcs = m_country_borders[m_selected_country]->get_num_line_strips();
if (--m_selected_arc < 0)
m_selected_arc = 0;
std::cout << "selected arc = " << m_selected_arc << std::endl;
}
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;
m_selected_country++;
if (m_selected_country == m_country_names.size())
m_selected_country--;
std::cout << m_selected_country << ": " << m_country_names[m_selected_country] << std::endl;
m_selected_arc = 0;
break;

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

m_selected_country--;
if (m_selected_country < 0)
m_selected_country = 0;
std::cout << m_selected_country << ": " << m_country_names[m_selected_country] << std::endl;
m_selected_arc = 0;
break;


}
}

#include <shapefil.h>

void readShapefile(const std::string& filename) {
// Open the shapefile
SHPHandle shp = SHPOpen(filename.c_str(), "rb");
if (shp == nullptr) {
std::cerr << "Failed to open shapefile: " << filename << std::endl;
return;
}

// Get shapefile information
int numEntities, shapeType;
double minBounds[4], maxBounds[4];
SHPGetInfo(shp, &numEntities, &shapeType, minBounds, maxBounds);
std::cout << "Number of entities: " << numEntities << std::endl;
std::cout << "Shape type: " << shapeType << std::endl;
std::cout << "Bounds: (" << minBounds[0] << ", " << minBounds[1] << "), ("
<< maxBounds[0] << ", " << maxBounds[1] << ")" << std::endl;
//SHPT_POLYGON
// Read individual shapes
for (int i = 0; i < numEntities; ++i) {
SHPObject* shape = SHPReadObject(shp, i);

// Process the shape data
// Example: Print the shape's type and number of points
std::cout << "Shape " << i << ": Type " << shape->nSHPType
<< ", Number of parts: " << shape->nParts
<< ", Number of points: " << shape->nVertices << std::endl;

// Clean up the shape object
SHPDestroyObject(shape);
}

// Close the shapefile
SHPClose(shp);
}

void Main_widget::initializeGL()
{
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";
auto countries = Kml::read(file_name);
Expand Down Expand Up @@ -173,7 +224,7 @@ void Main_widget::initializeGL()
// 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 = ga.get_approx_arcs(countries, error);
//auto lsa = ga.get_approx_arcs(countries, error);
//auto lsa = ga.get_approx_arcs(error);
// m_geodesic_arcs = std::make_unique<Line_strips>(lsa);
for (const auto& country : countries)
Expand All @@ -183,7 +234,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 = 0;
m_selected_country = 25;
m_selected_arc = 0;
}

glClearColor(0, 0, 0, 1);
Expand Down Expand Up @@ -400,11 +452,16 @@ void Main_widget::paintGL()
QVector4D plane(n.x(), n.y(), n.z(), -QVector3D::dotProduct(p, n));
const QVector4D arc_color(0, 0.5, 1, 1);
glLineWidth(5);
sp.set_uniform("u_color", arc_color);
sp.set_uniform("u_plane", plane);
if (show_map)
m_country_borders[m_selected_country]->draw();
//m_geodesic_arcs->draw();

// draw all countries
float a = 0.0;
sp.set_uniform("u_color", QVector4D(a, a, a, 1));
for(auto& country_border : m_country_borders)
country_border->draw();

sp.set_uniform("u_color", arc_color);
m_country_borders[m_selected_country]->draw(m_selected_arc);

const QVector4D vertex_color(1, 0, 0, 1);
sp.set_uniform("u_color", vertex_color);
Expand Down
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 @@ -61,7 +61,7 @@ class Main_widget : public QOpenGLWidget, protected OpenGLFunctionsBase
std::unique_ptr<Vertices> m_vertices;

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

Expand Down

0 comments on commit 7571f9a

Please sign in to comment.