OGS
VtkCompositeImageToCylindersFilter.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 <vtkLookupTable.h>
8#include <vtkPointData.h>
9#include <vtkSmartPointer.h>
10#include <vtkTubeFilter.h>
11#include <vtkUnsignedCharArray.h>
12
13#include <QMap>
14#include <QString>
15#include <QVariant>
16#include <QVector>
17
19
21 vtkAlgorithm* inputAlgorithm)
22 : VtkCompositeFilter(inputAlgorithm), _lineFilter(nullptr)
23{
24 this->init();
25}
26
28{
29 this->_inputDataObjectType = VTK_IMAGE_DATA;
30 this->_outputDataObjectType = VTK_POLY_DATA;
31
33 _lineFilter->SetInputConnection(_inputAlgorithm->GetOutputPort());
34 _lineFilter->SetLengthScaleFactor(1);
35 (*_algorithmUserProperties)["LengthScaleFactor"] = 1.0;
36 _lineFilter->Update();
37
38 double range[2];
39 // The data is always on points
40 vtkDataSet::SafeDownCast(_lineFilter->GetOutputDataObject(0))
41 ->GetPointData()
42 ->GetScalars()
43 ->GetRange(range);
44
45 vtkLookupTable* colormap = vtkLookupTable::New();
46 colormap->SetTableRange(range[0], range[1]);
47 colormap->SetHueRange(0.0, 0.666);
48 colormap->SetNumberOfTableValues(256);
49 colormap->ForceBuild();
50 QList<QVariant> tableRangeList;
51 tableRangeList.push_back(range[0]);
52 tableRangeList.push_back(range[1]);
53 QList<QVariant> hueRangeList;
54 hueRangeList.push_back(0.0);
55 hueRangeList.push_back(0.666);
56 (*_algorithmUserVectorProperties)["TableRange"] = tableRangeList;
57 (*_algorithmUserVectorProperties)["HueRange"] = hueRangeList;
58
59 this->SetLookUpTable("P-Colors", colormap);
60
61 vtkTubeFilter* tubeFilter = vtkTubeFilter::New();
62 tubeFilter->SetInputConnection(_lineFilter->GetOutputPort());
63 tubeFilter->CappingOn();
64 tubeFilter->SetNumberOfSides(6);
65 tubeFilter->SetRadius(_lineFilter->GetImageSpacing() * 0.25);
66 (*_algorithmUserProperties)["NumberOfColors"] = 256;
67 (*_algorithmUserProperties)["Capping"] = true;
68 (*_algorithmUserProperties)["NumberOfSides"] = 6;
69 (*_algorithmUserProperties)["RadiusFactor"] = 0.25;
70
71 _outputAlgorithm = tubeFilter;
72}
73
75 QVariant value)
76{
78
79 _lineFilter->SetUserProperty(name, value);
80
81 // VtkImageDataToLinePolyDataFilter is equal to _firstAlgorithm
82 // vtkTubeFilter is equal _outputAlgorithm
83 if (name.compare("NumberOfColors") == 0)
84 {
85 vtkLookupTable* lut = this->GetLookupTable("P-Colors");
86 if (lut)
87 {
88 lut->SetNumberOfTableValues(value.toInt());
89 }
90 }
91 else if (name.compare("NumberOfSides") == 0)
92 {
93 static_cast<vtkTubeFilter*>(_outputAlgorithm)
94 ->SetNumberOfSides(value.toInt());
95 }
96 else if (name.compare("Capping") == 0)
97 {
98 static_cast<vtkTubeFilter*>(_outputAlgorithm)
99 ->SetCapping(value.toBool());
100 }
101 else if (name.compare("RadiusFactor") == 0)
102 {
103 static_cast<vtkTubeFilter*>(_outputAlgorithm)
104 ->SetRadius(_lineFilter->GetImageSpacing() * value.toDouble());
105 }
106}
107
109 QString name, QList<QVariant> values)
110{
112
113 _lineFilter->SetUserVectorProperty(name, values);
114
115 if (name.compare("TableRange") == 0)
116 {
117 vtkLookupTable* lut = this->GetLookupTable("P-Colors");
118 if (lut)
119 {
120 lut->SetTableRange(values[0].toDouble(), values[1].toDouble());
121 }
122 }
123 else if (name.compare("HueRange") == 0)
124 {
125 vtkLookupTable* lut = this->GetLookupTable("P-Colors");
126 if (lut)
127 {
128 lut->SetHueRange(values[0].toDouble(), values[1].toDouble());
129 }
130 }
131}
132
vtkLookupTable * GetLookupTable(const QString &array_name)
Returns the colour lookup table (if one has been assigned).
virtual void SetUserVectorProperty(QString name, QList< QVariant > values)
Sets a vector user property. This should be implemented by subclasses.
void SetLookUpTable(const QString &array_name, vtkLookupTable *lut)
Sets a colour lookup table for the given scalar array of the VtkVisPipelineItem.
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
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.
VtkCompositeImageToCylindersFilter(vtkAlgorithm *inputAlgorithm)
static VtkImageDataToLinePolyDataFilter * New()
Create new objects with New() because of VTKs reference counting.