Skip to content

Commit

Permalink
sytling and other corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Jun 15, 2023
1 parent 96be82f commit 2d7db03
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 83 deletions.
2 changes: 1 addition & 1 deletion Arrangement_on_surface_2/demo/earth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
51 changes: 22 additions & 29 deletions Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp
Original file line number Diff line number Diff line change
@@ -1,52 +1,51 @@

#include "Geodesic_arcs.h"

#include <qvector3d.h>

#include <iostream>
#include <iterator>
#include <vector>
using namespace std;

#include <qvector3d.h>

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Arrangement_on_surface_2.h>
#include <CGAL/Arr_geodesic_arc_on_sphere_traits_2.h>
#include <CGAL/Arr_spherical_topology_traits_2.h>
#include <CGAL/Vector_3.h>

#include "arr_print.h"

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef CGAL::Arr_geodesic_arc_on_sphere_traits_2<Kernel> Geom_traits;
typedef Geom_traits::Point_2 Point;
typedef Geom_traits::Curve_2 Curve;
typedef CGAL::Arr_spherical_topology_traits_2<Geom_traits> Topol_traits;
typedef CGAL::Arrangement_on_surface_2<Geom_traits, Topol_traits> Arrangement;

using Kernel = CGAL::Exact_predicates_exact_constructions_kernel;
using Geom_traits = CGAL::Arr_geodesic_arc_on_sphere_traits_2<Kernel>;
using Point = Geom_traits::Point_2;
using Curve = Geom_traits::Curve_2;
using Topol_traits = CGAL::Arr_spherical_topology_traits_2<Geom_traits>;
using Arrangement = CGAL::Arrangement_on_surface_2<Geom_traits, Topol_traits>;

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 <CGAL/Vector_3.h>
typedef Geom_traits::Approximate_number_type Approximate_number_type;
typedef Geom_traits::Approximate_kernel Approximate_kernel;
typedef CGAL::Vector_3<Approximate_kernel> 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<Approximate_kernel>;
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();
Expand All @@ -67,7 +66,7 @@ Geodesic_arcs::Geodesic_arcs()
auto ctr_cv = traits.construct_curve_2_object();


vector<Curve> xcvs;
std::vector<Curve> 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)));
Expand All @@ -87,21 +86,15 @@ Geodesic_arcs::Geodesic_arcs()
std::vector<Approximate_point_2> 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
Expand Down
4 changes: 2 additions & 2 deletions Arrangement_on_surface_2/demo/earth/Sphere.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

#include "Sphere.h"

#include <qvector3d.h>

#include <cmath>
#include <vector>

#include <qvector3d.h>


Sphere::Sphere(int num_slices, int num_stacks, float r)
{
Expand Down
27 changes: 27 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Tools.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#include "Tools.h"

#include <fstream>
#include <iostream>
#include <vector>


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<char> bytes(file_size);
ifs.read(&bytes[0], file_size);

return std::string(&bytes[0], file_size);
}
16 changes: 1 addition & 15 deletions Arrangement_on_surface_2/demo/earth/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,10 @@
#ifndef TOOLS_H
#define TOOLS_H

#include <fstream>
#include <string>
#include <vector>


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<char> 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
4 changes: 2 additions & 2 deletions Arrangement_on_surface_2/demo/earth/World_coordinate_axes.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#include "World_coordinate_axes.h"

#include <qvector3d.h>

#include <vector>

#include <qvector3d.h>


World_coord_axes::World_coord_axes(float length)
{
Expand Down
44 changes: 25 additions & 19 deletions Arrangement_on_surface_2/demo/earth/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>

#include <QApplication>
#include <QLabel>
Expand All @@ -7,30 +15,28 @@
#include "mainwidget.h"
#endif

#include <iostream>
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();
}
15 changes: 5 additions & 10 deletions Arrangement_on_surface_2/demo/earth/mainwidget.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

#include "mainwidget.h"

#include <QMouseEvent>

#include <cmath>
#include <iostream>
#include <string>

#include <QMouseEvent>


MainWidget::~MainWidget()
{
Expand All @@ -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());
Expand All @@ -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<Geodesic_arcs> m_geodesic_arcs;

void MainWidget::initializeGL()
{
initializeOpenGLFunctions();
Expand Down
12 changes: 7 additions & 5 deletions Arrangement_on_surface_2/demo/earth/mainwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#include <QVector2D>
#include <QBasicTimer>

#include <qopenglwidget.h>

#include <memory>

#include <qopenglwidget.h>

#include "Camera.h"
#include "Common_defs.h"
#include "Geodesic_arcs.h"
#include "Shader_program.h"
#include "Sphere.h"
#include "World_coordinate_axes.h"
Expand All @@ -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;
Expand All @@ -53,6 +54,7 @@ class MainWidget : public QOpenGLWidget, protected OpenGLFunctionsBase
// Objects in the scene
std::unique_ptr<Sphere> m_sphere;
std::unique_ptr<World_coord_axes> m_world_coord_axes;
std::unique_ptr<Geodesic_arcs> m_geodesic_arcs;

// Shaders
Shader_program m_sp_smooth;
Expand Down

0 comments on commit 2d7db03

Please sign in to comment.