Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkPoint3iPropertySerializer_h_included
14 #define mitkPoint3iPropertySerializer_h_included
15 
17 #include "mitkProperties.h"
18 
19 namespace mitk
20 {
21  class Point3iPropertySerializer : public BasePropertySerializer
22  {
23  public:
24  mitkClassMacro(Point3iPropertySerializer, BasePropertySerializer);
25  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
26 
27  TiXmlElement *Serialize() override
28  {
29  if (const Point3iProperty *prop = dynamic_cast<const Point3iProperty *>(m_Property.GetPointer()))
30  {
31  auto element = new TiXmlElement("point");
32  Point3I point = prop->GetValue();
33  element->SetAttribute("x", point[0]);
34  element->SetAttribute("y", point[1]);
35  element->SetAttribute("z", point[2]);
36  return element;
37  }
38  else
39  return nullptr;
40  }
41 
42  BaseProperty::Pointer Deserialize(TiXmlElement *element) override
43  {
44  if (!element)
45  return nullptr;
46 
47  Point3I v;
48  if (element->QueryIntAttribute("x", &v[0]) != TIXML_SUCCESS)
49  return nullptr;
50  if (element->QueryIntAttribute("y", &v[1]) != TIXML_SUCCESS)
51  return nullptr;
52  if (element->QueryIntAttribute("z", &v[2]) != TIXML_SUCCESS)
53  return nullptr;
54  return Point3iProperty::New(v).GetPointer();
55  }
56 
57  protected:
58  Point3iPropertySerializer() {}
59  ~Point3iPropertySerializer() override {}
60  };
61 } // namespace
62 // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk')
63 MITK_REGISTER_SERIALIZER(Point3iPropertySerializer);
64 #endif
Point< int, 3 > Point3I
Definition: mitkPoint.h:99
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
MITK_REGISTER_SERIALIZER(Point3iPropertySerializer)
static Pointer New()