1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Data Visualization module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include "volumetric.h"
31
32#include <QtWidgets/QApplication>
33#include <QtWidgets/QWidget>
34#include <QtWidgets/QHBoxLayout>
35#include <QtWidgets/QVBoxLayout>
36#include <QtWidgets/QRadioButton>
37#include <QtWidgets/QSlider>
38#include <QtWidgets/QCheckBox>
39#include <QtWidgets/QLabel>
40#include <QtWidgets/QGroupBox>
41#include <QtWidgets/QMessageBox>
42#include <QtGui/QScreen>
43
44int main(int argc, char **argv)
45{
46 QApplication app(argc, argv);
47 Q3DScatter *graph = new Q3DScatter();
48 QWidget *container = QWidget::createWindowContainer(window: graph);
49
50 if (!graph->hasContext()) {
51 QMessageBox msgBox;
52 msgBox.setText("Couldn't initialize the OpenGL context.");
53 msgBox.exec();
54 return -1;
55 }
56
57 QSize screenSize = graph->screen()->size();
58 container->setMinimumSize(QSize(screenSize.width() / 3, screenSize.height() / 3));
59 container->setMaximumSize(screenSize);
60 container->setSizePolicy(hor: QSizePolicy::Expanding, ver: QSizePolicy::Expanding);
61 container->setFocusPolicy(Qt::StrongFocus);
62
63 QWidget *widget = new QWidget();
64 QHBoxLayout *hLayout = new QHBoxLayout(widget);
65 QVBoxLayout *vLayout = new QVBoxLayout();
66 QVBoxLayout *vLayout2 = new QVBoxLayout();
67 hLayout->addWidget(container, stretch: 1);
68 hLayout->addLayout(layout: vLayout);
69 hLayout->addLayout(layout: vLayout2);
70
71 widget->setWindowTitle(QStringLiteral("Volumetric object example - 3D terrain"));
72
73 QCheckBox *sliceXCheckBox = new QCheckBox(widget);
74 sliceXCheckBox->setText(QStringLiteral("Slice volume on X axis"));
75 sliceXCheckBox->setChecked(false);
76 QCheckBox *sliceYCheckBox = new QCheckBox(widget);
77 sliceYCheckBox->setText(QStringLiteral("Slice volume on Y axis"));
78 sliceYCheckBox->setChecked(false);
79 QCheckBox *sliceZCheckBox = new QCheckBox(widget);
80 sliceZCheckBox->setText(QStringLiteral("Slice volume on Z axis"));
81 sliceZCheckBox->setChecked(false);
82
83 QSlider *sliceXSlider = new QSlider(Qt::Horizontal, widget);
84 sliceXSlider->setMinimum(0);
85 sliceXSlider->setMaximum(1024);
86 sliceXSlider->setValue(512);
87 sliceXSlider->setEnabled(true);
88 QSlider *sliceYSlider = new QSlider(Qt::Horizontal, widget);
89 sliceYSlider->setMinimum(0);
90 sliceYSlider->setMaximum(1024);
91 sliceYSlider->setValue(512);
92 sliceYSlider->setEnabled(true);
93 QSlider *sliceZSlider = new QSlider(Qt::Horizontal, widget);
94 sliceZSlider->setMinimum(0);
95 sliceZSlider->setMaximum(1024);
96 sliceZSlider->setValue(512);
97 sliceZSlider->setEnabled(true);
98
99 QCheckBox *fpsCheckBox = new QCheckBox(widget);
100 fpsCheckBox->setText(QStringLiteral("Show FPS"));
101 fpsCheckBox->setChecked(false);
102 QLabel *fpsLabel = new QLabel(QStringLiteral(""), widget);
103
104 QGroupBox *textureDetailGroupBox = new QGroupBox(QStringLiteral("Texture detail"));
105
106 QRadioButton *lowDetailRB = new QRadioButton(widget);
107 lowDetailRB->setText(QStringLiteral("Low (128x64x128)"));
108 lowDetailRB->setChecked(true);
109
110 QRadioButton *mediumDetailRB = new QRadioButton(widget);
111 mediumDetailRB->setText(QStringLiteral("Generating..."));
112 mediumDetailRB->setChecked(false);
113 mediumDetailRB->setEnabled(false);
114
115 QRadioButton *highDetailRB = new QRadioButton(widget);
116 highDetailRB->setText(QStringLiteral("Generating..."));
117 highDetailRB->setChecked(false);
118 highDetailRB->setEnabled(false);
119
120 QVBoxLayout *textureDetailVBox = new QVBoxLayout;
121 textureDetailVBox->addWidget(lowDetailRB);
122 textureDetailVBox->addWidget(mediumDetailRB);
123 textureDetailVBox->addWidget(highDetailRB);
124 textureDetailGroupBox->setLayout(textureDetailVBox);
125
126 QGroupBox *areaGroupBox = new QGroupBox(QStringLiteral("Show area"));
127
128 QRadioButton *areaAllRB = new QRadioButton(widget);
129 areaAllRB->setText(QStringLiteral("Whole region"));
130 areaAllRB->setChecked(true);
131
132 QRadioButton *areaMineRB = new QRadioButton(widget);
133 areaMineRB->setText(QStringLiteral("The mine"));
134 areaMineRB->setChecked(false);
135
136 QRadioButton *areaMountainRB = new QRadioButton(widget);
137 areaMountainRB->setText(QStringLiteral("The mountain"));
138 areaMountainRB->setChecked(false);
139
140 QVBoxLayout *areaVBox = new QVBoxLayout;
141 areaVBox->addWidget(areaAllRB);
142 areaVBox->addWidget(areaMineRB);
143 areaVBox->addWidget(areaMountainRB);
144 areaGroupBox->setLayout(areaVBox);
145
146 QCheckBox *colorTableCheckBox = new QCheckBox(widget);
147 colorTableCheckBox->setText(QStringLiteral("Alternate color table"));
148 colorTableCheckBox->setChecked(false);
149
150 QLabel *sliceImageXLabel = new QLabel(widget);
151 QLabel *sliceImageYLabel = new QLabel(widget);
152 QLabel *sliceImageZLabel = new QLabel(widget);
153 sliceImageXLabel->setMinimumSize(QSize(200, 100));
154 sliceImageYLabel->setMinimumSize(QSize(200, 200));
155 sliceImageZLabel->setMinimumSize(QSize(200, 100));
156 sliceImageXLabel->setMaximumSize(QSize(200, 100));
157 sliceImageYLabel->setMaximumSize(QSize(200, 200));
158 sliceImageZLabel->setMaximumSize(QSize(200, 100));
159 sliceImageXLabel->setFrameShape(QFrame::Box);
160 sliceImageYLabel->setFrameShape(QFrame::Box);
161 sliceImageZLabel->setFrameShape(QFrame::Box);
162 sliceImageXLabel->setScaledContents(true);
163 sliceImageYLabel->setScaledContents(true);
164 sliceImageZLabel->setScaledContents(true);
165
166 QSlider *alphaMultiplierSlider = new QSlider(Qt::Horizontal, widget);
167 alphaMultiplierSlider->setMinimum(0);
168 alphaMultiplierSlider->setMaximum(139);
169 alphaMultiplierSlider->setValue(100);
170 alphaMultiplierSlider->setEnabled(true);
171 QLabel *alphaMultiplierLabel = new QLabel(QStringLiteral("Alpha multiplier: 1.0"));
172
173 QCheckBox *preserveOpacityCheckBox = new QCheckBox(widget);
174 preserveOpacityCheckBox->setText(QStringLiteral("Preserve opacity"));
175 preserveOpacityCheckBox->setChecked(true);
176
177 QCheckBox *transparentGroundCheckBox = new QCheckBox(widget);
178 transparentGroundCheckBox->setText(QStringLiteral("Transparent ground"));
179 transparentGroundCheckBox->setChecked(false);
180
181 QCheckBox *useHighDefShaderCheckBox = new QCheckBox(widget);
182 useHighDefShaderCheckBox->setText(QStringLiteral("Use HD shader"));
183 useHighDefShaderCheckBox->setChecked(true);
184
185 QLabel *performanceNoteLabel =
186 new QLabel(QStringLiteral(
187 "Note: A high end graphics card is\nrecommended with the HD shader\nwhen the volume contains a lot of\ntransparent areas."));
188 performanceNoteLabel->setFrameShape(QFrame::Box);
189
190 QCheckBox *drawSliceFramesCheckBox = new QCheckBox(widget);
191 drawSliceFramesCheckBox->setText(QStringLiteral("Draw slice frames"));
192 drawSliceFramesCheckBox->setChecked(false);
193
194 vLayout->addWidget(sliceXCheckBox);
195 vLayout->addWidget(sliceXSlider);
196 vLayout->addWidget(sliceImageXLabel);
197 vLayout->addWidget(sliceYCheckBox);
198 vLayout->addWidget(sliceYSlider);
199 vLayout->addWidget(sliceImageYLabel);
200 vLayout->addWidget(sliceZCheckBox);
201 vLayout->addWidget(sliceZSlider);
202 vLayout->addWidget(sliceImageZLabel);
203 vLayout->addWidget(drawSliceFramesCheckBox, stretch: 1, alignment: Qt::AlignTop);
204 vLayout2->addWidget(fpsCheckBox);
205 vLayout2->addWidget(fpsLabel);
206 vLayout2->addWidget(textureDetailGroupBox);
207 vLayout2->addWidget(areaGroupBox);
208 vLayout2->addWidget(colorTableCheckBox);
209 vLayout2->addWidget(alphaMultiplierLabel);
210 vLayout2->addWidget(alphaMultiplierSlider);
211 vLayout2->addWidget(preserveOpacityCheckBox);
212 vLayout2->addWidget(transparentGroundCheckBox);
213 vLayout2->addWidget(useHighDefShaderCheckBox);
214 vLayout2->addWidget(performanceNoteLabel, stretch: 1, alignment: Qt::AlignTop);
215
216 VolumetricModifier *modifier = new VolumetricModifier(graph);
217 modifier->setFpsLabel(fpsLabel);
218 modifier->setMediumDetailRB(mediumDetailRB);
219 modifier->setHighDetailRB(highDetailRB);
220 modifier->setSliceSliders(sliderX: sliceXSlider, sliderY: sliceYSlider, sliderZ: sliceZSlider);
221 modifier->setSliceLabels(xLabel: sliceImageXLabel, yLabel: sliceImageYLabel, zLabel: sliceImageZLabel);
222 modifier->setAlphaMultiplierLabel(alphaMultiplierLabel);
223 modifier->setTransparentGround(transparentGroundCheckBox->isChecked());
224
225 QObject::connect(sender: fpsCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
226 slot: &VolumetricModifier::setFpsMeasurement);
227 QObject::connect(sender: sliceXCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
228 slot: &VolumetricModifier::sliceX);
229 QObject::connect(sender: sliceYCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
230 slot: &VolumetricModifier::sliceY);
231 QObject::connect(sender: sliceZCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
232 slot: &VolumetricModifier::sliceZ);
233 QObject::connect(sender: sliceXSlider, signal: &QSlider::valueChanged, receiver: modifier,
234 slot: &VolumetricModifier::adjustSliceX);
235 QObject::connect(sender: sliceYSlider, signal: &QSlider::valueChanged, receiver: modifier,
236 slot: &VolumetricModifier::adjustSliceY);
237 QObject::connect(sender: sliceZSlider, signal: &QSlider::valueChanged, receiver: modifier,
238 slot: &VolumetricModifier::adjustSliceZ);
239 QObject::connect(sender: lowDetailRB, signal: &QRadioButton::toggled, receiver: modifier,
240 slot: &VolumetricModifier::toggleLowDetail);
241 QObject::connect(sender: mediumDetailRB, signal: &QRadioButton::toggled, receiver: modifier,
242 slot: &VolumetricModifier::toggleMediumDetail);
243 QObject::connect(sender: highDetailRB, signal: &QRadioButton::toggled, receiver: modifier,
244 slot: &VolumetricModifier::toggleHighDetail);
245 QObject::connect(sender: colorTableCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
246 slot: &VolumetricModifier::changeColorTable);
247 QObject::connect(sender: preserveOpacityCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
248 slot: &VolumetricModifier::setPreserveOpacity);
249 QObject::connect(sender: transparentGroundCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
250 slot: &VolumetricModifier::setTransparentGround);
251 QObject::connect(sender: useHighDefShaderCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
252 slot: &VolumetricModifier::setUseHighDefShader);
253 QObject::connect(sender: alphaMultiplierSlider, signal: &QSlider::valueChanged, receiver: modifier,
254 slot: &VolumetricModifier::adjustAlphaMultiplier);
255 QObject::connect(sender: areaAllRB, signal: &QRadioButton::toggled, receiver: modifier,
256 slot: &VolumetricModifier::toggleAreaAll);
257 QObject::connect(sender: areaMineRB, signal: &QRadioButton::toggled, receiver: modifier,
258 slot: &VolumetricModifier::toggleAreaMine);
259 QObject::connect(sender: areaMountainRB, signal: &QRadioButton::toggled, receiver: modifier,
260 slot: &VolumetricModifier::toggleAreaMountain);
261 QObject::connect(sender: drawSliceFramesCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
262 slot: &VolumetricModifier::setDrawSliceFrames);
263
264 widget->show();
265 return app.exec();
266}
267

source code of qtdatavis3d/examples/datavisualization/volumetric/main.cpp