forked from Rsnelllenberg/VolumeProjectorPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDVRViewPlugin.cpp
More file actions
472 lines (382 loc) · 17.6 KB
/
Copy pathDVRViewPlugin.cpp
File metadata and controls
472 lines (382 loc) · 17.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#include "DVRViewPlugin.h"
#include "DVRWidget.h"
#include <DVRVolumeData/VolumeData.h>
#include "GlobalSettingsAction.h"
#include <DatasetsMimeData.h>
#include <QLabel>
#include <QDebug>
#include <random>
#include <numeric>
#include <vector>
Q_PLUGIN_METADATA(IID "studio.manivault.DVRViewPlugin")
using namespace mv;
// -----------------------------------------------------------------------------
// DVRViewPlugin
// -----------------------------------------------------------------------------
DVRViewPlugin::DVRViewPlugin(const PluginFactory* factory) :
ViewPlugin(factory),
_currentDimensions({0, 1}),
_dropWidget(nullptr),
_DVRWidget(new DVRWidget()),
_settingsAction(this, "Settings Action")
{
setObjectName("DVR OpenGL view");
// Instantiate new drop widget, setting the DVR Widget as its parent
// the parent widget hat to setAcceptDrops(true) for the drop widget to work
_dropWidget = new DropWidget(_DVRWidget);
// Set the drop indicator widget (the widget that indicates that the view is eligible for data dropping)
_dropWidget->setDropIndicatorWidget(new DropWidget::DropIndicatorWidget(&getWidget(), "No data loaded", "Drag the DVRViewData from the data hierarchy here"));
// Initialize the drop regions
_dropWidget->initialize([this](const QMimeData* mimeData) -> DropWidget::DropRegions {
// A drop widget can contain zero or more drop regions
DropWidget::DropRegions dropRegions;
const auto datasetsMimeData = dynamic_cast<const DatasetsMimeData*>(mimeData);
if (datasetsMimeData == nullptr)
return dropRegions;
if (datasetsMimeData->getDatasets().count() > 1)
return dropRegions;
// Gather information to generate appropriate drop regions
const auto dataset = datasetsMimeData->getDatasets().first();
const auto datasetGuiName = dataset->getGuiName();
const auto datasetId = dataset->getId();
const auto dataType = dataset->getDataType();
const auto dataTypes = DataTypes({ VolumeType, ImageType, PointType });
if (!dataTypes.contains(dataType)) {
dropRegions << new DropWidget::DropRegion(this, "Incompatible data", "This type of data is not supported it only supports Volume Data", "exclamation-circle", false);
return dropRegions;
}
if (dataType == VolumeType) {
if (datasetId == getVolumeDataSetID()) {
dropRegions << new DropWidget::DropRegion(this, "Warning", "Data already loaded", "exclamation-circle", false);
}
else {
auto candidateDataset = mv::data().getDataset<Volumes>(datasetId);
dropRegions << new DropWidget::DropRegion(this, "Volumes", QString("Visualize %1 as a Volume").arg(datasetGuiName), "map-marker-alt", true, [this, candidateDataset]() {
loadData({ candidateDataset });
});
}
}
else if (dataType == ImageType) {
if (datasetId == getTfDatasetID()) {
dropRegions << new DropWidget::DropRegion(this, "Warning", "Data already loaded", "exclamation-circle", false);
}
else {
auto candidateDataset = mv::data().getDataset<Images>(datasetId);
dropRegions << new DropWidget::DropRegion(this, "Images", QString("Pass %1 along as the transfer function").arg(datasetGuiName), "map-marker-alt", true, [this, candidateDataset]() {
loadTfData(candidateDataset);
});
}
if (datasetId == getMaterialTransitionDataSetID()) {
dropRegions << new DropWidget::DropRegion(this, "Warning", "Data already loaded", "exclamation-circle", false);
}
else {
auto candidateDataset = mv::data().getDataset<Images>(datasetId);
dropRegions << new DropWidget::DropRegion(this, "Images", QString("Pass %1 along as the material transition texture").arg(datasetGuiName), "map-marker-alt", true, [this, candidateDataset]() {
loadMaterialTransitionData(candidateDataset);
});
}
if (datasetId == getMaterialPositionsDataSetID()) {
dropRegions << new DropWidget::DropRegion(this, "Warning", "Data already loaded", "exclamation-circle", false);
}
else {
auto candidateDataset = mv::data().getDataset<Images>(datasetId);
dropRegions << new DropWidget::DropRegion(this, "Images", QString("Pass %1 along as the material positions texture").arg(datasetGuiName), "map-marker-alt", true, [this, candidateDataset]() {
loadMaterialPositionsData(candidateDataset);
});
}
}
else if (dataType == PointType) {
if (datasetId == getReducedPosDataSetID()) {
dropRegions << new DropWidget::DropRegion(this, "Warning", "Data already loaded", "exclamation-circle", false);
}
else {
auto candidateDataset = mv::data().getDataset<Points>(datasetId);
if (candidateDataset->getNumDimensions() == 2) {
dropRegions << new DropWidget::DropRegion(this, "Points", QString("Pass %1 along as dimension reduced point locations").arg(datasetGuiName), "map-marker-alt", true, [this, candidateDataset]() {
loadReducedPosData({ candidateDataset });
});
}
else {
dropRegions << new DropWidget::DropRegion(this, "Incompatible data", "This type of data is not supported it only supports 2D data", "exclamation-circle", false);
}
}
}
return dropRegions;
});
// update data when data set changed
connect(&_volumeDataset, &Dataset<Points>::dataChanged, this, &DVRViewPlugin::updateVolumeData);
connect(&_tfTexture, &Dataset<Images>::dataChanged, this, &DVRViewPlugin::updateTfData);
connect(&_reducedPosDataset, &Dataset<Points>::dataChanged, this, &DVRViewPlugin::updateReducedPosData);
connect(&_materialTransitionTexture, &Dataset<Images>::dataChanged, this, &DVRViewPlugin::updateMaterialTransitionData);
connect(&_materialPositionTexture, &Dataset<Images>::dataChanged, this, &DVRViewPlugin::updateMaterialPositionsData); // New connection
// update settings UI when data set changed
connect(&_volumeDataset, &Dataset<Points>::changed, this, [this]() {
const auto enabled = _volumeDataset.isValid();
auto& nameString = _settingsAction.getDatasetNameAction();
auto& renderMode = _settingsAction.getRenderModeAction();
auto& mipDimension = _settingsAction.getMIPDimensionPickerAction();
auto& xDimPicker = _settingsAction.getXDimClippingPlaneAction();
auto& yDimPicker = _settingsAction.getYDimClippingPlaneAction();
auto& zDimPicker = _settingsAction.getZDimClippingPlaneAction();
auto& usecustomRenderSpace = _settingsAction.getUseCustomRenderSpaceAction();
auto& xRenderSize = _settingsAction.getXRenderSizeAction();
auto& yRenderSize = _settingsAction.getYRenderSizeAction();
auto& zRenderSize = _settingsAction.getZRenderSizeAction();
renderMode.setEnabled(enabled);
xDimPicker.setEnabled(enabled);
yDimPicker.setEnabled(enabled);
zDimPicker.setEnabled(enabled);
usecustomRenderSpace.setEnabled(enabled);
xRenderSize.setEnabled(enabled);
yRenderSize.setEnabled(enabled);
zRenderSize.setEnabled(enabled);
if (!enabled)
return;
nameString.setString(_volumeDataset->getGuiName());
auto parent = _volumeDataset->getParent();
if (parent->getDataType() == PointType) {
auto points = mv::Dataset<Points>(parent);
mipDimension.setPointsDataset(points);
}
else {
qCritical() << "DVRViewPlugin::updateSettings: Parent data set is not a point data set";
}
});
}
void DVRViewPlugin::init()
{
// Create layout
auto layout = new QVBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(_DVRWidget, 100);
// Apply the layout
getWidget().setLayout(layout);
addDockingAction(&_settingsAction);
_DVRWidget->installEventFilter(this);
// Update the data when the scatter plot widget is initialized
connect(_DVRWidget, &DVRWidget::initialized, this, []() { qDebug() << "DVRWidget is initialized."; } );
}
void DVRViewPlugin::updateRenderSettings()
{
if (_settingsAction.getRenderModeAction().getCurrentText() == "1D MIP") {
_settingsAction.getMIPDimensionPickerAction().setEnabled(true);
}
else {
_settingsAction.getMIPDimensionPickerAction().setEnabled(false);
}
if (_settingsAction.getUseCustomRenderSpaceAction().isChecked()) {
_settingsAction.getXRenderSizeAction().setEnabled(true);
_settingsAction.getYRenderSizeAction().setEnabled(true);
_settingsAction.getZRenderSizeAction().setEnabled(true);
}
else {
_settingsAction.getXRenderSizeAction().setEnabled(false);
_settingsAction.getYRenderSizeAction().setEnabled(false);
_settingsAction.getZRenderSizeAction().setEnabled(false);
}
_DVRWidget->setClippingPlaneBoundery(_settingsAction.getXDimClippingPlaneAction().getRange().getMinimum(),
_settingsAction.getXDimClippingPlaneAction().getRange().getMaximum(),
_settingsAction.getYDimClippingPlaneAction().getRange().getMinimum(),
_settingsAction.getYDimClippingPlaneAction().getRange().getMaximum(),
_settingsAction.getZDimClippingPlaneAction().getRange().getMinimum(),
_settingsAction.getZDimClippingPlaneAction().getRange().getMaximum());
_DVRWidget->setUseCustomRenderSpace(_settingsAction.getUseCustomRenderSpaceAction().isChecked());
_DVRWidget->setRenderSpace(_settingsAction.getXRenderSizeAction().getValue(),
_settingsAction.getYRenderSizeAction().getValue(),
_settingsAction.getZRenderSizeAction().getValue());
_DVRWidget->setStepSize(_settingsAction.getStepSizeAction().getValue());
_DVRWidget->setRenderMode(_settingsAction.getRenderModeAction().getCurrentText());
_DVRWidget->setMIPDimension(_settingsAction.getMIPDimensionPickerAction().getCurrentDimensionIndex());
_DVRWidget->setUseClutterRemover(_settingsAction.getUseClutterRemoverAction().isChecked());
_DVRWidget->setUseShading(_settingsAction.getUseShaderAction().isChecked());
_DVRWidget->setRenderCubeSize(_settingsAction.getRenderCubeSizeAction().getValue());
_DVRWidget->update();
}
void DVRViewPlugin::updateVolumeData()
{
if (_volumeDataset.isValid()) {
std::vector<std::uint32_t> dimensionIndices = generateSequence(_volumeDataset->getComponentsPerVoxel()); // TODO remove the max 8 componest part later just there for now to avoid memory crashes
_DVRWidget->setData(_volumeDataset, dimensionIndices);
}
else {
qDebug() << "DVRViewPlugin::updateVolumeData: No data to update";
}
}
void DVRViewPlugin::updateTfData()
{
if (_tfTexture.isValid()) {
_DVRWidget->setTfTexture(_tfTexture);
}
else {
qDebug() << "DVRViewPlugin::updateTfData: No data to update";
}
}
void DVRViewPlugin::updateReducedPosData()
{
if (_reducedPosDataset.isValid()) {
_DVRWidget->setReducedPosData(_reducedPosDataset);
}
else {
qDebug() << "DVRViewPlugin::updateReducedPosData: No data to update";
}
}
void DVRViewPlugin::updateMaterialTransitionData()
{
if (_materialTransitionTexture.isValid()) {
_DVRWidget->setMaterialTransitionTexture(_materialTransitionTexture);
}
else {
qDebug() << "DVRViewPlugin::updateMaterialTransitionData: No data to update";
}
}
void DVRViewPlugin::updateMaterialPositionsData()
{
if (_materialPositionTexture.isValid()) {
_DVRWidget->setMaterialPositionTexture(_materialPositionTexture);
}
else {
qDebug() << "DVRViewPlugin::updateMaterialPositionsData: No data to update";
}
}
void DVRViewPlugin::loadData(const mv::Dataset<Points>& dataset)
{
_volumeDataset = dataset;
updateShowDropIndicator();
updateVolumeData();
}
void DVRViewPlugin::loadTfData(const mv::Dataset<Images>& dataset)
{
_tfTexture = dataset;
updateShowDropIndicator();
updateTfData();
}
void DVRViewPlugin::loadReducedPosData(const mv::Dataset<Points>& dataset)
{
_reducedPosDataset = dataset;
updateShowDropIndicator();
updateReducedPosData();
}
void DVRViewPlugin::loadMaterialTransitionData(const mv::Dataset<Images>& datasets)
{
_materialTransitionTexture = datasets;
updateShowDropIndicator();
updateMaterialTransitionData();
}
void DVRViewPlugin::loadMaterialPositionsData(const mv::Dataset<Images>& datasets)
{
_materialPositionTexture = datasets;
updateShowDropIndicator();
updateMaterialPositionsData();
}
void DVRViewPlugin::updateShowDropIndicator()
{
if (_tfTexture.isValid() && _volumeDataset.isValid() && _reducedPosDataset.isValid() && _materialTransitionTexture.isValid() && _materialPositionTexture.isValid()) {
_dropWidget->setShowDropIndicator(false);
}
}
QString DVRViewPlugin::getVolumeDataSetID() const
{
if (_volumeDataset.isValid())
return _volumeDataset->getId();
else
return QString{};
}
QString DVRViewPlugin::getTfDatasetID() const
{
if (_tfTexture.isValid())
return _tfTexture->getId();
else
return QString{};
}
QString DVRViewPlugin::getReducedPosDataSetID() const
{
if (_reducedPosDataset.isValid())
return _reducedPosDataset->getId();
else
return QString{};
}
QString DVRViewPlugin::getMaterialTransitionDataSetID() const
{
if (_materialTransitionTexture.isValid())
return _materialTransitionTexture->getId();
else
return QString{};
}
QString DVRViewPlugin::getMaterialPositionsDataSetID() const
{
if (_materialPositionTexture.isValid())
return _materialPositionTexture->getId();
else
return QString{};
}
std::vector<std::uint32_t> DVRViewPlugin::generateSequence(int n) {
std::vector<std::uint32_t> sequence(n);
std::iota(sequence.begin(), sequence.end(), 0);
return sequence;
}
// -----------------------------------------------------------------------------
// DVRViewPluginFactory
// -----------------------------------------------------------------------------
ViewPlugin* DVRViewPluginFactory::produce()
{
return new DVRViewPlugin(this);
}
DVRViewPluginFactory::DVRViewPluginFactory() :
ViewPluginFactory(),
_statusBarAction(nullptr),
_statusBarPopupGroupAction(this, "Popup Group"),
_statusBarPopupAction(this, "Popup")
{
setIconByName("braille");
}
void DVRViewPluginFactory::initialize()
{
ViewPluginFactory::initialize();
// Create an instance of our GlobalSettingsAction (derived from PluginGlobalSettingsGroupAction) and assign it to the factory
setGlobalSettingsGroupAction(new GlobalSettingsAction(this, this));
// Configure the status bar popup action
_statusBarPopupAction.setDefaultWidgetFlags(StringAction::Label);
_statusBarPopupAction.setString("<p><b>DVR OpenGL View</b></p><p>This is an example of a plugin status bar item</p><p>A concrete example on how this status bar was created can be found <a href='https://github.com/ManiVaultStudio/ExamplePlugins/blob/master/ExampleViewOpenGL/src/DVRViewPlugin.cpp'>here</a>.</p>");
_statusBarPopupAction.setPopupSizeHint(QSize(200, 10));
_statusBarPopupGroupAction.setShowLabels(false);
_statusBarPopupGroupAction.setConfigurationFlag(WidgetAction::ConfigurationFlag::NoGroupBoxInPopupLayout);
_statusBarPopupGroupAction.addAction(&_statusBarPopupAction);
_statusBarPopupGroupAction.setWidgetConfigurationFunction([](WidgetAction* action, QWidget* widget) -> void {
auto label = widget->findChild<QLabel*>("Label");
Q_ASSERT(label != nullptr);
if (label == nullptr)
return;
label->setOpenExternalLinks(true);
});
_statusBarAction = new PluginStatusBarAction(this, "DVR View OpenGL", getKind());
// Sets the action that is shown when the status bar is clicked
_statusBarAction->setPopupAction(&_statusBarPopupGroupAction);
// Position to the right of the status bar action
_statusBarAction->setIndex(-1);
// Assign the status bar action so that it will appear on the main window status bar
setStatusBarAction(_statusBarAction);
}
mv::DataTypes DVRViewPluginFactory::supportedDataTypes() const
{
DataTypes supportedTypes;
// This example analysis plugin is compatible with points datasets
supportedTypes.append(PointType);
return supportedTypes;
}
mv::gui::PluginTriggerActions DVRViewPluginFactory::getPluginTriggerActions(const mv::Datasets& datasets) const
{
PluginTriggerActions pluginTriggerActions;
const auto getPluginInstance = [this]() -> DVRViewPlugin* {
return dynamic_cast<DVRViewPlugin*>(plugins().requestViewPlugin(getKind()));
};
const auto numberOfDatasets = datasets.count();
if (numberOfDatasets >= 1 && PluginFactory::areAllDatasetsOfTheSameType(datasets, PointType)) {
auto pluginTriggerAction = new PluginTriggerAction(const_cast<DVRViewPluginFactory*>(this), this, "Example GL", "OpenGL view example data", icon(), [this, getPluginInstance, datasets](PluginTriggerAction& pluginTriggerAction) -> void {
for (auto& dataset : datasets)
getPluginInstance()->loadData(dataset);
});
pluginTriggerActions << pluginTriggerAction;
}
return pluginTriggerActions;
}