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