17 #ifndef mitkVectorPropertySerializer_h
18 #define mitkVectorPropertySerializer_h
24 #include <boost/lexical_cast.hpp>
47 template <
typename DATATYPE>
60 virtual std::vector<std::string>
GetClassHierarchy()
const override {
return mitk::GetClassHierarchy<Self>(); }
67 static std::string nameOfClass =
69 return nameOfClass.c_str();
73 itkFactorylessNewMacro(Self);
77 virtual TiXmlElement *Serialize()
override
79 auto listElement =
new TiXmlElement(
"Values");
81 if (
const PropertyType *prop = dynamic_cast<const PropertyType *>(m_Property.GetPointer()))
84 unsigned int index(0);
85 for (
auto listEntry : elements)
87 std::stringstream indexS;
90 auto entryElement =
new TiXmlElement(
"Value");
91 entryElement->SetAttribute(
"idx", indexS.str());
92 entryElement->SetAttribute(
"value", boost::lexical_cast<std::string>(listEntry));
93 listElement->LinkEndChild(entryElement);
111 MITK_DEBUG <<
"Deserializing " << *listElement;
113 unsigned int index(0);
114 std::string valueString;
116 for (TiXmlElement *valueElement = listElement->FirstChildElement(
"Value"); valueElement;
117 valueElement = valueElement->NextSiblingElement(
"Value"))
119 if (valueElement->QueryValueAttribute(
"value", &valueString) != TIXML_SUCCESS)
121 MITK_ERROR <<
"Missing value attribute in <Values> list";
127 value = boost::lexical_cast<DATATYPE>(valueString);
129 catch (boost::bad_lexical_cast &e)
131 MITK_ERROR <<
"Could not parse '" << valueString <<
"' as number: " << e.what();
135 datalist.push_back(value);
140 property->SetValue(datalist);
141 return property.GetPointer();
static const char * GetStaticNameOfClass()
BasePropertySerializer SuperClass
Helper for VectorProperty to determine a good ITK ClassName.
itk::SmartPointer< const Self > ConstPointer
virtual const char * GetNameOfClass() const override
itk::SmartPointer< Self > Pointer
DataCollection - Class to facilitate loading/accessing structured data.
VectorPropertySerializer< DATATYPE > Self
Serializes a VectorProperty.
VectorPropertySerializer< double > DoubleVectorPropertySerializer
static const char * GetStaticNameOfClass()
virtual BaseProperty::Pointer Deserialize(TiXmlElement *listElement) override
Construct a property from an XML serialization.
Base class for objects that serialize BaseProperty types.
std::vector< DATATYPE > VectorType
Providing a std::vector as property.
#define MITKSCENESERIALIZATIONBASE_EXPORT
VectorPropertySerializer< int > IntVectorPropertySerializer
VectorProperty< DATATYPE > PropertyType
virtual std::vector< std::string > GetClassHierarchy() const override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.