Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkDCMPreloadedVolumeTest.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 #include "mitkImage.h"
18 #include "mitkTestDCMLoading.h"
19 #include "mitkTestingMacros.h"
20 
22 {
23  MITK_TEST_CONDITION_REQUIRED(list && otherList, "Comparison is passed two non-empty property lists")
24 
25  const mitk::PropertyList::PropertyMap *listM = list->GetMap();
26  const mitk::PropertyList::PropertyMap *otherListM = otherList->GetMap();
27 
28  bool equal = true;
29  for (auto iter = listM->begin(); iter != listM->end(); ++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 int mitkDCMPreloadedVolumeTest(int argc, char **const argv)
54 {
55  MITK_TEST_BEGIN("DCMPreloadedVolume")
56 
57  mitk::TestDCMLoading loader;
59 
60  // adapt expectations depending on configuration
61  std::string configuration = mitk::DicomSeriesReader::GetConfigurationString();
62  MITK_TEST_OUTPUT(<< "Configuration: " << configuration)
63 
64  // load files from commandline
65  for (int arg = 1; arg < argc; ++arg)
66  {
67  MITK_TEST_OUTPUT(<< "Test file " << argv[arg])
68  files.push_back(argv[arg]);
69  }
70 
71  // verify all files are DCM
72  for (mitk::TestDCMLoading::StringContainer::const_iterator fileIter = files.begin(); fileIter != files.end();
73  ++fileIter)
74  {
76  *fileIter << " is recognized as loadable DCM object")
77  }
78 
79  // load for a first time
81  MITK_TEST_OUTPUT(<< "Loaded " << images.size()
82  << " images. Remembering properties of the first one for later comparison.")
83  mitk::Image::Pointer firstImage = images.front();
84 
85  mitk::PropertyList::Pointer originalProperties = firstImage->GetPropertyList(); // save the original
86  firstImage->SetPropertyList(mitk::PropertyList::New()); // clear image properties
87  // what about DEFAULT properties? currently ONLY nodes get default properties
88 
89  // load for a second time, this time provide the image volume as a pointer
90  // expectation is that the reader will provide the same properties to this image (without actually loading a new
91  // mitk::Image)
92  mitk::TestDCMLoading::ImageList reloadedImages = loader.LoadFiles(files, firstImage);
93  MITK_TEST_OUTPUT(<< "Again loaded " << reloadedImages.size() << " images. Comparing to previously loaded version.")
94  mitk::Image::Pointer reloadedImage = reloadedImages.front();
95 
96  mitk::PropertyList::Pointer regeneratedProperties =
97  reloadedImage->GetPropertyList(); // get the version of the second load attempt
98 
99  bool listsAreEqual = VerifyPropertyListsEquality(regeneratedProperties, originalProperties);
100  MITK_TEST_CONDITION(listsAreEqual,
101  "LoadDicomSeries generates a valid property list when provided a pre-loaded image");
102 
103  MITK_TEST_END()
104 }
static Pointer New()
int mitkDCMPreloadedVolumeTest(int argc, char **const argv)
static std::string GetConfigurationString()
Provide combination of preprocessor defines that was active during compilation.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
Key-value list holding instances of BaseProperty.
DicomSeriesReader::StringContainer StringContainer
#define MITK_TEST_OUTPUT(x)
Output some text.
Abstract base class for properties.
std::map< std::string, BaseProperty::Pointer > PropertyMap
#define MITK_TEST_CONDITION(COND, MSG)
static bool IsDicom(const std::string &filename)
Checks if a specific file contains DICOM data.
bool VerifyPropertyListsEquality(const mitk::PropertyList *testList, const mitk::PropertyList *referenceList)
std::list< itk::SmartPointer< Image > > ImageList
and MITK_TEST_END()
bool CheckAllPropertiesAreInOtherList(const mitk::PropertyList *list, const mitk::PropertyList *otherList)
ImageList LoadFiles(const StringContainer &files, itk::SmartPointer< Image > preLoadedVolume=nullptr)
section MAP_FRAME_Mapper_Settings Mapper settings For the mapping of corrected images
const PropertyMap * GetMap() const