diff --git a/Modules/DicomRT/mitkRTStructureSetReader.cpp b/Modules/DicomRT/mitkRTStructureSetReader.cpp index 5f7f82a519..923609a878 100644 --- a/Modules/DicomRT/mitkRTStructureSetReader.cpp +++ b/Modules/DicomRT/mitkRTStructureSetReader.cpp @@ -1,247 +1,248 @@ /*=================================================================== 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; } - RTStructureSetReader::ContourModelSetNodes 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; RTStructureSetReader::ContourModelSetNodes x; return x; } DRTStructureSetROISequence &roiSequence = structureSetObject.getStructureSetROISequence(); if(!roiSequence.gotoFirstItem().good()) { MITK_ERROR << "Error reading the structure sequence" << endl; 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; 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()); 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"))); + 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")); + + /*The StructureSets should only be visible in the axial-view and the + 3D-view because in the other views they are just points and lines*/ + 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 f1d7833f44..9741553474 100644 --- a/Modules/DicomRT/mitkRTStructureSetReader.h +++ b/Modules/DicomRT/mitkRTStructureSetReader.h @@ -1,72 +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 ContourModelSetVector; 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: - mitkClassMacro( RTStructureSetReader, itk::Object ); - itkNewMacro( Self ); - + mitkClassMacro( 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