OGS
VtkCompositeColormapToImageFilter.cpp
Go to the documentation of this file.
1
15// ** INCLUDES **
17
18#include <vtkImageData.h>
19#include <vtkImageMapToColors.h>
20#include <vtkLookupTable.h>
21#include <vtkPointData.h>
22#include <vtkSmartPointer.h>
23
24#include <QFileDialog>
25#include <QSettings>
26
28#include "VtkColorLookupTable.h"
29
31 vtkAlgorithm* inputAlgorithm)
32 : VtkCompositeFilter(inputAlgorithm)
33{
34 this->init();
35}
36
38 default;
39
41{
42 this->_inputDataObjectType = VTK_IMAGE_DATA;
43 this->_outputDataObjectType = VTK_IMAGE_DATA;
44
45 vtkSmartPointer<VtkColorLookupTable> colormap =
46 vtkSmartPointer<VtkColorLookupTable>::New();
47
48 QWidget* parent = nullptr;
49 QSettings settings;
50 QString fileName = QFileDialog::getOpenFileName(
51 parent, "Select color lookup table",
52 settings.value("lastOpenedLookupTableFileDirectory").toString(),
53 "Lookup table XML files (*.xml);;");
54 double range[2];
55 dynamic_cast<vtkImageAlgorithm*>(_inputAlgorithm)
56 ->GetOutput()
57 ->GetPointData()
58 ->GetScalars()
59 ->GetRange(range);
60
62 if (FileIO::XmlLutReader::readFromFile(fileName, lut))
63 {
64 colormap->setLookupTable(lut);
65 settings.setValue("lastOpenedLookupTableFileDirectory", fileName);
66 }
67 else
68 {
69 colormap->SetTableRange(range[0], range[1]);
70 colormap->SetHueRange(0.0, 0.666);
71 }
72 colormap->SetNumberOfTableValues(256);
73 colormap->Build();
74
75 colormap->GetTableRange(range);
76 QList<QVariant> tableRangeList;
77 tableRangeList.push_back(range[0]);
78 tableRangeList.push_back(range[1]);
79 QList<QVariant> hueRangeList;
80 hueRangeList.push_back(0.0);
81 hueRangeList.push_back(0.666);
82 (*_algorithmUserVectorProperties)["TableRange"] = tableRangeList;
83 (*_algorithmUserVectorProperties)["HueRange"] = hueRangeList;
84
85 vtkImageMapToColors* map = vtkImageMapToColors::New();
86 map->SetInputConnection(0, _inputAlgorithm->GetOutputPort());
87 map->SetLookupTable(colormap);
88 map->SetPassAlphaToOutput(1);
89 (*_algorithmUserProperties)["PassAlphaToOutput"] = true;
90 (*_algorithmUserProperties)["NumberOfColors"] = 256;
91
92 _outputAlgorithm = map;
93}
94
96 QVariant value)
97{
99
100 auto* map = static_cast<vtkImageMapToColors*>(_outputAlgorithm);
101 if (name.compare("PassAlphaToOutput") == 0)
102 {
103 map->SetPassAlphaToOutput(value.toBool());
104 }
105 else if (name.compare("NumberOfColors") == 0)
106 {
107 static_cast<vtkLookupTable*>(map->GetLookupTable())
108 ->SetNumberOfTableValues(value.toInt());
109 }
110}
111
113 QString name, QList<QVariant> values)
114{
116
117 auto* map = static_cast<vtkImageMapToColors*>(_outputAlgorithm);
118 if (name.compare("TableRange") == 0)
119 {
120 static_cast<vtkLookupTable*>(map->GetLookupTable())
121 ->SetTableRange(values[0].toInt(), values[1].toInt());
122 }
123 else if (name.compare("HueRange") == 0)
124 {
125 static_cast<vtkLookupTable*>(map->GetLookupTable())
126 ->SetHueRange(values[0].toDouble(), values[1].toDouble());
127 }
128}
Definition of the VtkColorLookupTable class.
Definition of the VtkCompositeColormapToImageFilter class.
Definition of the XmlLutReader class.
static bool readFromFile(const QString &fileName, DataHolderLib::ColorLookupTable &lut)
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.
void SetUserProperty(QString name, QVariant value) override
Sets a user property. This should be implemented by subclasses.
void SetUserVectorProperty(QString name, QList< QVariant > values) override
Sets a vector user property. This should be implemented by subclasses.
VtkCompositeColormapToImageFilter(vtkAlgorithm *inputAlgorithm)
Is used to combine several filter in one VtkVisPipelineItem. You can use vtk filter and custom filter...
vtkAlgorithm * _outputAlgorithm
vtkAlgorithm * _inputAlgorithm