diff --git a/Modules/CEST/autoload/IO/mitkCESTDICOMReaderService.h b/Modules/CEST/autoload/IO/mitkCESTDICOMReaderService.h index cdd4022a92..8131a8fad1 100644 --- a/Modules/CEST/autoload/IO/mitkCESTDICOMReaderService.h +++ b/Modules/CEST/autoload/IO/mitkCESTDICOMReaderService.h @@ -1,46 +1,46 @@ /*============================================================================ 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 MITKCESTDICOMReaderService_H #define MITKCESTDICOMReaderService_H #include namespace mitk { /** Service wrapper that auto selects (using the mitk::DICOMFileReaderSelector) the best DICOMFileReader from the DICOMReader module and loads additional meta data for CEST data. */ class CESTDICOMReaderService : public BaseDICOMReaderService { public: CESTDICOMReaderService(); CESTDICOMReaderService(const std::string& description); /** Uses the BaseDICOMReaderService Read function and add extra steps for CEST meta data */ using AbstractFileReader::Read; std::vector > Read() override; protected: /** Returns the reader instance that should be used. The decision may be based - * one the passed relevant file list.*/ + * one the passed list of relevant files.*/ mitk::DICOMFileReader::Pointer GetReader(const mitk::StringList& relevantFiles) const override; private: CESTDICOMReaderService* Clone() const override; }; } #endif // MITKCESTDICOMREADERSERVICE_H diff --git a/Modules/Core/include/mitkPreferenceListReaderOptionsFunctor.h b/Modules/Core/include/mitkPreferenceListReaderOptionsFunctor.h index 592414d59a..8002dc3122 100644 --- a/Modules/Core/include/mitkPreferenceListReaderOptionsFunctor.h +++ b/Modules/Core/include/mitkPreferenceListReaderOptionsFunctor.h @@ -1,57 +1,62 @@ /*============================================================================ 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 MITKPREFERENCELISTREADEROPTIONSFUNCTOR_H #define MITKPREFERENCELISTREADEROPTIONSFUNCTOR_H #include #include #include #include namespace mitk { /** * \ingroup IO * * \brief Option callback functor with a preference list/ black list option selection strategy. * * This functor can be used if a option selection should be done without user interaction. * Setting up the functor one can specify a preference and black lists of controller descriptions. * Any controller description on the black list will be ignored and never selected. * The first controller description found on the preference list will be selected. * Any controller listed on the black list is always ignored. Even if it is also * listed on the preference list. * If no preference listed controller is available, the functor will use the pre selected reader. * If no pre selected controller is available, the functor will use the first not black * listed reader. + * If user options (non empty) are specified for the functor, the selected reader will be set + * with these user options. * * \see IOUtil */ struct MITKCORE_EXPORT PreferenceListReaderOptionsFunctor : public IOUtil::ReaderOptionsFunctorBase { using ListType = std::vector; bool operator()(IOUtil::LoadInfo &loadInfo) const override; PreferenceListReaderOptionsFunctor(); PreferenceListReaderOptionsFunctor(const ListType& preference, const ListType& black); + PreferenceListReaderOptionsFunctor(const ListType& preference, const IFileReader::Options& options); + PreferenceListReaderOptionsFunctor(const ListType& preference, const ListType& black, const IFileReader::Options& options); protected: - ListType m_PreferenceList; - ListType m_BlackList; + const ListType m_PreferenceList; + const ListType m_BlackList; + const IFileReader::Options m_Options; }; } #endif // MITKWHITELISTREADEROPTIONSFUNCTOR_H diff --git a/Modules/Core/src/IO/mitkPreferenceListReaderOptionsFunctor.cpp b/Modules/Core/src/IO/mitkPreferenceListReaderOptionsFunctor.cpp index dc7f493c68..632bf1a0a6 100644 --- a/Modules/Core/src/IO/mitkPreferenceListReaderOptionsFunctor.cpp +++ b/Modules/Core/src/IO/mitkPreferenceListReaderOptionsFunctor.cpp @@ -1,72 +1,88 @@ /*============================================================================ 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 "mitkPreferenceListReaderOptionsFunctor.h" mitk::PreferenceListReaderOptionsFunctor::PreferenceListReaderOptionsFunctor() { } +mitk::PreferenceListReaderOptionsFunctor::PreferenceListReaderOptionsFunctor(const ListType& preference, const IFileReader::Options& options) : m_PreferenceList(preference), m_Options(options) +{ + +} + mitk::PreferenceListReaderOptionsFunctor::PreferenceListReaderOptionsFunctor(const ListType& preference, const ListType& black) : m_PreferenceList(preference), m_BlackList(black) { } +mitk::PreferenceListReaderOptionsFunctor::PreferenceListReaderOptionsFunctor(const ListType& preference, const ListType& black, const IFileReader::Options& options) : m_PreferenceList(preference), m_BlackList(black), m_Options(options) +{ + +} + bool mitk::PreferenceListReaderOptionsFunctor::operator()(IOUtil::LoadInfo &loadInfo) const { auto readerItems = loadInfo.m_ReaderSelector.Get(); auto selectedID = loadInfo.m_ReaderSelector.GetSelectedId(); //check if the pre selected ID is on the blacklist. If true, "un"select. auto finding = std::find(m_BlackList.begin(), m_BlackList.end(), loadInfo.m_ReaderSelector.GetSelected().GetDescription()); if (finding != m_BlackList.end()) { selectedID = -1; } for (auto reader : readerItems) { finding = std::find(m_BlackList.begin(), m_BlackList.end(), reader.GetDescription()); if (finding != m_BlackList.end()) { continue; } finding = std::find(m_PreferenceList.begin(), m_PreferenceList.end(), reader.GetDescription()); if (finding != m_PreferenceList.end()) { selectedID = reader.GetServiceId(); break; } if (selectedID==-1) { selectedID = reader.GetServiceId(); } } if (selectedID == -1) { mitkThrow() << "No valid reader found. All available readers are black listed."; } if (!loadInfo.m_ReaderSelector.Select(selectedID)) { MITK_DEBUG << "Was not able to select reader found by the PreferenceListReaderOptionsFunctor"; } + auto reader = loadInfo.m_ReaderSelector.GetSelected().GetReader(); + if (!m_Options.empty() && nullptr != reader) + { + reader->SetOptions(m_Options); + } + return true; } diff --git a/Modules/Core/test/mitkPreferenceListReaderOptionsFunctorTest.cpp b/Modules/Core/test/mitkPreferenceListReaderOptionsFunctorTest.cpp index c4af10cd1c..f81ee9152c 100644 --- a/Modules/Core/test/mitkPreferenceListReaderOptionsFunctorTest.cpp +++ b/Modules/Core/test/mitkPreferenceListReaderOptionsFunctorTest.cpp @@ -1,199 +1,219 @@ /*============================================================================ 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 "mitkPreferenceListReaderOptionsFunctor.h" #include "mitkTestFixture.h" #include "mitkTestingMacros.h" #include #include #include #include #include namespace mitk { class TestFileReaderService : public mitk::AbstractFileReader { public: TestFileReaderService(const std::string &description) : AbstractFileReader(CustomMimeType("TestMimeType"), description) { + Options options; + options["o1"] = 0; + this->SetDefaultOptions(options); m_ServiceRegistration = RegisterService(); }; ~TestFileReaderService() override { }; using AbstractFileReader::Read; std::vector> DoRead() override { std::vector> result; return result; }; ConfidenceLevel GetConfidenceLevel() const override { return Supported; }; private: TestFileReaderService * Clone() const override { return new TestFileReaderService(*this); }; us::ServiceRegistration m_ServiceRegistration; }; } // namespace mitk class mitkPreferenceListReaderOptionsFunctorTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkPreferenceListReaderOptionsFunctorTestSuite); MITK_TEST(UsePreferenceList); MITK_TEST(UseBlackList); MITK_TEST(UseNoList); MITK_TEST(UseBlackAndPreferenceList); MITK_TEST(UseOverlappingBlackAndPreferenceList); MITK_TEST(UsePreferenceListWithInexistantReaders); MITK_TEST(UseAllBlackedList); - + MITK_TEST(SetOptions); CPPUNIT_TEST_SUITE_END(); private: std::string m_ImagePath; mitk::PreferenceListReaderOptionsFunctor::ListType preference; mitk::PreferenceListReaderOptionsFunctor::ListType black; mitk::PreferenceListReaderOptionsFunctor::ListType emptyList; mitk::TestFileReaderService* m_NormalService; mitk::TestFileReaderService* m_PrefService; mitk::TestFileReaderService* m_BlackService; mitk::CustomMimeType* m_TestMimeType; public: void setUp() override { m_ImagePath = GetTestDataFilePath("BallBinary30x30x30.nrrd"); preference = { "Prefered Test Service" }; black = { "Unwanted Test Service" }; emptyList = {}; m_TestMimeType = new mitk::CustomMimeType("TestMimeType"); m_TestMimeType->AddExtension("nrrd"); m_TestMimeType->SetCategory(mitk::IOMimeTypes::CATEGORY_IMAGES()); m_TestMimeType->SetComment("Test mime type"); us::ModuleContext *context = us::GetModuleContext(); us::ServiceProperties props; - props[us::ServiceConstants::SERVICE_RANKING()] = 10; + props[us::ServiceConstants::SERVICE_RANKING()] = 100; context->RegisterService(m_TestMimeType, props); m_NormalService = new mitk::TestFileReaderService("Normal Test Service"); m_PrefService = new mitk::TestFileReaderService("Prefered Test Service"); m_BlackService = new mitk::TestFileReaderService("Unwanted Test Service"); } void tearDown() override { delete m_PrefService; delete m_BlackService; delete m_NormalService; delete m_TestMimeType; } void UsePreferenceList() { mitk::IOUtil::LoadInfo info(m_ImagePath); mitk::PreferenceListReaderOptionsFunctor functor = mitk::PreferenceListReaderOptionsFunctor(preference, emptyList); CPPUNIT_ASSERT(true == functor(info)); auto description = info.m_ReaderSelector.GetSelected().GetDescription(); CPPUNIT_ASSERT_EQUAL(std::string("Prefered Test Service"), description); + CPPUNIT_ASSERT("0" == info.m_ReaderSelector.GetSelected().GetReader()->GetOptions()["o1"].ToString()); } void UseNoList() { mitk::IOUtil::LoadInfo info(m_ImagePath); mitk::PreferenceListReaderOptionsFunctor functor = mitk::PreferenceListReaderOptionsFunctor(emptyList, emptyList); CPPUNIT_ASSERT(true == functor(info)); auto description = info.m_ReaderSelector.GetSelected().GetDescription(); CPPUNIT_ASSERT_EQUAL(std::string("Normal Test Service"), description); } void UseBlackList() { mitk::IOUtil::LoadInfo info(m_ImagePath); mitk::PreferenceListReaderOptionsFunctor functor = mitk::PreferenceListReaderOptionsFunctor(emptyList, black); CPPUNIT_ASSERT(true == functor(info)); auto description = info.m_ReaderSelector.GetSelected().GetDescription(); CPPUNIT_ASSERT(description != "Unwanted Test Service"); } void UseBlackAndPreferenceList() { mitk::IOUtil::LoadInfo info(m_ImagePath); mitk::PreferenceListReaderOptionsFunctor functor = mitk::PreferenceListReaderOptionsFunctor(preference, black); CPPUNIT_ASSERT(true == functor(info)); auto description = info.m_ReaderSelector.GetSelected().GetDescription(); CPPUNIT_ASSERT_EQUAL(std::string("Prefered Test Service"), description); } void UseOverlappingBlackAndPreferenceList() { mitk::IOUtil::LoadInfo info(m_ImagePath); black.push_back("Prefered Test Service"); black.push_back("Normal Test Service"); mitk::PreferenceListReaderOptionsFunctor functor = mitk::PreferenceListReaderOptionsFunctor(preference, black); CPPUNIT_ASSERT(true == functor(info)); auto description = info.m_ReaderSelector.GetSelected().GetDescription(); CPPUNIT_ASSERT_EQUAL(std::string("ITK NrrdImageIO"), description); } void UsePreferenceListWithInexistantReaders() { mitk::IOUtil::LoadInfo info(m_ImagePath); preference.push_back("InexistantReader"); mitk::PreferenceListReaderOptionsFunctor functor = mitk::PreferenceListReaderOptionsFunctor(preference, emptyList); CPPUNIT_ASSERT(true == functor(info)); auto description = info.m_ReaderSelector.GetSelected().GetDescription(); CPPUNIT_ASSERT_EQUAL(std::string("Prefered Test Service"), description); } void UseAllBlackedList() { mitk::IOUtil::LoadInfo info(m_ImagePath); for (auto reader : info.m_ReaderSelector.Get()) { black.push_back(reader.GetDescription()); } mitk::PreferenceListReaderOptionsFunctor functor = mitk::PreferenceListReaderOptionsFunctor(emptyList, black); CPPUNIT_ASSERT_THROW(functor(info), mitk::Exception); } + + void SetOptions() + { + mitk::IOUtil::LoadInfo info(m_ImagePath); + + mitk::IFileReader::Options options; + options.insert(std::make_pair("o1", 42)); + + mitk::PreferenceListReaderOptionsFunctor functor = mitk::PreferenceListReaderOptionsFunctor(preference, options); + + CPPUNIT_ASSERT(true == functor(info)); + auto description = info.m_ReaderSelector.GetSelected().GetDescription(); + CPPUNIT_ASSERT_EQUAL(std::string("Prefered Test Service"), description); + CPPUNIT_ASSERT("42" == info.m_ReaderSelector.GetSelected().GetReader()->GetOption("o1").ToString()); + } + }; MITK_TEST_SUITE_REGISTRATION(mitkPreferenceListReaderOptionsFunctor) diff --git a/Modules/DICOMReader/include/mitkBaseDICOMReaderService.h b/Modules/DICOMReader/include/mitkBaseDICOMReaderService.h index e8527a8a93..0850f14699 100644 --- a/Modules/DICOMReader/include/mitkBaseDICOMReaderService.h +++ b/Modules/DICOMReader/include/mitkBaseDICOMReaderService.h @@ -1,70 +1,70 @@ /*============================================================================ 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 MITKBASEDICOMREADERSERVICE_H #define MITKBASEDICOMREADERSERVICE_H #include #include #include "MitkDICOMReaderExports.h" namespace mitk { /** Base class for service wrappers that make DICOMFileReader from the DICOMReader module usable. */ class MITKDICOMREADER_EXPORT BaseDICOMReaderService : public AbstractFileReader { public: using AbstractFileReader::Read; IFileReader::ConfidenceLevel GetConfidenceLevel() const override; protected: BaseDICOMReaderService(const std::string& description); BaseDICOMReaderService(const mitk::CustomMimeType& customType, const std::string& description); /** Uses this->GetRelevantFile() and this->GetReader to load the image. * data and puts it into base data instances-*/ std::vector> DoRead() override; /** Returns the list of all DCM files that are in the same directory * like this->GetLocalFileName().*/ mitk::StringList GetDICOMFilesInSameDirectory() const; - /** Returns the reader instance that should be used. The descission may be based - * one the passed relevant file list.*/ + /** Returns the reader instance that should be used. The decision may be based + * one the passed list of relevant files.*/ virtual mitk::DICOMFileReader::Pointer GetReader(const mitk::StringList& relevantFiles) const = 0; void SetOnlyRegardOwnSeries(bool); bool GetOnlyRegardOwnSeries() const; private: /** Flags that constrols if the read() operation should only regard DICOM files of the same series if the specified GetLocalFileName() is a file. If it is a director, this flag has no impact (it is assumed false then). */ bool m_OnlyRegardOwnSeries = true; }; class IPropertyProvider; /** Helper function that generates a name string (e.g. for DataNode names) from the DICOM properties of the passed provider instance. If the instance is nullptr, or has no dicom properties DataNode::NO_NAME_VALUE() will be returned.*/ std::string MITKDICOMREADER_EXPORT GenerateNameFromDICOMProperties(const mitk::IPropertyProvider* provider); } #endif // MITKBASEDICOMREADERSERVICE_H 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/mitkAutoSelectingDICOMReaderService.h b/Modules/DICOMReaderServices/include/mitkAutoSelectingDICOMReaderService.h index b4a3023aba..e0087dd882 100644 --- a/Modules/DICOMReaderServices/include/mitkAutoSelectingDICOMReaderService.h +++ b/Modules/DICOMReaderServices/include/mitkAutoSelectingDICOMReaderService.h @@ -1,41 +1,41 @@ /*============================================================================ 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 MITKAUTOSELECTINGDICOMREADERSERVICE_H #define MITKAUTOSELECTINGDICOMREADERSERVICE_H #include namespace mitk { /** Service wrapper that auto selects (using the mitk::DICOMFileReaderSelector) the best DICOMFileReader from the DICOMReader module. */ class AutoSelectingDICOMReaderService : public BaseDICOMReaderService { public: AutoSelectingDICOMReaderService(); protected: - /** Returns the reader instance that should be used. The descission may be based - * one the passed relevant file list.*/ + /** Returns the reader instance that should be used. The decision may be based + * one the passed list of relevant files.*/ mitk::DICOMFileReader::Pointer GetReader(const mitk::StringList& relevantFiles) const override; private: AutoSelectingDICOMReaderService* Clone() const override; }; } #endif // MITKDICOMSERIESREADERSERVICE_H diff --git a/Modules/DICOMReaderServices/include/mitkManualSelectingDICOMReaderService.h b/Modules/DICOMReaderServices/include/mitkManualSelectingDICOMReaderService.h new file mode 100644 index 0000000000..50dd72d7f7 --- /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 decision may be based + * one the passed list of relevant files.*/ + 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/include/mitkSimpleVolumeDICOMSeriesReaderService.h b/Modules/DICOMReaderServices/include/mitkSimpleVolumeDICOMSeriesReaderService.h index fd71f1844e..10a5ace8a0 100644 --- a/Modules/DICOMReaderServices/include/mitkSimpleVolumeDICOMSeriesReaderService.h +++ b/Modules/DICOMReaderServices/include/mitkSimpleVolumeDICOMSeriesReaderService.h @@ -1,40 +1,40 @@ /*============================================================================ 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 MITKSIMPLEVOLUMEDICOMSERIESREADERSERVICE_H #define MITKSIMPLEVOLUMEDICOMSERIESREADERSERVICE_H #include namespace mitk { /** Service wrapper that selects a DICOMITKSeriesGDCMReader configured for a simple and non-restrictive 3D volume import. */ class SimpleVolumeDICOMSeriesReaderService : public BaseDICOMReaderService { public: SimpleVolumeDICOMSeriesReaderService(); protected: - /** Returns the reader instance that should be used. The descission may be based - * one the passed relevant file list.*/ + /** Returns the reader instance that should be used. The decision may be based + * one the passed list of relevant files.*/ mitk::DICOMFileReader::Pointer GetReader(const mitk::StringList& relevantFiles) const override; private: SimpleVolumeDICOMSeriesReaderService* Clone() const override; }; } #endif // MITKSIMPLEVOLUMEDICOMSERIESREADERSERVICE_H diff --git a/Modules/DICOMReaderServices/src/mitkDICOMReaderServicesActivator.cpp b/Modules/DICOMReaderServices/src/mitkDICOMReaderServicesActivator.cpp index 8896d2b9a9..61cbded071 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_AutoSelectingDICOMReader = std::make_unique(); + m_SimpleVolumeDICOMSeriesReader = std::make_unique(); + m_ManualSelectingDICOMSeriesReader = std::make_unique(); - m_DICOMTagsOfInterestService.reset(new DICOMTagsOfInterestService()); + m_DICOMTagsOfInterestService = std::make_unique(); 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..47db50fdaa --- /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); +} + +}