Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
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);
26 
27  CPPUNIT_TEST_SUITE_END();
28 
29 private:
30 
31  mitk::DICOMTagPath simplePath;
32  mitk::DICOMTagPath deepPath;
33  mitk::DICOMTagPath deepPath2;
34  mitk::DICOMTagPath deepPath_withAnyElement;
35  mitk::DICOMTagPath deepPath_withAnySelection;
36  mitk::DICOMTagPath deepPath_withSelection;
37  mitk::DICOMTagPath deepPath_withSelection2;
38 
39  mitk::DICOMTagPath emptyPath;
40 
42 
43  std::string simplePathStr;
44  std::string deepPathStr;
45  std::string deepPath2Str;
46  std::string deepPath_withSelectionStr;
47 
48 public:
49 
50  void setUp() override
51  {
52  simplePath.AddElement(0x0010, 0x0010);
53 
54  deepPath.AddElement(0x0010, 0x0011).AddElement(0x0020, 0x0022).AddElement(0x0030, 0x0033);
55 
56  deepPath2.AddElement(0x0010, 0x0011).AddElement(0x0020, 0x0023).AddElement(0x0030, 0x0033);
57 
58  deepPath_withAnyElement.AddElement(0x0010, 0x0011).AddAnyElement().AddElement(0x0030, 0x0033);
59 
60  deepPath_withAnySelection.AddElement(0x0010, 0x0011).AddAnySelection(0x0020, 0x0024).AddElement(0x0030, 0x0033);
61 
62  deepPath_withSelection.AddElement(0x0010, 0x0011).AddSelection(0x0020, 0x0024, 1).AddElement(0x0030, 0x0033);
63 
64  deepPath_withSelection2.AddElement(0x0010, 0x0011).AddSelection(0x0020, 0x0024, 2).AddElement(0x0030, 0x0033);
65 
66  simplePathStr = mitk::DICOMTagPathToPropertyName(simplePath);
67  deepPathStr = mitk::DICOMTagPathToPropertyName(deepPath);
68  deepPath2Str = mitk::DICOMTagPathToPropertyName(deepPath2);
69  deepPath_withSelectionStr = mitk::DICOMTagPathToPropertyName(deepPath_withSelection);
70 
71  data = mitk::Image::New();
72  data->GetPropertyList()->SetStringProperty(simplePathStr.c_str(), "simplePath");
73  data->GetPropertyList()->SetStringProperty(deepPathStr.c_str(), "deepPath");
74  data->GetPropertyList()->SetStringProperty(deepPath2Str.c_str(), "deepPath2");
75  data->GetPropertyList()->SetStringProperty(deepPath_withSelectionStr.c_str(), "deepPath_withSelection");
76  data->GetPropertyList()->SetStringProperty("DICOM.0003.0003", "otherPath");
77  data->GetPropertyList()->SetStringProperty("not_a_dicom_prop", "not_a_dicom_prop");
78  }
79 
80  void tearDown() override
81  {
82  }
83 
85  {
86  std::map< std::string, mitk::BaseProperty::Pointer> result = mitk::GetPropertyByDICOMTagPath(data, simplePath);
87  CPPUNIT_ASSERT(result.size() == 1);
88  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("simplePath"));
89 
90  result = mitk::GetPropertyByDICOMTagPath(data, deepPath);
91  CPPUNIT_ASSERT(result.size() == 1);
92  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("deepPath"));
93 
94  result = mitk::GetPropertyByDICOMTagPath(data, deepPath2);
95  CPPUNIT_ASSERT(result.size() == 1);
96  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("deepPath2"));
97 
98  result = mitk::GetPropertyByDICOMTagPath(data, deepPath_withAnyElement);
99  CPPUNIT_ASSERT(result.size() == 3);
100  CPPUNIT_ASSERT_EQUAL(result[deepPathStr]->GetValueAsString(), std::string("deepPath"));
101  CPPUNIT_ASSERT_EQUAL(result[deepPath2Str]->GetValueAsString(), std::string("deepPath2"));
102  CPPUNIT_ASSERT_EQUAL(result[deepPath_withSelectionStr]->GetValueAsString(), std::string("deepPath_withSelection"));
103 
104  result = mitk::GetPropertyByDICOMTagPath(data, deepPath_withSelection);
105  CPPUNIT_ASSERT(result.size() == 1);
106  CPPUNIT_ASSERT_EQUAL(result[deepPath_withSelectionStr]->GetValueAsString(), std::string("deepPath_withSelection"));
107 
108  result = mitk::GetPropertyByDICOMTagPath(data, deepPath_withSelection2);
109  CPPUNIT_ASSERT(result.size() == 0);
110 
111  result = mitk::GetPropertyByDICOMTagPath(data, emptyPath);
112  CPPUNIT_ASSERT(result.size() == 0);
113  }
114 
115 
116  void GetPropertyByDICOMTagPath_2()
117  {
118  std::map< std::string, mitk::BaseProperty::Pointer> result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), simplePath);
119  CPPUNIT_ASSERT(result.size() == 1);
120  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("simplePath"));
121 
122  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath);
123  CPPUNIT_ASSERT(result.size() == 1);
124  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("deepPath"));
125 
126  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath2);
127  CPPUNIT_ASSERT(result.size() == 1);
128  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("deepPath2"));
129 
130  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath_withAnyElement);
131  CPPUNIT_ASSERT(result.size() == 3);
132  CPPUNIT_ASSERT_EQUAL(result[deepPathStr]->GetValueAsString(), std::string("deepPath"));
133  CPPUNIT_ASSERT_EQUAL(result[deepPath2Str]->GetValueAsString(), std::string("deepPath2"));
134  CPPUNIT_ASSERT_EQUAL(result[deepPath_withSelectionStr]->GetValueAsString(), std::string("deepPath_withSelection"));
135 
136  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath_withSelection);
137  CPPUNIT_ASSERT(result.size() == 1);
138  CPPUNIT_ASSERT_EQUAL(result[deepPath_withSelectionStr]->GetValueAsString(), std::string("deepPath_withSelection"));
139 
140  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath_withSelection2);
141  CPPUNIT_ASSERT(result.size() == 0);
142 
143  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), emptyPath);
144  CPPUNIT_ASSERT(result.size() == 0);
145  }
146 
148  {
149  CPPUNIT_ASSERT_EQUAL(mitk::ConvertDICOMStrToValue<double>("1.35"), 1.35);
150  CPPUNIT_ASSERT_EQUAL(mitk::ConvertDICOMStrToValue<double>("1"), 1.);
151  CPPUNIT_ASSERT_THROW(mitk::ConvertDICOMStrToValue<int>("1.35"), mitk::Exception);
152  CPPUNIT_ASSERT_EQUAL(mitk::ConvertDICOMStrToValue<int>("1"), 1);
153  CPPUNIT_ASSERT_THROW(mitk::ConvertDICOMStrToValue<double>("1,35"), mitk::Exception);
154  CPPUNIT_ASSERT_THROW(mitk::ConvertDICOMStrToValue<double>("nonumber"), mitk::Exception);
155  }
156 
157 };
158 
159 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.
MITKDICOMREADER_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)
TNumericReturnType ConvertDICOMStrToValue(const std::string &dcmValueString)
MITKDICOMREADER_EXPORT std::map< std::string, BaseProperty::Pointer > GetPropertyByDICOMTagPath(const PropertyList *list, const DICOMTagPath &path)