diff --git a/Modules/DicomRT/Testing/mitkRTStructureSetReaderTest.cpp b/Modules/DicomRT/Testing/mitkRTStructureSetReaderTest.cpp index 417c4e4243..6615729171 100644 --- a/Modules/DicomRT/Testing/mitkRTStructureSetReaderTest.cpp +++ b/Modules/DicomRT/Testing/mitkRTStructureSetReaderTest.cpp @@ -1,165 +1,165 @@ /*=================================================================== 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 #include "mitkRTStructureSetReader.h" #include #include #include class mitkRTStructureSetReaderTestSuite : public mitk::TestFixture { 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 contourModelVectorTest; std::deque contourModelVectorTestDel; LoadData(contourModelVectorCorrect); contourModelVectorTest = m_rtStructureReader->ReadStructureSet(GetTestDataFilePath("RT/StructureSet/RS.dcm").c_str()); //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)); + if(dynamic_cast(contourModelVectorTest.at(i)->GetData())->GetSize()>0){ + contourModelVectorTestDel.push_back(dynamic_cast(contourModelVectorTest.at(i)->GetData())); } } //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_SUITE_REGISTRATION(mitkRTStructureSetReader) diff --git a/Modules/DicomRT/mitkRTStructureSetReader.cpp b/Modules/DicomRT/mitkRTStructureSetReader.cpp index 260d95f2eb..5f7f82a519 100644 --- a/Modules/DicomRT/mitkRTStructureSetReader.cpp +++ b/Modules/DicomRT/mitkRTStructureSetReader.cpp @@ -1,230 +1,247 @@ /*=================================================================== 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 "mitkRTStructureSetReader.h" #include +#include + namespace mitk { RTStructureSetReader::RTStructureSetReader(){} RTStructureSetReader::~RTStructureSetReader(){} RTStructureSetReader::RoiEntry::RoiEntry() { Number = 0; DisplayColor[0]=1.0; DisplayColor[1]=0.0; DisplayColor[2]=0.0; ContourModelSet=mitk::ContourModelSet::New(); } RTStructureSetReader::RoiEntry::RoiEntry(const RoiEntry &src) { Number=src.Number; Name=src.Name; Description=src.Description; DisplayColor[0]=src.DisplayColor[0]; DisplayColor[1]=src.DisplayColor[1]; DisplayColor[2]=src.DisplayColor[2]; ContourModelSet=mitk::ContourModelSet::New(); SetPolyData(src.ContourModelSet); } RTStructureSetReader::RoiEntry::~RoiEntry(){} RTStructureSetReader::RoiEntry& RTStructureSetReader:: RoiEntry::operator =(const RoiEntry &src) { Number=src.Number; Name=src.Name; Description=src.Description; DisplayColor[0]=src.DisplayColor[0]; DisplayColor[1]=src.DisplayColor[1]; DisplayColor[2]=src.DisplayColor[2]; SetPolyData(src.ContourModelSet); return (*this); } void RTStructureSetReader::RoiEntry:: SetPolyData(mitk::ContourModelSet::Pointer roiPolyData) { if (roiPolyData == this->ContourModelSet) return; this->ContourModelSet = roiPolyData; } size_t RTStructureSetReader::GetNumberOfROIs() { return this->ROISequenceVector.size(); } RTStructureSetReader::RoiEntry* RTStructureSetReader:: FindRoiByNumber(unsigned int roiNum) { for(unsigned int i=0; iROISequenceVector.size(); ++i) { if(this->ROISequenceVector[i].Number == roiNum) return &this->ROISequenceVector[i]; } return NULL; } - std::deque RTStructureSetReader:: - ReadStructureSet(const char* filepath) + RTStructureSetReader::ContourModelSetNodes RTStructureSetReader::ReadStructureSet(const char* filepath) { DcmFileFormat file; OFCondition output = file.loadFile(filepath, EXS_Unknown); if(output.bad()) { MITK_ERROR << "Cant read the file" << endl; } DcmDataset *dataset = file.getDataset(); ContourModelSetVector contourModelSetVector; DRTStructureSetIOD structureSetObject; OFCondition outp = structureSetObject.read(*dataset); if(!outp.good()) { MITK_ERROR << "Error reading the file" << endl; - std::deque x; + RTStructureSetReader::ContourModelSetNodes x; return x; } DRTStructureSetROISequence &roiSequence = structureSetObject.getStructureSetROISequence(); if(!roiSequence.gotoFirstItem().good()) { MITK_ERROR << "Error reading the structure sequence" << endl; - std::deque x; + RTStructureSetReader::ContourModelSetNodes x; return x; } do{ DRTStructureSetROISequence::Item ¤tSequence = roiSequence.getCurrentItem(); if(!currentSequence.isValid()) { continue; } OFString roiName; OFString roiDescription; Sint32 roiNumber; RoiEntry roi; currentSequence.getROIName(roiName); currentSequence.getROIDescription(roiDescription); currentSequence.getROINumber(roiNumber); roi.Name = roiName.c_str(); roi.Description = roiDescription.c_str(); roi.Number = roiNumber; this->ROISequenceVector.push_back(roi); } while(roiSequence.gotoNextItem().good()); Sint32 refRoiNumber; DRTROIContourSequence &roiContourSeqObject = structureSetObject.getROIContourSequence(); if(!roiContourSeqObject.gotoFirstItem().good()) { MITK_ERROR << "Error reading the contour sequence" << endl; - std::deque x; + RTStructureSetReader::ContourModelSetNodes x; return x; } do { mitk::ContourModelSet::Pointer contourSet = mitk::ContourModelSet::New(); DRTROIContourSequence::Item ¤tRoiObject = roiContourSeqObject.getCurrentItem(); if(!currentRoiObject.isValid()) { continue; } currentRoiObject.getReferencedROINumber(refRoiNumber); DRTContourSequence &contourSeqObject = currentRoiObject.getContourSequence(); if(contourSeqObject.gotoFirstItem().good()) { do { DRTContourSequence::Item &contourItem = contourSeqObject.getCurrentItem(); if(!contourItem.isValid()) { continue; } int number; OFString contourNumber; OFString numberOfPoints; OFVector contourData_LPS; mitk::ContourModel::Pointer contourSequence = mitk::ContourModel::New(); contourItem.getContourNumber(contourNumber); contourItem.getNumberOfContourPoints(numberOfPoints); contourItem.getContourData(contourData_LPS); std::stringstream stream; stream << numberOfPoints; stream >> number; for(unsigned int i=0; iAddVertex(point); } contourSequence->Close(); contourSet->AddContourModel(contourSequence); } while(contourSeqObject.gotoNextItem().good()); } else { MITK_ERROR << "Error reading contourSeqObject" << endl; } RoiEntry* refROI = this->FindRoiByNumber(refRoiNumber); if(refROI==NULL) { MITK_ERROR << "Can not find references ROI" << endl; continue; } Sint32 roiColor; for(int j=0;j<3;j++) { currentRoiObject.getROIDisplayColor(roiColor, j); refROI->DisplayColor[j] = roiColor/255.0; } refROI->ContourModelSet = contourSet; contourSet->SetProperty("name", mitk::StringProperty::New(refROI->Name)); contourSet->SetProperty("contour.color", mitk::ColorProperty::New( refROI->DisplayColor[0], refROI->DisplayColor[1], refROI->DisplayColor[2])); contourModelSetVector.push_back(contourSet); } while(roiContourSeqObject.gotoNextItem().good()); - return contourModelSetVector; + std::deque nodes; + + for(int i=0; iSetData(contourModelSetVector.at(i)); + node->SetProperty("name", contourModelSetVector.at(i)->GetProperty("name")); + node->SetProperty("color",contourModelSetVector.at(i)->GetProperty("contour.color")); + node->SetProperty("contour.color",contourModelSetVector.at(i)->GetProperty("contour.color")); + node->SetVisibility(true, mitk::BaseRenderer::GetInstance( mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget1"))); + node->SetVisibility(false, mitk::BaseRenderer::GetInstance( mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget2"))); + node->SetVisibility(false, mitk::BaseRenderer::GetInstance( mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget3"))); + node->SetVisibility(true, mitk::BaseRenderer::GetInstance( mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget4"))); + nodes.push_back(node); + } + + return nodes; } } diff --git a/Modules/DicomRT/mitkRTStructureSetReader.h b/Modules/DicomRT/mitkRTStructureSetReader.h index aa7eabfc10..f1d7833f44 100644 --- a/Modules/DicomRT/mitkRTStructureSetReader.h +++ b/Modules/DicomRT/mitkRTStructureSetReader.h @@ -1,69 +1,72 @@ /*=================================================================== 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" +#include + namespace mitk { class MitkDicomRT_EXPORT RTStructureSetReader: public itk::Object { typedef std::deque ContourModelSetVector; + typedef std::deque ContourModelSetNodes; 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(const char* filepath); + ContourModelSetNodes ReadStructureSet(const char* filepath); protected: std::vector ROISequenceVector; RTStructureSetReader(); virtual ~RTStructureSetReader(); size_t GetNumberOfROIs(); RoiEntry* FindRoiByNumber(unsigned int roiNum); }; } #endif // MITKRTSTRUCTURESETREADER_H