Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkRawImageFileReaderTest.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 "mitkIOConstants.h"
18 #include "mitkIOUtil.h"
19 #include "mitkTestFixture.h"
20 #include "mitkTestingMacros.h"
21 
22 class mitkRawImageFileReaderTestSuite : public mitk::TestFixture
23 {
24  CPPUNIT_TEST_SUITE(mitkRawImageFileReaderTestSuite);
25  MITK_TEST(testReadFile);
26  CPPUNIT_TEST_SUITE_END();
27 
28 private:
30  std::string m_ImagePath;
31  std::string m_ImagePathNrrdRef; // corresponding mhd path for comparision
32 
33 public:
38  void setUp() override
39  {
40  m_ImagePath = GetTestDataFilePath("brain.raw");
41  m_ImagePathNrrdRef = GetTestDataFilePath("brainHalfSize.nrrd"); // we need half size because the brain file has
42  // spacing 2 and this reader doesn't support spacing
43  }
44 
45  void tearDown() override {}
46  void testReadFile()
47  {
49  options[mitk::IOConstants::DIMENSION()] = 3;
51  options[mitk::IOConstants::SIZE_X()] = 91;
52  options[mitk::IOConstants::SIZE_Y()] = 109;
53  options[mitk::IOConstants::SIZE_Z()] = 91;
55  mitk::Image::Pointer readFile =
56  dynamic_cast<mitk::Image *>(mitk::IOUtil::Load(m_ImagePath, options).front().GetPointer());
57  CPPUNIT_ASSERT_MESSAGE("Testing reading a raw file.", readFile.IsNotNull());
58 
59  // compare with the reference image
60  mitk::Image::Pointer compareImage = mitk::IOUtil::LoadImage(m_ImagePathNrrdRef);
62  compareImage, readFile, "Testing if image is equal to the same image as reference file loaded with mitk");
63  }
64 };
65 
66 MITK_TEST_SUITE_REGISTRATION(mitkRawImageFileReader)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:73
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
static std::string SIZE_Z()
Image class for storing images.
Definition: mitkImage.h:76
Test fixture for parameterized tests.
#define MITK_ASSERT_EQUAL(EXPECTED, ACTUAL, MSG)
Testing macro to test if two objects are equal.
static std::string DIMENSION()
static std::string SIZE_X()
static std::string ENDIANNESS_LITTLE()
static std::string ENDIANNESS()
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:483
static std::string PIXEL_TYPE_FLOAT()
static std::string SIZE_Y()
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:597
static std::string PIXEL_TYPE()