summaryrefslogtreecommitdiffstats
path: root/src/datavis3d
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-04-16 11:24:34 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-04-16 11:37:27 +0300
commit30bb9a571d9bccba1fb45f07277a014b91ac043c (patch)
treedde7607bd1c2be6b959f81723fe449ea158a440e /src/datavis3d
parentb228ba755311b8cb28e0253d9dbd111ae95ae90b (diff)
Object drawing and label generation moved to their own class
Change-Id: I3721b201dd83b471cb6d55f0dd7def908c4ab0be Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavis3d')
-rw-r--r--src/datavis3d/engine/drawer.cpp169
-rw-r--r--src/datavis3d/engine/drawer_p.h91
-rw-r--r--src/datavis3d/engine/engine.pri6
-rw-r--r--src/datavis3d/engine/q3dbars.cpp574
-rw-r--r--src/datavis3d/engine/q3dbars.h54
-rw-r--r--src/datavis3d/engine/q3dbars_p.h2
-rw-r--r--src/datavis3d/engine/q3dwindow.cpp14
-rw-r--r--src/datavis3d/engine/qdataitem.cpp14
-rw-r--r--src/datavis3d/engine/qdataitem.h1
-rw-r--r--src/datavis3d/engine/qdataitem_p.h4
-rw-r--r--src/datavis3d/engine/qdatarow.cpp4
-rw-r--r--src/datavis3d/engine/qdataset.cpp24
-rw-r--r--src/datavis3d/engine/qdataset.h10
-rw-r--r--src/datavis3d/engine/theme.cpp28
-rw-r--r--src/datavis3d/engine/theme_p.h1
-rw-r--r--src/datavis3d/utils/camerahelper.cpp22
-rw-r--r--src/datavis3d/utils/camerahelper_p.h16
-rw-r--r--src/datavis3d/utils/meshloader_p.h2
-rw-r--r--src/datavis3d/utils/objecthelper.cpp38
-rw-r--r--src/datavis3d/utils/shaderhelper.cpp32
-rw-r--r--src/datavis3d/utils/shaderhelper_p.h10
-rw-r--r--src/datavis3d/utils/texturehelper.cpp16
-rw-r--r--src/datavis3d/utils/texturehelper_p.h8
-rw-r--r--src/datavis3d/utils/utils.cpp93
-rw-r--r--src/datavis3d/utils/utils_p.h16
-rw-r--r--src/datavis3d/utils/vertexindexer.cpp68
-rw-r--r--src/datavis3d/utils/vertexindexer_p.h56
27 files changed, 803 insertions, 570 deletions
diff --git a/src/datavis3d/engine/drawer.cpp b/src/datavis3d/engine/drawer.cpp
new file mode 100644
index 00000000..c33dd625
--- /dev/null
+++ b/src/datavis3d/engine/drawer.cpp
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtDataVis3D module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "drawer_p.h"
+#include "shaderhelper_p.h"
+#include "objecthelper_p.h"
+#include "qdataitem.h"
+#include "qdataitem_p.h"
+#include "utils_p.h"
+#include "texturehelper_p.h"
+
+QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
+
+Drawer::Drawer(const Theme &theme, const QFont &font, Q3DBars::LabelTransparency transparency)
+ : m_theme(theme),
+ m_font(font),
+ m_transparency(transparency),
+ m_textureHelper(new TextureHelper())
+{
+ initializeOpenGLFunctions();
+}
+
+Drawer::~Drawer()
+{
+
+}
+
+void Drawer::setTheme(const Theme &theme)
+{
+ m_theme = theme;
+}
+
+void Drawer::setFont(const QFont &font)
+{
+ m_font = font;
+}
+
+void Drawer::setTransparency(Q3DBars::LabelTransparency transparency)
+{
+ m_transparency = transparency;
+}
+
+void Drawer::drawObject(ShaderHelper *shader, ObjectHelper *object, bool textured,
+ GLuint textureId)
+{
+ if (textured) {
+ // Activate texture
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, textureId);
+ shader->setUniformValue(shader->texture(), 0);
+ }
+
+ // 1st attribute buffer : vertices
+ glEnableVertexAttribArray(shader->posAtt());
+ glBindBuffer(GL_ARRAY_BUFFER, object->vertexBuf());
+ glVertexAttribPointer(shader->posAtt(), 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
+
+ // 2nd attribute buffer : normals
+ glEnableVertexAttribArray(shader->normalAtt());
+ glBindBuffer(GL_ARRAY_BUFFER, object->normalBuf());
+ glVertexAttribPointer(shader->normalAtt(), 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
+
+ if (textured) {
+ // 3rd attribute buffer : UVs
+ glEnableVertexAttribArray(shader->uvAtt());
+ glBindBuffer(GL_ARRAY_BUFFER, object->uvBuf());
+ glVertexAttribPointer(shader->uvAtt(), 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
+ }
+
+ // Index buffer
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object->elementBuf());
+
+ // Draw the triangles
+ glDrawElements(GL_TRIANGLES, object->indexCount(), GL_UNSIGNED_SHORT, (void*)0);
+
+ // Free buffers
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+
+ if (textured) {
+ glBindTexture(GL_TEXTURE_2D, 0);
+ glDisableVertexAttribArray(shader->uvAtt());
+ }
+ glDisableVertexAttribArray(shader->normalAtt());
+ glDisableVertexAttribArray(shader->posAtt());
+}
+
+void Drawer::generateLabelTexture(QDataItem *item)
+{
+ // Delete previous texture, if there is one
+ GLuint labelTexture = item->d_ptr->textureId();
+ if (labelTexture) {
+ // We have to do this, as we can't know if data is static or not;
+ // texture doesn't change with static data
+ // (basically we could create textures for all bars when data is added, but we
+ // may not need them -> better to do it here dynamically)
+ glDeleteTextures(1, &labelTexture);
+ item->d_ptr->setTextureId(0);
+ }
+
+ // Create labels
+ // Print label into a QImage using QPainter
+ QImage label = Utils::printTextToImage(m_font,
+ item->d_ptr->valueStr(),
+ m_theme.m_textBackgroundColor,
+ m_theme.m_textColor,
+ m_transparency);
+
+ // Set label size
+ item->d_ptr->setLabelSize(label.size());
+ // Insert text texture into label
+ item->d_ptr->setTextureId(m_textureHelper->create2DTexture(label, true, true));
+}
+
+GLuint Drawer::generateLabelTexture(const QString &text, QSize &labelSize)
+{
+ // Create labels
+ // Print label into a QImage using QPainter
+ QImage label = Utils::printTextToImage(m_font,
+ text,
+ m_theme.m_textBackgroundColor,
+ m_theme.m_textColor,
+ m_transparency);
+
+ // Set label size
+ labelSize = label.size();
+ // Insert text texture into label
+ return m_textureHelper->create2DTexture(label, true, true);
+}
+
+QTCOMMERCIALDATAVIS3D_END_NAMESPACE
diff --git a/src/datavis3d/engine/drawer_p.h b/src/datavis3d/engine/drawer_p.h
new file mode 100644
index 00000000..60cf06c5
--- /dev/null
+++ b/src/datavis3d/engine/drawer_p.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtDataVis3D module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt 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 DRAWER_P_H
+#define DRAWER_P_H
+
+#include "QtDataVis3D/qdatavis3dglobal.h"
+#include "q3dbars.h"
+#include "theme_p.h"
+#include <QFont>
+
+QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
+
+class QDataItem;
+class ShaderHelper;
+class ObjectHelper;
+class TextureHelper;
+
+class Drawer : protected QOpenGLFunctions
+{
+public:
+ explicit Drawer(const Theme &theme, const QFont &font, Q3DBars::LabelTransparency transparency);
+ ~Drawer();
+
+ void setTheme(const Theme &theme);
+ void setFont(const QFont &font);
+ void setTransparency(Q3DBars::LabelTransparency transparency);
+
+ void drawObject(ShaderHelper *shader, ObjectHelper *object, bool textured = false,
+ GLuint textureId = 0);
+ void generateLabelTexture(QDataItem *item);
+ GLuint generateLabelTexture(const QString &text, QSize &labelSize);
+
+private:
+ Theme m_theme;
+ QFont m_font;
+ Q3DBars::LabelTransparency m_transparency;
+ TextureHelper *m_textureHelper;
+};
+
+QTCOMMERCIALDATAVIS3D_END_NAMESPACE
+
+#endif
diff --git a/src/datavis3d/engine/engine.pri b/src/datavis3d/engine/engine.pri
index 7b5c7a67..e9d3fbb9 100644
--- a/src/datavis3d/engine/engine.pri
+++ b/src/datavis3d/engine/engine.pri
@@ -3,7 +3,8 @@ SOURCES += $$PWD/q3dwindow.cpp \
$$PWD/qdataitem.cpp \
$$PWD/qdatarow.cpp \
$$PWD/qdataset.cpp \
- $$PWD/theme.cpp
+ $$PWD/theme.cpp \
+ $$PWD/drawer.cpp
HEADERS += $$PWD/q3dwindow_p.h \
$$PWD/q3dwindow.h \
@@ -15,6 +16,7 @@ HEADERS += $$PWD/q3dwindow_p.h \
$$PWD/qdatarow_p.h \
$$PWD/qdataset.h \
$$PWD/qdataset_p.h \
- $$PWD/theme_p.h
+ $$PWD/theme_p.h \
+ $$PWD/drawer_p.h
RESOURCES += engine/engine.qrc
diff --git a/src/datavis3d/engine/q3dbars.cpp b/src/datavis3d/engine/q3dbars.cpp
index 5dc6b753..218351f0 100644
--- a/src/datavis3d/engine/q3dbars.cpp
+++ b/src/datavis3d/engine/q3dbars.cpp
@@ -50,6 +50,7 @@
#include "texturehelper_p.h"
#include "theme_p.h"
#include "utils_p.h"
+#include "drawer_p.h"
#include <QMatrix4x4>
#include <QOpenGLPaintDevice>
@@ -88,19 +89,19 @@ void Q3DBars::initialize()
{
// Initialize shaders
if (!d_ptr->m_theme->m_uniformColor) {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertex")
- , QStringLiteral(":/shaders/fragmentColorOnY"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragmentColorOnY"));
} else {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertex")
- , QStringLiteral(":/shaders/fragment"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragment"));
}
-// d_ptr->initBackgroundShaders(QStringLiteral(":/shaders/vertexTexture")
-// , QStringLiteral(":/shaders/fragmentTexture"));
- d_ptr->initBackgroundShaders(QStringLiteral(":/shaders/vertex")
- , QStringLiteral(":/shaders/fragment"));
+ // d_ptr->initBackgroundShaders(QStringLiteral(":/shaders/vertexTexture"),
+ // QStringLiteral(":/shaders/fragmentTexture"));
+ d_ptr->initBackgroundShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragment"));
#ifndef USE_PAINTER_TEXT
- d_ptr->initLabelShaders(QStringLiteral(":/shaders/vertexLabel")
- , QStringLiteral(":/shaders/fragmentLabel"));
+ d_ptr->initLabelShaders(QStringLiteral(":/shaders/vertexLabel"),
+ QStringLiteral(":/shaders/fragmentLabel"));
#endif
d_ptr->initSelectionShader();
@@ -128,9 +129,9 @@ void Q3DBars::initialize()
// Set initial camera position
// X must be 0 for rotation to work - we can use "setCameraRotation" for setting it later
- CameraHelper::setDefaultCameraOrientation(QVector3D(0.0f, 0.0f, 6.0f + zComp)
- , QVector3D(0.0f, 0.0f, zComp)
- , QVector3D(0.0f, 1.0f, 0.0f));
+ CameraHelper::setDefaultCameraOrientation(QVector3D(0.0f, 0.0f, 6.0f + zComp),
+ QVector3D(0.0f, 0.0f, zComp),
+ QVector3D(0.0f, 1.0f, 0.0f));
// Set view port
glViewport(0, 0, width(), height());
@@ -159,7 +160,7 @@ void Q3DBars::render()
// Measure speed (as milliseconds per frame)
nbFrames++;
if (lastTime.elapsed() >= 1000) { // print only if last measurement was more than 1s ago
- qDebug() << double(lastTime.elapsed()) / double(nbFrames) << "ms/frame (=" << double(nbFrames) << "fps)";
+ qDebug() << qreal(lastTime.elapsed()) / qreal(nbFrames) << "ms/frame (=" << qreal(nbFrames) << "fps)";
nbFrames = 0;
lastTime.restart();
}
@@ -271,8 +272,8 @@ void Q3DBars::drawZoomScene()
QVector3D lightPos;
// Specify viewport
- glViewport(d_ptr->m_zoomViewPort.x(), d_ptr->m_zoomViewPort.y()
- , d_ptr->m_zoomViewPort.width(), d_ptr->m_zoomViewPort.height());
+ glViewport(d_ptr->m_zoomViewPort.x(), d_ptr->m_zoomViewPort.y(),
+ d_ptr->m_zoomViewPort.width(), d_ptr->m_zoomViewPort.height());
// Set up projection matrix
QMatrix4x4 projectionMatrix;
@@ -281,10 +282,10 @@ void Q3DBars::drawZoomScene()
#ifdef ROTATE_ZOOM_SELECTION
// Calculate view matrix
- QMatrix4x4 viewMatrix = CameraHelper::calculateViewMatrix(d_ptr->m_mousePos
- , d_ptr->m_zoomLevel
- , d_ptr->m_zoomViewPort.width()
- , d_ptr->m_zoomViewPort.height());
+ QMatrix4x4 viewMatrix = CameraHelper::calculateViewMatrix(d_ptr->m_mousePos,
+ d_ptr->m_zoomLevel,
+ d_ptr->m_zoomViewPort.width(),
+ d_ptr->m_zoomViewPort.height());
// Get light position (rotate light with camera, a bit above it (as set in defaultLightPos))
lightPos = CameraHelper::calculateLightPosition(defaultLightPos);
@@ -298,13 +299,13 @@ void Q3DBars::drawZoomScene()
// Set view matrix
QMatrix4x4 viewMatrix;
#if 1
- viewMatrix.lookAt(QVector3D(0.0f, 0.0f, 5.0f + zComp)
- , QVector3D(0.0f, 0.0f, zComp)
- , QVector3D(0.0f, 1.0f, 0.0f));
+ viewMatrix.lookAt(QVector3D(0.0f, 0.0f, 5.0f + zComp),
+ QVector3D(0.0f, 0.0f, zComp),
+ QVector3D(0.0f, 1.0f, 0.0f));
#else
- viewMatrix.lookAt(QVector3D(0.0f, 0.0f, d_ptr->m_scaleFactorX + zComp)
- , QVector3D(0.0f, 0.0f, zComp)
- , QVector3D(0.0f, 1.0f, 0.0f));
+ viewMatrix.lookAt(QVector3D(0.0f, 0.0f, d_ptr->m_scaleFactorX + zComp),
+ QVector3D(0.0f, 0.0f, zComp),
+ QVector3D(0.0f, 1.0f, 0.0f));
float zoomwidth;
if (ZoomRow == d_ptr->m_selectionMode) {
zoomwidth = d_ptr->m_zoomSelection->d_ptr->getItem(0)->d_ptr->translation().x()
@@ -337,7 +338,7 @@ void Q3DBars::drawZoomScene()
d_ptr->m_barShader->bind();
// Draw bars
-// bool barSelectionFound = false;
+ // bool barSelectionFound = false;
// Draw the selected row / column
for (int bar = startBar; bar != stopBar; bar += stepBar) {
QDataItem *item = d_ptr->m_zoomSelection->d_ptr->getItem(bar);
@@ -350,9 +351,9 @@ void Q3DBars::drawZoomScene()
barPosX = item->d_ptr->translation().x();
else
barPosX = -(item->d_ptr->translation().z() - zComp); // flip z; frontmost bar to the left
- modelMatrix.translate(barPosX
- , item->d_ptr->translation().y() - 0.5f// TODO: Needs a better system; calculate y position modifier somehow
- , zComp);
+ modelMatrix.translate(barPosX,
+ item->d_ptr->translation().y() - 0.5f,// TODO: Needs a better system; calculate y position modifier somehow
+ zComp);
modelMatrix.scale(QVector3D(d_ptr->m_scaleX, barHeight, d_ptr->m_scaleZ));
MVPMatrix = projectionMatrix * viewMatrix * modelMatrix;
@@ -365,8 +366,7 @@ void Q3DBars::drawZoomScene()
float lightStrength = d_ptr->m_theme->m_lightStrength;
#if 0 // TODO: Implement selection in zoom
if (d_ptr->m_selectionMode > None) {
- Q3DBarsPrivate::SelectionType selectionType = d_ptr->isSelected(row, bar
- , selection);
+ Q3DBarsPrivate::SelectionType selectionType = d_ptr->isSelected(row, bar, selection);
switch (selectionType) {
case Q3DBarsPrivate::Bar:
{
@@ -411,16 +411,16 @@ void Q3DBars::drawZoomScene()
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->lightP(), lightPos);
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->view(), viewMatrix);
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->model(), modelMatrix);
- d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->nModel()
- , modelMatrix.inverted().transposed());
+ d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->nModel(),
+ modelMatrix.inverted().transposed());
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->MVP(), MVPMatrix);
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->color(), barColor);
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->lightS(), lightStrength);
- d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->ambientS()
- , d_ptr->m_theme->m_ambientStrength);
+ d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->ambientS(),
+ d_ptr->m_theme->m_ambientStrength);
// Draw the object
- drawObject(d_ptr->m_barShader, d_ptr->m_barObj);
+ d_ptr->m_drawer->drawObject(d_ptr->m_barShader, d_ptr->m_barObj);
}
#if 0
if (!barSelectionFound) {
@@ -431,17 +431,17 @@ void Q3DBars::drawZoomScene()
d_ptr->m_zoomActivated = false;
}
} else if (d_ptr->m_selectionMode >= ZoomRow
- && Q3DBarsPrivate::MouseOnScene == d_ptr->m_mousePressed) {
+ && Q3DBarsPrivate::MouseOnScene == d_ptr->m_mousePressed) {
d_ptr->m_zoomActivated = true;
- d_ptr->m_sceneViewPort = QRect(0, height() - height() / 5
- , width() / 5, height() / 5);
+ d_ptr->m_sceneViewPort = QRect(0, height() - height() / 5,
+ width() / 5, height() / 5);
}
#endif
// Release bar shader
d_ptr->m_barShader->release();
#ifndef USE_PAINTER_TEXT
- // Draw bar values
+ // Draw labels
d_ptr->m_labelShader->bind();
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
@@ -450,10 +450,23 @@ void Q3DBars::drawZoomScene()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
- // Do the actual drawing
for (int col = 0; col < d_ptr->m_zoomSelection->d_ptr->row().size(); col++) {
QDataItem *item = d_ptr->m_zoomSelection->d_ptr->getItem(col);
- drawLabel(*item, viewMatrix, projectionMatrix, false, -45.0f);
+ // Draw values
+ drawLabel(*item, item->d_ptr->textureId(), viewMatrix, projectionMatrix, false, 0.0f,
+ LabelOver);
+ // Draw labels // TODO: Generate label textures
+ if (ZoomRow == d_ptr->m_selectionMode) {
+ drawLabel(*item, item->d_ptr->textureId(), viewMatrix, projectionMatrix, false, -45.0f,
+ LabelBelow);
+ // drawLabel(*item, d_ptr->m_dataSet->d_ptr->rowLabels().at(col), viewMatrix,
+ // projectionMatrix, false, -45.0f, LabelBelow);
+ } else {
+ drawLabel(*item, item->d_ptr->textureId(), viewMatrix, projectionMatrix, false, -45.0f,
+ LabelBelow);
+ // drawLabel(*item, d_ptr->m_dataSet->d_ptr->columnLabels().at(col), viewMatrix,
+ // projectionMatrix, false, -45.0f, LabelBelow);
+ }
}
glDisable(GL_TEXTURE_2D);
@@ -484,8 +497,8 @@ void Q3DBars::drawScene()
static QVector3D selection = QVector3D(0, 0, 0);
// Specify viewport
- glViewport(d_ptr->m_sceneViewPort.x(), d_ptr->m_sceneViewPort.y()
- , d_ptr->m_sceneViewPort.width(), d_ptr->m_sceneViewPort.height());
+ glViewport(d_ptr->m_sceneViewPort.x(), d_ptr->m_sceneViewPort.y(),
+ d_ptr->m_sceneViewPort.width(), d_ptr->m_sceneViewPort.height());
// Set up projection matrix
QMatrix4x4 projectionMatrix;
@@ -493,10 +506,10 @@ void Q3DBars::drawScene()
/ (float)d_ptr->m_sceneViewPort.height(), 0.1f, 100.0f);
// Calculate view matrix
- QMatrix4x4 viewMatrix = CameraHelper::calculateViewMatrix(d_ptr->m_mousePos
- , d_ptr->m_zoomLevel
- , d_ptr->m_sceneViewPort.width()
- , d_ptr->m_sceneViewPort.height());
+ QMatrix4x4 viewMatrix = CameraHelper::calculateViewMatrix(d_ptr->m_mousePos,
+ d_ptr->m_zoomLevel,
+ d_ptr->m_sceneViewPort.width(),
+ d_ptr->m_sceneViewPort.height());
if (d_ptr->m_sceneViewPort.height() > d_ptr->m_sceneViewPort.width()) {
viewMatrix.scale((float)d_ptr->m_sceneViewPort.width()
/ (float)d_ptr->m_sceneViewPort.height());
@@ -527,15 +540,14 @@ void Q3DBars::drawScene()
}
// calculate background rotation based on view matrix rotation
- if (viewMatrix.row(0).x() >= 0 && viewMatrix.row(0).z() <= 0) {
+ if (viewMatrix.row(0).x() >= 0 && viewMatrix.row(0).z() <= 0)
backgroundRotation = 270.0f;
- } else if (viewMatrix.row(0).x() > 0 && viewMatrix.row(0).z() > 0) {
+ else if (viewMatrix.row(0).x() > 0 && viewMatrix.row(0).z() > 0)
backgroundRotation = 180.0f;
- } else if (viewMatrix.row(0).x() <= 0 && viewMatrix.row(0).z() >= 0) {
+ else if (viewMatrix.row(0).x() <= 0 && viewMatrix.row(0).z() >= 0)
backgroundRotation = 90.0f;
- } else if (viewMatrix.row(0).x() < 0 && viewMatrix.row(0).z() < 0) {
+ else if (viewMatrix.row(0).x() < 0 && viewMatrix.row(0).z() < 0)
backgroundRotation = 0.0f;
- }
// Get light position (rotate light with camera, a bit above it (as set in defaultLightPos))
QVector3D lightPos = CameraHelper::calculateLightPosition(defaultLightPos);
@@ -559,36 +571,39 @@ void Q3DBars::drawScene()
QMatrix4x4 MVPMatrix;
barPos = (bar + 1) * (d_ptr->m_barSpacing.x());
rowPos = (row + 1) * (d_ptr->m_barSpacing.y());
- modelMatrix.translate((d_ptr->m_rowWidth - barPos) / d_ptr->m_scaleFactorX
- , barHeight - 1.0f
- , (d_ptr->m_columnDepth - rowPos) / d_ptr->m_scaleFactorZ + zComp);
+ modelMatrix.translate((d_ptr->m_rowWidth - barPos) / d_ptr->m_scaleFactorX,
+ barHeight - 1.0f,
+ (d_ptr->m_columnDepth - rowPos) / d_ptr->m_scaleFactorZ
+ + zComp);
modelMatrix.scale(QVector3D(d_ptr->m_scaleX, barHeight, d_ptr->m_scaleZ));
MVPMatrix = projectionMatrix * viewMatrix * modelMatrix;
// add +2 to avoid black
- QVector3D barColor = QVector3D((float)(row + 2) / (float)(d_ptr->m_sampleCount.y() + 2)
- , (float)(bar + 2) / (float)(d_ptr->m_sampleCount.x() + 2)
- , 0.0f);
+ QVector3D barColor = QVector3D((float)(row + 2)
+ / (float)(d_ptr->m_sampleCount.y() + 2),
+ (float)(bar + 2)
+ / (float)(d_ptr->m_sampleCount.x() + 2),
+ 0.0f);
- d_ptr->m_selectionShader->setUniformValue(d_ptr->m_selectionShader->MVP()
- , MVPMatrix);
- d_ptr->m_selectionShader->setUniformValue(d_ptr->m_selectionShader->color()
- , barColor);
+ d_ptr->m_selectionShader->setUniformValue(d_ptr->m_selectionShader->MVP(),
+ MVPMatrix);
+ d_ptr->m_selectionShader->setUniformValue(d_ptr->m_selectionShader->color(),
+ barColor);
#ifdef USE_HAX0R_SELECTION
// 1st attribute buffer : vertices
glEnableVertexAttribArray(d_ptr->m_selectionShader->posAtt());
glBindBuffer(GL_ARRAY_BUFFER, d_ptr->m_barObj->vertexBuf());
- glVertexAttribPointer(d_ptr->m_selectionShader->posAtt()
- , 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
+ glVertexAttribPointer(d_ptr->m_selectionShader->posAtt(),
+ 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
// Index buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, d_ptr->m_barObj->elementBuf());
// Draw the triangles
- glDrawElements(GL_TRIANGLES, d_ptr->m_barObj->indexCount()
- , GL_UNSIGNED_SHORT, (void*)0);
+ glDrawElements(GL_TRIANGLES, d_ptr->m_barObj->indexCount(),
+ GL_UNSIGNED_SHORT, (void*)0);
// Free buffers
glBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -602,16 +617,16 @@ void Q3DBars::drawScene()
// 1st attribute buffer : vertices
glEnableVertexAttribArray(d_ptr->m_selectionShader->posAtt());
glBindBuffer(GL_ARRAY_BUFFER, d_ptr->m_barObj->vertexBuf());
- glVertexAttribPointer(d_ptr->m_selectionShader->posAtt()
- , 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
+ glVertexAttribPointer(d_ptr->m_selectionShader->posAtt(),
+ 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
// Index buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, d_ptr->m_barObj->elementBuf());
// Draw the triangles
GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
- glDrawElements(GL_TRIANGLES, d_ptr->m_barObj->indexCount()
- , GL_UNSIGNED_SHORT, DrawBuffers);
+ glDrawElements(GL_TRIANGLES, d_ptr->m_barObj->indexCount(),
+ GL_UNSIGNED_SHORT, DrawBuffers);
glDisableVertexAttribArray(d_ptr->m_selectionShader->posAtt());
@@ -627,9 +642,8 @@ void Q3DBars::drawScene()
glEnable(GL_DITHER);
// Read color under cursor
- if (Q3DBarsPrivate::MouseOnScene == d_ptr->m_mousePressed) {
+ if (Q3DBarsPrivate::MouseOnScene == d_ptr->m_mousePressed)
selection = Utils::getSelection(d_ptr->m_mousePos, height());
- }
// Release selection shader
d_ptr->m_selectionShader->release();
@@ -653,9 +667,9 @@ void Q3DBars::drawScene()
QMatrix4x4 MVPMatrix;
if (zComp != 0)
modelMatrix.translate(0.0f, 0.0f, zComp);
- modelMatrix.scale(QVector3D(d_ptr->m_rowWidth * d_ptr->m_sceneScale
- , 1.0f
- , d_ptr->m_columnDepth * d_ptr->m_sceneScale));
+ modelMatrix.scale(QVector3D(d_ptr->m_rowWidth * d_ptr->m_sceneScale,
+ 1.0f,
+ d_ptr->m_columnDepth * d_ptr->m_sceneScale));
modelMatrix.rotate(backgroundRotation, 0.0f, 1.0f, 0.0f);
MVPMatrix = projectionMatrix * viewMatrix * modelMatrix;
@@ -663,26 +677,26 @@ void Q3DBars::drawScene()
QVector3D backgroundColor = Utils::vectorFromColor(d_ptr->m_theme->m_backgroundColor);
// Set shader bindings
- d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->lightP()
- , lightPos);
- d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->view()
- , viewMatrix);
- d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->model()
- , modelMatrix);
- d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->nModel()
- , modelMatrix.inverted().transposed());
- d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->MVP()
- , MVPMatrix);
- d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->color()
- , backgroundColor);
- d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->lightS()
- , d_ptr->m_theme->m_lightStrength);
- d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->ambientS()
- , d_ptr->m_theme->m_ambientStrength);
+ d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->lightP(),
+ lightPos);
+ d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->view(),
+ viewMatrix);
+ d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->model(),
+ modelMatrix);
+ d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->nModel(),
+ modelMatrix.inverted().transposed());
+ d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->MVP(),
+ MVPMatrix);
+ d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->color(),
+ backgroundColor);
+ d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->lightS(),
+ d_ptr->m_theme->m_lightStrength);
+ d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->ambientS(),
+ d_ptr->m_theme->m_ambientStrength);
// Draw the object
- drawObject(d_ptr->m_backgroundShader, d_ptr->m_backgroundObj);
- //drawObject(d_ptr->m_backgroundShader, d_ptr->m_backgroundObj, true, bgrTexture);
+ d_ptr->m_drawer->drawObject(d_ptr->m_backgroundShader, d_ptr->m_backgroundObj);
+ //d_ptr->m_drawer->drawObject(d_ptr->m_backgroundShader, d_ptr->m_backgroundObj, true, bgrTexture);
}
// Disable textures
@@ -712,11 +726,12 @@ void Q3DBars::drawScene()
continue;
QMatrix4x4 modelMatrix;
QMatrix4x4 MVPMatrix;
+ // TODO: Laske rivi- ja sarakelabelien paikat (sijainnit: min-1 ja max+1) ja pistä johonki talteen?
barPos = (bar + 1) * (d_ptr->m_barSpacing.x());
rowPos = (row + 1) * (d_ptr->m_barSpacing.y());
- modelMatrix.translate((d_ptr->m_rowWidth - barPos) / d_ptr->m_scaleFactorX
- , barHeight - 1.0f
- , (d_ptr->m_columnDepth - rowPos) / d_ptr->m_scaleFactorZ + zComp);
+ modelMatrix.translate((d_ptr->m_rowWidth - barPos) / d_ptr->m_scaleFactorX,
+ barHeight - 1.0f,
+ (d_ptr->m_columnDepth - rowPos) / d_ptr->m_scaleFactorZ + zComp);
modelMatrix.scale(QVector3D(d_ptr->m_scaleX, barHeight, d_ptr->m_scaleZ));
MVPMatrix = projectionMatrix * viewMatrix * modelMatrix;
@@ -731,8 +746,8 @@ void Q3DBars::drawScene()
float lightStrength = d_ptr->m_theme->m_lightStrength;
if (d_ptr->m_selectionMode > None) {
- Q3DBarsPrivate::SelectionType selectionType = d_ptr->isSelected(row, bar
- , selection);
+ Q3DBarsPrivate::SelectionType selectionType = d_ptr->isSelected(row, bar,
+ selection);
switch (selectionType) {
case Q3DBarsPrivate::Bar:
{
@@ -746,8 +761,8 @@ void Q3DBars::drawScene()
if (!d_ptr->m_zoomActivated) {
d_ptr->m_selectedBar = item;
#ifdef USE_PAINTER_TEXT
- QSize mousePositionAsSize = QSize(d_ptr->m_mousePos.x()
- , d_ptr->m_mousePos.y());
+ QSize mousePositionAsSize = QSize(d_ptr->m_mousePos.x(),
+ d_ptr->m_mousePos.y());
d_ptr->m_selectedBar->d_ptr->setLabelSize(mousePositionAsSize);
#else
item->d_ptr->setTranslation(modelMatrix.column(3).toVector3D());
@@ -795,16 +810,16 @@ void Q3DBars::drawScene()
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->lightP(), lightPos);
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->view(), viewMatrix);
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->model(), modelMatrix);
- d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->nModel()
- , modelMatrix.inverted().transposed());
+ d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->nModel(),
+ modelMatrix.inverted().transposed());
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->MVP(), MVPMatrix);
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->color(), barColor);
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->lightS(), lightStrength);
- d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->ambientS()
- , d_ptr->m_theme->m_ambientStrength);
+ d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->ambientS(),
+ d_ptr->m_theme->m_ambientStrength);
// Draw the object
- drawObject(d_ptr->m_barShader, d_ptr->m_barObj);
+ d_ptr->m_drawer->drawObject(d_ptr->m_barShader, d_ptr->m_barObj);
}
}
if (!barSelectionFound) {
@@ -815,16 +830,16 @@ void Q3DBars::drawScene()
d_ptr->m_zoomActivated = false;
}
} else if (d_ptr->m_selectionMode >= ZoomRow
- && Q3DBarsPrivate::MouseOnScene == d_ptr->m_mousePressed) {
+ && Q3DBarsPrivate::MouseOnScene == d_ptr->m_mousePressed) {
// Activate zoom mode
d_ptr->m_zoomActivated = true;
- d_ptr->m_sceneViewPort = QRect(0, height() - height() / 5
- , width() / 5, height() / 5);
+ d_ptr->m_sceneViewPort = QRect(0, height() - height() / 5,
+ width() / 5, height() / 5);
// Create label textures
for (int col = 0; col < d_ptr->m_zoomSelection->d_ptr->row().size(); col++) {
QDataItem *item = d_ptr->m_zoomSelection->d_ptr->getItem(col);
- generateLabelTexture(item);
+ d_ptr->m_drawer->generateLabelTexture(item);
}
} else {
// Print value of selected bar
@@ -838,11 +853,12 @@ void Q3DBars::drawScene()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
if (prevItem != d_ptr->m_selectedBar) {
- generateLabelTexture(d_ptr->m_selectedBar);
+ d_ptr->m_drawer->generateLabelTexture(d_ptr->m_selectedBar);
prevItem = d_ptr->m_selectedBar;
}
- drawLabel(*d_ptr->m_selectedBar, viewMatrix, projectionMatrix, true);
+ drawLabel(*d_ptr->m_selectedBar, d_ptr->m_selectedBar->d_ptr->textureId(), viewMatrix,
+ projectionMatrix, true);
glDisable(GL_TEXTURE_2D);
if (d_ptr->m_labelTransparency > TransparencyNone)
@@ -858,91 +874,46 @@ void Q3DBars::drawScene()
d_ptr->m_barShader->release();
}
-// TODO: Move to a separate class, so that it can be used by other vis types as well
-void Q3DBars::drawObject(ShaderHelper *shader, ObjectHelper *object, bool textured
- , GLuint textureId)
-{
- if (textured) {
- // Activate texture
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, textureId);
- shader->setUniformValue(shader->texture(), 0);
- }
-
- // 1st attribute buffer : vertices
- glEnableVertexAttribArray(shader->posAtt());
- glBindBuffer(GL_ARRAY_BUFFER, object->vertexBuf());
- glVertexAttribPointer(shader->posAtt(), 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
-
- // 2nd attribute buffer : normals
- glEnableVertexAttribArray(shader->normalAtt());
- glBindBuffer(GL_ARRAY_BUFFER, object->normalBuf());
- glVertexAttribPointer(shader->normalAtt(), 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
-
- if (textured) {
- // 3rd attribute buffer : UVs
- glEnableVertexAttribArray(shader->uvAtt());
- glBindBuffer(GL_ARRAY_BUFFER, object->uvBuf());
- glVertexAttribPointer(shader->uvAtt(), 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
- }
-
- // Index buffer
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object->elementBuf());
-
- // Draw the triangles
- glDrawElements(GL_TRIANGLES, object->indexCount(), GL_UNSIGNED_SHORT, (void*)0);
-
- // Free buffers
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
-
- if (textured) {
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisableVertexAttribArray(shader->uvAtt());
- }
- glDisableVertexAttribArray(shader->normalAtt());
- glDisableVertexAttribArray(shader->posAtt());
-}
-
-// TODO: Move to a separate class, so that it can be used by other vis types as well
-void Q3DBars::generateLabelTexture(QDataItem *item)
-{
- // Delete previous texture, if there is one
- GLuint labelTexture = item->d_ptr->textureId();
- if (labelTexture) {
- // We have to do this, as we can't know if data is static or not;
- // texture doesn't change with static data
- // (basically we could create textures for all bars when data is added, but we
- // may not need them -> better to do it here dynamically)
- glDeleteTextures(1, &labelTexture);
- item->d_ptr->setTextureId(0);
- }
-
- // Create labels
- // Print label into a QImage using QPainter
- QImage label = Utils::printTextToImage(d_ptr->m_font
- , item->d_ptr->valueStr()
- , d_ptr->m_theme->m_textBackgroundColor
- , d_ptr->m_theme->m_textColor
- , d_ptr->m_labelTransparency);
-
- // Set label size
- item->d_ptr->setLabelSize(label.size());
- // Insert text texture into label
- item->d_ptr->setTextureId(d_ptr->m_textureHelper->create2DTexture(label, true, true));
-}
-
-// TODO: Move to a separate class, so that it can be used by other vis types as well (will need a lot more parameters..)
-void Q3DBars::drawLabel(const QDataItem &item, const QMatrix4x4 &viewmatrix
- , const QMatrix4x4 &projectionmatrix, bool useDepth, qreal rotation) // TODO: Add enum? for label position (below, middle, top etc.)
+void Q3DBars::drawLabel(const QDataItem &item, GLuint textureId, const QMatrix4x4 &viewmatrix,
+ const QMatrix4x4 &projectionmatrix, bool useDepth, qreal rotation,
+ Q3DBars::LabelPosition position)
{
// Draw label
QMatrix4x4 modelMatrix;
QMatrix4x4 MVPMatrix;
qreal yPosition = -1.5f;
- if (useDepth) // replace with enum? or adjustable height
+ switch (position) {
+ case Q3DBars::LabelBelow:
+ {
+ yPosition = -1.5f;
+ break;
+ }
+ case Q3DBars::LabelLow:
+ {
+ yPosition = 0.0f;
+ break;
+ }
+ case Q3DBars::LabelMid:
+ {
+ yPosition = item.d_ptr->translation().y();
+ break;
+ }
+ case Q3DBars::LabelHigh:
+ {
+ yPosition = item.d_ptr->translation().y() + (item.d_ptr->value()
+ / d_ptr->m_heightNormalizer) / 2.0f;
+ break;
+ }
+ case Q3DBars::LabelOver:
+ {
yPosition = item.d_ptr->translation().y()
- + (item.d_ptr->value() / d_ptr->m_heightNormalizer);
+ + (item.d_ptr->value() / d_ptr->m_heightNormalizer) + 0.1f;
+ if (!useDepth)
+ yPosition -= 0.5f;
+ break;
+ }
+ }
+
qreal zPosition = zComp;
qreal xPosition = item.d_ptr->translation().x();
if (useDepth)
@@ -973,11 +944,10 @@ void Q3DBars::drawLabel(const QDataItem &item, const QMatrix4x4 &viewmatrix
MVPMatrix = projectionmatrix * viewmatrix * modelMatrix;
// Set shader bindings
- d_ptr->m_labelShader->setUniformValue(d_ptr->m_labelShader->MVP()
- , MVPMatrix);
+ d_ptr->m_labelShader->setUniformValue(d_ptr->m_labelShader->MVP(), MVPMatrix);
// Draw the object
- drawObject(d_ptr->m_labelShader, d_ptr->m_labelObj, true, item.d_ptr->textureId());
+ d_ptr->m_drawer->drawObject(d_ptr->m_labelShader, d_ptr->m_labelObj, true, textureId);
}
void Q3DBars::mousePressEvent(QMouseEvent *event)
@@ -1011,22 +981,22 @@ void Q3DBars::mousePressEvent(QMouseEvent *event)
d_ptr->m_mousePos = event->pos();
// TODO: testing shaders
-// if (++shaderNo > 3)
-// shaderNo = 1;
-// switch (shaderNo) {
-// case 1:
-// d_ptr->initShaders(QStringLiteral(":/shaders/vertex")
-// , QStringLiteral(":/shaders/fragment"));
-// break;
-// case 2:
-// d_ptr->initShaders(QStringLiteral(":/shaders/vertex")
-// , QStringLiteral(":/shaders/fragmentColorOnY"));
-// break;
-// case 3:
-// d_ptr->initShaders(QStringLiteral(":/shaders/vertex")
-// , QStringLiteral(":/shaders/fragmentAmbient"));
-// break;
-// }
+ // if (++shaderNo > 3)
+ // shaderNo = 1;
+ // switch (shaderNo) {
+ // case 1:
+ // d_ptr->initShaders(QStringLiteral(":/shaders/vertex")
+ // , QStringLiteral(":/shaders/fragment"));
+ // break;
+ // case 2:
+ // d_ptr->initShaders(QStringLiteral(":/shaders/vertex")
+ // , QStringLiteral(":/shaders/fragmentColorOnY"));
+ // break;
+ // case 3:
+ // d_ptr->initShaders(QStringLiteral(":/shaders/vertex")
+ // , QStringLiteral(":/shaders/fragmentAmbient"));
+ // break;
+ // }
}
CameraHelper::updateMousePos(d_ptr->m_mousePos);
}
@@ -1050,8 +1020,8 @@ void Q3DBars::mouseMoveEvent(QMouseEvent *event)
}
#if 0
// TODO: Testi - laske kursorin sijainti scenessä
- QPointF mouse3D((2.0f * event->pos().x() - width()) / height()
- , 1.0f - (2.0f * event->pos().y()) / height());
+ QPointF mouse3D((2.0f * event->pos().x() - width()) / height(),
+ 1.0f - (2.0f * event->pos().y()) / height());
//qDebug() << "mouse position in scene" << mouse3D;
// TODO: Testi laske focal point
@@ -1067,18 +1037,16 @@ void Q3DBars::mouseMoveEvent(QMouseEvent *event)
void Q3DBars::wheelEvent(QWheelEvent *event)
{
- if (d_ptr->m_zoomLevel > 100) {
+ if (d_ptr->m_zoomLevel > 100)
d_ptr->m_zoomLevel += event->angleDelta().y() / 12;
- } else if (d_ptr->m_zoomLevel > 50) {
+ else if (d_ptr->m_zoomLevel > 50)
d_ptr->m_zoomLevel += event->angleDelta().y() / 60;
- } else {
+ else
d_ptr->m_zoomLevel += event->angleDelta().y() / 120;
- }
- if (d_ptr->m_zoomLevel > 500) {
+ if (d_ptr->m_zoomLevel > 500)
d_ptr->m_zoomLevel = 500;
- } else if (d_ptr->m_zoomLevel < 10) {
+ else if (d_ptr->m_zoomLevel < 10)
d_ptr->m_zoomLevel = 10;
- }
}
void Q3DBars::resizeEvent(QResizeEvent *event)
@@ -1139,11 +1107,12 @@ void Q3DBars::setMeshFileName(const QString &objFileName)
d_ptr->m_objFile = objFileName;
}
-void Q3DBars::setupSampleSpace(QPoint sampleCount, const QString &labelRow
- , const QString &labelColumn, const QString &labelHeight)
+void Q3DBars::setupSampleSpace(QPoint sampleCount, const QString &labelRow,
+ const QString &labelColumn, const QString &labelHeight)
{
d_ptr->m_sampleCount = sampleCount;
d_ptr->m_dataSet->setLabels(labelRow, labelColumn, labelHeight);
+ // TODO: Generate axis textures and replace qstrings with texture ids in qdataset
// TODO: Invent "idiotproof" max scene size formula..
// This seems to work ok if spacing is not negative
d_ptr->m_maxSceneSize = 2 * qSqrt(sampleCount.x() * sampleCount.y());
@@ -1165,21 +1134,22 @@ void Q3DBars::setCameraPosition(float horizontal, float vertical, int distance)
d_ptr->m_horizontalRotation = qBound(-180.0f, horizontal, 180.0f);
d_ptr->m_verticalRotation = qBound(0.0f, vertical, 90.0f);
d_ptr->m_zoomLevel = qBound(10, distance, 500);
- CameraHelper::setCameraRotation(QPointF(d_ptr->m_horizontalRotation
- , d_ptr->m_verticalRotation));
+ CameraHelper::setCameraRotation(QPointF(d_ptr->m_horizontalRotation,
+ d_ptr->m_verticalRotation));
qDebug() << "camera rotation set to" << d_ptr->m_horizontalRotation << d_ptr->m_verticalRotation;
}
void Q3DBars::setTheme(ColorTheme theme)
{
d_ptr->m_theme->useTheme(theme);
+ d_ptr->m_drawer->setTheme(*d_ptr->m_theme);
// Re-initialize shaders
if (!d_ptr->m_theme->m_uniformColor) {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertex")
- , QStringLiteral(":/shaders/fragmentColorOnY"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragmentColorOnY"));
} else {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertex")
- , QStringLiteral(":/shaders/fragment"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragment"));
}
}
@@ -1192,11 +1162,11 @@ void Q3DBars::setBarColor(QColor baseColor, QColor heightColor, QColor depthColo
if (d_ptr->m_theme->m_uniformColor != uniform) {
// Re-initialize shaders
if (!d_ptr->m_theme->m_uniformColor) {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertex")
- , QStringLiteral(":/shaders/fragmentColorOnY"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragmentColorOnY"));
} else {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertex")
- , QStringLiteral(":/shaders/fragment"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragment"));
}
}
d_ptr->m_theme->m_uniformColor = uniform;
@@ -1223,15 +1193,17 @@ void Q3DBars::setFont(const QFont &font)
{
d_ptr->m_font = font;
d_ptr->m_fontSize = font.pointSizeF();
+ d_ptr->m_drawer->setFont(font);
}
void Q3DBars::setLabelTransparency(LabelTransparency transparency)
{
d_ptr->m_labelTransparency = transparency;
+ d_ptr->m_drawer->setTransparency(transparency);
}
-void Q3DBars::addDataRow(const QVector<float> &dataRow, const QString &labelRow
- , const QVector<QString> &labelsColumn)
+void Q3DBars::addDataRow(const QVector<float> &dataRow, const QString &labelRow,
+ const QVector<QString> &labelsColumn)
{
// Convert to QDataRow and add to QDataSet
QDataRow *row = new QDataRow(labelRow);
@@ -1240,13 +1212,13 @@ void Q3DBars::addDataRow(const QVector<float> &dataRow, const QString &labelRow
row->d_ptr->verifySize(d_ptr->m_sampleCount.x());
d_ptr->m_dataSet->addRow(row);
d_ptr->m_heightNormalizer = d_ptr->m_dataSet->d_ptr->highestValue();
- d_ptr->m_dataSet->setLabels(d_ptr->m_axisLabelX, d_ptr->m_axisLabelZ, d_ptr->m_axisLabelY
- , QVector<QString>(), labelsColumn);
+ d_ptr->m_dataSet->setLabels(d_ptr->m_axisLabelX, d_ptr->m_axisLabelZ, d_ptr->m_axisLabelY,
+ QVector<QString>(), labelsColumn);
d_ptr->m_dataSet->d_ptr->verifySize(d_ptr->m_sampleCount.y());
}
-void Q3DBars::addDataRow(const QVector<QDataItem*> &dataRow, const QString &labelRow
- , const QVector<QString> &labelsColumn)
+void Q3DBars::addDataRow(const QVector<QDataItem*> &dataRow, const QString &labelRow,
+ const QVector<QString> &labelsColumn)
{
// Convert to QDataRow and add to QDataSet
QDataRow *row = new QDataRow(labelRow);
@@ -1255,8 +1227,8 @@ void Q3DBars::addDataRow(const QVector<QDataItem*> &dataRow, const QString &labe
row->d_ptr->verifySize(d_ptr->m_sampleCount.x());
d_ptr->m_dataSet->addRow(row);
d_ptr->m_heightNormalizer = d_ptr->m_dataSet->d_ptr->highestValue();
- d_ptr->m_dataSet->setLabels(d_ptr->m_axisLabelX, d_ptr->m_axisLabelZ, d_ptr->m_axisLabelY
- , QVector<QString>(), labelsColumn);
+ d_ptr->m_dataSet->setLabels(d_ptr->m_axisLabelX, d_ptr->m_axisLabelZ, d_ptr->m_axisLabelY,
+ QVector<QString>(), labelsColumn);
d_ptr->m_dataSet->d_ptr->verifySize(d_ptr->m_sampleCount.y());
}
@@ -1273,8 +1245,8 @@ void Q3DBars::addDataRow(QDataRow *dataRow)
d_ptr->m_dataSet->d_ptr->verifySize(d_ptr->m_sampleCount.y());
}
-void Q3DBars::addDataSet(const QVector< QVector<float> > &data, const QVector<QString> &labelsRow
- , const QVector<QString> &labelsColumn)
+void Q3DBars::addDataSet(const QVector< QVector<float> > &data, const QVector<QString> &labelsRow,
+ const QVector<QString> &labelsColumn)
{
delete d_ptr->m_dataSet;
d_ptr->m_dataSet = new QDataSet();
@@ -1294,12 +1266,13 @@ void Q3DBars::addDataSet(const QVector< QVector<float> > &data, const QVector<QS
d_ptr->m_heightNormalizer = d_ptr->m_dataSet->d_ptr->highestValue();
// Empty QStrings won't override already set axis labels
d_ptr->m_dataSet->setLabels(QString(), QString(), QString(), labelsRow, labelsColumn);
+ // TODO: generate label textures and replace qstring vectors with texture id (GLuint) vectors
d_ptr->m_dataSet->d_ptr->verifySize(d_ptr->m_sampleCount.y());
}
-void Q3DBars::addDataSet(const QVector< QVector<QDataItem*> > &data
- , const QVector<QString> &labelsRow
- , const QVector<QString> &labelsColumn)
+void Q3DBars::addDataSet(const QVector< QVector<QDataItem*> > &data,
+ const QVector<QString> &labelsRow,
+ const QVector<QString> &labelsColumn)
{
delete d_ptr->m_dataSet;
d_ptr->m_dataSet = new QDataSet();
@@ -1319,6 +1292,7 @@ void Q3DBars::addDataSet(const QVector< QVector<QDataItem*> > &data
d_ptr->m_heightNormalizer = d_ptr->m_dataSet->d_ptr->highestValue();
// Empty QStrings won't override already set axis labels
d_ptr->m_dataSet->setLabels(QString(), QString(), QString(), labelsRow, labelsColumn);
+ // TODO: generate label textures and replace qstring vectors with texture id (GLuint) vectors
d_ptr->m_dataSet->d_ptr->verifySize(d_ptr->m_sampleCount.y());
}
@@ -1331,53 +1305,55 @@ void Q3DBars::addDataSet(QDataSet* dataSet)
d_ptr->m_dataSet = dataSet;
// Find highest value
d_ptr->m_heightNormalizer = d_ptr->m_dataSet->d_ptr->highestValue();
+ // TODO: generate label textures and replace qstring vectors with texture id (GLuint) vectors
}
Q3DBarsPrivate::Q3DBarsPrivate(Q3DBars *q)
- : q_ptr(q)
- , m_paintDevice(0)
- , m_barShader(0)
- , m_selectionShader(0)
- , m_backgroundShader(0)
- , m_labelShader(0)
- , m_barObj(0)
- , m_backgroundObj(0)
- , m_labelObj(0)
- , m_sampleCount(QPoint(0, 0))
- , m_objFile(QStringLiteral(":/defaultMeshes/bar"))
- , m_mousePressed(MouseNone)
- , m_mousePos(QPoint(0, 0))
- , m_zoomLevel(100)
- , m_horizontalRotation(-45.0f)
- , m_verticalRotation(15.0f)
- , m_barThickness(QPointF(0.75f, 0.75f))
- , m_barSpacing(m_barThickness * 3.0f)
- , m_heightNormalizer(0.0f)
- , m_rowWidth(0)
- , m_columnDepth(0)
- , m_maxDimension(0)
- , m_scaleX(0)
- , m_scaleZ(0)
- , m_scaleFactorX(0)
- , m_scaleFactorZ(0)
- , m_sceneScale(0)
- , m_maxSceneSize(40.0)
- , m_theme(new Theme())
- , m_isInitialized(false)
- , m_selectionMode(Q3DBars::Bar)
- , m_selectedBar(0)
- , m_zoomSelection(0)
- , m_dataSet(new QDataSet())
- , m_axisLabelX(QStringLiteral("X"))
- , m_axisLabelZ(QStringLiteral("Z"))
- , m_axisLabelY(QStringLiteral("Y"))
- , m_sceneViewPort(0, 0, q->width(), q->height())
- , m_zoomViewPort(0, 0, q->width(), q->height())
- , m_zoomActivated(false)
- , m_textureHelper(new TextureHelper())
- , m_labelTransparency(Q3DBars::TransparencyNone)
- , m_fontSize(10.0f)
- , m_font(QFont(QStringLiteral("Arial")))
+ : q_ptr(q),
+ m_paintDevice(0),
+ m_barShader(0),
+ m_selectionShader(0),
+ m_backgroundShader(0),
+ m_labelShader(0),
+ m_barObj(0),
+ m_backgroundObj(0),
+ m_labelObj(0),
+ m_sampleCount(QPoint(0, 0)),
+ m_objFile(QStringLiteral(":/defaultMeshes/bar")),
+ m_mousePressed(MouseNone),
+ m_mousePos(QPoint(0, 0)),
+ m_zoomLevel(100),
+ m_horizontalRotation(-45.0f),
+ m_verticalRotation(15.0f),
+ m_barThickness(QPointF(0.75f, 0.75f)),
+ m_barSpacing(m_barThickness * 3.0f),
+ m_heightNormalizer(0.0f),
+ m_rowWidth(0),
+ m_columnDepth(0),
+ m_maxDimension(0),
+ m_scaleX(0),
+ m_scaleZ(0),
+ m_scaleFactorX(0),
+ m_scaleFactorZ(0),
+ m_sceneScale(0),
+ m_maxSceneSize(40.0),
+ m_theme(new Theme()),
+ m_isInitialized(false),
+ m_selectionMode(Q3DBars::Bar),
+ m_selectedBar(0),
+ m_zoomSelection(0),
+ m_dataSet(new QDataSet()),
+ m_axisLabelX(QStringLiteral("X")),
+ m_axisLabelZ(QStringLiteral("Z")),
+ m_axisLabelY(QStringLiteral("Y")),
+ m_sceneViewPort(0, 0, q->width(), q->height()),
+ m_zoomViewPort(0, 0, q->width(), q->height()),
+ m_zoomActivated(false),
+ m_textureHelper(new TextureHelper()),
+ m_labelTransparency(Q3DBars::TransparencyNone),
+ m_fontSize(10.0f),
+ m_font(QFont(QStringLiteral("Arial"))),
+ m_drawer(new Drawer(*m_theme, m_font, m_labelTransparency))
{
}
@@ -1395,6 +1371,7 @@ Q3DBarsPrivate::~Q3DBarsPrivate()
delete m_barObj;
delete m_backgroundObj;
delete m_textureHelper;
+ delete m_drawer;
#ifndef USE_HAX0R_SELECTION
q_ptr->glDeleteFramebuffers(1, &m_framebufferSelection);
@@ -1439,8 +1416,8 @@ void Q3DBarsPrivate::initSelectionShader()
{
if (m_selectionShader)
delete m_selectionShader;
- m_selectionShader = new ShaderHelper(q_ptr, QStringLiteral(":/shaders/vertexSelection")
- , QStringLiteral(":/shaders/fragmentSelection"));
+ m_selectionShader = new ShaderHelper(q_ptr, QStringLiteral(":/shaders/vertexSelection"),
+ QStringLiteral(":/shaders/fragmentSelection"));
m_selectionShader->initialize();
}
@@ -1481,8 +1458,8 @@ void Q3DBarsPrivate::initSelectionBuffer()
#endif
}
-void Q3DBarsPrivate::initBackgroundShaders(const QString &vertexShader
- , const QString &fragmentShader)
+void Q3DBarsPrivate::initBackgroundShaders(const QString &vertexShader,
+ const QString &fragmentShader)
{
if (m_backgroundShader)
delete m_backgroundShader;
@@ -1490,8 +1467,7 @@ void Q3DBarsPrivate::initBackgroundShaders(const QString &vertexShader
m_backgroundShader->initialize();
}
-void Q3DBarsPrivate::initLabelShaders(const QString &vertexShader
- , const QString &fragmentShader)
+void Q3DBarsPrivate::initLabelShaders(const QString &vertexShader, const QString &fragmentShader)
{
if (m_labelShader)
delete m_labelShader;
@@ -1524,10 +1500,10 @@ Q3DBarsPrivate::SelectionType Q3DBarsPrivate::isSelected(int row, int bar, const
if (selection == Utils::vectorFromColor(m_theme->m_windowColor))
return isSelectedType; // skip window
QVector3D current = QVector3D((GLubyte)(((float)(row + 2) / (float)(m_sampleCount.y() + 2))
- * 255 + 0.49) // add 0.49 to fix rounding
- , (GLubyte)(((float)(bar + 2) / (float)(m_sampleCount.x() + 2))
- * 255 + 0.49) // add 0.49 to fix rounding
- , 0);
+ * 255.0),
+ (GLubyte)(((float)(bar + 2) / (float)(m_sampleCount.x() + 2))
+ * 255.0),
+ 0);
if (current == selection)
isSelectedType = Bar;
else if (current.y() == selection.y() && (m_selectionMode == Q3DBars::BarAndColumn
diff --git a/src/datavis3d/engine/q3dbars.h b/src/datavis3d/engine/q3dbars.h
index a7b5eeb4..0251a306 100644
--- a/src/datavis3d/engine/q3dbars.h
+++ b/src/datavis3d/engine/q3dbars.h
@@ -53,8 +53,6 @@ class Q3DBarsPrivate;
class QDataItem;
class QDataRow;
class QDataSet;
-class ShaderHelper;
-class ObjectHelper;
class QTCOMMERCIALDATAVIS3D_EXPORT Q3DBars : public Q3DWindow
{
@@ -116,6 +114,14 @@ public:
ZoomColumn
};
+ enum LabelPosition {
+ LabelBelow = 0,
+ LabelLow,
+ LabelMid,
+ LabelHigh,
+ LabelOver
+ };
+
public:
explicit Q3DBars();
~Q3DBars();
@@ -127,37 +133,37 @@ public:
// Add a row of data. Each new row is added to the front of the sample space, moving previous
// rows back (if sample space is more than one row deep)
// TODO: Replace QVector<..> with a data row class (QDataRow)? Move labels to class.
- void addDataRow(const QVector<float> &dataRow
- , const QString &labelRow = QString()
- , const QVector<QString> &labelsColumn = QVector<QString>());
+ void addDataRow(const QVector<float> &dataRow,
+ const QString &labelRow = QString(),
+ const QVector<QString> &labelsColumn = QVector<QString>());
// TODO: Replace QVector<..> with a data row class (QDataRow)? Move labels to class.
// ownership of dataItems is transferred
- void addDataRow(const QVector<QDataItem*> &dataRow
- , const QString &labelRow = QString()
- , const QVector<QString> &labelsColumn = QVector<QString>());
+ void addDataRow(const QVector<QDataItem*> &dataRow,
+ const QString &labelRow = QString(),
+ const QVector<QString> &labelsColumn = QVector<QString>());
// ownership of dataRow is transferred
void addDataRow(QDataRow *dataRow);
// Add complete data set at a time, as a vector of data rows
// TODO: Replace QVector<QVector<..>> with a data set class (QDataSet)? Move labels to class.
- void addDataSet(const QVector< QVector<float> > &data
- , const QVector<QString> &labelsRow = QVector<QString>()
- , const QVector<QString> &labelsColumn = QVector<QString>());
+ void addDataSet(const QVector< QVector<float> > &data,
+ const QVector<QString> &labelsRow = QVector<QString>(),
+ const QVector<QString> &labelsColumn = QVector<QString>());
// TODO: Replace QVector<QVector<..>> with a data set class (QDataSet)? Move labels to class.
// ownership of dataItems is transferred
- void addDataSet(const QVector< QVector<QDataItem*> > &data
- , const QVector<QString> &labelsRow = QVector<QString>()
- , const QVector<QString> &labelsColumn = QVector<QString>());
+ void addDataSet(const QVector< QVector<QDataItem*> > &data,
+ const QVector<QString> &labelsRow = QVector<QString>(),
+ const QVector<QString> &labelsColumn = QVector<QString>());
// ownership of dataSet is transferred
void addDataSet(QDataSet* dataSet);
// bar thickness, spacing between bars, and is spacing relative to thickness or absolute
// y -component sets the thickness/spacing of z -direction
// With relative 0.0f means side-to-side, 1.0f = one thickness in between
- void setBarSpecs(QPointF thickness = QPointF(1.0f, 1.0f)
- , QPointF spacing = QPointF(1.0f, 1.0f)
- , bool relative = true);
+ void setBarSpecs(QPointF thickness = QPointF(1.0f, 1.0f),
+ QPointF spacing = QPointF(1.0f, 1.0f),
+ bool relative = true);
// bar type; bars (=cubes), pyramids, cones, cylinders, etc.
void setBarType(BarStyle style, bool smooth = false);
@@ -166,8 +172,9 @@ public:
void setMeshFileName(const QString &objFileName);
// how many samples per row and column, and names for axes
- void setupSampleSpace(QPoint sampleCount, const QString &labelRow = QString()
- , const QString &labelColumn = QString(), const QString &labelHeight = QString());
+ void setupSampleSpace(QPoint sampleCount, const QString &labelRow = QString(),
+ const QString &labelColumn = QString(),
+ const QString &labelHeight = QString());
// Select preset camera placement
void setCameraPreset(CameraPreset preset);
@@ -208,12 +215,9 @@ protected:
private:
void drawZoomScene();
void drawScene();
- void drawLabel(const QDataItem &item, const QMatrix4x4 &viewmatrix
- , const QMatrix4x4 &projectionmatrix, bool useDepth = false
- , qreal rotation = 0.0f);
- void drawObject(ShaderHelper *shader, ObjectHelper *object, bool textured = false
- , GLuint textureId = 0);
- void generateLabelTexture(QDataItem *item);
+ void drawLabel(const QDataItem &item, GLuint textureId, const QMatrix4x4 &viewmatrix,
+ const QMatrix4x4 &projectionmatrix, bool useDepth = false,
+ qreal rotation = 0.0f, Q3DBars::LabelPosition position = Q3DBars::LabelOver);
QScopedPointer<Q3DBarsPrivate> d_ptr;
Q_DISABLE_COPY(Q3DBars)
};
diff --git a/src/datavis3d/engine/q3dbars_p.h b/src/datavis3d/engine/q3dbars_p.h
index 4e70eb2b..675c553f 100644
--- a/src/datavis3d/engine/q3dbars_p.h
+++ b/src/datavis3d/engine/q3dbars_p.h
@@ -70,6 +70,7 @@ class ShaderHelper;
class ObjectHelper;
class TextureHelper;
class Theme;
+class Drawer;
class Q3DBarsPrivate
{
@@ -151,6 +152,7 @@ public:
Q3DBars::LabelTransparency m_labelTransparency;
float m_fontSize;
QFont m_font;
+ Drawer *m_drawer;
};
QTCOMMERCIALDATAVIS3D_END_NAMESPACE
diff --git a/src/datavis3d/engine/q3dwindow.cpp b/src/datavis3d/engine/q3dwindow.cpp
index 56a457b3..bb158226 100644
--- a/src/datavis3d/engine/q3dwindow.cpp
+++ b/src/datavis3d/engine/q3dwindow.cpp
@@ -53,8 +53,8 @@
QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
Q3DWindow::Q3DWindow(QWindow *parent)
- : QWindow(parent)
- , d_ptr(new Q3DWindowPrivate(this))
+ : QWindow(parent),
+ d_ptr(new Q3DWindowPrivate(this))
{
setSurfaceType(QWindow::OpenGLSurface);
QSurfaceFormat surfaceFormat;
@@ -177,11 +177,11 @@ QOpenGLPaintDevice *Q3DWindow::getDevice()
}
Q3DWindowPrivate::Q3DWindowPrivate(Q3DWindow *q)
- : q_ptr(q)
- , m_updatePending(false)
- , m_animating(false)
- , m_context(new QOpenGLContext(q))
- , m_device(0)
+ : q_ptr(q),
+ m_updatePending(false),
+ m_animating(false),
+ m_context(new QOpenGLContext(q)),
+ m_device(0)
{
}
diff --git a/src/datavis3d/engine/qdataitem.cpp b/src/datavis3d/engine/qdataitem.cpp
index 28a96cc0..f658b0ba 100644
--- a/src/datavis3d/engine/qdataitem.cpp
+++ b/src/datavis3d/engine/qdataitem.cpp
@@ -70,13 +70,13 @@ void QDataItem::setValue(float value)
}
QDataItemPrivate::QDataItemPrivate(QDataItem *q, float value, const QString &label)
- : q_ptr(q)
- , m_value(value)
- , m_label(label)
- , m_prependLabel(false)
- , m_size(QSize(0, 0))
- , m_translation(QVector3D(0, 0, 0))
- , m_textureId(0)
+ : q_ptr(q),
+ m_value(value),
+ m_label(label),
+ m_prependLabel(false),
+ m_size(QSize(0, 0)),
+ m_translation(QVector3D(0, 0, 0)),
+ m_textureId(0)
{
}
diff --git a/src/datavis3d/engine/qdataitem.h b/src/datavis3d/engine/qdataitem.h
index 1b9ec9e7..36d325ad 100644
--- a/src/datavis3d/engine/qdataitem.h
+++ b/src/datavis3d/engine/qdataitem.h
@@ -64,6 +64,7 @@ private:
friend class Q3DBars;
friend class Q3DBarsPrivate;
friend class QDataRowPrivate;
+ friend class Drawer;
};
QTCOMMERCIALDATAVIS3D_END_NAMESPACE
diff --git a/src/datavis3d/engine/qdataitem_p.h b/src/datavis3d/engine/qdataitem_p.h
index 55bb623e..77282e86 100644
--- a/src/datavis3d/engine/qdataitem_p.h
+++ b/src/datavis3d/engine/qdataitem_p.h
@@ -64,8 +64,8 @@ QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
class QDataItemPrivate
{
public:
- explicit QDataItemPrivate(QDataItem *q, float value = 0.0f
- , const QString &label = QString());
+ explicit QDataItemPrivate(QDataItem *q, float value = 0.0f,
+ const QString &label = QString());
~QDataItemPrivate();
void setLabelSize(const QSize &size);
diff --git a/src/datavis3d/engine/qdatarow.cpp b/src/datavis3d/engine/qdatarow.cpp
index 937c7b0b..2146aabe 100644
--- a/src/datavis3d/engine/qdatarow.cpp
+++ b/src/datavis3d/engine/qdatarow.cpp
@@ -70,8 +70,8 @@ void QDataRow::addItem(QDataItem *item)
}
QDataRowPrivate::QDataRowPrivate(QDataRow *q, const QString &label)
- : q_ptr(q)
- , m_label(label)
+ : q_ptr(q),
+ m_label(label)
{
}
diff --git a/src/datavis3d/engine/qdataset.cpp b/src/datavis3d/engine/qdataset.cpp
index ddfd907c..08e129ff 100644
--- a/src/datavis3d/engine/qdataset.cpp
+++ b/src/datavis3d/engine/qdataset.cpp
@@ -60,11 +60,11 @@ QDataSet::~QDataSet()
//qDebug("~QDataSet");
}
-void QDataSet::setLabels(const QString &xAxis
- , const QString &zAxis
- , const QString &yAxis
- , const QVector<QString> &labelsRow
- , const QVector<QString> &labelsColumn)
+void QDataSet::setLabels(const QString &xAxis,
+ const QString &zAxis,
+ const QString &yAxis,
+ const QVector<QString> &labelsRow,
+ const QVector<QString> &labelsColumn)
{
QString empty;
// skip empty labels, keep the previous ones
@@ -84,13 +84,13 @@ void QDataSet::addRow(QDataRow *row)
}
QDataSetPrivate::QDataSetPrivate(QDataSet *q)
- : q_ptr(q)
- , m_set(QVector<QDataRow*>())
- , m_xAxis(QString())
- , m_zAxis(QString())
- , m_yAxis(QString())
- , m_labelsRow(QVector<QString>())
- , m_labelsColumn(QVector<QString>())
+ : q_ptr(q),
+ m_set(QVector<QDataRow*>()),
+ m_xAxis(QString()),
+ m_zAxis(QString()),
+ m_yAxis(QString()),
+ m_labelsRow(QVector<QString>()),
+ m_labelsColumn(QVector<QString>())
{
}
diff --git a/src/datavis3d/engine/qdataset.h b/src/datavis3d/engine/qdataset.h
index 589cb9cd..57d06e2b 100644
--- a/src/datavis3d/engine/qdataset.h
+++ b/src/datavis3d/engine/qdataset.h
@@ -60,11 +60,11 @@ public:
explicit QDataSet();
~QDataSet();
- void setLabels(const QString &xAxis = QString()
- , const QString &zAxis = QString()
- , const QString &yAxis = QString()
- , const QVector<QString> &labelsRow = QVector<QString>()
- , const QVector<QString> &labelsColumn = QVector<QString>());
+ void setLabels(const QString &xAxis = QString(),
+ const QString &zAxis = QString(),
+ const QString &yAxis = QString(),
+ const QVector<QString> &labelsRow = QVector<QString>(),
+ const QVector<QString> &labelsColumn = QVector<QString>());
void addRow(QDataRow *row);
private:
diff --git a/src/datavis3d/engine/theme.cpp b/src/datavis3d/engine/theme.cpp
index 62d1651b..30c2393b 100644
--- a/src/datavis3d/engine/theme.cpp
+++ b/src/datavis3d/engine/theme.cpp
@@ -49,20 +49,20 @@
QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
Theme::Theme()
- : m_baseColor(QColor(Qt::gray))
- , m_heightColor(QColor(Qt::white))
- , m_depthColor(QColor(Qt::darkGray))
- , m_backgroundColor(QColor(Qt::gray))
- , m_windowColor(QColor(Qt::gray))
- , m_textColor(QColor(Qt::white))
- , m_textBackgroundColor(QColor(0x00, 0x00, 0x00, 0x80))
- , m_highlightBarColor(QColor(Qt::red))
- , m_highlightRowColor(QColor(Qt::darkRed))
- , m_highlightColumnColor(QColor(Qt::darkMagenta))
- , m_lightStrength(4.0f)
- , m_ambientStrength(0.3f)
- , m_highlightLightStrength(8.0f)
- , m_uniformColor(true)
+ : m_baseColor(QColor(Qt::gray)),
+ m_heightColor(QColor(Qt::white)),
+ m_depthColor(QColor(Qt::darkGray)),
+ m_backgroundColor(QColor(Qt::gray)),
+ m_windowColor(QColor(Qt::gray)),
+ m_textColor(QColor(Qt::white)),
+ m_textBackgroundColor(QColor(0x00, 0x00, 0x00, 0x80)),
+ m_highlightBarColor(QColor(Qt::red)),
+ m_highlightRowColor(QColor(Qt::darkRed)),
+ m_highlightColumnColor(QColor(Qt::darkMagenta)),
+ m_lightStrength(4.0f),
+ m_ambientStrength(0.3f),
+ m_highlightLightStrength(8.0f),
+ m_uniformColor(true)
{
}
diff --git a/src/datavis3d/engine/theme_p.h b/src/datavis3d/engine/theme_p.h
index 2bd5ed5f..9e77cf75 100644
--- a/src/datavis3d/engine/theme_p.h
+++ b/src/datavis3d/engine/theme_p.h
@@ -70,6 +70,7 @@ public:
private:
friend class Q3DBars;
friend class Q3DBarsPrivate;
+ friend class Drawer;
QColor m_baseColor;
QColor m_heightColor;
diff --git a/src/datavis3d/utils/camerahelper.cpp b/src/datavis3d/utils/camerahelper.cpp
index 4b8830a1..bd0f09f8 100644
--- a/src/datavis3d/utils/camerahelper.cpp
+++ b/src/datavis3d/utils/camerahelper.cpp
@@ -77,17 +77,17 @@ void CameraHelper::setCameraRotation(const QPointF &rotation)
m_defaultYRotation = m_yRotation;
}
-void CameraHelper::setDefaultCameraOrientation(const QVector3D &defaultPosition
- , const QVector3D &defaultTarget
- , const QVector3D &defaultUp)
+void CameraHelper::setDefaultCameraOrientation(const QVector3D &defaultPosition,
+ const QVector3D &defaultTarget,
+ const QVector3D &defaultUp)
{
m_position = defaultPosition;
m_target = defaultTarget;
m_up = defaultUp;
}
-QMatrix4x4 CameraHelper::calculateViewMatrix(const QPoint &mousePos, int zoom
- , int screenWidth, int screenHeight)
+QMatrix4x4 CameraHelper::calculateViewMatrix(const QPoint &mousePos, int zoom,
+ int screenWidth, int screenHeight)
{
QMatrix4x4 viewMatrix;
@@ -108,11 +108,7 @@ QMatrix4x4 CameraHelper::calculateViewMatrix(const QPoint &mousePos, int zoom
m_yRotation = 0;
// Apply to view matrix
- viewMatrix.lookAt(
- m_position // Camera is here
- , m_target // and looks here
- , m_up // Head is up (set to 0,-1,0 to look upside-down)
- );
+ viewMatrix.lookAt(m_position, m_target, m_up);
// Compensate for translation (if m_target is off origin)
viewMatrix.translate(m_target.x(), m_target.y(), m_target.z());
// Apply rotations
@@ -154,9 +150,9 @@ QVector3D CameraHelper::calculateLightPosition(const QVector3D &lightPosition, f
float yPos = lightPosition.y() * sin(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());
+ newLightPosition = QVector3D(-xPos + lightPosition.x(),
+ yPos + lightPosition.y(),
+ zPos + lightPosition.z());
//qDebug() << newLightPosition << xAngle << yAngle << fixedRotation;
return newLightPosition;
}
diff --git a/src/datavis3d/utils/camerahelper_p.h b/src/datavis3d/utils/camerahelper_p.h
index a27bbc3b..94dacffd 100644
--- a/src/datavis3d/utils/camerahelper_p.h
+++ b/src/datavis3d/utils/camerahelper_p.h
@@ -64,7 +64,7 @@ QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
class CameraHelper
{
-public:
+ public:
// How fast camera rotates when mouse is dragged. Default is 100.
static void setRotationSpeed(int speed);
// Set camera rotation in degrees
@@ -72,16 +72,16 @@ public:
// Get camera rotations
static QPointF getCameraRotations();
// Set default camera orientation. Position's x and y should be 0.
- static void setDefaultCameraOrientation(const QVector3D &defaultPosition
- , const QVector3D &defaultTarget
- , const QVector3D &defaultUp);
+ static 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
- , int screenWidth, int screenHeight);
+ static QMatrix4x4 calculateViewMatrix(const QPoint &mousePos, int zoom,
+ int screenWidth, int screenHeight);
// Calcluate light position based on rotation. Call after calling calculateViewMatrix to get
// up-to-date position
- static QVector3D calculateLightPosition(const QVector3D &lightPosition
- , float fixedRotation = 0.0f);
+ static QVector3D calculateLightPosition(const QVector3D &lightPosition,
+ float fixedRotation = 0.0f);
static void updateMousePos(const QPoint &mousePos);
static void setCameraPreset(Q3DBars::CameraPreset preset);
};
diff --git a/src/datavis3d/utils/meshloader_p.h b/src/datavis3d/utils/meshloader_p.h
index c8baa1ac..514ae5c6 100644
--- a/src/datavis3d/utils/meshloader_p.h
+++ b/src/datavis3d/utils/meshloader_p.h
@@ -61,7 +61,7 @@ QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
class MeshLoader
{
-public:
+ public:
static bool loadOBJ(const QString &path,
QVector<QVector3D> &out_vertices,
QVector<QVector2D> &out_uvs,
diff --git a/src/datavis3d/utils/objecthelper.cpp b/src/datavis3d/utils/objecthelper.cpp
index b7f2fa42..a86994e9 100644
--- a/src/datavis3d/utils/objecthelper.cpp
+++ b/src/datavis3d/utils/objecthelper.cpp
@@ -48,13 +48,13 @@
QTCOMMERCIALDATAVIS3D_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_vertexbuffer(0),
+ m_normalbuffer(0),
+ m_uvbuffer(0),
+ m_elementbuffer(0),
+ m_indexCount(0),
+ m_meshDataLoaded(false)
{
initializeOpenGLFunctions();
}
@@ -95,33 +95,33 @@ void ObjectHelper::load()
QVector<QVector3D> indexed_vertices;
QVector<QVector2D> indexed_uvs;
QVector<QVector3D> indexed_normals;
- VertexIndexer::indexVBO(vertices, uvs, normals, indices, indexed_vertices, indexed_uvs
- , indexed_normals);
+ VertexIndexer::indexVBO(vertices, uvs, normals, indices, indexed_vertices, indexed_uvs,
+ indexed_normals);
m_indexCount = indices.size();
//qDebug() << "index count" << m_indexCount;
glGenBuffers(1, &m_vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexbuffer);
- glBufferData(GL_ARRAY_BUFFER, indexed_vertices.size() * sizeof(QVector3D)
- , &indexed_vertices.at(0)
- , GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, indexed_vertices.size() * sizeof(QVector3D),
+ &indexed_vertices.at(0),
+ GL_STATIC_DRAW);
glGenBuffers(1, &m_normalbuffer);
glBindBuffer(GL_ARRAY_BUFFER, m_normalbuffer);
- glBufferData(GL_ARRAY_BUFFER, indexed_normals.size() * sizeof(QVector3D)
- , &indexed_normals.at(0)
- , GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, indexed_normals.size() * sizeof(QVector3D),
+ &indexed_normals.at(0),
+ GL_STATIC_DRAW);
glGenBuffers(1, &m_uvbuffer);
glBindBuffer(GL_ARRAY_BUFFER, m_uvbuffer);
- glBufferData(GL_ARRAY_BUFFER, indexed_uvs.size() * sizeof(QVector2D)
- , &indexed_uvs.at(0), GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, indexed_uvs.size() * sizeof(QVector2D),
+ &indexed_uvs.at(0), GL_STATIC_DRAW);
glGenBuffers(1, &m_elementbuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementbuffer);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned short)
- , &indices.at(0), GL_STATIC_DRAW);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned short),
+ &indices.at(0), GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
diff --git a/src/datavis3d/utils/shaderhelper.cpp b/src/datavis3d/utils/shaderhelper.cpp
index 66bcafd4..50cc564d 100644
--- a/src/datavis3d/utils/shaderhelper.cpp
+++ b/src/datavis3d/utils/shaderhelper.cpp
@@ -45,17 +45,17 @@
QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
-ShaderHelper::ShaderHelper(QObject *parent
- , const QString &vertexShader
- , const QString &fragmentShader
- , const QString &texture
- , const QString &depthTexture)
- : m_caller(parent)
- , m_program(0)
- , m_vertexShaderFile(vertexShader)
- , m_fragmentShaderFile(fragmentShader)
- , m_textureFile(texture)
- , m_depthTextureFile(depthTexture)
+ShaderHelper::ShaderHelper(QObject *parent,
+ const QString &vertexShader,
+ const QString &fragmentShader,
+ const QString &texture,
+ const QString &depthTexture)
+ : m_caller(parent),
+ m_program(0),
+ m_vertexShaderFile(vertexShader),
+ m_fragmentShaderFile(fragmentShader),
+ m_textureFile(texture),
+ m_depthTextureFile(depthTexture)
{
}
@@ -64,15 +64,15 @@ ShaderHelper::~ShaderHelper()
delete m_program;
}
-void ShaderHelper::setShaders(const QString &vertexShader
- , const QString &fragmentShader)
+void ShaderHelper::setShaders(const QString &vertexShader,
+ const QString &fragmentShader)
{
m_vertexShaderFile = vertexShader;
m_fragmentShaderFile = fragmentShader;
}
-void ShaderHelper::setTextures(const QString &texture
- , const QString &depthTexture)
+void ShaderHelper::setTextures(const QString &texture,
+ const QString &depthTexture)
{
m_textureFile = texture;
m_depthTextureFile = depthTexture;
@@ -219,6 +219,4 @@ GLuint ShaderHelper::normalAtt()
return m_normalAttr;
}
-// TODO: Add texture stuff
-
QTCOMMERCIALDATAVIS3D_END_NAMESPACE
diff --git a/src/datavis3d/utils/shaderhelper_p.h b/src/datavis3d/utils/shaderhelper_p.h
index 29e3583b..986ca826 100644
--- a/src/datavis3d/utils/shaderhelper_p.h
+++ b/src/datavis3d/utils/shaderhelper_p.h
@@ -62,11 +62,11 @@ QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
class ShaderHelper
{
public:
- ShaderHelper(QObject *parent
- , const QString &vertexShader = QString()
- , const QString &fragmentShader = QString()
- , const QString &texture = QString()
- , const QString &depthTexture = QString());
+ ShaderHelper(QObject *parent,
+ const QString &vertexShader = QString(),
+ const QString &fragmentShader = QString(),
+ const QString &texture = QString(),
+ const QString &depthTexture = QString());
~ShaderHelper();
void setShaders(const QString &vertexShader, const QString &fragmentShader);
diff --git a/src/datavis3d/utils/texturehelper.cpp b/src/datavis3d/utils/texturehelper.cpp
index 99a3e6bf..428359a7 100644
--- a/src/datavis3d/utils/texturehelper.cpp
+++ b/src/datavis3d/utils/texturehelper.cpp
@@ -63,11 +63,11 @@ GLuint TextureHelper::create2DTexture(const QImage &image, bool useTrilinearFilt
glBindTexture(GL_TEXTURE_2D, textureId);
if (convert) {
QImage glTexture = convertToGLFormat(image);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, glTexture.width(), glTexture.height()
- , 0, GL_RGBA, GL_UNSIGNED_BYTE, glTexture.bits());
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, glTexture.width(), glTexture.height(),
+ 0, GL_RGBA, GL_UNSIGNED_BYTE, glTexture.bits());
} else {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height()
- , 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits());
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(),
+ 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits());
}
if (useTrilinearFiltering) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -87,8 +87,8 @@ GLuint TextureHelper::createCubeMapTexture(const QImage &image, bool useTrilinea
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureId);
QImage glTexture = convertToGLFormat(image);
- glTexImage2D(GL_TEXTURE_CUBE_MAP, 0, GL_RGBA, glTexture.width(), glTexture.height()
- , 0, GL_RGBA, GL_UNSIGNED_BYTE, glTexture.bits());
+ glTexImage2D(GL_TEXTURE_CUBE_MAP, 0, GL_RGBA, glTexture.width(), glTexture.height(),
+ 0, GL_RGBA, GL_UNSIGNED_BYTE, glTexture.bits());
if (useTrilinearFiltering) {
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
@@ -108,8 +108,8 @@ QImage TextureHelper::convertToGLFormat(const QImage &srcImage)
return res;
}
-void TextureHelper::convertToGLFormatHelper(QImage &dstImage, const QImage &srcImage
- , GLenum texture_format)
+void TextureHelper::convertToGLFormatHelper(QImage &dstImage, const QImage &srcImage,
+ GLenum texture_format)
{
Q_ASSERT(dstImage.depth() == 32);
Q_ASSERT(srcImage.depth() == 32);
diff --git a/src/datavis3d/utils/texturehelper_p.h b/src/datavis3d/utils/texturehelper_p.h
index 541c79ee..7fa0816b 100644
--- a/src/datavis3d/utils/texturehelper_p.h
+++ b/src/datavis3d/utils/texturehelper_p.h
@@ -60,16 +60,16 @@ QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
class TextureHelper: protected QOpenGLFunctions
{
-public:
+ public:
TextureHelper();
~TextureHelper();
// Ownership of created texture is transferred to caller
- GLuint create2DTexture(const QImage &image, bool useTrilinearFiltering = false
- , bool convert = true);
+ GLuint create2DTexture(const QImage &image, bool useTrilinearFiltering = false,
+ bool convert = true);
GLuint createCubeMapTexture(const QImage &image, bool useTrilinearFiltering = false);
-private:
+ private:
QImage convertToGLFormat(const QImage &srcImage);
void convertToGLFormatHelper(QImage &dstImage, const QImage &srcImage, GLenum texture_format);
QRgb qt_gl_convertToGLFormatHelper(QRgb src_pixel, GLenum texture_format);
diff --git a/src/datavis3d/utils/utils.cpp b/src/datavis3d/utils/utils.cpp
index 89068c01..c6a17eae 100644
--- a/src/datavis3d/utils/utils.cpp
+++ b/src/datavis3d/utils/utils.cpp
@@ -60,16 +60,11 @@ QVector3D Utils::vectorFromColor(const QColor &color)
return QVector3D(color.redF(), color.greenF(), color.blueF());
}
-void Utils::printText(QPainter *painter, const QString &text, const QSize &position
- , bool absoluteCoords, qreal rotation, qreal scale)
+void Utils::printText(QPainter *painter, const QString &text, const QSize &position,
+ bool absoluteCoords, qreal rotation, qreal scale)
{
painter->save();
painter->setCompositionMode(QPainter::CompositionMode_Source);
- // TODO: None of the commented-out stuff works..
- //painter->setBackgroundMode(Qt::OpaqueMode);
- //painter->setBackground(QBrush(d_ptr->m_textBackgroundColor));
- //painter->setBrush(QBrush(d_ptr->m_textBackgroundColor));
- //painter->setPen(d_ptr->m_textBackgroundColor);
painter->setPen(Qt::black); // TODO: Use black, as nothing works
QFont bgrFont = QFont(QStringLiteral("Arial"), 17);
QFont valueFont = QFont(QStringLiteral("Arial"), 11);
@@ -85,40 +80,38 @@ void Utils::printText(QPainter *painter, const QString &text, const QSize &posit
bgrStr.append(QStringLiteral("I"));
bgrStrLen = bgrFM.width(bgrStr);
} while (bgrStrLen <= (valueStrLen + 8));
- //int bgrLen = valueStrLen + 10;
- //painter->drawRoundedRect(data->d_ptr->position().x() - (bgrLen / 2)
- // , data->d_ptr->position().y() - 30
- // , bgrLen, 30, 10.0, 10.0);
#if 0
// Hack solution, as drawRect doesn't work
- painter->drawText(position.width() - (bgrStrLen / 2)
- , position.height() - bgrHeight
- , bgrStrLen, bgrHeight
- , Qt::AlignCenter | Qt::AlignVCenter
- , bgrStr);
+ painter->drawText(position.width() - (bgrStrLen / 2),
+ position.height() - bgrHeight,
+ bgrStrLen, bgrHeight,
+ Qt::AlignCenter | Qt::AlignVCenter,
+ bgrStr);
//painter->setPen(d_ptr->m_textColor);
painter->setPen(Qt::lightGray); // TODO: Use lightGray, as nothing works
painter->setFont(valueFont);
- painter->drawText(position.width() - (valueStrLen / 2)
- , position.height() - bgrHeight
- , valueStrLen, bgrHeight
- , Qt::AlignCenter | Qt::AlignVCenter
- , text);
+ painter->drawText(position.width() - (valueStrLen / 2),
+ position.height() - bgrHeight,
+ valueStrLen, bgrHeight,
+ Qt::AlignCenter | Qt::AlignVCenter,
+ text);
#else
//qDebug() << painter->window() << painter->viewport();
painter->scale(scale, scale);
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))
- , position.height()
+ painter->translate(position.width() - (((float)bgrStrLen / 2.0f)
+ * cos(rotation * m_pi / 180.0f))
+ + (((float)bgrHeight / 2.0f) * sin(rotation * m_pi / 180.0f)),
+ position.height()
- ((((float)bgrHeight / 2.0f) * cos(rotation * m_pi / 180.0f))
+ (((float)bgrStrLen / 2.0f) * sin(rotation * m_pi / 180.0f))));
} else {
// This calculates y as a distance from screen bottom
- painter->translate(position.width() - (((float)bgrStrLen / 2) * cos(rotation * m_pi / 180.0f))
- + (((float)bgrHeight / 2.0f) * sin(rotation * m_pi / 180.0f))
- , painter->window().height() - position.height()
+ painter->translate(position.width() - (((float)bgrStrLen / 2.0f)
+ * cos(rotation * m_pi / 180.0f))
+ + (((float)bgrHeight / 2.0f) * sin(rotation * m_pi / 180.0f)),
+ 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))));
}
@@ -126,24 +119,24 @@ void Utils::printText(QPainter *painter, const QString &text, const QSize &posit
// - ((((float)bgrHeight / 2.0f) * cos(rotation * m_pi / 180.0f))
// + (((float)bgrStrLen / 2.0f) * sin(rotation * m_pi / 180.0f)));
painter->rotate(rotation);
- painter->drawText(0, 0
- , bgrStrLen, bgrHeight
- , Qt::AlignCenter | Qt::AlignVCenter
- , bgrStr);
+ painter->drawText(0, 0,
+ bgrStrLen, bgrHeight,
+ Qt::AlignCenter | Qt::AlignVCenter,
+ bgrStr);
painter->setPen(Qt::lightGray); // TODO: Use lightGray, as nothing works
painter->setFont(valueFont);
- painter->drawText(6, 0
- , valueStrLen, bgrHeight
- , Qt::AlignCenter | Qt::AlignVCenter
- , text);
+ painter->drawText(6, 0,
+ valueStrLen, bgrHeight,
+ Qt::AlignCenter | Qt::AlignVCenter,
+ text);
painter->resetTransform();
#endif
painter->restore();
}
-QImage Utils::printTextToImage(const QFont &font, const QString &text, const QColor &bgrColor
- , const QColor &txtColor
- , Q3DBars::LabelTransparency transparency)
+QImage Utils::printTextToImage(const QFont &font, const QString &text, const QColor &bgrColor,
+ const QColor &txtColor,
+ Q3DBars::LabelTransparency transparency)
{
// Calculate text dimensions
QFont valueFont = font;
@@ -171,10 +164,10 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo
{
painter.setFont(valueFont);
painter.setPen(txtColor);
- painter.drawText(0, 0
- , valueStrWidth, valueStrHeight
- , Qt::AlignCenter | Qt::AlignVCenter
- , text);
+ painter.drawText(0, 0,
+ valueStrWidth, valueStrHeight,
+ Qt::AlignCenter | Qt::AlignVCenter,
+ text);
break;
}
case Q3DBars::TransparencyFromTheme:
@@ -184,10 +177,10 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo
painter.drawRoundedRect(0, 0, labelSize.width(), labelSize.height(), 10.0, 10.0f);
painter.setFont(valueFont);
painter.setPen(txtColor);
- painter.drawText(15, 15
- , valueStrWidth, valueStrHeight
- , Qt::AlignCenter | Qt::AlignVCenter
- , text);
+ painter.drawText(15, 15,
+ valueStrWidth, valueStrHeight,
+ Qt::AlignCenter | Qt::AlignVCenter,
+ text);
break;
}
case Q3DBars::TransparencyNone:
@@ -197,10 +190,10 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo
painter.drawRect(0, 0, labelSize.width(), labelSize.height());
painter.setFont(valueFont);
painter.setPen(txtColor);
- painter.drawText(15, 15
- , valueStrWidth, valueStrHeight
- , Qt::AlignCenter | Qt::AlignVCenter
- , text);
+ painter.drawText(15, 15,
+ valueStrWidth, valueStrHeight,
+ Qt::AlignCenter | Qt::AlignVCenter,
+ text);
break;
}
}
diff --git a/src/datavis3d/utils/utils_p.h b/src/datavis3d/utils/utils_p.h
index 4d49c0d5..abe47621 100644
--- a/src/datavis3d/utils/utils_p.h
+++ b/src/datavis3d/utils/utils_p.h
@@ -66,15 +66,15 @@ QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
class Utils
{
-public:
+ public:
static QVector3D vectorFromColor(const QColor &color);
- static void printText(QPainter *painter, const QString &text, const QSize &position
- , bool absoluteCoords = true, qreal rotation = 0, qreal scale = 1.0f);
- static QImage printTextToImage(const QFont &font
- , const QString &text
- , const QColor &bgrColor
- , const QColor &txtColor
- , Q3DBars::LabelTransparency transparency);
+ static void printText(QPainter *painter, const QString &text, const QSize &position,
+ bool absoluteCoords = true, qreal rotation = 0, qreal scale = 1.0f);
+ static QImage printTextToImage(const QFont &font,
+ const QString &text,
+ const QColor &bgrColor,
+ const QColor &txtColor,
+ Q3DBars::LabelTransparency transparency);
static QVector3D getSelection(QPoint mousepos, int height);
};
diff --git a/src/datavis3d/utils/vertexindexer.cpp b/src/datavis3d/utils/vertexindexer.cpp
index d10d7903..432e3895 100644
--- a/src/datavis3d/utils/vertexindexer.cpp
+++ b/src/datavis3d/utils/vertexindexer.cpp
@@ -59,13 +59,13 @@ bool VertexIndexer::is_near(float v1, float v2)
// 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
- , const QVector3D &in_normal
- , QVector<QVector3D> &out_vertices
- , QVector<QVector2D> &out_uvs
- , QVector<QVector3D> &out_normals
- , unsigned short &result)
+bool VertexIndexer::getSimilarVertexIndex(const QVector3D &in_vertex,
+ const QVector2D &in_uv,
+ const QVector3D &in_normal,
+ QVector<QVector3D> &out_vertices,
+ QVector<QVector2D> &out_uvs,
+ QVector<QVector3D> &out_normals,
+ unsigned short &result)
{
// Lame linear search
for (int i = 0; i < out_vertices.size(); i++) {
@@ -86,9 +86,9 @@ bool VertexIndexer::getSimilarVertexIndex(const QVector3D &in_vertex
return false;
}
-bool VertexIndexer::getSimilarVertexIndex_fast(const PackedVertex &packed
- , QMap<PackedVertex, unsigned short> &VertexToOutIndex
- , unsigned short &result)
+bool VertexIndexer::getSimilarVertexIndex_fast(const PackedVertex &packed,
+ QMap<PackedVertex, unsigned short> &VertexToOutIndex,
+ unsigned short &result)
{
QMap<PackedVertex, unsigned short>::iterator it = VertexToOutIndex.find(packed);
if (it == VertexToOutIndex.end()) {
@@ -99,13 +99,13 @@ bool VertexIndexer::getSimilarVertexIndex_fast(const PackedVertex &packed
}
}
-void VertexIndexer::indexVBO(const QVector<QVector3D> &in_vertices
- , const QVector<QVector2D> &in_uvs
- , const QVector<QVector3D> &in_normals
- , QVector<unsigned short> &out_indices
- , QVector<QVector3D> &out_vertices
- , QVector<QVector2D> &out_uvs
- , QVector<QVector3D> &out_normals)
+void VertexIndexer::indexVBO(const QVector<QVector3D> &in_vertices,
+ const QVector<QVector2D> &in_uvs,
+ const QVector<QVector3D> &in_normals,
+ QVector<unsigned short> &out_indices,
+ QVector<QVector3D> &out_vertices,
+ QVector<QVector2D> &out_uvs,
+ QVector<QVector3D> &out_normals)
{
unique_vertices = 0;
QMap<PackedVertex, unsigned short> VertexToOutIndex;
@@ -118,9 +118,9 @@ void VertexIndexer::indexVBO(const QVector<QVector3D> &in_vertices
unsigned short index;
bool found = getSimilarVertexIndex_fast(packed, VertexToOutIndex, index);
- if (found) { // A similar vertex is already in the VBO, use it instead !
+ if (found) {
out_indices.append(index);
- } else { // If not, it needs to be added in the output data.
+ } else {
unique_vertices++;
out_vertices.append(in_vertices[i]);
out_uvs.append(in_uvs[i]);
@@ -133,17 +133,17 @@ void VertexIndexer::indexVBO(const QVector<QVector3D> &in_vertices
qDebug() << "unique vertices" << unique_vertices;
}
-void VertexIndexer::indexVBO_TBN(const QVector<QVector3D> &in_vertices
- , const QVector<QVector2D> &in_uvs
- , const QVector<QVector3D> &in_normals
- , const QVector<QVector3D> &in_tangents
- , const QVector<QVector3D> &in_bitangents
- , QVector<unsigned short> &out_indices
- , QVector<QVector3D> &out_vertices
- , QVector<QVector2D> &out_uvs
- , QVector<QVector3D> &out_normals
- , QVector<QVector3D> &out_tangents
- , QVector<QVector3D> &out_bitangents)
+void VertexIndexer::indexVBO_TBN(const QVector<QVector3D> &in_vertices,
+ const QVector<QVector2D> &in_uvs,
+ const QVector<QVector3D> &in_normals,
+ const QVector<QVector3D> &in_tangents,
+ const QVector<QVector3D> &in_bitangents,
+ QVector<unsigned short> &out_indices,
+ QVector<QVector3D> &out_vertices,
+ QVector<QVector2D> &out_uvs,
+ QVector<QVector3D> &out_normals,
+ QVector<QVector3D> &out_tangents,
+ QVector<QVector3D> &out_bitangents)
{
unique_vertices = 0;
// For each input vertex
@@ -151,16 +151,16 @@ void VertexIndexer::indexVBO_TBN(const QVector<QVector3D> &in_vertices
// Try to find a similar vertex in out_XXXX
unsigned short index;
- bool found = getSimilarVertexIndex(in_vertices[i], in_uvs[i], in_normals[i]
- , out_vertices, out_uvs, out_normals, index);
+ bool found = getSimilarVertexIndex(in_vertices[i], in_uvs[i], in_normals[i],
+ out_vertices, out_uvs, out_normals, index);
- if (found) { // A similar vertex is already in the VBO, use it instead !
+ if (found) {
out_indices.append(index);
// Average the tangents and the bitangents
out_tangents[index] += in_tangents[i];
out_bitangents[index] += in_bitangents[i];
- } else { // If not, it needs to be added in the output data.
+ } else {
unique_vertices++;
out_vertices.append(in_vertices[i]);
out_uvs.append(in_uvs[i]);
diff --git a/src/datavis3d/utils/vertexindexer_p.h b/src/datavis3d/utils/vertexindexer_p.h
index 13824b22..3ee908af 100644
--- a/src/datavis3d/utils/vertexindexer_p.h
+++ b/src/datavis3d/utils/vertexindexer_p.h
@@ -72,38 +72,38 @@ class VertexIndexer
}
};
- static void indexVBO(const QVector<QVector3D> &in_vertices
- , const QVector<QVector2D> &in_uvs
- , const QVector<QVector3D> &in_normals
- , QVector<unsigned short> &out_indices
- , QVector<QVector3D> &out_vertices
- , QVector<QVector2D> &out_uvs
- , QVector<QVector3D> &out_normals);
+ static void indexVBO(const QVector<QVector3D> &in_vertices,
+ const QVector<QVector2D> &in_uvs,
+ const QVector<QVector3D> &in_normals,
+ QVector<unsigned short> &out_indices,
+ QVector<QVector3D> &out_vertices,
+ QVector<QVector2D> &out_uvs,
+ QVector<QVector3D> &out_normals);
- static void indexVBO_TBN(const QVector<QVector3D> &in_vertices
- , const QVector<QVector2D> &in_uvs
- , const QVector<QVector3D> &in_normals
- , const QVector<QVector3D> &in_tangents
- , const QVector<QVector3D> &in_bitangents
- , QVector<unsigned short> &out_indices
- , QVector<QVector3D> &out_vertices
- , QVector<QVector2D> &out_uvs
- , QVector<QVector3D> &out_normals
- , QVector<QVector3D> &out_tangents
- , QVector<QVector3D> &out_bitangents);
+ static void indexVBO_TBN(const QVector<QVector3D> &in_vertices,
+ const QVector<QVector2D> &in_uvs,
+ const QVector<QVector3D> &in_normals,
+ const QVector<QVector3D> &in_tangents,
+ const QVector<QVector3D> &in_bitangents,
+ QVector<unsigned short> &out_indices,
+ QVector<QVector3D> &out_vertices,
+ QVector<QVector2D> &out_uvs,
+ QVector<QVector3D> &out_normals,
+ QVector<QVector3D> &out_tangents,
+ QVector<QVector3D> &out_bitangents);
private:
static bool is_near(float v1, float v2);
- static bool getSimilarVertexIndex(const QVector3D &in_vertex
- , const QVector2D &in_uv
- , const QVector3D &in_normal
- , QVector<QVector3D> &out_vertices
- , QVector<QVector2D> &out_uvs
- , QVector<QVector3D> &out_normals
- , unsigned short &result);
- static bool getSimilarVertexIndex_fast(const PackedVertex &packed
- , QMap<PackedVertex, unsigned short> &VertexToOutIndex
- , unsigned short &result);
+ static bool getSimilarVertexIndex(const QVector3D &in_vertex,
+ const QVector2D &in_uv,
+ const QVector3D &in_normal,
+ QVector<QVector3D> &out_vertices,
+ QVector<QVector2D> &out_uvs,
+ QVector<QVector3D> &out_normals,
+ unsigned short &result);
+ static bool getSimilarVertexIndex_fast(const PackedVertex &packed,
+ QMap<PackedVertex, unsigned short> &VertexToOutIndex,
+ unsigned short &result);
};
QTCOMMERCIALDATAVIS3D_END_NAMESPACE