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