Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkRTStructureSetReaderTest.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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkTestingMacros.h"
18 #include <mitkTestFixture.h>
19 
21 #include <mitkIOUtil.h>
22 #include <mitkStringProperty.h>
23 
24 class mitkRTStructureSetReaderTestSuite : public mitk::TestFixture
25 {
26  CPPUNIT_TEST_SUITE(mitkRTStructureSetReaderTestSuite);
27 // MITK_TEST(TestBody);
28  MITK_TEST(TestStructureSets);
29  CPPUNIT_TEST_SUITE_END();
30 
31 private:
32 
33  mitk::RTStructureSetReader::Pointer m_rtStructureReader;
34 
35 public:
36 
37  void setUp() override
38  {
39  m_rtStructureReader = mitk::RTStructureSetReader::New();
40  CPPUNIT_ASSERT_MESSAGE("Failed to initialize RTStructureSetReader", m_rtStructureReader.IsNotNull());
41  }
42 
43  void TestStructureSets()
44  {
45  std::deque<mitk::ContourModelSet::Pointer> contourModelVectorCorrect;
46  std::deque<mitk::ContourModelSet::Pointer> contourModelVectorCorrectSequ;
47  std::deque<mitk::DataNode::Pointer> contourModelVectorTest;
48  std::deque<mitk::ContourModelSet::Pointer> contourModelVectorTestDel;
49 
50  LoadData(contourModelVectorCorrect);
51 
52  contourModelVectorTest = m_rtStructureReader->ReadStructureSet(GetTestDataFilePath("RT/StructureSet/RS.dcm").c_str());
53 
54  //Deleting all empty contourmodelsets - empty contourmodelsets cant be
55  //saved so we have reference for the comparison
56  for(unsigned int i=0; i<contourModelVectorTest.size();++i)
57  {
58  if(dynamic_cast<mitk::ContourModelSet*>(contourModelVectorTest.at(i)->GetData())->GetSize()>0){
59  contourModelVectorTestDel.push_back(dynamic_cast<mitk::ContourModelSet*>(contourModelVectorTest.at(i)->GetData()));
60  }
61  }
62 
63  //Loop for ordering the loaded contourmodelsets(contourModelVectorCorrect)
64  for(unsigned int i=0; i<contourModelVectorTestDel.size();++i)
65  {
66  mitk::BaseProperty::Pointer name = contourModelVectorTestDel.at(i)->GetProperty("name");
67  for(unsigned int j=0; j<contourModelVectorCorrect.size();++j)
68  {
69  mitk::BaseProperty::Pointer tmp = contourModelVectorCorrect.at(j)->GetProperty("name");
70  if(tmp->GetValueAsString().compare(name->GetValueAsString()) == 0)
71  contourModelVectorCorrectSequ.push_back(contourModelVectorCorrect.at(j));
72  }
73  }
74 
75  //Testing wheather the two deques are equal
76  bool equal = true;
77  for(unsigned int i=0;i<contourModelVectorCorrectSequ.size();++i)
78  {
79  if(!Compare(contourModelVectorCorrectSequ.at(i),contourModelVectorTestDel.at(i)))
80  equal = false;
81  }
82 
83  CPPUNIT_ASSERT(equal);
84  }
85 
87  if(c1->GetSize()!=c2->GetSize())
88  {
89  MITK_INFO << "Number of ContourModelSets different" << std::endl;
90  return false;
91  }
92  else
93  {
94  for(int i=0;i<c1->GetSize();++i)
95  {
96  mitk::ContourModel::Pointer cm1 = c1->GetContourModelAt(i);
97  mitk::ContourModel::Pointer cm2 = c2->GetContourModelAt(i);
98  if(cm1->GetNumberOfVertices()!=cm2->GetNumberOfVertices())
99  {
100  MITK_INFO << "Number of Vertices different" << std::endl;
101  return false;
102  }
103  else
104  {
105  float ep = 0.001;
106  for(int j=0;j<cm1->GetNumberOfVertices();++j)
107  {
108  mitk::Point3D p1 = cm1->GetVertexAt(i)->Coordinates;
109  mitk::Point3D p2 = cm2->GetVertexAt(i)->Coordinates;
110  if(fabs(p1[0]-p2[0]) > ep || fabs(p1[0]-p2[0]) > ep || fabs(p1[0]-p2[0]) > ep)
111  {
112  return false;
113  }
114  }
115  }
116  }
117  }
118  return true;
119  }
120 
121  void LoadData(std::deque<mitk::ContourModelSet::Pointer> &r)
122  {
123  std::vector<itk::SmartPointer<mitk::BaseData> > readerOutput;
124 
125  readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/BODY.cnt_set"));
126  mitk::ContourModelSet::Pointer cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
127  cnt_set->SetProperty("name", mitk::StringProperty::New("BODY"));
128  r.push_back(cnt_set);
129 
130  readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Bladder.cnt_set"));
131  cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
132  cnt_set->SetProperty("name", mitk::StringProperty::New("Bladder"));
133  r.push_back(cnt_set);
134 
135  readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Femoral Head Lt.cnt_set"));
136  cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
137  cnt_set->SetProperty("name", mitk::StringProperty::New("Femoral Head Lt"));
138  r.push_back(cnt_set);
139 
140  readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Femoral Head RT.cnt_set"));
141  cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
142  cnt_set->SetProperty("name", mitk::StringProperty::New("Femoral Head RT"));
143  r.push_back(cnt_set);
144 
145  readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/PTV.cnt_set"));
146  cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
147  cnt_set->SetProperty("name", mitk::StringProperty::New("PTV"));
148  r.push_back(cnt_set);
149 
150  readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Rectum.cnt_set"));
151  cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
152  cnt_set->SetProperty("name", mitk::StringProperty::New("Rectum"));
153  r.push_back(cnt_set);
154  }
155 
156 };
157 
158 MITK_TEST_SUITE_REGISTRATION(mitkRTStructureSetReader)
itk::SmartPointer< Self > Pointer
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_INFO
Definition: mitkLogMacros.h:22
#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.
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:483
static Pointer New()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.