OGS
VtkCompositeContourFilter.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 <vtkContourFilter.h>
8#include <vtkPointData.h>
9#include <vtkSmartPointer.h>
10#include <vtkUnstructuredGrid.h>
11
12#include <limits>
13
15 vtkAlgorithm* inputAlgorithm)
16 : VtkCompositeFilter(inputAlgorithm)
17{
18 this->init();
19}
20
22
24{
25 // Set meta information about input and output data types
26 this->_inputDataObjectType = VTK_UNSTRUCTURED_GRID; // VTK_DATA_SET;
27 this->_outputDataObjectType = VTK_UNSTRUCTURED_GRID;
28
29 // Because this is the only filter here we cannot use vtkSmartPointer
30 vtkContourFilter* contour = vtkContourFilter::New();
31 contour->SetInputConnection(_inputAlgorithm->GetOutputPort());
32
33 // Getting the scalar range from the active point data scalar of the input
34 // algorithm This assumes that we do not want to contour on cell data.
35 double range[2];
36 vtkDataSet* dataSet =
37 vtkDataSet::SafeDownCast(_inputAlgorithm->GetOutputDataObject(0));
38 if (dataSet)
39 {
40 vtkPointData* pointData = dataSet->GetPointData();
41 if (pointData)
42 {
43 auto* scalars = pointData->GetScalars();
44 if (scalars)
45 {
46 scalars->GetRange(range);
47 }
48 }
49 }
50 else
51 {
52 // Setting the range to min / max values, this will result in a "bad
53 // table range" vtk warning.
54 range[0] = std::numeric_limits<double>::lowest();
55 range[1] = std::numeric_limits<double>::max();
56 }
57
58 // Sets a filter vector property which will be user editable
59 contour->GenerateValues(10, range[0], range[1]);
60
61 // Create a list for the ThresholdBetween (vector) property.
62 QList<QVariant> contourRangeList;
63 // Insert the values (same values as above)
64 contourRangeList.push_back(range[0]);
65 contourRangeList.push_back(range[1]);
66 // Put that list in the property map
67 (*_algorithmUserVectorProperties)["Range"] = contourRangeList;
68
69 // Make a new entry in the property map for the "Number of Values" property
70 (*_algorithmUserProperties)["Number of Contours"] = 10;
71
72 // The threshold filter is last one and so it is also the _outputAlgorithm
73 _outputAlgorithm = contour;
74}
75
76void VtkCompositeContourFilter::SetUserProperty(QString name, QVariant value)
77{
79
80 // Use the same name as in init()
81 if (name.compare("Number of Contours") == 0)
82 {
83 static_cast<vtkContourFilter*>(_outputAlgorithm)
84 ->SetNumberOfContours(value.toInt());
85 }
86}
87
89 QString name, QList<QVariant> values)
90{
92
93 // Use the same name as in init()
94 if (name.compare("Range") == 0)
95 {
96 static_cast<vtkContourFilter*>(_outputAlgorithm)
97 ->GenerateValues(
98 VtkAlgorithmProperties::GetUserProperty("Number of Contours")
99 .toInt(),
100 values[0].toDouble(),
101 values[1].toDouble());
102 }
103}
virtual void SetUserVectorProperty(QString name, QList< QVariant > values)
Sets a vector user property. This should be implemented by subclasses.
QVariant GetUserProperty(QString name) const
Returns the value of a user property.
virtual void SetUserProperty(QString name, QVariant value)
Sets a user property. This should be implemented by subclasses.
VtkCompositeContourFilter(vtkAlgorithm *inputAlgorithm)
~VtkCompositeContourFilter() override
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.
vtkAlgorithm * _outputAlgorithm
VtkCompositeFilter(vtkAlgorithm *inputAlgorithm)
Constructor.
vtkAlgorithm * _inputAlgorithm