Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkSimulationBatchGeneratorTest.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 #include <mitkTestFixture.h>
13 #include <mitkTestingMacros.h>
14 
16 #include <mitkPAVolume.h>
17 #include <itkFileTools.h>
18 
19 class mitkSimulationBatchGeneratorTestSuite : public mitk::TestFixture
20 {
21  CPPUNIT_TEST_SUITE(mitkSimulationBatchGeneratorTestSuite);
22  MITK_TEST(testGenerateBatchFileString);
23  MITK_TEST(testGenerateBatchFileAndSaveFile);
24  CPPUNIT_TEST_SUITE_END();
25 
26 private:
27 
28  const std::string TEST_FOLDER_PATH = "testFiles/";
29  mitk::pa::SimulationBatchGeneratorParameters::Pointer m_Parameters;
30  mitk::pa::Volume::Pointer m_Test3DVolume;
31 
32 public:
33 
34  void setUp() override
35  {
37  m_Parameters->SetBinaryPath("binary");
38  m_Parameters->SetNrrdFilePath(TEST_FOLDER_PATH);
39  m_Parameters->SetNumberOfPhotons(100);
40  m_Parameters->SetTissueName("tissueName");
41  m_Parameters->SetVolumeIndex(0);
42  m_Parameters->SetYOffsetLowerThresholdInCentimeters(-1);
43  m_Parameters->SetYOffsetUpperThresholdInCentimeters(1);
44  m_Parameters->SetYOffsetStepInCentimeters(0.5);
45 
46  m_Test3DVolume = createTest3DVolume(5);
47  itk::FileTools::CreateDirectory(TEST_FOLDER_PATH);
48  CPPUNIT_ASSERT(itksys::SystemTools::FileIsDirectory(TEST_FOLDER_PATH));
49  }
50 
51  mitk::pa::Volume::Pointer createTest3DVolume(double value)
52  {
53  unsigned int xDim = 10;
54  unsigned int yDim = 10;
55  unsigned int zDim = 10;
56  unsigned int length = xDim * yDim * zDim;
57  auto* data = new double[length];
58  for (unsigned int i = 0; i < length; i++)
59  data[i] = value;
60 
61  return mitk::pa::Volume::New(data, xDim, yDim, zDim, 1);
62  }
63 
64  void testGenerateBatchFileString()
65  {
66  std::string batchGenerationString = mitk::pa::SimulationBatchGenerator::CreateBatchSimulationString(m_Parameters);
67  CPPUNIT_ASSERT(!batchGenerationString.empty());
68  }
69 
70  void testGenerateBatchFileAndSaveFile()
71  {
72  mitk::pa::SimulationBatchGenerator::WriteBatchFileAndSaveTissueVolume(m_Parameters, m_Test3DVolume->AsMitkImage());
73  CPPUNIT_ASSERT(itksys::SystemTools::FileExists(TEST_FOLDER_PATH + m_Parameters->GetTissueName() + "000.nrrd"));
74  CPPUNIT_ASSERT(itksys::SystemTools::FileExists(TEST_FOLDER_PATH + "simulate_all.sh") || itksys::SystemTools::FileExists(TEST_FOLDER_PATH + "simulate_all.bat"));
75  CPPUNIT_ASSERT(itksys::SystemTools::FileExists(TEST_FOLDER_PATH + m_Parameters->GetTissueName() + "000")
76  && itksys::SystemTools::FileIsDirectory(TEST_FOLDER_PATH + m_Parameters->GetTissueName() + "000"));
77  }
78 
79  void tearDown() override
80  {
81  m_Parameters = nullptr;
82  CPPUNIT_ASSERT_MESSAGE("Resource leak of test files onto hard drive..", itksys::SystemTools::RemoveADirectory(TEST_FOLDER_PATH) == true);
83  }
84 };
85 
86 MITK_TEST_SUITE_REGISTRATION(mitkSimulationBatchGenerator)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static void WriteBatchFileAndSaveTissueVolume(SimulationBatchGeneratorParameters::Pointer parameters, mitk::Image::Pointer tissueVolume)
static std::string CreateBatchSimulationString(SimulationBatchGeneratorParameters::Pointer parameter)
Test fixture for parameterized tests.
static Volume::Pointer New(double *data, unsigned int xDim, unsigned int yDim, unsigned int zDim, double spacing)
returns smartpointer reference to a new instance of this objects. The given data array will be freed ...