Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
21 #include "mitkDICOMSortByTag.h"
22 
23 #include "mitkTestingMacros.h"
24 
25 #include <unordered_map>
26 #include "mitkStringProperty.h"
27 
28 using mitk::DICOMTag;
29 
30 int mitkDICOMITKSeriesGDCMReaderBasicsTest(int argc, char* argv[])
31 {
32  MITK_TEST_BEGIN("mitkDICOMITKSeriesGDCMReaderBasicsTest");
33 
35  MITK_TEST_CONDITION_REQUIRED(gdcmReader.IsNotNull(), "DICOMITKSeriesGDCMReader can be instantiated.");
36 
38 
39  std::unordered_map<std::string, std::string> expectedPropertyTypes;
41  additionalTags.insert( std::make_pair(DICOMTag( 0x0008, 0x0005 ), "Test1") );
42  additionalTags.insert( std::make_pair(DICOMTag( 0x0008, 0x0060 ), "Test2") );
43  additionalTags.insert( std::make_pair(DICOMTag( 0x0020, 0x1041 ), "Test3") );
44 
45  gdcmReader->SetAdditionalTagsOfInterest( additionalTags );
46 
47  // check the Set/GetInput function
49 
50  // check that output is a good reproduction of input (no duplicates, no new elements)
52 
53 
54  // repeat test with filename based sorter in-between
56  gdcmReader->AddSortingElement( filenameSorter );
58 
59  // repeat test with some more realistic sorting
60  gdcmReader = mitk::DICOMITKSeriesGDCMReader::New(); // this also tests destruction
62 
63  // all the things that split by tag in DicomSeriesReader
64  tagSorter->AddDistinguishingTag( DICOMTag(0x0028, 0x0010) ); // Number of Rows
65  tagSorter->AddDistinguishingTag( DICOMTag(0x0028, 0x0011) ); // Number of Columns
66  tagSorter->AddDistinguishingTag( DICOMTag(0x0028, 0x0030) ); // Pixel Spacing
67  tagSorter->AddDistinguishingTag( DICOMTag(0x0018, 0x1164) ); // Imager Pixel Spacing
68  tagSorter->AddDistinguishingTag( DICOMTag(0x0020, 0x0037), new mitk::DICOMTagBasedSorter::CutDecimalPlaces(5) ); // Image Orientation (Patient)
69  tagSorter->AddDistinguishingTag( DICOMTag(0x0020, 0x000e) ); // Series Instance UID
70  tagSorter->AddDistinguishingTag( DICOMTag(0x0018, 0x0050) ); // Slice Thickness
71  tagSorter->AddDistinguishingTag( DICOMTag(0x0028, 0x0008) ); // Number of Frames
72  tagSorter->AddDistinguishingTag( DICOMTag(0x0020, 0x0052) ); // Frame of Reference UID
73 
74  // a sorter...
76  mitk::DICOMSortByTag::New( DICOMTag(0x0020, 0x0013), // instance number
77  mitk::DICOMSortByTag::New( DICOMTag(0x0020, 0x0012), // aqcuisition number
78  mitk::DICOMSortByTag::New( DICOMTag(0x0008, 0x0032), // aqcuisition time
79  mitk::DICOMSortByTag::New( DICOMTag(0x0018, 0x1060), // trigger time
80  mitk::DICOMSortByTag::New( DICOMTag(0x0008, 0x0018) // SOP instance UID (last resort, not really meaningful but decides clearly)
81  ).GetPointer()
82  ).GetPointer()
83  ).GetPointer()
84  ).GetPointer()
85  ).GetPointer();
86  tagSorter->SetSortCriterion( sorting );
87 
88  gdcmReader->AddSortingElement( tagSorter );
89 
90  gdcmReader->SetAdditionalTagsOfInterest( additionalTags );
91 
92 
94 
95  gdcmReader->PrintOutputs(std::cout, true);
96 
97  // really load images
98  mitk::DICOMFileReaderTestHelper::TestMitkImagesAreLoaded( gdcmReader, additionalTags, expectedPropertyTypes );
99 
100 
102  //
103  // Load the images again with another TagLookupTableToPropertyFunctor
104  //
106 
107  gdcmReader->SetTagLookupTableToPropertyFunctor( []( const mitk::DICOMCachedValueLookupTable& table )
108  {
110  } );
111 
112  expectedPropertyTypes.insert(std::make_pair("Test1", "StringProperty"));
113  expectedPropertyTypes.insert(std::make_pair("Test2", "StringProperty"));
114  expectedPropertyTypes.insert(std::make_pair("Test3", "StringProperty"));
115 
117 
118  gdcmReader->PrintOutputs(std::cout, true);
119 
120  // really load images
121  mitk::DICOMFileReaderTestHelper::TestMitkImagesAreLoaded( gdcmReader, additionalTags, expectedPropertyTypes );
122 
123 
124  MITK_TEST_END();
125 }
static void TestMitkImagesAreLoaded(DICOMFileReader *reader, const DICOMFileReader::AdditionalTagsMapType &requestedTags, const std::unordered_map< std::string, std::string > &expectedProperties)
itk::SmartPointer< Self > Pointer
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
Representation of a DICOM tag.
Definition: mitkDICOMTag.h:37
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
ValueType GetTableValue(IdentifierType id) const
itk::SmartPointer< const Self > ConstPointer
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)
int mitkDICOMITKSeriesGDCMReaderBasicsTest(int argc, char *argv[])
static Pointer New()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.