Medical Imaging Interaction Toolkit  2018.4.99-f51274ea
Medical Imaging Interaction Toolkit
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkPropertyNameHelper.h"
14 #include <iomanip>
15 #include <mitkPropertyList.h>
16 #include <sstream>
17 
18 std::string mitk::GeneratePropertyNameForDICOMTag(unsigned int group, unsigned int element)
19 {
20  std::ostringstream nameStream;
21  nameStream << "DICOM."
22  << std::setw(4) << std::setfill('0') << std::hex << std::uppercase << group << std::nouppercase << "."
23  << std::setw(4) << std::setfill('0') << std::hex << std::uppercase << element;
24 
25  return nameStream.str();
26 };
27 
29  unsigned int element,
30  std::string const &backwardsCompatiblePropertyName,
31  mitk::PropertyList const *propertyList,
32  std::string &propertyValue)
33 {
34  propertyValue = "";
35 
36  BaseProperty *prop = propertyList->GetProperty(mitk::GeneratePropertyNameForDICOMTag(group, element).c_str());
37 
38  if (prop)
39  { // may not be a string property so use the generic access.
40  propertyValue = prop->GetValueAsString();
41  }
42 
43  if (!propertyValue.empty() || propertyList->GetStringProperty(backwardsCompatiblePropertyName.c_str(), propertyValue))
44  // 2nd part is for backwards compatibility with the old property naming style
45  {
46  return true;
47  }
48 
49  return false;
50 };
std::string MITKCORE_EXPORT GeneratePropertyNameForDICOMTag(unsigned int group, unsigned int element)
Key-value list holding instances of BaseProperty.
virtual std::string GetValueAsString() const
Abstract base class for properties.
bool GetStringProperty(const char *propertyKey, std::string &stringValue) const
Convenience method to access the value of a StringProperty.
mitk::BaseProperty * GetProperty(const std::string &propertyKey) const
Get a property by its name.
bool MITKCORE_EXPORT GetBackwardsCompatibleDICOMProperty(unsigned int group, unsigned int element, std::string const &backwardsCompatiblePropertyName, PropertyList const *propertyList, std::string &propertyValue)