Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Jun 29, 2023
1 parent 38c4146 commit 03e2234
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
10 changes: 5 additions & 5 deletions Arrangement_on_surface_2/demo/earth/Aos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,18 @@ std::vector<QVector3D> Aos::ext_check(const Kml::Placemarks& placemarks)
// extract all vertices that are ADDED when inserting the arcs!
int num_created_vertices = 0;
std::vector<QVector3D> created_vertices;
auto approx = traits.approximate_2_object();
for (auto vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit)
{
auto& d = vit->data();
if (vit->data().v == false)
{
num_created_vertices++;
auto p = vit->point();
const auto x = CGAL::to_double(p.dx());
const auto y = CGAL::to_double(p.dy());
const auto z = CGAL::to_double(p.dz());
std::cout << QVector3D(x, y, z) << std::endl;
created_vertices.emplace_back(x, y, z);
auto ap = approx(p);
QVector3D new_vertex(ap.dx(), ap.dy(), ap.dz());
std::cout << new_vertex << std::endl;
created_vertices.push_back(new_vertex);
}
}
std::cout << "*** num created vertices = " << num_created_vertices << std::endl;
Expand Down
54 changes: 28 additions & 26 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void Main_widget::initializeGL()
auto dup_nodes = Kml::get_duplicates(countries);

// initialize rendering of DUPLICATE VERTICES
if(0)
if(1)
{
std::vector<QVector3D> vertices;
for (const auto& node : dup_nodes)
Expand Down Expand Up @@ -199,6 +199,29 @@ void Main_widget::init_shader_programs()
m_sp_arc.init_with_vs_fs("arc");
}

float Main_widget::compute_backprojected_error(float pixel_error)
{
// compute the back-projected error
QRect vp(0, 0, m_vp_width, m_vp_height);
auto proj = m_camera.get_projection_matrix();
auto view = m_camera.get_view_matrix();
QMatrix4x4 model;
auto model_view = view * model;

QVector3D p0(m_vp_width / 2, m_vp_height / 2, 0);
QVector3D p1(p0.x() + pixel_error, p0.y(), 0);
auto wp0 = p0.unproject(model_view, proj, vp);
auto wp1 = p1.unproject(model_view, proj, vp);
const float z_near = m_camera.get_z_near();
const float r = 1.f; // sphere radius
const QVector3D origin(0, 0, 0);
const float dist_to_cam = m_camera.get_pos().distanceToPoint(origin);

float d = dist_to_cam - r;
float err = wp0.distanceToPoint(wp1) * (d / z_near);
//find_minimum_projected_error_on_sphere(err);
return err;
}
void Main_widget::find_minimum_projected_error_on_sphere(float we)
{
QRect vp(0, 0, m_vp_width, m_vp_height);
Expand Down Expand Up @@ -293,31 +316,9 @@ void Main_widget::resizeGL(int w, int h)
const qreal z_near = 0.1, z_far = 100.0, fov = 45.0;
m_camera.perspective(fov, aspect, z_near, z_far);

{
// compute the back-projected error
QRect vp(0, 0, m_vp_width, m_vp_height);
auto proj = m_camera.get_projection_matrix();
auto view = m_camera.get_view_matrix();
QMatrix4x4 model;
auto model_view = view * model;

QVector3D p0(m_vp_width / 2, m_vp_height / 2, 0);
QVector3D p1(p0.x() + 1, p0.y(), 0);
auto wp0 = p0.unproject(model_view, proj, vp);
auto wp1 = p1.unproject(model_view, proj, vp);
const float z_near = m_camera.get_z_near();
const float r = 1.f; // sphere radius
const QVector3D origin(0, 0, 0);
const float dist_to_cam = m_camera.get_pos().distanceToPoint(origin);

float d = dist_to_cam - r;
float err = wp0.distanceToPoint(wp1) * (d / z_near);
std::cout << "error = " << err << std::endl;

// find the minimum error over the sphere
//find_minimum_projected_error_on_sphere(err);
}

// compute the world-space error for the given pixel-error
const auto err = compute_backprojected_error(0.5f);
std::cout << "error = " << err << std::endl;
}
void Main_widget::paintGL()
{
Expand Down Expand Up @@ -383,6 +384,7 @@ void Main_widget::paintGL()

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

sp.unuse();
Expand Down
1 change: 1 addition & 0 deletions Arrangement_on_surface_2/demo/earth/Main_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Main_widget : public QOpenGLWidget, protected OpenGLFunctionsBase
void init_geometry();
void init_shader_programs();

float compute_backprojected_error(float pixel_error);
// Use this to find the approximate of the true minimum projected error.
// we are ot using this complicated method, but provide it for completeness.
void find_minimum_projected_error_on_sphere(float we);
Expand Down

0 comments on commit 03e2234

Please sign in to comment.