Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkDICOMSimpleVolumeImportTest.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 
15 
16 #include <usModuleContext.h>
17 #include <usModuleResource.h>
18 #include <usGetModuleContext.h>
19 #include <usModuleResourceStream.h>
20 #include <usModule.h>
21 #include <usModuleRegistry.h>
22 
23 #include "mitkImageToItk.h"
24 #include "itkImageRegionConstIteratorWithIndex.h"
25 
26 #include "mitkTestingMacros.h"
27 
31 int mitkDICOMSimpleVolumeImportTest(int argc, char* argv[])
32 {
34  typedef itk::Image< short, 3 > ImageType;
35  typedef itk::ImageRegionConstIteratorWithIndex< ImageType > IteratorType;
36 
37  MITK_TEST_BEGIN("mitkDICOMSimpleVolumeImportTest");
38 
39  us::ModuleResource resource =
40  us::ModuleRegistry::GetModule("MitkDICOMReader")->GetResource("configurations/3D/simpleinstancenumber_soft.xml");
41 
42  std::string descr;
43  if ( resource.IsValid() )
44  {
45  us::ModuleResourceStream stream(resource);
46 
47  stream.seekg(0, std::ios::end);
48  descr.reserve(stream.tellg());
49  stream.seekg(0, std::ios::beg);
50 
51  descr.assign((std::istreambuf_iterator<char>(stream)),
52  std::istreambuf_iterator<char>());
53  }
54  mitk::DICOMFileReaderSelector::Pointer readerSelector = mitk::DICOMFileReaderSelector::New();
55 
56  readerSelector->AddConfig( descr );
57  ReaderList readers = readerSelector->GetAllConfiguredReaders();
58 
59  mitk::DICOMFileReader::Pointer simpleReader;
60  for ( ReaderList::const_iterator it = readers.begin(); it != readers.end(); ++it )
61  {
62  mitk::DICOMFileReader::Pointer reader = *it;
63  std::string configLabel = reader->GetConfigurationLabel();
64  if ( configLabel == "Instance Number, non-consecutive, simple import" )
65  {
66  simpleReader = reader;
67  }
68  }
69 
70  MITK_TEST_CONDITION_REQUIRED( simpleReader.IsNotNull(), "DICOMFileReaderSelector is able to create simple reader from XML");
71 
72  if ( argc > 1 )
73  {
75 
79 
80  const mitk::DICOMImageBlockDescriptor block = simpleReader->GetOutput( 0 );
81  const mitk::Image::Pointer mitkImage = block.GetMitkImage();
82 
83  ImageType::Pointer itkImage = mitk::ImageToItkImage<short,3>( mitkImage );
84 
85  IteratorType it( itkImage, itkImage->GetLargestPossibleRegion() );
86  bool success = true;
87  while ( !it.IsAtEnd() )
88  {
89  ImageType::PixelType val = it.Get();
90  ImageType::IndexType ind = it.GetIndex();
91 
92  if ( !(val == ind[2]) )
93  {
94  success = false;
95  break;
96  }
97 
98  ++it;
99  }
100 
101  MITK_TEST_CONDITION( success, "Single block image composed as expected.");
102  }
103 
104  MITK_TEST_END();
105 }
106 
itk::Image< unsigned char, 3 > ImageType
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
static Module * GetModule(long id)
Image::Pointer GetMitkImage() const
the 3D mitk::Image that is loaded from the DICOM files of a DICOMImageFrameList
std::list< DICOMFileReader::Pointer > ReaderList
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
#define MITK_TEST_CONDITION(COND, MSG)
ModuleResource GetResource(const std::string &path) const
Definition: usModule.cpp:267
static void TestSingleBlockIsRead(DICOMFileReader *reader)
Output descriptor for DICOMFileReader.
static void TestOutputsContainInputs(DICOMFileReader *reader)
int mitkDICOMSimpleVolumeImportTest(int argc, char *argv[])
Verify single block reading of SimpleDICOMvolumeImport for sloppily tagged data.
static void SetTestInputFilenames(int argc, char *argv[])
and MITK_TEST_END()
static void TestInputFilenames(DICOMFileReader *reader)