comparison Plugins/Engine/OrthancPlugins.cpp @ 3205:6c86d4d407da

new in plugin sdk: OrthancPluginEncodeDicomWebJson() and OrthancPluginEncodeDicomWebXml()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 06 Feb 2019 18:01:43 +0100
parents fca730c267d7
children f6374c36a671
comparison
equal deleted inserted replaced
3204:8792867b739a 3205:6c86d4d407da
45 45
46 #include "../../Core/ChunkedBuffer.h" 46 #include "../../Core/ChunkedBuffer.h"
47 #include "../../Core/Compression/GzipCompressor.h" 47 #include "../../Core/Compression/GzipCompressor.h"
48 #include "../../Core/Compression/ZlibCompressor.h" 48 #include "../../Core/Compression/ZlibCompressor.h"
49 #include "../../Core/DicomFormat/DicomArray.h" 49 #include "../../Core/DicomFormat/DicomArray.h"
50 #include "../../Core/DicomParsing/DicomWebJsonVisitor.h"
50 #include "../../Core/DicomParsing/FromDcmtkBridge.h" 51 #include "../../Core/DicomParsing/FromDcmtkBridge.h"
51 #include "../../Core/DicomParsing/Internals/DicomImageDecoder.h" 52 #include "../../Core/DicomParsing/Internals/DicomImageDecoder.h"
52 #include "../../Core/DicomParsing/ToDcmtkBridge.h" 53 #include "../../Core/DicomParsing/ToDcmtkBridge.h"
53 #include "../../Core/HttpServer/HttpToolbox.h" 54 #include "../../Core/HttpServer/HttpToolbox.h"
54 #include "../../Core/Images/Image.h" 55 #include "../../Core/Images/Image.h"
309 310
310 const WebServiceParameters& GetPeerParameters(size_t i) const 311 const WebServiceParameters& GetPeerParameters(size_t i) const
311 { 312 {
312 CheckIndex(i); 313 CheckIndex(i);
313 return parameters_[i]; 314 return parameters_[i];
315 }
316 };
317
318
319 class DicomWebBinaryFormatter : public DicomWebJsonVisitor::IBinaryFormatter
320 {
321 private:
322 OrthancPluginDicomWebBinaryCallback callback_;
323 DicomWebJsonVisitor::BinaryMode currentMode_;
324 std::string currentBulkDataUri_;
325
326 static void Setter(OrthancPluginDicomWebNode* node,
327 OrthancPluginDicomWebBinaryMode mode,
328 const char* bulkDataUri)
329 {
330 DicomWebBinaryFormatter& that = *reinterpret_cast<DicomWebBinaryFormatter*>(node);
331
332 switch (mode)
333 {
334 case OrthancPluginDicomWebBinaryMode_Ignore:
335 that.currentMode_ = DicomWebJsonVisitor::BinaryMode_Ignore;
336 break;
337
338 case OrthancPluginDicomWebBinaryMode_InlineBinary:
339 that.currentMode_ = DicomWebJsonVisitor::BinaryMode_InlineBinary;
340 break;
341
342 case OrthancPluginDicomWebBinaryMode_BulkDataUri:
343 if (bulkDataUri == NULL)
344 {
345 throw OrthancException(ErrorCode_NullPointer);
346 }
347
348 that.currentBulkDataUri_ = bulkDataUri;
349 that.currentMode_ = DicomWebJsonVisitor::BinaryMode_BulkDataUri;
350 break;
351
352 default:
353 throw OrthancException(ErrorCode_ParameterOutOfRange);
354 }
355 }
356
357 public:
358 DicomWebBinaryFormatter(const _OrthancPluginEncodeDicomWeb& parameters) :
359 callback_(parameters.callback)
360 {
361 }
362
363 virtual DicomWebJsonVisitor::BinaryMode Format(std::string& bulkDataUri,
364 const std::vector<DicomTag>& parentTags,
365 const std::vector<size_t>& parentIndexes,
366 const DicomTag& tag,
367 ValueRepresentation vr)
368 {
369 if (callback_ == NULL)
370 {
371 return DicomWebJsonVisitor::BinaryMode_InlineBinary;
372 }
373 else
374 {
375 assert(parentTags.size() == parentIndexes.size());
376 std::vector<uint16_t> groups(parentTags.size());
377 std::vector<uint16_t> elements(parentTags.size());
378 std::vector<uint32_t> indexes(parentTags.size());
379
380 for (size_t i = 0; i < parentTags.size(); i++)
381 {
382 groups[i] = parentTags[i].GetGroup();
383 elements[i] = parentTags[i].GetElement();
384 indexes[i] = static_cast<uint32_t>(parentIndexes[i]);
385 }
386 bool empty = parentTags.empty();
387
388 currentMode_ = DicomWebJsonVisitor::BinaryMode_Ignore;
389
390 callback_(reinterpret_cast<OrthancPluginDicomWebNode*>(this),
391 DicomWebBinaryFormatter::Setter,
392 static_cast<uint32_t>(parentTags.size()),
393 (empty ? NULL : &groups[0]),
394 (empty ? NULL : &elements[0]),
395 (empty ? NULL : &indexes[0]),
396 tag.GetGroup(),
397 tag.GetElement(),
398 Plugins::Convert(vr));
399
400 bulkDataUri = currentBulkDataUri_;
401 return currentMode_;
402 }
314 } 403 }
315 }; 404 };
316 } 405 }
317 406
318 407
3138 } 3227 }
3139 3228
3140 return true; 3229 return true;
3141 } 3230 }
3142 3231
3232 case _OrthancPluginService_EncodeDicomWebJson:
3233 case _OrthancPluginService_EncodeDicomWebXml:
3234 {
3235 const _OrthancPluginEncodeDicomWeb& p =
3236 *reinterpret_cast<const _OrthancPluginEncodeDicomWeb*>(parameters);
3237
3238 DicomWebBinaryFormatter formatter(p);
3239
3240 DicomWebJsonVisitor visitor;
3241 visitor.SetFormatter(formatter);
3242
3243 {
3244 ParsedDicomFile dicom(p.dicom, p.dicomSize);
3245 dicom.Apply(visitor);
3246 }
3247
3248 std::string s;
3249
3250 if (service == _OrthancPluginService_EncodeDicomWebJson)
3251 {
3252 s = visitor.GetResult().toStyledString();
3253 }
3254 else
3255 {
3256 visitor.FormatXml(s);
3257 }
3258
3259 *p.target = CopyString(s);
3260 return true;
3261 }
3262
3143 default: 3263 default:
3144 return false; 3264 return false;
3145 } 3265 }
3146 } 3266 }
3147 3267