OGS
VtkCompositeThresholdFilter.cpp
Go to the documentation of this file.
1 
15 // ** INCLUDES **
17 
18 #include <vtkCellData.h>
19 #include <vtkThreshold.h>
20 #include <vtkUnstructuredGrid.h>
21 
22 #include "BaseLib/Logging.h"
23 
25  vtkAlgorithm* inputAlgorithm)
26  : VtkCompositeFilter(inputAlgorithm)
27 {
28  this->init();
29 }
30 
32 
34 {
35  // Set meta information about input and output data types
36  this->_inputDataObjectType = VTK_DATA_SET;
37  this->_outputDataObjectType = VTK_UNSTRUCTURED_GRID;
38 
39  // Because this is the only filter here we cannot use vtkSmartPointer
40  vtkThreshold* threshold = vtkThreshold::New();
41  threshold->SetInputConnection(_inputAlgorithm->GetOutputPort());
42 
43  // Use first array of parent as input array
44  _inputAlgorithm->Update();
45  vtkDataSet* dataSet =
46  vtkDataSet::SafeDownCast(_inputAlgorithm->GetOutputDataObject(0));
47  vtkDataSetAttributes* pointAttributes =
48  dataSet->GetAttributes(vtkDataObject::AttributeTypes::POINT);
49  vtkDataSetAttributes* cellAttributes =
50  dataSet->GetAttributes(vtkDataObject::AttributeTypes::CELL);
51  if (pointAttributes->GetNumberOfArrays() > 0)
52  {
53  threshold->SetInputArrayToProcess(
54  0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS,
55  pointAttributes->GetArray(0)->GetName());
56  }
57  else if (cellAttributes->GetNumberOfArrays() > 0)
58  {
59  threshold->SetInputArrayToProcess(
60  0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_CELLS,
61  cellAttributes->GetArray(0)->GetName());
62  }
63  else
64  {
65  WARN("Threshold filter could not find an array on its input object!");
66  return;
67  }
68 
69  // Sets a filter property which will be user editable
70  threshold->SetSelectedComponent(0);
71 
72  // Setting the threshold to min / max values to ensure that the whole data
73  // is first processed. This is needed for correct lookup table generation.
74  const double dMin = std::numeric_limits<double>::lowest();
75  const double dMax = std::numeric_limits<double>::max();
76  threshold->ThresholdBetween(dMin, dMax);
77 
78  // Create a list for the ThresholdBetween (vector) property.
79  QList<QVariant> thresholdRangeList;
80  // Insert the values (same values as above)
81  thresholdRangeList.push_back(dMin);
82  thresholdRangeList.push_back(dMax);
83  // Put that list in the property map
84  (*_algorithmUserVectorProperties)["Range"] = thresholdRangeList;
85 
86  // Make a new entry in the property map for the SelectedComponent property
87  (*_algorithmUserProperties)["Selected Component"] = 0;
88 
89  // Must all scalars match the criterium
90  threshold->SetAllScalars(1);
91  (*_algorithmUserProperties)["Evaluate all points"] = true;
92 
93  // The threshold filter is last one and so it is also the _outputAlgorithm
94  _outputAlgorithm = threshold;
95 }
96 
98 {
100 
101  // Use the same name as in init()
102  if (name.compare("Selected Component") == 0)
103  {
104  // Set the property on the algorithm
105  static_cast<vtkThreshold*>(_outputAlgorithm)
106  ->SetSelectedComponent(value.toInt());
107  }
108  else if (name.compare("Evaluate all points") == 0)
109  {
110  static_cast<vtkThreshold*>(_outputAlgorithm)
111  ->SetAllScalars(value.toBool());
112  }
113 }
114 
116  QList<QVariant> values)
117 {
119 
120  // Use the same name as in init()
121  if (name.compare("Range") == 0)
122  {
123  // Set the vector property on the algorithm
124  static_cast<vtkThreshold*>(_outputAlgorithm)
125  ->ThresholdBetween(values[0].toDouble(), values[1].toDouble());
126  }
127 }
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
Definition of the VtkCompositeThresholdFilter class.
virtual void SetUserVectorProperty(QString name, QList< QVariant > values)
Sets a vector user property. This should be implemented by subclasses.
virtual void SetUserProperty(QString name, QVariant value)
Sets a user property. This should be implemented by subclasses.
Is used to combine several filter in one VtkVisPipelineItem. You can use vtk filter and custom filter...
vtkAlgorithm * _outputAlgorithm
vtkAlgorithm * _inputAlgorithm
VtkCompositeThresholdFilter(vtkAlgorithm *inputAlgorithm)
void SetUserVectorProperty(QString name, QList< QVariant > values) override
Sets a vector user property. This should be implemented by subclasses.
void SetUserProperty(QString name, QVariant value) override
Sets a user property. This should be implemented by subclasses.
~VtkCompositeThresholdFilter() override