# HG changeset patch # User Sebastien Jodogne # Date 1589380989 -7200 # Node ID 395c59208f10ca167c26cccda61dd548f230bdf6 # Parent 2434e98987ba47da7fd01e3871404f5e57826f65 new functions in SDK: OrthancPluginEncodeDicomWebJson2() and OrthancPluginEncodeDicomWebXml2() diff -r 2434e98987ba -r 395c59208f10 NEWS --- a/NEWS Tue May 12 21:05:15 2020 +0200 +++ b/NEWS Wed May 13 16:43:09 2020 +0200 @@ -21,6 +21,8 @@ ------- * New functions in the SDK: + - OrthancPluginEncodeDicomWebJson2() + - OrthancPluginEncodeDicomWebXml2() - OrthancPluginCreateDicomInstance() - OrthancPluginFreeDicomInstance() - OrthancPluginGetInstanceFramesCount() diff -r 2434e98987ba -r 395c59208f10 Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Tue May 12 21:05:15 2020 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Wed May 13 16:43:09 2020 +0200 @@ -330,9 +330,11 @@ class DicomWebBinaryFormatter : public DicomWebJsonVisitor::IBinaryFormatter { private: - OrthancPluginDicomWebBinaryCallback callback_; - DicomWebJsonVisitor::BinaryMode currentMode_; - std::string currentBulkDataUri_; + OrthancPluginDicomWebBinaryCallback oldCallback_; + OrthancPluginDicomWebBinaryCallback2 newCallback_; // New in Orthanc 1.7.0 + void* newPayload_; // New in Orthanc 1.7.0 + DicomWebJsonVisitor::BinaryMode currentMode_; + std::string currentBulkDataUri_; static void Setter(OrthancPluginDicomWebNode* node, OrthancPluginDicomWebBinaryMode mode, @@ -367,7 +369,16 @@ public: DicomWebBinaryFormatter(const _OrthancPluginEncodeDicomWeb& parameters) : - callback_(parameters.callback) + oldCallback_(parameters.callback), + newCallback_(NULL), + newPayload_(NULL) + { + } + + DicomWebBinaryFormatter(const _OrthancPluginEncodeDicomWeb2& parameters) : + oldCallback_(NULL), + newCallback_(parameters.callback), + newPayload_(parameters.payload) { } @@ -377,7 +388,8 @@ const DicomTag& tag, ValueRepresentation vr) { - if (callback_ == NULL) + if (oldCallback_ == NULL && + newCallback_ == NULL) { return DicomWebJsonVisitor::BinaryMode_InlineBinary; } @@ -398,15 +410,32 @@ currentMode_ = DicomWebJsonVisitor::BinaryMode_Ignore; - callback_(reinterpret_cast(this), - DicomWebBinaryFormatter::Setter, - static_cast(parentTags.size()), - (empty ? NULL : &groups[0]), - (empty ? NULL : &elements[0]), - (empty ? NULL : &indexes[0]), - tag.GetGroup(), - tag.GetElement(), - Plugins::Convert(vr)); + if (oldCallback_ != NULL) + { + oldCallback_(reinterpret_cast(this), + DicomWebBinaryFormatter::Setter, + static_cast(parentTags.size()), + (empty ? NULL : &groups[0]), + (empty ? NULL : &elements[0]), + (empty ? NULL : &indexes[0]), + tag.GetGroup(), + tag.GetElement(), + Plugins::Convert(vr)); + } + else + { + assert(newCallback_ != NULL); + newCallback_(reinterpret_cast(this), + DicomWebBinaryFormatter::Setter, + static_cast(parentTags.size()), + (empty ? NULL : &groups[0]), + (empty ? NULL : &elements[0]), + (empty ? NULL : &indexes[0]), + tag.GetGroup(), + tag.GetElement(), + Plugins::Convert(vr), + newPayload_); + } bulkDataUri = currentBulkDataUri_; return currentMode_; @@ -3514,6 +3543,35 @@ } + static void FormatDicomWeb(char** target, + bool isJson, + DicomWebBinaryFormatter& formatter, + const void* dicom, + size_t dicomSize) + { + DicomWebJsonVisitor visitor; + visitor.SetFormatter(formatter); + + { + ParsedDicomFile parsed(dicom, dicomSize); + parsed.Apply(visitor); + } + + std::string s; + + if (isJson) + { + s = visitor.GetResult().toStyledString(); + } + else + { + visitor.FormatXml(s); + } + + *target = CopyString(s); + } + + bool OrthancPlugins::InvokeSafeService(SharedLibrary& plugin, _OrthancPluginService service, const void* parameters) @@ -4196,27 +4254,24 @@ *reinterpret_cast(parameters); DicomWebBinaryFormatter formatter(p); - - DicomWebJsonVisitor visitor; - visitor.SetFormatter(formatter); - - { - ParsedDicomFile dicom(p.dicom, p.dicomSize); - dicom.Apply(visitor); - } - - std::string s; - - if (service == _OrthancPluginService_EncodeDicomWebJson) - { - s = visitor.GetResult().toStyledString(); - } - else - { - visitor.FormatXml(s); - } - - *p.target = CopyString(s); + + FormatDicomWeb(p.target, + (service == _OrthancPluginService_EncodeDicomWebJson), + formatter, p.dicom, p.dicomSize); + return true; + } + + case _OrthancPluginService_EncodeDicomWebJson2: + case _OrthancPluginService_EncodeDicomWebXml2: + { + const _OrthancPluginEncodeDicomWeb2& p = + *reinterpret_cast(parameters); + + DicomWebBinaryFormatter formatter(p); + + FormatDicomWeb(p.target, + (service == _OrthancPluginService_EncodeDicomWebJson2), + formatter, p.dicom, p.dicomSize); return true; } diff -r 2434e98987ba -r 395c59208f10 Plugins/Include/orthanc/OrthancCPlugin.h --- a/Plugins/Include/orthanc/OrthancCPlugin.h Tue May 12 21:05:15 2020 +0200 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Wed May 13 16:43:09 2020 +0200 @@ -437,8 +437,10 @@ _OrthancPluginService_SetMetricsValue = 31, _OrthancPluginService_EncodeDicomWebJson = 32, _OrthancPluginService_EncodeDicomWebXml = 33, - _OrthancPluginService_ChunkedHttpClient = 34, /* New in Orthanc 1.5.7 */ - _OrthancPluginService_GetTagName = 35, /* New in Orthanc 1.5.7 */ + _OrthancPluginService_ChunkedHttpClient = 34, /* New in Orthanc 1.5.7 */ + _OrthancPluginService_GetTagName = 35, /* New in Orthanc 1.5.7 */ + _OrthancPluginService_EncodeDicomWebJson2 = 36, /* New in Orthanc 1.7.0 */ + _OrthancPluginService_EncodeDicomWebXml2 = 37, /* New in Orthanc 1.7.0 */ /* Registration of callbacks */ _OrthancPluginService_RegisterRestCallback = 1000, @@ -1616,6 +1618,45 @@ /** + * @brief Callback executed to encode a binary tag in DICOMweb. + * + * Signature of a callback function that is called by Orthanc + * whenever a DICOM tag that contains a binary value must be written + * to a JSON or XML node, while a DICOMweb document is being + * generated. The value representation (VR) of the DICOM tag can be + * OB, OD, OF, OL, OW, or UN. + * + * @see OrthancPluginEncodeDicomWebJson() and OrthancPluginEncodeDicomWebXml() + * @param node The node being generated, as provided by Orthanc. + * @param setter The setter to be used to encode the content of the node. If + * the setter is not called, the binary tag is not written to the output document. + * @param levelDepth The depth of the node in the DICOM hierarchy of sequences. + * This parameter gives the number of elements in the "levelTagGroup", + * "levelTagElement", and "levelIndex" arrays. + * @param levelTagGroup The group of the parent DICOM tags in the hierarchy. + * @param levelTagElement The element of the parent DICOM tags in the hierarchy. + * @param levelIndex The index of the node in the parent sequences of the hierarchy. + * @param tagGroup The group of the DICOM tag of interest. + * @param tagElement The element of the DICOM tag of interest. + * @param vr The value representation of the binary DICOM node. + * @param payload The user payload. + * @ingroup Callbacks + **/ + typedef void (*OrthancPluginDicomWebBinaryCallback2) ( + OrthancPluginDicomWebNode* node, + OrthancPluginDicomWebSetBinaryNode setter, + uint32_t levelDepth, + const uint16_t* levelTagGroup, + const uint16_t* levelTagElement, + const uint32_t* levelIndex, + uint16_t tagGroup, + uint16_t tagElement, + OrthancPluginValueRepresentation vr, + void* payload); + + + + /** * @brief Data structure that contains information about the Orthanc core. **/ typedef struct _OrthancPluginContext_t @@ -6798,6 +6839,7 @@ * @see OrthancPluginCreateDicom() * @return The NULL value in case of error, or the JSON document. This string must * be freed by OrthancPluginFreeString(). + * @deprecated OrthancPluginEncodeDicomWebJson2() * @ingroup Toolbox **/ ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebJson( @@ -6839,6 +6881,7 @@ * @return The NULL value in case of error, or the JSON document. This string must * be freed by OrthancPluginFreeString(). * @see OrthancPluginCreateDicom() + * @deprecated OrthancPluginEncodeDicomWebXml2() * @ingroup Toolbox **/ ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebXml( @@ -6868,6 +6911,105 @@ + typedef struct + { + char** target; + const void* dicom; + uint32_t dicomSize; + OrthancPluginDicomWebBinaryCallback2 callback; + void* payload; + } _OrthancPluginEncodeDicomWeb2; + + /** + * @brief Convert a DICOM instance to DICOMweb JSON. + * + * This function converts a memory buffer containing a DICOM instance, + * into its DICOMweb JSON representation. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param dicom Pointer to the DICOM instance. + * @param dicomSize Size of the DICOM instance. + * @param callback Callback to set the value of the binary tags. + * @param payload User payload. + * @see OrthancPluginCreateDicom() + * @return The NULL value in case of error, or the JSON document. This string must + * be freed by OrthancPluginFreeString(). + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebJson2( + OrthancPluginContext* context, + const void* dicom, + uint32_t dicomSize, + OrthancPluginDicomWebBinaryCallback2 callback, + void* payload) + { + char* target = NULL; + + _OrthancPluginEncodeDicomWeb2 params; + params.target = ⌖ + params.dicom = dicom; + params.dicomSize = dicomSize; + params.callback = callback; + params.payload = payload; + + if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebJson2, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return target; + } + } + + + /** + * @brief Convert a DICOM instance to DICOMweb XML. + * + * This function converts a memory buffer containing a DICOM instance, + * into its DICOMweb XML representation. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param dicom Pointer to the DICOM instance. + * @param dicomSize Size of the DICOM instance. + * @param callback Callback to set the value of the binary tags. + * @param payload User payload. + * @return The NULL value in case of error, or the JSON document. This string must + * be freed by OrthancPluginFreeString(). + * @see OrthancPluginCreateDicom() + * @deprecated OrthancPluginEncodeDicomWebXml2() + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebXml2( + OrthancPluginContext* context, + const void* dicom, + uint32_t dicomSize, + OrthancPluginDicomWebBinaryCallback2 callback, + void* payload) + { + char* target = NULL; + + _OrthancPluginEncodeDicomWeb2 params; + params.target = ⌖ + params.dicom = dicom; + params.dicomSize = dicomSize; + params.callback = callback; + params.payload = payload; + + if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebXml2, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return target; + } + } + + + /** * @brief Callback executed when a HTTP header is received during a chunked transfer. *