Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkDICOMPreloadedVolumeTest.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 
17 
18 #include "mitkTestDICOMLoading.h"
19 #include "mitkTestingMacros.h"
20 
21 #include "mitkDICOMTagCache.h"
22 
24 {
25  MITK_TEST_CONDITION_REQUIRED(list && otherList, "Comparison is passed two non-empty property lists")
26 
27  const mitk::PropertyList::PropertyMap* listM = list->GetMap();
28  const mitk::PropertyList::PropertyMap* otherListM = otherList->GetMap();
29 
30  bool equal = true;
31  for ( auto iter = listM->begin();
32  iter != listM->end();
33  ++iter )
34  {
35  std::string key = iter->first;
36  mitk::BaseProperty* property = iter->second;
37 
38  auto otherEntry = otherListM->find( key );
39  MITK_TEST_CONDITION( otherEntry != otherListM->end(), " Property '" << key << "' is contained in other list" )
40 
41  mitk::BaseProperty* otherProperty = otherEntry->second;
42  MITK_TEST_CONDITION( equal &= (*property == *otherProperty), " Property '" << key << "' is equal in both list" )
43  }
44 
45  return equal;
46 }
47 
48 bool VerifyPropertyListsEquality(const mitk::PropertyList* testList, const mitk::PropertyList* referenceList)
49 {
50  bool allTestPropsInReference = CheckAllPropertiesAreInOtherList(testList, referenceList);
51  MITK_TEST_CONDITION(allTestPropsInReference, "All test properties found in reference properties")
52  bool allReferencePropsInTest = CheckAllPropertiesAreInOtherList(referenceList, testList);
53  MITK_TEST_CONDITION(allReferencePropsInTest, "All reference properties found in test properties")
54  return allTestPropsInReference && allReferencePropsInTest;
55 }
56 
57 // !!! we expect that this tests get a list of files that load as ONE SINGLE mitk::Image!
58 int mitkDICOMPreloadedVolumeTest(int argc, char** const argv)
59 {
60  MITK_TEST_BEGIN("DICOMPreloadedVolume")
61 
63  mitk::StringList files;
64 
65  // load files from commandline
66  for (int arg = 1; arg < argc; ++arg)
67  {
68  MITK_TEST_OUTPUT(<< "Test file " << argv[arg])
69  files.push_back( argv[arg] );
70  }
71 
72 
73  // verify all files are DICOM
74  for (mitk::StringList::const_iterator fileIter = files.begin();
75  fileIter != files.end();
76  ++fileIter)
77  {
78  MITK_TEST_CONDITION_REQUIRED( mitk::DICOMFileReader::IsDICOM(*fileIter) , *fileIter << " is recognized as loadable DICOM object" )
79  }
80 
81  // load for a first time
83  MITK_TEST_OUTPUT(<< "Loaded " << images.size() << " images. Remembering properties of the first one for later comparison.")
84  mitk::Image::Pointer firstImage = images.front();
85 
86  mitk::PropertyList::Pointer originalProperties = firstImage->GetPropertyList(); // save the original
87  firstImage->SetPropertyList( mitk::PropertyList::New() ); // clear image properties
88  // what about DEFAULT properties? currently ONLY nodes get default properties
89 
90  // load for a second time, this time provide the image volume as a pointer
91  // expectation is that the reader will provide the same properties to this image (without actually loading a new mitk::Image)
92 
93  // !!! we expect that this tests get a list of files that load as ONE SINGLE mitk::Image!
94  MITK_TEST_CONDITION_REQUIRED( images.size() == 1, "Not more than 1 images loaded." );
95  // otherwise, we would need to determine the correct set of files here
96  MITK_TEST_OUTPUT(<< "Generating properties via reader. Comparing new properties to previously loaded version.")
97  mitk::Image::Pointer reloadedImage = loader.DecorateVerifyCachedImage(files, firstImage);
98  MITK_TEST_CONDITION_REQUIRED(reloadedImage.IsNotNull(), "Reader was able to property-decorate image.");
99 
100  mitk::PropertyList::Pointer regeneratedProperties = reloadedImage->GetPropertyList(); // get the version of the second load attempt
101 
102  bool listsAreEqual = VerifyPropertyListsEquality(regeneratedProperties, originalProperties);
103  MITK_TEST_CONDITION(listsAreEqual, "DICOM file reader generates a valid property list when provided a pre-loaded image");
104 
105 
106  // test again, this time provide a tag cache.
107  // expectation is, that an empty tag cache will lead to NO image
108  mitk::DICOMTagCache::Pointer tagCache; // empty
109  MITK_TEST_OUTPUT(<< "Generating properties via reader. Comparing new properties to previously loaded version.")
110  firstImage->SetPropertyList( mitk::PropertyList::New() ); // clear image properties
111  reloadedImage = loader.DecorateVerifyCachedImage(files, tagCache, firstImage);
112  MITK_TEST_CONDITION_REQUIRED(reloadedImage.IsNull(), "Reader was able to detect missing tag-cache.");
113 
114  MITK_TEST_END()
115 }
116 
bool CheckAllPropertiesAreInOtherList(const mitk::PropertyList *list, const mitk::PropertyList *otherList)
itk::SmartPointer< Self > Pointer
static Pointer New()
static bool IsDICOM(const std::string &filename)
Test whether a file is DICOM at all.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
Key-value list holding instances of BaseProperty.
bool VerifyPropertyListsEquality(const mitk::PropertyList *testList, const mitk::PropertyList *referenceList)
#define MITK_TEST_OUTPUT(x)
Output some text.
std::list< Image::Pointer > ImageList
Abstract base class for properties.
std::map< std::string, BaseProperty::Pointer > PropertyMap
#define MITK_TEST_CONDITION(COND, MSG)
std::vector< std::string > StringList
int mitkDICOMPreloadedVolumeTest(int argc, char **const argv)
Image::Pointer DecorateVerifyCachedImage(const StringList &files, mitk::Image::Pointer cachedImage)
and MITK_TEST_END()
section MAP_FRAME_Mapper_Settings Mapper settings For the mapping of corrected images
ImageList LoadFiles(const StringList &files)
const PropertyMap * GetMap() const