18 #include <vtkObjectFactory.h>
28 const std::string AnatomicalStructureColorPresets::PRESET =
"preset";
29 const std::string AnatomicalStructureColorPresets::CATEGORY =
"category";
30 const std::string AnatomicalStructureColorPresets::TYPE =
"type";
31 const std::string AnatomicalStructureColorPresets::MODIFIER =
"modifier";
32 const std::string AnatomicalStructureColorPresets::COLOR =
"color";
34 const std::string AnatomicalStructureColorPresets::CODE_VALUE =
"code_value";
35 const std::string AnatomicalStructureColorPresets::CODE_SCHEME =
"coding_scheme";
36 const std::string AnatomicalStructureColorPresets::CODE_NAME =
"code_name";
38 const std::string AnatomicalStructureColorPresets::COLOR_R =
"rgb_r";
39 const std::string AnatomicalStructureColorPresets::COLOR_G =
"rgb_g";
40 const std::string AnatomicalStructureColorPresets::COLOR_B =
"rgb_b";
48 if (!presetResource)
return false;
51 vtkXMLParser::SetStream(&presetStream);
52 if (!vtkXMLParser::Parse())
55 MITK_INFO<<
"AnatomicalStructureColorPresets::LoadPreset xml file cannot parse!"<<std::endl;
67 vtkXMLParser::SetFileName(fileName.c_str());
69 if (!vtkXMLParser::Parse())
72 MITK_INFO<<
"AnatomicalStructureColorPresets::LoadPreset xml file cannot parse!"<<std::endl;
80 void AnatomicalStructureColorPresets::StartElement(
const char *elementName,
const char **atts)
82 std::string elementNameString = elementName;
83 if (elementNameString == PRESET)
85 m_presetName = ReadXMLStringAttribute(
"name", atts);
87 else if (elementNameString == CATEGORY)
89 std::string value = ReadXMLStringAttribute(CODE_VALUE, atts);
90 std::string scheme = ReadXMLStringAttribute(CODE_SCHEME, atts);
91 std::string name = ReadXMLStringAttribute(CODE_NAME, atts);
92 m_Category[m_presetName] = Category(value, scheme, name);
94 else if (elementNameString == TYPE)
96 std::string value = ReadXMLStringAttribute(CODE_VALUE, atts);
97 std::string scheme = ReadXMLStringAttribute(CODE_SCHEME, atts);
98 std::string name = ReadXMLStringAttribute(CODE_NAME, atts);
99 m_Type[m_presetName] = Type(value, scheme, name);
101 else if (elementNameString == MODIFIER)
103 std::string value = ReadXMLStringAttribute(CODE_VALUE, atts);
104 std::string scheme = ReadXMLStringAttribute(CODE_SCHEME, atts);
105 std::string name = ReadXMLStringAttribute(CODE_NAME, atts);
106 m_Type[m_presetName].modifier = Type::Modifier(value, scheme, name);
108 else if (elementNameString == COLOR)
110 std::string red = ReadXMLStringAttribute(COLOR_R, atts);
111 float r = atof(red.c_str());
112 std::string green = ReadXMLStringAttribute(COLOR_G, atts);
113 float g = atof(green.c_str());
114 std::string blue = ReadXMLStringAttribute(COLOR_B, atts);
115 float b = atof(blue.c_str());
117 color.SetRed(r); color.SetGreen(g); color.SetBlue(b);
118 m_Color[m_presetName] = color;
122 std::string AnatomicalStructureColorPresets::ReadXMLStringAttribute(
const std::string& name,
const char **atts)
126 const char** attsIter = atts;
128 while (*attsIter !=
nullptr)
130 if (name == *attsIter)
132 return *(++attsIter);
138 return std::string();
143 return m_Category[name];
153 return m_Color[name];
171 void AnatomicalStructureColorPresets::Save()
176 void AnatomicalStructureColorPresets::NewPresets(std::map<std::string, AnatomicalStructureColorPresets::Category>& newCategory, std::map<std::string, AnatomicalStructureColorPresets::Type>& newType, std::map<std::string, Color>& newColor)
178 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.