14 #include <vtkObjectFactory.h> 24 const std::string AnatomicalStructureColorPresets::PRESET =
"preset";
25 const std::string AnatomicalStructureColorPresets::CATEGORY =
"category";
26 const std::string AnatomicalStructureColorPresets::TYPE =
"type";
27 const std::string AnatomicalStructureColorPresets::MODIFIER =
"modifier";
28 const std::string AnatomicalStructureColorPresets::COLOR =
"color";
30 const std::string AnatomicalStructureColorPresets::CODE_VALUE =
"code_value";
31 const std::string AnatomicalStructureColorPresets::CODE_SCHEME =
"coding_scheme";
32 const std::string AnatomicalStructureColorPresets::CODE_NAME =
"code_name";
34 const std::string AnatomicalStructureColorPresets::COLOR_R =
"rgb_r";
35 const std::string AnatomicalStructureColorPresets::COLOR_G =
"rgb_g";
36 const std::string AnatomicalStructureColorPresets::COLOR_B =
"rgb_b";
44 if (!presetResource)
return false;
47 vtkXMLParser::SetStream(&presetStream);
48 if (!vtkXMLParser::Parse())
51 MITK_INFO<<
"AnatomicalStructureColorPresets::LoadPreset xml file cannot parse!"<<std::endl;
63 vtkXMLParser::SetFileName(fileName.c_str());
65 if (!vtkXMLParser::Parse())
68 MITK_INFO<<
"AnatomicalStructureColorPresets::LoadPreset xml file cannot parse!"<<std::endl;
76 void AnatomicalStructureColorPresets::StartElement(
const char *elementName,
const char **atts)
78 std::string elementNameString = elementName;
79 if (elementNameString == PRESET)
81 m_presetName = ReadXMLStringAttribute(
"name", atts);
83 else if (elementNameString == CATEGORY)
85 std::string value = ReadXMLStringAttribute(CODE_VALUE, atts);
86 std::string scheme = ReadXMLStringAttribute(CODE_SCHEME, atts);
87 std::string name = ReadXMLStringAttribute(CODE_NAME, atts);
88 m_Category[m_presetName] =
Category(value, scheme, name);
90 else if (elementNameString == TYPE)
92 std::string value = ReadXMLStringAttribute(CODE_VALUE, atts);
93 std::string scheme = ReadXMLStringAttribute(CODE_SCHEME, atts);
94 std::string name = ReadXMLStringAttribute(CODE_NAME, atts);
95 m_Type[m_presetName] =
Type(value, scheme, name);
97 else if (elementNameString == MODIFIER)
99 std::string value = ReadXMLStringAttribute(CODE_VALUE, atts);
100 std::string scheme = ReadXMLStringAttribute(CODE_SCHEME, atts);
101 std::string name = ReadXMLStringAttribute(CODE_NAME, atts);
102 m_Type[m_presetName].modifier =
Type::Modifier(value, scheme, name);
104 else if (elementNameString == COLOR)
106 std::string red = ReadXMLStringAttribute(COLOR_R, atts);
107 float r = atof(red.c_str());
108 std::string green = ReadXMLStringAttribute(COLOR_G, atts);
109 float g = atof(green.c_str());
110 std::string blue = ReadXMLStringAttribute(COLOR_B, atts);
111 float b = atof(blue.c_str());
113 color.SetRed(r); color.SetGreen(g); color.SetBlue(b);
114 m_Color[m_presetName] = color;
118 std::string AnatomicalStructureColorPresets::ReadXMLStringAttribute(
const std::string& name,
const char **atts)
122 const char** attsIter = atts;
124 while (*attsIter !=
nullptr)
126 if (name == *attsIter)
128 return *(++attsIter);
134 return std::string();
139 return m_Category[name];
149 return m_Color[name];
167 void AnatomicalStructureColorPresets::Save()
172 void AnatomicalStructureColorPresets::NewPresets(std::map<std::string, AnatomicalStructureColorPresets::Category>& newCategory, std::map<std::string, AnatomicalStructureColorPresets::Type>& newType, std::map<std::string, Color>& newColor)
174 m_Category = newCategory;
std::map< std::string, Color > const GetColorPresets()
DataCollection - Class to facilitate loading/accessing structured data.
Type GetType(const std::string &name)
Category GetCategory(const std::string &name)
void NewPresets(std::map< std::string, Category > &newCategory, std::map< std::string, Type > &newType, std::map< std::string, Color > &newColor)
std::map< std::string, Type > const GetTypePresets()
Module * GetModule() const
vtkStandardNewMacro(AnatomicalStructureColorPresets)
Color GetColor(const std::string &name)
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
std::map< std::string, Category > const GetCategoryPresets()
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.