diff options
-rw-r--r-- | examples/examples.pro | 3 | ||||
-rw-r--r-- | examples/surfacechart/main.cpp | 74 | ||||
-rw-r--r-- | examples/surfacechart/surfacechart.pro | 7 | ||||
-rw-r--r-- | src/datavis3d/engine/engine.pri | 11 | ||||
-rw-r--r-- | src/datavis3d/engine/q3dsurface.cpp | 156 | ||||
-rw-r--r-- | src/datavis3d/engine/q3dsurface.h | 86 | ||||
-rw-r--r-- | src/datavis3d/engine/q3dsurface_p.h | 85 | ||||
-rw-r--r-- | src/datavis3d/engine/surface3dcontroller.cpp | 126 | ||||
-rw-r--r-- | src/datavis3d/engine/surface3dcontroller_p.h | 90 | ||||
-rw-r--r-- | src/datavis3d/engine/surface3drenderer.cpp | 290 | ||||
-rw-r--r-- | src/datavis3d/engine/surface3drenderer_p.h | 150 | ||||
-rw-r--r-- | src/datavis3d/engine/theme_p.h | 2 |
12 files changed, 1077 insertions, 3 deletions
diff --git a/examples/examples.pro b/examples/examples.pro index f057b1c1..348aab53 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -4,6 +4,7 @@ SUBDIRS += barchart \ widget \ mapdata \ qmlbarchart \ - qmlmaps + qmlmaps \ + surfacechart qtHaveModule(multimedia):!android: SUBDIRS += spectrum diff --git a/examples/surfacechart/main.cpp b/examples/surfacechart/main.cpp new file mode 100644 index 00000000..764e9b0f --- /dev/null +++ b/examples/surfacechart/main.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the QtDataVis3D module. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <Q3DSurface> + +#include <QGuiApplication> + +using namespace QtDataVis3D; + +int main(int argc, char *argv[]) +{ + QGuiApplication a(argc, argv); + + Q3DSurface surfaceChart; + + QList<qreal> lowList; + lowList << 15.0 << 65.0 << 105.0 << 65.0 << 15.0; + lowList << 35.0 << 105.0 << 170.0 << 105.0 << 35; + lowList << 55.0 << 135.0 << 215.0 << 135.0 << 55; + lowList << 75.0 << 155.0 << 240.0 << 155.0 << 75; + lowList << 80.0 << 190.0 << 245.0 << 190.0 << 80; + lowList << 75.0 << 155.0 << 240.0 << 155.0 << 75.0; + lowList << 55.0 << 135.0 << 215.0 << 135.0 << 55; + lowList << 35.0 << 105.0 << 170.0 << 105.0 << 35.0; + lowList << 15.0 << 65.0 << 105.0 << 65.0 << 16.1; + + surfaceChart.appendSeries(lowList); + +// QList<qreal> topList; +// topList << 2.1 << 2.2; +// surfaceChart.appendSeries(topList); + + surfaceChart.showData(); + surfaceChart.show(); + + return a.exec(); +} diff --git a/examples/surfacechart/surfacechart.pro b/examples/surfacechart/surfacechart.pro new file mode 100644 index 00000000..668b5195 --- /dev/null +++ b/examples/surfacechart/surfacechart.pro @@ -0,0 +1,7 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +SOURCES += main.cpp + +INSTALLS += target diff --git a/src/datavis3d/engine/engine.pri b/src/datavis3d/engine/engine.pri index e17f225c..fb6b026b 100644 --- a/src/datavis3d/engine/engine.pri +++ b/src/datavis3d/engine/engine.pri @@ -10,7 +10,10 @@ SOURCES += $$PWD/q3dwindow.cpp \ $$PWD/bars3dcontroller.cpp \ $$PWD/bars3drenderer.cpp \ $$PWD/maps3dcontroller.cpp \ - $$PWD/maps3drenderer.cpp + $$PWD/maps3drenderer.cpp \ + $$PWD/q3dsurface.cpp \ + $$PWD/surface3drenderer.cpp \ + $$PWD/surface3dcontroller.cpp HEADERS += $$PWD/q3dwindow_p.h \ $$PWD/q3dwindow.h \ @@ -30,6 +33,10 @@ HEADERS += $$PWD/q3dwindow_p.h \ $$PWD/bars3dcontroller_p.h \ $$PWD/bars3drenderer_p.h \ $$PWD/maps3dcontroller_p.h \ - $$PWD/maps3drenderer_p.h + $$PWD/maps3drenderer_p.h \ + $$PWD/q3dsurface.h \ + $$PWD/q3dsurface_p.h \ + $$PWD/surface3dcontroller_p.h \ + $$PWD/surface3drenderer_p.h RESOURCES += engine/engine.qrc diff --git a/src/datavis3d/engine/q3dsurface.cpp b/src/datavis3d/engine/q3dsurface.cpp new file mode 100644 index 00000000..0019ab23 --- /dev/null +++ b/src/datavis3d/engine/q3dsurface.cpp @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtDataVis3D module. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "q3dsurface.h" +#include "q3dsurface_p.h" + +#include <QMouseEvent> + +#include <QDebug> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +Q3DSurface::Q3DSurface() + : d_ptr(new Q3DSurfacePrivate(this, geometry())) +{ +} + +Q3DSurface::~Q3DSurface() +{ +} + +void Q3DSurface::initialize() +{ + d_ptr->m_shared->setWidth(width()); + d_ptr->m_shared->setHeight(height()); + d_ptr->m_shared->initializeOpenGL(); +} + +void Q3DSurface::render() +{ + d_ptr->m_shared->render(); +} + +#if defined(Q_OS_ANDROID) +void Q3DSurface::mouseDoubleClickEvent(QMouseEvent *event) +{ +} +void Q3DSurface::touchEvent(QTouchEvent *event) +{ +} +#endif + +void Q3DSurface::mousePressEvent(QMouseEvent *event) +{ + d_ptr->m_shared->mousePressEvent(event, event->pos()); +} + +void Q3DSurface::mouseReleaseEvent(QMouseEvent *event) +{ + d_ptr->m_shared->mouseReleaseEvent(event, event->pos()); +} + +void Q3DSurface::mouseMoveEvent(QMouseEvent *event) +{ + d_ptr->m_shared->mouseMoveEvent(event, event->pos()); +} + +void Q3DSurface::wheelEvent(QWheelEvent *event) +{ + Q_UNUSED(event) +} + +void Q3DSurface::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event); + d_ptr->m_shared->setWidth(width()); + d_ptr->m_shared->setHeight(height()); + d_ptr->m_shared->resizeNotify(); +} + + +// TODO ///////////////////////////////////////// +void Q3DSurface::appendSeries(QList<qreal> series) +{ + d_ptr->appendSeries(series); +} + +void Q3DSurface::showData() +{ + for (int i = 0; i < d_ptr->numOfSeries(); i++) { + QList<qreal> s = d_ptr->seriesAt(i); + qDebug() << "Series = "; + foreach (qreal val, s) { + qDebug() << val; + } + } +} + +// TODO END ////////////////////////////////////////// + +/////////////////// PRIVATE /////////////////////////////////// + +Q3DSurfacePrivate::Q3DSurfacePrivate(Q3DSurface *q, QRect rect) + : q_ptr(q), + m_shared(new Surface3dController(rect)) +{ +} + +Q3DSurfacePrivate::~Q3DSurfacePrivate() +{ +} + +void Q3DSurfacePrivate::appendSeries(QList<qreal> series) +{ + m_seriesList.append(series); +} + +QList<qreal> Q3DSurfacePrivate::seriesAt(int i) +{ + return m_seriesList.at(i); +} + +int Q3DSurfacePrivate::numOfSeries() +{ + return m_seriesList.count(); +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/engine/q3dsurface.h b/src/datavis3d/engine/q3dsurface.h new file mode 100644 index 00000000..4d0661be --- /dev/null +++ b/src/datavis3d/engine/q3dsurface.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtDataVis3D module. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef Q3DSURFACE_H +#define Q3DSURFACE_H + +#include "qdatavis3dnamespace.h" +#include "q3dwindow.h" + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class Q3DSurfacePrivate; + +class QT_DATAVIS3D_EXPORT Q3DSurface : public Q3DWindow +{ + Q_OBJECT + +public: + explicit Q3DSurface(); + ~Q3DSurface(); + +//TODO part + void appendSeries(QList<qreal> series); + void showData(); +//END TODO + +protected: + void initialize(); + void render(); + +#if defined(Q_OS_ANDROID) + void mouseDoubleClickEvent(QMouseEvent *event); + void touchEvent(QTouchEvent *event); +#endif + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent *event); + void resizeEvent(QResizeEvent *event); + +private: + QScopedPointer<Q3DSurfacePrivate> d_ptr; + Q_DISABLE_COPY(Q3DSurface) +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif // Q3DSURFACE_H diff --git a/src/datavis3d/engine/q3dsurface_p.h b/src/datavis3d/engine/q3dsurface_p.h new file mode 100644 index 00000000..925a671e --- /dev/null +++ b/src/datavis3d/engine/q3dsurface_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtDataVis3D module. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtDataVis3D API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef Q3DSURFACE_P_H +#define Q3DSURFACE_P_H + +#include "surface3dcontroller_p.h" +#include "qdatavis3dnamespace.h" + +#include <QList> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class Q3DSurface; + +class Q3DSurfacePrivate : public QObject +{ +public: + Q3DSurfacePrivate(Q3DSurface *q, QRect rect); + ~Q3DSurfacePrivate(); + + // TODO + void appendSeries(QList<qreal> series); + QList<qreal> seriesAt(int i); + int numOfSeries(); + // TODO + + Surface3dController *m_shared; + +private: + Q3DSurface *q_ptr; + QList<QList<qreal> > m_seriesList; // Temp to be replaced by dataset +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif // Q3DSURFACE_P_H diff --git a/src/datavis3d/engine/surface3dcontroller.cpp b/src/datavis3d/engine/surface3dcontroller.cpp new file mode 100644 index 00000000..bb765942 --- /dev/null +++ b/src/datavis3d/engine/surface3dcontroller.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtDataVis3D module. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "surface3dcontroller_p.h" +#include "surface3drenderer_p.h" + +#include <QMouseEvent> + +#include <QDebug> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +Surface3dController::Surface3dController(QRect rect) + : m_renderer(new Surface3dRenderer(rect, this)), + m_isInitialized(false) +{ +} + +Surface3dController::~Surface3dController() +{ +} + +void Surface3dController::initializeOpenGL() +{ + // Initialization is called multiple times when Qt Quick components are used + if (m_isInitialized) + return; + + m_renderer->initializeOpenGL(); + m_isInitialized = true; +} + +void Surface3dController::render(const GLuint defaultFboHandle) +{ + if (!m_isInitialized) + return; + + m_renderer->render(defaultFboHandle); +} + +void Surface3dController::setWidth(const int width) +{ + m_renderer->setWidth(width); +} + +void Surface3dController::setHeight(const int height) +{ + m_renderer->setHeight(height); +} + +#if defined(Q_OS_ANDROID) +void Surface3dController::mouseDoubleClickEvent(QMouseEvent *event) +{ +} +void touchEvent(QTouchEvent *event) +{ +} +#endif + +void Surface3dController::mousePressEvent(QMouseEvent *event, const QPoint &mousePos) +{ + Q_UNUSED(event) + Q_UNUSED(mousePos) +} + +void Surface3dController::mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos) +{ + Q_UNUSED(event) + Q_UNUSED(mousePos) +} + +void Surface3dController::mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos) +{ + Q_UNUSED(event) + Q_UNUSED(mousePos) +} + +void Surface3dController::wheelEvent(QWheelEvent *event) +{ + Q_UNUSED(event) +} + +void Surface3dController::resizeNotify() +{ + +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/engine/surface3dcontroller_p.h b/src/datavis3d/engine/surface3dcontroller_p.h new file mode 100644 index 00000000..6855865c --- /dev/null +++ b/src/datavis3d/engine/surface3dcontroller_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtDataVis3D module. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtDataVis3D API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef SURFACE3DCONTROLLER_P_H +#define SURFACE3DCONTROLLER_P_H + +#include "datavis3dglobal_p.h" +#include "surface3drenderer_p.h" + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class QT_DATAVIS3D_EXPORT Surface3dController : public QObject +{ + Q_OBJECT + + Surface3dRenderer *m_renderer; + bool m_isInitialized; + +public: + explicit Surface3dController(QRect rect); + ~Surface3dController(); + + void initializeOpenGL(); + void render(const GLuint defaultFboHandle = 0); + + void setWidth(const int width); + void setHeight(const int height); + +#if defined(Q_OS_ANDROID) + void mouseDoubleClickEvent(QMouseEvent *event); + void touchEvent(QTouchEvent *event); +#endif + void mousePressEvent(QMouseEvent *event, const QPoint &mousePos); + void mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos); + void mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos); + void wheelEvent(QWheelEvent *event); + void resizeNotify(); +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif // SURFACE3DCONTROLLER_P_H diff --git a/src/datavis3d/engine/surface3drenderer.cpp b/src/datavis3d/engine/surface3drenderer.cpp new file mode 100644 index 00000000..852ccd02 --- /dev/null +++ b/src/datavis3d/engine/surface3drenderer.cpp @@ -0,0 +1,290 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtDataVis3D module. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "surface3dcontroller_p.h" +#include "surface3drenderer_p.h" +#include "camerahelper_p.h" +#include "objecthelper_p.h" +#include "theme_p.h" +#include "utils_p.h" +#include "drawer_p.h" + +#include <QMatrix4x4> +#include <QMouseEvent> + +#include <QDebug> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +Surface3dRenderer::Surface3dRenderer(QRect rect, Surface3dController *controller) + : QObject(controller), + m_controller(controller), + m_mousePressed(MouseNone), + m_mousePos(QPoint(0, 0)), + m_boundingRect(rect.x(), rect.y(), rect.width(), rect.height()), + m_theme(new Theme()), + m_labelTransparency(TransparencyFromTheme), + m_font(QFont(QStringLiteral("Arial"))), + m_hasNegativeValues(false), + m_camera(new CameraHelper()), + m_mainViewPort(rect.x(), rect.y(), rect.width(), rect.height()), + m_sliceViewPort(rect.x(), rect.y(), rect.width(), rect.height()), + m_isInitialized(false), + m_backgroundObj(0), + m_drawer(new Drawer(*m_theme, m_font, m_labelTransparency)) +{ +} + +Surface3dRenderer::~Surface3dRenderer() +{ + if (m_backgroundObj) + delete m_backgroundObj; +} + +void Surface3dRenderer::initializeOpenGL() +{ + // Initialization is called multiple times when Qt Quick components are used + if (m_isInitialized) + return; + + initializeOpenGLFunctions(); + + m_drawer->initializeOpenGL(); + + // Init selection shader + //initSelectionShader(); + + // Load grid line mesh + //loadGridLineMesh(); + + // Load label mesh + //loadLabelMesh(); + + // Set OpenGL features + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + +#if !defined(QT_OPENGL_ES_2) + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); +#endif + + // Set initial camera position + // X must be 0 for rotation to work - we can use "setCameraRotation" for setting it later + m_camera->setDefaultCameraOrientation(QVector3D(0.0f, 0.0f, 6.0f + zComp), + QVector3D(0.0f, 0.0f, zComp), + QVector3D(0.0f, 1.0f, 0.0f)); + + // Set view port + glViewport(m_sliceViewPort.x(), m_sliceViewPort.y(), + m_sliceViewPort.width(), m_sliceViewPort.height()); + + // Set initialized -flag + m_isInitialized = true; + + // Resize in case we've missed resize events + // Resize calls initSelectionBuffer and initDepthBuffer, so they don't need to be called here + resizeNotify(); + + // Load background mesh (we need to be initialized first) + loadBackgroundMesh(); +} + +void Surface3dRenderer::render(const GLuint defaultFboHandle) +{ + if (!m_isInitialized) + return; + + if (defaultFboHandle) { + glDepthMask(true); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + } + + QVector3D clearColor = Utils::vectorFromColor(m_theme->m_windowColor); + glClearColor(clearColor.x(), clearColor.y(), clearColor.z(), 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + drawScene(defaultFboHandle); +} + +void Surface3dRenderer::drawScene(const GLuint defaultFboHandle) +{ + Q_UNUSED(defaultFboHandle) + + // Specify viewport + glViewport(m_mainViewPort.x(), m_mainViewPort.y(), + m_mainViewPort.width(), m_mainViewPort.height()); + + // Set up projection matrix + QMatrix4x4 projectionMatrix; + projectionMatrix.perspective(45.0f, (GLfloat)m_mainViewPort.width() + / (GLfloat)m_mainViewPort.height(), 0.1f, 100.0f); + + // Calculate view matrix + QMatrix4x4 viewMatrix = m_camera->calculateViewMatrix(m_mousePos, + 1.0, //Hard coded + m_mainViewPort.width(), + m_mainViewPort.height(), + m_hasNegativeValues); +} + +void Surface3dRenderer::loadBackgroundMesh() +{ + if (!m_isInitialized) + return; + + if (m_backgroundObj) + delete m_backgroundObj; + if (m_hasNegativeValues) + m_backgroundObj = new ObjectHelper(QStringLiteral(":/defaultMeshes/negativeBackground")); + else + m_backgroundObj = new ObjectHelper(QStringLiteral(":/defaultMeshes/background")); + m_backgroundObj->load(); +} + + +const QSize Surface3dRenderer::size() +{ + return m_boundingRect.size(); +} + +const QRect Surface3dRenderer::boundingRect() +{ + return m_boundingRect; +} + +void Surface3dRenderer::setBoundingRect(const QRect boundingRect) +{ + m_boundingRect = boundingRect; + resizeNotify(); +} + +void Surface3dRenderer::setWidth(const int width) +{ + m_boundingRect.setWidth(width); + resizeNotify(); +} + +int Surface3dRenderer::width() +{ + return m_boundingRect.width(); +} + +void Surface3dRenderer::setHeight(const int height) +{ + m_boundingRect.setHeight(height); + resizeNotify(); +} + +int Surface3dRenderer::height() +{ + return m_boundingRect.height(); +} + +void Surface3dRenderer::setX(const int x) +{ + m_boundingRect.setX(x); +} + +int Surface3dRenderer::x() +{ + return m_boundingRect.x(); +} + +void Surface3dRenderer::setY(const int y) +{ + m_boundingRect.setY(y); +} + +int Surface3dRenderer::y() +{ + return m_boundingRect.y(); +} + +#if defined(Q_OS_ANDROID) +void Surface3dRenderer::mouseDoubleClickEvent(QMouseEvent *event) +{ + +} + +void Surface3dRenderer::touchEvent(QTouchEvent *event) +{ + +} +#endif +void Surface3dRenderer::mousePressEvent(QMouseEvent *event, const QPoint &mousePos) +{ + Q_UNUSED(event) + Q_UNUSED(mousePos) +} + +void Surface3dRenderer::mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos) +{ + Q_UNUSED(event) + Q_UNUSED(mousePos) +} + +void Surface3dRenderer::mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos) +{ + Q_UNUSED(event) + Q_UNUSED(mousePos) +} + +void Surface3dRenderer::wheelEvent(QWheelEvent *event) +{ + Q_UNUSED(event) +} + +void Surface3dRenderer::resizeNotify() +{ + if (!m_isInitialized) + return; + + m_sliceViewPort = QRect(0, 0, width(), height()); +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/engine/surface3drenderer_p.h b/src/datavis3d/engine/surface3drenderer_p.h new file mode 100644 index 00000000..d93adf10 --- /dev/null +++ b/src/datavis3d/engine/surface3drenderer_p.h @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtDataVis3D module. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtDataVis3D API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef SURFACE3DRENDERER_P_H +#define SURFACE3DRENDERER_P_H + +#include "datavis3dglobal_p.h" +#include <QtCore/QSize> +#include <QtCore/QObject> +#include <QtGui/QOpenGLFunctions> +#include <QtGui/QFont> +#include <QWindow> + +class QOpenGLShaderProgram; + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class ShaderHelper; +class ObjectHelper; +class Theme; +class Drawer; +class Surface3dController; +class CameraHelper; + +class QT_DATAVIS3D_EXPORT Surface3dRenderer : public QObject, protected QOpenGLFunctions +{ + Q_OBJECT + +public: + enum MousePressType { + MouseNone = 0, + MouseOnScene, + MouseOnOverview, + MouseOnZoom, + MouseRotating, + MouseOnPinch + }; + + Surface3dController *m_controller; + + // Interaction related parameters + MousePressType m_mousePressed; + QPoint m_mousePos; + SelectionMode m_selectionMode; + + // Visual parameters + QRect m_boundingRect; + Theme *m_theme; + LabelTransparency m_labelTransparency; + QFont m_font; + bool m_hasNegativeValues; + + CameraHelper *m_camera; + +private: + QRect m_mainViewPort; + QRect m_sliceViewPort; + bool m_isInitialized; + ObjectHelper *m_backgroundObj; + + Drawer *m_drawer; + +public: + explicit Surface3dRenderer(QRect rect, Surface3dController *controller); + ~Surface3dRenderer(); + + void initializeOpenGL(); + void render(const GLuint defaultFboHandle = 0); + + // Size + const QSize size(); + const QRect boundingRect(); + void setBoundingRect(const QRect boundingRect); + void setWidth(const int width); + int width(); + void setHeight(const int height); + int height(); + void setX(const int x); + int x(); + void setY(const int y); + int y(); + +#if defined(Q_OS_ANDROID) + void mouseDoubleClickEvent(QMouseEvent *event); + void touchEvent(QTouchEvent *event); +#endif + void mousePressEvent(QMouseEvent *event, const QPoint &mousePos); + void mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos); + void mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos); + void wheelEvent(QWheelEvent *event); + void resizeNotify(); + + void loadBackgroundMesh(); + +private: + void drawScene(const GLuint defaultFboHandle); + Q_DISABLE_COPY(Surface3dRenderer) +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif // SURFACE3DRENDERER_P_H diff --git a/src/datavis3d/engine/theme_p.h b/src/datavis3d/engine/theme_p.h index 93d4943b..772fe168 100644 --- a/src/datavis3d/engine/theme_p.h +++ b/src/datavis3d/engine/theme_p.h @@ -71,6 +71,8 @@ private: friend class Bars3dRenderer; friend class Bars3dController; friend class Maps3DController; + friend class Surface3dRenderer; + friend class Surface3dController; friend class Drawer; QColor m_baseColor; |