Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Jun 17, 2023
1 parent f9c98fe commit 531399f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 25 deletions.
12 changes: 9 additions & 3 deletions Arrangement_on_surface_2/demo/earth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ if ( NOT Boost_FOUND )
endif()


file(GLOB source_files_geometry
Line_strips.h Line_strips.cpp
Sphere.h Sphere.cpp
World_coordinate_axes.h World_coordinate_axes.cpp
)
source_group( "geometry" FILES ${source_files_geometry} )


qt_standard_project_setup()

qt_add_executable(earth
Expand All @@ -43,11 +51,9 @@ qt_add_executable(earth
Camera.h Camera.cpp
Common_defs.h
Geodesic_arcs.h Geodesic_arcs.cpp
Line_strips.h Line_strips.cpp
Shader_program.h Shader_program.cpp
Sphere.h Sphere.cpp
Tools.h Tools.cpp
World_coordinate_axes.h World_coordinate_axes.cpp
${source_files_geometry}
)


Expand Down
7 changes: 0 additions & 7 deletions Arrangement_on_surface_2/demo/earth/Common_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@
#ifndef COMMON_DEFS_H
#define COMMON_DEFS_H

#include <vector>

#include <qopenglfunctions_3_3_core.h>
//#include <qopenglfunctions_4_5_core.h>
#include <qvector3d.h>


using OpenGLFunctionsBase = QOpenGLFunctions_3_3_Core;


struct Line_strip_approx
{
std::vector<QVector3D> points;
std::vector<GLuint> offsets;
};


#endif
16 changes: 8 additions & 8 deletions Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ std::ostream& operator << (std::ostream& os, const Approximate_Vector_3& v)
}


Line_strip_approx Geodesic_arcs::get_approximate_arcs(double error)
std::vector<std::vector<QVector3D>> Geodesic_arcs::get_approximate_arcs(double
error)
{
// Construct the arrangement from 12 geodesic arcs.
Geom_traits traits;
Expand All @@ -73,22 +74,21 @@ Line_strip_approx Geodesic_arcs::get_approximate_arcs(double error)
auto approx = traits.approximate_2_object();


Line_strip_approx lsa;
lsa.offsets.push_back(0);
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());
lsa.points.push_back(arc_point);
arc_points.push_back(arc_point);
}
const auto current_vertex_data_size = lsa.points.size();
lsa.offsets.push_back(current_vertex_data_size);
arcs.push_back(std::move(arc_points));
}
//std::cout << "offset count = " << m_arc_offsets.size() << std::endl;

return lsa;
return arcs;
}
7 changes: 5 additions & 2 deletions Arrangement_on_surface_2/demo/earth/Geodesic_arcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
#ifndef GEODESIC_ARCS_H
#define GEODESIC_ARCS_H

#include "Common_defs.h"
#include <vector>
#include <qvector3d.h>


class Geodesic_arcs
{
public:

std::vector<std::vector<QVector3D>> get_approximate_arcs(double error);

Line_strip_approx get_approximate_arcs(double error);
//Line_strip_approx get_approximate_arcs(double error);
};


Expand Down
15 changes: 12 additions & 3 deletions Arrangement_on_surface_2/demo/earth/Line_strips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
#include "Line_strips.h"


Line_strips::Line_strips(Line_strip_approx& lsa)
Line_strips::Line_strips(std::vector<std::vector<QVector3D>>& arcs)
{
initializeOpenGLFunctions();

const auto& vertex_data = lsa.points;
m_offsets = lsa.offsets;
std::vector<QVector3D> vertex_data;
m_offsets.push_back(0);
for (const auto& arc : arcs)
{
for(const auto& p : arc)
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);
Expand Down
3 changes: 2 additions & 1 deletion Arrangement_on_surface_2/demo/earth/Line_strips.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
#define LINE_STRIPS_H

#include <vector>
#include <qvector3d.h>
#include "Common_defs.h"


class Line_strips : protected OpenGLFunctionsBase
{
public:
Line_strips(Line_strip_approx& lsa);
Line_strips(std::vector<std::vector<QVector3D>>& arcs);

void draw();

Expand Down
2 changes: 1 addition & 1 deletion Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void Main_widget::paintGL()

// GEODESIC ARCS
{
//glDisable(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST);

auto& sp = m_sp_arc;
sp.use();
Expand Down

0 comments on commit 531399f

Please sign in to comment.