OGS
VtkAlgorithmProperties.h
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#pragma once
5
6// ** INCLUDES **
7#include <QList>
8#include <QMap>
9#include <QObject>
10#include <QString>
11#include <QVariant>
12
13class vtkProperty;
14class vtkTexture;
15class vtkLookupTable;
16
17
18#define ogsUserPropertyMacro(name,type) \
19 virtual void Set ## name (type _arg) \
20 { \
21 vtkDebugMacro( \
22 << this->GetClassName() << " (" << this << "): setting " # name " to " << \
23 _arg); \
24 if (this->name != _arg) \
25 { \
26 this->name = _arg; \
27 this->Modified(); \
28 (*(this->_algorithmUserProperties))[QString(# name)] = QVariant(_arg); \
29 } \
30 } \
31\
32 type name;
33// End of ogsUserPropertyMacro
34
35#define ogsUserVec2PropertyMacro(name,type) \
36 virtual void Set ## name (type _arg1, type _arg2) \
37 { \
38 vtkDebugMacro( \
39 << this->GetClassName() << " (" << this << "): setting " << \
40 # name " to (" << \
41 _arg1 << "," << _arg2 << ")"); \
42 if ((this->name[0] != _arg1) || (this->name[1] != _arg2)) \
43 { \
44 this->name[0] = _arg1; \
45 this->name[1] = _arg2; \
46 this->Modified(); \
47 QList<QVariant> list; \
48 list.push_back(QVariant(_arg1)); \
49 list.push_back(QVariant(_arg2)); \
50 (*(this->_algorithmUserVectorProperties))[QString(# name)] = list; \
51 } \
52 } \
53\
54 virtual void Set ## name (type _arg[2]) \
55 { \
56 this->Set ## name (_arg[0], _arg[1]); \
57 } \
58\
59 type name[2];
60// End of ogsUserVec2PropertyMacro
61
62#define ogsUserVec3PropertyMacro(name,type) \
63 virtual void Set ## name (type _arg1, type _arg2, type _arg3) \
64 { \
65 vtkDebugMacro( \
66 << this->GetClassName() << " (" << this << "): setting " << \
67 # name " to (" << \
68 _arg1 << "," << _arg2 << "," << _arg3 << ")"); \
69 if ((this->name[0] != _arg1) || (this->name[1] != _arg2) || (this->name[2] != _arg3)) \
70 { \
71 this->name[0] = _arg1; \
72 this->name[1] = _arg2; \
73 this->name[2] = _arg3; \
74 this->Modified(); \
75 QList<QVariant> list; \
76 list.push_back(QVariant(_arg1)); \
77 list.push_back(QVariant(_arg2)); \
78 list.push_back(QVariant(_arg3)); \
79 (*(this->_algorithmUserVectorProperties))[QString(# name)] = list; \
80 } \
81 } \
82\
83 virtual void Set ## name (type _arg[3]) \
84 { \
85 this->Set ## name (_arg[0], _arg[1], _arg[2]); \
86 } \
87\
88 type name[3];
89// End of ogsUserVec3PropertyMacro
90
91#define ogsUserVec4PropertyMacro(name,type) \
92 virtual void Set ## name (type _arg1, type _arg2, type _arg3, type _arg4) \
93 { \
94 vtkDebugMacro( \
95 << this->GetClassName() << " (" << this << "): setting " << \
96 # name " to (" << \
97 _arg1 << "," << _arg2 << "," << _arg3 << "," << _arg4 << ")"); \
98 if ((this->name[0] != _arg1) || (this->name[1] != _arg2) || \
99 (this->name[2] != _arg3) || (this->name[3] != _arg4)) \
100 { \
101 this->name[0] = _arg1; \
102 this->name[1] = _arg2; \
103 this->name[2] = _arg3; \
104 this->name[3] = _arg4; \
105 this->Modified(); \
106 QList<QVariant> list; \
107 list.push_back(QVariant(_arg1)); \
108 list.push_back(QVariant(_arg2)); \
109 list.push_back(QVariant(_arg3)); \
110 list.push_back(QVariant(_arg4)); \
111 (*(this->_algorithmUserVectorProperties))[QString(# name)] = list; \
112 } \
113 } \
114\
115 virtual void Set ## name (type _arg[4]) \
116 { \
117 this->Set ## name (_arg[0], _arg[1], _arg[2], _arg[3]); \
118 } \
119\
120 type name[4];
121// End of ogsUserVec4PropertyMacro
122
126class VtkAlgorithmProperties : public QObject
127{
128 Q_OBJECT
129
130public:
132 explicit VtkAlgorithmProperties(QObject* parent = nullptr);
133
134 ~VtkAlgorithmProperties() override;
135
137 vtkProperty* GetProperties() const { return _property; }
138
140 vtkTexture* GetTexture() { return _texture; }
141
143 void SetTexture(vtkTexture* t) { _texture = t; }
144
146 vtkLookupTable* GetLookupTable(const QString& array_name);
147
149 void RemoveLookupTable(const QString& array_name);
150
152 void SetLookUpTable(const QString &array_name, vtkLookupTable* lut);
153
155 void SetLookUpTable(const QString &array_name, const QString &filename);
156
158 bool GetScalarVisibility() const { return _scalarVisibility; }
159
161 void SetScalarVisibility(bool on);
162
164 QString GetName() const { return _name; }
165
167 void SetName(QString name) { _name = name; }
168
170 bool IsRemovable() const { return _removable; }
171
173 QMap<QString, QVariant>* GetAlgorithmUserProperties() const {
175 }
176
178 QMap<QString, QList<QVariant> >* GetAlgorithmUserVectorProperties() const {
180 }
181
183 virtual void SetUserProperty(QString name, QVariant value)
184 {
185 (*_algorithmUserProperties)[name] = value;
186 }
187
189 QVariant GetUserProperty(QString name) const;
190
192 virtual void SetUserVectorProperty(QString name, QList<QVariant> values)
193 {
194 (*_algorithmUserVectorProperties)[name] = values;
195 }
196
198 QList<QVariant> GetUserVectorProperty(QString name) const;
199
201 void SetActiveAttribute(QString name);
202
204 QString GetActiveAttribute() const { return _activeAttributeName; }
205
206
207protected:
208
209 // Properties set on vtkActor
210 vtkProperty* _property;
211 vtkTexture* _texture;
212
213 // Properties set on vtkMapper
215 std::map<QString, vtkLookupTable*> _lut;
216
217 // Properties used in the GUI
218 QString _name;
221
222 QMap<QString, QVariant>* _algorithmUserProperties;
223 QMap<QString, QList<QVariant> >* _algorithmUserVectorProperties;
224
225signals:
227};
vtkLookupTable * GetLookupTable(const QString &array_name)
Returns the colour lookup table (if one has been assigned).
QMap< QString, QList< QVariant > > * _algorithmUserVectorProperties
void ScalarVisibilityChanged(bool on)
void SetActiveAttribute(QString name)
Set the active attribute.
virtual void SetUserVectorProperty(QString name, QList< QVariant > values)
Sets a vector user property. This should be implemented by subclasses.
bool GetScalarVisibility() const
Returns the scalar visibility.
void SetScalarVisibility(bool on)
Sets the scalar visibility.
vtkTexture * GetTexture()
Returns a texture (if one has been assigned).
QMap< QString, QVariant > * GetAlgorithmUserProperties() const
Returns a map of user properties.
QString GetActiveAttribute() const
Returns the desired active attribute.
void SetLookUpTable(const QString &array_name, vtkLookupTable *lut)
Sets a colour lookup table for the given scalar array of the VtkVisPipelineItem.
std::map< QString, vtkLookupTable * > _lut
QVariant GetUserProperty(QString name) const
Returns the value of a user property.
void SetName(QString name)
Sets the name.
void RemoveLookupTable(const QString &array_name)
Removes the lookup table for the given scalar.
QList< QVariant > GetUserVectorProperty(QString name) const
Returns a list of values of a vector user property.
VtkAlgorithmProperties(QObject *parent=nullptr)
Constructor (sets default values)
QMap< QString, QVariant > * _algorithmUserProperties
QMap< QString, QList< QVariant > > * GetAlgorithmUserVectorProperties() const
Returns a map of vector user properties.
void SetTexture(vtkTexture *t)
Sets a texture for the VtkVisPipelineItem.
QString GetName() const
Returns the name. This is set to the file path if it is a source algorithm.
vtkProperty * GetProperties() const
Returns the vtk properties.
bool IsRemovable() const
Is this algorithm removable from the pipeline (view).
virtual void SetUserProperty(QString name, QVariant value)
Sets a user property. This should be implemented by subclasses.