comparison Plugins/Engine/OrthancPlugins.cpp @ 3924:395c59208f10 transcoding

new functions in SDK: OrthancPluginEncodeDicomWebJson2() and OrthancPluginEncodeDicomWebXml2()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 13 May 2020 16:43:09 +0200
parents 6f11b3233a06
children dd112d2b83f0
comparison
equal deleted inserted replaced
3923:2434e98987ba 3924:395c59208f10
328 328
329 329
330 class DicomWebBinaryFormatter : public DicomWebJsonVisitor::IBinaryFormatter 330 class DicomWebBinaryFormatter : public DicomWebJsonVisitor::IBinaryFormatter
331 { 331 {
332 private: 332 private:
333 OrthancPluginDicomWebBinaryCallback callback_; 333 OrthancPluginDicomWebBinaryCallback oldCallback_;
334 DicomWebJsonVisitor::BinaryMode currentMode_; 334 OrthancPluginDicomWebBinaryCallback2 newCallback_; // New in Orthanc 1.7.0
335 std::string currentBulkDataUri_; 335 void* newPayload_; // New in Orthanc 1.7.0
336 DicomWebJsonVisitor::BinaryMode currentMode_;
337 std::string currentBulkDataUri_;
336 338
337 static void Setter(OrthancPluginDicomWebNode* node, 339 static void Setter(OrthancPluginDicomWebNode* node,
338 OrthancPluginDicomWebBinaryMode mode, 340 OrthancPluginDicomWebBinaryMode mode,
339 const char* bulkDataUri) 341 const char* bulkDataUri)
340 { 342 {
365 } 367 }
366 } 368 }
367 369
368 public: 370 public:
369 DicomWebBinaryFormatter(const _OrthancPluginEncodeDicomWeb& parameters) : 371 DicomWebBinaryFormatter(const _OrthancPluginEncodeDicomWeb& parameters) :
370 callback_(parameters.callback) 372 oldCallback_(parameters.callback),
373 newCallback_(NULL),
374 newPayload_(NULL)
375 {
376 }
377
378 DicomWebBinaryFormatter(const _OrthancPluginEncodeDicomWeb2& parameters) :
379 oldCallback_(NULL),
380 newCallback_(parameters.callback),
381 newPayload_(parameters.payload)
371 { 382 {
372 } 383 }
373 384
374 virtual DicomWebJsonVisitor::BinaryMode Format(std::string& bulkDataUri, 385 virtual DicomWebJsonVisitor::BinaryMode Format(std::string& bulkDataUri,
375 const std::vector<DicomTag>& parentTags, 386 const std::vector<DicomTag>& parentTags,
376 const std::vector<size_t>& parentIndexes, 387 const std::vector<size_t>& parentIndexes,
377 const DicomTag& tag, 388 const DicomTag& tag,
378 ValueRepresentation vr) 389 ValueRepresentation vr)
379 { 390 {
380 if (callback_ == NULL) 391 if (oldCallback_ == NULL &&
392 newCallback_ == NULL)
381 { 393 {
382 return DicomWebJsonVisitor::BinaryMode_InlineBinary; 394 return DicomWebJsonVisitor::BinaryMode_InlineBinary;
383 } 395 }
384 else 396 else
385 { 397 {
396 } 408 }
397 bool empty = parentTags.empty(); 409 bool empty = parentTags.empty();
398 410
399 currentMode_ = DicomWebJsonVisitor::BinaryMode_Ignore; 411 currentMode_ = DicomWebJsonVisitor::BinaryMode_Ignore;
400 412
401 callback_(reinterpret_cast<OrthancPluginDicomWebNode*>(this), 413 if (oldCallback_ != NULL)
402 DicomWebBinaryFormatter::Setter, 414 {
403 static_cast<uint32_t>(parentTags.size()), 415 oldCallback_(reinterpret_cast<OrthancPluginDicomWebNode*>(this),
404 (empty ? NULL : &groups[0]), 416 DicomWebBinaryFormatter::Setter,
405 (empty ? NULL : &elements[0]), 417 static_cast<uint32_t>(parentTags.size()),
406 (empty ? NULL : &indexes[0]), 418 (empty ? NULL : &groups[0]),
407 tag.GetGroup(), 419 (empty ? NULL : &elements[0]),
408 tag.GetElement(), 420 (empty ? NULL : &indexes[0]),
409 Plugins::Convert(vr)); 421 tag.GetGroup(),
422 tag.GetElement(),
423 Plugins::Convert(vr));
424 }
425 else
426 {
427 assert(newCallback_ != NULL);
428 newCallback_(reinterpret_cast<OrthancPluginDicomWebNode*>(this),
429 DicomWebBinaryFormatter::Setter,
430 static_cast<uint32_t>(parentTags.size()),
431 (empty ? NULL : &groups[0]),
432 (empty ? NULL : &elements[0]),
433 (empty ? NULL : &indexes[0]),
434 tag.GetGroup(),
435 tag.GetElement(),
436 Plugins::Convert(vr),
437 newPayload_);
438 }
410 439
411 bulkDataUri = currentBulkDataUri_; 440 bulkDataUri = currentBulkDataUri_;
412 return currentMode_; 441 return currentMode_;
413 } 442 }
414 } 443 }
3512 p.target->maxMultiplicity = (entry->getVMMax() == DcmVariableVM ? 0 : static_cast<uint32_t>(entry->getVMMax())); 3541 p.target->maxMultiplicity = (entry->getVMMax() == DcmVariableVM ? 0 : static_cast<uint32_t>(entry->getVMMax()));
3513 } 3542 }
3514 } 3543 }
3515 3544
3516 3545
3546 static void FormatDicomWeb(char** target,
3547 bool isJson,
3548 DicomWebBinaryFormatter& formatter,
3549 const void* dicom,
3550 size_t dicomSize)
3551 {
3552 DicomWebJsonVisitor visitor;
3553 visitor.SetFormatter(formatter);
3554
3555 {
3556 ParsedDicomFile parsed(dicom, dicomSize);
3557 parsed.Apply(visitor);
3558 }
3559
3560 std::string s;
3561
3562 if (isJson)
3563 {
3564 s = visitor.GetResult().toStyledString();
3565 }
3566 else
3567 {
3568 visitor.FormatXml(s);
3569 }
3570
3571 *target = CopyString(s);
3572 }
3573
3574
3517 bool OrthancPlugins::InvokeSafeService(SharedLibrary& plugin, 3575 bool OrthancPlugins::InvokeSafeService(SharedLibrary& plugin,
3518 _OrthancPluginService service, 3576 _OrthancPluginService service,
3519 const void* parameters) 3577 const void* parameters)
3520 { 3578 {
3521 // Services that can be run without mutual exclusion 3579 // Services that can be run without mutual exclusion
4194 { 4252 {
4195 const _OrthancPluginEncodeDicomWeb& p = 4253 const _OrthancPluginEncodeDicomWeb& p =
4196 *reinterpret_cast<const _OrthancPluginEncodeDicomWeb*>(parameters); 4254 *reinterpret_cast<const _OrthancPluginEncodeDicomWeb*>(parameters);
4197 4255
4198 DicomWebBinaryFormatter formatter(p); 4256 DicomWebBinaryFormatter formatter(p);
4199 4257
4200 DicomWebJsonVisitor visitor; 4258 FormatDicomWeb(p.target,
4201 visitor.SetFormatter(formatter); 4259 (service == _OrthancPluginService_EncodeDicomWebJson),
4202 4260 formatter, p.dicom, p.dicomSize);
4203 { 4261 return true;
4204 ParsedDicomFile dicom(p.dicom, p.dicomSize); 4262 }
4205 dicom.Apply(visitor); 4263
4206 } 4264 case _OrthancPluginService_EncodeDicomWebJson2:
4207 4265 case _OrthancPluginService_EncodeDicomWebXml2:
4208 std::string s; 4266 {
4209 4267 const _OrthancPluginEncodeDicomWeb2& p =
4210 if (service == _OrthancPluginService_EncodeDicomWebJson) 4268 *reinterpret_cast<const _OrthancPluginEncodeDicomWeb2*>(parameters);
4211 { 4269
4212 s = visitor.GetResult().toStyledString(); 4270 DicomWebBinaryFormatter formatter(p);
4213 } 4271
4214 else 4272 FormatDicomWeb(p.target,
4215 { 4273 (service == _OrthancPluginService_EncodeDicomWebJson2),
4216 visitor.FormatXml(s); 4274 formatter, p.dicom, p.dicomSize);
4217 }
4218
4219 *p.target = CopyString(s);
4220 return true; 4275 return true;
4221 } 4276 }
4222 4277
4223 case _OrthancPluginService_GetTagName: 4278 case _OrthancPluginService_GetTagName:
4224 GetTagName(parameters); 4279 GetTagName(parameters);