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
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
90 }
91 point = point.nextSiblingElement();
92 }
93
95
96 file.close();
97 return true;
98 };
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
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)
std::array< unsigned char, 4 > Color