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 pointData->GetScalars()->GetRange(range);
55 }
56 }
57 else
58 {
59 // Setting the range to min / max values, this will result in a "bad
60 // table range" vtk warning.
61 range[0] = std::numeric_limits<double>::lowest();
62 range[1] = std::numeric_limits<double>::max();
63 }
64
65 // Sets a filter vector property which will be user editable
66 contour->GenerateValues(10, range[0], range[1]);
67
68 // Create a list for the ThresholdBetween (vector) property.
69 QList<QVariant> contourRangeList;
70 // Insert the values (same values as above)
71 contourRangeList.push_back(range[0]);
72 contourRangeList.push_back(range[1]);
73 // Put that list in the property map
74 (*_algorithmUserVectorProperties)["Range"] = contourRangeList;
75
76 // Make a new entry in the property map for the "Number of Values" property
77 (*_algorithmUserProperties)["Number of Contours"] = 10;
78
79 // The threshold filter is last one and so it is also the _outputAlgorithm
80 _outputAlgorithm = contour;
81}
82
83void VtkCompositeContourFilter::SetUserProperty(QString name, QVariant value)
84{
86
87 // Use the same name as in init()
88 if (name.compare("Number of Contours") == 0)
89 {
90 static_cast<vtkContourFilter*>(_outputAlgorithm)
91 ->SetNumberOfContours(value.toInt());
92 }
93}
94
96 QString name, QList<QVariant> values)
97{
99
100 // Use the same name as in init()
101 if (name.compare("Range") == 0)
102 {
103 static_cast<vtkContourFilter*>(_outputAlgorithm)
104 ->GenerateValues(
105 VtkAlgorithmProperties::GetUserProperty("Number of Contours")
106 .toInt(),
107 values[0].toDouble(),
108 values[1].toDouble());
109 }
110}
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