diff --git a/Modules/DicomRT/Testing/mitkRTStructureSetReaderTest.cpp b/Modules/DicomRT/Testing/mitkRTStructureSetReaderTest.cpp index e2da33a97f..ec9d3039b4 100644 --- a/Modules/DicomRT/Testing/mitkRTStructureSetReaderTest.cpp +++ b/Modules/DicomRT/Testing/mitkRTStructureSetReaderTest.cpp @@ -1,28 +1,169 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkTestingMacros.h" -#include "mitkRTStructureSetReader.h" -#include +#include +#include "mitkRTStructureSetReader.h" +#include +#include +#include -int mitkRTStructureSetReaderTest(int argc , char* argv[]) +class mitkRTStructureSetReaderTestSuite : public mitk::TestFixture { - // always start with this! - MITK_TEST_BEGIN("DicomRTReader") + CPPUNIT_TEST_SUITE(mitkRTStructureSetReaderTestSuite); +// MITK_TEST(TestBody); + MITK_TEST(TestStructureSets); + CPPUNIT_TEST_SUITE_END(); + +private: + + mitk::RTStructureSetReader::Pointer m_rtStructureReader; + +public: + + void setUp() + { + m_rtStructureReader = mitk::RTStructureSetReader::New(); + CPPUNIT_ASSERT_MESSAGE("Failed to initialize RTStructureSetReader", m_rtStructureReader.IsNotNull()); + } + + void TestStructureSets() + { + std::deque contourModelVectorCorrect; + std::deque contourModelVectorCorrectSequ; + std::deque contourModelVectorTest; + std::deque contourModelVectorTestDel; + + LoadData(contourModelVectorCorrect); + + DcmFileFormat file; + file.loadFile(GetTestDataFilePath("RT/StructureSet/RS.dcm").c_str(), EXS_Unknown); + DcmDataset *dataset = file.getDataset(); + + contourModelVectorTest = m_rtStructureReader->ReadStructureSet(dataset); + + //Deleting all empty contourmodelsets - empty contourmodelsets cant be + //saved so we have reference for the comparison + for(unsigned int i=0; iGetSize()>0){ + contourModelVectorTestDel.push_back(contourModelVectorTest.at(i)); + } + } + + //Loop for ordering the loaded contourmodelsets(contourModelVectorCorrect) + for(unsigned int i=0; iGetProperty("name"); + for(unsigned int j=0; jGetProperty("name"); + if(tmp->GetValueAsString().compare(name->GetValueAsString()) == 0) + contourModelVectorCorrectSequ.push_back(contourModelVectorCorrect.at(j)); + } + } + + //Testing wheather the two deques are equal + bool equal = true; + for(unsigned int i=0;iGetSize()!=c2->GetSize()) + { + MITK_INFO << "Number of ContourModelSets different" << endl; + return false; + } + else + { + for(int i=0;iGetSize();++i) + { + mitk::ContourModel::Pointer cm1 = c1->GetContourModelAt(i); + mitk::ContourModel::Pointer cm2 = c2->GetContourModelAt(i); + if(cm1->GetNumberOfVertices()!=cm2->GetNumberOfVertices()) + { + MITK_INFO << "Number of Vertices different" << endl; + return false; + } + else + { + float ep = 0.001; + for(int j=0;jGetNumberOfVertices();++j) + { + mitk::Point3D p1 = cm1->GetVertexAt(i)->Coordinates; + mitk::Point3D p2 = cm2->GetVertexAt(i)->Coordinates; + if(abs(p1[0]-p2[0]) > ep || abs(p1[0]-p2[0]) > ep || abs(p1[0]-p2[0]) > ep) + { + return false; + } + } + } + } + } + return true; + } + + void LoadData(std::deque &r) + { + mitk::ContourModelSetReader::Pointer reader = mitk::ContourModelSetReader::New(); + + reader->SetFileName(GetTestDataFilePath("RT/StructureSet/BODY.cnt_set")); + reader->Update(); + mitk::ContourModelSet::Pointer cnt_set = reader->GetOutput(); + cnt_set->SetProperty("name", mitk::StringProperty::New("BODY")); + r.push_back(cnt_set); + + reader->SetFileName(GetTestDataFilePath("RT/StructureSet/Bladder.cnt_set")); + reader->Update(); + cnt_set = reader->GetOutput(); + cnt_set->SetProperty("name", mitk::StringProperty::New("Bladder")); + r.push_back(cnt_set); + + reader->SetFileName(GetTestDataFilePath("RT/StructureSet/Femoral Head Lt.cnt_set")); + reader->Update(); + cnt_set = reader->GetOutput(); + cnt_set->SetProperty("name", mitk::StringProperty::New("Femoral Head Lt")); + r.push_back(cnt_set); + + reader->SetFileName(GetTestDataFilePath("RT/StructureSet/Femoral Head RT.cnt_set")); + reader->Update(); + cnt_set = reader->GetOutput(); + cnt_set->SetProperty("name", mitk::StringProperty::New("Femoral Head RT")); + r.push_back(cnt_set); + + reader->SetFileName(GetTestDataFilePath("RT/StructureSet/PTV.cnt_set")); + reader->Update(); + cnt_set = reader->GetOutput(); + cnt_set->SetProperty("name", mitk::StringProperty::New("PTV")); + r.push_back(cnt_set); + + reader->SetFileName(GetTestDataFilePath("RT/StructureSet/Rectum.cnt_set")); + reader->Update(); + cnt_set = reader->GetOutput(); + cnt_set->SetProperty("name", mitk::StringProperty::New("Rectum")); + r.push_back(cnt_set); + } + +}; - MITK_TEST_END() -} +MITK_TEST_SUITE_REGISTRATION(mitkRTStructureSetReader) diff --git a/Modules/DicomRT/mitkRTStructureSetReader.h b/Modules/DicomRT/mitkRTStructureSetReader.h index 2d07c5456f..82fa6883a2 100644 --- a/Modules/DicomRT/mitkRTStructureSetReader.h +++ b/Modules/DicomRT/mitkRTStructureSetReader.h @@ -1,68 +1,69 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKRTSTRUCTURESETREADER_H #define MITKRTSTRUCTURESETREADER_H #include #include #include #include #include #include "dcmtk/dcmrt/drtstrct.h" namespace mitk { class MitkDicomRT_EXPORT RTStructureSetReader: public itk::Object { typedef std::deque ContourModelSetVector; class RoiEntry { public: RoiEntry(); RoiEntry( const RoiEntry& src); virtual ~RoiEntry(); RoiEntry &operator=(const RoiEntry &src); void SetPolyData(ContourModelSet::Pointer roiPolyData); unsigned int Number; std::string Name; std::string Description; double DisplayColor[3]; mitk::ContourModelSet::Pointer ContourModelSet; }; public: mitkClassMacro( RTStructureSetReader, itk::Object ); itkNewMacro( Self ); + ContourModelSetVector ReadStructureSet(DcmDataset* dataset); + protected: std::vector ROISequenceVector; RTStructureSetReader(); virtual ~RTStructureSetReader(); size_t GetNumberOfROIs(); RoiEntry* FindRoiByNumber(unsigned int roiNum); - ContourModelSetVector ReadStructureSet(DcmDataset* dataset); }; } #endif // MITKRTSTRUCTURESETREADER_H