Medical Imaging Interaction Toolkit  2018.4.99-dfa0c14e
Medical Imaging Interaction Toolkit
mitkDICOMPropertyTest.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 "mitkDICOMProperty.h"
14 
15 #include "mitkImage.h"
16 #include "mitkTestFixture.h"
17 #include "mitkTestingMacros.h"
18 
19 class mitkDICOMPropertyTestSuite : public mitk::TestFixture
20 {
21  CPPUNIT_TEST_SUITE(mitkDICOMPropertyTestSuite);
22 
24  MITK_TEST(GetPropertyByDICOMTagPath_2);
27 
28  CPPUNIT_TEST_SUITE_END();
29 
30 private:
31 
32  mitk::DICOMTagPath simplePath;
33  mitk::DICOMTagPath deepPath;
34  mitk::DICOMTagPath deepPath2;
35  mitk::DICOMTagPath deepPath_withAnyElement;
36  mitk::DICOMTagPath deepPath_withAnySelection;
37  mitk::DICOMTagPath deepPath_withSelection;
38  mitk::DICOMTagPath deepPath_withSelection2;
39 
40  mitk::DICOMTagPath emptyPath;
41 
43 
44  std::string simplePathStr;
45  std::string deepPathStr;
46  std::string deepPath2Str;
47  std::string deepPath_withSelectionStr;
48 
49 public:
50 
51  void setUp() override
52  {
53  simplePath.AddElement(0x0010, 0x0010);
54 
55  deepPath.AddElement(0x0010, 0x0011).AddElement(0x0020, 0x0022).AddElement(0x0030, 0x0033);
56 
57  deepPath2.AddElement(0x0010, 0x0011).AddElement(0x0020, 0x0023).AddElement(0x0030, 0x0033);
58 
59  deepPath_withAnyElement.AddElement(0x0010, 0x0011).AddAnyElement().AddElement(0x0030, 0x0033);
60 
61  deepPath_withAnySelection.AddElement(0x0010, 0x0011).AddAnySelection(0x0020, 0x0024).AddElement(0x0030, 0x0033);
62 
63  deepPath_withSelection.AddElement(0x0010, 0x0011).AddSelection(0x0020, 0x0024, 1).AddElement(0x0030, 0x0033);
64 
65  deepPath_withSelection2.AddElement(0x0010, 0x0011).AddSelection(0x0020, 0x0024, 2).AddElement(0x0030, 0x0033);
66 
67  simplePathStr = mitk::DICOMTagPathToPropertyName(simplePath);
68  deepPathStr = mitk::DICOMTagPathToPropertyName(deepPath);
69  deepPath2Str = mitk::DICOMTagPathToPropertyName(deepPath2);
70  deepPath_withSelectionStr = mitk::DICOMTagPathToPropertyName(deepPath_withSelection);
71 
72  data = mitk::Image::New();
73  data->GetPropertyList()->SetStringProperty(simplePathStr.c_str(), "simplePath");
74  data->GetPropertyList()->SetStringProperty(deepPathStr.c_str(), "deepPath");
75  data->GetPropertyList()->SetStringProperty(deepPath2Str.c_str(), "deepPath2");
76  data->GetPropertyList()->SetStringProperty(deepPath_withSelectionStr.c_str(), "deepPath_withSelection");
77  data->GetPropertyList()->SetStringProperty("DICOM.0003.0003", "otherPath");
78  data->GetPropertyList()->SetStringProperty("not_a_dicom_prop", "not_a_dicom_prop");
79  }
80 
81  void tearDown() override
82  {
83  }
84 
86  {
87  std::map< std::string, mitk::BaseProperty::Pointer> result = mitk::GetPropertyByDICOMTagPath(data, simplePath);
88  CPPUNIT_ASSERT(result.size() == 1);
89  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("simplePath"));
90 
91  result = mitk::GetPropertyByDICOMTagPath(data, deepPath);
92  CPPUNIT_ASSERT(result.size() == 1);
93  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("deepPath"));
94 
95  result = mitk::GetPropertyByDICOMTagPath(data, deepPath2);
96  CPPUNIT_ASSERT(result.size() == 1);
97  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("deepPath2"));
98 
99  result = mitk::GetPropertyByDICOMTagPath(data, deepPath_withAnyElement);
100  CPPUNIT_ASSERT(result.size() == 3);
101  CPPUNIT_ASSERT_EQUAL(result[deepPathStr]->GetValueAsString(), std::string("deepPath"));
102  CPPUNIT_ASSERT_EQUAL(result[deepPath2Str]->GetValueAsString(), std::string("deepPath2"));
103  CPPUNIT_ASSERT_EQUAL(result[deepPath_withSelectionStr]->GetValueAsString(), std::string("deepPath_withSelection"));
104 
105  result = mitk::GetPropertyByDICOMTagPath(data, deepPath_withSelection);
106  CPPUNIT_ASSERT(result.size() == 1);
107  CPPUNIT_ASSERT_EQUAL(result[deepPath_withSelectionStr]->GetValueAsString(), std::string("deepPath_withSelection"));
108 
109  result = mitk::GetPropertyByDICOMTagPath(data, deepPath_withSelection2);
110  CPPUNIT_ASSERT(result.size() == 0);
111 
112  result = mitk::GetPropertyByDICOMTagPath(data, emptyPath);
113  CPPUNIT_ASSERT(result.size() == 0);
114  }
115 
116 
117  void GetPropertyByDICOMTagPath_2()
118  {
119  std::map< std::string, mitk::BaseProperty::Pointer> result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), simplePath);
120  CPPUNIT_ASSERT(result.size() == 1);
121  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("simplePath"));
122 
123  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath);
124  CPPUNIT_ASSERT(result.size() == 1);
125  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("deepPath"));
126 
127  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath2);
128  CPPUNIT_ASSERT(result.size() == 1);
129  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("deepPath2"));
130 
131  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath_withAnyElement);
132  CPPUNIT_ASSERT(result.size() == 3);
133  CPPUNIT_ASSERT_EQUAL(result[deepPathStr]->GetValueAsString(), std::string("deepPath"));
134  CPPUNIT_ASSERT_EQUAL(result[deepPath2Str]->GetValueAsString(), std::string("deepPath2"));
135  CPPUNIT_ASSERT_EQUAL(result[deepPath_withSelectionStr]->GetValueAsString(), std::string("deepPath_withSelection"));
136 
137  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath_withSelection);
138  CPPUNIT_ASSERT(result.size() == 1);
139  CPPUNIT_ASSERT_EQUAL(result[deepPath_withSelectionStr]->GetValueAsString(), std::string("deepPath_withSelection"));
140 
141  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath_withSelection2);
142  CPPUNIT_ASSERT(result.size() == 0);
143 
144  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), emptyPath);
145  CPPUNIT_ASSERT(result.size() == 0);
146  }
147 
149  {
150  CPPUNIT_ASSERT_EQUAL(mitk::ConvertDICOMStrToValue<double>("1.35"), 1.35);
151  CPPUNIT_ASSERT_EQUAL(mitk::ConvertDICOMStrToValue<double>("1"), 1.);
152  CPPUNIT_ASSERT_THROW(mitk::ConvertDICOMStrToValue<int>("1.35"), mitk::Exception);
153  CPPUNIT_ASSERT_EQUAL(mitk::ConvertDICOMStrToValue<int>("1"), 1);
154  CPPUNIT_ASSERT_THROW(mitk::ConvertDICOMStrToValue<double>("1,35"), mitk::Exception);
155  CPPUNIT_ASSERT_THROW(mitk::ConvertDICOMStrToValue<double>("nonumber"), mitk::Exception);
156  }
157 
159  {
160  CPPUNIT_ASSERT_EQUAL(mitk::ConvertValueToDICOMStr(1.35), std::string("1.35"));
161  CPPUNIT_ASSERT_EQUAL(mitk::ConvertValueToDICOMStr(1), std::string("1"));
162  }
163 
164 };
165 
166 MITK_TEST_SUITE_REGISTRATION(mitkDICOMProperty)
DICOMTagPath & AddElement(unsigned int group, unsigned int element)
DICOMTagPath & AddAnySelection(unsigned int group, unsigned int element)
Class is used to identify (nested) attributes in a DICOM dataset. In contrast to the class DICOMTag...
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
DICOMTagPath & AddAnyElement()
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
MITKDICOM_EXPORT std::string DICOMTagPathToPropertyName(const DICOMTagPath &tagPath)
An object of this class represents an exception of MITK. Please don&#39;t instantiate exceptions manually...
Definition: mitkException.h:45
Test fixture for parameterized tests.
static Pointer New()
DICOMTagPath & AddSelection(unsigned int group, unsigned int element, ItemSelectionIndex index)
std::string ConvertValueToDICOMStr(const TNumericType value)
TNumericReturnType ConvertDICOMStrToValue(const std::string &dcmValueString)
MITKDICOM_EXPORT std::map< std::string, BaseProperty::Pointer > GetPropertyByDICOMTagPath(const PropertyList *list, const DICOMTagPath &path)