Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPoint3iPropertySerializer.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 mitkPoint3iPropertySerializer_h_included
18 #define mitkPoint3iPropertySerializer_h_included
19 
21 #include "mitkProperties.h"
22 
23 namespace mitk
24 {
25  class Point3iPropertySerializer : public BasePropertySerializer
26  {
27  public:
28  mitkClassMacro(Point3iPropertySerializer, BasePropertySerializer);
29  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
30 
31  virtual TiXmlElement *Serialize() override
32  {
33  if (const Point3iProperty *prop = dynamic_cast<const Point3iProperty *>(m_Property.GetPointer()))
34  {
35  auto element = new TiXmlElement("point");
36  Point3I point = prop->GetValue();
37  element->SetAttribute("x", point[0]);
38  element->SetAttribute("y", point[1]);
39  element->SetAttribute("z", point[2]);
40  return element;
41  }
42  else
43  return nullptr;
44  }
45 
46  virtual BaseProperty::Pointer Deserialize(TiXmlElement *element) override
47  {
48  if (!element)
49  return nullptr;
50 
51  Point3I v;
52  if (element->QueryIntAttribute("x", &v[0]) != TIXML_SUCCESS)
53  return nullptr;
54  if (element->QueryIntAttribute("y", &v[1]) != TIXML_SUCCESS)
55  return nullptr;
56  if (element->QueryIntAttribute("z", &v[2]) != TIXML_SUCCESS)
57  return nullptr;
58  return Point3iProperty::New(v).GetPointer();
59  }
60 
61  protected:
62  Point3iPropertySerializer() {}
63  virtual ~Point3iPropertySerializer() {}
64  };
65 } // namespace
66 // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk')
67 MITK_REGISTER_SERIALIZER(Point3iPropertySerializer);
68 #endif
Point< int, 3 > Point3I
Definition: mitkPoint.h:103
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
MITK_REGISTER_SERIALIZER(Point3iPropertySerializer)
static Pointer New()