17 #ifndef mitkLevelWindowPropertySerializer_h_included
18 #define mitkLevelWindowPropertySerializer_h_included
22 #include <boost/lexical_cast.hpp>
27 class LevelWindowPropertySerializer :
public BasePropertySerializer
30 mitkClassMacro(LevelWindowPropertySerializer, BasePropertySerializer);
31 itkFactorylessNewMacro(Self) itkCloneMacro(Self)
33 virtual TiXmlElement *Serialize()
override
35 if (
const LevelWindowProperty *prop = dynamic_cast<const LevelWindowProperty *>(m_Property.GetPointer()))
37 LocaleSwitch localeSwitch(
"C");
39 auto element =
new TiXmlElement(
"LevelWindow");
41 LevelWindow lw = prop->GetLevelWindow();
42 std::string boolString(
"false");
43 if (lw.IsFixed() ==
true)
45 element->SetAttribute(
"fixed", boolString.c_str());
47 std::string boolStringFltImage(
"false");
48 if (lw.IsFloatingValues() ==
true)
49 boolStringFltImage =
"true";
50 element->SetAttribute(
"isFloatingImage", boolStringFltImage.c_str());
52 auto child =
new TiXmlElement(
"CurrentSettings");
53 element->LinkEndChild(child);
54 child->SetAttribute(
"level", boost::lexical_cast<std::string>(lw.GetLevel()));
55 child->SetAttribute(
"window", boost::lexical_cast<std::string>(lw.GetWindow()));
57 child =
new TiXmlElement(
"DefaultSettings");
58 element->LinkEndChild(child);
59 child->SetAttribute(
"level", boost::lexical_cast<std::string>(lw.GetDefaultLevel()));
60 child->SetAttribute(
"window", boost::lexical_cast<std::string>(lw.GetDefaultWindow()));
62 child =
new TiXmlElement(
"CurrentRange");
63 element->LinkEndChild(child);
64 child->SetAttribute(
"min", boost::lexical_cast<std::string>(lw.GetRangeMin()));
65 child->SetAttribute(
"max", boost::lexical_cast<std::string>(lw.GetRangeMax()));
78 LocaleSwitch localeSwitch(
"C");
81 if (element->Attribute(
"fixed"))
82 isFixed = std::string(element->Attribute(
"fixed")) ==
"true";
83 bool isFloatingImage(
false);
84 if (element->Attribute(
"isFloatingImage"))
85 isFloatingImage = std::string(element->Attribute(
"isFloatingImage")) ==
"true";
87 std::string level_string;
88 std::string window_string;
89 TiXmlElement *child = element->FirstChildElement(
"CurrentSettings");
90 if (child->QueryStringAttribute(
"level", &level_string) != TIXML_SUCCESS)
92 if (child->QueryStringAttribute(
"window", &window_string) != TIXML_SUCCESS)
95 std::string defaultLevel_string;
96 std::string defaultWindow_string;
97 child = element->FirstChildElement(
"DefaultSettings");
98 if (child->QueryStringAttribute(
"level", &defaultLevel_string) != TIXML_SUCCESS)
100 if (child->QueryStringAttribute(
"window", &defaultWindow_string) != TIXML_SUCCESS)
103 std::string minRange_string;
104 std::string maxRange_string;
105 child = element->FirstChildElement(
"CurrentRange");
106 if (child->QueryStringAttribute(
"min", &minRange_string) != TIXML_SUCCESS)
108 if (child->QueryStringAttribute(
"max", &maxRange_string) != TIXML_SUCCESS)
114 lw.SetRangeMinMax(boost::lexical_cast<double>(minRange_string), boost::lexical_cast<double>(maxRange_string));
115 lw.SetDefaultLevelWindow(boost::lexical_cast<double>(defaultLevel_string),
116 boost::lexical_cast<double>(defaultWindow_string));
117 lw.SetLevelWindow(boost::lexical_cast<double>(level_string), boost::lexical_cast<double>(window_string));
118 lw.SetFixed(isFixed);
119 lw.SetFloatingValues(isFloatingImage);
121 catch (boost::bad_lexical_cast &e)
123 MITK_ERROR <<
"Could not parse string as number: " << e.what();
130 LevelWindowPropertySerializer() {}
131 virtual ~LevelWindowPropertySerializer() {}
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
MITK_REGISTER_SERIALIZER(LevelWindowPropertySerializer)
#define mitkClassMacro(className, SuperClassName)