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