diff --git a/Modules/CEST/autoload/IO/mitkCESTIOActivator.cpp b/Modules/CEST/autoload/IO/mitkCESTIOActivator.cpp index fd293302d9..0c2344667e 100644 --- a/Modules/CEST/autoload/IO/mitkCESTIOActivator.cpp +++ b/Modules/CEST/autoload/IO/mitkCESTIOActivator.cpp @@ -1,103 +1,101 @@ /*============================================================================ 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 "mitkCESTIOActivator.h" #include "mitkCESTDICOMReaderService.h" #include "mitkCESTGenericDICOMReaderService.h" #include #include #include "mitkCESTIOMimeTypes.h" #include namespace mitk { void CESTIOActivator::Load(us::ModuleContext *context) { us::ServiceProperties props; props[us::ServiceConstants::SERVICE_RANKING()] = 10; m_MimeTypes = mitk::MitkCESTIOMimeTypes::Get(); for (auto& mimeType : m_MimeTypes) { if (mimeType->GetName() == mitk::MitkCESTIOMimeTypes::CEST_DICOM_WITHOUT_META_FILE_NAME()) { // "w/o meta" mimetype should only registered with low priority. context->RegisterService(mimeType); } else { context->RegisterService(mimeType, props); } } m_CESTDICOMReader.reset(new CESTDICOMReaderService()); m_CESTDICOMManualWithMetaFileReader.reset(new CESTDICOMManualReaderService(MitkCESTIOMimeTypes::CEST_DICOM_WITH_META_FILE_MIMETYPE(), "CEST DICOM Manual Reader")); m_CESTDICOMManualWithOutMetaFileReader.reset(new CESTDICOMManualReaderService(MitkCESTIOMimeTypes::CEST_DICOM_WITHOUT_META_FILE_MIMETYPE(), "CEST DICOM Manual Reader")); m_Context = context; { std::lock_guard lock(m_Mutex); // Listen for events pertaining to dictionary services. m_Context->AddServiceListener(this, &CESTIOActivator::DICOMTagsOfInterestServiceChanged, std::string("(&(") + us::ServiceConstants::OBJECTCLASS() + "=" + us_service_interface_iid() + "))"); // Query for any service references matching any language. std::vector > refs = context->GetServiceReferences(); if (!refs.empty()) { for (auto ref : refs) { this->RegisterTagsOfInterest(m_Context->GetService(ref)); m_Context->UngetService(ref); } } } - - IDICOMTagsOfInterest* toiService = mitk::GetDicomTagsOfInterestService(); } void CESTIOActivator::Unload(us::ModuleContext *) { for (auto& elem : m_MimeTypes) { delete elem; } } void CESTIOActivator::RegisterTagsOfInterest(IDICOMTagsOfInterest* toiService) const { if (toiService != nullptr) { toiService->AddTagOfInterest(mitk::DICOM_IMAGING_FREQUENCY_PATH()); } } void CESTIOActivator::DICOMTagsOfInterestServiceChanged(const us::ServiceEvent event) { std::lock_guard lock(m_Mutex); // If a dictionary service was registered, see if we // need one. If so, get a reference to it. if (event.GetType() == us::ServiceEvent::REGISTERED) { // Get a reference to the service object. us::ServiceReference ref = event.GetServiceReference(); this->RegisterTagsOfInterest(m_Context->GetService(ref)); m_Context->UngetService(ref); } } } US_EXPORT_MODULE_ACTIVATOR(mitk::CESTIOActivator) diff --git a/Modules/CEST/src/mitkCESTPropertyHelper.cpp b/Modules/CEST/src/mitkCESTPropertyHelper.cpp index f6c154afb4..5cf42bfe28 100644 --- a/Modules/CEST/src/mitkCESTPropertyHelper.cpp +++ b/Modules/CEST/src/mitkCESTPropertyHelper.cpp @@ -1,146 +1,146 @@ /*============================================================================ 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 "mitkCESTPropertyHelper.h" #include "mitkDICOMProperty.h" #include "mitkStringProperty.h" const std::string mitk::CEST_PROPERTY_NAME_PREPERATIONTYPE() { return "CEST.PreparationType"; } const std::string mitk::CEST_PROPERTY_NAME_RECOVERYMODE() { return "CEST.RecoveryMode"; } const std::string mitk::CEST_PROPERTY_NAME_SPOILINGTYPE() { return "CEST.SpoilingType"; } const std::string mitk::CEST_PROPERTY_NAME_OFFSETS() { return "CEST.Offsets"; } const std::string mitk::CEST_PROPERTY_NAME_TREC() { return std::string("CEST.TREC"); } const std::string mitk::CEST_PROPERTY_NAME_FREQ() { return std::string("CEST.FREQ"); } const std::string mitk::CEST_PROPERTY_NAME_PULSEDURATION() { return std::string("CEST.PulseDuration"); } const std::string mitk::CEST_PROPERTY_NAME_B1Amplitude() { return std::string("CEST.B1Amplitude"); } const std::string mitk::CEST_PROPERTY_NAME_DutyCycle() { return std::string("CEST.DutyCycle"); } double mitk::GetCESTB1Amplitude(const IPropertyProvider* provider) { if (!provider) { mitkThrow() << "Cannot determine B! amplitude. Passed property provider is invalid."; } double result = 0.0; auto prop = provider->GetConstProperty(CEST_PROPERTY_NAME_B1Amplitude().c_str()); if (prop.IsNotNull()) { result = mitk::ConvertDICOMStrToValue(prop->GetValueAsString()); } - else mitkThrow() << "Cannot determine B! amplitude. Selected input has no property \"" << CEST_PROPERTY_NAME_B1Amplitude << "\""; + else mitkThrow() << "Cannot determine B! amplitude. Selected input has no property \"" << CEST_PROPERTY_NAME_B1Amplitude() << "\""; return result; } double mitk::GetCESTFrequency(const IPropertyProvider* provider) { if (!provider) { mitkThrow() << "Cannot determine frequency. Passed property provider is invalid."; } double result = 0.0; auto prop = provider->GetConstProperty(CEST_PROPERTY_NAME_FREQ().c_str()); if (prop.IsNotNull()) { result = mitk::ConvertDICOMStrToValue(prop->GetValueAsString()) * 0.000001; } - else mitkThrow() << "Cannot determine frequency. Selected input has no property \"" << CEST_PROPERTY_NAME_FREQ << "\""; + else mitkThrow() << "Cannot determine frequency. Selected input has no property \"" << CEST_PROPERTY_NAME_FREQ() << "\""; return result; } void mitk::SetCESTFrequencyMHz(IPropertyOwner* owner, double freqInMHz) { if (nullptr != owner) { owner->SetProperty(CEST_PROPERTY_NAME_FREQ().c_str(), mitk::StringProperty::New(ConvertValueToDICOMStr(freqInMHz * 1000000))); } } double mitk::GetCESTPulseDuration(const IPropertyProvider* provider) { if (!provider) { mitkThrow() << "Cannot determine pulse duration. Passed property provider is invalid."; } double result = 0.0; auto prop = provider->GetConstProperty(CEST_PROPERTY_NAME_PULSEDURATION().c_str()); if (prop.IsNotNull()) { result = mitk::ConvertDICOMStrToValue(prop->GetValueAsString()) * 0.000001; } - else mitkThrow() << "Cannot determine pulse duration. Selected input has no property \"" << CEST_PROPERTY_NAME_PULSEDURATION << "\""; + else mitkThrow() << "Cannot determine pulse duration. Selected input has no property \"" << CEST_PROPERTY_NAME_PULSEDURATION() << "\""; return result; } double mitk::GetCESTDutyCycle(const IPropertyProvider* provider) { if (!provider) { mitkThrow() << "Cannot determine duty cycle. Passed property provider is invalid."; } double result = 0.0; auto prop = provider->GetConstProperty(CEST_PROPERTY_NAME_DutyCycle().c_str()); if (prop.IsNotNull()) { result = mitk::ConvertDICOMStrToValue(prop->GetValueAsString()) * 0.01; } - else mitkThrow() << "Cannot determine duty cycle. Selected input has no property \"" << CEST_PROPERTY_NAME_DutyCycle << "\""; + else mitkThrow() << "Cannot determine duty cycle. Selected input has no property \"" << CEST_PROPERTY_NAME_DutyCycle() << "\""; return result; } diff --git a/Modules/DICOMReader/include/mitkDICOMProperty.h b/Modules/DICOMReader/include/mitkDICOMProperty.h index 20bd65cca6..4f24614af2 100644 --- a/Modules/DICOMReader/include/mitkDICOMProperty.h +++ b/Modules/DICOMReader/include/mitkDICOMProperty.h @@ -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. ============================================================================*/ #ifndef mitkDICOMProperty_h #define mitkDICOMProperty_h #include "mitkDICOMImageBlockDescriptor.h" #include "mitkTemporoSpatialStringProperty.h" #include "mitkDICOMTagPath.h" #include "MitkDICOMReaderExports.h" namespace mitk { typedef TemporoSpatialStringProperty DICOMProperty; /** Generation functor for DICOMFileReader classes to convert the collected tag values into DICOMProperty instances. */ MITKDICOMREADER_EXPORT mitk::BaseProperty::Pointer GetDICOMPropertyForDICOMValuesFunctor(const DICOMCachedValueLookupTable& cacheLookupTable); class PropertyList; class BaseData; /** Helper function that searches for all properties in a given property list that matches the passed path. * The result will be the matching properties in a map*/ MITKDICOMREADER_EXPORT std::map< std::string, BaseProperty::Pointer> GetPropertyByDICOMTagPath(const PropertyList* list, const DICOMTagPath& path); /** Helper function that searches for all properties in a given base data that matches the passed path. * The result will be the matching properties in a map*/ MITKDICOMREADER_EXPORT std::map< std::string, BaseProperty::Pointer> GetPropertyByDICOMTagPath(const BaseData* data, const DICOMTagPath& path); /**Helper function that can be used to convert the content of a DICOM property into the given return type. The function makes the following assumptions: 1. dcmValueString does only encode one number. 2. The value is encoded compliant to locale "C". @pre dcmValueString must be convertibel into the return type. If this is not the case an exception will be thrown. */ template TNumericReturnType ConvertDICOMStrToValue(const std::string& dcmValueString) { std::istringstream iss(dcmValueString); iss.imbue(std::locale("C")); TNumericReturnType d; if (!(iss >> d) || !(iss.eof())) { mitkThrow() << "Cannot convert string to value type. Type: " << typeid(TNumericReturnType).name() << "; String: " << dcmValueString; } return d; }; /**Helper function that can be used to convert a numeric value into content of a DICOM property. @pre value must be convertibel into a string. If this is not the case an exception will be thrown. */ template std::string ConvertValueToDICOMStr(const TNumericType value) { - std::ostringstream oss(value); + std::ostringstream oss; oss.imbue(std::locale("C")); if (!(oss << value)) { mitkThrow() << "Cannot convert value type to dicom string. Type: " << typeid(TNumericType).name() << "; value: " << value; } return oss.str(); }; } #endif