17 #ifndef mitkClippingPropertySerializer_h_included
18 #define mitkClippingPropertySerializer_h_included
29 class ClippingPropertySerializer :
public BasePropertySerializer
32 mitkClassMacro(ClippingPropertySerializer, BasePropertySerializer);
33 itkFactorylessNewMacro(Self) itkCloneMacro(Self)
35 virtual TiXmlElement *Serialize()
override
37 if (
const ClippingProperty *prop = dynamic_cast<const ClippingProperty *>(m_Property.GetPointer()))
39 LocaleSwitch localeSwitch(
"C");
41 auto element =
new TiXmlElement(
"clipping");
42 if (prop->GetClippingEnabled())
43 element->SetAttribute(
"enabled",
"true");
45 element->SetAttribute(
"enabled",
"false");
46 auto originElement =
new TiXmlElement(
"origin");
47 const Point3D origin = prop->GetOrigin();
48 originElement->SetAttribute(
"x", boost::lexical_cast<std::string>(origin[0]));
49 originElement->SetAttribute(
"y", boost::lexical_cast<std::string>(origin[1]));
50 originElement->SetAttribute(
"z", boost::lexical_cast<std::string>(origin[2]));
51 element->LinkEndChild(originElement);
52 auto normalElement =
new TiXmlElement(
"normal");
53 const Vector3D normal = prop->GetNormal();
54 normalElement->SetAttribute(
"x", boost::lexical_cast<std::string>(normal[0]));
55 normalElement->SetAttribute(
"y", boost::lexical_cast<std::string>(normal[1]));
56 normalElement->SetAttribute(
"z", boost::lexical_cast<std::string>(normal[2]));
57 element->LinkEndChild(normalElement);
69 LocaleSwitch localeSwitch(
"C");
71 bool enabled = std::string(element->Attribute(
"enabled")) ==
"true";
73 TiXmlElement *originElement = element->FirstChildElement(
"origin");
74 if (originElement ==
nullptr)
76 std::string origin_string[3];
77 if (originElement->QueryStringAttribute(
"x", &origin_string[0]) != TIXML_SUCCESS)
79 if (originElement->QueryStringAttribute(
"y", &origin_string[1]) != TIXML_SUCCESS)
81 if (originElement->QueryStringAttribute(
"z", &origin_string[2]) != TIXML_SUCCESS)
86 StringsToNumbers<ScalarType>(3, origin_string, origin);
88 catch (boost::bad_lexical_cast &e)
90 MITK_ERROR <<
"Could not parse string as number: " << e.what();
94 TiXmlElement *normalElement = element->FirstChildElement(
"normal");
95 if (normalElement ==
nullptr)
97 std::string normal_string[3];
98 if (normalElement->QueryStringAttribute(
"x", &normal_string[0]) != TIXML_SUCCESS)
100 if (normalElement->QueryStringAttribute(
"y", &normal_string[1]) != TIXML_SUCCESS)
102 if (normalElement->QueryStringAttribute(
"z", &normal_string[2]) != TIXML_SUCCESS)
107 StringsToNumbers<ScalarType>(3, normal_string, normal);
109 catch (boost::bad_lexical_cast &e)
111 MITK_ERROR <<
"Could not parse string as number: " << e.what();
116 cp->SetClippingEnabled(enabled);
117 return cp.GetPointer();
121 ClippingPropertySerializer() {}
122 virtual ~ClippingPropertySerializer() {}
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
itk::SmartPointer< Self > Pointer
Vector< ScalarType, 3 > Vector3D
#define mitkClassMacro(className, SuperClassName)
Point< ScalarType, 3 > Point3D
MITK_REGISTER_SERIALIZER(ClippingPropertySerializer)