Skip to content

Commit

Permalink
solved the triangulation error
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Aug 10, 2023
1 parent dbd9511 commit 7254741
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
26 changes: 26 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Aos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,10 @@ Aos::Arr_handle Aos::construct(Kml::Placemarks& placemarks)
#include <CGAL/Polygon_2.h>
//#include <CGAL/Projection_traits_3.h>

#include <iostream>
#include <unordered_map>
#include <boost/property_map/property_map.hpp>

std::vector<QVector3D> Aos::get_triangles(Arr_handle arrh)
{
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
Expand Down Expand Up @@ -1356,9 +1360,20 @@ std::vector<QVector3D> Aos::get_triangles(Arr_handle arrh)
// RESULTING TRIANGLE POINTS (every 3 point => triangle)
std::vector<QVector3D> triangles;

std::cout << "triangulating individual faces\n";

// loop on all approximated faces
for (auto& face_points : all_faces)
{
std::cout << "num face points = " << face_points.size() << std::endl;
// no need to triangulate if the number of points is 3
if (face_points.size() == 3)
{
triangles.insert(triangles.end(), face_points.begin(), face_points.end());
continue;
}


// find the centroid of all face-points
QVector3D centroid(0, 0, 0);
for (const auto& fp : face_points)
Expand Down Expand Up @@ -1394,9 +1409,20 @@ std::vector<QVector3D> Aos::get_triangles(Arr_handle arrh)
CDT cdt;
cdt.insert_constraint(polygon.vertices_begin(), polygon.vertices_end(), true);

std::unordered_map<Face_handle, bool> in_domain_map;
boost::associative_property_map< std::unordered_map<Face_handle, bool> >
in_domain(in_domain_map);

//Mark facets that are inside the domain bounded by the polygon
CGAL::mark_domain_in_triangulation(cdt, in_domain);

// loop on all the triangles ("faces" in triangulation doc)
for (Face_handle f : cdt.finite_face_handles())
{
// if the current triangles is not inside the polygon -> skip it
if (false == get(in_domain, f))
continue;

for(int i=0; i<3; ++i)
{
auto tp = f->vertex(i)->point();
Expand Down
24 changes: 16 additions & 8 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ void Main_widget::initializeGL()
//Shapefile::read(shape_file_name);

//const auto file_name = data_path + "world_countries.kml";
//const auto file_name = data_path + "ne_110m_admin_0_countries.kml";
const auto file_name = data_path + "ne_110m_admin_0_countries_africa.kml";
const auto file_name = data_path + "ne_110m_admin_0_countries.kml";
//const auto file_name = data_path + "ne_110m_admin_0_countries_africa.kml";
m_countries = Kml::read(file_name);
auto dup_nodes = Kml::get_duplicates(m_countries);
//auto all_nodes = Kml::generate_ids(m_countries);
Expand All @@ -199,8 +199,12 @@ void Main_widget::initializeGL()

// trianglulation
{
qDebug() << "constructiong arr..";
auto arrh = Aos::construct(m_countries);

qDebug() << "generating triangles..";
auto triangle_points = Aos::get_triangles(arrh);

qDebug() << "num triangles = " << triangle_points.size() / 3;
g_face_triangles = std::make_unique<Triangles>(triangle_points);
}
Expand Down Expand Up @@ -477,22 +481,25 @@ void Main_widget::paintGL()
auto& sp = m_sp_smooth;
sp.use();
sp.set_uniform("u_mvp", mvp);
sp.set_uniform("u_color", m_sphere->get_color());
QVector4D sphere_color(167. / 255, 205. / 255, 242. / 255, 1);
sp.set_uniform("u_color", sphere_color);
//sp.set_uniform("u_color", m_sphere->get_color());

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
m_sphere->draw();

// DRAW SOLID FACES
if(1)
{
glDisable(GL_DEPTH_TEST);
QVector4D face_color(1, .5, 0, 1);
sp.set_uniform("u_color", face_color);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
g_face_triangles->draw();

sp.set_uniform("u_color", QVector4D(0,0,0,1));
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
g_face_triangles->draw();
//sp.set_uniform("u_color", QVector4D(0,0,0,1));
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
//g_face_triangles->draw();
}

sp.unuse();
Expand All @@ -504,6 +511,7 @@ void Main_widget::paintGL()
sp.use();
sp.set_uniform("u_mvp", mvp);

glEnable(GL_DEPTH_TEST);
m_world_coord_axes->draw();

sp.unuse();
Expand Down

0 comments on commit 7254741

Please sign in to comment.