# HG changeset patch # User Sebastien Jodogne # Date 1551267326 -3600 # Node ID 6443aa133b6e6ecc38b7d743a82e303ecf366965 # Parent 69d8e34b04de2fd461183435794fc8bca9bfc82b renamed Dicom.h to GdcmParsedDicomFile.h diff -r 69d8e34b04de -r 6443aa133b6e CMakeLists.txt --- a/CMakeLists.txt Wed Feb 27 12:32:19 2019 +0100 +++ b/CMakeLists.txt Wed Feb 27 12:35:26 2019 +0100 @@ -119,7 +119,7 @@ set(CORE_SOURCES Plugin/Configuration.cpp - Plugin/Dicom.cpp + Plugin/GdcmParsedDicomFile.cpp ${ORTHANC_ROOT}/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp ${ORTHANC_CORE_SOURCES} diff -r 69d8e34b04de -r 6443aa133b6e Plugin/Dicom.cpp --- a/Plugin/Dicom.cpp Wed Feb 27 12:32:19 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,409 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2019 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - **/ - - -#include "Dicom.h" - -#include "Plugin.h" -#include "ChunkedBuffer.h" - -#include - -#include -#include -#include -#include - - -namespace OrthancPlugins -{ - static std::string MyStripSpaces(const std::string& source) - { - size_t first = 0; - - while (first < source.length() && - (isspace(source[first]) || - source[first] == '\0')) - { - first++; - } - - if (first == source.length()) - { - // String containing only spaces - return ""; - } - - size_t last = source.length(); - while (last > first && - (isspace(source[last - 1]) || - source[last - 1] == '\0')) - { - last--; - } - - assert(first <= last); - return source.substr(first, last - first); - } - - - static const char* GetVRName(bool& isSequence, - const gdcm::Dict& dictionary, - const gdcm::Tag& tag, - gdcm::VR vr) - { - if (vr == gdcm::VR::INVALID) - { - const gdcm::DictEntry &entry = dictionary.GetDictEntry(tag); - vr = entry.GetVR(); - - if (vr == gdcm::VR::OB_OW) - { - vr = gdcm::VR::OB; - } - } - - isSequence = (vr == gdcm::VR::SQ); - - const char* str = gdcm::VR::GetVRString(vr); - if (isSequence) - { - return str; - } - - if (str == NULL || - strlen(str) != 2 || - !(str[0] >= 'A' && str[0] <= 'Z') || - !(str[1] >= 'A' && str[1] <= 'Z')) - { - return "UN"; - } - else - { - return str; - } - } - - - static const char* GetVRName(bool& isSequence, - const gdcm::Dict& dictionary, - const gdcm::DataElement& element) - { - return GetVRName(isSequence, dictionary, element.GetTag(), element.GetVR()); - } - - - template - static void ConvertNumberTag(std::string& target, - const gdcm::DataElement& source) - { - if (source.IsEmpty()) - { - target.clear(); - } - else - { - typename gdcm::Element element; - - element.Set(source.GetValue()); - - for (unsigned int i = 0; i < element.GetLength(); i++) - { - if (i != 0) - { - target += "\\"; - } - - target = boost::lexical_cast(element.GetValue()); - } - } - } - - - static bool ConvertDicomStringToUtf8(std::string& result, - const gdcm::Dict& dictionary, - const gdcm::DataElement& element, - const Orthanc::Encoding sourceEncoding) - { - const gdcm::ByteValue* data = element.GetByteValue(); - if (!data) - { - return false; - } - - bool isSequence; - std::string vr = GetVRName(isSequence, dictionary, element); - - if (!isSequence) - { - if (vr == "FL") - { - ConvertNumberTag(result, element); - return true; - } - else if (vr == "FD") - { - ConvertNumberTag(result, element); - return true; - } - else if (vr == "SL") - { - ConvertNumberTag(result, element); - return true; - } - else if (vr == "SS") - { - ConvertNumberTag(result, element); - return true; - } - else if (vr == "UL") - { - ConvertNumberTag(result, element); - return true; - } - else if (vr == "US") - { - ConvertNumberTag(result, element); - return true; - } - } - - if (sourceEncoding == Orthanc::Encoding_Utf8) - { - result.assign(data->GetPointer(), data->GetLength()); - } - else - { - std::string tmp(data->GetPointer(), data->GetLength()); - result = Orthanc::Toolbox::ConvertToUtf8(tmp, sourceEncoding, false); - } - - result = MyStripSpaces(result); - return true; - } - - - - void ParsedDicomFile::Setup(const std::string& dicom) - { - // Prepare a memory stream over the DICOM instance - std::stringstream stream(dicom); - - // Parse the DICOM instance using GDCM - reader_.SetStream(stream); - - if (!reader_.Read()) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, - "GDCM cannot decode this DICOM instance of length " + - boost::lexical_cast(dicom.size())); - } - } - - - ParsedDicomFile::ParsedDicomFile(const OrthancPlugins::MemoryBuffer& buffer) - { - // TODO Avoid this unnecessary memcpy by defining a stream over the MemoryBuffer - std::string dicom(buffer.GetData(), buffer.GetData() + buffer.GetSize()); - Setup(dicom); - } - - - static bool GetRawTag(std::string& result, - const gdcm::DataSet& dataset, - const gdcm::Tag& tag, - bool stripSpaces) - { - if (dataset.FindDataElement(tag)) - { - const gdcm::ByteValue* value = dataset.GetDataElement(tag).GetByteValue(); - if (value) - { - result.assign(value->GetPointer(), value->GetLength()); - - if (stripSpaces) - { - result = MyStripSpaces(result); - } - - return true; - } - } - - return false; - } - - - bool ParsedDicomFile::GetRawTag(std::string& result, - const gdcm::Tag& tag, - bool stripSpaces) const - { - return OrthancPlugins::GetRawTag(result, GetDataSet(), tag, stripSpaces); - } - - - std::string ParsedDicomFile::GetRawTagWithDefault(const gdcm::Tag& tag, - const std::string& defaultValue, - bool stripSpaces) const - { - std::string result; - if (!GetRawTag(result, tag, stripSpaces)) - { - return defaultValue; - } - else - { - return result; - } - } - - - std::string ParsedDicomFile::GetRawTagWithDefault(const Orthanc::DicomTag& tag, - const std::string& defaultValue, - bool stripSpaces) const - { - gdcm::Tag t(tag.GetGroup(), tag.GetElement()); - return GetRawTagWithDefault(t, defaultValue, stripSpaces); - } - - - bool ParsedDicomFile::GetStringTag(std::string& result, - const gdcm::Dict& dictionary, - const gdcm::Tag& tag, - bool stripSpaces) const - { - if (!GetDataSet().FindDataElement(tag)) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag); - } - - const gdcm::DataElement& element = GetDataSet().GetDataElement(tag); - - if (!ConvertDicomStringToUtf8(result, dictionary, element, GetEncoding())) - { - return false; - } - - if (stripSpaces) - { - result = MyStripSpaces(result); - } - - return true; - } - - - bool ParsedDicomFile::GetIntegerTag(int& result, - const gdcm::Dict& dictionary, - const gdcm::Tag& tag) const - { - std::string tmp; - if (!GetStringTag(tmp, dictionary, tag, true)) - { - return false; - } - - try - { - result = boost::lexical_cast(tmp); - return true; - } - catch (boost::bad_lexical_cast&) - { - return false; - } - } - - - std::string FormatTag(const gdcm::Tag& tag) - { - char tmp[16]; - sprintf(tmp, "%04X%04X", tag.GetGroup(), tag.GetElement()); - return std::string(tmp); - } - - - static std::string GetWadoUrl(const std::string& wadoBase, - const gdcm::DataSet& dicom) - { - static const gdcm::Tag DICOM_TAG_STUDY_INSTANCE_UID(0x0020, 0x000d); - static const gdcm::Tag DICOM_TAG_SERIES_INSTANCE_UID(0x0020, 0x000e); - static const gdcm::Tag DICOM_TAG_SOP_INSTANCE_UID(0x0008, 0x0018); - - std::string study, series, instance; - - if (!GetRawTag(study, dicom, DICOM_TAG_STUDY_INSTANCE_UID, true) || - !GetRawTag(series, dicom, DICOM_TAG_SERIES_INSTANCE_UID, true) || - !GetRawTag(instance, dicom, DICOM_TAG_SOP_INSTANCE_UID, true)) - { - return ""; - } - else - { - return Configuration::GetWadoUrl(wadoBase, study, series, instance); - } - } - - - static Orthanc::Encoding DetectEncoding(const gdcm::DataSet& dicom) - { - static const gdcm::Tag DICOM_TAG_SPECIFIC_CHARACTER_SET(0x0008, 0x0005); - - if (!dicom.FindDataElement(DICOM_TAG_SPECIFIC_CHARACTER_SET)) - { - return Orthanc::Encoding_Ascii; - } - - const gdcm::DataElement& element = - dicom.GetDataElement(DICOM_TAG_SPECIFIC_CHARACTER_SET); - - const gdcm::ByteValue* data = element.GetByteValue(); - if (!data) - { - return Configuration::GetDefaultEncoding(); - } - - std::string tmp(data->GetPointer(), data->GetLength()); - tmp = MyStripSpaces(tmp); - - Orthanc::Encoding encoding; - if (Orthanc::GetDicomEncoding(encoding, tmp.c_str())) - { - return encoding; - } - else - { - return Configuration::GetDefaultEncoding(); - } - } - - - Orthanc::Encoding ParsedDicomFile::GetEncoding() const - { - return DetectEncoding(GetDataSet()); - } - - - std::string ParsedDicomFile::GetWadoUrl(const OrthancPluginHttpRequest* request) const - { - const std::string base = OrthancPlugins::Configuration::GetBaseUrl(request); - return OrthancPlugins::GetWadoUrl(base, GetDataSet()); - } -} diff -r 69d8e34b04de -r 6443aa133b6e Plugin/Dicom.h --- a/Plugin/Dicom.h Wed Feb 27 12:32:19 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2019 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - **/ - - -#pragma once - -#include "Configuration.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - - -namespace OrthancPlugins -{ - class ParsedDicomFile - { - private: - gdcm::Reader reader_; - - void Setup(const std::string& dicom); - - Orthanc::Encoding GetEncoding() const; - - public: - explicit ParsedDicomFile(const OrthancPlugins::MemoryBuffer& item); - - explicit ParsedDicomFile(const std::string& dicom) - { - Setup(dicom); - } - - const gdcm::File& GetFile() const - { - return reader_.GetFile(); - } - - const gdcm::DataSet& GetDataSet() const - { - return reader_.GetFile().GetDataSet(); - } - - bool GetRawTag(std::string& result, - const gdcm::Tag& tag, - bool stripSpaces) const; - - std::string GetRawTagWithDefault(const gdcm::Tag& tag, - const std::string& defaultValue, - bool stripSpaces) const; - - std::string GetRawTagWithDefault(const Orthanc::DicomTag& tag, - const std::string& defaultValue, - bool stripSpaces) const; - - bool GetStringTag(std::string& result, - const gdcm::Dict& dictionary, - const gdcm::Tag& tag, - bool stripSpaces) const; - - bool GetIntegerTag(int& result, - const gdcm::Dict& dictionary, - const gdcm::Tag& tag) const; - - std::string GetWadoUrl(const OrthancPluginHttpRequest* request) const; - }; -} diff -r 69d8e34b04de -r 6443aa133b6e Plugin/GdcmParsedDicomFile.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Plugin/GdcmParsedDicomFile.cpp Wed Feb 27 12:35:26 2019 +0100 @@ -0,0 +1,409 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#include "GdcmParsedDicomFile.h" + +#include "Plugin.h" +#include "ChunkedBuffer.h" + +#include + +#include +#include +#include +#include + + +namespace OrthancPlugins +{ + static std::string MyStripSpaces(const std::string& source) + { + size_t first = 0; + + while (first < source.length() && + (isspace(source[first]) || + source[first] == '\0')) + { + first++; + } + + if (first == source.length()) + { + // String containing only spaces + return ""; + } + + size_t last = source.length(); + while (last > first && + (isspace(source[last - 1]) || + source[last - 1] == '\0')) + { + last--; + } + + assert(first <= last); + return source.substr(first, last - first); + } + + + static const char* GetVRName(bool& isSequence, + const gdcm::Dict& dictionary, + const gdcm::Tag& tag, + gdcm::VR vr) + { + if (vr == gdcm::VR::INVALID) + { + const gdcm::DictEntry &entry = dictionary.GetDictEntry(tag); + vr = entry.GetVR(); + + if (vr == gdcm::VR::OB_OW) + { + vr = gdcm::VR::OB; + } + } + + isSequence = (vr == gdcm::VR::SQ); + + const char* str = gdcm::VR::GetVRString(vr); + if (isSequence) + { + return str; + } + + if (str == NULL || + strlen(str) != 2 || + !(str[0] >= 'A' && str[0] <= 'Z') || + !(str[1] >= 'A' && str[1] <= 'Z')) + { + return "UN"; + } + else + { + return str; + } + } + + + static const char* GetVRName(bool& isSequence, + const gdcm::Dict& dictionary, + const gdcm::DataElement& element) + { + return GetVRName(isSequence, dictionary, element.GetTag(), element.GetVR()); + } + + + template + static void ConvertNumberTag(std::string& target, + const gdcm::DataElement& source) + { + if (source.IsEmpty()) + { + target.clear(); + } + else + { + typename gdcm::Element element; + + element.Set(source.GetValue()); + + for (unsigned int i = 0; i < element.GetLength(); i++) + { + if (i != 0) + { + target += "\\"; + } + + target = boost::lexical_cast(element.GetValue()); + } + } + } + + + static bool ConvertDicomStringToUtf8(std::string& result, + const gdcm::Dict& dictionary, + const gdcm::DataElement& element, + const Orthanc::Encoding sourceEncoding) + { + const gdcm::ByteValue* data = element.GetByteValue(); + if (!data) + { + return false; + } + + bool isSequence; + std::string vr = GetVRName(isSequence, dictionary, element); + + if (!isSequence) + { + if (vr == "FL") + { + ConvertNumberTag(result, element); + return true; + } + else if (vr == "FD") + { + ConvertNumberTag(result, element); + return true; + } + else if (vr == "SL") + { + ConvertNumberTag(result, element); + return true; + } + else if (vr == "SS") + { + ConvertNumberTag(result, element); + return true; + } + else if (vr == "UL") + { + ConvertNumberTag(result, element); + return true; + } + else if (vr == "US") + { + ConvertNumberTag(result, element); + return true; + } + } + + if (sourceEncoding == Orthanc::Encoding_Utf8) + { + result.assign(data->GetPointer(), data->GetLength()); + } + else + { + std::string tmp(data->GetPointer(), data->GetLength()); + result = Orthanc::Toolbox::ConvertToUtf8(tmp, sourceEncoding, false); + } + + result = MyStripSpaces(result); + return true; + } + + + + void GdcmParsedDicomFile::Setup(const std::string& dicom) + { + // Prepare a memory stream over the DICOM instance + std::stringstream stream(dicom); + + // Parse the DICOM instance using GDCM + reader_.SetStream(stream); + + if (!reader_.Read()) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, + "GDCM cannot decode this DICOM instance of length " + + boost::lexical_cast(dicom.size())); + } + } + + + GdcmParsedDicomFile::GdcmParsedDicomFile(const OrthancPlugins::MemoryBuffer& buffer) + { + // TODO Avoid this unnecessary memcpy by defining a stream over the MemoryBuffer + std::string dicom(buffer.GetData(), buffer.GetData() + buffer.GetSize()); + Setup(dicom); + } + + + static bool GetRawTag(std::string& result, + const gdcm::DataSet& dataset, + const gdcm::Tag& tag, + bool stripSpaces) + { + if (dataset.FindDataElement(tag)) + { + const gdcm::ByteValue* value = dataset.GetDataElement(tag).GetByteValue(); + if (value) + { + result.assign(value->GetPointer(), value->GetLength()); + + if (stripSpaces) + { + result = MyStripSpaces(result); + } + + return true; + } + } + + return false; + } + + + bool GdcmParsedDicomFile::GetRawTag(std::string& result, + const gdcm::Tag& tag, + bool stripSpaces) const + { + return OrthancPlugins::GetRawTag(result, GetDataSet(), tag, stripSpaces); + } + + + std::string GdcmParsedDicomFile::GetRawTagWithDefault(const gdcm::Tag& tag, + const std::string& defaultValue, + bool stripSpaces) const + { + std::string result; + if (!GetRawTag(result, tag, stripSpaces)) + { + return defaultValue; + } + else + { + return result; + } + } + + + std::string GdcmParsedDicomFile::GetRawTagWithDefault(const Orthanc::DicomTag& tag, + const std::string& defaultValue, + bool stripSpaces) const + { + gdcm::Tag t(tag.GetGroup(), tag.GetElement()); + return GetRawTagWithDefault(t, defaultValue, stripSpaces); + } + + + bool GdcmParsedDicomFile::GetStringTag(std::string& result, + const gdcm::Dict& dictionary, + const gdcm::Tag& tag, + bool stripSpaces) const + { + if (!GetDataSet().FindDataElement(tag)) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag); + } + + const gdcm::DataElement& element = GetDataSet().GetDataElement(tag); + + if (!ConvertDicomStringToUtf8(result, dictionary, element, GetEncoding())) + { + return false; + } + + if (stripSpaces) + { + result = MyStripSpaces(result); + } + + return true; + } + + + bool GdcmParsedDicomFile::GetIntegerTag(int& result, + const gdcm::Dict& dictionary, + const gdcm::Tag& tag) const + { + std::string tmp; + if (!GetStringTag(tmp, dictionary, tag, true)) + { + return false; + } + + try + { + result = boost::lexical_cast(tmp); + return true; + } + catch (boost::bad_lexical_cast&) + { + return false; + } + } + + + std::string FormatTag(const gdcm::Tag& tag) + { + char tmp[16]; + sprintf(tmp, "%04X%04X", tag.GetGroup(), tag.GetElement()); + return std::string(tmp); + } + + + static std::string GetWadoUrl(const std::string& wadoBase, + const gdcm::DataSet& dicom) + { + static const gdcm::Tag DICOM_TAG_STUDY_INSTANCE_UID(0x0020, 0x000d); + static const gdcm::Tag DICOM_TAG_SERIES_INSTANCE_UID(0x0020, 0x000e); + static const gdcm::Tag DICOM_TAG_SOP_INSTANCE_UID(0x0008, 0x0018); + + std::string study, series, instance; + + if (!GetRawTag(study, dicom, DICOM_TAG_STUDY_INSTANCE_UID, true) || + !GetRawTag(series, dicom, DICOM_TAG_SERIES_INSTANCE_UID, true) || + !GetRawTag(instance, dicom, DICOM_TAG_SOP_INSTANCE_UID, true)) + { + return ""; + } + else + { + return Configuration::GetWadoUrl(wadoBase, study, series, instance); + } + } + + + static Orthanc::Encoding DetectEncoding(const gdcm::DataSet& dicom) + { + static const gdcm::Tag DICOM_TAG_SPECIFIC_CHARACTER_SET(0x0008, 0x0005); + + if (!dicom.FindDataElement(DICOM_TAG_SPECIFIC_CHARACTER_SET)) + { + return Orthanc::Encoding_Ascii; + } + + const gdcm::DataElement& element = + dicom.GetDataElement(DICOM_TAG_SPECIFIC_CHARACTER_SET); + + const gdcm::ByteValue* data = element.GetByteValue(); + if (!data) + { + return Configuration::GetDefaultEncoding(); + } + + std::string tmp(data->GetPointer(), data->GetLength()); + tmp = MyStripSpaces(tmp); + + Orthanc::Encoding encoding; + if (Orthanc::GetDicomEncoding(encoding, tmp.c_str())) + { + return encoding; + } + else + { + return Configuration::GetDefaultEncoding(); + } + } + + + Orthanc::Encoding GdcmParsedDicomFile::GetEncoding() const + { + return DetectEncoding(GetDataSet()); + } + + + std::string GdcmParsedDicomFile::GetWadoUrl(const OrthancPluginHttpRequest* request) const + { + const std::string base = OrthancPlugins::Configuration::GetBaseUrl(request); + return OrthancPlugins::GetWadoUrl(base, GetDataSet()); + } +} diff -r 69d8e34b04de -r 6443aa133b6e Plugin/GdcmParsedDicomFile.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Plugin/GdcmParsedDicomFile.h Wed Feb 27 12:35:26 2019 +0100 @@ -0,0 +1,90 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#pragma once + +#include "Configuration.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + + +namespace OrthancPlugins +{ + class GdcmParsedDicomFile : public boost::noncopyable + { + private: + gdcm::Reader reader_; + + void Setup(const std::string& dicom); + + Orthanc::Encoding GetEncoding() const; + + public: + explicit GdcmParsedDicomFile(const OrthancPlugins::MemoryBuffer& item); + + explicit GdcmParsedDicomFile(const std::string& dicom) + { + Setup(dicom); + } + + const gdcm::File& GetFile() const + { + return reader_.GetFile(); + } + + const gdcm::DataSet& GetDataSet() const + { + return reader_.GetFile().GetDataSet(); + } + + bool GetRawTag(std::string& result, + const gdcm::Tag& tag, + bool stripSpaces) const; + + std::string GetRawTagWithDefault(const gdcm::Tag& tag, + const std::string& defaultValue, + bool stripSpaces) const; + + std::string GetRawTagWithDefault(const Orthanc::DicomTag& tag, + const std::string& defaultValue, + bool stripSpaces) const; + + bool GetStringTag(std::string& result, + const gdcm::Dict& dictionary, + const gdcm::Tag& tag, + bool stripSpaces) const; + + bool GetIntegerTag(int& result, + const gdcm::Dict& dictionary, + const gdcm::Tag& tag) const; + + std::string GetWadoUrl(const OrthancPluginHttpRequest* request) const; + }; +} diff -r 69d8e34b04de -r 6443aa133b6e Plugin/WadoRsRetrieveFrames.cpp --- a/Plugin/WadoRsRetrieveFrames.cpp Wed Feb 27 12:32:19 2019 +0100 +++ b/Plugin/WadoRsRetrieveFrames.cpp Wed Feb 27 12:35:26 2019 +0100 @@ -21,7 +21,7 @@ #include "WadoRs.h" -#include "Dicom.h" +#include "GdcmParsedDicomFile.h" #include "Plugin.h" #include @@ -333,7 +333,7 @@ static void AnswerSingleFrame(OrthancPluginRestOutput* output, const OrthancPluginHttpRequest* request, - const OrthancPlugins::ParsedDicomFile& dicom, + const OrthancPlugins::GdcmParsedDicomFile& dicom, const char* frame, size_t size, unsigned int frameIndex) @@ -359,7 +359,7 @@ static bool AnswerFrames(OrthancPluginRestOutput* output, const OrthancPluginHttpRequest* request, - const OrthancPlugins::ParsedDicomFile& dicom, + const OrthancPlugins::GdcmParsedDicomFile& dicom, const gdcm::TransferSyntax& syntax, std::list& frames) { @@ -509,7 +509,7 @@ OrthancPlugins::LogInfo(s); } - std::auto_ptr source; + std::auto_ptr source; gdcm::TransferSyntax sourceSyntax; @@ -520,7 +520,7 @@ } else { - source.reset(new OrthancPlugins::ParsedDicomFile(content)); + source.reset(new OrthancPlugins::GdcmParsedDicomFile(content)); sourceSyntax = source->GetFile().GetHeader().GetDataSetTransferSyntax(); } @@ -532,7 +532,7 @@ if (source.get() == NULL) { - source.reset(new OrthancPlugins::ParsedDicomFile(content)); + source.reset(new OrthancPlugins::GdcmParsedDicomFile(content)); } AnswerFrames(output, request, *source, targetSyntax, frames); @@ -580,7 +580,7 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory); } - OrthancPlugins::ParsedDicomFile transcoded(ss.str()); + OrthancPlugins::GdcmParsedDicomFile transcoded(ss.str()); AnswerFrames(output, request, transcoded, targetSyntax, frames); } }