Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (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 
13 #include "mitkIOConstants.h"
14 #include "mitkIOUtil.h"
15 #include "mitkTestFixture.h"
16 #include "mitkTestingMacros.h"
17 
18 class mitkRawImageFileReaderTestSuite : public mitk::TestFixture
19 {
20  CPPUNIT_TEST_SUITE(mitkRawImageFileReaderTestSuite);
21  MITK_TEST(testReadFile);
22  CPPUNIT_TEST_SUITE_END();
23 
24 private:
26  std::string m_ImagePath;
27  std::string m_ImagePathNrrdRef; // corresponding mhd path for comparision
28 
29 public:
34  void setUp() override
35  {
36  m_ImagePath = GetTestDataFilePath("brain.raw");
37  m_ImagePathNrrdRef = GetTestDataFilePath("brainHalfSize.nrrd"); // we need half size because the brain file has
38  // spacing 2 and this reader doesn't support spacing
39  }
40 
41  void tearDown() override {}
42  void testReadFile()
43  {
45  options[mitk::IOConstants::DIMENSION()] = 3;
47  options[mitk::IOConstants::SIZE_X()] = 91;
48  options[mitk::IOConstants::SIZE_Y()] = 109;
49  options[mitk::IOConstants::SIZE_Z()] = 91;
51  mitk::Image::Pointer readFile =
52  mitk::IOUtil::Load<mitk::Image >(m_ImagePath, options);
53  CPPUNIT_ASSERT_MESSAGE("Testing reading a raw file.", readFile.IsNotNull());
54 
55  // compare with the reference image
56  mitk::Image::Pointer compareImage = mitk::IOUtil::Load<mitk::Image>(m_ImagePathNrrdRef);
58  compareImage, readFile, "Testing if image is equal to the same image as reference file loaded with mitk");
59  }
60 };
61 
62 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:69
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
static std::string SIZE_Z()
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 std::string PIXEL_TYPE_FLOAT()
static std::string SIZE_Y()
static std::string PIXEL_TYPE()