OGS
FileIO::XmlLutReader Class Reference

Detailed Description

Reader for vtk-Lookup-Tables (in XML / ParaView Format)

Definition at line 31 of file XmlLutReader.h.

#include <XmlLutReader.h>

Static Public Member Functions

static bool readFromFile (const QString &fileName, DataHolderLib::ColorLookupTable &lut)
 

Member Function Documentation

◆ readFromFile()

static bool FileIO::XmlLutReader::readFromFile ( const QString & fileName,
DataHolderLib::ColorLookupTable & lut )
inlinestatic

Definition at line 34 of file XmlLutReader.h.

35 {
36 QFile file(fileName);
37 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
38 {
39 ERR("XmlLutReader::readFromFile(): Can't open xml-file {:s}.",
40 fileName.toStdString());
41 return false;
42 }
43
44 QDomDocument doc("ColorMap");
45 doc.setContent(&file);
46 QDomElement docElement = doc.documentElement();
47 if (docElement.nodeName().compare("ColorMap"))
48 {
49 ERR("XmlLutReader::readFromFile(): Unexpected XML root.");
50 file.close();
51 return false;
52 }
53
54 if (docElement.hasAttribute("interpolation"))
55 {
56 if (docElement.attribute("interpolation").compare("Linear") == 0)
58 else if (docElement.attribute("interpolation").compare("Exponential") == 0)
60 else
62 }
63 else // default
65
66 QDomElement point = docElement.firstChildElement();
67 double range[2] = { point.attribute("x").toDouble(), point.attribute("x").toDouble() };
68
69 while (!point.isNull())
70 {
71 if ((point.nodeName().compare("Point") == 0 )
72 && point.hasAttribute("x")
73 && point.hasAttribute("r")
74 && point.hasAttribute("g")
75 && point.hasAttribute("b"))
76 {
77 double value = point.attribute("x").toDouble();
78 unsigned char r = static_cast<int>(255 * point.attribute("r").toDouble());
79 unsigned char g = static_cast<int>(255 * point.attribute("g").toDouble());
80 unsigned char b = static_cast<int>(255 * point.attribute("b").toDouble());
81 unsigned char o = static_cast<int>(255 * (point.hasAttribute("o") ? point.attribute("o").toDouble() : 1));
82
83 if (value < range[0])
84 range[0] = value;
85 if (value > range[1])
86 range[1] = value;
87
89 lut.setColor(value, color);
90 }
91 point = point.nextSiblingElement();
92 }
93
94 lut.setTableRange(range[0], range[1]);
95
96 file.close();
97 return true;
98 };
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
void setColor(double id, DataHolderLib::Color const &color)
void setInterpolationType(LUTType type)
void setTableRange(double min, double max)
Color createColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Definition Color.cpp:21
std::array< unsigned char, 4 > Color
Definition Color.h:24

References DataHolderLib::createColor(), ERR(), DataHolderLib::EXPONENTIAL, DataHolderLib::LINEAR, DataHolderLib::NONE, DataHolderLib::ColorLookupTable::setColor(), DataHolderLib::ColorLookupTable::setInterpolationType(), and DataHolderLib::ColorLookupTable::setTableRange().

Referenced by VtkCompositeColormapToImageFilter::init(), and VtkAlgorithmProperties::SetLookUpTable().


The documentation for this class was generated from the following file: