diff --git a/Modules/DICOMReaderServices/files.cmake b/Modules/DICOMReaderServices/files.cmake index b0f9199daa..1a80da327e 100644 --- a/Modules/DICOMReaderServices/files.cmake +++ b/Modules/DICOMReaderServices/files.cmake @@ -1,9 +1,10 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") set(CPP_FILES mitkAutoSelectingDICOMReaderService.cpp mitkClassicDICOMSeriesReaderService.cpp mitkDICOMReaderServicesActivator.cpp mitkDICOMTagsOfInterestService.cpp mitkSimpleVolumeDICOMSeriesReaderService.cpp + mitkManualSelectingDICOMReaderService.cpp ) diff --git a/Modules/DICOMReaderServices/include/mitkManualSelectingDICOMReaderService.h b/Modules/DICOMReaderServices/include/mitkManualSelectingDICOMReaderService.h new file mode 100644 index 0000000000..18468d373b --- /dev/null +++ b/Modules/DICOMReaderServices/include/mitkManualSelectingDICOMReaderService.h @@ -0,0 +1,43 @@ +/*============================================================================ + +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 MITKMANUALSELECTINGDICOMREADERSERVICE_H +#define MITKMANUALSELECTINGDICOMREADERSERVICE_H + +#include +#include + +namespace mitk { + + /** + Service wrapper that offers a manual selection of the DICOMFileReader configuration that should be used. + */ +class ManualSelectingDICOMReaderService : public BaseDICOMReaderService +{ +public: + ManualSelectingDICOMReaderService(); + +protected: + /** Returns the reader instance that should be used. The descission may be based + * one the passed relevant file list.*/ + mitk::DICOMFileReader::Pointer GetReader(const mitk::StringList& relevantFiles) const override; + +private: + + ManualSelectingDICOMReaderService* Clone() const override; + + DICOMFileReaderSelector::Pointer m_Selector; +}; + +} + +#endif // MITKMANUALSELECTINGDICOMREADERSERVICE_H diff --git a/Modules/DICOMReaderServices/src/mitkDICOMReaderServicesActivator.cpp b/Modules/DICOMReaderServices/src/mitkDICOMReaderServicesActivator.cpp index 8896d2b9a9..e6a54654e9 100644 --- a/Modules/DICOMReaderServices/src/mitkDICOMReaderServicesActivator.cpp +++ b/Modules/DICOMReaderServices/src/mitkDICOMReaderServicesActivator.cpp @@ -1,93 +1,94 @@ /*============================================================================ 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 "mitkDICOMReaderServicesActivator.h" #include "mitkAutoSelectingDICOMReaderService.h" -#include "mitkClassicDICOMSeriesReaderService.h" +#include "mitkManualSelectingDICOMReaderService.h" #include "mitkDICOMTagsOfInterestService.h" #include "mitkSimpleVolumeDICOMSeriesReaderService.h" #include "mitkCoreServices.h" #include "mitkPropertyPersistenceInfo.h" #include "mitkDICOMIOMetaInformationPropertyConstants.h" #include "mitkIPropertyPersistence.h" #include "mitkTemporoSpatialStringProperty.h" #include void AddPropertyPersistence(const mitk::PropertyKeyPath& propPath, bool temporoSpatial = false) { mitk::CoreServicePointer persistenceService(mitk::CoreServices::GetPropertyPersistence()); mitk::PropertyPersistenceInfo::Pointer info = mitk::PropertyPersistenceInfo::New(); if (propPath.IsExplicit()) { std::string name = mitk::PropertyKeyPathToPropertyName(propPath); std::string key = name; std::replace(key.begin(), key.end(), '.', '_'); info->SetNameAndKey(name, key); } else { std::string key = mitk::PropertyKeyPathToPersistenceKeyRegEx(propPath); std::string keyTemplate = mitk::PropertyKeyPathToPersistenceKeyTemplate(propPath); std::string propRegEx = mitk::PropertyKeyPathToPropertyRegEx(propPath); std::string propTemplate = mitk::PropertyKeyPathToPersistenceNameTemplate(propPath); info->UseRegEx(propRegEx, propTemplate, key, keyTemplate); } if (temporoSpatial) { info->SetDeserializationFunction(mitk::PropertyPersistenceDeserialization::deserializeJSONToTemporoSpatialStringProperty); info->SetSerializationFunction(mitk::PropertyPersistenceSerialization::serializeTemporoSpatialStringPropertyToJSON); } persistenceService->AddInfo(info); } namespace mitk { void DICOMReaderServicesActivator::Load(us::ModuleContext* context) { m_AutoSelectingDICOMReader.reset(new AutoSelectingDICOMReaderService()); m_SimpleVolumeDICOMSeriesReader.reset(new SimpleVolumeDICOMSeriesReaderService()); + m_ManualSelectingDICOMSeriesReader.reset(new ManualSelectingDICOMReaderService()); m_DICOMTagsOfInterestService.reset(new DICOMTagsOfInterestService()); context->RegisterService(m_DICOMTagsOfInterestService.get()); DICOMTagPathMapType tagmap = GetDefaultDICOMTagsOfInterest(); for (auto tag : tagmap) { m_DICOMTagsOfInterestService->AddTagOfInterest(tag.first); } //add properties that should be persistent (if possible/supported by the writer) AddPropertyPersistence(mitk::DICOMIOMetaInformationPropertyConstants::READER_3D_plus_t()); AddPropertyPersistence(mitk::DICOMIOMetaInformationPropertyConstants::READER_CONFIGURATION()); AddPropertyPersistence(mitk::DICOMIOMetaInformationPropertyConstants::READER_DCMTK()); AddPropertyPersistence(mitk::DICOMIOMetaInformationPropertyConstants::READER_FILES(), true); AddPropertyPersistence(mitk::DICOMIOMetaInformationPropertyConstants::READER_GANTRY_TILT_CORRECTED()); AddPropertyPersistence(mitk::DICOMIOMetaInformationPropertyConstants::READER_GDCM()); AddPropertyPersistence(mitk::DICOMIOMetaInformationPropertyConstants::READER_IMPLEMENTATION_LEVEL()); AddPropertyPersistence(mitk::DICOMIOMetaInformationPropertyConstants::READER_IMPLEMENTATION_LEVEL_STRING()); AddPropertyPersistence(mitk::DICOMIOMetaInformationPropertyConstants::READER_PIXEL_SPACING_INTERPRETATION()); AddPropertyPersistence(mitk::DICOMIOMetaInformationPropertyConstants::READER_PIXEL_SPACING_INTERPRETATION_STRING()); } void DICOMReaderServicesActivator::Unload(us::ModuleContext*) { } } US_EXPORT_MODULE_ACTIVATOR(mitk::DICOMReaderServicesActivator) diff --git a/Modules/DICOMReaderServices/src/mitkDICOMReaderServicesActivator.h b/Modules/DICOMReaderServices/src/mitkDICOMReaderServicesActivator.h index bc6b72ec16..4793cd2145 100644 --- a/Modules/DICOMReaderServices/src/mitkDICOMReaderServicesActivator.h +++ b/Modules/DICOMReaderServices/src/mitkDICOMReaderServicesActivator.h @@ -1,48 +1,48 @@ /*============================================================================ 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 MITKDICOMREADERSERVICESACTIVATOR_H #define MITKDICOMREADERSERVICESACTIVATOR_H #include #include #include namespace mitk { struct IFileReader; class IDICOMTagsOfInterest; class DICOMReaderServicesActivator : public us::ModuleActivator { public: void Load(us::ModuleContext* context) override; void Unload(us::ModuleContext* context) override; void AliasServiceChanged(const us::ServiceEvent event); private: std::unique_ptr m_AutoSelectingDICOMReader; - std::unique_ptr m_ClassicDICOMSeriesReader; + std::unique_ptr m_ManualSelectingDICOMSeriesReader; std::unique_ptr m_SimpleVolumeDICOMSeriesReader; std::unique_ptr m_DICOMTagsOfInterestService; us::ModuleContext* mitkContext; }; } #endif // MITKDICOMREADERSERVICESACTIVATOR_H diff --git a/Modules/DICOMReaderServices/src/mitkManualSelectingDICOMReaderService.cpp b/Modules/DICOMReaderServices/src/mitkManualSelectingDICOMReaderService.cpp new file mode 100644 index 0000000000..479da04892 --- /dev/null +++ b/Modules/DICOMReaderServices/src/mitkManualSelectingDICOMReaderService.cpp @@ -0,0 +1,64 @@ +/*============================================================================ + +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 "mitkManualSelectingDICOMReaderService.h" + +namespace mitk { + +ManualSelectingDICOMReaderService::ManualSelectingDICOMReaderService() + : BaseDICOMReaderService("MITK DICOM Reader v2 (manual)") +{ + Options defaultOptions; + + m_Selector = mitk::DICOMFileReaderSelector::New(); + + m_Selector->LoadBuiltIn3DConfigs(); + m_Selector->LoadBuiltIn3DnTConfigs(); + + auto readers = m_Selector->GetAllConfiguredReaders(); + + std::vector configs; + for (const auto& reader : readers) + { + configs.push_back(reader->GetConfigurationLabel()); + } + defaultOptions["Configuration"] = configs; + + this->SetDefaultOptions(defaultOptions); + + this->RegisterService(); +} + +DICOMFileReader::Pointer ManualSelectingDICOMReaderService::GetReader(const mitk::StringList& relevantFiles) const +{ + const auto label = this->GetOption("Configuration").ToString(); + + mitk::DICOMFileReader::Pointer selectedReader = nullptr; + + auto readers = m_Selector->GetAllConfiguredReaders(); + for (const auto& reader : readers) + { + if (label == reader->GetConfigurationLabel()) + { + selectedReader = reader; + } + } + + return selectedReader; +}; + +ManualSelectingDICOMReaderService* ManualSelectingDICOMReaderService::Clone() const +{ + return new ManualSelectingDICOMReaderService(*this); +} + +}