Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkMeasurementFramePropertySerializer.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef mitkMeasurementFramePropertySerializer_h_included
18 #define mitkMeasurementFramePropertySerializer_h_included
19 
21 
23 
25 
26 namespace mitk
27 {
28 
29 class MITKDIFFUSIONCORE_EXPORT MeasurementFramePropertySerializer : public BasePropertySerializer
30 {
31  public:
32 
33  mitkClassMacro( MeasurementFramePropertySerializer, BasePropertySerializer )
34  itkFactorylessNewMacro(Self)
35  itkCloneMacro(Self)
36 
37  virtual TiXmlElement* Serialize() override
38  {
39  if (const MeasurementFrameProperty* prop = dynamic_cast<const MeasurementFrameProperty*>(m_Property.GetPointer()))
40  {
41 
42  typedef mitk::MeasurementFrameProperty::MeasurementFrameType MeasurementFrameType;
43  const MeasurementFrameType & mft = prop->GetMeasurementFrame();
44 
45  if(mft.is_zero()) return nullptr;
46 
47  auto element = new TiXmlElement("measurementframe");
48 
49  auto child = new TiXmlElement("entry");
50  std::stringstream ss;
51  ss << mft;
52  child->SetAttribute("value", ss.str());
53  element->InsertEndChild(*child);
54 
55  return element;
56  }
57  else return nullptr;
58  }
59 
60  virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) override
61  {
62  if (!element) return nullptr;
63 
64  TiXmlElement* entry = element->FirstChildElement( "entry" )->ToElement();
65 
66  std::stringstream ss;
67  std::string value;
68 
69  entry->QueryStringAttribute("value",&value);
70  ss << value;
71 
73  matrix.read_ascii(ss);
74 
75  return MeasurementFrameProperty::New(matrix).GetPointer();
76  }
77 
78  protected:
79 
80  MeasurementFramePropertySerializer() {}
81  virtual ~MeasurementFramePropertySerializer() {}
82 };
83 
84 } // namespace
85 
86 // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk')
87 MITK_REGISTER_SERIALIZER(MeasurementFramePropertySerializer)
88 
89 #endif
#define MITK_REGISTER_SERIALIZER(classname)
vnl_matrix_fixed< double, 3, 3 > MeasurementFrameType
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
#define MITKDIFFUSIONCORE_EXPORT
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.