diff --git a/Modules/RT/include/mitkDICOMRTMimeTypes.h b/Modules/RT/include/mitkDICOMRTMimeTypes.h index 37522ba7bf..08ec13a39a 100644 --- a/Modules/RT/include/mitkDICOMRTMimeTypes.h +++ b/Modules/RT/include/mitkDICOMRTMimeTypes.h @@ -1,79 +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 MITKDICOMRTMimeTypes_H #define MITKDICOMRTMimeTypes_H #include -#include #include #include #include #include namespace mitk { class MITKRT_EXPORT DICOMRTMimeTypes { public: class MITKRT_EXPORT RTDoseMimeType : public CustomMimeType { public: RTDoseMimeType(); bool AppliesTo(const std::string &path) const override; RTDoseMimeType* Clone() const override; }; class MITKRT_EXPORT RTStructMimeType : public CustomMimeType { public: RTStructMimeType(); bool AppliesTo(const std::string &path) const override; RTStructMimeType* Clone() const override; }; class MITKRT_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::array, 3> 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(); 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 // MITKDICOMRTMimeTypes_H diff --git a/Modules/RT/src/mitkDICOMRTMimeTypes.cpp b/Modules/RT/src/mitkDICOMRTMimeTypes.cpp index bbb3cc0260..0f93ded382 100644 --- a/Modules/RT/src/mitkDICOMRTMimeTypes.cpp +++ b/Modules/RT/src/mitkDICOMRTMimeTypes.cpp @@ -1,252 +1,214 @@ /*============================================================================ 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 -#include -#include + namespace mitk { std::array, 3> DICOMRTMimeTypes::Get() { return { std::make_unique(), std::make_unique(), std::make_unique() }; } // Mime Types DICOMRTMimeTypes::RTDoseMimeType::RTDoseMimeType() : CustomMimeType(DICOMRT_DOSE_MIMETYPE_NAME()) { std::string category = "DICOMRT"; this->SetCategory(category); this->SetComment("RTDose"); this->AddExtension("dcm"); } bool DICOMRTMimeTypes::RTDoseMimeType::AppliesTo(const std::string &path) const { bool canRead( CustomMimeType::AppliesTo(path) ); - if (!canRead) { - return false; - } - - if (!canReadByDicomFileReader(path)) { + if (!canRead) + { return false; } auto modality = GetModality(path); - - if (modality == "RTDOSE") { - return true; + if (modality == "RTDOSE") + { + return canReadByDicomFileReader(path); } - else { - return false; - } + + return false; } 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); - } + const auto modalityTagPath = DICOMTagPath(0x0008, 0x0060); mitk::DICOMDCMTKTagScanner::Pointer scanner = mitk::DICOMDCMTKTagScanner::New(); scanner->SetInputFiles({ path }); - scanner->AddTagPaths(tagsOfInterestList); + scanner->AddTagPaths({ modalityTagPath }); scanner->Scan(); mitk::DICOMDatasetAccessingImageFrameList frames = scanner->GetFrameInfoList(); std::string modality = ""; if (frames.empty()) return modality; - auto findings = frames.front()->GetTagValueAsString(DICOMTagPath(0x0008, 0x0060)); + auto findings = frames.front()->GetTagValueAsString(modalityTagPath); modality = findings.front().value; return modality; } 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; - } + return reader.IsNotNull(); } DICOMRTMimeTypes::RTDoseMimeType* DICOMRTMimeTypes::RTDoseMimeType::Clone() const { return new RTDoseMimeType(*this); } DICOMRTMimeTypes::RTStructMimeType::RTStructMimeType() : CustomMimeType(DICOMRT_STRUCT_MIMETYPE_NAME()) { std::string category = "DICOMRT"; this->SetCategory(category); this->SetComment("RTStruct"); this->AddExtension("dcm"); } 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; - } + + return false; } DICOMRTMimeTypes::RTStructMimeType* DICOMRTMimeTypes::RTStructMimeType::Clone() const { return new RTStructMimeType(*this); } DICOMRTMimeTypes::RTPlanMimeType::RTPlanMimeType() : CustomMimeType(DICOMRT_PLAN_MIMETYPE_NAME()) { std::string category = "DICOMRT"; this->SetCategory(category); this->SetComment("RTPLAN"); this->AddExtension("dcm"); } 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; - } + if (modality == "RTPLAN") { + return true; + } + + return false; } DICOMRTMimeTypes::RTPlanMimeType* DICOMRTMimeTypes::RTPlanMimeType::Clone() const { return new RTPlanMimeType(*this); } DICOMRTMimeTypes::RTDoseMimeType DICOMRTMimeTypes::DICOMRT_DOSE_MIMETYPE() { return RTDoseMimeType(); } DICOMRTMimeTypes::RTStructMimeType DICOMRTMimeTypes::DICOMRT_STRUCT_MIMETYPE() { return RTStructMimeType(); } DICOMRTMimeTypes::RTPlanMimeType DICOMRTMimeTypes::DICOMRT_PLAN_MIMETYPE() { return RTPlanMimeType(); } // Names std::string DICOMRTMimeTypes::DICOMRT_DOSE_MIMETYPE_NAME() { return IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.dose"; } std::string DICOMRTMimeTypes::DICOMRT_STRUCT_MIMETYPE_NAME() { return IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.struct"; } std::string DICOMRTMimeTypes::DICOMRT_PLAN_MIMETYPE_NAME() { return IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.plan"; } // Descriptions std::string DICOMRTMimeTypes::DICOMRT_DOSE_MIMETYPE_DESCRIPTION() { return "RTDOSE reader"; } std::string DICOMRTMimeTypes::DICOMRT_STRUCT_MIMETYPE_DESCRIPTION() { return "RTSTRUCT reader"; } std::string DICOMRTMimeTypes::DICOMRT_PLAN_MIMETYPE_DESCRIPTION() { return "RTPLAN reader"; } -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; -} - }