summaryrefslogtreecommitdiffstats
path: root/src/datavis3d/engine
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2013-07-08 15:11:06 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2013-07-09 07:40:05 +0300
commit24275c551f0a10df022f037962d1678b7213ef09 (patch)
tree310a339c2c1582d68618881c905fd32dd64f2f5e /src/datavis3d/engine
parentd9267977b3f5bb8ab5573c29f0721a07397e5b82 (diff)
Refactor data item
Data items do not need to know about rendering related stuff, so separated that to render items. Renderer will maintain array of render items equal to the sample space. Change-Id: I61c0db96f115b7c667e37ea92aa5ae6b8583c61a Reviewed-by: Mika Salmela <mika.salmela@digia.com>
Diffstat (limited to 'src/datavis3d/engine')
-rw-r--r--src/datavis3d/engine/bars3dcontroller.cpp17
-rw-r--r--src/datavis3d/engine/bars3dcontroller_p.h1
-rw-r--r--src/datavis3d/engine/bars3drenderer.cpp165
-rw-r--r--src/datavis3d/engine/bars3drenderer_p.h21
-rw-r--r--src/datavis3d/engine/drawer.cpp19
-rw-r--r--src/datavis3d/engine/drawer_p.h6
-rw-r--r--src/datavis3d/engine/maps3dcontroller.cpp7
7 files changed, 144 insertions, 92 deletions
diff --git a/src/datavis3d/engine/bars3dcontroller.cpp b/src/datavis3d/engine/bars3dcontroller.cpp
index c3f7aa5f..a633999e 100644
--- a/src/datavis3d/engine/bars3dcontroller.cpp
+++ b/src/datavis3d/engine/bars3dcontroller.cpp
@@ -76,7 +76,8 @@ Bars3dController::Bars3dController(QRect boundRect)
m_tickStep(0),
m_tickMinimum(0.0f),
m_renderer(0),
- m_data(0)
+ m_data(0),
+ m_valuesDirty(false)
{
// Default axes. Only Y axis can actually be changed by user.
setAxisX(new QCategoryAxis());
@@ -113,9 +114,10 @@ void Bars3dController::render(const GLuint defaultFboHandle)
return;
// TODO do not give the entire data array, just the data window
- QMutexLocker(m_data->mutex());
- m_renderer->render(m_data->array(), m_cameraHelper, m_axisX->d_ptr->titleItem(),
+ m_renderer->render(m_data, m_valuesDirty, m_cameraHelper, m_axisX->d_ptr->titleItem(),
m_axisY->d_ptr->titleItem(), m_axisZ->d_ptr->titleItem(), defaultFboHandle);
+
+ m_valuesDirty = false;
}
QMatrix4x4 Bars3dController::calculateViewMatrix(int zoom, int viewPortWidth, int viewPortHeight, bool showUnder)
@@ -278,7 +280,7 @@ void Bars3dController::setDataProxy(QBarDataProxy *proxy)
QObject::connect(m_data, &QBarDataProxy::rowsRemoved, this, &Bars3dController::handleRowsRemoved);
QObject::connect(m_data, &QBarDataProxy::rowsInserted, this, &Bars3dController::handleRowsInserted);
- // emit something?
+ // emit something? Renderer might be interested?
}
QBarDataProxy *Bars3dController::dataProxy()
@@ -290,6 +292,7 @@ void Bars3dController::handleArrayReset()
{
setSlicingActive(false);
handleLimitChange();
+ m_valuesDirty = true;
}
void Bars3dController::handleRowsAdded(int startIndex, int count)
@@ -300,6 +303,7 @@ void Bars3dController::handleRowsAdded(int startIndex, int count)
// TODO should update slice instead of deactivating?
setSlicingActive(false);
handleLimitChange();
+ m_valuesDirty = true;
}
void Bars3dController::handleRowsChanged(int startIndex, int count)
@@ -310,6 +314,7 @@ void Bars3dController::handleRowsChanged(int startIndex, int count)
// TODO should update slice instead of deactivating?
setSlicingActive(false);
handleLimitChange();
+ m_valuesDirty = true;
}
void Bars3dController::handleRowsRemoved(int startIndex, int count)
@@ -320,6 +325,7 @@ void Bars3dController::handleRowsRemoved(int startIndex, int count)
// TODO should update slice instead of deactivating?
setSlicingActive(false);
handleLimitChange();
+ m_valuesDirty = true;
}
void Bars3dController::handleRowsInserted(int startIndex, int count)
@@ -330,6 +336,7 @@ void Bars3dController::handleRowsInserted(int startIndex, int count)
// TODO should update slice instead of deactivating?
setSlicingActive(false);
handleLimitChange();
+ m_valuesDirty = true;
}
void Bars3dController::setBarSpecs(QSizeF thickness, QSizeF spacing, bool relative)
@@ -416,7 +423,7 @@ void Bars3dController::setupSampleSpace(int rowCount, int columnCount)
m_rowCount = rowCount;
m_columnCount = columnCount;
- emit sampleSpaceChanged(columnCount, rowCount);
+ emit sampleSpaceChanged(rowCount, columnCount);
}
diff --git a/src/datavis3d/engine/bars3dcontroller_p.h b/src/datavis3d/engine/bars3dcontroller_p.h
index 0fa00ea0..8151ea2b 100644
--- a/src/datavis3d/engine/bars3dcontroller_p.h
+++ b/src/datavis3d/engine/bars3dcontroller_p.h
@@ -111,6 +111,7 @@ private:
Bars3dRenderer *m_renderer;
QBarDataProxy *m_data;
+ bool m_valuesDirty;
public:
explicit Bars3dController(QRect rect);
diff --git a/src/datavis3d/engine/bars3drenderer.cpp b/src/datavis3d/engine/bars3drenderer.cpp
index f8031734..c2bfc8ed 100644
--- a/src/datavis3d/engine/bars3drenderer.cpp
+++ b/src/datavis3d/engine/bars3drenderer.cpp
@@ -49,7 +49,7 @@
#include "utils_p.h"
#include "drawer_p.h"
#include "qabstractaxis_p.h"
-#include "qbardataitem_p.h"
+#include "qbardataitem.h"
#include <QMatrix4x4>
#include <QMouseEvent>
@@ -121,12 +121,15 @@ Bars3dRenderer::Bars3dRenderer(Bars3dController *controller)
m_maxSceneSize(40.0),
m_selection(selectionSkipColor),
m_hasHeightAdjustmentChanged(true),
- m_dummyBarDataItem(new QBarDataItem)
+ m_dataProxy(0),
+ m_dataWindowChanged(false)
#ifdef DISPLAY_RENDER_SPEED
,m_isFirstFrame(true),
m_numFrames(0)
#endif
{
+ m_dummyBarRenderItem.setRenderer(this);
+
// Listen to changes in the drawer
QObject::connect(m_drawer, &Drawer::drawerChanged, this, &Bars3dRenderer::updateTextures);
@@ -167,7 +170,7 @@ Bars3dRenderer::Bars3dRenderer(Bars3dController *controller)
&Bars3dRenderer::updateZoomLevel);
updateTheme(m_controller->theme());
- updateSampleSpace(m_controller->columnCount(), m_controller->rowCount());
+ updateSampleSpace(m_controller->rowCount(), m_controller->columnCount());
updateSelectionMode(m_controller->selectionMode());
updateSlicingActive(m_controller->isSlicingActive());
updateLimits(m_controller->limits());
@@ -214,7 +217,6 @@ Bars3dRenderer::~Bars3dRenderer()
delete m_gridLineObj;
delete m_textureHelper;
delete m_drawer;
- delete m_dummyBarDataItem;
}
void Bars3dRenderer::initializeOpenGL()
@@ -303,7 +305,8 @@ void Bars3dRenderer::initializeOpenGL()
loadBackgroundMesh();
}
-void Bars3dRenderer::render(const QBarDataArray &dataArray,
+void Bars3dRenderer::render(QBarDataProxy *dataProxy,
+ bool valuesDirty,
CameraHelper *camera,
const LabelItem &xLabel,
const LabelItem &yLabel,
@@ -326,6 +329,32 @@ void Bars3dRenderer::render(const QBarDataArray &dataArray,
}
#endif
+ // TODO Would it be enough to just mutex cache update?
+ // TODO --> Only if there is no need to store m_dataProxy for later, e.g. for string formatting
+ QMutexLocker(dataProxy->mutex());
+ m_dataProxy = dataProxy;
+
+ // Update cached data window
+ // TODO Should data changes be notified via signal instead of reading data in render?
+ // TODO this cache initialization assumes data window starts at 0,0 offset from array
+ if (valuesDirty || m_dataWindowChanged) {
+ m_dataWindowChanged = false;
+ int dataRowCount = dataProxy->rowCount();
+ for (int i = 0; i < m_renderItemArray.size(); i++) {
+ int j = 0;
+ if (i < dataRowCount) {
+ const QBarDataRow *dataRow = dataProxy->rowAt(i);
+ int updateSize = qMin(dataRow->size(), m_renderItemArray[i].size());
+ if (dataRow) {
+ for (; j < updateSize ; j++)
+ m_renderItemArray[i][j].setValue(dataRow->at(j).value());
+ }
+ }
+ for (; j < m_renderItemArray[i].size(); j++)
+ m_renderItemArray[i][j].setValue(0);
+ }
+ }
+
if (defaultFboHandle) {
glDepthMask(true);
glEnable(GL_DEPTH_TEST);
@@ -350,7 +379,7 @@ void Bars3dRenderer::render(const QBarDataArray &dataArray,
drawSlicedScene(camera, xLabel, yLabel, zLabel);
// Draw bars scene
- drawScene(dataArray, camera, defaultFboHandle);
+ drawScene(camera, defaultFboHandle);
}
void Bars3dRenderer::drawSlicedScene(CameraHelper *camera,
@@ -413,7 +442,7 @@ void Bars3dRenderer::drawSlicedScene(CameraHelper *camera,
// Draw bars
// Draw the selected row / column
for (int bar = startBar; bar != stopBar; bar += stepBar) {
- QBarDataItem *item = m_sliceSelection->at(bar);
+ BarRenderItem *item = m_sliceSelection->at(bar);
if (!item)
continue;
@@ -428,11 +457,11 @@ void Bars3dRenderer::drawSlicedScene(CameraHelper *camera,
QMatrix4x4 MVPMatrix;
QMatrix4x4 itModelMatrix;
- GLfloat barPosY = item->d_ptr->translation().y() - m_yAdjustment / 2.0f + 0.2f; // we need some room for labels underneath; add +0.2f
+ GLfloat barPosY = item->translation().y() - m_yAdjustment / 2.0f + 0.2f; // we need some room for labels underneath; add +0.2f
if (ModeZoomRow == m_cachedSelectionMode)
- barPosX = item->d_ptr->translation().x();
+ barPosX = item->translation().x();
else
- barPosX = -(item->d_ptr->translation().z() - zComp); // flip z; frontmost bar to the left
+ barPosX = -(item->translation().z() - zComp); // flip z; frontmost bar to the left
modelMatrix.translate(barPosX, barPosY, zComp);
modelMatrix.scale(QVector3D(m_scaleX, barHeight, m_scaleZ));
itModelMatrix.scale(QVector3D(m_scaleX, barHeight, m_scaleZ));
@@ -477,7 +506,7 @@ void Bars3dRenderer::drawSlicedScene(CameraHelper *camera,
}
// Draw labels for axes
- QBarDataItem *dummyItem = NULL;
+ BarRenderItem *dummyItem(0);
const LabelItem &sliceSelectionLabel = *m_sliceTitleItem;
if (ModeZoomRow == m_cachedSelectionMode) {
if (m_sliceTitleItem) {
@@ -514,9 +543,9 @@ void Bars3dRenderer::drawSlicedScene(CameraHelper *camera,
// Draw labels for bars
for (int col = 0; col < m_sliceSelection->size(); col++) {
- QBarDataItem *item = m_sliceSelection->at(col);
+ BarRenderItem *item = m_sliceSelection->at(col);
// Draw values
- m_drawer->drawLabel(*item, item->dptr()->labelItem(), viewMatrix, projectionMatrix,
+ m_drawer->drawLabel(*item, item->labelItem(), viewMatrix, projectionMatrix,
QVector3D(0.0f, m_yAdjustment, zComp),
QVector3D(0.0f, 0.0f, 0.0f), (item->value() / m_heightNormalizer),
m_cachedSelectionMode, m_labelShader,
@@ -550,8 +579,7 @@ void Bars3dRenderer::drawSlicedScene(CameraHelper *camera,
m_labelShader->release();
}
-void Bars3dRenderer::drawScene(const QBarDataArray &dataArray,
- CameraHelper *camera,
+void Bars3dRenderer::drawScene(CameraHelper *camera,
const GLuint defaultFboHandle)
{
GLint startBar = 0;
@@ -668,16 +696,13 @@ void Bars3dRenderer::drawScene(const QBarDataArray &dataArray,
#endif
// Draw bars to depth buffer
for (int row = startRow; row != stopRow; row += stepRow) {
- if (dataArray.size() <= row || !dataArray.at(row))
- continue;
for (int bar = startBar; bar != stopBar; bar += stepBar) {
- if (dataArray.at(row)->size() <= bar)
- continue;
- QBarDataItem *item = dataArray.at(row)->at(bar);
- if (!item)
+ BarRenderItem &item = m_renderItemArray[row][bar];
+ if (!item.value())
continue;
- GLfloat barHeight = item->value() / m_heightNormalizer;
+ // TODO Cache barHeights to render items
+ GLfloat barHeight = item.value() / m_heightNormalizer;
// skip shadows for 0 -height bars
if (barHeight == 0)
@@ -772,16 +797,12 @@ void Bars3dRenderer::drawScene(const QBarDataArray &dataArray,
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Needed for clearing the frame buffer
glDisable(GL_DITHER); // disable dithering, it may affect colors if enabled
for (int row = startRow; row != stopRow; row += stepRow) {
- if (dataArray.size() <= row || !dataArray.at(row))
- continue;
for (int bar = startBar; bar != stopBar; bar += stepBar) {
- if (dataArray.at(row)->size() <= bar)
- continue;
- QBarDataItem *item = dataArray.at(row)->at(bar);
- if (!item)
+ BarRenderItem &item = m_renderItemArray[row][bar];
+ if (!item.value())
continue;
-
- GLfloat barHeight = item->value() / m_heightNormalizer;
+ // TODO resolved bar heights should be cached?
+ GLfloat barHeight = item.value() / m_heightNormalizer;
if (barHeight < 0)
glCullFace(GL_FRONT);
@@ -888,16 +909,13 @@ void Bars3dRenderer::drawScene(const QBarDataArray &dataArray,
}
bool barSelectionFound = false;
for (int row = startRow; row != stopRow; row += stepRow) {
- if (dataArray.size() <= row || !dataArray.at(row))
- continue;
for (int bar = startBar; bar != stopBar; bar += stepBar) {
- if (dataArray.at(row)->size() <= bar)
- continue;
- QBarDataItem *item = dataArray.at(row)->at(bar);
- if (!item)
+ BarRenderItem &item = m_renderItemArray[row][bar];
+ if (!item.value())
continue;
- GLfloat barHeight = item->value() / m_heightNormalizer;
+ // TODO resolved bar heights should be cached?
+ GLfloat barHeight = item.value() / m_heightNormalizer;
if (barHeight < 0)
glCullFace(GL_FRONT);
@@ -942,13 +960,13 @@ void Bars3dRenderer::drawScene(const QBarDataArray &dataArray,
lightStrength = m_cachedTheme.m_highlightLightStrength;
// Insert data to QDataItem. We have no ownership, don't delete the previous one
if (!m_cachedIsSlicingActivated) {
- m_selectedBar = item;
- m_selectedBar->dptr()->setPosition(QPoint(row, bar));
- item->d_ptr->setTranslation(modelMatrix.column(3).toVector3D());
+ m_selectedBar = &item;
+ m_selectedBar->setPosition(QPoint(row, bar));
+ item.setTranslation(modelMatrix.column(3).toVector3D());
barSelectionFound = true;
if (m_cachedSelectionMode >= ModeZoomRow) {
- item->d_ptr->setTranslation(modelMatrix.column(3).toVector3D());
- m_sliceSelection->append(item);
+ item.setTranslation(modelMatrix.column(3).toVector3D());
+ m_sliceSelection->append(&item);
}
}
break;
@@ -958,8 +976,8 @@ void Bars3dRenderer::drawScene(const QBarDataArray &dataArray,
barColor = Utils::vectorFromColor(m_cachedTheme.m_highlightRowColor);
lightStrength = m_cachedTheme.m_highlightLightStrength;
if (!m_cachedIsSlicingActivated && ModeZoomRow == m_cachedSelectionMode) {
- item->d_ptr->setTranslation(modelMatrix.column(3).toVector3D());
- m_sliceSelection->append(item);
+ item.setTranslation(modelMatrix.column(3).toVector3D());
+ m_sliceSelection->append(&item);
if (!m_sliceAxisP) {
// m_sliceAxisP is the axis for labels, while title comes from different axis.
m_sliceAxisP = m_controller->axisZ()->d_ptr.data();
@@ -974,8 +992,8 @@ void Bars3dRenderer::drawScene(const QBarDataArray &dataArray,
barColor = Utils::vectorFromColor(m_cachedTheme.m_highlightColumnColor);
lightStrength = m_cachedTheme.m_highlightLightStrength;
if (!m_cachedIsSlicingActivated && ModeZoomColumn == m_cachedSelectionMode) {
- item->d_ptr->setTranslation(modelMatrix.column(3).toVector3D());
- m_sliceSelection->append(item);
+ item.setTranslation(modelMatrix.column(3).toVector3D());
+ m_sliceSelection->append(&item);
if (!m_sliceAxisP) {
// m_sliceAxisP is the axis for labels, while title comes from different axis.
m_sliceAxisP = m_controller->axisX()->d_ptr.data();
@@ -1342,7 +1360,7 @@ void Bars3dRenderer::drawScene(const QBarDataArray &dataArray,
if (m_cachedIsSlicingActivated && m_updateLabels) {
// Create label textures
for (int col = 0; col < m_sliceSelection->size(); col++) {
- QBarDataItem *item = m_sliceSelection->at(col);
+ BarRenderItem *item = m_sliceSelection->at(col);
m_drawer->generateLabelTexture(item);
}
}
@@ -1360,7 +1378,7 @@ void Bars3dRenderer::drawScene(const QBarDataArray &dataArray,
// Create label textures
for (int col = 0; col < m_sliceSelection->size(); col++) {
- QBarDataItem *item = m_sliceSelection->at(col);
+ BarRenderItem *item = m_sliceSelection->at(col);
m_drawer->generateLabelTexture(item);
}
} else {
@@ -1386,18 +1404,16 @@ void Bars3dRenderer::drawScene(const QBarDataArray &dataArray,
m_cachedSelectionMode, m_labelShader,
m_labelObj, true);
#else
- // TODO: using static is bad, cannot use two barcharts at the same time!
- // TODO: Besides, doesn't m_previouslySelectedBar mechanic already cover this?
// Draw the value string followed by row label and column label
- LabelItem &labelItem = m_selectedBar->d_ptr->selectionLabel();
- if (m_previouslySelectedBar != m_selectedBar || m_updateLabels) {
+ LabelItem &labelItem = m_selectedBar->selectionLabel();
+ if (m_previouslySelectedBar != m_selectedBar || m_updateLabels || !labelItem.textureId()) {
QString labelText = m_selectedBar->label();
- if ((m_controller->axisZ()->labels().size() > m_selectedBar->dptr()->position().y())
- && (m_controller->axisX()->labels().size() > m_selectedBar->dptr()->position().x())) {
+ if ((m_controller->axisZ()->labels().size() > m_selectedBar->position().y())
+ && (m_controller->axisX()->labels().size() > m_selectedBar->position().x())) {
labelText.append(QStringLiteral(" ("));
- labelText.append(m_controller->axisX()->labels().at(m_selectedBar->dptr()->position().x()));
+ labelText.append(m_controller->axisX()->labels().at(m_selectedBar->position().x()));
labelText.append(QStringLiteral(", "));
- labelText.append(m_controller->axisZ()->labels().at(m_selectedBar->dptr()->position().y()));
+ labelText.append(m_controller->axisZ()->labels().at(m_selectedBar->position().y()));
labelText.append(QStringLiteral(")"));
//qDebug() << labelText;
}
@@ -1463,11 +1479,11 @@ void Bars3dRenderer::drawScene(const QBarDataArray &dataArray,
// TODO: Try it; draw the label here
- m_dummyBarDataItem->d_ptr->setTranslation(labelPos);
+ m_dummyBarRenderItem.setTranslation(labelPos);
const LabelItem &axisLabelItem = *m_controller->axisX()->d_ptr->labelItems().at(row);
//qDebug() << "labelPos, row" << row + 1 << ":" << labelPos << dataSet->rowLabels().at(row);
- m_drawer->drawLabel(*m_dummyBarDataItem, axisLabelItem, viewMatrix, projectionMatrix,
+ m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
QVector3D(0.0f, m_yAdjustment, zComp),
QVector3D(rotLabelX, rotLabelY, rotLabelZ),
0, m_cachedSelectionMode,
@@ -1505,11 +1521,11 @@ void Bars3dRenderer::drawScene(const QBarDataArray &dataArray,
// TODO: Try it; draw the label here
- m_dummyBarDataItem->d_ptr->setTranslation(labelPos);
+ m_dummyBarRenderItem.setTranslation(labelPos);
const LabelItem &axisLabelItem = *m_controller->axisZ()->d_ptr->labelItems().at(bar);
//qDebug() << "labelPos, col" << bar + 1 << ":" << labelPos << dataSet->columnLabels().at(bar);
- m_drawer->drawLabel(*m_dummyBarDataItem, axisLabelItem, viewMatrix, projectionMatrix,
+ m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
QVector3D(0.0f, m_yAdjustment, zComp),
QVector3D(rotLabelX, rotLabelY, rotLabelZ),
0, m_cachedSelectionMode,
@@ -1587,8 +1603,26 @@ void Bars3dRenderer::updateMeshFileName(const QString &objFileName)
loadBarMesh();
}
-void Bars3dRenderer::updateSampleSpace(int columnCount, int rowCount)
+void Bars3dRenderer::updateSampleSpace(int rowCount, int columnCount)
{
+ // Destroy old render items and reallocate new array
+ // TODO is there a way to allocate the whole array with one allocation?
+ m_renderItemArray.clear();
+ m_renderItemArray.resize(rowCount);
+ for (int i = 0; i < rowCount; i++) {
+ m_renderItemArray[i].resize(columnCount);
+ for (int j = 0; j < columnCount; j++)
+ m_renderItemArray[i][j].setRenderer(this);
+ }
+
+ m_dataWindowChanged = true;
+
+ // Force update for selection related items
+ m_sliceAxisP = 0;
+ m_sliceTitleItem = 0;
+ if (m_sliceSelection)
+ m_sliceSelection->clear();
+
m_cachedColumnCount = columnCount;
m_cachedRowCount = rowCount;
// TODO: Invent "idiotproof" max scene size formula..
@@ -1639,8 +1673,13 @@ void Bars3dRenderer::updateSelectionMode(SelectionMode mode)
m_cachedSelectionMode = mode;
// Create zoom selection if there isn't one
- if (mode >= ModeZoomRow && !m_sliceSelection)
- m_sliceSelection = new QBarDataRow;
+ if (mode >= ModeZoomRow && !m_sliceSelection) {
+ m_sliceSelection = new QList<BarRenderItem *>;
+ if (mode == ModeZoomRow)
+ m_sliceSelection->reserve(m_cachedRowCount);
+ else
+ m_sliceSelection->reserve(m_cachedColumnCount);
+ }
}
void Bars3dRenderer::updateFont(const QFont &font)
diff --git a/src/datavis3d/engine/bars3drenderer_p.h b/src/datavis3d/engine/bars3drenderer_p.h
index 3a1bc515..2f56ef62 100644
--- a/src/datavis3d/engine/bars3drenderer_p.h
+++ b/src/datavis3d/engine/bars3drenderer_p.h
@@ -63,6 +63,7 @@
#include "datavis3dglobal_p.h"
#include "bars3dcontroller_p.h"
#include "qbardataproxy.h"
+#include "barrenderitem_p.h"
//#define DISPLAY_RENDER_SPEED
@@ -114,9 +115,9 @@ private:
// Internal state
bool m_hasNegativeValues;
- QBarDataItem *m_selectedBar; // TODO: Does this need to be member variable?
- QBarDataItem *m_previouslySelectedBar;
- QBarDataRow *m_sliceSelection;
+ BarRenderItem *m_selectedBar; // TODO: Does this need to be member variable?
+ BarRenderItem *m_previouslySelectedBar;
+ QList<BarRenderItem *> *m_sliceSelection;
QAbstractAxisPrivate *m_sliceAxisP; // not owned
const LabelItem *m_sliceTitleItem; // not owned
GLint m_tickCount;
@@ -162,7 +163,11 @@ private:
bool m_hasHeightAdjustmentChanged;
QPair<GLfloat,GLfloat> m_limits;
- QBarDataItem *m_dummyBarDataItem;
+ BarRenderItem m_dummyBarRenderItem;
+ QBarDataProxy *m_dataProxy; // Only valid during render
+
+ BarRenderItemArray m_renderItemArray;
+ bool m_dataWindowChanged;
#ifdef DISPLAY_RENDER_SPEED
bool m_isFirstFrame;
@@ -174,7 +179,7 @@ public:
explicit Bars3dRenderer(Bars3dController *controller);
~Bars3dRenderer();
- void render(const QBarDataArray &dataArray, CameraHelper *camera,
+ void render(QBarDataProxy *dataProxy, bool valuesDirty, CameraHelper *camera,
const LabelItem &xLabel, const LabelItem &yLabel, const LabelItem &zLabel,
const GLuint defaultFboHandle = 0);
@@ -190,7 +195,7 @@ public slots:
void updateSelectionMode(SelectionMode newMode);
void updateSlicingActive(bool isSlicing);
void updateLimits(QPair<GLfloat, GLfloat> newLimits);
- void updateSampleSpace(int columnCount, int rowCount);
+ void updateSampleSpace(int rowCount, int columnCount);
void updateZoomLevel(int newZoomLevel);
void updateFont(const QFont &font);
void updateLabelTransparency(LabelTransparency transparency);
@@ -214,7 +219,7 @@ private:
void initializeOpenGL();
void drawSlicedScene(CameraHelper *camera,
const LabelItem &xLabel, const LabelItem &yLabel, const LabelItem &zLabel);
- void drawScene(const QBarDataArray &dataArray, CameraHelper *camera, const GLuint defaultFboHandle);
+ void drawScene(CameraHelper *camera, const GLuint defaultFboHandle);
void handleResize();
void loadBarMesh();
@@ -236,6 +241,8 @@ private:
Bars3dController::SelectionType isSelected(GLint row, GLint bar);
Q_DISABLE_COPY(Bars3dRenderer)
+
+ friend class BarRenderItem;
};
diff --git a/src/datavis3d/engine/drawer.cpp b/src/datavis3d/engine/drawer.cpp
index b5a59607..675848b0 100644
--- a/src/datavis3d/engine/drawer.cpp
+++ b/src/datavis3d/engine/drawer.cpp
@@ -46,7 +46,6 @@
#include "camerahelper_p.h"
#include "utils_p.h"
#include "texturehelper_p.h"
-#include "qabstractdataitem_p.h"
#include <QMatrix4x4>
#include <qmath.h>
@@ -162,7 +161,7 @@ void Drawer::drawObject(ShaderHelper *shader, ObjectHelper *object, GLuint textu
glBindTexture(GL_TEXTURE_2D, *oldTexId);
}
-void Drawer::drawLabel(const QAbstractDataItem &item, const LabelItem &labelItem,
+void Drawer::drawLabel(const AbstractRenderItem &item, const LabelItem &labelItem,
const QMatrix4x4 &viewmatrix, const QMatrix4x4 &projectionmatrix,
const QVector3D &positionComp, const QVector3D &rotation,
GLfloat itemHeight, SelectionMode mode,
@@ -193,19 +192,19 @@ void Drawer::drawLabel(const QAbstractDataItem &item, const LabelItem &labelItem
}
case LabelMid: {
// Use this for positioning with absolute item y position value
- yPosition = item.d_ptr->translation().y();
+ yPosition = item.translation().y();
break;
}
case LabelHigh: {
// TODO: Fix this. Can't seem to get it right (if ok with positive-only bars, doesn't look good on +- and vice versa)
- yPosition = item.d_ptr->translation().y() + itemHeight / 2.0f;
+ yPosition = item.translation().y() + itemHeight / 2.0f;
break;
}
case LabelOver: {
float mod = 0.1f;
if (itemHeight < 0)
mod = -0.1f;
- yPosition = item.d_ptr->translation().y() - (positionComp.y() / 2.0f - 0.2f)
+ yPosition = item.translation().y() - (positionComp.y() / 2.0f - 0.2f)
+ itemHeight + mod;
break;
}
@@ -259,11 +258,11 @@ void Drawer::drawLabel(const QAbstractDataItem &item, const LabelItem &labelItem
}
if (position < LabelBottom) {
- xPosition = item.d_ptr->translation().x();
+ xPosition = item.translation().x();
if (useDepth)
- zPosition = item.d_ptr->translation().z();
+ zPosition = item.translation().z();
else if (ModeZoomColumn == mode)
- xPosition = -(item.d_ptr->translation().z()) + positionComp.z(); // flip first to left
+ xPosition = -(item.translation().z()) + positionComp.z(); // flip first to left
}
// Position label
@@ -295,9 +294,9 @@ void Drawer::drawLabel(const QAbstractDataItem &item, const LabelItem &labelItem
drawObject(shader, object, labelItem.textureId());
}
-void Drawer::generateLabelTexture(QAbstractDataItem *item)
+void Drawer::generateLabelTexture(AbstractRenderItem *item)
{
- LabelItem &labelItem = item->d_ptr->labelItem();
+ LabelItem &labelItem = item->labelItem();
generateLabelItem(labelItem, item->label());
}
diff --git a/src/datavis3d/engine/drawer_p.h b/src/datavis3d/engine/drawer_p.h
index e822d79f..0657da0c 100644
--- a/src/datavis3d/engine/drawer_p.h
+++ b/src/datavis3d/engine/drawer_p.h
@@ -56,7 +56,7 @@
#include "q3dbars.h"
#include "theme_p.h"
#include "labelitem_p.h"
-#include "qabstractdataitem.h"
+#include "abstractrenderitem_p.h"
#include <QFont>
QT_DATAVIS3D_BEGIN_NAMESPACE
@@ -82,7 +82,7 @@ public:
void drawObject(ShaderHelper *shader, ObjectHelper *object, GLuint textureId = 0,
GLuint depthTextureId = 0);
- void drawLabel(const QAbstractDataItem &item, const LabelItem &label,
+ void drawLabel(const AbstractRenderItem &item, const LabelItem &label,
const QMatrix4x4 &viewmatrix, const QMatrix4x4 &projectionmatrix,
const QVector3D &positionComp, const QVector3D &rotation, GLfloat maxHeight,
SelectionMode mode, ShaderHelper *shader, ObjectHelper *object,
@@ -91,7 +91,7 @@ public:
LabelPosition position = LabelOver,
Qt::AlignmentFlag alignment = Qt::AlignCenter);
- void generateLabelTexture(QAbstractDataItem *item);
+ void generateLabelTexture(AbstractRenderItem *item);
void generateLabelItem(LabelItem &item, const QString &text);
Q_SIGNALS:
diff --git a/src/datavis3d/engine/maps3dcontroller.cpp b/src/datavis3d/engine/maps3dcontroller.cpp
index 8df4b53e..81edf0b2 100644
--- a/src/datavis3d/engine/maps3dcontroller.cpp
+++ b/src/datavis3d/engine/maps3dcontroller.cpp
@@ -51,8 +51,7 @@
#include "theme_p.h"
#include "utils_p.h"
#include "drawer_p.h"
-#include "qbardataitem.h" // TODO change to mapdataitem?
-#include "qabstractdataitem_p.h"
+#include "barrenderitem_p.h" // TODO change to maprenderitem?
#include <QOpenGLFunctions>
#include <QMatrix4x4>
@@ -838,14 +837,14 @@ void Maps3DController::drawScene(const GLuint defaultFboHandle)
}
#ifndef DISPLAY_FULL_DATA_ON_SELECTION
// Draw just the value string of the selected bar
- QBarDataItem dummyItem; // TODO temporary solution
+ BarRenderItem dummyItem; // TODO temporary solution
dummyItem.setValue(m_selectedBar->d_ptr->value());
if (prevItem != m_selectedBar || m_updateLabels) {
m_drawer->generateLabelTexture(&dummyItem);
prevItem = m_selectedBar;
}
- m_drawer->drawLabel(dummyItem, dummyItem.d_ptr->labelItem(),
+ m_drawer->drawLabel(dummyItem, dummyItem.labelItem(),
viewMatrix, projectionMatrix,
QVector3D(0.0f, m_yAdjustment, zComp),
QVector3D(0.0f, 0.0f, 0.0f),