Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkBValueMapPropertySerializer.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 mitkBValueMapPropertySerializer_h_included
18 #define mitkBValueMapPropertySerializer_h_included
19 
21 
22 #include "mitkBValueMapProperty.h"
23 
25 
26 namespace mitk
27 {
28 
29 class MITKDIFFUSIONCORE_EXPORT BValueMapPropertySerializer : public BasePropertySerializer
30 {
31 
32 protected:
33 
34 
35  void split(const std::string &s, char delim, std::vector<unsigned int> &elems) {
36  std::stringstream ss(s);
37  std::string item;
38  while (std::getline(ss, item, delim)) {
39  elems.push_back(std::atoi(item.c_str()));
40  }
41  }
42 
43  std::vector<unsigned int> split(const std::string &s, char delim) {
44  std::vector<unsigned int> elems;
45  split(s, delim, elems);
46  return elems;
47  }
48 
49 public:
50 
51  mitkClassMacro( BValueMapPropertySerializer, BasePropertySerializer )
52  itkFactorylessNewMacro(Self)
53  itkCloneMacro(Self)
54 
55  virtual TiXmlElement* Serialize() override
56  {
57  if (const BValueMapProperty* prop = dynamic_cast<const BValueMapProperty*>(m_Property.GetPointer()))
58  {
59 
60  BValueMapProperty::BValueMap map = prop->GetBValueMap();
61 
62  if(map.empty()) return nullptr;
63 
64  BValueMapProperty::BValueMap::const_iterator it = map.begin();
65  BValueMapProperty::BValueMap::const_iterator end = map.end();
66 
67  auto element = new TiXmlElement("bvaluemap");
68 
69 
70 
71  while (it != end) {
72  auto child = new TiXmlElement("entry");
73  {
74  std::stringstream ss;
75  ss << it->first;
76  child->SetAttribute("key", ss.str());
77  }
78 
79  {
80  std::stringstream ss;
81  for(unsigned int i = 0 ; i < it->second.size(); i++)
82  {
83 
84  ss << it->second[i] << ",";
85  }
86  child->SetAttribute("value", ss.str());
87  }
88  element->InsertEndChild(*child);
89  ++it;
90  }
91 
92  return element;
93  }
94  else return nullptr;
95  }
96 
97 
98  virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) override
99  {
100  if (!element) return nullptr;
101 
103 
104  TiXmlElement* entry = element->FirstChildElement( "entry" )->ToElement();
105  while(entry != nullptr){
106 
107  std::string key, value;
108  entry->QueryStringAttribute("key",&key);
109  entry->QueryStringAttribute("value",&value);
110 
111  std::vector<unsigned int> indices = split(value.c_str(), ',');
112 
113  map[std::atoi(key.c_str())] = indices;
114  entry = entry->NextSiblingElement( "entry" );
115  }
116 
117  return BValueMapProperty::New(map).GetPointer();
118  }
119 
120 protected:
121 
122  BValueMapPropertySerializer(){}
123  virtual ~BValueMapPropertySerializer() {}
124 };
125 
126 } // namespace
127 
128 // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk')
129 MITK_REGISTER_SERIALIZER(BValueMapPropertySerializer)
130 
131 #endif
#define MITK_REGISTER_SERIALIZER(classname)
std::map< unsigned int, std::vector< unsigned int > > BValueMap
The BValueMap contains seperated IndicesVectors for each b value (index for GradientDirectionContaine...
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
#define MITKDIFFUSIONCORE_EXPORT
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=NULL, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
static std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.