diff options
Diffstat (limited to 'src/datavis3d/utils')
-rw-r--r-- | src/datavis3d/utils/abstractobjecthelper.cpp | 81 | ||||
-rw-r--r-- | src/datavis3d/utils/abstractobjecthelper_p.h | 65 | ||||
-rw-r--r-- | src/datavis3d/utils/camerahelper.cpp | 154 | ||||
-rw-r--r-- | src/datavis3d/utils/camerahelper_p.h | 88 | ||||
-rw-r--r-- | src/datavis3d/utils/meshloader.cpp | 43 | ||||
-rw-r--r-- | src/datavis3d/utils/meshloader_p.h | 47 | ||||
-rw-r--r-- | src/datavis3d/utils/objecthelper.cpp | 90 | ||||
-rw-r--r-- | src/datavis3d/utils/objecthelper_p.h | 69 | ||||
-rw-r--r-- | src/datavis3d/utils/shaderhelper.cpp | 43 | ||||
-rw-r--r-- | src/datavis3d/utils/shaderhelper_p.h | 47 | ||||
-rw-r--r-- | src/datavis3d/utils/surfaceobject.cpp | 349 | ||||
-rw-r--r-- | src/datavis3d/utils/surfaceobject_p.h | 65 | ||||
-rw-r--r-- | src/datavis3d/utils/texturehelper.cpp | 82 | ||||
-rw-r--r-- | src/datavis3d/utils/texturehelper_p.h | 54 | ||||
-rw-r--r-- | src/datavis3d/utils/utils.cpp | 73 | ||||
-rw-r--r-- | src/datavis3d/utils/utils.pri | 8 | ||||
-rw-r--r-- | src/datavis3d/utils/utils_p.h | 50 | ||||
-rw-r--r-- | src/datavis3d/utils/vertexindexer.cpp | 45 | ||||
-rw-r--r-- | src/datavis3d/utils/vertexindexer_p.h | 47 |
19 files changed, 863 insertions, 637 deletions
diff --git a/src/datavis3d/utils/abstractobjecthelper.cpp b/src/datavis3d/utils/abstractobjecthelper.cpp new file mode 100644 index 00000000..d54a50c7 --- /dev/null +++ b/src/datavis3d/utils/abstractobjecthelper.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "abstractobjecthelper_p.h" + +#include <QDebug> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +AbstractObjectHelper::AbstractObjectHelper() + : m_vertexbuffer(0), + m_normalbuffer(0), + m_uvbuffer(0), + m_elementbuffer(0), + m_indexCount(0), + m_meshDataLoaded(false) +{ +} + +AbstractObjectHelper::~AbstractObjectHelper() +{ + glDeleteBuffers(1, &m_vertexbuffer); + glDeleteBuffers(1, &m_uvbuffer); + glDeleteBuffers(1, &m_normalbuffer); + glDeleteBuffers(1, &m_elementbuffer); +} + +GLuint AbstractObjectHelper::vertexBuf() +{ + if (!m_meshDataLoaded) + qFatal("No loaded object"); + return m_vertexbuffer; +} + +GLuint AbstractObjectHelper::normalBuf() +{ + if (!m_meshDataLoaded) + qFatal("No loaded object"); + return m_normalbuffer; +} + +GLuint AbstractObjectHelper::uvBuf() +{ + if (!m_meshDataLoaded) + qFatal("No loaded object"); + return m_uvbuffer; +} + +GLuint AbstractObjectHelper::elementBuf() +{ + if (!m_meshDataLoaded) + qFatal("No loaded object"); + return m_elementbuffer; +} + +GLuint AbstractObjectHelper::indexCount() +{ + return m_indexCount; +} + +GLuint AbstractObjectHelper::indicesType() +{ + return m_indicesType; +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/utils/abstractobjecthelper_p.h b/src/datavis3d/utils/abstractobjecthelper_p.h new file mode 100644 index 00000000..a4d701fa --- /dev/null +++ b/src/datavis3d/utils/abstractobjecthelper_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +// +// 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 ABSTRACTOBJECTHELPER_H +#define ABSTRACTOBJECTHELPER_H + +#include "datavis3dglobal_p.h" +#include <QOpenGLFunctions> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class AbstractObjectHelper: protected QOpenGLFunctions +{ +protected: + AbstractObjectHelper(); +public: + ~AbstractObjectHelper(); + + GLuint vertexBuf(); + GLuint normalBuf(); + GLuint uvBuf(); + GLuint elementBuf(); + GLuint indexCount(); + GLuint indicesType(); + +public: + GLuint m_vertexbuffer; + GLuint m_normalbuffer; + GLuint m_uvbuffer; + GLuint m_elementbuffer; + + GLuint m_indexCount; + GLboolean m_meshDataLoaded; + + GLuint m_indicesType; +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif // ABSTRACTOBJECTHELPER_H diff --git a/src/datavis3d/utils/camerahelper.cpp b/src/datavis3d/utils/camerahelper.cpp index 4d59132f..5ae91adb 100644 --- a/src/datavis3d/utils/camerahelper.cpp +++ b/src/datavis3d/utils/camerahelper.cpp @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -45,21 +22,26 @@ #include <QMatrix4x4> #include <QVector3D> -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE - -// Initial camera position -QVector3D m_position = QVector3D(0, 0.25, 3); -QVector3D m_target = QVector3D(0, 0, 0); -QVector3D m_up = QVector3D(0, 1, 0); +QT_DATAVIS3D_BEGIN_NAMESPACE -QPoint m_previousMousePos(0, 0); +CameraHelper::CameraHelper(QObject *parent) : + QObject(parent), + m_position(0, 0.25, 3), + m_target(0, 0, 0), + m_up(0, 1, 0), + m_previousMousePos(0,0), + m_xRotation(0), + m_yRotation(0), + m_defaultXRotation(0), + m_defaultYRotation(0), + m_rotationSpeed(100) +{ +} -GLfloat m_xRotation = 0; -GLfloat m_yRotation = 0; -GLfloat m_defaultXRotation = 0; -GLfloat m_defaultYRotation = 0; +CameraHelper::~CameraHelper() +{ +} -GLfloat m_rotationSpeed = 100; // FUNCTIONS void CameraHelper::setRotationSpeed(int speed) @@ -89,10 +71,10 @@ QMatrix4x4 CameraHelper::calculateViewMatrix(const QPoint &mousePos, int zoom, int screenWidth, int screenHeight, bool showUnder) { QMatrix4x4 viewMatrix; - GLint lowerLimit = 0; + GLfloat lowerLimit = 0.0f; if (showUnder) - lowerLimit = -90; + lowerLimit = -90.0f; // Calculate mouse movement since last frame GLfloat mouseMoveX = GLfloat(m_previousMousePos.x() - mousePos.x()) @@ -103,10 +85,10 @@ QMatrix4x4 CameraHelper::calculateViewMatrix(const QPoint &mousePos, int zoom, m_xRotation -= mouseMoveX; m_yRotation -= mouseMoveY; // Reset at 360 in x and limit to 0...90 in y - if (qFabs(m_xRotation) >= 360) - m_xRotation = 0; - if (m_yRotation >= 90) - m_yRotation = 90; + if (qAbs(m_xRotation) >= 360.0f) + m_xRotation = 0.0f; + if (m_yRotation >= 90.0f) + m_yRotation = 90.0f; else if (m_yRotation <= lowerLimit) m_yRotation = lowerLimit; @@ -116,8 +98,8 @@ QMatrix4x4 CameraHelper::calculateViewMatrix(const QPoint &mousePos, int zoom, viewMatrix.translate(m_target.x(), m_target.y(), m_target.z()); // Apply rotations // Handle x and z rotation when y -angle is other than 0 - viewMatrix.rotate(m_xRotation, 0, cos(m_yRotation * m_pi / 180.0f), - sin(m_yRotation * m_pi / 180.0f)); + viewMatrix.rotate(m_xRotation, 0, qCos(qDegreesToRadians(m_yRotation)), + qSin(qDegreesToRadians(m_yRotation))); // y rotation is always "clean" viewMatrix.rotate(m_yRotation, 1.0f, 0.0f, 0.0f); // handle zoom by scaling @@ -126,11 +108,6 @@ QMatrix4x4 CameraHelper::calculateViewMatrix(const QPoint &mousePos, int zoom, viewMatrix.translate(-m_target.x(), -m_target.y(), -m_target.z()); //qDebug() << m_xRotation << m_yRotation; - //qDebug() << "sin(m_yRotation)" << sin(m_yRotation*m_pi/180); - //qDebug() << "asin(m_yRotation)" << asin(m_yRotation*m_pi/180); - //qDebug() << "cos(m_yRotation)" << cos(m_yRotation*m_pi/180); - //qDebug() << "tan(m_yRotation)" << tan(m_yRotation*m_pi/180); - m_previousMousePos = mousePos; return viewMatrix; } @@ -144,18 +121,17 @@ QVector3D CameraHelper::calculateLightPosition(const QVector3D &lightPosition, GLfloat xAngle; GLfloat yAngle; if (!fixedRotation) { - xAngle = m_xRotation * m_pi / 180.0f; - yAngle = m_yRotation * m_pi / 180.0f; + xAngle = qDegreesToRadians(m_xRotation); + yAngle = qDegreesToRadians(m_yRotation); } else { - xAngle = fixedRotation * m_pi / 180.0f; + xAngle = qDegreesToRadians(fixedRotation); yAngle = 0; } GLfloat radius = (radiusFactor + lightPosition.y()); // set radius to match the highest height of the light - GLfloat zPos = radius * cos(xAngle) * cos(yAngle); - GLfloat xPos = radius * sin(xAngle) * cos(yAngle); - GLfloat yPos = (radiusFactor + lightPosition.y()) * sin(yAngle); + GLfloat zPos = radius * qCos(xAngle) * qCos(yAngle); + GLfloat xPos = radius * qSin(xAngle) * qCos(yAngle); + GLfloat yPos = (radiusFactor + lightPosition.y()) * qSin(yAngle); // Keep light in the set position in relation to camera - // TODO: Does not work perfectly yet; Light seems wrong when viewing scene from sides (or isometrically) newLightPosition = QVector3D(-xPos + lightPosition.x(), yPos + lightPosition.y(), zPos + lightPosition.z()); @@ -179,125 +155,125 @@ QPointF CameraHelper::getCameraRotations() return rotations; } -void CameraHelper::setCameraPreset(CameraPreset preset) +void CameraHelper::setCameraPreset(QDataVis::CameraPreset preset) { switch (preset) { - case PresetFrontLow: { + case QDataVis::PresetFrontLow: { qDebug("PresetFrontLow"); CameraHelper::setCameraRotation(QPointF(0.0f, 0.0f)); break; } - case PresetFront: { + case QDataVis::PresetFront: { qDebug("PresetFront"); CameraHelper::setCameraRotation(QPointF(0.0f, 22.5f)); break; } - case PresetFrontHigh: { + case QDataVis::PresetFrontHigh: { qDebug("PresetFrontHigh"); CameraHelper::setCameraRotation(QPointF(0.0f, 45.0f)); break; } - case PresetLeftLow: { + case QDataVis::PresetLeftLow: { qDebug("PresetLeftLow"); CameraHelper::setCameraRotation(QPointF(90.0f, 0.0f)); break; } - case PresetLeft: { + case QDataVis::PresetLeft: { qDebug("PresetLeft"); CameraHelper::setCameraRotation(QPointF(90.0f, 22.5f)); break; } - case PresetLeftHigh: { + case QDataVis::PresetLeftHigh: { qDebug("PresetLeftHigh"); CameraHelper::setCameraRotation(QPointF(90.0f, 45.0f)); break; } - case PresetRightLow: { + case QDataVis::PresetRightLow: { qDebug("PresetRightLow"); CameraHelper::setCameraRotation(QPointF(-90.0f, 0.0f)); break; } - case PresetRight: { + case QDataVis::PresetRight: { qDebug("PresetRight"); CameraHelper::setCameraRotation(QPointF(-90.0f, 22.5f)); break; } - case PresetRightHigh: { + case QDataVis::PresetRightHigh: { qDebug("PresetRightHigh"); CameraHelper::setCameraRotation(QPointF(-90.0f, 45.0f)); break; } - case PresetBehindLow: { + case QDataVis::PresetBehindLow: { qDebug("PresetBehindLow"); CameraHelper::setCameraRotation(QPointF(180.0f, 0.0f)); break; } - case PresetBehind: { + case QDataVis::PresetBehind: { qDebug("PresetBehind"); CameraHelper::setCameraRotation(QPointF(180.0f, 22.5f)); break; } - case PresetBehindHigh: { + case QDataVis::PresetBehindHigh: { qDebug("PresetBehindHigh"); CameraHelper::setCameraRotation(QPointF(180.0f, 45.0f)); break; } - case PresetIsometricLeft: { + case QDataVis::PresetIsometricLeft: { qDebug("PresetIsometricLeft"); CameraHelper::setCameraRotation(QPointF(45.0f, 22.5f)); break; } - case PresetIsometricLeftHigh: { + case QDataVis::PresetIsometricLeftHigh: { qDebug("PresetIsometricLeftHigh"); CameraHelper::setCameraRotation(QPointF(45.0f, 45.0f)); break; } - case PresetIsometricRight: { + case QDataVis::PresetIsometricRight: { qDebug("PresetIsometricRight"); CameraHelper::setCameraRotation(QPointF(-45.0f, 22.5f)); break; } - case PresetIsometricRightHigh: { + case QDataVis::PresetIsometricRightHigh: { qDebug("PresetIsometricRightHigh"); CameraHelper::setCameraRotation(QPointF(-45.0f, 45.0f)); break; } - case PresetDirectlyAbove: { + case QDataVis::PresetDirectlyAbove: { qDebug("PresetDirectlyAbove"); CameraHelper::setCameraRotation(QPointF(0.0f, 90.0f)); break; } - case PresetDirectlyAboveCW45: { + case QDataVis::PresetDirectlyAboveCW45: { qDebug("PresetDirectlyAboveCW45"); CameraHelper::setCameraRotation(QPointF(-45.0f, 90.0f)); break; } - case PresetDirectlyAboveCCW45: { + case QDataVis::PresetDirectlyAboveCCW45: { qDebug("PresetDirectlyAboveCCW45"); CameraHelper::setCameraRotation(QPointF(45.0f, 90.0f)); break; } - case PresetFrontBelow: { + case QDataVis::PresetFrontBelow: { qDebug("PresetFrontBelow"); CameraHelper::setCameraRotation(QPointF(0.0f, -45.0f)); break; } - case PresetLeftBelow: { + case QDataVis::PresetLeftBelow: { qDebug("PresetLeftBelow"); CameraHelper::setCameraRotation(QPointF(90.0f, -45.0f)); break; } - case PresetRightBelow: { + case QDataVis::PresetRightBelow: { qDebug("PresetRightBelow"); CameraHelper::setCameraRotation(QPointF(-90.0f, -45.0f)); break; } - case PresetBehindBelow: { + case QDataVis::PresetBehindBelow: { qDebug("PresetBehindBelow"); CameraHelper::setCameraRotation(QPointF(180.0f, -45.0f)); break; } - case PresetDirectlyBelow: { + case QDataVis::PresetDirectlyBelow: { qDebug("PresetDirectlyBelow"); CameraHelper::setCameraRotation(QPointF(0.0f, -90.0f)); break; @@ -307,4 +283,4 @@ void CameraHelper::setCameraPreset(CameraPreset preset) } } -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/utils/camerahelper_p.h b/src/datavis3d/utils/camerahelper_p.h index 21b6ccac..3b8c0c9c 100644 --- a/src/datavis3d/utils/camerahelper_p.h +++ b/src/datavis3d/utils/camerahelper_p.h @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -43,7 +20,7 @@ // W A R N I N G // ------------- // -// This file is not part of the Qt API. It exists purely as an +// 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. // @@ -52,43 +29,62 @@ #ifndef CAMERAPOSITIONER_P_H #define CAMERAPOSITIONER_P_H -#include "qdatavis3dglobal.h" -#include "qdatavis3namespace.h" +#include "datavis3dglobal_p.h" #include "q3dbars.h" +#include <QObject> class QMatrix4x4; class QVector3D; class QPoint; class QPointF; -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE -class CameraHelper +class CameraHelper : public QObject { - public: + Q_OBJECT + +private: + QVector3D m_position; + QVector3D m_target; + QVector3D m_up; + + QPoint m_previousMousePos; + + GLfloat m_xRotation; + GLfloat m_yRotation; + GLfloat m_defaultXRotation; + GLfloat m_defaultYRotation; + + GLfloat m_rotationSpeed; + +public: + explicit CameraHelper(QObject *parent = 0); + ~CameraHelper(); + // How fast camera rotates when mouse is dragged. Default is 100. - static void setRotationSpeed(int speed); + void setRotationSpeed(int speed); // Set camera rotation in degrees - static void setCameraRotation(const QPointF &rotation); + void setCameraRotation(const QPointF &rotation); // Get camera rotations - static QPointF getCameraRotations(); + QPointF getCameraRotations(); // Set default camera orientation. Position's x and y should be 0. - static void setDefaultCameraOrientation(const QVector3D &defaultPosition, + void setDefaultCameraOrientation(const QVector3D &defaultPosition, const QVector3D &defaultTarget, const QVector3D &defaultUp); // Calculate view matrix based on rotation and zoom - static QMatrix4x4 calculateViewMatrix(const QPoint &mousePos, int zoom, + QMatrix4x4 calculateViewMatrix(const QPoint &mousePos, int zoom, int screenWidth, int screenHeight, bool showUnder = false); // Calcluate light position based on rotation. Call after calling calculateViewMatrix to get // up-to-date position - static QVector3D calculateLightPosition(const QVector3D &lightPosition, + QVector3D calculateLightPosition(const QVector3D &lightPosition, GLfloat fixedRotation = 0.0f, GLfloat distanceModifier = 0.0f); - static void updateMousePos(const QPoint &mousePos); - static void setCameraPreset(CameraPreset preset); + void updateMousePos(const QPoint &mousePos); + void setCameraPreset(QDataVis::CameraPreset preset); }; -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE #endif diff --git a/src/datavis3d/utils/meshloader.cpp b/src/datavis3d/utils/meshloader.cpp index 0bb780ce..ee2f12a6 100644 --- a/src/datavis3d/utils/meshloader.cpp +++ b/src/datavis3d/utils/meshloader.cpp @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -49,7 +26,7 @@ #include <QDebug> -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE QString slashTag = QStringLiteral("/"); @@ -145,4 +122,4 @@ bool MeshLoader::loadOBJ(const QString &path, return true; } -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/utils/meshloader_p.h b/src/datavis3d/utils/meshloader_p.h index 88ab89b3..acbfb037 100644 --- a/src/datavis3d/utils/meshloader_p.h +++ b/src/datavis3d/utils/meshloader_p.h @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -43,7 +20,7 @@ // W A R N I N G // ------------- // -// This file is not part of the Qt API. It exists purely as an +// 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. // @@ -52,12 +29,12 @@ #ifndef MESHLOADER_P_H #define MESHLOADER_P_H -#include "qdatavis3dglobal.h" +#include "datavis3dglobal_p.h" class QVector2D; class QVector3D; -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE class MeshLoader { @@ -69,6 +46,6 @@ class MeshLoader // TODO: add loaders for other formats? }; -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE #endif diff --git a/src/datavis3d/utils/objecthelper.cpp b/src/datavis3d/utils/objecthelper.cpp index d280abf8..cbd1e960 100644 --- a/src/datavis3d/utils/objecthelper.cpp +++ b/src/datavis3d/utils/objecthelper.cpp @@ -1,69 +1,38 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ #include "meshloader_p.h" #include "vertexindexer_p.h" #include "objecthelper_p.h" +#include "abstractobjecthelper_p.h" #include <QDebug> -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE ObjectHelper::ObjectHelper(const QString &objectFile) - : m_objectFile(objectFile), - m_vertexbuffer(0), - m_normalbuffer(0), - m_uvbuffer(0), - m_elementbuffer(0), - m_indexCount(0), - m_meshDataLoaded(false) + : m_objectFile(objectFile) { + m_indicesType = GL_UNSIGNED_SHORT; } ObjectHelper::~ObjectHelper() { - glDeleteBuffers(1, &m_vertexbuffer); - glDeleteBuffers(1, &m_uvbuffer); - glDeleteBuffers(1, &m_normalbuffer); - glDeleteBuffers(1, &m_elementbuffer); } void ObjectHelper::setObjectFile(const QString &objectFile) @@ -129,37 +98,4 @@ void ObjectHelper::load() m_meshDataLoaded = true; } -GLuint ObjectHelper::vertexBuf() -{ - if (!m_meshDataLoaded) - qFatal("No loaded object"); - return m_vertexbuffer; -} - -GLuint ObjectHelper::normalBuf() -{ - if (!m_meshDataLoaded) - qFatal("No loaded object"); - return m_normalbuffer; -} - -GLuint ObjectHelper::uvBuf() -{ - if (!m_meshDataLoaded) - qFatal("No loaded object"); - return m_uvbuffer; -} - -GLuint ObjectHelper::elementBuf() -{ - if (!m_meshDataLoaded) - qFatal("No loaded object"); - return m_elementbuffer; -} - -GLuint ObjectHelper::indexCount() -{ - return m_indexCount; -} - -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/utils/objecthelper_p.h b/src/datavis3d/utils/objecthelper_p.h index 6cac8770..ba9fc2f3 100644 --- a/src/datavis3d/utils/objecthelper_p.h +++ b/src/datavis3d/utils/objecthelper_p.h @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -43,7 +20,7 @@ // W A R N I N G // ------------- // -// This file is not part of the Qt API. It exists purely as an +// 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. // @@ -52,14 +29,15 @@ #ifndef OBJECTHELPER_P_H #define OBJECTHELPER_P_H -#include "qdatavis3dglobal.h" +#include "datavis3dglobal_p.h" +#include "abstractobjecthelper_p.h" #include <QOpenGLFunctions> -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE -class ObjectHelper: protected QOpenGLFunctions +class ObjectHelper : public AbstractObjectHelper { - public: +public: ObjectHelper(const QString &objectFile = QString()); ~ObjectHelper(); @@ -67,25 +45,10 @@ class ObjectHelper: protected QOpenGLFunctions void load(); - GLuint vertexBuf(); - GLuint normalBuf(); - GLuint uvBuf(); - GLuint elementBuf(); - GLuint indexCount(); - - private: +private: QString m_objectFile; - - GLuint m_vertexbuffer; - GLuint m_normalbuffer; - GLuint m_uvbuffer; - GLuint m_elementbuffer; - - GLuint m_indexCount; - - GLboolean m_meshDataLoaded; }; -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE #endif diff --git a/src/datavis3d/utils/shaderhelper.cpp b/src/datavis3d/utils/shaderhelper.cpp index c8a92dae..c8716910 100644 --- a/src/datavis3d/utils/shaderhelper.cpp +++ b/src/datavis3d/utils/shaderhelper.cpp @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -43,7 +20,7 @@ #include <QOpenGLShader> -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE ShaderHelper::ShaderHelper(QObject *parent, const QString &vertexShader, @@ -249,4 +226,4 @@ GLuint ShaderHelper::normalAtt() return m_normalAttr; } -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/utils/shaderhelper_p.h b/src/datavis3d/utils/shaderhelper_p.h index 55d075de..97fcf8a0 100644 --- a/src/datavis3d/utils/shaderhelper_p.h +++ b/src/datavis3d/utils/shaderhelper_p.h @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -43,7 +20,7 @@ // W A R N I N G // ------------- // -// This file is not part of the Qt API. It exists purely as an +// 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. // @@ -52,12 +29,12 @@ #ifndef SHADERHELPER_P_H #define SHADERHELPER_P_H -#include "qdatavis3dglobal.h" +#include "datavis3dglobal_p.h" #include <QOpenGLFunctions> class QOpenGLShaderProgram; -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE class ShaderHelper { @@ -128,6 +105,6 @@ class ShaderHelper GLboolean m_initialized; }; -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE #endif diff --git a/src/datavis3d/utils/surfaceobject.cpp b/src/datavis3d/utils/surfaceobject.cpp new file mode 100644 index 00000000..4c05c442 --- /dev/null +++ b/src/datavis3d/utils/surfaceobject.cpp @@ -0,0 +1,349 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "surfaceobject_p.h" +#include "abstractobjecthelper_p.h" + +#include <QVector3D> +#include <QVector2D> + +#include <QDebug> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +SurfaceObject::SurfaceObject() +{ + m_indicesType = GL_UNSIGNED_INT; +} + +SurfaceObject::~SurfaceObject() +{ +} + +void SurfaceObject::setUpSmoothData(QList<qreal> series, int columns, int rows, GLfloat yRange, bool changeGeometry) +{ + GLfloat width = (GLfloat(columns) - 1.0f) / 2.0f; + GLfloat depth = (GLfloat(rows) - 1.0f) / -2.0f; + GLfloat height = yRange / 2.0f; + + // Create vertice table + QVector<QVector3D> vertices; + QVector<QVector2D> uvs; + float uvX = 1.0 / float(columns - 1); + float uvY = 1.0 / float(rows - 1); + int row = 0; + for (float i = 0.0f; i < float(rows); i += 1.0, row += columns) { + for (float j = 0; j < columns; j++) { + vertices.append(QVector3D(j / width - 1.0f, + series.at(row + int(j)) / height - 1.0f, + i / depth + 1.0f)); + uvs.append(QVector2D(j * uvX, i * uvY)); + } + } + + // Create normals + QVector<QVector3D> normals; + for (int row = 0; row < (rows - 1) * columns; row += columns) { + for (int j = 0; j < columns - 1; j++) { + normals.append(normal(vertices.at(row + j), + vertices.at(row + j + 1), + vertices.at(row + columns + j))); + } + int p = row + columns - 1; + normals.append(normal(vertices.at(p), + vertices.at(p + columns), + vertices.at(p - 1))); + } + for (int j = (rows - 1) * columns ; j < rows * columns - 1; j++) { + normals.append(normal(vertices.at(j), + vertices.at(j - columns), + vertices.at(j + 1))); + } + int p = rows * columns - 1; + normals.append(normal(vertices.at(p), + vertices.at(p - 1), + vertices.at(p - columns - 1))); + + // Create indices table + GLint *indices = 0; + if (changeGeometry) { + m_indexCount = 6 * (columns - 1) * (rows - 1); + indices = new GLint[m_indexCount]; + p = 0; + for (int row = 0; row < (rows - 1) * columns; row += columns) { + for (int j = 0; j < columns - 1; j++) { + // Left triangle + indices[p++] = row + j + 1; + indices[p++] = row + columns + j; + indices[p++] = row + j; + + // Right triangle + indices[p++] = row + columns + j + 1; + indices[p++] = row + columns + j; + indices[p++] = row + j + 1; + } + } + } + + // Create line element indices + GLint *gridIndices = 0; + if (changeGeometry) { + m_gridIndexCount = 2 * columns * (rows - 1) + 2 * rows * (columns - 1); + gridIndices = new GLint[m_gridIndexCount]; + p = 0; + for (int i = 0, row = 0; i < rows; i++, row += columns) { + for (int j = 0; j < columns - 1; j++) { + gridIndices[p++] = row + j; + gridIndices[p++] = row + j + 1; + } + } + for (int i = 0, row = 0; i < rows - 1; i++, row += columns) { + for (int j = 0; j < columns; j++) { + gridIndices[p++] = row + j; + gridIndices[p++] = row + j + columns; + } + } + } + + createBuffers(vertices, uvs, normals, indices, gridIndices, changeGeometry); + + if (indices) + delete indices; + if (gridIndices) + delete gridIndices; +} + + +void SurfaceObject::setUpData(QList<qreal> series, int columns, int rows, GLfloat yRange, bool changeGeometry) +{ + GLfloat width = (GLfloat(columns) - 1.0f) / 2.0f; + GLfloat depth = (GLfloat(rows) - 1.0f) / -2.0f; + GLfloat height = yRange / 2.0f; + float uvX = 1.0 / float(columns - 1); + float uvY = 1.0 / float(rows - 1); + + // Create vertice table + QVector<QVector3D> vertices; + QVector<QVector2D> uvs; + int row = 0; + for (float i = 0.0f; i < float(rows); i += 1.0f, row += columns) { + for (float j = 0.0f; j < float(columns); j += 1.0f) { + vertices.append(QVector3D(j / width - 1.0f, + series.at(row + int(j)) / height - 1.0f, + i / depth + 1.0f)); + uvs.append(QVector2D(j * uvX, i * uvY)); + if (j > 0 && j < columns - 1) { + vertices.append(vertices.last()); + uvs.append(uvs.last()); + } + } + } + + // Create normals & indices table + QVector<QVector3D> normals; + int doubleColumns = columns * 2 - 2; + + GLint *indices = 0; + int p = 0; + if (changeGeometry) { + m_indexCount = 6 * (columns - 1) * (rows - 1); + indices = new GLint[m_indexCount]; + } + + for (int row = 0, upperRow = doubleColumns; + row < (rows - 1) * doubleColumns; + row += doubleColumns, upperRow += doubleColumns) { + for (int j = 0; j < doubleColumns; j += 2) { + // Normal for the left triangle + normals.append(normal(vertices.at(row + j), + vertices.at(row + j + 1), + vertices.at(upperRow + j))); + + // Normal for the right triangle + normals.append(normal(vertices.at(row + j + 1), + vertices.at(upperRow + j + 1), + vertices.at(upperRow + j))); + + if (changeGeometry) { + // Left triangle + indices[p++] = row + j + 1; + indices[p++] = upperRow + j; + indices[p++] = row + j; + + // Right triangle + indices[p++] = upperRow + j + 1; + indices[p++] = upperRow + j; + indices[p++] = row + j + 1; + } + } + } + + // Create grid line element indices + m_gridIndexCount = 2 * columns * (rows - 1) + 2 * rows * (columns - 1); + GLint *gridIndices = new GLint[m_gridIndexCount]; + p = 0; + int rowLimit = (rows - 1) * doubleColumns; + for (int row = 0; row < rows * doubleColumns; row += doubleColumns) { + for (int j = 0; j < doubleColumns; j += 2) { + gridIndices[p++] = row + j; + gridIndices[p++] = row + j + 1; + + if (row < rowLimit) { + gridIndices[p++] = row + j; + gridIndices[p++] = row + j + doubleColumns; + } + } + } + for (int i = doubleColumns - 1; i < rowLimit; i += doubleColumns) { + gridIndices[p++] = i; + gridIndices[p++] = i + doubleColumns; + } + + createBuffers(vertices, uvs, normals, indices, gridIndices, changeGeometry); + + if (indices) + delete indices; + if (gridIndices) + delete gridIndices; +} + + +void SurfaceObject::createBuffers(const QVector<QVector3D> &vertices, const QVector<QVector2D> &uvs, + const QVector<QVector3D> &normals, const GLint *indices, + const GLint *gridIndices, bool changeGeometry) +{ + initializeOpenGLFunctions(); + if (m_meshDataLoaded) { + // Delete old data + glDeleteBuffers(1, &m_vertexbuffer); + glDeleteBuffers(1, &m_normalbuffer); + if (changeGeometry) { + glDeleteBuffers(1, &m_uvbuffer); + glDeleteBuffers(1, &m_elementbuffer); + glDeleteBuffers(1, &m_gridElementbuffer); + } + } + + // Move to buffers + glGenBuffers(1, &m_vertexbuffer); + glBindBuffer(GL_ARRAY_BUFFER, m_vertexbuffer); + glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(QVector3D), + &vertices.at(0), GL_STATIC_DRAW); + + glGenBuffers(1, &m_normalbuffer); + glBindBuffer(GL_ARRAY_BUFFER, m_normalbuffer); + glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(QVector3D), + &normals.at(0), GL_STATIC_DRAW); + + if (changeGeometry) { + glGenBuffers(1, &m_uvbuffer); + glBindBuffer(GL_ARRAY_BUFFER, m_uvbuffer); + glBufferData(GL_ARRAY_BUFFER, uvs.size() * sizeof(QVector2D), + &uvs.at(0), GL_STATIC_DRAW); + + glGenBuffers(1, &m_elementbuffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementbuffer); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indexCount * sizeof(GLint), + indices, GL_STATIC_DRAW); + + glGenBuffers(1, &m_gridElementbuffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_gridElementbuffer); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_gridIndexCount * sizeof(GLint), + gridIndices, GL_STATIC_DRAW); + } + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + + // We're done. Set the flag ON + m_meshDataLoaded = true; +} + +GLuint SurfaceObject::gridElementBuf() +{ + if (!m_meshDataLoaded) + qFatal("No loaded object"); + return m_gridElementbuffer; +} + +GLuint SurfaceObject::gridIndexCount() +{ + return m_gridIndexCount; +} + +QVector3D SurfaceObject::normal(const QVector3D &a, const QVector3D &b, const QVector3D &c) +{ + QVector3D v1 = b - a; + QVector3D v2 = c - a; + return QVector3D::crossProduct(v1, v2); +} + +QT_DATAVIS3D_END_NAMESPACE + + + +// For rainy days + +// QVector3D vertices[] = { +// QVector3D(-0.5f, 0.0f, 0.1f), +// QVector3D(0.5f, 0.0f, 0.1f), +// QVector3D(0.0f, 1.0f, -0.5f) +// }; + +// QVector3D normals[] = { +// QVector3D(0.5, 0.0, 1.0), +// QVector3D(0.5, 0.0, 1.0), +// QVector3D(0.5, 0.0, 1.0) +// }; + +// vertices.append(QVector3D(-1.0f, 0.0f, 0.1f)); +// vertices.append(QVector3D(0.0f, 0.0f, 0.1f)); +// vertices.append(QVector3D(0.0f, 0.5f, -0.5f)); + +// normals.append(QVector3D(0.5, 0.0, 1.0)); +// normals.append(QVector3D(0.5, 0.0, 1.0)); +// normals.append(QVector3D(0.5, 0.0, 1.0)); + +//GLushort indices[] = {0, 1, 2, 1, 3, 2}; +//GLushort indices[] = {1, 3, 2}; + +//qDebug() << indices[p + 0] << ", " << indices[p + 1] << ", " << indices[p + 2]; +//qDebug() << indices[p + 3] << ", " << indices[p + 4] << ", " << indices[p + 5]; + +//qDebug() << "(" << float(j) / width << ", 0.0, " << float(i) / depth * -1.0f << ")"; + +//normals.append(QVector3D(1,0,0)); +//normals.append(QVector3D(0,1,0)); +//normals.append(QVector3D(0,0,1)); +//normals.append(QVector3D(1,0,1)); + +//normals.append(QVector3D(1,0,0)); +//normals.append(QVector3D(0,1,0)); +//normals.append(QVector3D(0,0,1)); +//normals.append(QVector3D(1,0,1)); + +//normals.append(QVector3D(1,0,0)); +//normals.append(QVector3D(0,1,0)); +//normals.append(QVector3D(0,0,1)); +//normals.append(QVector3D(1,0,1)); + + +//qDebug() << "Left normal from (" << row + j << ", " << row + j + 1 << ", " << row + doubleColumns + j << ")"; + +//qDebug() << "right normal from (" << row + j +1 << ", " << row + doubleColumns + j + 1 << ", " << row + doubleColumns + j << ")"; + diff --git a/src/datavis3d/utils/surfaceobject_p.h b/src/datavis3d/utils/surfaceobject_p.h new file mode 100644 index 00000000..729757c4 --- /dev/null +++ b/src/datavis3d/utils/surfaceobject_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +// +// 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 SURFACEOBJECT_P_H +#define SURFACEOBJECT_P_H + +#include "datavis3dglobal_p.h" +#include "abstractobjecthelper_p.h" +#include <QOpenGLFunctions> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class SurfaceObject : public AbstractObjectHelper +{ +public: + SurfaceObject(); + ~SurfaceObject(); + + void setUpData(QList<qreal> series, int columns, int rows, GLfloat yRange, bool changeGeometry); + void setUpSmoothData(QList<qreal> series, int columns, int rows, GLfloat yRange, bool changeGeometry); + GLuint gridElementBuf(); + GLuint gridIndexCount(); + +private: + QVector3D normal(const QVector3D &a, const QVector3D &b, const QVector3D &c); + void createBuffers(const QVector<QVector3D> &vertices, const QVector<QVector2D> &uvs, + const QVector<QVector3D> &normals, const GLint *indices, + const GLint *gridIndices, bool changeGeometry); + +private: + QList<qreal> m_series; + int m_dataWidth; + int m_dataDepth; + GLfloat m_yRange; + GLuint m_gridElementbuffer; + GLuint m_gridIndexCount; +}; + +QT_DATAVIS3D_END_NAMESPACE +#endif // SURFACEOBJECT_P_H diff --git a/src/datavis3d/utils/texturehelper.cpp b/src/datavis3d/utils/texturehelper.cpp index 3d827c50..1773c0f8 100644 --- a/src/datavis3d/utils/texturehelper.cpp +++ b/src/datavis3d/utils/texturehelper.cpp @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -46,7 +23,7 @@ #include <QDebug> -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE TextureHelper::TextureHelper() { @@ -101,6 +78,22 @@ GLuint TextureHelper::create2DTexture(const QImage &image, bool useTrilinearFilt return textureId; } +GLuint TextureHelper::create2DTexture(const uchar *image, int width, int height) +{ + GLuint textureId; + glGenTextures(1, &textureId); + glBindTexture(GL_TEXTURE_2D, textureId); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_UNSIGNED_BYTE, image); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glBindTexture(GL_TEXTURE_2D, 0); + return textureId; +} + GLuint TextureHelper::createCubeMapTexture(const QImage &image, bool useTrilinearFiltering) { if (image.isNull()) @@ -139,8 +132,8 @@ GLuint TextureHelper::createSelectionBuffer(const QSize &size, GLuint &texture, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //#if !defined(QT_OPENGL_ES_2) -// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.width(), size.height(), 0, GL_RGB, -// GL_UNSIGNED_INT, NULL); +// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, GL_RGB, +// GL_UNSIGNED_BYTE, NULL); //#else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.width(), size.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); @@ -181,17 +174,18 @@ GLuint TextureHelper::createSelectionTexture(const QSize &size, GLuint &frameBuf glBindTexture(GL_TEXTURE_2D, textureid); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); -//#if !defined(QT_OPENGL_ES_2) -// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.width(), size.height(), 0, GL_RGB, -// GL_UNSIGNED_INT, NULL); -//#else +#if !defined(QT_OPENGL_ES_2) + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, GL_RGBA, + GL_UNSIGNED_BYTE, NULL); +#else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.width(), size.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); -//#endif +#endif glBindTexture(GL_TEXTURE_2D, 0); // Create render buffer - glGenRenderbuffers(1, &depthBuffer); + if (!depthBuffer) + glGenRenderbuffers(1, &depthBuffer); glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer); #if !defined(QT_OPENGL_ES_2) glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size.width(), size.height()); @@ -201,7 +195,8 @@ GLuint TextureHelper::createSelectionTexture(const QSize &size, GLuint &frameBuf glBindRenderbuffer(GL_RENDERBUFFER, 0); // Create frame buffer - glGenFramebuffers(1, &frameBuffer); + if (!frameBuffer) + glGenFramebuffers(1, &frameBuffer); glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); // Attach texture to color attachment @@ -241,7 +236,8 @@ GLuint TextureHelper::createDepthTexture(const QSize &size, GLuint &frameBuffer, glBindTexture(GL_TEXTURE_2D, 0); // Create frame buffer - glGenFramebuffers(1, &frameBuffer); + if (!frameBuffer) + glGenFramebuffers(1, &frameBuffer); glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); // Attach texture to depth attachment @@ -395,4 +391,4 @@ QRgb TextureHelper::qt_gl_convertToGLFormatHelper(QRgb src_pixel, GLenum texture } } -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/utils/texturehelper_p.h b/src/datavis3d/utils/texturehelper_p.h index e848f063..e8f17d33 100644 --- a/src/datavis3d/utils/texturehelper_p.h +++ b/src/datavis3d/utils/texturehelper_p.h @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -43,7 +20,7 @@ // W A R N I N G // ------------- // -// This file is not part of the Qt API. It exists purely as an +// 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. // @@ -52,11 +29,11 @@ #ifndef TEXTUREHELPER_P_H #define TEXTUREHELPER_P_H -#include "qdatavis3dglobal.h" +#include "datavis3dglobal_p.h" #include <QOpenGLFunctions> #include <QRgb> -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE class TextureHelper : protected QOpenGLFunctions { @@ -67,6 +44,7 @@ class TextureHelper : protected QOpenGLFunctions // Ownership of created texture is transferred to caller GLuint create2DTexture(const QImage &image, bool useTrilinearFiltering = false, bool convert = true); + GLuint create2DTexture(const uchar *image, int width, int height); GLuint createCubeMapTexture(const QImage &image, bool useTrilinearFiltering = false); // Returns selection framebuffer and inserts generated texture id to texture parameters GLuint createSelectionBuffer(const QSize &size, GLuint &texture, GLuint &depthTexture); @@ -83,10 +61,12 @@ class TextureHelper : protected QOpenGLFunctions void convertToGLFormatHelper(QImage &dstImage, const QImage &srcImage, GLenum texture_format); QRgb qt_gl_convertToGLFormatHelper(QRgb src_pixel, GLenum texture_format); - friend class Q3DBarsPrivate; - friend class Q3DMapsPrivate; + friend class Bars3dRenderer; + friend class Maps3DController; + friend class Surface3dRenderer; + friend class Scatter3DRenderer; }; -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE #endif diff --git a/src/datavis3d/utils/utils.cpp b/src/datavis3d/utils/utils.cpp index 7acca185..cf6b91f8 100644 --- a/src/datavis3d/utils/utils.cpp +++ b/src/datavis3d/utils/utils.cpp @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -51,7 +28,7 @@ #include <QDebug> -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE #define NUM_IN_POWER(y, x) for (;y<x;y<<=1) #define MIN_POWER 32 @@ -110,23 +87,23 @@ void Utils::printText(QPainter *painter, const QString &text, const QSize &posit if (absoluteCoords) { // This assumes absolute screen coordinates painter->translate(position.width() - (((float)bgrStrLen / 2.0f) - * cos(rotation * m_pi / 180.0f)) - + (((float)bgrHeight / 2.0f) * sin(rotation * m_pi / 180.0f)), + * qCos(qDegreesToRadians(rotation))) + + (((float)bgrHeight / 2.0f) * qSin(qDegreesToRadians(rotation))), position.height() - - ((((float)bgrHeight / 2.0f) * cos(rotation * m_pi / 180.0f)) - + (((float)bgrStrLen / 2.0f) * sin(rotation * m_pi / 180.0f)))); + - ((((float)bgrHeight / 2.0f) * qCos(qDegreesToRadians(rotation))) + + (((float)bgrStrLen / 2.0f) * qSin(qDegreesToRadians(rotation))))); } else { // This calculates y as a distance from screen bottom painter->translate(position.width() - (((float)bgrStrLen / 2.0f) - * cos(rotation * m_pi / 180.0f)) - + (((float)bgrHeight / 2.0f) * sin(rotation * m_pi / 180.0f)), + * qCos(qDegreesToRadians(rotation))) + + (((float)bgrHeight / 2.0f) * qSin(qDegreesToRadians(rotation))), painter->window().height() - position.height() - - ((((float)bgrHeight / 2.0f) * cos(rotation * m_pi / 180.0f)) - + (((float)bgrStrLen / 2.0f) * sin(rotation * m_pi / 180.0f)))); + - ((((float)bgrHeight / 2.0f) * qCos(qDegreesToRadians(rotation))) + + (((float)bgrStrLen / 2.0f) * qSin(qDegreesToRadians(rotation))))); } //qDebug() << painter->window().height() - position.height() - // - ((((float)bgrHeight / 2.0f) * cos(rotation * m_pi / 180.0f)) - // + (((float)bgrStrLen / 2.0f) * sin(rotation * m_pi / 180.0f))); + // - ((((float)bgrHeight / 2.0f) * qCos(qDegreesToRadians(rotation))) + // + (((float)bgrStrLen / 2.0f) * qSin(qDegreesToRadians(rotation)))); painter->rotate(rotation); painter->drawText(0, 0, bgrStrLen, bgrHeight, @@ -144,7 +121,7 @@ void Utils::printText(QPainter *painter, const QString &text, const QSize &posit } QImage Utils::printTextToImage(const QFont &font, const QString &text, const QColor &bgrColor, - const QColor &txtColor, LabelTransparency transparency) + const QColor &txtColor, QDataVis::LabelTransparency transparency) { GLuint paddingWidth = 15; GLuint paddingHeight = 15; @@ -170,7 +147,7 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo paddingHeight /= 2; //qDebug() << "label size after padding" << labelSize << paddingWidth << paddingHeight; #else - if (TransparencyNoBackground == transparency) + if (QDataVis::TransparencyNoBackground == transparency) labelSize = QSize(valueStrWidth, valueStrHeight); else labelSize = QSize(valueStrWidth + paddingWidth * 2, valueStrHeight + paddingHeight * 2); @@ -187,7 +164,7 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo painter.setCompositionMode(QPainter::CompositionMode_Source); switch (transparency) { // TODO: Texture size padding fix for Android f**ks this up for axis labels. Fix or disable for android. - case TransparencyNoBackground: { + case QDataVis::TransparencyNoBackground: { painter.setFont(valueFont); painter.setPen(txtColor); painter.drawText(0, 0, @@ -196,7 +173,7 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo text); break; } - case TransparencyFromTheme: { + case QDataVis::TransparencyFromTheme: { painter.setBrush(QBrush(bgrColor)); painter.setPen(bgrColor); painter.drawRoundedRect(0, 0, labelSize.width(), labelSize.height(), 10.0, 10.0f); @@ -208,7 +185,7 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo text); break; } - case TransparencyNone: { + case QDataVis::TransparencyNone: { painter.setBrush(QBrush(bgrColor)); painter.setPen(bgrColor); painter.drawRect(0, 0, labelSize.width(), labelSize.height()); @@ -254,4 +231,4 @@ QVector3D Utils::getSelection(QPoint mousepos, int height) return selectedColor; } -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/utils/utils.pri b/src/datavis3d/utils/utils.pri index 566af55f..cef5ebf0 100644 --- a/src/datavis3d/utils/utils.pri +++ b/src/datavis3d/utils/utils.pri @@ -4,7 +4,9 @@ HEADERS += $$PWD/meshloader_p.h \ $$PWD/shaderhelper_p.h \ $$PWD/objecthelper_p.h \ $$PWD/texturehelper_p.h \ - $$PWD/utils_p.h + $$PWD/utils_p.h \ + $$PWD/abstractobjecthelper_p.h \ + $$PWD/surfaceobject_p.h SOURCES += $$PWD/meshloader.cpp \ $$PWD/vertexindexer.cpp \ @@ -12,4 +14,6 @@ SOURCES += $$PWD/meshloader.cpp \ $$PWD/shaderhelper.cpp \ $$PWD/objecthelper.cpp \ $$PWD/texturehelper.cpp \ - $$PWD/utils.cpp + $$PWD/utils.cpp \ + $$PWD/abstractobjecthelper.cpp \ + $$PWD/surfaceobject.cpp diff --git a/src/datavis3d/utils/utils_p.h b/src/datavis3d/utils/utils_p.h index f809dad7..fe7d6081 100644 --- a/src/datavis3d/utils/utils_p.h +++ b/src/datavis3d/utils/utils_p.h @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -43,7 +20,7 @@ // W A R N I N G // ------------- // -// This file is not part of the Qt API. It exists purely as an +// 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. // @@ -52,8 +29,7 @@ #ifndef UTILS_P_H #define UTILS_P_H -#include "qdatavis3dglobal.h" -#include "qdatavis3namespace.h" +#include "datavis3dglobal_p.h" #include "q3dbars.h" class QVector3D; @@ -63,7 +39,7 @@ class QString; class QPoint; class QImage; -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE class Utils { @@ -76,10 +52,10 @@ class Utils const QString &text, const QColor &bgrColor, const QColor &txtColor, - LabelTransparency transparency); + QDataVis::LabelTransparency transparency); static QVector3D getSelection(QPoint mousepos, int height); }; -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE #endif diff --git a/src/datavis3d/utils/vertexindexer.cpp b/src/datavis3d/utils/vertexindexer.cpp index c1dfb1aa..6efba116 100644 --- a/src/datavis3d/utils/vertexindexer.cpp +++ b/src/datavis3d/utils/vertexindexer.cpp @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -46,14 +23,14 @@ #include <QDebug> -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE int unique_vertices = 0; // Returns true if v1 can be considered equal to v2 bool VertexIndexer::is_near(float v1, float v2) { - return qFabs(v1 - v2) < 0.01f; + return qAbs(v1 - v2) < 0.01f; } // Searches through all already-exported vertices @@ -173,4 +150,4 @@ void VertexIndexer::indexVBO_TBN(const QVector<QVector3D> &in_vertices, //qDebug() << "unique vertices" << unique_vertices; } -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/utils/vertexindexer_p.h b/src/datavis3d/utils/vertexindexer_p.h index cced863b..3ca62236 100644 --- a/src/datavis3d/utils/vertexindexer_p.h +++ b/src/datavis3d/utils/vertexindexer_p.h @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com ** ** 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 +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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. +** a written agreement between you and Digia. ** -** 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$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -43,7 +20,7 @@ // W A R N I N G // ------------- // -// This file is not part of the Qt API. It exists purely as an +// 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. // @@ -52,13 +29,13 @@ #ifndef VERTEXINDEXER_P_H #define VERTEXINDEXER_P_H -#include "qdatavis3dglobal.h" +#include "datavis3dglobal_p.h" #include <QVector> #include <QVector2D> #include <QVector3D> -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE class VertexIndexer { @@ -106,6 +83,6 @@ class VertexIndexer unsigned short &result); }; -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE #endif |