diff --git a/Modules/DicomRT/autoload/IO/mitkDicomRTIOActivator.cpp b/Modules/DicomRT/autoload/IO/mitkDicomRTIOActivator.cpp index 7ba37a6b15..24cf226694 100644 --- a/Modules/DicomRT/autoload/IO/mitkDicomRTIOActivator.cpp +++ b/Modules/DicomRT/autoload/IO/mitkDicomRTIOActivator.cpp @@ -1,74 +1,56 @@ /*============================================================================ 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 - namespace mitk { - /** - \brief Registers services for segmentation module. - */ class DicomRTIOActivator : public us::ModuleActivator { public: + DicomRTIOActivator() + { + } + + ~DicomRTIOActivator() = default; void Load(us::ModuleContext* context) override { us::ServiceProperties props; - props[ us::ServiceConstants::SERVICE_RANKING() ] = 100; + props[us::ServiceConstants::SERVICE_RANKING()] = 100; - 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); - } + for (const auto& mimeType : DicomRTMimeTypes::Get()) + context->RegisterService(mimeType.get(), props); - m_RTDoseReader = new RTDoseReaderService(); - m_RTPlanReader = new RTPlanReaderService(); - m_RTStructureSetReader = new RTStructureSetReaderService(); + m_RTDoseReader.reset(new RTDoseReaderService); + m_RTPlanReader.reset(new RTPlanReaderService); + m_RTStructureSetReader.reset(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; - + std::unique_ptr m_RTDoseReader; + std::unique_ptr m_RTPlanReader; + std::unique_ptr m_RTStructureSetReader; }; } US_EXPORT_MODULE_ACTIVATOR(mitk::DicomRTIOActivator) diff --git a/Modules/DicomRT/include/mitkDicomRTMimeTypes.h b/Modules/DicomRT/include/mitkDicomRTMimeTypes.h index fe059907ca..d57d821f0d 100644 --- a/Modules/DicomRT/include/mitkDicomRTMimeTypes.h +++ b/Modules/DicomRT/include/mitkDicomRTMimeTypes.h @@ -1,77 +1,79 @@ /*============================================================================ 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 MITKDICOMRT_EXPORT DicomRTMimeTypes { public: class MITKDICOMRT_EXPORT RTDoseMimeType : public CustomMimeType { public: RTDoseMimeType(); bool AppliesTo(const std::string &path) const override; RTDoseMimeType* Clone() const override; }; class MITKDICOMRT_EXPORT RTStructMimeType : public CustomMimeType { public: RTStructMimeType(); bool AppliesTo(const std::string &path) const override; RTStructMimeType* Clone() const override; }; 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 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/DicomRT/src/mitkDicomRTMimeTypes.cpp b/Modules/DicomRT/src/mitkDicomRTMimeTypes.cpp index 344f31eff5..b8a26714b8 100644 --- a/Modules/DicomRT/src/mitkDicomRTMimeTypes.cpp +++ b/Modules/DicomRT/src/mitkDicomRTMimeTypes.cpp @@ -1,261 +1,252 @@ /*============================================================================ 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::vector DicomRTMimeTypes::Get() +std::array, 3> 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; + 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)) { return false; } auto modality = GetModality(path); if (modality == "RTDOSE") { return true; } else { 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); } 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 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; } } 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; } } 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; } } 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() { - static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.dose"; - return name; + return IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.dose"; } std::string DicomRTMimeTypes::DICOMRT_STRUCT_MIMETYPE_NAME() { - static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.struct"; - return name; + return IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.struct"; } std::string DicomRTMimeTypes::DICOMRT_PLAN_MIMETYPE_NAME() { - static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.plan"; - return name; + return IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.plan"; } // Descriptions std::string DicomRTMimeTypes::DICOMRT_DOSE_MIMETYPE_DESCRIPTION() { - static std::string description = "RTDOSE reader"; - return description; + return "RTDOSE reader"; } std::string DicomRTMimeTypes::DICOMRT_STRUCT_MIMETYPE_DESCRIPTION() { - static std::string description = "RTSTRUCT reader"; - return description; + return "RTSTRUCT reader"; } std::string DicomRTMimeTypes::DICOMRT_PLAN_MIMETYPE_DESCRIPTION() { - static std::string description = "RTPLAN reader"; - return 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; } }