Medical Imaging Interaction Toolkit  2018.4.99-08619e4f
Medical Imaging Interaction Toolkit
mitkDICOMITKSeriesGDCMReaderBasicsTest.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 
17 #include "mitkDICOMSortByTag.h"
18 
19 #include "mitkTestingMacros.h"
20 
21 #include <unordered_map>
22 #include "mitkStringProperty.h"
23 
24 using mitk::DICOMTag;
25 
26 int mitkDICOMITKSeriesGDCMReaderBasicsTest(int argc, char* argv[])
27 {
28  MITK_TEST_BEGIN("mitkDICOMITKSeriesGDCMReaderBasicsTest");
29 
30  mitk::DICOMITKSeriesGDCMReader::Pointer gdcmReader = mitk::DICOMITKSeriesGDCMReader::New();
31  MITK_TEST_CONDITION_REQUIRED(gdcmReader.IsNotNull(), "DICOMITKSeriesGDCMReader can be instantiated.");
32 
34 
35  std::unordered_map<std::string, std::string> expectedPropertyTypes;
37  additionalTags.insert( std::make_pair(DICOMTag( 0x0008, 0x0005 ), "Test1") );
38  additionalTags.insert( std::make_pair(DICOMTag( 0x0008, 0x0060 ), "Test2") );
39  additionalTags.insert( std::make_pair(DICOMTag( 0x0020, 0x1041 ), "Test3") );
40 
41  gdcmReader->SetAdditionalTagsOfInterest( additionalTags );
42 
43  // check the Set/GetInput function
45 
46  // check that output is a good reproduction of input (no duplicates, no new elements)
48 
49 
50  // repeat test with filename based sorter in-between
51  mitk::DICOMFilenameSorter::Pointer filenameSorter = mitk::DICOMFilenameSorter::New();
52  gdcmReader->AddSortingElement( filenameSorter );
54 
55  // repeat test with some more realistic sorting
56  gdcmReader = mitk::DICOMITKSeriesGDCMReader::New(); // this also tests destruction
57  mitk::DICOMTagBasedSorter::Pointer tagSorter = mitk::DICOMTagBasedSorter::New();
58 
59  // all the things that split by tag in DicomSeriesReader
60  tagSorter->AddDistinguishingTag( DICOMTag(0x0028, 0x0010) ); // Number of Rows
61  tagSorter->AddDistinguishingTag( DICOMTag(0x0028, 0x0011) ); // Number of Columns
62  tagSorter->AddDistinguishingTag( DICOMTag(0x0028, 0x0030) ); // Pixel Spacing
63  tagSorter->AddDistinguishingTag( DICOMTag(0x0018, 0x1164) ); // Imager Pixel Spacing
64  tagSorter->AddDistinguishingTag( DICOMTag(0x0020, 0x0037), new mitk::DICOMTagBasedSorter::CutDecimalPlaces(5) ); // Image Orientation (Patient)
65  tagSorter->AddDistinguishingTag( DICOMTag(0x0020, 0x000e) ); // Series Instance UID
66  tagSorter->AddDistinguishingTag( DICOMTag(0x0018, 0x0050) ); // Slice Thickness
67  tagSorter->AddDistinguishingTag( DICOMTag(0x0028, 0x0008) ); // Number of Frames
68  tagSorter->AddDistinguishingTag( DICOMTag(0x0020, 0x0052) ); // Frame of Reference UID
69 
70  // a sorter...
71  mitk::DICOMSortCriterion::ConstPointer sorting =
72  mitk::DICOMSortByTag::New( DICOMTag(0x0020, 0x0013), // instance number
73  mitk::DICOMSortByTag::New( DICOMTag(0x0020, 0x0012), // aqcuisition number
74  mitk::DICOMSortByTag::New( DICOMTag(0x0008, 0x0032), // aqcuisition time
75  mitk::DICOMSortByTag::New( DICOMTag(0x0018, 0x1060), // trigger time
76  mitk::DICOMSortByTag::New( DICOMTag(0x0008, 0x0018) // SOP instance UID (last resort, not really meaningful but decides clearly)
77  ).GetPointer()
78  ).GetPointer()
79  ).GetPointer()
80  ).GetPointer()
81  ).GetPointer();
82  tagSorter->SetSortCriterion( sorting );
83 
84  gdcmReader->AddSortingElement( tagSorter );
85 
86  gdcmReader->SetAdditionalTagsOfInterest( additionalTags );
87 
88 
90 
91  gdcmReader->PrintOutputs(std::cout, true);
92 
93  // really load images
94  mitk::DICOMFileReaderTestHelper::TestMitkImagesAreLoaded( gdcmReader, additionalTags, expectedPropertyTypes );
95 
96 
98  //
99  // Load the images again with another TagLookupTableToPropertyFunctor
100  //
102 
103  gdcmReader->SetTagLookupTableToPropertyFunctor( []( const mitk::DICOMCachedValueLookupTable& table )
104  {
106  } );
107 
108  expectedPropertyTypes.insert(std::make_pair("Test1", "StringProperty"));
109  expectedPropertyTypes.insert(std::make_pair("Test2", "StringProperty"));
110  expectedPropertyTypes.insert(std::make_pair("Test3", "StringProperty"));
111 
113 
114  gdcmReader->PrintOutputs(std::cout, true);
115 
116  // really load images
117  mitk::DICOMFileReaderTestHelper::TestMitkImagesAreLoaded( gdcmReader, additionalTags, expectedPropertyTypes );
118 
119 
120  MITK_TEST_END();
121 }
static void TestMitkImagesAreLoaded(DICOMFileReader *reader, const DICOMFileReader::AdditionalTagsMapType &requestedTags, const std::unordered_map< std::string, std::string > &expectedProperties)
static Pointer New()
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
Representation of a DICOM tag.
Definition: mitkDICOMTag.h:32
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
ValueType GetTableValue(IdentifierType id) const
DICOMImageBlockDescriptor::AdditionalTagsMapType AdditionalTagsMapType
static void TestOutputsContainInputs(DICOMFileReader *reader)
static void SetTestInputFilenames(int argc, char *argv[])
Cuts a number after configured number of decimal places. An instance of this class can be used to avo...
and MITK_TEST_END()
static void TestInputFilenames(DICOMFileReader *reader)
static Pointer New()
int mitkDICOMITKSeriesGDCMReaderBasicsTest(int argc, char *argv[])
static Pointer New()