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
mitkLevelWindowPreset.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 #include "mitkLevelWindowPreset.h"
18 #include <vtkObjectFactory.h>
19 
20 #include "usGetModuleContext.h"
21 #include "usModule.h"
22 #include "usModuleContext.h"
23 #include "usModuleResource.h"
24 #include "usModuleResourceStream.h"
25 
26 namespace mitk
27 {
28  const std::string LevelWindowPreset::PRESET = "preset";
29 
30  vtkStandardNewMacro(LevelWindowPreset);
31 
35  {
36  us::ModuleResource presetResource = us::GetModuleContext()->GetModule()->GetResource("mitkLevelWindowPresets.xml");
37  if (!presetResource)
38  return false;
39 
40  us::ModuleResourceStream presetStream(presetResource);
41  vtkXMLParser::SetStream(&presetStream);
42  if (!vtkXMLParser::Parse())
43  {
44 #ifdef INTERDEBUG
45  MITK_INFO << "LevelWindowPreset::LoadPreset xml file cannot parse!" << std::endl;
46 #endif
47  return false;
48  }
49  return true;
50  }
51 
52  bool LevelWindowPreset::LoadPreset(std::string fileName)
53  {
54  if (fileName.empty())
55  return false;
56 
57  vtkXMLParser::SetFileName(fileName.c_str());
58 
59  if (!vtkXMLParser::Parse())
60  {
61 #ifdef INTERDEBUG
62  MITK_INFO << "LevelWindowPreset::LoadPreset xml file cannot parse!" << std::endl;
63 #endif
64  }
65 
66  return true;
67  }
68 
69  void LevelWindowPreset::StartElement(const char *elementName, const char **atts)
70  {
71  std::string elementNameString = elementName;
72  if (elementNameString == PRESET)
73  {
74  std::string name = ReadXMLStringAttribut("NAME", atts);
75  std::string level = ReadXMLStringAttribut("LEVEL", atts);
76  double lev = atof(level.c_str());
77  std::string window = ReadXMLStringAttribut("WINDOW", atts);
78  double win = atof(window.c_str());
79  m_Level[name] = lev;
80  m_Window[name] = win;
81  }
82  }
83 
84  std::string LevelWindowPreset::ReadXMLStringAttribut(std::string name, const char **atts)
85  {
86  if (atts)
87  {
88  const char **attsIter = atts;
89 
90  while (*attsIter)
91  {
92  if (name == *attsIter)
93  {
94  attsIter++;
95  return *attsIter;
96  }
97  attsIter++;
98  attsIter++;
99  }
100  }
101 
102  return std::string();
103  }
104 
105  double LevelWindowPreset::getLevel(std::string name) { return m_Level[name]; }
106  double LevelWindowPreset::getWindow(std::string name) { return m_Window[name]; }
107  std::map<std::string, double> &LevelWindowPreset::getLevelPresets() { return m_Level; }
108  std::map<std::string, double> &LevelWindowPreset::getWindowPresets() { return m_Window; }
109  void LevelWindowPreset::save()
110  {
111  // XMLWriter writer(m_XmlFileName.c_str());
112  // saveXML(writer);
113  }
114 
115  void LevelWindowPreset::newPresets(std::map<std::string, double> newLevel, std::map<std::string, double> newWindow)
116  {
117  m_Level = newLevel;
118  m_Window = newWindow;
119  save();
120  }
121 }
#define MITK_INFO
Definition: mitkLogMacros.h:22
DataCollection - Class to facilitate loading/accessing structured data.
std::map< std::string, double > & getLevelPresets()
Module * GetModule() const
void newPresets(std::map< std::string, double > newLevel, std::map< std::string, double > newWindow)
vtkStandardNewMacro(AnatomicalStructureColorPresets)
double getWindow(std::string window)
std::map< std::string, double > & getWindowPresets()
double getLevel(std::string name)
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.