13 #ifndef mitkColorPropertySerializer_h_included 14 #define mitkColorPropertySerializer_h_included 23 class ColorPropertySerializer :
public BasePropertySerializer
27 itkFactorylessNewMacro(Self) itkCloneMacro(Self)
29 TiXmlElement *Serialize()
override 31 if (
const ColorProperty *prop = dynamic_cast<const ColorProperty *>(m_Property.GetPointer()))
33 LocaleSwitch localeSwitch(
"C");
35 auto element =
new TiXmlElement(
"color");
36 Color color = prop->GetValue();
37 element->SetAttribute(
"r", boost::lexical_cast<std::string>(color[0]));
38 element->SetAttribute(
"g", boost::lexical_cast<std::string>(color[1]));
39 element->SetAttribute(
"b", boost::lexical_cast<std::string>(color[2]));
51 LocaleSwitch localeSwitch(
"C");
53 std::string c_string[3];
54 if (element->QueryStringAttribute(
"r", &c_string[0]) != TIXML_SUCCESS)
56 if (element->QueryStringAttribute(
"g", &c_string[1]) != TIXML_SUCCESS)
58 if (element->QueryStringAttribute(
"b", &c_string[2]) != TIXML_SUCCESS)
63 StringsToNumbers<double>(3, c_string, c);
65 catch (boost::bad_lexical_cast &e)
67 MITK_ERROR <<
"Could not parse string as number: " << e.what();
75 ColorPropertySerializer() {}
76 ~ColorPropertySerializer()
override {}
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
#define mitkClassMacro(className, SuperClassName)
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
MITK_REGISTER_SERIALIZER(ColorPropertySerializer)