diff --git a/Arrangement_on_surface_2/demo/earth/CMakeLists.txt b/Arrangement_on_surface_2/demo/earth/CMakeLists.txt index 915d3de7df4..71c3cd93789 100644 --- a/Arrangement_on_surface_2/demo/earth/CMakeLists.txt +++ b/Arrangement_on_surface_2/demo/earth/CMakeLists.txt @@ -45,7 +45,7 @@ qt_add_executable(earth Geodesic_arcs.h Geodesic_arcs.cpp Shader_program.h Shader_program.cpp Sphere.h Sphere.cpp - Tools.h + Tools.h Tools.cpp World_coordinate_axes.h World_coordinate_axes.cpp ) diff --git a/Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp b/Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp index 4c5731472a7..5458bf199fc 100644 --- a/Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp +++ b/Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp @@ -1,52 +1,51 @@ #include "Geodesic_arcs.h" -#include - #include #include #include -using namespace std; +#include #include #include #include #include +#include + #include "arr_print.h" -typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; -typedef CGAL::Arr_geodesic_arc_on_sphere_traits_2 Geom_traits; -typedef Geom_traits::Point_2 Point; -typedef Geom_traits::Curve_2 Curve; -typedef CGAL::Arr_spherical_topology_traits_2 Topol_traits; -typedef CGAL::Arrangement_on_surface_2 Arrangement; +using Kernel = CGAL::Exact_predicates_exact_constructions_kernel; +using Geom_traits = CGAL::Arr_geodesic_arc_on_sphere_traits_2; +using Point = Geom_traits::Point_2; +using Curve = Geom_traits::Curve_2; +using Topol_traits = CGAL::Arr_spherical_topology_traits_2; +using Arrangement = CGAL::Arrangement_on_surface_2; -typedef Kernel::Direction_3 Dir3; -ostream& operator << (ostream& os, const Dir3& d) + +using Dir3 = Kernel::Direction_3 ; +std::ostream& operator << (std::ostream& os, const Dir3& d) { os << d.dx() << ", " << d.dy() << ", " << d.dz(); return os; } -typedef Geom_traits::Approximate_point_2 Approximate_point_2; -ostream& operator << (ostream& os, const Approximate_point_2& d) +using Approximate_point_2 = Geom_traits::Approximate_point_2; +std::ostream& operator << (std::ostream& os, const Approximate_point_2& d) { os << d.dx() << ", " << d.dy() << ", " << d.dz(); return os; } -#include -typedef Geom_traits::Approximate_number_type Approximate_number_type; -typedef Geom_traits::Approximate_kernel Approximate_kernel; -typedef CGAL::Vector_3 Approximate_Vector_3; -typedef Approximate_kernel::Direction_3 Approximate_Direction_3; - -typedef Kernel::Direction_3 Direction_3; +using Approximate_number_type = Geom_traits::Approximate_number_type; +using Approximate_kernel = Geom_traits::Approximate_kernel; +using Approximate_Vector_3 = CGAL::Vector_3; +using Approximate_Direction_3 = Approximate_kernel::Direction_3; +using Direction_3 = Kernel::Direction_3; -ostream& operator << (ostream& os, const Approximate_Vector_3& v) +std::ostream& operator << (std::ostream& os, const Approximate_Vector_3& v) { os << v.x() << ", " << v.y() << ", " << v.z(); //os << v.hx() << ", " << v.hy() << ", " << v.hz() << ", " << v.hw(); @@ -67,7 +66,7 @@ Geodesic_arcs::Geodesic_arcs() auto ctr_cv = traits.construct_curve_2_object(); - vector xcvs; + std::vector xcvs; 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))); @@ -87,21 +86,15 @@ Geodesic_arcs::Geodesic_arcs() std::vector v; auto oi2 = approx(xcv, error, std::back_insert_iterator(v)); - //for (auto it = v.begin(); it != v.end(); ++it) - // cout << *it << endl; - //cout << "num points output = " << v.size() << endl; for (const auto& p : v) { const QVector3D arc_point(p.dx(), p.dy(), p.dz()); vertex_data.push_back(arc_point); } - //m_num_arc_points = v.size(); // CAREFUL: not size of vertex_data!!! const auto current_vertex_data_size = vertex_data.size(); m_arc_offsets.push_back(current_vertex_data_size); - std::cout << "current_vertex_data_size = " << current_vertex_data_size << std::endl; - } - std::cout << "offset count = " << m_arc_offsets.size() << std::endl; + //std::cout << "offset count = " << m_arc_offsets.size() << std::endl; // DEFINE OPENGL BUFFERS diff --git a/Arrangement_on_surface_2/demo/earth/Sphere.cpp b/Arrangement_on_surface_2/demo/earth/Sphere.cpp index 2943ec6ce31..fac28fd4147 100644 --- a/Arrangement_on_surface_2/demo/earth/Sphere.cpp +++ b/Arrangement_on_surface_2/demo/earth/Sphere.cpp @@ -1,11 +1,11 @@ #include "Sphere.h" -#include - #include #include +#include + Sphere::Sphere(int num_slices, int num_stacks, float r) { diff --git a/Arrangement_on_surface_2/demo/earth/Tools.cpp b/Arrangement_on_surface_2/demo/earth/Tools.cpp new file mode 100644 index 00000000000..250ebadfcc2 --- /dev/null +++ b/Arrangement_on_surface_2/demo/earth/Tools.cpp @@ -0,0 +1,27 @@ + +#include "Tools.h" + +#include +#include +#include + + +std::string read_file(const std::string& file_name) +{ + const auto flags = std::ios::in | std::ios::binary | std::ios::ate; + std::ifstream ifs(file_name.c_str(), flags); + + if (ifs.is_open() == false) + { + std::cout << "could not open file: " << file_name << std::endl; + return ""; + } + + std::ifstream::pos_type file_size = ifs.tellg(); + ifs.seekg(0, std::ios::beg); + + std::vector bytes(file_size); + ifs.read(&bytes[0], file_size); + + return std::string(&bytes[0], file_size); +} \ No newline at end of file diff --git a/Arrangement_on_surface_2/demo/earth/Tools.h b/Arrangement_on_surface_2/demo/earth/Tools.h index 5e52e3fd746..dcc1f70bf64 100644 --- a/Arrangement_on_surface_2/demo/earth/Tools.h +++ b/Arrangement_on_surface_2/demo/earth/Tools.h @@ -2,24 +2,10 @@ #ifndef TOOLS_H #define TOOLS_H -#include #include -#include -std::string read_file(const std::string& file_name) -{ - std::ifstream ifs(file_name.c_str(), std::ios::in | std::ios::binary | - std::ios::ate); - - std::ifstream::pos_type file_size = ifs.tellg(); - ifs.seekg(0, std::ios::beg); - - std::vector bytes(file_size); - ifs.read(&bytes[0], file_size); - - return std::string(&bytes[0], file_size); -} +std::string read_file(const std::string& file_name); #endif diff --git a/Arrangement_on_surface_2/demo/earth/World_coordinate_axes.cpp b/Arrangement_on_surface_2/demo/earth/World_coordinate_axes.cpp index 44ca581cab2..20c12b192c2 100644 --- a/Arrangement_on_surface_2/demo/earth/World_coordinate_axes.cpp +++ b/Arrangement_on_surface_2/demo/earth/World_coordinate_axes.cpp @@ -1,10 +1,10 @@ #include "World_coordinate_axes.h" -#include - #include +#include + World_coord_axes::World_coord_axes(float length) { diff --git a/Arrangement_on_surface_2/demo/earth/main.cpp b/Arrangement_on_surface_2/demo/earth/main.cpp index 2da5819072b..ba8822a8cc2 100644 --- a/Arrangement_on_surface_2/demo/earth/main.cpp +++ b/Arrangement_on_surface_2/demo/earth/main.cpp @@ -1,3 +1,11 @@ +// Copyright(c) 2012, 2020 Tel - Aviv University(Israel). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s): Deniz Diktas #include #include @@ -7,30 +15,28 @@ #include "mainwidget.h" #endif -#include -using namespace std; -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { - QApplication app(argc, argv); + QApplication app(argc, argv); - QSurfaceFormat format; - format.setVersion(3, 3); - format.setProfile(QSurfaceFormat::CoreProfile); - //format.setProfile(QSurfaceFormat::CompatibilityProfile); - //format.setOptions(QSurfaceFormat::DeprecatedFunctions); - //QSurfaceFormat::setDefaultFormat(format); - format.setDepthBufferSize(24); - QSurfaceFormat::setDefaultFormat(format); + QSurfaceFormat format; + format.setVersion(3, 3); + format.setProfile(QSurfaceFormat::CoreProfile); + //format.setProfile(QSurfaceFormat::CompatibilityProfile); + //format.setOptions(QSurfaceFormat::DeprecatedFunctions); + //QSurfaceFormat::setDefaultFormat(format); + format.setDepthBufferSize(24); + QSurfaceFormat::setDefaultFormat(format); - app.setApplicationName("Earth"); - app.setApplicationVersion("0.1"); + app.setApplicationName("Earth"); + app.setApplicationVersion("0.1"); #ifndef QT_NO_OPENGL - MainWidget widget; - widget.show(); + MainWidget widget; + widget.show(); #else - QLabel note("OpenGL Support required"); - note.show(); + QLabel note("OpenGL Support required"); + note.show(); #endif - return app.exec(); + return app.exec(); } diff --git a/Arrangement_on_surface_2/demo/earth/mainwidget.cpp b/Arrangement_on_surface_2/demo/earth/mainwidget.cpp index 19c31176006..4ad6b1f8e0d 100644 --- a/Arrangement_on_surface_2/demo/earth/mainwidget.cpp +++ b/Arrangement_on_surface_2/demo/earth/mainwidget.cpp @@ -1,12 +1,12 @@ #include "mainwidget.h" -#include - #include #include #include +#include + MainWidget::~MainWidget() { @@ -29,7 +29,7 @@ void MainWidget::set_mouse_button_pressed_flag(QMouseEvent* e, bool flag) break; } } -void MainWidget::mousePressEvent(QMouseEvent *e) +void MainWidget::mousePressEvent(QMouseEvent* e) { set_mouse_button_pressed_flag(e, true); m_last_mouse_pos = QVector2D(e->position()); @@ -55,21 +55,16 @@ void MainWidget::mouseMoveEvent(QMouseEvent* e) m_last_mouse_pos = current_mouse_pos; } -void MainWidget::mouseReleaseEvent(QMouseEvent *e) +void MainWidget::mouseReleaseEvent(QMouseEvent* e) { set_mouse_button_pressed_flag(e, false); } -void MainWidget::timerEvent(QTimerEvent *) +void MainWidget::timerEvent(QTimerEvent*) { update(); } -#include "Geodesic_arcs.h" - - -std::unique_ptr m_geodesic_arcs; - void MainWidget::initializeGL() { initializeOpenGLFunctions(); diff --git a/Arrangement_on_surface_2/demo/earth/mainwidget.h b/Arrangement_on_surface_2/demo/earth/mainwidget.h index 0ed2b768563..b1015c43f0a 100644 --- a/Arrangement_on_surface_2/demo/earth/mainwidget.h +++ b/Arrangement_on_surface_2/demo/earth/mainwidget.h @@ -10,12 +10,13 @@ #include #include -#include - #include +#include + #include "Camera.h" #include "Common_defs.h" +#include "Geodesic_arcs.h" #include "Shader_program.h" #include "Sphere.h" #include "World_coordinate_axes.h" @@ -31,10 +32,10 @@ class MainWidget : public QOpenGLWidget, protected OpenGLFunctionsBase protected: void set_mouse_button_pressed_flag(QMouseEvent* e, bool flag); - void mousePressEvent(QMouseEvent *e) override; + void mousePressEvent(QMouseEvent* e) override; void mouseMoveEvent(QMouseEvent* e) override; - void mouseReleaseEvent(QMouseEvent *e) override; - void timerEvent(QTimerEvent *e) override; + void mouseReleaseEvent(QMouseEvent* e) override; + void timerEvent(QTimerEvent* e) override; void initializeGL() override; void resizeGL(int w, int h) override; @@ -53,6 +54,7 @@ class MainWidget : public QOpenGLWidget, protected OpenGLFunctionsBase // Objects in the scene std::unique_ptr m_sphere; std::unique_ptr m_world_coord_axes; + std::unique_ptr m_geodesic_arcs; // Shaders Shader_program m_sp_smooth;