diff --git a/Modules/DicomRT/autoload/IO/files.cmake b/Modules/DicomRT/autoload/IO/files.cmake index f3970e6991..e05e20b944 100644 --- a/Modules/DicomRT/autoload/IO/files.cmake +++ b/Modules/DicomRT/autoload/IO/files.cmake @@ -1,7 +1,6 @@ set(CPP_FILES mitkDicomRTIOActivator.cpp - mitkDicomRTIOMimeTypes.cpp mitkRTDoseReaderService.cpp mitkRTPlanReaderService.cpp mitkRTStructureSetReaderService.cpp ) diff --git a/Modules/DicomRT/autoload/IO/mitkDicomRTIOActivator.cpp b/Modules/DicomRT/autoload/IO/mitkDicomRTIOActivator.cpp index 9abbc079d7..7ba37a6b15 100644 --- a/Modules/DicomRT/autoload/IO/mitkDicomRTIOActivator.cpp +++ b/Modules/DicomRT/autoload/IO/mitkDicomRTIOActivator.cpp @@ -1,74 +1,74 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include #include #include #include #include #include #include #include -#include "mitkDicomRTIOMimeTypes.h" +#include namespace mitk { /** \brief Registers services for segmentation module. */ class DicomRTIOActivator : public us::ModuleActivator { public: void Load(us::ModuleContext* context) override { us::ServiceProperties props; props[ us::ServiceConstants::SERVICE_RANKING() ] = 100; - m_MimeTypes = mitk::DicomRTIOMimeTypes::Get(); + m_MimeTypes = mitk::DicomRTMimeTypes::Get(); for (std::vector::const_iterator mimeTypeIter = m_MimeTypes.begin(), iterEnd = m_MimeTypes.end(); mimeTypeIter != iterEnd; ++mimeTypeIter) { context->RegisterService(*mimeTypeIter, props); } m_RTDoseReader = new RTDoseReaderService(); m_RTPlanReader = new RTPlanReaderService(); m_RTStructureSetReader = new RTStructureSetReaderService(); } void Unload(us::ModuleContext*) override { for (auto& aMimeType : m_MimeTypes) { delete aMimeType; } delete m_RTDoseReader; delete m_RTPlanReader; delete m_RTStructureSetReader; } private: RTDoseReaderService * m_RTDoseReader; RTPlanReaderService * m_RTPlanReader; RTStructureSetReaderService * m_RTStructureSetReader; std::vector m_MimeTypes; }; } US_EXPORT_MODULE_ACTIVATOR(mitk::DicomRTIOActivator) diff --git a/Modules/DicomRT/autoload/IO/mitkRTDoseReaderService.cpp b/Modules/DicomRT/autoload/IO/mitkRTDoseReaderService.cpp index 9bd6a9c05b..a1e45309f7 100644 --- a/Modules/DicomRT/autoload/IO/mitkRTDoseReaderService.cpp +++ b/Modules/DicomRT/autoload/IO/mitkRTDoseReaderService.cpp @@ -1,168 +1,168 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ -#include "mitkRTDoseReaderService.h" +#include #include #include #include #include #include #include #include #include -#include "mitkDICOMDCMTKTagScanner.h" -#include "mitkDicomRTIOMimeTypes.h" +#include +#include #include -#include "dcmtk/dcmrt/drtdose.h" +#include #include #include namespace mitk { - RTDoseReaderService::RTDoseReaderService() : AbstractFileReader(CustomMimeType(mitk::DicomRTIOMimeTypes::DICOMRT_DOSE_MIMETYPE_NAME()), mitk::DicomRTIOMimeTypes::DICOMRT_DOSE_MIMETYPE_DESCRIPTION()) { + RTDoseReaderService::RTDoseReaderService() : AbstractFileReader(CustomMimeType(mitk::DicomRTMimeTypes::DICOMRT_DOSE_MIMETYPE_NAME()), mitk::DicomRTMimeTypes::DICOMRT_DOSE_MIMETYPE_DESCRIPTION()) { m_FileReaderServiceReg = RegisterService(); } RTDoseReaderService::RTDoseReaderService(const RTDoseReaderService& other) : mitk::AbstractFileReader(other) { } RTDoseReaderService::~RTDoseReaderService() {} template void RTDoseReaderService::MultiplyGridScaling(itk::Image* image, float gridscale) { typedef itk::Image OutputImageType; typedef itk::Image InputImageType; typedef itk::CastImageFilter CastFilterType; typedef itk::ShiftScaleImageFilter ScaleFilterType; typename CastFilterType::Pointer castFilter = CastFilterType::New(); typename ScaleFilterType::Pointer scaleFilter = ScaleFilterType::New(); castFilter->SetInput(image); scaleFilter->SetInput(castFilter->GetOutput()); scaleFilter->SetScale(gridscale); scaleFilter->Update(); typename OutputImageType::Pointer scaledOutput = scaleFilter->GetOutput(); this->scaledDoseImage = mitk::Image::New(); mitk::CastToMitkImage(scaledOutput, this->scaledDoseImage); } std::vector > RTDoseReaderService::Read() { std::vector > result; mitk::IDICOMTagsOfInterest* toiSrv = GetDicomTagsOfInterestService(); auto tagsOfInterest = toiSrv->GetTagsOfInterest(); DICOMTagPathList tagsOfInterestList; for (const auto& tag : tagsOfInterest) { tagsOfInterestList.push_back(tag.first); } std::string location = GetInputLocation(); mitk::DICOMFileReaderSelector::Pointer selector = mitk::DICOMFileReaderSelector::New(); selector->LoadBuiltIn3DConfigs(); selector->SetInputFiles({ location }); mitk::DICOMFileReader::Pointer reader = selector->GetFirstReaderWithMinimumNumberOfOutputImages(); reader->SetAdditionalTagsOfInterest(toiSrv->GetTagsOfInterest()); reader->SetInputFiles({ location }); reader->AnalyzeInputFiles(); reader->LoadImages(); if (reader->GetNumberOfOutputs() == 0) { MITK_ERROR << "Could not determine a DICOM reader for this file" << std::endl; return result; } mitk::DICOMDCMTKTagScanner::Pointer scanner = mitk::DICOMDCMTKTagScanner::New(); scanner->SetInputFiles({ location }); scanner->AddTagPaths(tagsOfInterestList); scanner->Scan(); mitk::DICOMDatasetAccessingImageFrameList frames = scanner->GetFrameInfoList(); if (frames.empty()) { MITK_ERROR << "Error reading the RTDOSE file" << std::endl; return result; } const mitk::DICOMImageBlockDescriptor& desc = reader->GetOutput(0); mitk::Image::Pointer originalImage = desc.GetMitkImage(); if (originalImage.IsNull()) { MITK_ERROR << "Error reading the RTDOSE file in mitk::DicomFileReader" << std::endl; return result; } DcmFileFormat fileformat; OFCondition outp = fileformat.loadFile(location.c_str(), EXS_Unknown); if (outp.bad()) { MITK_ERROR << "Error reading the RTDOSE file in DCMTK" << std::endl; return result; } DcmDataset *dataset = fileformat.getDataset(); DRTDoseIOD doseObject; OFCondition DCMTKresult = doseObject.read(*dataset); if (DCMTKresult.bad()) { MITK_ERROR << "Error reading the RTDOSE file in DCMTK" << std::endl; return result; } auto findingsGridScaling = frames.front()->GetTagValueAsString(DICOMTagPath(0x3004, 0x000e)); //(0x3004, 0x000e) is grid scaling double gridScaling; if (findingsGridScaling.empty()) { MITK_ERROR << "Could not find DoseGridScaling tag" << std::endl; return result; } else { gridScaling = boost::lexical_cast(findingsGridScaling.front().value); } AccessByItk_1(originalImage, MultiplyGridScaling, gridScaling); auto statistics = this->scaledDoseImage->GetStatistics(); double maxDose = statistics->GetScalarValueMax(); this->scaledDoseImage->SetPropertyList(originalImage->GetPropertyList()); this->scaledDoseImage->SetProperty(mitk::RTConstants::PRESCRIBED_DOSE_PROPERTY_NAME.c_str(), mitk::GenericProperty::New(0.8*maxDose)); auto findings = ExtractPathsOfInterest(tagsOfInterestList, frames); SetProperties(this->scaledDoseImage, findings); result.push_back(this->scaledDoseImage.GetPointer()); return result; } RTDoseReaderService* RTDoseReaderService::Clone() const { return new RTDoseReaderService(*this); } } diff --git a/Modules/DicomRT/autoload/IO/mitkRTPlanReaderService.cpp b/Modules/DicomRT/autoload/IO/mitkRTPlanReaderService.cpp index ddebbbc6b6..d5d2879a6c 100644 --- a/Modules/DicomRT/autoload/IO/mitkRTPlanReaderService.cpp +++ b/Modules/DicomRT/autoload/IO/mitkRTPlanReaderService.cpp @@ -1,82 +1,82 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ -#include "mitkRTPlanReaderService.h" +#include -#include "mitkImage.h" -#include "mitkDICOMDCMTKTagScanner.h" -#include "mitkIOMimeTypes.h" +#include +#include +#include #include -#include "mitkDICOMTagPath.h" -#include "mitkIDICOMTagsOfInterest.h" -#include "mitkDICOMDatasetAccessingImageFrameInfo.h" -#include "mitkDicomRTIOMimeTypes.h" +#include +#include +#include +#include namespace mitk { - RTPlanReaderService::RTPlanReaderService() : AbstractFileReader(CustomMimeType(mitk::DicomRTIOMimeTypes::DICOMRT_PLAN_MIMETYPE_NAME()), mitk::DicomRTIOMimeTypes::DICOMRT_PLAN_MIMETYPE_DESCRIPTION()) { + RTPlanReaderService::RTPlanReaderService() : AbstractFileReader(CustomMimeType(mitk::DicomRTMimeTypes::DICOMRT_PLAN_MIMETYPE_NAME()), mitk::DicomRTMimeTypes::DICOMRT_PLAN_MIMETYPE_DESCRIPTION()) { m_FileReaderServiceReg = RegisterService(); } RTPlanReaderService::RTPlanReaderService(const RTPlanReaderService& other) : mitk::AbstractFileReader(other) { } RTPlanReaderService::~RTPlanReaderService() {} std::vector > RTPlanReaderService::Read() { std::vector > result; auto DICOMTagsOfInterestService = GetDicomTagsOfInterestService(); auto tagsOfInterest = DICOMTagsOfInterestService->GetTagsOfInterest(); DICOMTagPathList tagsOfInterestList; for (const auto& tag : tagsOfInterest) { tagsOfInterestList.push_back(tag.first); } std::string location = GetInputLocation(); mitk::StringList files = { location }; mitk::DICOMDCMTKTagScanner::Pointer scanner = mitk::DICOMDCMTKTagScanner::New(); scanner->SetInputFiles(files); scanner->AddTagPaths(tagsOfInterestList); scanner->Scan(); mitk::DICOMDatasetAccessingImageFrameList frames = scanner->GetFrameInfoList(); if (frames.empty()) { MITK_ERROR << "Error reading the RTPLAN file" << std::endl; return result; } auto findings = ExtractPathsOfInterest(tagsOfInterestList, frames); //just create empty image. No image information available in RTPLAN. But properties will be attached. Image::Pointer dummyImage = Image::New(); mitk::PixelType pt = mitk::MakeScalarPixelType(); unsigned int dim[] = { 1,1}; dummyImage->Initialize(pt, 2, dim); SetProperties(dummyImage, findings); result.push_back(dummyImage.GetPointer()); return result; } RTPlanReaderService* RTPlanReaderService::Clone() const { return new RTPlanReaderService(*this); } } diff --git a/Modules/DicomRT/autoload/IO/mitkRTStructureSetReaderService.cpp b/Modules/DicomRT/autoload/IO/mitkRTStructureSetReaderService.cpp index 5b08e25989..ef2a5132ef 100644 --- a/Modules/DicomRT/autoload/IO/mitkRTStructureSetReaderService.cpp +++ b/Modules/DicomRT/autoload/IO/mitkRTStructureSetReaderService.cpp @@ -1,288 +1,288 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "mitkRTStructureSetReaderService.h" -#include "mitkDicomRTIOMimeTypes.h" +#include #include #include #include #include "dcmtk/dcmrt/drtstrct.h" namespace mitk { - RTStructureSetReaderService::RTStructureSetReaderService() : AbstractFileReader(CustomMimeType(mitk::DicomRTIOMimeTypes::DICOMRT_STRUCT_MIMETYPE_NAME()), mitk::DicomRTIOMimeTypes::DICOMRT_STRUCT_MIMETYPE_DESCRIPTION()) { + RTStructureSetReaderService::RTStructureSetReaderService() : AbstractFileReader(CustomMimeType(mitk::DicomRTMimeTypes::DICOMRT_STRUCT_MIMETYPE_NAME()), mitk::DicomRTMimeTypes::DICOMRT_STRUCT_MIMETYPE_DESCRIPTION()) { m_FileReaderServiceReg = RegisterService(); } RTStructureSetReaderService::RTStructureSetReaderService(const RTStructureSetReaderService& other) : mitk::AbstractFileReader(other) { } RTStructureSetReaderService::~RTStructureSetReaderService() {} RTStructureSetReaderService::RoiEntry::RoiEntry() { Number = 0; DisplayColor[0] = 1.0; DisplayColor[1] = 0.0; DisplayColor[2] = 0.0; ContourModelSet = mitk::ContourModelSet::New(); } RTStructureSetReaderService::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); } RTStructureSetReaderService::RoiEntry::~RoiEntry() {} RTStructureSetReaderService::RoiEntry& RTStructureSetReaderService:: 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 RTStructureSetReaderService::RoiEntry:: SetPolyData(mitk::ContourModelSet::Pointer roiPolyData) { if (roiPolyData == this->ContourModelSet) { return; } this->ContourModelSet = roiPolyData; } size_t RTStructureSetReaderService::GetNumberOfROIs() const { return this->ROISequenceVector.size(); } RTStructureSetReaderService::RoiEntry* RTStructureSetReaderService:: FindRoiByNumber(unsigned int roiNum) { for (unsigned int i = 0; i < this->ROISequenceVector.size(); ++i) { if (this->ROISequenceVector[i].Number == roiNum) { return &this->ROISequenceVector[i]; } } return nullptr; } std::vector > RTStructureSetReaderService::Read() { std::vector > result; std::string location = GetInputLocation(); auto DICOMTagsOfInterestService = GetDicomTagsOfInterestService(); auto tagsOfInterest = DICOMTagsOfInterestService->GetTagsOfInterest(); DICOMTagPathList tagsOfInterestList; for (const auto& tag : tagsOfInterest) { tagsOfInterestList.push_back(tag.first); } mitk::DICOMDCMTKTagScanner::Pointer scanner = mitk::DICOMDCMTKTagScanner::New(); scanner->SetInputFiles({ location }); scanner->AddTagPaths(tagsOfInterestList); scanner->Scan(); mitk::DICOMDatasetAccessingImageFrameList frames = scanner->GetFrameInfoList(); if (frames.empty()) { MITK_ERROR << "Error reading the RTSTRUCT file" << std::endl; return result; } auto findings = ExtractPathsOfInterest(tagsOfInterestList, frames); DcmFileFormat file; OFCondition output = file.loadFile(location.c_str(), EXS_Unknown); if (output.bad()) { MITK_ERROR << "Can't read the file" << std::endl; return result; } DcmDataset* dataset = file.getDataset(); DRTStructureSetIOD structureSetObject; OFCondition outp = structureSetObject.read(*dataset); if (!outp.good()) { MITK_ERROR << "Error reading the file" << std::endl; return result; } DRTStructureSetROISequence& roiSequence = structureSetObject.getStructureSetROISequence(); if (!roiSequence.gotoFirstItem().good()) { MITK_ERROR << "Error reading the structure sequence" << std::endl; return result; } do { 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; return result; } do { mitk::ContourModelSet::Pointer contourSet = mitk::ContourModelSet::New(); DRTROIContourSequence::Item& currentRoiObject = roiContourSeqObject.getCurrentItem(); if (!currentRoiObject.isValid()) { continue; } currentRoiObject.getReferencedROINumber(refRoiNumber); DRTContourSequence& contourSeqObject = currentRoiObject.getContourSequence(); if (contourSeqObject.getNumberOfItems() > 0 && 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); 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_WARN << "contourSeqObject has no items in sequence. Object is neglected and not read. Struct name: " << this->FindRoiByNumber(refRoiNumber)->Name << std::endl; } RoiEntry* refROI = this->FindRoiByNumber(refRoiNumber); if (refROI == nullptr) { MITK_ERROR << "Can not find references ROI" << std::endl; continue; } Sint32 roiColor; for (unsigned 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()); for (auto const& aROI : ROISequenceVector) { result.push_back(aROI.ContourModelSet.GetPointer()); result.at(result.size() - 1)->SetProperty("name", aROI.ContourModelSet->GetProperty("name")); result.at(result.size() - 1)->SetProperty("color", aROI.ContourModelSet->GetProperty("contour.color")); result.at(result.size() - 1)->SetProperty("contour.color", aROI.ContourModelSet->GetProperty("contour.color")); SetProperties(result.at(result.size() - 1).GetPointer(), findings); } return result; } RTStructureSetReaderService* RTStructureSetReaderService::Clone() const { return new RTStructureSetReaderService(*this); } } diff --git a/Modules/DicomRT/files.cmake b/Modules/DicomRT/files.cmake index 64210e3cf4..b7fe17c979 100644 --- a/Modules/DicomRT/files.cmake +++ b/Modules/DicomRT/files.cmake @@ -1,18 +1,19 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") SET(CPP_FILES mitkRTConstants.cpp mitkIsoDoseLevel.cpp mitkIsoDoseLevelCollections.cpp mitkIsoDoseLevelSetProperty.cpp mitkIsoDoseLevelVectorProperty.cpp mitkDoseImageVtkMapper2D.cpp mitkIsoLevelsGenerator.cpp mitkDoseNodeHelper.cpp + mitkDicomRTMimeTypes.cpp ) set(TPP_FILES ) set(MOC_H_FILES ) diff --git a/Modules/DicomRT/autoload/IO/mitkDicomRTIOMimeTypes.h b/Modules/DicomRT/include/mitkDicomRTMimeTypes.h similarity index 77% rename from Modules/DicomRT/autoload/IO/mitkDicomRTIOMimeTypes.h rename to Modules/DicomRT/include/mitkDicomRTMimeTypes.h index b58e11df9e..fe059907ca 100644 --- a/Modules/DicomRT/autoload/IO/mitkDicomRTIOMimeTypes.h +++ b/Modules/DicomRT/include/mitkDicomRTMimeTypes.h @@ -1,76 +1,77 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ -#ifndef MITKDicomRTIOMimeTypes_H -#define MITKDicomRTIOMimeTypes_H +#ifndef MITKDicomRTMimeTypes_H +#define MITKDicomRTMimeTypes_H -#include "mitkCustomMimeType.h" +#include #include +#include #include namespace mitk { -class DicomRTIOMimeTypes +class MITKDICOMRT_EXPORT DicomRTMimeTypes { public: - class RTDoseMimeType : public CustomMimeType + class MITKDICOMRT_EXPORT RTDoseMimeType : public CustomMimeType { public: RTDoseMimeType(); bool AppliesTo(const std::string &path) const override; RTDoseMimeType* Clone() const override; }; - class RTStructMimeType : public CustomMimeType + class MITKDICOMRT_EXPORT RTStructMimeType : public CustomMimeType { public: RTStructMimeType(); bool AppliesTo(const std::string &path) const override; RTStructMimeType* Clone() const override; }; - class RTPlanMimeType : public CustomMimeType + class MITKDICOMRT_EXPORT RTPlanMimeType : public CustomMimeType { public: RTPlanMimeType(); bool AppliesTo(const std::string &path) const override; RTPlanMimeType* Clone() const override; }; // Get all DicomRT Mime Types static std::vector Get(); static RTDoseMimeType DICOMRT_DOSE_MIMETYPE(); static RTStructMimeType DICOMRT_STRUCT_MIMETYPE(); static RTPlanMimeType DICOMRT_PLAN_MIMETYPE(); static std::string DICOMRT_DOSE_MIMETYPE_NAME(); static std::string DICOMRT_STRUCT_MIMETYPE_NAME(); static std::string DICOMRT_PLAN_MIMETYPE_NAME(); static std::string DICOMRT_DOSE_MIMETYPE_DESCRIPTION(); static std::string DICOMRT_STRUCT_MIMETYPE_DESCRIPTION(); static std::string DICOMRT_PLAN_MIMETYPE_DESCRIPTION(); - DicomRTIOMimeTypes() = delete; - DicomRTIOMimeTypes(const DicomRTIOMimeTypes&) = delete; + DicomRTMimeTypes() = delete; + DicomRTMimeTypes(const DicomRTMimeTypes&) = delete; static mitk::IDICOMTagsOfInterest* GetDicomTagsOfInterestService(); static bool canReadByDicomFileReader(const std::string & path); static std::string GetModality(const std::string & path); }; } -#endif // MITKDicomRTIOMimeTypes_H +#endif // MITKDicomRTMimeTypes_H diff --git a/Modules/DicomRT/autoload/IO/mitkDicomRTIOMimeTypes.cpp b/Modules/DicomRT/src/mitkDicomRTMimeTypes.cpp similarity index 73% rename from Modules/DicomRT/autoload/IO/mitkDicomRTIOMimeTypes.cpp rename to Modules/DicomRT/src/mitkDicomRTMimeTypes.cpp index 8fad1d262a..344f31eff5 100644 --- a/Modules/DicomRT/autoload/IO/mitkDicomRTIOMimeTypes.cpp +++ b/Modules/DicomRT/src/mitkDicomRTMimeTypes.cpp @@ -1,261 +1,261 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ -#include "mitkDicomRTIOMimeTypes.h" +#include -#include "mitkIOMimeTypes.h" +#include -#include "mitkDICOMDCMTKTagScanner.h" -#include "mitkDICOMTagPath.h" +#include +#include #include #include #include #include #include #include #include namespace mitk { -std::vector DicomRTIOMimeTypes::Get() +std::vector DicomRTMimeTypes::Get() { std::vector mimeTypes; // order matters here (descending rank for mime types) mimeTypes.push_back(DICOMRT_DOSE_MIMETYPE().Clone()); mimeTypes.push_back(DICOMRT_PLAN_MIMETYPE().Clone()); mimeTypes.push_back(DICOMRT_STRUCT_MIMETYPE().Clone()); return mimeTypes; } // Mime Types -DicomRTIOMimeTypes::RTDoseMimeType::RTDoseMimeType() +DicomRTMimeTypes::RTDoseMimeType::RTDoseMimeType() : CustomMimeType(DICOMRT_DOSE_MIMETYPE_NAME()) { std::string category = "DICOMRT"; this->SetCategory(category); this->SetComment("RTDose"); this->AddExtension("dcm"); } -bool DicomRTIOMimeTypes::RTDoseMimeType::AppliesTo(const std::string &path) const +bool DicomRTMimeTypes::RTDoseMimeType::AppliesTo(const std::string &path) const { bool canRead( CustomMimeType::AppliesTo(path) ); if (!canRead) { return false; } if (!canReadByDicomFileReader(path)) { return false; } auto modality = GetModality(path); if (modality == "RTDOSE") { return true; } else { return false; } } -std::string DicomRTIOMimeTypes::GetModality(const std::string & path) +std::string DicomRTMimeTypes::GetModality(const std::string & path) { mitk::IDICOMTagsOfInterest* toiSrv = GetDicomTagsOfInterestService(); auto tagsOfInterest = toiSrv->GetTagsOfInterest(); DICOMTagPathList tagsOfInterestList; for (const auto& tag : tagsOfInterest) { tagsOfInterestList.push_back(tag.first); } mitk::DICOMDCMTKTagScanner::Pointer scanner = mitk::DICOMDCMTKTagScanner::New(); scanner->SetInputFiles({ path }); scanner->AddTagPaths(tagsOfInterestList); scanner->Scan(); mitk::DICOMDatasetAccessingImageFrameList frames = scanner->GetFrameInfoList(); std::string modality = ""; if (frames.empty()) return modality; auto findings = frames.front()->GetTagValueAsString(DICOMTagPath(0x0008, 0x0060)); modality = findings.front().value; return modality; } -bool DicomRTIOMimeTypes::canReadByDicomFileReader(const std::string & filename) +bool DicomRTMimeTypes::canReadByDicomFileReader(const std::string & filename) { mitk::DICOMFileReaderSelector::Pointer selector = mitk::DICOMFileReaderSelector::New(); selector->LoadBuiltIn3DConfigs(); selector->SetInputFiles({ filename }); mitk::DICOMFileReader::Pointer reader = selector->GetFirstReaderWithMinimumNumberOfOutputImages(); if (reader.IsNull()) { return false; } else { return true; } } -DicomRTIOMimeTypes::RTDoseMimeType* DicomRTIOMimeTypes::RTDoseMimeType::Clone() const +DicomRTMimeTypes::RTDoseMimeType* DicomRTMimeTypes::RTDoseMimeType::Clone() const { return new RTDoseMimeType(*this); } -DicomRTIOMimeTypes::RTStructMimeType::RTStructMimeType() +DicomRTMimeTypes::RTStructMimeType::RTStructMimeType() : CustomMimeType(DICOMRT_STRUCT_MIMETYPE_NAME()) { std::string category = "DICOMRT"; this->SetCategory(category); this->SetComment("RTStruct"); this->AddExtension("dcm"); } -bool DicomRTIOMimeTypes::RTStructMimeType::AppliesTo(const std::string &path) const +bool DicomRTMimeTypes::RTStructMimeType::AppliesTo(const std::string &path) const { bool canRead(CustomMimeType::AppliesTo(path)); if (!canRead) { return false; } auto modality = GetModality(path); if (modality == "RTSTRUCT") { return true; } else { return false; } } -DicomRTIOMimeTypes::RTStructMimeType* DicomRTIOMimeTypes::RTStructMimeType::Clone() const +DicomRTMimeTypes::RTStructMimeType* DicomRTMimeTypes::RTStructMimeType::Clone() const { return new RTStructMimeType(*this); } -DicomRTIOMimeTypes::RTPlanMimeType::RTPlanMimeType() +DicomRTMimeTypes::RTPlanMimeType::RTPlanMimeType() : CustomMimeType(DICOMRT_PLAN_MIMETYPE_NAME()) { std::string category = "DICOMRT"; this->SetCategory(category); this->SetComment("RTPLAN"); this->AddExtension("dcm"); } -bool DicomRTIOMimeTypes::RTPlanMimeType::AppliesTo(const std::string &path) const +bool DicomRTMimeTypes::RTPlanMimeType::AppliesTo(const std::string &path) const { bool canRead(CustomMimeType::AppliesTo(path)); if (!canRead) { return false; } auto modality = GetModality(path); if (modality == "RTPLAN") { return true; } else { return false; } } -DicomRTIOMimeTypes::RTPlanMimeType* DicomRTIOMimeTypes::RTPlanMimeType::Clone() const +DicomRTMimeTypes::RTPlanMimeType* DicomRTMimeTypes::RTPlanMimeType::Clone() const { return new RTPlanMimeType(*this); } -DicomRTIOMimeTypes::RTDoseMimeType DicomRTIOMimeTypes::DICOMRT_DOSE_MIMETYPE() +DicomRTMimeTypes::RTDoseMimeType DicomRTMimeTypes::DICOMRT_DOSE_MIMETYPE() { return RTDoseMimeType(); } -DicomRTIOMimeTypes::RTStructMimeType DicomRTIOMimeTypes::DICOMRT_STRUCT_MIMETYPE() +DicomRTMimeTypes::RTStructMimeType DicomRTMimeTypes::DICOMRT_STRUCT_MIMETYPE() { return RTStructMimeType(); } -DicomRTIOMimeTypes::RTPlanMimeType DicomRTIOMimeTypes::DICOMRT_PLAN_MIMETYPE() +DicomRTMimeTypes::RTPlanMimeType DicomRTMimeTypes::DICOMRT_PLAN_MIMETYPE() { return RTPlanMimeType(); } // Names -std::string DicomRTIOMimeTypes::DICOMRT_DOSE_MIMETYPE_NAME() +std::string DicomRTMimeTypes::DICOMRT_DOSE_MIMETYPE_NAME() { static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.dose"; return name; } -std::string DicomRTIOMimeTypes::DICOMRT_STRUCT_MIMETYPE_NAME() +std::string DicomRTMimeTypes::DICOMRT_STRUCT_MIMETYPE_NAME() { static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.struct"; return name; } -std::string DicomRTIOMimeTypes::DICOMRT_PLAN_MIMETYPE_NAME() +std::string DicomRTMimeTypes::DICOMRT_PLAN_MIMETYPE_NAME() { static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.plan"; return name; } // Descriptions -std::string DicomRTIOMimeTypes::DICOMRT_DOSE_MIMETYPE_DESCRIPTION() +std::string DicomRTMimeTypes::DICOMRT_DOSE_MIMETYPE_DESCRIPTION() { static std::string description = "RTDOSE reader"; return description; } -std::string DicomRTIOMimeTypes::DICOMRT_STRUCT_MIMETYPE_DESCRIPTION() +std::string DicomRTMimeTypes::DICOMRT_STRUCT_MIMETYPE_DESCRIPTION() { static std::string description = "RTSTRUCT reader"; return description; } -std::string DicomRTIOMimeTypes::DICOMRT_PLAN_MIMETYPE_DESCRIPTION() +std::string DicomRTMimeTypes::DICOMRT_PLAN_MIMETYPE_DESCRIPTION() { static std::string description = "RTPLAN reader"; return description; } -mitk::IDICOMTagsOfInterest* DicomRTIOMimeTypes::GetDicomTagsOfInterestService() +mitk::IDICOMTagsOfInterest* DicomRTMimeTypes::GetDicomTagsOfInterestService() { mitk::IDICOMTagsOfInterest* result = nullptr; std::vector > toiRegisters = us::GetModuleContext()->GetServiceReferences(); if (!toiRegisters.empty()) { if (toiRegisters.size() > 1) { MITK_WARN << "Multiple DICOM tags of interest services found. Using just one."; } result = us::GetModuleContext()->GetService(toiRegisters.front()); } return result; } }