17 #ifndef mitkFloatLookupTablePropertySerializer_h_included
18 #define mitkFloatLookupTablePropertySerializer_h_included
22 #include <boost/lexical_cast.hpp>
27 class FloatLookupTablePropertySerializer :
public BasePropertySerializer
30 mitkClassMacro(FloatLookupTablePropertySerializer, BasePropertySerializer);
31 itkFactorylessNewMacro(Self) itkCloneMacro(Self)
33 virtual TiXmlElement *Serialize()
override
35 const FloatLookupTableProperty *prop =
dynamic_cast<const FloatLookupTableProperty *
>(m_Property.GetPointer());
39 LocaleSwitch localeSwitch(
"C");
41 FloatLookupTable lut = prop->GetValue();
46 auto element =
new TiXmlElement(
"FloatLookupTableTable");
47 for (
auto it = map.begin(); it != map.end(); ++it)
49 auto tableEntry =
new TiXmlElement(
"LUTValue");
50 tableEntry->SetAttribute(
"id", it->first);
51 tableEntry->SetAttribute(
"value", boost::lexical_cast<std::string>(it->second));
52 element->LinkEndChild(tableEntry);
62 LocaleSwitch localeSwitch(
"C");
65 for (TiXmlElement *child = element->FirstChildElement(
"LUTValue"); child !=
nullptr;
66 child = child->NextSiblingElement(
"LUTValue"))
69 if (child->QueryIntAttribute(
"id", &tempID) != TIXML_SUCCESS)
72 std::string value_string;
73 if (child->QueryStringAttribute(
"value", &value_string) != TIXML_SUCCESS)
77 lut.SetTableValue(
id, boost::lexical_cast<float>(value_string));
79 catch (boost::bad_lexical_cast &e)
81 MITK_ERROR <<
"Could not parse string as number: " << e.what();
89 FloatLookupTablePropertySerializer() {}
90 virtual ~FloatLookupTablePropertySerializer() {}
std::map< IdentifierType, ValueType > LookupTableType
MITK_REGISTER_SERIALIZER(FloatLookupTablePropertySerializer)
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
unsigned int IdentifierType
#define mitkClassMacro(className, SuperClassName)