Mercurial > hg > orthanc
changeset 1740:5e99a70b0635
DicomToJson callable from plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 22 Oct 2015 19:53:51 +0200 |
parents | df331354cea2 |
children | 06addfcd1d4c |
files | Plugins/Engine/OrthancPlugins.cpp Plugins/Engine/OrthancPlugins.h Plugins/Engine/PluginsEnumerations.cpp Plugins/Engine/PluginsEnumerations.h Plugins/Include/orthanc/OrthancCPlugin.h |
diffstat | 5 files changed, 170 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp Thu Oct 22 19:00:32 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Thu Oct 22 19:53:51 2015 +0200 @@ -299,7 +299,15 @@ sizeof(int32_t) != sizeof(OrthancPluginImageFormat) || sizeof(int32_t) != sizeof(OrthancPluginCompressionType) || sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) || - sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType)) + sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) || + sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) || + sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType) || + static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeBinary) != static_cast<int>(DicomToJsonFlags_IncludeBinary) || + static_cast<int>(OrthancPluginDicomToJsonFlags_IncludePrivateTags) != static_cast<int>(DicomToJsonFlags_IncludePrivateTags) || + static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeUnknownTags) != static_cast<int>(DicomToJsonFlags_IncludeUnknownTags) || + static_cast<int>(OrthancPluginDicomToJsonFlags_IncludePixelData) != static_cast<int>(DicomToJsonFlags_IncludePixelData) || + static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToNull) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToNull) || + static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToAscii)) { /* Sanity check of the compiler */ throw OrthancException(ErrorCode_Plugin); @@ -1229,6 +1237,39 @@ font.Draw(target, p.utf8Text, p.x, p.y, p.r, p.g, p.b); } + + + void OrthancPlugins::ApplyDicomToJson(_OrthancPluginService service, + const void* parameters) + { + const _OrthancPluginDicomToJson& p = + *reinterpret_cast<const _OrthancPluginDicomToJson*>(parameters); + + std::auto_ptr<ParsedDicomFile> dicom; + + if (service == _OrthancPluginService_DicomBufferToJson) + { + dicom.reset(new ParsedDicomFile(p.buffer, p.size)); + } + else + { + if (p.instanceId == NULL) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + std::string content; + pimpl_->context_->ReadFile(content, p.instanceId, FileContentType_Dicom); + dicom.reset(new ParsedDicomFile(content)); + } + + Json::Value json; + dicom->ToJson(json, Plugins::Convert(p.format), + static_cast<DicomToJsonFlags>(p.flags), p.maxStringLength); + + Json::FastWriter writer; + *p.result = CopyString(writer.write(json)); + } bool OrthancPlugins::InvokeService(SharedLibrary& plugin, @@ -1726,6 +1767,11 @@ return true; } + case _OrthancPluginService_DicomBufferToJson: + case _OrthancPluginService_DicomInstanceToJson: + ApplyDicomToJson(service, parameters); + return true; + default: { // This service is unknown to the Orthanc plugin engine
--- a/Plugins/Engine/OrthancPlugins.h Thu Oct 22 19:00:32 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.h Thu Oct 22 19:53:51 2015 +0200 @@ -127,6 +127,9 @@ void DrawText(const void* parameters); + void ApplyDicomToJson(_OrthancPluginService service, + const void* parameters); + public: OrthancPlugins();
--- a/Plugins/Engine/PluginsEnumerations.cpp Thu Oct 22 19:00:32 2015 +0200 +++ b/Plugins/Engine/PluginsEnumerations.cpp Thu Oct 22 19:53:51 2015 +0200 @@ -210,6 +210,25 @@ } + DicomToJsonFormat Convert(OrthancPluginDicomToJsonFormat format) + { + switch (format) + { + case OrthancPluginDicomToJsonFormat_Full: + return DicomToJsonFormat_Full; + + case OrthancPluginDicomToJsonFormat_Short: + return DicomToJsonFormat_Short; + + case OrthancPluginDicomToJsonFormat_Simple: + return DicomToJsonFormat_Simple; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + } + + #if !defined(ORTHANC_ENABLE_DCMTK) || ORTHANC_ENABLE_DCMTK != 0 DcmEVR Convert(OrthancPluginValueRepresentation vr) {
--- a/Plugins/Engine/PluginsEnumerations.h Thu Oct 22 19:00:32 2015 +0200 +++ b/Plugins/Engine/PluginsEnumerations.h Thu Oct 22 19:53:51 2015 +0200 @@ -59,6 +59,8 @@ FileContentType Convert(OrthancPluginContentType type); + DicomToJsonFormat Convert(OrthancPluginDicomToJsonFormat format); + #if !defined(ORTHANC_ENABLE_DCMTK) || ORTHANC_ENABLE_DCMTK != 0 DcmEVR Convert(OrthancPluginValueRepresentation vr); #endif
--- a/Plugins/Include/orthanc/OrthancCPlugin.h Thu Oct 22 19:00:32 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Thu Oct 22 19:53:51 2015 +0200 @@ -387,6 +387,8 @@ _OrthancPluginService_CallHttpClient = 18, _OrthancPluginService_RegisterErrorCode = 19, _OrthancPluginService_RegisterDictionaryTag = 20, + _OrthancPluginService_DicomBufferToJson = 21, + _OrthancPluginService_DicomInstanceToJson = 22, /* Registration of callbacks */ _OrthancPluginService_RegisterRestCallback = 1000, @@ -641,6 +643,29 @@ } OrthancPluginValueRepresentation; + typedef enum + { + OrthancPluginDicomToJsonFormat_Full = 1, + OrthancPluginDicomToJsonFormat_Short = 2, + OrthancPluginDicomToJsonFormat_Simple = 3, + + _OrthancPluginDicomToJsonFormat_INTERNAL = 0x7fffffff + } OrthancPluginDicomToJsonFormat; + + + typedef enum + { + OrthancPluginDicomToJsonFlags_IncludeBinary = (1 << 0), + OrthancPluginDicomToJsonFlags_IncludePrivateTags = (1 << 1), + OrthancPluginDicomToJsonFlags_IncludeUnknownTags = (1 << 2), + OrthancPluginDicomToJsonFlags_IncludePixelData = (1 << 3), + OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii = (1 << 4), + OrthancPluginDicomToJsonFlags_ConvertBinaryToNull = (1 << 5), + + _OrthancPluginDicomToJsonFlags_INTERNAL = 0x7fffffff + } OrthancPluginDicomToJsonFlags; + + /** * @brief A memory buffer allocated by the core system of Orthanc. * @@ -852,7 +877,9 @@ sizeof(int32_t) != sizeof(OrthancPluginChangeType) || sizeof(int32_t) != sizeof(OrthancPluginCompressionType) || sizeof(int32_t) != sizeof(OrthancPluginImageFormat) || - sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation)) + sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) || + sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) || + sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags)) { /* Mismatch in the size of the enumerations */ return 0; @@ -3806,6 +3833,77 @@ } + typedef struct + { + char** result; + const char* instanceId; + const char* buffer; + uint32_t size; + OrthancPluginDicomToJsonFormat format; + OrthancPluginDicomToJsonFlags flags; + uint32_t maxStringLength; + } _OrthancPluginDicomToJson; + + ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomBufferToJson( + OrthancPluginContext* context, + const char* buffer, + uint32_t size, + OrthancPluginDicomToJsonFormat format, + OrthancPluginDicomToJsonFlags flags, + uint32_t maxStringLength) + { + char* result; + + _OrthancPluginDicomToJson params; + memset(¶ms, 0, sizeof(params)); + params.result = &result; + params.buffer = buffer; + params.size = size; + params.format = format; + params.flags = flags; + params.maxStringLength = maxStringLength; + + if (context->InvokeService(context, _OrthancPluginService_DicomBufferToJson, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomInstanceToJson( + OrthancPluginContext* context, + const char* instanceId, + OrthancPluginDicomToJsonFormat format, + OrthancPluginDicomToJsonFlags flags, + uint32_t maxStringLength) + { + char* result; + + _OrthancPluginDicomToJson params; + memset(¶ms, 0, sizeof(params)); + params.result = &result; + params.instanceId = instanceId; + params.format = format; + params.flags = flags; + params.maxStringLength = maxStringLength; + + if (context->InvokeService(context, _OrthancPluginService_DicomBufferToJson, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + #ifdef __cplusplus } #endif