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