sytling and other corrections

This commit is contained in:
denizdiktas 2023-06-15 15:56:52 +03:00
parent 96be82f0cc
commit 2d7db030cd
9 changed files with 92 additions and 83 deletions

View File

@ -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
)

View File

@ -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();
@ -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)));
@ -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

View File

@ -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)
{

View File

@ -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);
}

View File

@ -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

View File

@ -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)
{

View File

@ -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 <denizdiktas@gmail.com>
#include <QApplication>
#include <QLabel>
@ -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();
}

View File

@ -1,12 +1,12 @@
#include "mainwidget.h"
#include <QMouseEvent>
#include <cmath>
#include <iostream>
#include <string>
#include <QMouseEvent>
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<Geodesic_arcs> m_geodesic_arcs;
void MainWidget::initializeGL()
{
initializeOpenGLFunctions();

View File

@ -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"
@ -31,10 +32,10 @@ public:
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 @@ private:
// 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;