20 if (
const auto *prop = dynamic_cast<const LookupTableProperty *>(
m_Property.GetPointer()))
28 vtkLookupTable *lut = mitkLut->GetVtkLookupTable();
32 auto element =
new TiXmlElement(
"LookupTable");
37 element->SetAttribute(
"NumberOfColors", lut->GetNumberOfTableValues());
38 element->SetAttribute(
"Scale", lut->GetScale());
39 element->SetAttribute(
"Ramp", lut->GetRamp());
41 range = lut->GetHueRange();
42 auto child =
new TiXmlElement(
"HueRange");
43 element->LinkEndChild(child);
44 child->SetAttribute(
"min", boost::lexical_cast<std::string>(range[0]));
45 child->SetAttribute(
"max", boost::lexical_cast<std::string>(range[1]));
47 range = lut->GetValueRange();
48 child =
new TiXmlElement(
"ValueRange");
49 element->LinkEndChild(child);
50 child->SetAttribute(
"min", boost::lexical_cast<std::string>(range[0]));
51 child->SetAttribute(
"max", boost::lexical_cast<std::string>(range[1]));
53 range = lut->GetSaturationRange();
54 child =
new TiXmlElement(
"SaturationRange");
55 element->LinkEndChild(child);
56 child->SetAttribute(
"min", boost::lexical_cast<std::string>(range[0]));
57 child->SetAttribute(
"max", boost::lexical_cast<std::string>(range[1]));
59 range = lut->GetAlphaRange();
60 child =
new TiXmlElement(
"AlphaRange");
61 element->LinkEndChild(child);
62 child->SetAttribute(
"min", boost::lexical_cast<std::string>(range[0]));
63 child->SetAttribute(
"max", boost::lexical_cast<std::string>(range[1]));
65 range = lut->GetTableRange();
66 child =
new TiXmlElement(
"TableRange");
67 element->LinkEndChild(child);
68 child->SetAttribute(
"min", boost::lexical_cast<std::string>(range[0]));
69 child->SetAttribute(
"max", boost::lexical_cast<std::string>(range[1]));
71 child =
new TiXmlElement(
"Table");
72 element->LinkEndChild(child);
73 for (
int index = 0; index < lut->GetNumberOfTableValues(); ++index)
75 auto grandChild =
new TiXmlElement(
"RgbaColor");
76 rgba = lut->GetTableValue(index);
77 grandChild->SetAttribute(
"R", boost::lexical_cast<std::string>(rgba[0]));
78 grandChild->SetAttribute(
"G", boost::lexical_cast<std::string>(rgba[1]));
79 grandChild->SetAttribute(
"B", boost::lexical_cast<std::string>(rgba[2]));
80 grandChild->SetAttribute(
"A", boost::lexical_cast<std::string>(rgba[3]));
81 child->LinkEndChild(grandChild);
99 std::string double_strings[4];
101 vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
106 if (element->QueryIntAttribute(
"NumberOfColors", &numberOfColors) == TIXML_SUCCESS)
108 lut->SetNumberOfTableValues(numberOfColors);
112 if (element->QueryIntAttribute(
"Scale", &scale) == TIXML_SUCCESS)
114 lut->SetScale(scale);
118 if (element->QueryIntAttribute(
"Ramp", &ramp) == TIXML_SUCCESS)
127 TiXmlElement *child = element->FirstChildElement(
"HueRange");
130 if (child->QueryStringAttribute(
"min", &double_strings[0]) != TIXML_SUCCESS)
132 if (child->QueryStringAttribute(
"max", &double_strings[1]) != TIXML_SUCCESS)
134 StringsToNumbers<double>(2, double_strings, range);
135 lut->SetHueRange(range);
138 child = element->FirstChildElement(
"ValueRange");
141 if (child->QueryStringAttribute(
"min", &double_strings[0]) != TIXML_SUCCESS)
143 if (child->QueryStringAttribute(
"max", &double_strings[1]) != TIXML_SUCCESS)
145 StringsToNumbers<double>(2, double_strings, range);
146 lut->SetValueRange(range);
149 child = element->FirstChildElement(
"SaturationRange");
152 if (child->QueryStringAttribute(
"min", &double_strings[0]) != TIXML_SUCCESS)
154 if (child->QueryStringAttribute(
"max", &double_strings[1]) != TIXML_SUCCESS)
156 StringsToNumbers<double>(2, double_strings, range);
157 lut->SetSaturationRange(range);
160 child = element->FirstChildElement(
"AlphaRange");
163 if (child->QueryStringAttribute(
"min", &double_strings[0]) != TIXML_SUCCESS)
165 if (child->QueryStringAttribute(
"max", &double_strings[1]) != TIXML_SUCCESS)
167 StringsToNumbers<double>(2, double_strings, range);
168 lut->SetAlphaRange(range);
171 child = element->FirstChildElement(
"TableRange");
174 if (child->QueryStringAttribute(
"min", &double_strings[0]) != TIXML_SUCCESS)
176 if (child->QueryStringAttribute(
"max", &double_strings[1]) != TIXML_SUCCESS)
178 StringsToNumbers<double>(2, double_strings, range);
179 lut->SetTableRange(range);
182 child = element->FirstChildElement(
"Table");
185 unsigned int index(0);
186 for (TiXmlElement *grandChild = child->FirstChildElement(
"RgbaColor"); grandChild;
187 grandChild = grandChild->NextSiblingElement(
"RgbaColor"))
189 if (grandChild->QueryStringAttribute(
"R", &double_strings[0]) != TIXML_SUCCESS)
191 if (grandChild->QueryStringAttribute(
"G", &double_strings[1]) != TIXML_SUCCESS)
193 if (grandChild->QueryStringAttribute(
"B", &double_strings[2]) != TIXML_SUCCESS)
195 if (grandChild->QueryStringAttribute(
"A", &double_strings[3]) != TIXML_SUCCESS)
197 StringsToNumbers<double>(4, double_strings, rgba);
198 lut->SetTableValue(index, rgba);
203 catch (boost::bad_lexical_cast &e)
205 MITK_ERROR <<
"Could not parse string as number: " << e.what();
210 mitkLut->SetVtkLookupTable(lut);
BaseProperty::Pointer Deserialize(TiXmlElement *element) override
Deserializes given TiXmlElement.
The LookupTableProperty class Property to associate mitk::LookupTable to an mitk::DataNode.
Convenience class to temporarily change the current locale.
BaseProperty::ConstPointer m_Property
TiXmlElement * Serialize() override
Serializes given BaseData object.