Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
VerifyDCMMitkImageDump.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 "mitkTestDCMLoading.h"
18 
19 #include "mitkImage.h"
20 
21 std::vector<std::string> LoadDumps(const std::string &fileName)
22 {
23  std::vector<std::string> separatedDumps;
24 
25  std::ifstream fileStream(fileName.c_str());
26 
27  std::string buffer;
28  std::string line;
29  while (fileStream)
30  {
31  std::getline(fileStream, line);
32 
33  if (line.find("-- Image ") == 0)
34  {
35  // separator: starts a new image block
36  if (!buffer.empty())
37  {
38  // unless this is the first block
39  separatedDumps.push_back(buffer);
40  buffer.clear();
41  }
42  }
43  else
44  {
45  buffer += line + "\n";
46  }
47  }
48  fileStream.close();
49 
50  // eat last image dump
51  if (!buffer.empty())
52  {
53  separatedDumps.push_back(buffer);
54  buffer.clear();
55  }
56 
57  return separatedDumps;
58 }
59 
60 int main(int argc, char **argv)
61 {
69  if (argc < 2)
70  {
71  MITK_ERROR << "Usage:";
72  MITK_ERROR << " " << argv[0] << " reference.dump file1 [file2 .. fileN]";
73  MITK_ERROR << " ";
74  MITK_ERROR << " Loads all DCM images in file1 to fileN as MITK images ";
75  MITK_ERROR << " and compares loaded images against stored expectations (dumps).";
76  MITK_ERROR << " See also DumpDCMMitkImage (generates dumps)";
77  return EXIT_FAILURE;
78  }
79 
80  mitk::TestDCMLoading loader;
82 
83  // TODO load reference dumps
84 
85  // load from argv[1]
86  // separate at "-- Image n"
87  // store in an array of dumps
88 
89  std::vector<std::string> expectedDumps = LoadDumps(argv[1]);
90 
91  for (int arg = 2; arg < argc; ++arg)
92  files.push_back(argv[arg]);
93 
95 
96  unsigned int imageCounter(0);
97  for (mitk::TestDCMLoading::ImageList::const_iterator imageIter = images.begin(); imageIter != images.end();
98  ++imageIter, ++imageCounter)
99  {
100  std::string imageDump = loader.DumpImageInformation(*imageIter);
101 
102  if (imageCounter >= expectedDumps.size())
103  {
104  MITK_ERROR << "Loader produces more images than expected. Aborting after image " << (imageCounter - 1);
105  MITK_INFO << "Image " << imageCounter << " loaded as:\n" << imageDump;
106  return EXIT_FAILURE;
107  }
108 
109  bool loadedAsExpected = loader.CompareImageInformationDumps(expectedDumps[imageCounter], imageDump);
110  if (loadedAsExpected)
111  {
112  MITK_INFO << "Image " << imageCounter << " loads as expected.";
113  }
114  else
115  {
116  MITK_ERROR << "Image " << imageCounter << " did not load as expected.";
117  MITK_INFO << "Expected: \n" << expectedDumps[imageCounter] << "\nGot:\n" << imageDump;
118  return EXIT_FAILURE;
119  }
120  }
121 
122  return EXIT_SUCCESS;
123 }
static char * line
Definition: svm.cpp:2884
#define MITK_INFO
Definition: mitkLogMacros.h:22
int main(int argc, char **argv)
#define MITK_ERROR
Definition: mitkLogMacros.h:24
std::string DumpImageInformation(const Image *image)
Dump relevant image information for later comparison.
DicomSeriesReader::StringContainer StringContainer
bool CompareImageInformationDumps(const std::string &reference, const std::string &test)
Compare two image information dumps.
std::vector< std::string > LoadDumps(const std::string &fileName)
std::list< itk::SmartPointer< Image > > ImageList
ImageList LoadFiles(const StringContainer &files, itk::SmartPointer< Image > preLoadedVolume=nullptr)
section MAP_FRAME_Mapper_Settings Mapper settings For the mapping of corrected images