diff --git a/Modules/DicomRT/include/mitkRTStructureSetReader.h b/Modules/DicomRT/include/mitkRTStructureSetReader.h index 1ac771678d..5cbbc74e8b 100644 --- a/Modules/DicomRT/include/mitkRTStructureSetReader.h +++ b/Modules/DicomRT/include/mitkRTStructureSetReader.h @@ -1,93 +1,93 @@ /*=================================================================== 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 ContourModelSetNodes; - - /** - * Represent a region of interest (ROI) - */ - class RoiEntry + class MITKDICOMRT_EXPORT RTStructureSetReader : public itk::Object { - 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; + typedef std::deque ContourModelSetNodes; + + /** + * Represent a region of interest (ROI) + */ + 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: + mitkClassMacroItkParent(RTStructureSetReader, itk::Object) + itkNewMacro(Self) + + /** + * @brief Reading a RT StructureSet from the DICOM file and returns the ROIs + * (region of interest) as a ContourModelSet. One ContourModelSet represent + * one ROI. A ContourModelSet contains ContourModels which represent the + * single structures. + * @param filepath to the RT StructureSet (.dmc) file + * @return Returns a std::deque filled with ContourModelSet::Pointer the + * deque contains all ROIs from the DICOM file + */ + ContourModelSetNodes ReadStructureSet(const char* filepath); + + protected: + /** + * containing the ROIs meta information like name number and description + */ + std::vector ROISequenceVector; + + RTStructureSetReader(); + virtual ~RTStructureSetReader(); + + /** + * Returns the number of ROIs from the ROISequenceVector + */ + size_t GetNumberOfROIs(); + + /** + * Returns the relevant ROI from the ROISequenceVector by its number + */ + RoiEntry* FindRoiByNumber(unsigned int roiNum); }; - - public: - mitkClassMacroItkParent( RTStructureSetReader, itk::Object ) - itkNewMacro( Self ) - - /** - * @brief Reading a RT StructureSet from the DICOM file and returns the ROIs - * (region of interest) as a ContourModelSet. One ContourModelSet represent - * one ROI. A ContourModelSet contains ContourModels which represent the - * single structures. - * @param filepath to the RT StructureSet (.dmc) file - * @return Returns a std::deque filled with ContourModelSet::Pointer the - * deque contains all ROIs from the DICOM file - */ - ContourModelSetNodes ReadStructureSet(const char* filepath); - - protected: - /** - * containing the ROIs meta information like name number and description - */ - std::vector ROISequenceVector; - - RTStructureSetReader(); - virtual ~RTStructureSetReader(); - - /** - * Returns the number of ROIs from the ROISequenceVector - */ - size_t GetNumberOfROIs(); - - /** - * Returns the relevant ROI from the ROISequenceVector by its number - */ - RoiEntry* FindRoiByNumber(unsigned int roiNum); - }; } #endif // MITKRTSTRUCTURESETREADER_H diff --git a/Modules/DicomRT/src/mitkRTStructureSetReader.cpp b/Modules/DicomRT/src/mitkRTStructureSetReader.cpp index 020afe6985..daf4db0240 100644 --- a/Modules/DicomRT/src/mitkRTStructureSetReader.cpp +++ b/Modules/DicomRT/src/mitkRTStructureSetReader.cpp @@ -1,239 +1,283 @@ /*=================================================================== 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 +#include "mitkDICOMTagHelper.h" 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) + RTStructureSetReader::RTStructureSetReader() {} + + RTStructureSetReader::~RTStructureSetReader() {} + + RTStructureSetReader::RoiEntry::RoiEntry() { - if(this->ROISequenceVector[i].Number == roiNum) - return &this->ROISequenceVector[i]; + Number = 0; + DisplayColor[0] = 1.0; + DisplayColor[1] = 0.0; + DisplayColor[2] = 0.0; + ContourModelSet = mitk::ContourModelSet::New(); } - return NULL; - } - - RTStructureSetReader::ContourModelSetNodes RTStructureSetReader:: - ReadStructureSet(const char* filepath) - { - DcmFileFormat file; - OFCondition output = file.loadFile(filepath, EXS_Unknown); - if(output.bad()) + + RTStructureSetReader::RoiEntry::RoiEntry(const RoiEntry& src) { - MITK_ERROR << "Cant read the file" << std::endl; + 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); } - DcmDataset *dataset = file.getDataset(); - DRTStructureSetIOD structureSetObject; - OFCondition outp = structureSetObject.read(*dataset); - if(!outp.good()) + RTStructureSetReader::RoiEntry::~RoiEntry() {} + + RTStructureSetReader::RoiEntry& RTStructureSetReader:: + RoiEntry::operator =(const RoiEntry& src) { - MITK_ERROR << "Error reading the file" << std::endl; - RTStructureSetReader::ContourModelSetNodes x; - return x; + 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); } - DRTStructureSetROISequence &roiSequence = - structureSetObject.getStructureSetROISequence(); - if(!roiSequence.gotoFirstItem().good()) + + void RTStructureSetReader::RoiEntry:: + SetPolyData(mitk::ContourModelSet::Pointer roiPolyData) { - MITK_ERROR << "Error reading the structure sequence" << std::endl; - RTStructureSetReader::ContourModelSetNodes x; - return x; + if (roiPolyData == this->ContourModelSet) + { + return; + } + + this->ContourModelSet = roiPolyData; } - 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); + + size_t RTStructureSetReader::GetNumberOfROIs() + { + return this->ROISequenceVector.size(); } - while(roiSequence.gotoNextItem().good()); - Sint32 refRoiNumber; - DRTROIContourSequence &roiContourSeqObject = - structureSetObject.getROIContourSequence(); - if(!roiContourSeqObject.gotoFirstItem().good()) + RTStructureSetReader::RoiEntry* RTStructureSetReader:: + FindRoiByNumber(unsigned int roiNum) { - MITK_ERROR << "Error reading the contour sequence" << std::endl; - RTStructureSetReader::ContourModelSetNodes x; - return x; + for (unsigned int i = 0; i < this->ROISequenceVector.size(); ++i) + { + if (this->ROISequenceVector[i].Number == roiNum) + { + return &this->ROISequenceVector[i]; + } + } + + return NULL; } - do + + RTStructureSetReader::ContourModelSetNodes RTStructureSetReader:: + ReadStructureSet(const char* filepath) { - 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()) - { + DcmFileFormat file; + OFCondition output = file.loadFile(filepath, EXS_Unknown); + + if (output.bad()) + { + MITK_ERROR << "Cant read the file" << std::endl; + } + + DcmDataset* dataset = file.getDataset(); + + DRTStructureSetIOD structureSetObject; + OFCondition outp = structureSetObject.read(*dataset); + + if (!outp.good()) + { + MITK_ERROR << "Error reading the file" << std::endl; + RTStructureSetReader::ContourModelSetNodes x; + return x; + } + + DRTStructureSetROISequence& roiSequence = + structureSetObject.getStructureSetROISequence(); + + if (!roiSequence.gotoFirstItem().good()) + { + MITK_ERROR << "Error reading the structure sequence" << std::endl; + RTStructureSetReader::ContourModelSetNodes x; + return x; + } + do { - DRTContourSequence::Item &contourItem = - contourSeqObject.getCurrentItem(); - if(!contourItem.isValid()) - { - continue; - } - OFString contourNumber; - OFString numberOfPoints; - OFVector contourData_LPS; - mitk::ContourModel::Pointer contourSequence = - mitk::ContourModel::New(); - - contourItem.getContourNumber(contourNumber); - contourItem.getNumberOfContourPoints(numberOfPoints); - contourItem.getContourData(contourData_LPS); - - for(unsigned int i=0; iAddVertex(point); - } - contourSequence->Close(); - contourSet->AddContourModel(contourSequence); + DRTStructureSetROISequence::Item& currentSequence = + 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" << std::endl; + RTStructureSetReader::ContourModelSetNodes x; + return x; } - while(contourSeqObject.gotoNextItem().good()); - } - else - { - MITK_ERROR << "Error reading contourSeqObject" << std::endl; - } - RoiEntry* refROI = this->FindRoiByNumber(refRoiNumber); - if(refROI==NULL) - { - MITK_ERROR << "Can not find references ROI" << std::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])); - } - while(roiContourSeqObject.gotoNextItem().good()); - std::deque nodes; + do + { + mitk::ContourModelSet::Pointer contourSet = mitk::ContourModelSet::New(); + DRTROIContourSequence::Item& currentRoiObject = + roiContourSeqObject.getCurrentItem(); + + if (!currentRoiObject.isValid()) + { + continue; + } - for(unsigned int i=0; iSetData(ROISequenceVector.at(i).ContourModelSet); - node->SetProperty("name", ROISequenceVector.at(i).ContourModelSet->GetProperty("name")); - node->SetProperty("color",ROISequenceVector.at(i).ContourModelSet->GetProperty("contour.color")); - node->SetProperty("contour.color",ROISequenceVector.at(i).ContourModelSet->GetProperty("contour.color")); - node->SetProperty("includeInBoundingBox", mitk::BoolProperty::New(false)); - 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); - } + currentRoiObject.getReferencedROINumber(refRoiNumber); + DRTContourSequence& contourSeqObject = + currentRoiObject.getContourSequence(); + + if (contourSeqObject.gotoFirstItem().good()) + { + do + { + DRTContourSequence::Item& contourItem = + contourSeqObject.getCurrentItem(); + + if (!contourItem.isValid()) + { + continue; + } + + OFString contourNumber; + OFString numberOfPoints; + OFVector contourData_LPS; + mitk::ContourModel::Pointer contourSequence = + mitk::ContourModel::New(); + + contourItem.getContourNumber(contourNumber); + contourItem.getNumberOfContourPoints(numberOfPoints); + contourItem.getContourData(contourData_LPS); - return nodes; - } + for (unsigned int i = 0; i < contourData_LPS.size() / 3; i++) + { + mitk::Point3D point; + point[0] = contourData_LPS.at(3 * i); + point[1] = contourData_LPS.at(3 * i + 1); + point[2] = contourData_LPS.at(3 * i + 2); + contourSequence->AddVertex(point); + } + + contourSequence->Close(); + contourSet->AddContourModel(contourSequence); + } while (contourSeqObject.gotoNextItem().good()); + } + else + { + MITK_ERROR << "Error reading contourSeqObject" << std::endl; + } + + RoiEntry* refROI = this->FindRoiByNumber(refRoiNumber); + + if (refROI == NULL) + { + MITK_ERROR << "Can not find references ROI" << std::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])); + + //add uid and patient uid to property + OFString uid; + structureSetObject.getSeriesInstanceUID(uid); + std::string uidPropertyName = mitk::GeneratPropertyNameForDICOMTag(mitk::DICOMTag(0x0020, 0x000e)); + contourSet->SetProperty(uidPropertyName.c_str(), mitk::StringProperty::New(uid.c_str())); + + OFString patientUid; + structureSetObject.getPatientID(patientUid); + std::string patientUidPropertyName = mitk::GeneratPropertyNameForDICOMTag(mitk::DICOMTag(0x0010, + 0x0020)); + contourSet->SetProperty(patientUidPropertyName.c_str(), + mitk::StringProperty::New(patientUid.c_str())); + + } while (roiContourSeqObject.gotoNextItem().good()); + + std::deque nodes; + + for (unsigned int i = 0; i < ROISequenceVector.size(); i++) + { + mitk::DataNode::Pointer node = mitk::DataNode::New(); + node->SetData(ROISequenceVector.at(i).ContourModelSet); + node->SetProperty("name", ROISequenceVector.at(i).ContourModelSet->GetProperty("name")); + node->SetProperty("color", ROISequenceVector.at(i).ContourModelSet->GetProperty("contour.color")); + node->SetProperty("contour.color", + ROISequenceVector.at(i).ContourModelSet->GetProperty("contour.color")); + node->SetProperty("includeInBoundingBox", mitk::BoolProperty::New(false)); + 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; + } }