13 #ifndef mitkLevelWindowPropertySerializer_h_included 14 #define mitkLevelWindowPropertySerializer_h_included 23 class LevelWindowPropertySerializer :
public BasePropertySerializer
26 mitkClassMacro(LevelWindowPropertySerializer, BasePropertySerializer);
27 itkFactorylessNewMacro(Self) itkCloneMacro(Self)
29 TiXmlElement *Serialize()
override 31 if (
const LevelWindowProperty *prop = dynamic_cast<const LevelWindowProperty *>(m_Property.GetPointer()))
33 LocaleSwitch localeSwitch(
"C");
35 auto element =
new TiXmlElement(
"LevelWindow");
37 LevelWindow lw = prop->GetLevelWindow();
38 std::string boolString(
"false");
39 if (lw.IsFixed() ==
true)
41 element->SetAttribute(
"fixed", boolString.c_str());
43 std::string boolStringFltImage(
"false");
44 if (lw.IsFloatingValues() ==
true)
45 boolStringFltImage =
"true";
46 element->SetAttribute(
"isFloatingImage", boolStringFltImage.c_str());
48 auto child =
new TiXmlElement(
"CurrentSettings");
49 element->LinkEndChild(child);
50 child->SetAttribute(
"level", boost::lexical_cast<std::string>(lw.GetLevel()));
51 child->SetAttribute(
"window", boost::lexical_cast<std::string>(lw.GetWindow()));
53 child =
new TiXmlElement(
"DefaultSettings");
54 element->LinkEndChild(child);
55 child->SetAttribute(
"level", boost::lexical_cast<std::string>(lw.GetDefaultLevel()));
56 child->SetAttribute(
"window", boost::lexical_cast<std::string>(lw.GetDefaultWindow()));
58 child =
new TiXmlElement(
"CurrentRange");
59 element->LinkEndChild(child);
60 child->SetAttribute(
"min", boost::lexical_cast<std::string>(lw.GetRangeMin()));
61 child->SetAttribute(
"max", boost::lexical_cast<std::string>(lw.GetRangeMax()));
74 LocaleSwitch localeSwitch(
"C");
77 if (element->Attribute(
"fixed"))
78 isFixed = std::string(element->Attribute(
"fixed")) ==
"true";
79 bool isFloatingImage(
false);
80 if (element->Attribute(
"isFloatingImage"))
81 isFloatingImage = std::string(element->Attribute(
"isFloatingImage")) ==
"true";
83 std::string level_string;
84 std::string window_string;
85 TiXmlElement *child = element->FirstChildElement(
"CurrentSettings");
86 if (child->QueryStringAttribute(
"level", &level_string) != TIXML_SUCCESS)
88 if (child->QueryStringAttribute(
"window", &window_string) != TIXML_SUCCESS)
91 std::string defaultLevel_string;
92 std::string defaultWindow_string;
93 child = element->FirstChildElement(
"DefaultSettings");
94 if (child->QueryStringAttribute(
"level", &defaultLevel_string) != TIXML_SUCCESS)
96 if (child->QueryStringAttribute(
"window", &defaultWindow_string) != TIXML_SUCCESS)
99 std::string minRange_string;
100 std::string maxRange_string;
101 child = element->FirstChildElement(
"CurrentRange");
102 if (child->QueryStringAttribute(
"min", &minRange_string) != TIXML_SUCCESS)
104 if (child->QueryStringAttribute(
"max", &maxRange_string) != TIXML_SUCCESS)
110 lw.SetRangeMinMax(boost::lexical_cast<double>(minRange_string), boost::lexical_cast<double>(maxRange_string));
111 lw.SetDefaultLevelWindow(boost::lexical_cast<double>(defaultLevel_string),
112 boost::lexical_cast<double>(defaultWindow_string));
113 lw.SetLevelWindow(boost::lexical_cast<double>(level_string), boost::lexical_cast<double>(window_string));
114 lw.SetFixed(isFixed);
115 lw.SetFloatingValues(isFloatingImage);
117 catch (boost::bad_lexical_cast &e)
119 MITK_ERROR <<
"Could not parse string as number: " << e.what();
126 LevelWindowPropertySerializer() {}
127 ~LevelWindowPropertySerializer()
override {}
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
MITK_REGISTER_SERIALIZER(LevelWindowPropertySerializer)
#define mitkClassMacro(className, SuperClassName)