OGS
VtkVisTabWidget.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "VtkVisTabWidget.h"
5
6#include <vtkActor.h>
7#include <vtkImageChangeInformation.h>
8#include <vtkProperty.h>
9#include <vtkTransform.h>
10#include <vtkTransformFilter.h>
11
12#include "BaseLib/Logging.h"
18#include "VtkVisImageItem.h"
19#include "VtkVisPipelineItem.h"
20
21VtkVisTabWidget::VtkVisTabWidget(QWidget* parent /*= 0*/) : QWidget(parent)
22{
23 setupUi(this);
24
25 this->scaleZ->setValidator(new QDoubleValidator(0, 100, 8, this));
26
27 this->transX->setValidator(new QDoubleValidator(this));
28 this->transY->setValidator(new QDoubleValidator(this));
29 this->transZ->setValidator(new QDoubleValidator(this));
30
31 connect(this->vtkVisPipelineView, SIGNAL(requestViewUpdate()), this,
32 SIGNAL(requestViewUpdate()));
33
34 connect(this->vtkVisPipelineView, SIGNAL(itemSelected(VtkVisPipelineItem*)),
35 this, SLOT(setActiveItem(VtkVisPipelineItem*)));
36
37 connect(this->activeScalarComboBox,
38 SIGNAL(currentIndexChanged(const QString&)), this,
39 SLOT(SetActiveAttributeOnItem(const QString&)));
40}
41
43{
44 VtkAlgorithmProperties* props = _item->getVtkProperties();
45 const QString selected_array_name =
46 this->activeScalarComboBox->currentText();
47 props->RemoveLookupTable(selected_array_name);
48 _item->SetActiveAttribute(selected_array_name);
49}
50
52{
53 if (item)
54 {
55 _item = item;
56 transformTabWidget->setEnabled(true);
57
58 auto* transform_filter =
59 dynamic_cast<vtkTransformFilter*>(_item->transformFilter());
60 if (transform_filter) // if data set
61 {
62 actorPropertiesGroupBox->setEnabled(true);
63 vtkProperty* vtkProps =
64 static_cast<vtkActor*>(_item->actor())->GetProperty();
65 diffuseColorPickerButton->setColor(vtkProps->GetDiffuseColor());
66 visibleEdgesCheckBox->setChecked(vtkProps->GetEdgeVisibility());
67 edgeColorPickerButton->setColor(vtkProps->GetEdgeColor());
68 opacitySlider->setValue(
69 static_cast<int>(vtkProps->GetOpacity() * 100.0));
70
71 auto* transform =
72 static_cast<vtkTransform*>(transform_filter->GetTransform());
73 if (transform)
74 {
75 double scale[3];
76 transform->GetScale(scale);
77 double trans[3];
78 transform->GetPosition(trans);
79
80 // switch signals off for just filling in text-boxes after
81 // clicking on an item
82 this->scaleZ->blockSignals(true);
83 this->transX->blockSignals(true);
84 this->transY->blockSignals(true);
85 this->transZ->blockSignals(true);
86 this->scaleZ->setText(QString::number(scale[2]));
87 this->transX->setText(QString::number(trans[0] / scale[0]));
88 this->transY->setText(QString::number(trans[1] / scale[1]));
89 this->transZ->setText(QString::number(trans[2] / scale[2]));
90 this->scaleZ->blockSignals(false);
91 this->transX->blockSignals(false);
92 this->transY->blockSignals(false);
93 this->transZ->blockSignals(false);
94 // switch signals back on
95 }
97
98 // Set to last active attribute
99 QString activeAttribute = _item->GetActiveAttribute();
100 if (activeAttribute.length() > 0)
101 {
102 for (int i = 0; i < this->activeScalarComboBox->count(); i++)
103 {
104 QString itemText = this->activeScalarComboBox->itemText(i);
105 if (itemText.compare(activeAttribute) == 0)
106 {
107 this->activeScalarComboBox->setCurrentIndex(i);
108 break;
109 }
110 }
111 }
112 }
113 else // if image
114 {
115 const VtkVisImageItem* img = static_cast<VtkVisImageItem*>(_item);
116 actorPropertiesGroupBox->setEnabled(false);
117 auto* transform =
118 static_cast<vtkImageChangeInformation*>(img->transformFilter());
119 double trans[3];
120 transform->GetOriginTranslation(trans);
121 this->transX->blockSignals(true);
122 this->transY->blockSignals(true);
123 this->transZ->blockSignals(true);
124 this->transX->setText(QString::number(trans[0]));
125 this->transY->setText(QString::number(trans[1]));
126 this->transZ->setText(QString::number(trans[2]));
127 this->transX->blockSignals(false);
128 this->transY->blockSignals(false);
129 this->transZ->blockSignals(false);
130 }
131
132 this->buildProportiesDialog(item);
133
134 emit requestViewUpdate();
135 }
136 else
137 {
138 actorPropertiesGroupBox->setEnabled(false);
139 transformTabWidget->setEnabled(false);
140 this->activeScalarComboBox->clear();
141 }
142}
143
145{
146 static_cast<vtkActor*>(_item->actor())
147 ->GetProperty()
148 ->SetDiffuseColor(color.redF(), color.greenF(), color.blueF());
149
150 emit requestViewUpdate();
151}
152
154{
155 if (state == Qt::Checked)
156 {
157 static_cast<vtkActor*>(_item->actor())
158 ->GetProperty()
159 ->SetEdgeVisibility(1);
160 edgeColorPickerButton->setEnabled(true);
161 }
162 else
163 {
164 static_cast<vtkActor*>(_item->actor())
165 ->GetProperty()
166 ->SetEdgeVisibility(0);
167 edgeColorPickerButton->setEnabled(false);
168 }
169
170 emit requestViewUpdate();
171}
172
174{
175 static_cast<vtkActor*>(_item->actor())
176 ->GetProperty()
177 ->SetEdgeColor(color.redF(), color.greenF(), color.blueF());
178 emit requestViewUpdate();
179}
180
182{
183 static_cast<vtkActor*>(_item->actor())
184 ->GetProperty()
185 ->SetOpacity(value / 100.0);
186 emit requestViewUpdate();
187}
188
190{
191 bool ok = true;
192 double scale = text.toDouble(&ok);
193
194 // If z scale becomes zero, the object becomes invisible
195 if (ok && scale != 0.0)
196 {
197 _item->setScale(1.0, 1.0, scale);
198
199 for (int i = 0; i < _item->childCount(); i++)
200 {
201 VtkVisPipelineItem* childItem = _item->child(i);
202 if (childItem)
203 {
204 auto* colorFilter =
205 dynamic_cast<VtkCompositeColorByHeightFilter*>(
206 childItem->compositeFilter());
207 if (colorFilter)
208 {
209 VtkColorByHeightFilter::SafeDownCast(
210 colorFilter->GetOutputAlgorithm())
211 ->SetTableRangeScaling(scale);
212 }
213 }
214 }
215
216 emit requestViewUpdate();
217 }
218}
219
221{
222 bool okX(true);
223 bool okY(true);
224 bool okZ(true);
225 double trans[3];
226
227 trans[0] = transX->text().toDouble(&okX);
228 trans[1] = transY->text().toDouble(&okY);
229 trans[2] = transZ->text().toDouble(&okZ);
230
231 if (okX && okY && okZ)
232 {
233 _item->setTranslation(trans[0], trans[1], trans[2]);
234 emit requestViewUpdate();
235 }
236}
237
239{
240 auto* layout =
241 static_cast<QFormLayout*>(this->scrollAreaWidgetContents->layout());
242 while (layout->count())
243 {
244 delete layout->takeAt(0)->widget();
245 }
246
247 QMap<QString, QVariant>* propMap = nullptr;
248 QMap<QString, QList<QVariant>>* propVecMap = nullptr;
249 VtkAlgorithmProperties* algProps = item->getVtkProperties();
250
251 if (algProps == nullptr)
252 WARN("VtkAlgorithmProperties null!");
253
254 // Retrieve algorithm properties
255 if (item->compositeFilter())
256 {
257 propMap = item->compositeFilter()->GetAlgorithmUserProperties();
258 propVecMap =
260 }
261 else
262 {
263 if (algProps)
264 {
265 propMap = algProps->GetAlgorithmUserProperties();
266 propVecMap = algProps->GetAlgorithmUserVectorProperties();
267 }
268 }
269
270 // Select appropriate GUI element and set connect for each property
271 if (propMap)
272 {
273 QMapIterator<QString, QVariant> i(*propMap);
274 while (i.hasNext())
275 {
276 i.next();
277 QString key = i.key();
278 QVariant value = i.value();
279
282 switch (value.type())
283 {
284 case QVariant::Double:
285 lineEdit = new VtkAlgorithmPropertyLineEdit(
286 QString::number(value.toDouble()), key,
287 QVariant::Double, algProps);
288 connect(lineEdit, SIGNAL(editingFinished()), this,
289 SIGNAL(requestViewUpdate()));
290 layout->addRow(key, lineEdit);
291 break;
292
293 case QVariant::Int:
294 lineEdit = new VtkAlgorithmPropertyLineEdit(
295 QString::number(value.toInt()), key, QVariant::Int,
296 algProps);
297 connect(lineEdit, SIGNAL(editingFinished()), this,
298 SIGNAL(requestViewUpdate()));
299 layout->addRow(key, lineEdit);
300 break;
301
302 case QVariant::Bool:
303 checkbox = new VtkAlgorithmPropertyCheckbox(value.toBool(),
304 key, algProps);
305 connect(checkbox, SIGNAL(stateChanged(int)), this,
306 SIGNAL(requestViewUpdate()));
307 layout->addRow(key, checkbox);
308 break;
309
310 default:
311 break;
312 }
313 }
314 }
315
316 if (propVecMap)
317 {
318 QMapIterator<QString, QList<QVariant>> i(*propVecMap);
319 while (i.hasNext())
320 {
321 i.next();
322 QString key = i.key();
323 QList<QVariant> values = i.value();
324
325 if (!values.empty())
326 {
327 QList<QString> valuesAsString;
328 foreach (QVariant variant, values)
329 valuesAsString.push_back(variant.toString());
330
333 valuesAsString, key, values.front().type(), algProps);
334 connect(vectorEdit, SIGNAL(editingFinished()), this,
335 SIGNAL(requestViewUpdate()));
336 layout->addRow(key, vectorEdit);
337 }
338 }
339 }
340}
341
343{
344 QStringList dataSetAttributesList = item->getScalarArrayNames();
345 dataSetAttributesList.push_back("Solid Color"); // all scalars switched off
346 this->activeScalarComboBox->blockSignals(true);
347 this->activeScalarComboBox->clear();
348 this->activeScalarComboBox->insertItems(0, dataSetAttributesList);
349 this->activeScalarComboBox->blockSignals(false);
350 QString active_array_name = item->GetActiveAttribute();
351 QList<QString>::iterator it = dataSetAttributesList.begin();
352 if (active_array_name.length() == 0)
353 {
354 item->SetActiveAttribute(*it);
355 }
356 else
357 {
358 int idx(0);
359 for (it = dataSetAttributesList.begin();
360 it != dataSetAttributesList.end();
361 ++it)
362 {
363 if (active_array_name.compare((*it).right((*it).length() - 2)) == 0)
364 {
365 this->activeScalarComboBox->setCurrentIndex(idx);
366 break;
367 }
368
369 idx++;
370 }
371 }
372}
373
375{
376 _item->SetActiveAttribute(name);
377 emit requestViewUpdate();
378}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
Contains properties for the visualization of objects as VtkVisPipelineItems.
QMap< QString, QVariant > * GetAlgorithmUserProperties() const
Returns a map of user properties.
void RemoveLookupTable(const QString &array_name)
Removes the lookup table for the given scalar.
QMap< QString, QList< QVariant > > * GetAlgorithmUserVectorProperties() const
Returns a map of vector user properties.
This checkbox sets a user property on the given VtkAlgorithmProperties object automatically.
This QLineEdit sets a user property on the given VtkAlgorithmProperties object automatically.
This edit widget consists of several QLineEdit to set a user vector property on the given VtkAlgorith...
This filter colors the input by the points z-value.
An item in the VtkVisPipeline containing an image to be visualized.
vtkAlgorithm * transformFilter() const override
An item in the VtkVisPipeline containing a graphic object to be visualized.
QStringList getScalarArrayNames() const
Returns a list of array names prefixed with P- or C- for point and cell data.
VtkAlgorithmProperties * getVtkProperties() const
Returns the VtkAlgorithmProperties.
virtual QString GetActiveAttribute() const
VtkCompositeFilter * compositeFilter() const
Returns the composite filter.
virtual void SetActiveAttribute(const QString &str)
void buildProportiesDialog(VtkVisPipelineItem *item)
Reads the algorithm properties of the given pipeline item and builds a dialog for adjusting these pro...
void setActiveItem(VtkVisPipelineItem *item)
Updates the property panels to show information on the given VtkVisPipelineItem.
void on_opacitySlider_sliderMoved(int value)
void buildScalarArrayComboBox(VtkVisPipelineItem *item)
Reads the scalar arrays of the given vtk-object and constructs content for the scalar array selection...
void on_edgeColorPickerButton_colorPicked(QColor color)
void on_visibleEdgesCheckBox_stateChanged(int state)
VtkVisPipelineItem * _item
void SetActiveAttributeOnItem(const QString &name)
void on_scaleZ_textChanged(const QString &text)
void on_diffuseColorPickerButton_colorPicked(QColor color)
void on_arrayResetPushButton_clicked()
void requestViewUpdate()
Is emitted when a property was changed.
VtkVisTabWidget(QWidget *parent=nullptr)
Constructor.