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
mitkPropertyNameHelper.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
10 {
11 }
12  without
13 even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 A PARTICULAR PURPOSE.
15 
16 See LICENSE.txt or http://www.mitk.org for details.
17 
18 ===================================================================*/
19 
20 #include "mitkPropertyNameHelper.h"
21 #include <iomanip>
22 #include <mitkPropertyList.h>
23 #include <sstream>
24 
25 std::string mitk::GeneratePropertyNameForDICOMTag(unsigned int group, unsigned int element)
26 {
27  std::ostringstream nameStream;
28  nameStream << "DICOM."
29  << std::setw(4) << std::setfill('0') << std::hex << std::uppercase << group << std::nouppercase << "."
30  << std::setw(4) << std::setfill('0') << std::hex << std::uppercase << element;
31 
32  return nameStream.str();
33 };
34 
36  unsigned int element,
37  std::string const &backwardsCompatiblePropertyName,
38  mitk::PropertyList const *propertyList,
39  std::string &propertyValue)
40 {
41  propertyValue = "";
42 
43  BaseProperty *prop = propertyList->GetProperty(mitk::GeneratePropertyNameForDICOMTag(group, element).c_str());
44 
45  if (prop)
46  { // may not be a string property so use the generic access.
47  propertyValue = prop->GetValueAsString();
48  }
49 
50  if (!propertyValue.empty() || propertyList->GetStringProperty(backwardsCompatiblePropertyName.c_str(), propertyValue))
51  // 2nd part is for backwards compatibility with the old property naming style
52  {
53  return true;
54  }
55 
56  return false;
57 };
mitk::BaseProperty * GetProperty(const std::string &propertyKey) const
Get a property by its name.
std::string MITKCORE_EXPORT GeneratePropertyNameForDICOMTag(unsigned int group, unsigned int element)
Key-value list holding instances of BaseProperty.
Abstract base class for properties.
virtual std::string GetValueAsString() const
bool GetStringProperty(const char *propertyKey, std::string &stringValue) const
Convenience method to access the value of a StringProperty.
bool MITKCORE_EXPORT GetBackwardsCompatibleDICOMProperty(unsigned int group, unsigned int element, std::string const &backwardsCompatiblePropertyName, PropertyList const *propertyList, std::string &propertyValue)