Medical Imaging Interaction Toolkit  2018.4.99-a28b433c
Medical Imaging Interaction Toolkit
mitkImageDataItemTest.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 <array>
14 
15 #include "mitkTestFixture.h"
16 #include "mitkTestingMacros.h"
17 
18 #include <mitkImageDataItem.h>
19 
20 #include <mitkPixelType.h>
21 #include <mitkImage.h>
23 
24 class mitkImageDataItemTestSuite : public mitk::TestFixture
25 {
26  CPPUNIT_TEST_SUITE(mitkImageDataItemTestSuite);
27  MITK_TEST(TestAccessOnHugeImage);
28  CPPUNIT_TEST_SUITE_END();
29 
30 private:
31  mitk::Image::Pointer m_Image;
32 
33 public:
34  void setUp() override
35  {
36  m_Image = mitk::Image::New();
37  mitk::PixelType pixelType = mitk::MakeScalarPixelType<unsigned char>();
38 
39  std::array<unsigned int, 3> dimensions = {{ 1700, 1700, 1700 }};
40  m_Image->Initialize(pixelType, 3, dimensions.data());
41  }
42 
43  void TestAccessOnHugeImage()
44  {
45  CPPUNIT_ASSERT(m_Image.IsNotNull());
46 
47  try
48  {
49  mitk::ImagePixelWriteAccessor<unsigned char, 3> writeAccess(m_Image.GetPointer(), m_Image->GetVolumeData());
50 
51  auto* voxelStart = writeAccess.GetData();
52  size_t imageSize = 1;
53  for (unsigned int i = 0; i < m_Image->GetDimension(); i++)
54  imageSize *= m_Image->GetDimension(i);
55 
56  auto* voxelEnd = voxelStart + imageSize;
57 
58  CPPUNIT_ASSERT(writeAccess.GetData() != nullptr);
59  auto* accessCheck = voxelEnd - 1;
60  *accessCheck = 1;
61  }
62  catch (const itk::MemoryAllocationError& e)
63  {
64  MITK_ERROR << e.what();
65  exit(77);
66  }
67  }
68 };
69 
70 MITK_TEST_SUITE_REGISTRATION(mitkImageDataItem)
Gives locked and index-based write access for a particular image part. The class provides several set...
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_ERROR
Definition: mitkLogMacros.h:20
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Test fixture for parameterized tests.
static Pointer New()
virtual TPixel * GetData() const
Gives full data access.
Class for defining the data type of pixels.
Definition: mitkPixelType.h:51