OGS
FileIO::XmlLutReader Class Reference

Detailed Description

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

Definition at line 20 of file XmlLutReader.h.

#include <XmlLutReader.h>

Static Public Member Functions

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

Member Function Documentation

◆ readFromFile()

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

Definition at line 23 of file XmlLutReader.h.

24 {
25 QFile file(fileName);
26 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
27 {
28 ERR("XmlLutReader::readFromFile(): Can't open xml-file {:s}.",
29 fileName.toStdString());
30 return false;
31 }
32
33 QDomDocument doc("ColorMap");
34 doc.setContent(&file);
35 QDomElement docElement = doc.documentElement();
36 if (docElement.nodeName().compare("ColorMap"))
37 {
38 ERR("XmlLutReader::readFromFile(): Unexpected XML root.");
39 file.close();
40 return false;
41 }
42
43 if (docElement.hasAttribute("interpolation"))
44 {
45 if (docElement.attribute("interpolation").compare("Linear") == 0)
47 else if (docElement.attribute("interpolation").compare("Exponential") == 0)
49 else
51 }
52 else // default
54
55 QDomElement point = docElement.firstChildElement();
56 double range[2] = { point.attribute("x").toDouble(), point.attribute("x").toDouble() };
57
58 while (!point.isNull())
59 {
60 if ((point.nodeName().compare("Point") == 0 )
61 && point.hasAttribute("x")
62 && point.hasAttribute("r")
63 && point.hasAttribute("g")
64 && point.hasAttribute("b"))
65 {
66 double value = point.attribute("x").toDouble();
67 unsigned char r = static_cast<int>(255 * point.attribute("r").toDouble());
68 unsigned char g = static_cast<int>(255 * point.attribute("g").toDouble());
69 unsigned char b = static_cast<int>(255 * point.attribute("b").toDouble());
70 unsigned char o = static_cast<int>(255 * (point.hasAttribute("o") ? point.attribute("o").toDouble() : 1));
71
72 if (value < range[0])
73 range[0] = value;
74 if (value > range[1])
75 range[1] = value;
76
78 lut.setColor(value, color);
79 }
80 point = point.nextSiblingElement();
81 }
82
83 lut.setTableRange(range[0], range[1]);
84
85 file.close();
86 return true;
87 };
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
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:10
std::array< unsigned char, 4 > Color
Definition Color.h:12

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: