From 77fc314f897f882dfe85604013e62c54a67cbb06 Mon Sep 17 00:00:00 2001 From: James Hogan Date: Tue, 18 Nov 2008 03:47:00 +0000 Subject: [PATCH] Basic globe rendering --- CMakeLists.txt | 4 + geo/CMakeLists.txt | 25 + tcViewportWidget.cpp => geo/tcElevationData.cpp | 15 +- tcViewportWidget.h => geo/tcElevationData.h | 22 +- tcMainWindow.h => geo/tcGeo.h | 90 +++- tcViewportWidget.cpp => geo/tcGeoData.cpp | 12 +- tcMainWindow.h => geo/tcGeoData.h | 48 +- tcMainWindow.h => geo/tcGeoVector.h | 83 ++- tcViewportWidget.cpp => geo/tcGlobe.cpp | 69 ++- tcMainWindow.h => geo/tcGlobe.h | 50 +- tcViewportWidget.cpp => geo/tcObserver.cpp | 11 +- tcViewportWidget.h => geo/tcObserver.h | 20 +- tcMainWindow.cpp => geo/tcPhotographyData.cpp | 18 +- tcMainWindow.h => geo/tcPhotographyData.h | 32 +- tcMainWindow.cpp => geo/tcRangeSpectrum.cpp | 50 +- tcMainWindow.h => geo/tcRangeSpectrum.h | 44 +- tcViewportWidget.cpp => geo/tcSensor.cpp | 13 +- tcMainWindow.h => geo/tcSensor.h | 44 +- tcMainWindow.cpp => geo/tcSpectrum.cpp | 23 +- tcMainWindow.h => geo/tcSpectrum.h | 39 +- main.cpp | 2 +- maths/TemplateMaths.h | 164 ++++++ maths/Vector.h | 643 ++++++++++++++++++++++++ tcMainWindow.cpp | 4 + tcMainWindow.h | 10 +- tcViewportWidget.cpp | 54 ++ tcViewportWidget.h | 39 +- 27 files changed, 1405 insertions(+), 223 deletions(-) create mode 100644 geo/CMakeLists.txt copy tcViewportWidget.cpp => geo/tcElevationData.cpp (86%) copy tcViewportWidget.h => geo/tcElevationData.h (82%) copy tcMainWindow.h => geo/tcGeo.h (53%) copy tcViewportWidget.cpp => geo/tcGeoData.cpp (87%) copy tcMainWindow.h => geo/tcGeoData.h (71%) copy tcMainWindow.h => geo/tcGeoVector.h (55%) copy tcViewportWidget.cpp => geo/tcGlobe.cpp (54%) copy tcMainWindow.h => geo/tcGlobe.h (69%) copy tcViewportWidget.cpp => geo/tcObserver.cpp (87%) copy tcViewportWidget.h => geo/tcObserver.h (83%) copy tcMainWindow.cpp => geo/tcPhotographyData.cpp (84%) copy tcMainWindow.h => geo/tcPhotographyData.h (76%) copy tcMainWindow.cpp => geo/tcRangeSpectrum.cpp (69%) copy tcMainWindow.h => geo/tcRangeSpectrum.h (70%) copy tcViewportWidget.cpp => geo/tcSensor.cpp (87%) copy tcMainWindow.h => geo/tcSensor.h (74%) copy tcMainWindow.cpp => geo/tcSpectrum.cpp (83%) copy tcMainWindow.h => geo/tcSpectrum.h (74%) create mode 100644 maths/TemplateMaths.h create mode 100644 maths/Vector.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 562eae0..1341d20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,10 @@ find_package(Qt4 REQUIRED) set(QT_USE_QTOPENGL true) include(${QT_USE_FILE}) include_directories(${QT_INCLUDES} + maths + geo ) +add_subdirectory(geo) set(tecorrec_SRCS main.cpp @@ -25,5 +28,6 @@ add_executable(tecorrec ${tecorrec_SRCS} ${tecorrec_MOCS}) target_link_libraries(tecorrec ${QT_LIBRARIES} + tecorrec_geo ) diff --git a/geo/CMakeLists.txt b/geo/CMakeLists.txt new file mode 100644 index 0000000..caa9cfa --- /dev/null +++ b/geo/CMakeLists.txt @@ -0,0 +1,25 @@ +find_package(Qt4 REQUIRED) + +set(QT_USE_QTOPENGL true) +include(${QT_USE_FILE}) +include_directories(${QT_INCLUDES} +) + +set(tecorrec_geo_SRCS + tcObserver.cpp + tcGlobe.cpp + tcGeoData.cpp + tcElevationData.cpp + tcPhotographyData.cpp + tcSensor.cpp + tcSpectrum.cpp + tcRangeSpectrum.cpp +) + +set(tecorrec_geo_HEADERS +) + +qt4_wrap_cpp(tecorrec_geo_MOCS ${tecorrec_geo_HEADERS}) + +add_library(tecorrec_geo ${tecorrec_geo_SRCS} ${tecorrec_geo_MOCS}) + diff --git a/tcViewportWidget.cpp b/geo/tcElevationData.cpp similarity index 86% copy from tcViewportWidget.cpp copy to geo/tcElevationData.cpp index 1f17965..635f93f 100644 --- a/tcViewportWidget.cpp +++ b/geo/tcElevationData.cpp @@ -18,23 +18,24 @@ ***************************************************************************/ /** - * @file tcViewportWidget.cpp - * @brief OpenGL viewport widget. + * @file tcElevationData.cpp + * @brief Terrain elevation data. */ -#include "tcViewportWidget.h" +#include "tcElevationData.h" /* * Constructors + destructor */ -/// Primary constructor. -tcViewportWidget::tcViewportWidget(QWidget* parent) -: QGLWidget(parent) +/// Default constructor. +tcElevationData::tcElevationData() +: tcGeoData(tcGeoData::ElevationData) { } /// Destructor. -tcViewportWidget::~tcViewportWidget() +tcElevationData::~tcElevationData() { } + diff --git a/tcViewportWidget.h b/geo/tcElevationData.h similarity index 82% copy from tcViewportWidget.h copy to geo/tcElevationData.h index e684cb2..aa23143 100644 --- a/tcViewportWidget.h +++ b/geo/tcElevationData.h @@ -17,32 +17,30 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _tcViewportWidget_h_ -#define _tcViewportWidget_h_ +#ifndef _tcElevationData_h_ +#define _tcElevationData_h_ /** - * @file tcViewportWidget.h - * @brief OpenGL viewport widget. + * @file tcElevationData.h + * @brief Terrain elevation data. */ -#include +#include "tcGeoData.h" -/// OpenGL viewport widget. -class tcViewportWidget : public QGLWidget +/// Terrain elevation data. +class tcElevationData : public tcGeoData { - Q_OBJECT - public: /* * Constructors + destructor */ - /// Primary constructor. - tcViewportWidget(QWidget* parent); + /// Default constructor. + tcElevationData(); /// Destructor. - ~tcViewportWidget(); + virtual ~tcElevationData(); }; #endif diff --git a/tcMainWindow.h b/geo/tcGeo.h similarity index 53% copy from tcMainWindow.h copy to geo/tcGeo.h index 5068d62..9b5b6b3 100644 --- a/tcMainWindow.h +++ b/geo/tcGeo.h @@ -17,44 +17,96 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _tcMainWindow_h_ -#define _tcMainWindow_h_ +#ifndef _tcGeo_h_ +#define _tcGeo_h_ /** - * @file tcMainWindow.h - * @brief Main application window. + * @file tcGeo.h + * @brief Geographical coordinates. */ -#include +/// Use doubles for angles. +typedef double tcGeoAngle; -class tcViewportWidget; - -/// Main application window. -class tcMainWindow : public QMainWindow +/// Geographical coordinates. +class tcGeo { - Q_OBJECT - public: /* * Constructors + destructor */ - /// Default constructor. - tcMainWindow(); + /// Primary constructor. + tcGeo() + : m_longitude(0.0) + , m_latitude(0.0) + { + } + + /// Primary constructor. + tcGeo(const tcGeoAngle lon, const tcGeoAngle lat) + : m_longitude(lon) + , m_latitude(lat) + { + } - /// Destructor. - ~tcMainWindow(); + /* + * Accessors + */ + + /// Get the longitude. + tcGeoAngle lon() const + { + return m_longitude; + } + + /// Get the latitude. + tcGeoAngle lat() const + { + return m_latitude; + } + + /* + * Mutators + */ + + /// Set the longitude. + void setLon(const tcGeoAngle lon) + { + m_longitude = lon; + } + + /// Set the latitude. + void setLat(const tcGeoAngle lat) + { + m_latitude = lat; + } + + /// Set the longitude and latitude. + void setLonLat(const tcGeoAngle lon, const tcGeoAngle lat) + { + m_longitude = lon; + m_latitude = lat; + } private: /* - * Widgets + * Variables + */ + + /** East-West geographical coordinate. + * Units are radians. + */ + tcGeoAngle m_longitude; + + /** North-South geographical coordinate. + * Units are radians. */ + tcGeoAngle m_latitude; - /// Main viewport. - tcViewportWidget* m_viewport; }; -#endif +#endif // _tcGeo_h_ diff --git a/tcViewportWidget.cpp b/geo/tcGeoData.cpp similarity index 87% copy from tcViewportWidget.cpp copy to geo/tcGeoData.cpp index 1f17965..289c524 100644 --- a/tcViewportWidget.cpp +++ b/geo/tcGeoData.cpp @@ -18,23 +18,23 @@ ***************************************************************************/ /** - * @file tcViewportWidget.cpp - * @brief OpenGL viewport widget. + * @file tcGeoData.cpp + * @brief Data for a section of the globe. */ -#include "tcViewportWidget.h" +#include "tcGeoData.h" /* * Constructors + destructor */ /// Primary constructor. -tcViewportWidget::tcViewportWidget(QWidget* parent) -: QGLWidget(parent) +tcGeoData::tcGeoData(DataType type) +: m_type(type) { } /// Destructor. -tcViewportWidget::~tcViewportWidget() +tcGeoData::~tcGeoData() { } diff --git a/tcMainWindow.h b/geo/tcGeoData.h similarity index 71% copy from tcMainWindow.h copy to geo/tcGeoData.h index 5068d62..69628fe 100644 --- a/tcMainWindow.h +++ b/geo/tcGeoData.h @@ -17,43 +17,59 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _tcMainWindow_h_ -#define _tcMainWindow_h_ +#ifndef _tcGeoData_h_ +#define _tcGeoData_h_ /** - * @file tcMainWindow.h - * @brief Main application window. + * @file tcGeoData.h + * @brief Data for a section of the globe. */ -#include +#include "tcGeo.h" -class tcViewportWidget; +#include -/// Main application window. -class tcMainWindow : public QMainWindow +/// Data for a section of the globe. +class tcGeoData { - Q_OBJECT - public: /* + * Types + */ + + /// Types of data. + enum DataType + { + ElevationData = 0, + PhotographicData = 1 + }; + + /* * Constructors + destructor */ - /// Default constructor. - tcMainWindow(); + /// Primary constructor. + tcGeoData(DataType type); /// Destructor. - ~tcMainWindow(); + virtual ~tcGeoData(); private: /* - * Widgets + * Variables */ - /// Main viewport. - tcViewportWidget* m_viewport; + /// Type of data. + DataType m_type; + + /// Time of collection. + QDateTime m_captureTime; + + /// Coordinates of corners of data. + tcGeo m_coordinates[2][2]; + }; #endif diff --git a/tcMainWindow.h b/geo/tcGeoVector.h similarity index 55% copy from tcMainWindow.h copy to geo/tcGeoVector.h index 5068d62..064e225 100644 --- a/tcMainWindow.h +++ b/geo/tcGeoVector.h @@ -17,44 +17,89 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _tcMainWindow_h_ -#define _tcMainWindow_h_ +#ifndef _tcGeoVector_h_ +#define _tcGeoVector_h_ /** - * @file tcMainWindow.h - * @brief Main application window. + * @file tcGeoVector.h + * @brief Geographical coordinates. */ -#include +/// Use doubles for angles. +typedef double tcGeoAngle; -class tcViewportWidget; - -/// Main application window. -class tcMainWindow : public QMainWindow +/// Geographical coordinates. +class tcGeoVector { - Q_OBJECT - public: /* * Constructors + destructor */ - /// Default constructor. - tcMainWindow(); + /// Primary constructor. + tcGeoVector() + : m_azimuth(0.0) + , m_elevation(0.0) + { + } + + /// Primary constructor. + tcGeoVector(const tcGeoAngle azimuth, const tcGeoAngle elevation) + : m_azimuth(azimuth) + , m_elevation(elevation) + { + } + + /* + * Accessors + */ + + /// Get the azimuth. + tcGeoAngle azim() const + { + return m_azimuth; + } + + /// Get the elevation. + tcGeoAngle elev() const + { + return m_elevation; + } + + /* + * Mutators + */ + + /// Set the azimuth. + void setAzim(const tcGeoAngle azimuth) + { + m_azimuth = azimuth; + } - /// Destructor. - ~tcMainWindow(); + /// Set the elevation. + void setElev(const tcGeoAngle elevation) + { + m_elevation = elevation; + } private: /* - * Widgets + * Variables + */ + + /** Azimuth (bearing). + * Units are radians. + */ + tcGeoAngle m_azimuth; + + /** Elevation (positive is upwards). + * Units are radians. */ + tcGeoAngle m_elevation; - /// Main viewport. - tcViewportWidget* m_viewport; }; -#endif +#endif // _tcGeoVector_h_ diff --git a/tcViewportWidget.cpp b/geo/tcGlobe.cpp similarity index 54% copy from tcViewportWidget.cpp copy to geo/tcGlobe.cpp index 1f17965..12c9361 100644 --- a/tcViewportWidget.cpp +++ b/geo/tcGlobe.cpp @@ -18,23 +18,80 @@ ***************************************************************************/ /** - * @file tcViewportWidget.cpp - * @brief OpenGL viewport widget. + * @file tcGlobe.cpp + * @brief Manages data for a globe. */ -#include "tcViewportWidget.h" +#include "tcGlobe.h" + +#include + +#include /* * Constructors + destructor */ /// Primary constructor. -tcViewportWidget::tcViewportWidget(QWidget* parent) -: QGLWidget(parent) +tcGlobe::tcGlobe(double meanRadius) +: m_meanRadius(meanRadius) +, m_data() { } /// Destructor. -tcViewportWidget::~tcViewportWidget() +tcGlobe::~tcGlobe() +{ +} + +/* + * Data sets + */ + +/// Add a dataset to the globe. +void tcGlobe::addDataSet(tcGeoData* data) { + m_data.push_back(data); +} + +/* + * Rendering + */ + +/// Render from the POV of an observer. +void tcGlobe::render(tcObserver* observer) +{ + glColor3f(0.0f, 1.0f, 0.0f); + + // Lines of longitude + for (int lat = 5; lat < 180; lat += 5) + { + double z = cos(M_PI/180*lat) * m_meanRadius; + double xy = sin(M_PI/180*lat) * m_meanRadius; + glBegin(GL_LINE_LOOP); + { + for (int lon = 0; lon < 360; ++lon) + { + glVertex3d(xy*sin(M_PI/180*lon), xy*cos(M_PI/180*lon), z); + } + } + glEnd(); + } + + // Lines of latitude + for (int lon = 0; lon < 360; lon += 5) + { + double x = sin(M_PI/180*lon) * m_meanRadius; + double y = cos(M_PI/180*lon) * m_meanRadius; + glBegin(GL_LINE_STRIP); + { + for (int lat = 10; lat <= 170; ++lat) + { + double z = cos(M_PI/180*lat) * m_meanRadius; + double xy = sin(M_PI/180*lat); + glVertex3d(xy*x, xy*y, z); + } + } + glEnd(); + } } diff --git a/tcMainWindow.h b/geo/tcGlobe.h similarity index 69% copy from tcMainWindow.h copy to geo/tcGlobe.h index 5068d62..6e146f9 100644 --- a/tcMainWindow.h +++ b/geo/tcGlobe.h @@ -17,43 +17,61 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _tcMainWindow_h_ -#define _tcMainWindow_h_ +#ifndef _tcGlobe_h_ +#define _tcGlobe_h_ /** - * @file tcMainWindow.h - * @brief Main application window. + * @file tcGlobe.h + * @brief Manages data for a globe. */ -#include +#include -class tcViewportWidget; +class tcGeoData; +class tcObserver; -/// Main application window. -class tcMainWindow : public QMainWindow +/** Manages data for a globe. + * Holds terrain elevation and imagery data. + */ +class tcGlobe { - Q_OBJECT - public: /* * Constructors + destructor */ - /// Default constructor. - tcMainWindow(); + /// Primary constructor. + tcGlobe(double meanRadius); /// Destructor. - ~tcMainWindow(); + virtual ~tcGlobe(); + + /* + * Data sets + */ + + /// Add a dataset to the globe. + void addDataSet(tcGeoData* data); + + /* + * Rendering + */ + + /// Render from the POV of an observer. + void render(tcObserver* observer); private: /* - * Widgets + * Variables */ - /// Main viewport. - tcViewportWidget* m_viewport; + /// Mean radius in metres. + double m_meanRadius; + + /// List of geo data sets. + QList m_data; }; #endif diff --git a/tcViewportWidget.cpp b/geo/tcObserver.cpp similarity index 87% copy from tcViewportWidget.cpp copy to geo/tcObserver.cpp index 1f17965..a31bfa0 100644 --- a/tcViewportWidget.cpp +++ b/geo/tcObserver.cpp @@ -18,23 +18,22 @@ ***************************************************************************/ /** - * @file tcViewportWidget.cpp - * @brief OpenGL viewport widget. + * @file tcObserver.cpp + * @brief Viewing information for an observer. */ -#include "tcViewportWidget.h" +#include "tcObserver.h" /* * Constructors + destructor */ /// Primary constructor. -tcViewportWidget::tcViewportWidget(QWidget* parent) -: QGLWidget(parent) +tcObserver::tcObserver() { } /// Destructor. -tcViewportWidget::~tcViewportWidget() +tcObserver::~tcObserver() { } diff --git a/tcViewportWidget.h b/geo/tcObserver.h similarity index 83% copy from tcViewportWidget.h copy to geo/tcObserver.h index e684cb2..86033ff 100644 --- a/tcViewportWidget.h +++ b/geo/tcObserver.h @@ -17,21 +17,17 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _tcViewportWidget_h_ -#define _tcViewportWidget_h_ +#ifndef _tcObserver_h_ +#define _tcObserver_h_ /** - * @file tcViewportWidget.h - * @brief OpenGL viewport widget. + * @file tcObserver.h + * @brief Viewing information for an observer. */ -#include - -/// OpenGL viewport widget. -class tcViewportWidget : public QGLWidget +/// Viewing information for an observer. +class tcObserver { - Q_OBJECT - public: /* @@ -39,10 +35,10 @@ class tcViewportWidget : public QGLWidget */ /// Primary constructor. - tcViewportWidget(QWidget* parent); + tcObserver(); /// Destructor. - ~tcViewportWidget(); + virtual ~tcObserver(); }; #endif diff --git a/tcMainWindow.cpp b/geo/tcPhotographyData.cpp similarity index 84% copy from tcMainWindow.cpp copy to geo/tcPhotographyData.cpp index 836365a..c8f751e 100644 --- a/tcMainWindow.cpp +++ b/geo/tcPhotographyData.cpp @@ -18,27 +18,25 @@ ***************************************************************************/ /** - * @file tcMainWindow.h - * @brief Main application window. + * @file tcPhotographyData.cpp + * @brief Terrain photography data. */ -#include "tcMainWindow.h" -#include "tcViewportWidget.h" +#include "tcPhotographyData.h" /* * Constructors + destructor */ /// Default constructor. -tcMainWindow::tcMainWindow() -: QMainWindow() -, m_viewport(new tcViewportWidget(this)) +tcPhotographyData::tcPhotographyData() +: tcGeoData(tcGeoData::PhotographicData) +, m_sensor(0) +, m_sunDirection(0) { - setCentralWidget(m_viewport); } /// Destructor. -tcMainWindow::~tcMainWindow() +tcPhotographyData::~tcPhotographyData() { } - diff --git a/tcMainWindow.h b/geo/tcPhotographyData.h similarity index 76% copy from tcMainWindow.h copy to geo/tcPhotographyData.h index 5068d62..97d7cde 100644 --- a/tcMainWindow.h +++ b/geo/tcPhotographyData.h @@ -17,23 +17,22 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _tcMainWindow_h_ -#define _tcMainWindow_h_ +#ifndef _tcPhotographyData_h_ +#define _tcPhotographyData_h_ /** - * @file tcMainWindow.h - * @brief Main application window. + * @file tcPhotographyData.h + * @brief Terrain photography data. */ -#include +#include "tcGeoData.h" -class tcViewportWidget; +class tcSensor; +class tcGeoVector; -/// Main application window. -class tcMainWindow : public QMainWindow +/// Terrain photography data. +class tcPhotographyData : public tcGeoData { - Q_OBJECT - public: /* @@ -41,19 +40,22 @@ class tcMainWindow : public QMainWindow */ /// Default constructor. - tcMainWindow(); + tcPhotographyData(); /// Destructor. - ~tcMainWindow(); + virtual ~tcPhotographyData(); private: /* - * Widgets + * Variables */ - /// Main viewport. - tcViewportWidget* m_viewport; + /// Sensor which collected the data. + tcSensor* m_sensor; + + /// Direction of the sun in local space. + tcGeoVector* m_sunDirection; }; #endif diff --git a/tcMainWindow.cpp b/geo/tcRangeSpectrum.cpp similarity index 69% copy from tcMainWindow.cpp copy to geo/tcRangeSpectrum.cpp index 836365a..7e26fa4 100644 --- a/tcMainWindow.cpp +++ b/geo/tcRangeSpectrum.cpp @@ -18,27 +18,59 @@ ***************************************************************************/ /** - * @file tcMainWindow.h - * @brief Main application window. + * @file tcRangeSpectrum.h + * @brief Frequency spectrum of a uniform value in a range. */ -#include "tcMainWindow.h" -#include "tcViewportWidget.h" +#include "tcRangeSpectrum.h" + +#include /* * Constructors + destructor */ /// Default constructor. -tcMainWindow::tcMainWindow() -: QMainWindow() -, m_viewport(new tcViewportWidget(this)) +tcRangeSpectrum::tcRangeSpectrum(float max, float x, float y) +: tcSpectrum() +, m_max(max) +, m_x(x) +, m_y(y) { - setCentralWidget(m_viewport); + Q_ASSERT(y >= x); } /// Destructor. -tcMainWindow::~tcMainWindow() +tcRangeSpectrum::~tcRangeSpectrum() +{ +} + +/* + * Virtual interface + */ + +float tcRangeSpectrum::mean() const +{ + return (m_x + m_y) / 2.0f; +} + +float tcRangeSpectrum::integrate() const { + return (m_y - m_x) * m_max; } +float tcRangeSpectrum::integrate(float x) const +{ + if (x <= m_x) + { + return 0.0f; + } + else + { + if (x >= m_y) + { + x = m_y; + } + return (x - m_x) * m_max; + } +} diff --git a/tcMainWindow.h b/geo/tcRangeSpectrum.h similarity index 70% copy from tcMainWindow.h copy to geo/tcRangeSpectrum.h index 5068d62..08b7b66 100644 --- a/tcMainWindow.h +++ b/geo/tcRangeSpectrum.h @@ -17,23 +17,19 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _tcMainWindow_h_ -#define _tcMainWindow_h_ +#ifndef _tcRangeSpectrum_h_ +#define _tcRangeSpectrum_h_ /** - * @file tcMainWindow.h - * @brief Main application window. + * @file tcRangeSpectrum.h + * @brief Frequency spectrum of a uniform value in a range. */ -#include +#include "tcSpectrum.h" -class tcViewportWidget; - -/// Main application window. -class tcMainWindow : public QMainWindow +/// Frequency spectrum. +class tcRangeSpectrum : public tcSpectrum { - Q_OBJECT - public: /* @@ -41,19 +37,35 @@ class tcMainWindow : public QMainWindow */ /// Default constructor. - tcMainWindow(); + tcRangeSpectrum(float max, float x, float y); /// Destructor. - ~tcMainWindow(); + virtual ~tcRangeSpectrum(); + + /* + * Virtual interface + */ + + // Reimplemented + virtual float mean() const; + + // Reimplemented + virtual float integrate() const; + + // Reimplemented + virtual float integrate(float x) const; private: /* - * Widgets + * Variables */ - /// Main viewport. - tcViewportWidget* m_viewport; + /// Value for the range. + float m_max; + + /// Start and end of the value. + float m_x, m_y; }; #endif diff --git a/tcViewportWidget.cpp b/geo/tcSensor.cpp similarity index 87% copy from tcViewportWidget.cpp copy to geo/tcSensor.cpp index 1f17965..595b0e4 100644 --- a/tcViewportWidget.cpp +++ b/geo/tcSensor.cpp @@ -18,23 +18,24 @@ ***************************************************************************/ /** - * @file tcViewportWidget.cpp - * @brief OpenGL viewport widget. + * @file tcSensor.cpp + * @brief Description of an electromagnetic sensor. */ -#include "tcViewportWidget.h" +#include "tcSensor.h" /* * Constructors + destructor */ /// Primary constructor. -tcViewportWidget::tcViewportWidget(QWidget* parent) -: QGLWidget(parent) +tcSensor::tcSensor(SensorType type) +: m_type(type) +, m_sensitivity(0) { } /// Destructor. -tcViewportWidget::~tcViewportWidget() +tcSensor::~tcSensor() { } diff --git a/tcMainWindow.h b/geo/tcSensor.h similarity index 74% copy from tcMainWindow.h copy to geo/tcSensor.h index 5068d62..0122304 100644 --- a/tcMainWindow.h +++ b/geo/tcSensor.h @@ -17,43 +17,53 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _tcMainWindow_h_ -#define _tcMainWindow_h_ +#ifndef _tcSensor_h_ +#define _tcSensor_h_ /** - * @file tcMainWindow.h - * @brief Main application window. + * @file tcSensor.h + * @brief Description of an electromagnetic sensor. */ -#include +class tcSpectrum; -class tcViewportWidget; - -/// Main application window. -class tcMainWindow : public QMainWindow +/// Description of an electromagnetic sensor. +class tcSensor { - Q_OBJECT - public: /* + * Types + */ + + /// Types of data. + enum SensorType + { + Photographic = 0, + }; + + /* * Constructors + destructor */ - /// Default constructor. - tcMainWindow(); + /// Primary constructor. + tcSensor(SensorType type); /// Destructor. - ~tcMainWindow(); + virtual ~tcSensor(); private: /* - * Widgets + * Variables */ - /// Main viewport. - tcViewportWidget* m_viewport; + /// Type of sensor. + SensorType m_type; + + /// Wavelength sensitivity distribution. + tcSpectrum* m_sensitivity; + }; #endif diff --git a/tcMainWindow.cpp b/geo/tcSpectrum.cpp similarity index 83% copy from tcMainWindow.cpp copy to geo/tcSpectrum.cpp index 836365a..4b5772b 100644 --- a/tcMainWindow.cpp +++ b/geo/tcSpectrum.cpp @@ -18,27 +18,32 @@ ***************************************************************************/ /** - * @file tcMainWindow.h - * @brief Main application window. + * @file tcSpectrum.cpp + * @brief Frequency spectrum. */ -#include "tcMainWindow.h" -#include "tcViewportWidget.h" +#include "tcSpectrum.h" /* * Constructors + destructor */ /// Default constructor. -tcMainWindow::tcMainWindow() -: QMainWindow() -, m_viewport(new tcViewportWidget(this)) +tcSpectrum::tcSpectrum() { - setCentralWidget(m_viewport); } /// Destructor. -tcMainWindow::~tcMainWindow() +tcSpectrum::~tcSpectrum() { } +/* + * Virtual interface + */ + +/// Range integral (@p x, @p y). +float tcSpectrum::integrate(float x, float y) const +{ + return integrate(y) - integrate(x); +} diff --git a/tcMainWindow.h b/geo/tcSpectrum.h similarity index 74% copy from tcMainWindow.h copy to geo/tcSpectrum.h index 5068d62..b4392e4 100644 --- a/tcMainWindow.h +++ b/geo/tcSpectrum.h @@ -17,23 +17,17 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _tcMainWindow_h_ -#define _tcMainWindow_h_ +#ifndef _tcSpectrum_h_ +#define _tcSpectrum_h_ /** - * @file tcMainWindow.h - * @brief Main application window. + * @file tcSpectrum.h + * @brief Frequency spectrum. */ -#include - -class tcViewportWidget; - -/// Main application window. -class tcMainWindow : public QMainWindow +/// Frequency spectrum. +class tcSpectrum { - Q_OBJECT - public: /* @@ -41,19 +35,26 @@ class tcMainWindow : public QMainWindow */ /// Default constructor. - tcMainWindow(); + tcSpectrum(); /// Destructor. - ~tcMainWindow(); - - private: + virtual ~tcSpectrum(); /* - * Widgets + * Virtual interface */ - /// Main viewport. - tcViewportWidget* m_viewport; + /// Get the mean input value. + virtual float mean() const = 0; + + /// Full integral (-inf, inf). + virtual float integrate() const = 0; + + /// Partial integral (-inf, @p x). + virtual float integrate(float x) const = 0; + + /// Range integral (@p x, @p y). + virtual float integrate(float x, float y) const; }; #endif diff --git a/main.cpp b/main.cpp index ad935a6..d046565 100644 --- a/main.cpp +++ b/main.cpp @@ -25,6 +25,6 @@ int main(int argc, char **argv) { QApplication app(argc, argv); tcMainWindow mainWindow; - mainWindow.show(); + mainWindow.showMaximized(); return app.exec(); } diff --git a/maths/TemplateMaths.h b/maths/TemplateMaths.h new file mode 100644 index 0000000..8cd3097 --- /dev/null +++ b/maths/TemplateMaths.h @@ -0,0 +1,164 @@ +/*************************************************************************** + * This file is part of Tecorrec. * + * Copyright 2008 James Hogan * + * * + * Tecorrec is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 2 of the License, or * + * (at your option) any later version. * + * * + * Tecorrec is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with Tecorrec. If not, write to the Free Software Foundation, * + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +/** + * @file TemplateMaths.h + * @brief Template maths functions, some unecessary. + * @author James Hogan + * @note Copyright (C) 2007 + * + * @version 1 : From Computer Graphics and Visualisation Open Assessment. + */ + +#ifndef _maths_TemplateMaths_h +#define _maths_TemplateMaths_h + +#include + +// Defines template functions for merging fp functions with 1 argument +#define DEFINE_FP1_TEMPLATE_FUNCTIONS_SAFE(NAME, FLOAT, DOUBLE) \ + template \ + inline T NAME(T arg) \ + { \ + return arg.NAME(); \ + } \ + template <> inline float NAME(float arg) \ + { \ + return FLOAT(arg); \ + } \ + template <> inline double NAME(double arg) \ + { \ + return DOUBLE(arg); \ + } \ + +// Defines template functions for merging fp functions with 1 argument +#define DEFINE_FP1_TEMPLATE_FUNCTIONS(NAME, FLOAT, DOUBLE) \ + template \ + inline T NAME(T arg); \ + template <> inline float NAME(float arg) \ + { \ + return FLOAT(arg); \ + } \ + template <> inline double NAME(double arg) \ + { \ + return DOUBLE(arg); \ + } \ + +// Defines template functions for merging fp functions with 2 arguments +#define DEFINE_FP2_TEMPLATE_FUNCTIONS(NAME, FLOAT, DOUBLE) \ + template \ + inline T NAME(T arg1, T arg2); \ + template <> inline float NAME(float arg1, float arg2) \ + { \ + return FLOAT(arg1, arg2); \ + } \ + template <> inline double NAME(double arg1, double arg2) \ + { \ + return DOUBLE(arg1, arg2); \ + } \ + +namespace maths { + DEFINE_FP1_TEMPLATE_FUNCTIONS_SAFE(sqrt, std::sqrt, std::sqrt) + + DEFINE_FP1_TEMPLATE_FUNCTIONS(sin, std::sin, std::sin) + DEFINE_FP1_TEMPLATE_FUNCTIONS(cos, std::cos, std::cos) + DEFINE_FP1_TEMPLATE_FUNCTIONS(tan, std::tan, std::tan) + + DEFINE_FP1_TEMPLATE_FUNCTIONS(asin, std::asin, std::asin) + DEFINE_FP1_TEMPLATE_FUNCTIONS(acos, std::acos, std::acos) + DEFINE_FP1_TEMPLATE_FUNCTIONS(atan, std::atan, std::atan) + + DEFINE_FP2_TEMPLATE_FUNCTIONS(atan2, std::atan2, std::atan2) + + // Cleanup internal preprocessor definitions. + #undef DEFINE_FP1_TEMPLATE_FUNCTIONS + #undef DEFINE_FP2_TEMPLATE_FUNCTIONS + + /// Write values into a 2 dimentional vector. + /** + * @param T Data type of vector components. + * @param vec Vector pointer to array of @a T. + * @param x X coordinate of vector. + * @param y Y coordinate of vector. + */ + template + inline T * setVector2(const T * vec, const T x, const T y) + { + vec[0] = x; + vec[1] = y; + return vec; + } + + /// Write values into a 3 dimentional vector. + /** + * @param T Data type of vector components. + * @param vec Vector pointer to array of @a T. + * @param x X coordinate of vector. + * @param y Y coordinate of vector. + * @param z Z coordinate of vector. + */ + template + inline T * setVector3(T * const vec, const T x, const T y, const T z) + { + vec[0] = x; + vec[1] = y; + vec[2] = z; + return vec; + } + + /// Write values into a 3 dimentional vector. + /** + * @param T Data type of vector components. + * @param vec Vector pointer to array of @a T. + * @param x X coordinate of vector. + * @param y Y coordinate of vector. + * @param z Z coordinate of vector. + */ + template + inline T * setVector4(T * const vec, const T x, const T y, const T z, const T w) + { + vec[0] = x; + vec[1] = y; + vec[2] = z; + vec[3] = w; + return vec; + } + + + /// Find the square of a number + /** + * Useful when the expression is complex and a macro should be avoided + */ + template + inline T sqr(T value) + { + return value*value; + } + + /// Zero in different types + /** + */ + template + inline T zero() + { + return (T)0; + } +} + +#endif // _maths_TemplateMaths_h diff --git a/maths/Vector.h b/maths/Vector.h new file mode 100644 index 0000000..6e2dc34 --- /dev/null +++ b/maths/Vector.h @@ -0,0 +1,643 @@ +/*************************************************************************** + * This file is part of Tecorrec. * + * Copyright 2008 James Hogan * + * * + * Tecorrec is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 2 of the License, or * + * (at your option) any later version. * + * * + * Tecorrec is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with Tecorrec. If not, write to the Free Software Foundation, * + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +/** + * @file Vector.h + * @brief Vector of values, designed for spacial coordinate vectors. + * @author James Hogan + * @note Copyright (C) 2007 + * + * @version 1 : From Computer Graphics and Visualisation Open Assessment. + */ + +#ifndef _maths_Vector_h +#define _maths_Vector_h + +#include "TemplateMaths.h" + +#include +#include + +namespace maths +{ + + /// Vector. + /** + * @param N int Number of components in the vector. + * @param T typename Type of the components of the vector. + */ + template + class Vector + { + public: + T v[N]; + + enum { + length = N + }; + typedef T Scalar; + + /// Default constructor (Does not initialise the values!) + inline Vector() + { + } + + inline explicit Vector(T value) + { + for (int i = 0; i < N; ++i) + { + v[i] = value; + } + } + inline Vector(T x, T y) + { + v[0] = x; + v[1] = y; + if (N > 2) + { + for (int i = 2; i < N; ++i) + { + v[i] = maths::zero(); + } + } + } + inline Vector(T x, T y, T z) + { + v[0] = x; + v[1] = y; + if (N > 2) + { + v[2] = z; + if (N > 3) + { + for (int i = 3; i < N; ++i) + { + v[i] = maths::zero(); + } + } + } + } + inline Vector(T x, T y, T z, T w) + { + v[0] = x; + v[1] = y; + if (N > 2) + { + v[2] = z; + if (N > 3) + { + v[3] = w; + if (N > 4) + { + for (int i = 4; i < N; ++i) + { + v[i] = maths::zero(); + } + } + } + } + } + inline explicit Vector(const T * vec) + { + for (int i = 0; i < N; ++i) + { + v[i] = vec[i]; + } + } + template inline explicit Vector(const Vector & copy) + { + int i = 0; + for (; i < N && i < M; ++i) + { + v[i] = (T)copy.v[i]; + } + for (; i < N; ++i) + { + v[i] = maths::zero(); + } + } + + inline const Vector & set() + { + for (int i = 0; i < N; ++i) + { + v[i] = maths::zero(); + } + return *this; + } + inline const Vector & set(T all) + { + for (int i = 0; i < N; ++i) + { + v[i] = all; + } + return *this; + } + inline const Vector & set(T x, T y) + { + v[0] = x; + v[1] = y; + if (N > 2) + { + for (int i = 2; i < N; ++i) + { + v[i] = maths::zero(); + } + } + return *this; + } + inline const Vector & set(T x, T y, T z) + { + v[0] = x; + v[1] = y; + if (N > 2) + { + v[2] = z; + if (N > 3) + { + for (int i = 3; i < N; ++i) + { + v[i] = maths::zero(); + } + } + } + return *this; + } + inline const Vector & set(T x, T y, T z, T w) + { + v[0] = x; + v[1] = y; + if (N > 2) + { + v[2] = z; + if (N > 3) + { + v[3] = w; + if (N > 4) + { + for (int i = 4; i < N; ++i) + { + v[i] = maths::zero(); + } + } + } + } + return *this; + } + inline const Vector & set(const Vector<3,T> xyz, T w) + { + v[0] = xyz[0]; + v[1] = xyz[1]; + if (N > 2) + { + v[2] = xyz[2]; + if (N > 3) + { + v[3] = w; + if (N > 4) + { + for (int i = 4; i < N; ++i) + { + v[i] = maths::zero(); + } + } + } + } + return *this; + } + + /// Setter for specific component. + template + inline void setComponent(const T newValue) + { + v[X] = newValue; + } + + /// Getter for specific component. + template + inline T getComponent() const + { + return v[X]; + } + + /// Concatination operator, append a number. + inline Vector operator , (T f) const + { + Vector result; + for (int i = 0; i < N; ++i) + { + result[i] = v[i]; + } + result[N] = f; + return result; + } + + /// Concatination operator, prepend a number. + inline friend Vector operator , (T f, const Vector & vector) + { + Vector result; + result[0] = f; + for (int i = 0; i < N; ++i) + { + result[i+1] = vector[i]; + } + return result; + } + + /// Concatination operator, append a vector. + template + inline Vector operator , (const Vector & vector) const + { + Vector result; + for (int i = 0; i < N; ++i) + { + result[i] = v[i]; + } + for (int i = 0; i < M; ++i) + { + result[N+i] = vector[i]; + } + return result; + } + + /// Slice out of the vector a reference. + template + inline Vector & slice() + { + return *(Vector*)(v+S); + } + + /// Slice out of the vector a reference. + template + inline const Vector & slice() const + { + return *(Vector*)(v+S); + } + + inline T & operator [] (int index) + { + return v[index]; + } + inline const T & operator [] (int index) const + { + return v[index]; + } + + inline operator T * () + { + return v; + } + inline operator const T * () const + { + return v; + } + + inline Vector operator - () const + { + Vector ret; + for (int i = 0; i < N; ++i) + { + ret[i] = -v[i]; + } + return ret; + } + + template + inline Vector & operator += (const Vector & rhs) + { + for (int i = 0; i < N; ++i) + { + v[i] += rhs.v[i]; + } + return *this; + } + template + inline Vector operator + (const Vector & rhs) const + { + Vector ret = *this; + return ret += rhs; + } + + inline Vector & operator -= (const Vector & rhs) + { + for (int i = 0; i < N; ++i) + { + v[i] -= rhs.v[i]; + } + return *this; + } + inline Vector operator - (const Vector & rhs) const + { + Vector ret = *this; + return ret -= rhs; + } + + inline Vector & operator *= (const T rhs) + { + for (int i = 0; i < N; ++i) + { + v[i] *= rhs; + } + return *this; + } + inline Vector operator * (const T rhs) const + { + Vector ret = *this; + return ret *= rhs; + } + inline friend Vector operator * (const T lhs, const Vector & rhs) + { + return rhs * lhs; + } + + /// Dot product + inline T operator * (const Vector & rhs) const + { + T fDot = maths::zero(); + for (int i = 0; i < N; ++i) + { + fDot += v[i]*rhs.v[i]; + } + return fDot; + } + + /// Dot quotient + inline T operator / (const Vector & rhs) const + { + // a = B/C = (B*C)/(C*C) + return operator * (rhs) / rhs.sqr(); + } + + inline Vector & operator /= (const T rhs) + { + for (int i = 0; i < N; ++i) + { + v[i] /= rhs; + } + return *this; + } + inline Vector operator / (const T rhs) const + { + Vector ret = *this; + return ret /= rhs; + } + inline friend Vector operator / (const T lhs, const Vector & rhs) + { + return rhs * (lhs / rhs.sqr()); + } + + inline T sqr() const + { + return tsqr(); + } + template + inline U tsqr() const + { + U ret = maths::zero(); + for (int i = 0; i < N; ++i) + { + ret += maths::sqr(v[i]); + } + return ret; + } + + inline Vector inv() const + { + return *this / sqr(); + } + + inline T mag() const + { + return tmag(); + } + template + inline U tmag() const + { + return maths::sqrt(tsqr()); + } + + + inline Vector & normalize() + { + return operator /= (mag()); + } + inline Vector normalized() const + { + return operator / (mag()); + } + inline Vector & resize(T tLength) + { + return operator *= (tLength / mag()); + } + inline Vector resized(T tLength) const + { + return operator * (tLength / mag()); + } + + + // predicates + + /// Equality + inline bool operator == (const Vector & rhs) const + { + for (int i = 0; i < N; ++i) + { + if (v[i] != rhs.v[i]) + { + return false; + } + } + return true; + } + /// Nonequality + inline bool operator != (const Vector & rhs) const + { + for (int i = 0; i < N; ++i) + { + if (v[i] != rhs.v[i]) + { + return true; + } + } + return false; + } + + /// Compare the magnitude of vectors. + inline bool operator < (const Vector & rhs) const + { + return sqr() < rhs.sqr(); + } + /// Compare the magnitude of the vector with a scalar magnitude. + inline bool operator < (const T & rhs) const + { + return sqr() < rhs*rhs; + } + /// Compare the magnitude of the vector with a scalar magnitude. + inline friend bool operator < (const T & lhs, const Vector & rhs) + { + return lhs*lhs < rhs.sqr(); + } + /// Compare the magnitude of vectors. + inline bool operator <= (const Vector & rhs) const + { + return sqr() <= rhs.sqr(); + } + /// Compare the magnitude of the vector with a scalar magnitude. + inline bool operator <= (const T & rhs) const + { + return sqr() <= rhs*rhs; + } + /// Compare the magnitude of the vector with a scalar magnitude. + inline friend bool operator <= (const T & lhs, const Vector & rhs) + { + return lhs*lhs <= rhs.sqr(); + } + /// Compare the magnitude of vectors. + inline bool operator > (const Vector & rhs) const + { + return sqr() > rhs.sqr(); + } + /// Compare the magnitude of the vector with a scalar magnitude. + inline bool operator > (const T & rhs) const + { + return sqr() > rhs*rhs; + } + /// Compare the magnitude of the vector with a scalar magnitude. + inline friend bool operator > (const T & lhs, const Vector & rhs) + { + return lhs*lhs > rhs.sqr(); + } + /// Compare the magnitude of vectors. + inline bool operator >= (const Vector & rhs) const + { + return sqr() >= rhs.sqr(); + } + /// Compare the magnitude of the vector with a scalar magnitude. + inline bool operator >= (const T & rhs) const + { + return sqr() >= rhs*rhs; + } + /// Compare the magnitude of the vector with a scalar magnitude. + inline friend bool operator >= (const T & lhs, const Vector & rhs) + { + return lhs*lhs >= rhs.sqr(); + } + + /// Find whether the vector zero. + inline bool zero() const + { + for (int i = 0; i < N; ++i) + { + if (v[i]) + { + return false; + } + } + return true; + } + + + inline operator std::string() const; + }; // ::maths::Vector + + template + inline Vector & add (Vector & dest, const Vector & lhs, const Vector & rhs) + { + for (int i = 0; i < N; ++i) + { + dest.v[i] = lhs.v[i] + rhs.v[i]; + } + return dest; + } + + template + inline Vector & sub (Vector & dest, const Vector & lhs, const Vector & rhs) + { + for (int i = 0; i < N; ++i) + { + dest.v[i] = lhs.v[i] - rhs.v[i]; + } + return dest; + } + + template + inline Vector<3,T> & cross (Vector<3,T> & dest, const Vector<3,T> & lhs, const Vector<3,T> & rhs) + { + dest.v[0] = lhs.v[1]*rhs.v[2] - lhs.v[2]*rhs.v[1]; + dest.v[1] = lhs.v[2]*rhs.v[0] - lhs.v[0]*rhs.v[2]; + dest.v[2] = lhs.v[0]*rhs.v[1] - lhs.v[1]*rhs.v[0]; + return dest; + } + + template + inline Vector<3,T> cross (const Vector<3,T> & lhs, const Vector<3,T> & rhs) + { + Vector<3, T> dest; + dest.v[0] = lhs.v[1]*rhs.v[2] - lhs.v[2]*rhs.v[1]; + dest.v[1] = lhs.v[2]*rhs.v[0] - lhs.v[0]*rhs.v[2]; + dest.v[2] = lhs.v[0]*rhs.v[1] - lhs.v[1]*rhs.v[0]; + return dest; + } + + template + inline Vector<4,T> homogenous(Vector<3,T> & vec, T homogenousness = (T)1) + { + Vector<4,T> ret(vec); + ret[3] = homogenousness; + return ret; + } + + /// Get the distance from a plane. + template + inline T plane(const Vector<4, T> & plane, const Vector<3, T> & point) + { + return plane[0]*point[0] + plane[1]*point[1] + plane[2]*point[2] + plane[3]; + } + + + /// Write a vector to an output stream. + template + inline std::ostream & operator << (std::ostream & out, const Vector & v) + { + out << "(" << v[0]; + for (int i = 1; i < N; ++i) + { + out << ", " << v[i]; + } + return out << ")"; + } + /// Convert to a string using the above stream operator + template + inline Vector::operator std::string() const + { + std::stringstream ss; + ss << v; + return ss.str(); + } + + /// Basic function to create a one dimentional vector (scalar) which can then be expanded by concatination. + template + inline maths::Vector<1,T> Scalar(const T a) + { + return maths::Vector<1,T>(a); + } + +} // ::maths + +#endif // _maths_vector_h diff --git a/tcMainWindow.cpp b/tcMainWindow.cpp index 836365a..0e06cda 100644 --- a/tcMainWindow.cpp +++ b/tcMainWindow.cpp @@ -24,6 +24,7 @@ #include "tcMainWindow.h" #include "tcViewportWidget.h" +#include /* * Constructors + destructor @@ -33,12 +34,15 @@ tcMainWindow::tcMainWindow() : QMainWindow() , m_viewport(new tcViewportWidget(this)) +, m_globe(new tcGlobe(6378.1e3)) { + m_viewport->setGlobe(m_globe); setCentralWidget(m_viewport); } /// Destructor. tcMainWindow::~tcMainWindow() { + delete m_globe; } diff --git a/tcMainWindow.h b/tcMainWindow.h index 5068d62..f92d4fa 100644 --- a/tcMainWindow.h +++ b/tcMainWindow.h @@ -28,6 +28,7 @@ #include class tcViewportWidget; +class tcGlobe; /// Main application window. class tcMainWindow : public QMainWindow @@ -44,7 +45,7 @@ class tcMainWindow : public QMainWindow tcMainWindow(); /// Destructor. - ~tcMainWindow(); + virtual ~tcMainWindow(); private: @@ -54,6 +55,13 @@ class tcMainWindow : public QMainWindow /// Main viewport. tcViewportWidget* m_viewport; + + /* + * Objects + */ + + /// Globe object. + tcGlobe* m_globe; }; #endif diff --git a/tcViewportWidget.cpp b/tcViewportWidget.cpp index 1f17965..7ffab68 100644 --- a/tcViewportWidget.cpp +++ b/tcViewportWidget.cpp @@ -23,6 +23,8 @@ */ #include "tcViewportWidget.h" +#include +#include /* * Constructors + destructor @@ -31,10 +33,62 @@ /// Primary constructor. tcViewportWidget::tcViewportWidget(QWidget* parent) : QGLWidget(parent) +, m_observer(new tcObserver()) +, m_globe(0) { } /// Destructor. tcViewportWidget::~tcViewportWidget() { + delete m_observer; +} + +/* + * Modifiers + */ + +/// Set the globe object. +void tcViewportWidget::setGlobe(tcGlobe* globe) +{ + m_globe = globe; +} + +/* + * Rendering + */ + +void tcViewportWidget::initializeGL() +{ + glClearColor(0.0, 0.5, 1.0, 0.0); +} + +void tcViewportWidget::resizeGL(int w, int h) +{ + glViewport(0, 0, (GLint)w, (GLint)h); + + double aspect = (double)w / h; + + // Set up the camera + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-100.0*aspect, 100.0*aspect, -100.0, 100.0, 100.0, 20000e3); + glMatrixMode(GL_MODELVIEW); +} + +void tcViewportWidget::paintGL() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_DEPTH_TEST); + + glLoadIdentity(); + + glPushMatrix(); + { + glTranslatef(0.0f, 0.0f, -10000e3); + glRotatef(35.0f, -1.0f, 0.0f, 0.0f); + + m_globe->render(m_observer); + } + glPopMatrix(); } diff --git a/tcViewportWidget.h b/tcViewportWidget.h index e684cb2..b4773df 100644 --- a/tcViewportWidget.h +++ b/tcViewportWidget.h @@ -27,6 +27,9 @@ #include +class tcObserver; +class tcGlobe; + /// OpenGL viewport widget. class tcViewportWidget : public QGLWidget { @@ -42,7 +45,41 @@ class tcViewportWidget : public QGLWidget tcViewportWidget(QWidget* parent); /// Destructor. - ~tcViewportWidget(); + virtual ~tcViewportWidget(); + + /* + * Modifiers + */ + + /// Set the globe object. + void setGlobe(tcGlobe* globe); + + protected: + + /* + * Rendering + */ + + // Reimplemented + virtual void initializeGL(); + + // Reimplemented + virtual void resizeGL(int w, int h); + + // Reimplemented + virtual void paintGL(); + + private: + + /* + * Variables + */ + + /// Observer. + tcObserver* m_observer; + + /// Globe to display. + tcGlobe* m_globe; }; #endif -- 2.11.4.GIT