17 #ifndef mitkColorPropertySerializer_h_included
18 #define mitkColorPropertySerializer_h_included
27 class ColorPropertySerializer :
public BasePropertySerializer
31 itkFactorylessNewMacro(Self) itkCloneMacro(Self)
33 virtual TiXmlElement *Serialize()
override
35 if (
const ColorProperty *prop = dynamic_cast<const ColorProperty *>(m_Property.GetPointer()))
37 LocaleSwitch localeSwitch(
"C");
39 auto element =
new TiXmlElement(
"color");
40 Color color = prop->GetValue();
41 element->SetAttribute(
"r", boost::lexical_cast<std::string>(color[0]));
42 element->SetAttribute(
"g", boost::lexical_cast<std::string>(color[1]));
43 element->SetAttribute(
"b", boost::lexical_cast<std::string>(color[2]));
55 LocaleSwitch localeSwitch(
"C");
57 std::string c_string[3];
58 if (element->QueryStringAttribute(
"r", &c_string[0]) != TIXML_SUCCESS)
60 if (element->QueryStringAttribute(
"g", &c_string[1]) != TIXML_SUCCESS)
62 if (element->QueryStringAttribute(
"b", &c_string[2]) != TIXML_SUCCESS)
67 StringsToNumbers<double>(3, c_string, c);
69 catch (boost::bad_lexical_cast &e)
71 MITK_ERROR <<
"Could not parse string as number: " << e.what();
79 ColorPropertySerializer() {}
80 virtual ~ColorPropertySerializer() {}
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)