Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkGradientDirectionsPropertySerializer.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 mitkGradientDirectionPropertySerializer_h_included
18 #define mitkGradientDirectionPropertySerializer_h_included
19 
21 
23 
25 
26 namespace mitk
27 {
28 
29 class MITKDIFFUSIONCORE_EXPORT GradientDirectionsPropertySerializer : public BasePropertySerializer
30 {
31  public:
32 
33  mitkClassMacro( GradientDirectionsPropertySerializer, BasePropertySerializer )
34  itkFactorylessNewMacro(Self)
35  itkCloneMacro(Self)
36 
37  virtual TiXmlElement* Serialize() override
38  {
39  if (const GradientDirectionsProperty* prop = dynamic_cast<const GradientDirectionsProperty*>(m_Property.GetPointer()))
40  {
41 
42  typedef mitk::GradientDirectionsProperty::GradientDirectionsContainerType GradientDirectionsContainerType;
43  GradientDirectionsContainerType::Pointer gdc = prop->GetGradientDirectionsContainer().GetPointer();
44 
45  if(gdc.IsNull() || gdc->Size() == 0) return nullptr;
46 
47 
48  GradientDirectionsContainerType::Iterator it = gdc->Begin();
49  GradientDirectionsContainerType::Iterator end = gdc->End();
50 
51  auto element = new TiXmlElement("gradientdirections");
52 
53  while (it != end) {
54  auto child = new TiXmlElement("entry");
55  std::stringstream ss;
56  ss << it.Value();
57  child->SetAttribute("value", ss.str());
58  element->InsertEndChild(*child);
59 
60  ++it;
61  }
62 
63  return element;
64  }
65  else return nullptr;
66  }
67 
68  virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) override
69  {
70  if (!element) return nullptr;
71 
74 
75  TiXmlElement* entry = element->FirstChildElement( "entry" )->ToElement();
76  while(entry != nullptr){
77 
78  std::stringstream ss;
79  std::string value;
80 
81  entry->QueryStringAttribute("value",&value);
82  ss << value;
83 
84  vnl_vector_fixed<double, 3> vector;
85  vector.read_ascii(ss);
86 
87  gdc->push_back(vector);
88 
89  entry = entry->NextSiblingElement( "entry" );
90  }
91 
92  return GradientDirectionsProperty::New(gdc).GetPointer();
93  }
94 
95  protected:
96 
97  GradientDirectionsPropertySerializer() {}
98  virtual ~GradientDirectionsPropertySerializer() {}
99 };
100 
101 } // namespace
102 
103 // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk')
104 MITK_REGISTER_SERIALIZER(GradientDirectionsPropertySerializer)
105 
106 #endif
#define MITK_REGISTER_SERIALIZER(classname)
itk::SmartPointer< Self > Pointer
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
#define MITKDIFFUSIONCORE_EXPORT
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
itk::VectorContainer< IndexType, GradientDirectionType > GradientDirectionsContainerType
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.