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