13 #ifndef mitkClippingPropertySerializer_h_included 14 #define mitkClippingPropertySerializer_h_included 25 class ClippingPropertySerializer :
public BasePropertySerializer
28 mitkClassMacro(ClippingPropertySerializer, BasePropertySerializer);
29 itkFactorylessNewMacro(Self) itkCloneMacro(Self)
31 TiXmlElement *Serialize()
override 33 if (
const ClippingProperty *prop = dynamic_cast<const ClippingProperty *>(m_Property.GetPointer()))
35 LocaleSwitch localeSwitch(
"C");
37 auto element =
new TiXmlElement(
"clipping");
38 if (prop->GetClippingEnabled())
39 element->SetAttribute(
"enabled",
"true");
41 element->SetAttribute(
"enabled",
"false");
42 auto originElement =
new TiXmlElement(
"origin");
43 const Point3D origin = prop->GetOrigin();
44 originElement->SetAttribute(
"x", boost::lexical_cast<std::string>(origin[0]));
45 originElement->SetAttribute(
"y", boost::lexical_cast<std::string>(origin[1]));
46 originElement->SetAttribute(
"z", boost::lexical_cast<std::string>(origin[2]));
47 element->LinkEndChild(originElement);
48 auto normalElement =
new TiXmlElement(
"normal");
49 const Vector3D normal = prop->GetNormal();
50 normalElement->SetAttribute(
"x", boost::lexical_cast<std::string>(normal[0]));
51 normalElement->SetAttribute(
"y", boost::lexical_cast<std::string>(normal[1]));
52 normalElement->SetAttribute(
"z", boost::lexical_cast<std::string>(normal[2]));
53 element->LinkEndChild(normalElement);
65 LocaleSwitch localeSwitch(
"C");
67 bool enabled = std::string(element->Attribute(
"enabled")) ==
"true";
69 TiXmlElement *originElement = element->FirstChildElement(
"origin");
70 if (originElement ==
nullptr)
72 std::string origin_string[3];
73 if (originElement->QueryStringAttribute(
"x", &origin_string[0]) != TIXML_SUCCESS)
75 if (originElement->QueryStringAttribute(
"y", &origin_string[1]) != TIXML_SUCCESS)
77 if (originElement->QueryStringAttribute(
"z", &origin_string[2]) != TIXML_SUCCESS)
82 StringsToNumbers<ScalarType>(3, origin_string, origin);
84 catch (boost::bad_lexical_cast &e)
86 MITK_ERROR <<
"Could not parse string as number: " << e.what();
90 TiXmlElement *normalElement = element->FirstChildElement(
"normal");
91 if (normalElement ==
nullptr)
93 std::string normal_string[3];
94 if (normalElement->QueryStringAttribute(
"x", &normal_string[0]) != TIXML_SUCCESS)
96 if (normalElement->QueryStringAttribute(
"y", &normal_string[1]) != TIXML_SUCCESS)
98 if (normalElement->QueryStringAttribute(
"z", &normal_string[2]) != TIXML_SUCCESS)
103 StringsToNumbers<ScalarType>(3, normal_string, normal);
105 catch (boost::bad_lexical_cast &e)
107 MITK_ERROR <<
"Could not parse string as number: " << e.what();
112 cp->SetClippingEnabled(enabled);
113 return cp.GetPointer();
117 ClippingPropertySerializer() {}
118 ~ClippingPropertySerializer()
override {}
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)