Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkRTDoseReaderServiceTest.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 <mitkTestingMacros.h>
14 #include <mitkTestFixture.h>
15 
16 #include <mitkRTConstants.h>
17 #include <mitkGenericProperty.h>
19 #include <mitkIOUtil.h>
20 
21 class mitkRTDoseReaderServiceTestSuite : public mitk::TestFixture
22 {
23  CPPUNIT_TEST_SUITE(mitkRTDoseReaderServiceTestSuite);
24  MITK_TEST(TestDoseImage);
25  MITK_TEST(TestProperties);
26  CPPUNIT_TEST_SUITE_END();
27 
28 private:
29  mitk::Image::ConstPointer m_doseImage;
30  mitk::Image::ConstPointer m_referenceImage;
31 
32 public:
33 
34  void setUp() override
35  {
36  m_referenceImage = mitk::IOUtil::Load<mitk::Image>(GetTestDataFilePath("RT/Dose/RT_Dose.nrrd"));
37  m_doseImage = mitk::IOUtil::Load<mitk::Image>(GetTestDataFilePath("RT/Dose/RD.dcm"));
38  }
39 
40  void TestDoseImage()
41  {
42  CPPUNIT_ASSERT_EQUAL_MESSAGE("image should not be null", m_doseImage.IsNotNull(), true);
43  CPPUNIT_ASSERT_EQUAL_MESSAGE("reference image and image should be equal", true, mitk::Equal(*m_doseImage, *m_referenceImage, mitk::eps, true));
44  }
45 
46  void TestProperties() {
47  CheckStringProperty("DICOM.0008.0060", "RTDOSE"); //Modality
48  auto prescibedDoseProperty = m_doseImage->GetProperty(mitk::RTConstants::PRESCRIBED_DOSE_PROPERTY_NAME.c_str());
49  auto prescribedDoseGenericProperty = dynamic_cast<mitk::GenericProperty<double>*>(prescibedDoseProperty.GetPointer());
50  double actualPrescribedDose = prescribedDoseGenericProperty->GetValue();
51  double expectedPrescribedDose = 65535 * 0.0010494648*0.8;
52  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("prescribed dose property is not as expected", expectedPrescribedDose, actualPrescribedDose, 1e-5);
53  CheckStringProperty("DICOM.0020.000D", "1.2.826.0.1.3680043.8.176.2013826104517910.408.3433258507"); //StudyInstanceUID
54  CheckStringProperty("DICOM.3004.000E", "0.0010494648"); //DoseGridScaling
55  CheckStringProperty("DICOM.300C.0002.[0].0008.1155", "1.2.826.0.1.3680043.8.176.2013826104526987.672.1228523524"); //ReferencedRTPlanSequence.ReferencedSOPInstanceUID
56  }
57 
58  void CheckStringProperty(const std::string& propertyName, const std::string& expectedPropertyValue)
59  {
60  auto actualProperty = m_doseImage->GetProperty(propertyName.c_str());
61  CPPUNIT_ASSERT_EQUAL_MESSAGE("Property not found: " + propertyName, actualProperty.IsNotNull(), true);
62  auto actualTemporoSpatialStringProperty = dynamic_cast<mitk::TemporoSpatialStringProperty*>(actualProperty.GetPointer());
63  CPPUNIT_ASSERT_EQUAL_MESSAGE("Property has not type string: " + propertyName, actualTemporoSpatialStringProperty != nullptr, true);
64  std::string actualStringProperty = actualTemporoSpatialStringProperty->GetValue();
65  CPPUNIT_ASSERT_EQUAL_MESSAGE(propertyName + " is not as expected", actualStringProperty, expectedPropertyValue);
66  }
67 
68 };
69 
70 MITK_TEST_SUITE_REGISTRATION(mitkRTDoseReaderService)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
virtual T GetValue() const
Test fixture for parameterized tests.
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
static const std::string PRESCRIBED_DOSE_PROPERTY_NAME
MITKCORE_EXPORT const ScalarType eps
Property for time and space resolved string values.