From 5a51d06ec8f0210f51e65abfde9f868ab7bfa8ef Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 25 Aug 2014 13:16:04 +0300 Subject: Add alpha multiplier to QCustom3DVolume api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I856c4166513f6d6f7b73fd52bc46d52ab1b8fdff Reviewed-by: Tomi Korpipää Reviewed-by: Mika Salmela --- examples/datavisualization/volumetric/main.cpp | 41 +++++++++++++++----- .../datavisualization/volumetric/volumetric.cpp | 44 +++++++++++++++++++--- examples/datavisualization/volumetric/volumetric.h | 4 ++ 3 files changed, 74 insertions(+), 15 deletions(-) (limited to 'examples/datavisualization') diff --git a/examples/datavisualization/volumetric/main.cpp b/examples/datavisualization/volumetric/main.cpp index 5a90070e..84062969 100644 --- a/examples/datavisualization/volumetric/main.cpp +++ b/examples/datavisualization/volumetric/main.cpp @@ -36,16 +36,18 @@ int main(int argc, char **argv) QWidget *container = QWidget::createWindowContainer(graph); QSize screenSize = graph->screen()->size(); - container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.5)); + container->setMinimumSize(QSize(screenSize.width() / 3, screenSize.height() / 3)); container->setMaximumSize(screenSize); container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); container->setFocusPolicy(Qt::StrongFocus); - QWidget *widget = new QWidget; + QWidget *widget = new QWidget(); QHBoxLayout *hLayout = new QHBoxLayout(widget); QVBoxLayout *vLayout = new QVBoxLayout(); + QVBoxLayout *vLayout2 = new QVBoxLayout(); hLayout->addWidget(container, 1); hLayout->addLayout(vLayout); + hLayout->addLayout(vLayout2); widget->setWindowTitle(QStringLiteral("Volumetric Object Example")); @@ -122,10 +124,17 @@ int main(int argc, char **argv) sliceImageYLabel->setScaledContents(true); sliceImageZLabel->setScaledContents(true); - vLayout->addWidget(fpsCheckBox); - vLayout->addWidget(fpsLabel); - vLayout->addWidget(textureDetailGroupBox); - vLayout->addWidget(colorTableCheckBox); + QSlider *alphaMultiplierSlider = new QSlider(Qt::Horizontal, widget); + alphaMultiplierSlider->setMinimum(0); + alphaMultiplierSlider->setMaximum(139); + alphaMultiplierSlider->setValue(100); + alphaMultiplierSlider->setEnabled(true); + QLabel *alphaMultiplierLabel = new QLabel(QStringLiteral("Alpha multiplier: 1.0")); + + QCheckBox *preserveOpacityCheckBox = new QCheckBox(widget); + preserveOpacityCheckBox->setText(QStringLiteral("Preserve opacity")); + preserveOpacityCheckBox->setChecked(true); + vLayout->addWidget(sliceXCheckBox); vLayout->addWidget(sliceXSlider); vLayout->addWidget(sliceImageXLabel); @@ -135,6 +144,13 @@ int main(int argc, char **argv) vLayout->addWidget(sliceZCheckBox); vLayout->addWidget(sliceZSlider); vLayout->addWidget(sliceImageZLabel, 1, Qt::AlignTop); + vLayout2->addWidget(fpsCheckBox); + vLayout2->addWidget(fpsLabel); + vLayout2->addWidget(textureDetailGroupBox); + vLayout2->addWidget(colorTableCheckBox); + vLayout2->addWidget(alphaMultiplierLabel); + vLayout2->addWidget(alphaMultiplierSlider); + vLayout2->addWidget(preserveOpacityCheckBox, 1, Qt::AlignTop); VolumetricModifier *modifier = new VolumetricModifier(graph); modifier->setFpsLabel(fpsLabel); @@ -142,6 +158,7 @@ int main(int argc, char **argv) modifier->setHighDetailRB(highDetailRB); modifier->setSliceSliders(sliceXSlider, sliceYSlider, sliceZSlider); modifier->setSliceLabels(sliceImageXLabel, sliceImageYLabel, sliceImageZLabel); + modifier->setAlphaMultiplierLabel(alphaMultiplierLabel); QObject::connect(fpsCheckBox, &QCheckBox::stateChanged, modifier, &VolumetricModifier::setFpsMeasurement); @@ -157,14 +174,18 @@ int main(int argc, char **argv) &VolumetricModifier::adjustSliceY); QObject::connect(sliceZSlider, &QSlider::valueChanged, modifier, &VolumetricModifier::adjustSliceZ); - QObject::connect(lowDetailRB, &QRadioButton::toggled, modifier, + QObject::connect(lowDetailRB, &QRadioButton::toggled, modifier, &VolumetricModifier::toggleLowDetail); - QObject::connect(mediumDetailRB, &QRadioButton::toggled, modifier, + QObject::connect(mediumDetailRB, &QRadioButton::toggled, modifier, &VolumetricModifier::toggleMediumDetail); - QObject::connect(highDetailRB, &QRadioButton::toggled, modifier, + QObject::connect(highDetailRB, &QRadioButton::toggled, modifier, &VolumetricModifier::toggleHighDetail); - QObject::connect(colorTableCheckBox, &QCheckBox::stateChanged, modifier, + QObject::connect(colorTableCheckBox, &QCheckBox::stateChanged, modifier, &VolumetricModifier::changeColorTable); + QObject::connect(preserveOpacityCheckBox, &QCheckBox::stateChanged, modifier, + &VolumetricModifier::setPreserveOpacity); + QObject::connect(alphaMultiplierSlider, &QSlider::valueChanged, modifier, + &VolumetricModifier::adjustAlphaMultiplier); widget->show(); return app.exec(); diff --git a/examples/datavisualization/volumetric/volumetric.cpp b/examples/datavisualization/volumetric/volumetric.cpp index a553ccf8..56f02dcb 100644 --- a/examples/datavisualization/volumetric/volumetric.cpp +++ b/examples/datavisualization/volumetric/volumetric.cpp @@ -80,7 +80,7 @@ VolumetricModifier::VolumetricModifier(Q3DScatter *scatter) // Both tables have a fully transparent colors to fill outer portions of the volume. // The primary color table. - // The first visible layer, red, is somewhat transparent. Rest of to colors are opaque. + // The top two layers are transparent. m_colorTable1.resize(colorTableSize); m_colorTable2.resize(colorTableSize); @@ -88,9 +88,9 @@ VolumetricModifier::VolumetricModifier(Q3DScatter *scatter) if (i < cutOffColorIndex) m_colorTable1[i] = qRgba(0, 0, 0, 0); else if (i < 60) - m_colorTable1[i] = qRgba((i * 2) + 120, 0, 0, 20); + m_colorTable1[i] = qRgba((i * 2) + 120, 0, 0, 15); else if (i < 120) - m_colorTable1[i] = qRgba(0, ((i - 60) * 2) + 120, 0, 255); + m_colorTable1[i] = qRgba(0, ((i - 60) * 2) + 120, 0, 50); else if (i < 180) m_colorTable1[i] = qRgba(0, 0, ((i - 120) * 2) + 120, 255); else @@ -98,14 +98,15 @@ VolumetricModifier::VolumetricModifier(Q3DScatter *scatter) } // The alternate color table. - // The first visible layer is a thin single color, and rest of the volume uses a smooth gradient. + // The first visible layer is a thin opaque color, and rest of the volume uses a smooth + // transparent gradient. for (int i = 1; i < colorTableSize; i++) { if (i < cutOffColorIndex) m_colorTable2[i] = qRgba(0, 0, 0, 0); else if (i < cutOffColorIndex + 4) m_colorTable2[i] = qRgba(75, 150, 0, 255); else - m_colorTable2[i] = qRgba(i, 0, 255 - i, 255); + m_colorTable2[i] = qRgba(i, 0, 255 - i, i); } m_volumeItem->setColorTable(m_colorTable1); @@ -167,6 +168,11 @@ void VolumetricModifier::setSliceLabels(QLabel *xLabel, QLabel *yLabel, QLabel * adjustSliceZ(m_sliceSliderZ->value()); } +void VolumetricModifier::setAlphaMultiplierLabel(QLabel *label) +{ + m_alphaMultiplierLabel = label; +} + void VolumetricModifier::sliceX(int enabled) { if (m_volumeItem) @@ -322,6 +328,34 @@ void VolumetricModifier::changeColorTable(int enabled) adjustSliceZ(m_sliceSliderZ->value()); } +void VolumetricModifier::setPreserveOpacity(bool enabled) +{ + m_volumeItem->setPreserveOpacity(enabled); + + // Rerender image labels + adjustSliceX(m_sliceSliderX->value()); + adjustSliceY(m_sliceSliderY->value()); + adjustSliceZ(m_sliceSliderZ->value()); +} + +void VolumetricModifier::adjustAlphaMultiplier(int value) +{ + float mult; + if (value > 100) + mult = float(value - 99) / 2.0f; + else + mult = float(value) / float(500 - value * 4); + m_volumeItem->setAlphaMultiplier(mult); + QString labelFormat = QStringLiteral("Alpha multiplier: %1"); + m_alphaMultiplierLabel->setText(labelFormat.arg( + QString::number(m_volumeItem->alphaMultiplier(), 'f', 3))); + + // Rerender image labels + adjustSliceX(m_sliceSliderX->value()); + adjustSliceY(m_sliceSliderY->value()); + adjustSliceZ(m_sliceSliderZ->value()); +} + int VolumetricModifier::createVolume(int textureSize, int startIndex, int count, QVector *textureData) { diff --git a/examples/datavisualization/volumetric/volumetric.h b/examples/datavisualization/volumetric/volumetric.h index eb8a4172..497506ad 100644 --- a/examples/datavisualization/volumetric/volumetric.h +++ b/examples/datavisualization/volumetric/volumetric.h @@ -41,6 +41,7 @@ public: void setMediumDetailRB(QRadioButton *button); void setHighDetailRB(QRadioButton *button); void setSliceLabels(QLabel *xLabel, QLabel *yLabel, QLabel *zLabel); + void setAlphaMultiplierLabel(QLabel *label); public slots: void sliceX(int enabled); @@ -58,6 +59,8 @@ public slots: void setFpsMeasurement(bool enabled); void setSliceSliders(QSlider *sliderX, QSlider *sliderY, QSlider *sliderZ); void changeColorTable(int enabled); + void setPreserveOpacity(bool enabled); + void adjustAlphaMultiplier(int value); private: @@ -86,6 +89,7 @@ private: QLabel *m_sliceLabelX; QLabel *m_sliceLabelY; QLabel *m_sliceLabelZ; + QLabel *m_alphaMultiplierLabel; }; #endif -- cgit v1.2.3