diff options
Diffstat (limited to 'src/datavisualization/utils')
20 files changed, 134 insertions, 142 deletions
diff --git a/src/datavisualization/utils/abstractobjecthelper.cpp b/src/datavisualization/utils/abstractobjecthelper.cpp index 96cdc0c4..9ced43a1 100644 --- a/src/datavisualization/utils/abstractobjecthelper.cpp +++ b/src/datavisualization/utils/abstractobjecthelper.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -20,7 +20,7 @@ #include <QDebug> -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION AbstractObjectHelper::AbstractObjectHelper() : m_vertexbuffer(0), @@ -80,4 +80,4 @@ GLuint AbstractObjectHelper::indicesType() return m_indicesType; } -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/utils/abstractobjecthelper_p.h b/src/datavisualization/utils/abstractobjecthelper_p.h index a6de6941..5ec34318 100644 --- a/src/datavisualization/utils/abstractobjecthelper_p.h +++ b/src/datavisualization/utils/abstractobjecthelper_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -32,7 +32,7 @@ #include "datavisualizationglobal_p.h" #include <QOpenGLFunctions> -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION class AbstractObjectHelper: protected QOpenGLFunctions { @@ -60,6 +60,6 @@ public: GLuint m_indicesType; }; -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION -#endif // ABSTRACTOBJECTHELPER_H +#endif diff --git a/src/datavisualization/utils/camerahelper.cpp b/src/datavisualization/utils/camerahelper.cpp index 9e7e58aa..220c49db 100644 --- a/src/datavisualization/utils/camerahelper.cpp +++ b/src/datavisualization/utils/camerahelper.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -22,7 +22,7 @@ #include <QMatrix4x4> #include <QVector3D> -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION CameraHelper::CameraHelper(QObject *parent) : QObject(parent), @@ -42,8 +42,6 @@ CameraHelper::~CameraHelper() { } - -// FUNCTIONS void CameraHelper::setRotationSpeed(int speed) { // increase for faster rotation @@ -106,7 +104,6 @@ QMatrix4x4 CameraHelper::calculateViewMatrix(const QPoint &mousePos, int zoom, viewMatrix.scale((GLfloat)zoom / 100.0f); // Compensate for translation (if m_target is off origin) viewMatrix.translate(-m_target.x(), -m_target.y(), -m_target.z()); - //qDebug() << m_xRotation << m_yRotation; m_previousMousePos = mousePos; return viewMatrix; @@ -135,7 +132,6 @@ QVector3D CameraHelper::calculateLightPosition(const QVector3D &lightPosition, newLightPosition = QVector3D(-xPos + lightPosition.x(), yPos + lightPosition.y(), zPos + lightPosition.z()); - //qDebug() << newLightPosition << xAngle << yAngle << fixedRotation; return newLightPosition; } @@ -159,122 +155,98 @@ void CameraHelper::setCameraPreset(Q3DCamera::CameraPreset preset) { switch (preset) { case Q3DCamera::CameraPresetFrontLow: { - qDebug("CameraPresetFrontLow"); CameraHelper::setCameraRotation(QPointF(0.0f, 0.0f)); break; } case Q3DCamera::CameraPresetFront: { - qDebug("CameraPresetFront"); CameraHelper::setCameraRotation(QPointF(0.0f, 22.5f)); break; } case Q3DCamera::CameraPresetFrontHigh: { - qDebug("CameraPresetFrontHigh"); CameraHelper::setCameraRotation(QPointF(0.0f, 45.0f)); break; } case Q3DCamera::CameraPresetLeftLow: { - qDebug("CameraPresetLeftLow"); CameraHelper::setCameraRotation(QPointF(90.0f, 0.0f)); break; } case Q3DCamera::CameraPresetLeft: { - qDebug("CameraPresetLeft"); CameraHelper::setCameraRotation(QPointF(90.0f, 22.5f)); break; } case Q3DCamera::CameraPresetLeftHigh: { - qDebug("CameraPresetLeftHigh"); CameraHelper::setCameraRotation(QPointF(90.0f, 45.0f)); break; } case Q3DCamera::CameraPresetRightLow: { - qDebug("CameraPresetRightLow"); CameraHelper::setCameraRotation(QPointF(-90.0f, 0.0f)); break; } case Q3DCamera::CameraPresetRight: { - qDebug("CameraPresetRight"); CameraHelper::setCameraRotation(QPointF(-90.0f, 22.5f)); break; } case Q3DCamera::CameraPresetRightHigh: { - qDebug("CameraPresetRightHigh"); CameraHelper::setCameraRotation(QPointF(-90.0f, 45.0f)); break; } case Q3DCamera::CameraPresetBehindLow: { - qDebug("CameraPresetBehindLow"); CameraHelper::setCameraRotation(QPointF(180.0f, 0.0f)); break; } case Q3DCamera::CameraPresetBehind: { - qDebug("CameraPresetBehind"); CameraHelper::setCameraRotation(QPointF(180.0f, 22.5f)); break; } case Q3DCamera::CameraPresetBehindHigh: { - qDebug("CameraPresetBehindHigh"); CameraHelper::setCameraRotation(QPointF(180.0f, 45.0f)); break; } case Q3DCamera::CameraPresetIsometricLeft: { - qDebug("CameraPresetIsometricLeft"); CameraHelper::setCameraRotation(QPointF(45.0f, 22.5f)); break; } case Q3DCamera::CameraPresetIsometricLeftHigh: { - qDebug("CameraPresetIsometricLeftHigh"); CameraHelper::setCameraRotation(QPointF(45.0f, 45.0f)); break; } case Q3DCamera::CameraPresetIsometricRight: { - qDebug("CameraPresetIsometricRight"); CameraHelper::setCameraRotation(QPointF(-45.0f, 22.5f)); break; } case Q3DCamera::CameraPresetIsometricRightHigh: { - qDebug("CameraPresetIsometricRightHigh"); CameraHelper::setCameraRotation(QPointF(-45.0f, 45.0f)); break; } case Q3DCamera::CameraPresetDirectlyAbove: { - qDebug("CameraPresetDirectlyAbove"); CameraHelper::setCameraRotation(QPointF(0.0f, 90.0f)); break; } case Q3DCamera::CameraPresetDirectlyAboveCW45: { - qDebug("CameraPresetDirectlyAboveCW45"); CameraHelper::setCameraRotation(QPointF(-45.0f, 90.0f)); break; } case Q3DCamera::CameraPresetDirectlyAboveCCW45: { - qDebug("CameraPresetDirectlyAboveCCW45"); CameraHelper::setCameraRotation(QPointF(45.0f, 90.0f)); break; } case Q3DCamera::CameraPresetFrontBelow: { - qDebug("CameraPresetFrontBelow"); CameraHelper::setCameraRotation(QPointF(0.0f, -45.0f)); break; } case Q3DCamera::CameraPresetLeftBelow: { - qDebug("CameraPresetLeftBelow"); CameraHelper::setCameraRotation(QPointF(90.0f, -45.0f)); break; } case Q3DCamera::CameraPresetRightBelow: { - qDebug("CameraPresetRightBelow"); CameraHelper::setCameraRotation(QPointF(-90.0f, -45.0f)); break; } case Q3DCamera::CameraPresetBehindBelow: { - qDebug("CameraPresetBehindBelow"); CameraHelper::setCameraRotation(QPointF(180.0f, -45.0f)); break; } case Q3DCamera::CameraPresetDirectlyBelow: { - qDebug("CameraPresetDirectlyBelow"); CameraHelper::setCameraRotation(QPointF(0.0f, -90.0f)); break; } @@ -283,4 +255,4 @@ void CameraHelper::setCameraPreset(Q3DCamera::CameraPreset preset) } } -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/utils/camerahelper_p.h b/src/datavisualization/utils/camerahelper_p.h index 50de93a8..e78bc24c 100644 --- a/src/datavisualization/utils/camerahelper_p.h +++ b/src/datavisualization/utils/camerahelper_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -26,8 +26,8 @@ // // We mean it. -#ifndef CAMERAPOSITIONER_P_H -#define CAMERAPOSITIONER_P_H +#ifndef CAMERAHELPER_P_H +#define CAMERAHELPER_P_H #include "datavisualizationglobal_p.h" #include "q3dcamera.h" @@ -39,7 +39,7 @@ class QVector3D; class QPoint; class QPointF; -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION class CameraHelper : public QObject { @@ -86,6 +86,6 @@ public: void setCameraPreset(Q3DCamera::CameraPreset preset); }; -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION #endif diff --git a/src/datavisualization/utils/meshloader.cpp b/src/datavisualization/utils/meshloader.cpp index 119cde3a..49bdf710 100644 --- a/src/datavisualization/utils/meshloader.cpp +++ b/src/datavisualization/utils/meshloader.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -24,9 +24,7 @@ #include <QVector2D> #include <QVector3D> -#include <QDebug> - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION QString slashTag = QStringLiteral("/"); @@ -35,8 +33,6 @@ bool MeshLoader::loadOBJ(const QString &path, QVector<QVector2D> &out_uvs, QVector<QVector3D> &out_normals) { - //qDebug() << "Loading OBJ file" << path; - QVector<unsigned int> vertexIndices, uvIndices, normalIndices; QVector<QVector3D> temp_vertices; QVector<QVector2D> temp_uvs; @@ -96,9 +92,6 @@ bool MeshLoader::loadOBJ(const QString &path, normalIndices.append(normalIndex[1]); normalIndices.append(normalIndex[2]); } - else { - //qWarning("Line did not contain usable data"); - } } // For each vertex of each triangle @@ -122,4 +115,4 @@ bool MeshLoader::loadOBJ(const QString &path, return true; } -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/utils/meshloader_p.h b/src/datavisualization/utils/meshloader_p.h index 48551fff..e7425ae6 100644 --- a/src/datavisualization/utils/meshloader_p.h +++ b/src/datavisualization/utils/meshloader_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -34,7 +34,7 @@ class QVector2D; class QVector3D; -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION class MeshLoader { @@ -43,9 +43,8 @@ class MeshLoader QVector<QVector3D> &out_vertices, QVector<QVector2D> &out_uvs, QVector<QVector3D> &out_normals); - // TODO: add loaders for other formats? }; -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION #endif diff --git a/src/datavisualization/utils/objecthelper.cpp b/src/datavisualization/utils/objecthelper.cpp index 180ce009..97695193 100644 --- a/src/datavisualization/utils/objecthelper.cpp +++ b/src/datavisualization/utils/objecthelper.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -21,9 +21,7 @@ #include "objecthelper_p.h" #include "abstractobjecthelper_p.h" -#include <QDebug> - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION ObjectHelper::ObjectHelper(const QString &objectFile) : m_objectFile(objectFile) @@ -95,4 +93,4 @@ void ObjectHelper::load() m_meshDataLoaded = true; } -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/utils/objecthelper_p.h b/src/datavisualization/utils/objecthelper_p.h index 9d643fdd..f96fc87d 100644 --- a/src/datavisualization/utils/objecthelper_p.h +++ b/src/datavisualization/utils/objecthelper_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -33,7 +33,7 @@ #include "abstractobjecthelper_p.h" #include <QOpenGLFunctions> -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION class ObjectHelper : public AbstractObjectHelper { @@ -49,6 +49,6 @@ private: QString m_objectFile; }; -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION #endif diff --git a/src/datavisualization/utils/qutils.h b/src/datavisualization/utils/qutils.h new file mode 100644 index 00000000..43375a9c --- /dev/null +++ b/src/datavisualization/utils/qutils.h @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 QtDataVisualization 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 +** +****************************************************************************/ + +#ifndef QUTILS_H +#define QUTILS_H + +#include <QtGui/QSurfaceFormat> + +namespace QtDataVisualization { + +inline static QSurfaceFormat qDefaultSurfaceFormat(bool antialias = true) +{ + QSurfaceFormat surfaceFormat; + + surfaceFormat.setDepthBufferSize(24); + surfaceFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer); +#if !defined(QT_OPENGL_ES_2) + surfaceFormat.setRenderableType(QSurfaceFormat::OpenGL); +#else + // Antialias not supported for ES + antialias = false; + surfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES); +#endif + + if (antialias) + surfaceFormat.setSamples(8); + + return surfaceFormat; +} + +} + +#endif diff --git a/src/datavisualization/utils/shaderhelper.cpp b/src/datavisualization/utils/shaderhelper.cpp index b4d2ee76..d4df11b4 100644 --- a/src/datavisualization/utils/shaderhelper.cpp +++ b/src/datavisualization/utils/shaderhelper.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -20,7 +20,7 @@ #include <QOpenGLShader> -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION void discardDebugMsgs(QtMsgType type, const QMessageLogContext &context, const QString &msg) { @@ -92,6 +92,7 @@ void ShaderHelper::initialize() m_shadowUniform = m_program->uniformLocation("shadowMap"); m_gradientMinUniform = m_program->uniformLocation("gradMin"); m_gradientHeightUniform = m_program->uniformLocation("gradHeight"); + m_lightColorUniform = m_program->uniformLocation("lightColor"); m_initialized = true; } @@ -247,6 +248,13 @@ GLuint ShaderHelper::gradientHeight() return m_gradientHeightUniform; } +GLuint ShaderHelper::lightColor() +{ + if (!m_initialized) + qFatal("Shader not initialized"); + return m_lightColorUniform; +} + GLuint ShaderHelper::posAtt() { if (!m_initialized) @@ -268,4 +276,4 @@ GLuint ShaderHelper::normalAtt() return m_normalAttr; } -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/utils/shaderhelper_p.h b/src/datavisualization/utils/shaderhelper_p.h index 191b7bf6..34bbf39e 100644 --- a/src/datavisualization/utils/shaderhelper_p.h +++ b/src/datavisualization/utils/shaderhelper_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -34,7 +34,7 @@ class QOpenGLShaderProgram; -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION class ShaderHelper { @@ -73,6 +73,7 @@ class ShaderHelper GLuint shadow(); GLuint gradientMin(); GLuint gradientHeight(); + GLuint lightColor(); GLuint posAtt(); GLuint uvAtt(); @@ -106,10 +107,11 @@ class ShaderHelper GLuint m_shadowUniform; GLuint m_gradientMinUniform; GLuint m_gradientHeightUniform; + GLuint m_lightColorUniform; GLboolean m_initialized; }; -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION #endif diff --git a/src/datavisualization/utils/surfaceobject.cpp b/src/datavisualization/utils/surfaceobject.cpp index 6e4765e5..b0cd6c82 100644 --- a/src/datavisualization/utils/surfaceobject.cpp +++ b/src/datavisualization/utils/surfaceobject.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -22,9 +22,7 @@ #include <QVector3D> #include <QVector2D> -#include <QDebug> - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION SurfaceObject::SurfaceObject() { @@ -74,7 +72,8 @@ void SurfaceObject::setUpSmoothData(const QSurfaceDataArray &dataArray, const QR float normalizedX = ((data.x() - xMin) / xNormalizer); float normalizedY = ((data.y() - yMin) / yNormalizer); float normalizedZ = ((data.z() - zMin) / zNormalizer); - m_vertices[totalIndex] = QVector3D(normalizedX - 1.0f, normalizedY - 1.0f, normalizedZ + 1.0f); + m_vertices[totalIndex] = QVector3D(normalizedX - 1.0f, normalizedY - 1.0f, + normalizedZ + 1.0f); if (changeGeometry) uvs[totalIndex] = QVector2D(GLfloat(j) * uvX, GLfloat(i) * uvY); totalIndex++; @@ -195,7 +194,8 @@ void SurfaceObject::updateSmoothItem(const QSurfaceDataArray &dataArray, int row float normalizedX = ((data.x() - xMin) / xNormalizer); float normalizedY = ((data.y() - yMin) / yNormalizer); float normalizedZ = ((data.z() - zMin) / zNormalizer); - m_vertices[row * m_columns + column] = QVector3D(normalizedX - 1.0f, normalizedY - 1.0f, normalizedZ + 1.0f); + m_vertices[row * m_columns + column] = QVector3D(normalizedX - 1.0f, normalizedY - 1.0f, + normalizedZ + 1.0f); // Create normals int startRow = row; @@ -354,7 +354,8 @@ void SurfaceObject::setUpData(const QSurfaceDataArray &dataArray, const QRect &s float normalizedX = ((data.x() - xMin) / xNormalizer); float normalizedY = ((data.y() - yMin) / yNormalizer); float normalizedZ = ((data.z() - zMin) / zNormalizer); - m_vertices[totalIndex] = QVector3D(normalizedX - 1.0f, normalizedY - 1.0f, normalizedZ + 1.0f); + m_vertices[totalIndex] = QVector3D(normalizedX - 1.0f, normalizedY - 1.0f, + normalizedZ + 1.0f); if (changeGeometry) uvs[totalIndex] = QVector2D(GLfloat(j) * uvX, GLfloat(i) * uvY); @@ -681,4 +682,4 @@ QVector3D SurfaceObject::normal(const QVector3D &a, const QVector3D &b, const QV return QVector3D::crossProduct(v1, v2); } -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/utils/surfaceobject_p.h b/src/datavisualization/utils/surfaceobject_p.h index e035d905..ec1a30bd 100644 --- a/src/datavisualization/utils/surfaceobject_p.h +++ b/src/datavisualization/utils/surfaceobject_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -33,10 +33,9 @@ #include "abstractobjecthelper_p.h" #include "qsurfacedataproxy.h" -#include <QOpenGLFunctions> #include <QRect> -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION class SurfaceObject : public AbstractObjectHelper { @@ -85,5 +84,6 @@ private: QVector<QVector3D> m_normals; }; -QT_DATAVISUALIZATION_END_NAMESPACE -#endif // SURFACEOBJECT_P_H +QT_END_NAMESPACE_DATAVISUALIZATION + +#endif diff --git a/src/datavisualization/utils/texturehelper.cpp b/src/datavisualization/utils/texturehelper.cpp index c88fc8dc..b5079f1b 100644 --- a/src/datavisualization/utils/texturehelper.cpp +++ b/src/datavisualization/utils/texturehelper.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -24,7 +24,7 @@ #include <QDebug> -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION TextureHelper::TextureHelper() { @@ -43,7 +43,7 @@ GLuint TextureHelper::create2DTexture(const QImage &image, bool useTrilinearFilt QImage texImage = image; -#if defined(Q_OS_ANDROID) +#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) GLuint temp; //qDebug() << "old size" << image.size(); GLuint imageWidth = Utils::getNearestPowerOfTwo(image.width(), temp); @@ -367,4 +367,4 @@ QRgb TextureHelper::qt_gl_convertToGLFormatHelper(QRgb src_pixel, GLenum texture } } -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/utils/texturehelper_p.h b/src/datavisualization/utils/texturehelper_p.h index 11022495..17553f30 100644 --- a/src/datavisualization/utils/texturehelper_p.h +++ b/src/datavisualization/utils/texturehelper_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -34,7 +34,7 @@ #include <QRgb> #include <QLinearGradient> -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION class TextureHelper : protected QOpenGLFunctions { @@ -67,6 +67,6 @@ class TextureHelper : protected QOpenGLFunctions friend class Scatter3DRenderer; }; -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION #endif diff --git a/src/datavisualization/utils/utils.cpp b/src/datavisualization/utils/utils.cpp index e6f33032..482fc831 100644 --- a/src/datavisualization/utils/utils.cpp +++ b/src/datavisualization/utils/utils.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -26,7 +26,7 @@ #include <QRegExp> #include <qmath.h> -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION #define NUM_IN_POWER(y, x) for (;y<x;y<<=1) #define MIN_POWER 2 @@ -66,7 +66,7 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo valueStrWidth += paddingWidth / 2; // Fix clipping problem with skewed fonts (italic or italic-style) QSize labelSize; -#if defined(Q_OS_ANDROID) +#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) // Android can't handle textures with dimensions not in power of 2. Resize labels accordingly. // Add some padding before converting to power of two to avoid too tight fit GLuint prePadding = 5; @@ -74,10 +74,8 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo if (maxLabelWidth) valueStrWidth = maxLabelWidth + paddingWidth / 2; labelSize = QSize(valueStrWidth + prePadding, valueStrHeight + prePadding); - //qDebug() << "label size before padding" << text << labelSize; labelSize.setWidth(getNearestPowerOfTwo(labelSize.width(), paddingWidth)); labelSize.setHeight(getNearestPowerOfTwo(labelSize.height(), paddingHeight)); - //qDebug() << "label size after padding" << labelSize << paddingWidth << paddingHeight; #else if (!labelBackground) labelSize = QSize(valueStrWidth, valueStrHeight); @@ -97,7 +95,7 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo painter.setFont(valueFont); if (!labelBackground) { painter.setPen(txtColor); -#if defined(Q_OS_ANDROID) +#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) painter.drawText((labelSize.width() - valueStrWidth) / 2.0f, (labelSize.height() - valueStrHeight) / 2.0f, valueStrWidth, valueStrHeight, @@ -131,30 +129,12 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo QVector3D Utils::getSelection(QPoint mousepos, int height) { - //#if defined(QT_OPENGL_ES_2) - // This is the only one that works with ANGLE (ES 2.0) + // This is the only one that works with OpenGL ES 2.0, so we're forced to use it // Item count will be limited to 256*256*256 GLubyte pixel[4] = {255, 255, 255, 0}; glReadPixels(mousepos.x(), height - mousepos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void *)pixel); - - //qDebug() << "rgba" << pixel[0] << pixel[1] << pixel[2] << pixel[3] << "mousepos:" << mousepos << "height:" << height; - - //#else - // These work with desktop OpenGL - // They offer a lot higher possible object count and a possibility to use object ids - //GLuint pixel[3]; - //glReadPixels(mousepos.x(), height - mousepos.y(), 1, 1, - // GL_RGB, GL_UNSIGNED_INT, (void *)pixel); - //qDebug() << "rgba" << pixel[0] << pixel[1] << pixel[2];// << pixel[3]; - - //GLfloat pixel3[3]; - //glReadPixels(mousepos.x(), height - mousepos.y(), 1, 1, - // GL_RGB, GL_FLOAT, (void *)pixel3); - //qDebug() << "rgba" << pixel3[0] << pixel3[1] << pixel3[2];// << pixel[3]; - //#endif QVector3D selectedColor(pixel[0], pixel[1], pixel[2]); - //qDebug() << selectedColor; return selectedColor; } @@ -239,4 +219,4 @@ float Utils::wrapValue(float value, float min, float max) return value; } -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/utils/utils.pri b/src/datavisualization/utils/utils.pri index cef5ebf0..8ce8794e 100644 --- a/src/datavisualization/utils/utils.pri +++ b/src/datavisualization/utils/utils.pri @@ -6,7 +6,8 @@ HEADERS += $$PWD/meshloader_p.h \ $$PWD/texturehelper_p.h \ $$PWD/utils_p.h \ $$PWD/abstractobjecthelper_p.h \ - $$PWD/surfaceobject_p.h + $$PWD/surfaceobject_p.h \ + $$PWD/qutils.h SOURCES += $$PWD/meshloader.cpp \ $$PWD/vertexindexer.cpp \ diff --git a/src/datavisualization/utils/utils_p.h b/src/datavisualization/utils/utils_p.h index 3142e4c2..7288419b 100644 --- a/src/datavisualization/utils/utils_p.h +++ b/src/datavisualization/utils/utils_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -30,7 +30,6 @@ #define UTILS_P_H #include "datavisualizationglobal_p.h" -#include "q3dbars.h" class QVector3D; class QColor; @@ -39,7 +38,7 @@ class QString; class QPoint; class QImage; -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION class Utils { @@ -75,6 +74,6 @@ private: static ParamType mapFormatCharToParamType(const QChar &formatChar); }; -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION #endif diff --git a/src/datavisualization/utils/vertexindexer.cpp b/src/datavisualization/utils/vertexindexer.cpp index dafe5dbc..f089ce6e 100644 --- a/src/datavisualization/utils/vertexindexer.cpp +++ b/src/datavisualization/utils/vertexindexer.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -18,12 +18,9 @@ #include "vertexindexer_p.h" -#include <string.h> // for memcmp #include <qmath.h> -#include <QDebug> - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION int unique_vertices = 0; @@ -33,8 +30,7 @@ bool VertexIndexer::is_near(float v1, float v2) return qAbs(v1 - v2) < 0.01f; } -// Searches through all already exported vertices -// for a similar one. +// Searches through all already exported vertices for a similar one. // Similar = same position + same UVs + same normal bool VertexIndexer::getSimilarVertexIndex(const QVector3D &in_vertex, const QVector2D &in_uv, @@ -44,7 +40,7 @@ bool VertexIndexer::getSimilarVertexIndex(const QVector3D &in_vertex, QVector<QVector3D> &out_normals, unsigned short &result) { - // Lame linear search + // Linear search for (int i = 0; i < out_vertices.size(); i++) { if (is_near(in_vertex.x() , out_vertices[i].x()) && is_near(in_vertex.y() , out_vertices[i].y()) @@ -58,8 +54,7 @@ bool VertexIndexer::getSimilarVertexIndex(const QVector3D &in_vertex, return true; } } - // No other vertex could be used instead. - // Looks like we'll have to add it to the VBO. + // No other vertex could be used instead return false; } @@ -107,7 +102,6 @@ void VertexIndexer::indexVBO(const QVector<QVector3D> &in_vertices, VertexToOutIndex[packed] = newindex; } } - //qDebug() << "unique vertices" << unique_vertices; } void VertexIndexer::indexVBO_TBN(const QVector<QVector3D> &in_vertices, @@ -125,7 +119,6 @@ void VertexIndexer::indexVBO_TBN(const QVector<QVector3D> &in_vertices, unique_vertices = 0; // For each input vertex for (int i = 0; i < in_vertices.size(); i++) { - // Try to find a similar vertex in out_XXXX unsigned short index; bool found = getSimilarVertexIndex(in_vertices[i], in_uvs[i], in_normals[i], @@ -133,7 +126,6 @@ void VertexIndexer::indexVBO_TBN(const QVector<QVector3D> &in_vertices, if (found) { out_indices.append(index); - // Average the tangents and the bitangents out_tangents[index] += in_tangents[i]; out_bitangents[index] += in_bitangents[i]; @@ -147,7 +139,6 @@ void VertexIndexer::indexVBO_TBN(const QVector<QVector3D> &in_vertices, out_indices.append((unsigned short)out_vertices.size() - 1); } } - //qDebug() << "unique vertices" << unique_vertices; } -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/utils/vertexindexer_p.h b/src/datavisualization/utils/vertexindexer_p.h index 0cf1857b..fe100e21 100644 --- a/src/datavisualization/utils/vertexindexer_p.h +++ b/src/datavisualization/utils/vertexindexer_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc +** Copyright (C) 2014 Digia Plc ** All rights reserved. ** For any questions to Digia, please use contact form at http://qt.digia.com ** @@ -35,11 +35,11 @@ #include <QVector2D> #include <QVector3D> -QT_DATAVISUALIZATION_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE_DATAVISUALIZATION class VertexIndexer { - public: +public: struct PackedVertex { QVector3D position; QVector2D uv; @@ -69,7 +69,7 @@ class VertexIndexer QVector<QVector3D> &out_tangents, QVector<QVector3D> &out_bitangents); - private: +private: static bool is_near(float v1, float v2); static bool getSimilarVertexIndex(const QVector3D &in_vertex, const QVector2D &in_uv, @@ -83,6 +83,6 @@ class VertexIndexer unsigned short &result); }; -QT_DATAVISUALIZATION_END_NAMESPACE +QT_END_NAMESPACE_DATAVISUALIZATION #endif |