OGS
VtkAlgorithmProperties.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 <vtkProperty.h>
8#include <vtkTexture.h>
9
12#include "BaseLib/Logging.h"
13#include "VtkColorLookupTable.h"
14
16 : QObject(parent)
17{
18 _property = vtkProperty::New();
19 _texture = nullptr;
20 _scalarVisibility = true;
21 _algorithmUserProperties = new QMap<QString, QVariant>;
22 _algorithmUserVectorProperties = new QMap<QString, QList<QVariant>>;
24 _removable = true;
25}
26
28{
29 _property->Delete();
30 if (_texture != nullptr)
31 {
32 _texture->Delete();
33 }
34
35 for (auto& row : _lut)
36 {
37 row.second->Delete();
38 }
41}
42
44 const QString& array_name)
45{
46 auto it = _lut.find(array_name);
47 if (it != _lut.end())
48 {
49 return it->second;
50 }
51
52 return nullptr;
53}
54
55void VtkAlgorithmProperties::RemoveLookupTable(const QString& array_name)
56{
57 auto it = _lut.find(array_name);
58 if (it != _lut.end())
59 {
60 it->second->Delete();
61 _lut.erase(it);
62 }
63}
64
65void VtkAlgorithmProperties::SetLookUpTable(const QString& array_name,
66 vtkLookupTable* lut)
67{
68 lut->Build();
69
70 if (array_name.length() > 0)
71 {
72 this->RemoveLookupTable(array_name);
73 _lut.insert(std::pair<QString, vtkLookupTable*>(array_name, lut));
74 _activeAttributeName = array_name;
75 }
76}
77
78void VtkAlgorithmProperties::SetLookUpTable(const QString& array_name,
79 const QString& filename)
80{
82 if (FileIO::XmlLutReader::readFromFile(filename, lut))
83 {
85 colorLookupTable->setLookupTable(lut);
86 SetLookUpTable(array_name, colorLookupTable);
87 }
88 else
89 ERR("Error reading color look-up table.");
90}
91
97
98QVariant VtkAlgorithmProperties::GetUserProperty(QString name) const
99{
100 if (this->_algorithmUserProperties->contains(name))
101 {
102 return this->_algorithmUserProperties->value(name);
103 }
104
105 ERR("Not a valid property: {:s}", name.toStdString());
106 return QVariant();
107}
108
110 QString name) const
111{
112 if (this->_algorithmUserVectorProperties->contains(name))
113 {
114 return this->_algorithmUserVectorProperties->value(name);
115 }
116
117 ERR("Not a valid property: {:s}", name.toStdString());
118 return QList<QVariant>();
119}
120
122{
123 if (name.contains("Solid Color") || name.contains("P-TextureCoordinates"))
124 {
125 SetScalarVisibility(false);
126 }
127 else
128 {
130 }
132}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
static bool readFromFile(const QString &fileName, DataHolderLib::ColorLookupTable &lut)
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.
void SetScalarVisibility(bool on)
Sets the scalar visibility.
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 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
Calculates and stores a colour lookup table.
void setLookupTable(DataHolderLib::ColorLookupTable const &lut)
Imports settings of OGS lookup table class.
static VtkColorLookupTable * New()
Create new objects with New() because of VTKs object reference counting.