Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkRTStructureSetReaderServiceTest.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 <mitkIOUtil.h>
17 #include <mitkContourModelSet.h>
18 
19 class mitkRTStructureSetReaderServiceTestSuite : public mitk::TestFixture
20 {
21  CPPUNIT_TEST_SUITE(mitkRTStructureSetReaderServiceTestSuite);
22  MITK_TEST(TestStructureSets);
23  CPPUNIT_TEST_SUITE_END();
24 
25 private:
26  std::vector<mitk::ContourModelSet::Pointer> structureSets;
27 
28 public:
29 
30  void setUp() override
31  {
32  auto baseDataVector = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/RS.dcm"));
33  //16 structures are in the data set
34  CPPUNIT_ASSERT_EQUAL(baseDataVector.size(), size_t(16));
35  for (auto& baseData : baseDataVector) {
36  auto contour = dynamic_cast<mitk::ContourModelSet*>(baseData.GetPointer());
37  CPPUNIT_ASSERT_EQUAL(contour != nullptr, true);
38  //only compare structs with content
39  if (contour->GetSize() > 0) {
40  structureSets.push_back(contour);
41  }
42  }
43  }
44 
45  void TestStructureSets()
46  {
47  auto contourModelVectorCorrect = LoadGroundTruthData();
48 
49  bool equal = true;
50  unsigned int comparedStructs = 0;
51  for (const auto& aStructTest : structureSets)
52  {
53  const std::string nameTest = aStructTest->GetProperty("name")->GetValueAsString();
54  for (const auto& aStructCorrect : contourModelVectorCorrect)
55  {
56  const std::string nameCorrect = aStructCorrect->GetProperty("name")->GetValueAsString();
57  if (nameTest == nameCorrect) {
58  if (!Compare(aStructTest, aStructCorrect)) {
59  equal = false;
60  }
61  else {
62  comparedStructs++;
63  }
64  }
65  }
66  }
67 
68  CPPUNIT_ASSERT(equal);
69  //only 6 structure sets have content
70  unsigned int structsExpected = 6;
71  CPPUNIT_ASSERT_EQUAL(comparedStructs, structsExpected);
72 
73  }
74 
76  if (c1->GetSize() != c2->GetSize())
77  {
78  MITK_INFO << "Number of ContourModelSets different" << std::endl;
79  return false;
80  }
81  else
82  {
83  for (int i = 0; i < c1->GetSize(); ++i)
84  {
85  mitk::ContourModel::Pointer cm1 = c1->GetContourModelAt(i);
86  mitk::ContourModel::Pointer cm2 = c2->GetContourModelAt(i);
87 
88  if (cm1->GetNumberOfVertices() != cm2->GetNumberOfVertices())
89  {
90  MITK_INFO << "Number of Vertices different" << std::endl;
91  return false;
92  }
93  else
94  {
95  for (int j = 0; j < cm1->GetNumberOfVertices(); ++j)
96  {
97  mitk::Point3D p1 = cm1->GetVertexAt(i)->Coordinates;
98  mitk::Point3D p2 = cm2->GetVertexAt(i)->Coordinates;
99  if (!Equal(p1, p2, 0.001)) {
100  return false;
101  }
102  }
103  }
104  }
105  }
106  return true;
107  }
108 
109  mitk::ContourModelSet::Pointer LoadFileWithNameProperty(const std::string& filename, const std::string& propertyName) {
110  auto readerOutput = mitk::IOUtil::Load(GetTestDataFilePath(filename));
111  mitk::ContourModelSet::Pointer contourSet = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
112  contourSet->SetProperty("name", mitk::StringProperty::New(propertyName));
113  return contourSet;
114  }
115 
116  std::vector<mitk::ContourModelSet::Pointer> LoadGroundTruthData()
117  {
118  std::vector<mitk::ContourModelSet::Pointer> allStructs;
119 
120  allStructs.push_back(LoadFileWithNameProperty("RT/StructureSet/BODY.cnt_set", "BODY"));
121  allStructs.push_back(LoadFileWithNameProperty("RT/StructureSet/Bladder.cnt_set", "Bladder"));
122  allStructs.push_back(LoadFileWithNameProperty("RT/StructureSet/Femoral Head Lt.cnt_set", "Femoral Head Lt"));
123  allStructs.push_back(LoadFileWithNameProperty("RT/StructureSet/Femoral Head RT.cnt_set", "Femoral Head RT"));
124  allStructs.push_back(LoadFileWithNameProperty("RT/StructureSet/PTV.cnt_set", "PTV"));
125  allStructs.push_back(LoadFileWithNameProperty("RT/StructureSet/Rectum.cnt_set", "Rectum"));
126 
127  return allStructs;
128  }
129 
130 };
131 
132 MITK_TEST_SUITE_REGISTRATION(mitkRTStructureSetReaderService)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_INFO
Definition: mitkLogMacros.h:18
#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.
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 Pointer New()
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:489