Mercurial > hg > orthanc
comparison OrthancServer/FromDcmtkBridge.cpp @ 1737:ec66a16aa398
removal of DicomStringValue and DicomNullValue
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 22 Oct 2015 07:52:24 +0200 |
parents | b953c6eef28d |
children | 15a788a63846 |
comparison
equal
deleted
inserted
replaced
1736:b953c6eef28d | 1737:ec66a16aa398 |
---|---|
45 #include "../Core/Logging.h" | 45 #include "../Core/Logging.h" |
46 #include "../Core/Toolbox.h" | 46 #include "../Core/Toolbox.h" |
47 #include "../Core/OrthancException.h" | 47 #include "../Core/OrthancException.h" |
48 #include "../Core/Images/PngWriter.h" | 48 #include "../Core/Images/PngWriter.h" |
49 #include "../Core/Uuid.h" | 49 #include "../Core/Uuid.h" |
50 #include "../Core/DicomFormat/DicomString.h" | |
51 #include "../Core/DicomFormat/DicomNullValue.h" | |
52 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h" | 50 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h" |
53 | 51 |
54 #include <list> | 52 #include <list> |
55 #include <limits> | 53 #include <limits> |
56 | 54 |
378 char *c; | 376 char *c; |
379 if (element.getString(c).good()) | 377 if (element.getString(c).good()) |
380 { | 378 { |
381 if (c == NULL) // This case corresponds to the empty string | 379 if (c == NULL) // This case corresponds to the empty string |
382 { | 380 { |
383 return new DicomString(""); | 381 return new DicomValue("", false); |
384 } | 382 } |
385 else | 383 else |
386 { | 384 { |
387 std::string s(c); | 385 std::string s(c); |
388 std::string utf8 = Toolbox::ConvertToUtf8(s, encoding); | 386 std::string utf8 = Toolbox::ConvertToUtf8(s, encoding); |
389 return new DicomString(utf8); | 387 return new DicomValue(utf8, false); |
390 } | 388 } |
391 } | 389 } |
392 else | 390 else |
393 { | 391 { |
394 return new DicomNullValue; | 392 return new DicomValue; |
395 } | 393 } |
396 } | 394 } |
397 | 395 |
398 try | 396 try |
399 { | 397 { |
407 | 405 |
408 case EVR_OB: // other byte | 406 case EVR_OB: // other byte |
409 case EVR_OF: // other float | 407 case EVR_OF: // other float |
410 case EVR_OW: // other word | 408 case EVR_OW: // other word |
411 case EVR_UN: // unknown value representation | 409 case EVR_UN: // unknown value representation |
412 return new DicomNullValue; | 410 return new DicomValue; |
413 | 411 |
414 /** | 412 /** |
415 * String types, should never happen at this point because of | 413 * String types, should never happen at this point because of |
416 * "element.isaString()". | 414 * "element.isaString()". |
417 **/ | 415 **/ |
429 case EVR_ST: // short text | 427 case EVR_ST: // short text |
430 case EVR_LT: // long text | 428 case EVR_LT: // long text |
431 case EVR_UT: // unlimited text | 429 case EVR_UT: // unlimited text |
432 case EVR_PN: // person name | 430 case EVR_PN: // person name |
433 case EVR_UI: // unique identifier | 431 case EVR_UI: // unique identifier |
434 return new DicomNullValue; | 432 return new DicomValue; |
435 | 433 |
436 | 434 |
437 /** | 435 /** |
438 * Numberic types | 436 * Numberic types |
439 **/ | 437 **/ |
440 | 438 |
441 case EVR_SL: // signed long | 439 case EVR_SL: // signed long |
442 { | 440 { |
443 Sint32 f; | 441 Sint32 f; |
444 if (dynamic_cast<DcmSignedLong&>(element).getSint32(f).good()) | 442 if (dynamic_cast<DcmSignedLong&>(element).getSint32(f).good()) |
445 return new DicomString(boost::lexical_cast<std::string>(f)); | 443 return new DicomValue(boost::lexical_cast<std::string>(f), false); |
446 else | 444 else |
447 return new DicomNullValue; | 445 return new DicomValue; |
448 } | 446 } |
449 | 447 |
450 case EVR_SS: // signed short | 448 case EVR_SS: // signed short |
451 { | 449 { |
452 Sint16 f; | 450 Sint16 f; |
453 if (dynamic_cast<DcmSignedShort&>(element).getSint16(f).good()) | 451 if (dynamic_cast<DcmSignedShort&>(element).getSint16(f).good()) |
454 return new DicomString(boost::lexical_cast<std::string>(f)); | 452 return new DicomValue(boost::lexical_cast<std::string>(f), false); |
455 else | 453 else |
456 return new DicomNullValue; | 454 return new DicomValue; |
457 } | 455 } |
458 | 456 |
459 case EVR_UL: // unsigned long | 457 case EVR_UL: // unsigned long |
460 { | 458 { |
461 Uint32 f; | 459 Uint32 f; |
462 if (dynamic_cast<DcmUnsignedLong&>(element).getUint32(f).good()) | 460 if (dynamic_cast<DcmUnsignedLong&>(element).getUint32(f).good()) |
463 return new DicomString(boost::lexical_cast<std::string>(f)); | 461 return new DicomValue(boost::lexical_cast<std::string>(f), false); |
464 else | 462 else |
465 return new DicomNullValue; | 463 return new DicomValue; |
466 } | 464 } |
467 | 465 |
468 case EVR_US: // unsigned short | 466 case EVR_US: // unsigned short |
469 { | 467 { |
470 Uint16 f; | 468 Uint16 f; |
471 if (dynamic_cast<DcmUnsignedShort&>(element).getUint16(f).good()) | 469 if (dynamic_cast<DcmUnsignedShort&>(element).getUint16(f).good()) |
472 return new DicomString(boost::lexical_cast<std::string>(f)); | 470 return new DicomValue(boost::lexical_cast<std::string>(f), false); |
473 else | 471 else |
474 return new DicomNullValue; | 472 return new DicomValue; |
475 } | 473 } |
476 | 474 |
477 case EVR_FL: // float single-precision | 475 case EVR_FL: // float single-precision |
478 { | 476 { |
479 Float32 f; | 477 Float32 f; |
480 if (dynamic_cast<DcmFloatingPointSingle&>(element).getFloat32(f).good()) | 478 if (dynamic_cast<DcmFloatingPointSingle&>(element).getFloat32(f).good()) |
481 return new DicomString(boost::lexical_cast<std::string>(f)); | 479 return new DicomValue(boost::lexical_cast<std::string>(f), false); |
482 else | 480 else |
483 return new DicomNullValue; | 481 return new DicomValue; |
484 } | 482 } |
485 | 483 |
486 case EVR_FD: // float double-precision | 484 case EVR_FD: // float double-precision |
487 { | 485 { |
488 Float64 f; | 486 Float64 f; |
489 if (dynamic_cast<DcmFloatingPointDouble&>(element).getFloat64(f).good()) | 487 if (dynamic_cast<DcmFloatingPointDouble&>(element).getFloat64(f).good()) |
490 return new DicomString(boost::lexical_cast<std::string>(f)); | 488 return new DicomValue(boost::lexical_cast<std::string>(f), false); |
491 else | 489 else |
492 return new DicomNullValue; | 490 return new DicomValue; |
493 } | 491 } |
494 | 492 |
495 | 493 |
496 /** | 494 /** |
497 * Attribute tag. | 495 * Attribute tag. |
501 { | 499 { |
502 DcmTagKey tag; | 500 DcmTagKey tag; |
503 if (dynamic_cast<DcmAttributeTag&>(element).getTagVal(tag, 0).good()) | 501 if (dynamic_cast<DcmAttributeTag&>(element).getTagVal(tag, 0).good()) |
504 { | 502 { |
505 DicomTag t(tag.getGroup(), tag.getElement()); | 503 DicomTag t(tag.getGroup(), tag.getElement()); |
506 return new DicomString(t.Format()); | 504 return new DicomValue(t.Format(), false); |
507 } | 505 } |
508 else | 506 else |
509 { | 507 { |
510 return new DicomNullValue; | 508 return new DicomValue; |
511 } | 509 } |
512 } | 510 } |
513 | 511 |
514 | 512 |
515 /** | 513 /** |
516 * Sequence types, should never occur at this point because of | 514 * Sequence types, should never occur at this point because of |
517 * "element.isLeaf()". | 515 * "element.isLeaf()". |
518 **/ | 516 **/ |
519 | 517 |
520 case EVR_SQ: // sequence of items | 518 case EVR_SQ: // sequence of items |
521 return new DicomNullValue; | 519 return new DicomValue; |
522 | 520 |
523 | 521 |
524 /** | 522 /** |
525 * Internal to DCMTK. | 523 * Internal to DCMTK. |
526 **/ | 524 **/ |
540 case EVR_pixelItem: // used internally for pixel items in a compressed image | 538 case EVR_pixelItem: // used internally for pixel items in a compressed image |
541 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) | 539 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) |
542 case EVR_PixelData: // used internally for uncompressed pixeld data | 540 case EVR_PixelData: // used internally for uncompressed pixeld data |
543 case EVR_OverlayData: // used internally for overlay data | 541 case EVR_OverlayData: // used internally for overlay data |
544 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR | 542 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR |
545 return new DicomNullValue; | 543 return new DicomValue; |
546 | 544 |
547 | 545 |
548 /** | 546 /** |
549 * Default case. | 547 * Default case. |
550 **/ | 548 **/ |
551 | 549 |
552 default: | 550 default: |
553 return new DicomNullValue; | 551 return new DicomValue; |
554 } | 552 } |
555 } | 553 } |
556 catch (boost::bad_lexical_cast) | 554 catch (boost::bad_lexical_cast) |
557 { | 555 { |
558 return new DicomNullValue; | 556 return new DicomValue; |
559 } | 557 } |
560 catch (std::bad_cast) | 558 catch (std::bad_cast) |
561 { | 559 { |
562 return new DicomNullValue; | 560 return new DicomValue; |
563 } | 561 } |
564 } | 562 } |
565 | 563 |
566 | 564 |
567 static Json::Value& PrepareNode(Json::Value& parent, | 565 static Json::Value& PrepareNode(Json::Value& parent, |
623 static void LeafValueToJson(Json::Value& target, | 621 static void LeafValueToJson(Json::Value& target, |
624 const DicomValue& value, | 622 const DicomValue& value, |
625 DicomToJsonFormat format, | 623 DicomToJsonFormat format, |
626 unsigned int maxStringLength) | 624 unsigned int maxStringLength) |
627 { | 625 { |
628 std::string content = value.AsString(); | |
629 | |
630 switch (format) | 626 switch (format) |
631 { | 627 { |
632 case DicomToJsonFormat_Short: | 628 case DicomToJsonFormat_Short: |
633 case DicomToJsonFormat_Simple: | 629 case DicomToJsonFormat_Simple: |
634 { | 630 { |
635 assert(target.type() == Json::nullValue); | 631 assert(target.type() == Json::nullValue); |
636 | 632 |
637 if (!value.IsNull() && | 633 if (!value.IsNull() && |
638 (maxStringLength == 0 || | 634 (maxStringLength == 0 || |
639 content.size() <= maxStringLength)) | 635 value.GetContent().size() <= maxStringLength)) |
640 { | 636 { |
641 target = content; | 637 target = value.GetContent(); |
642 } | 638 } |
643 | 639 |
644 break; | 640 break; |
645 } | 641 } |
646 | 642 |
654 target["Value"] = Json::nullValue; | 650 target["Value"] = Json::nullValue; |
655 } | 651 } |
656 else | 652 else |
657 { | 653 { |
658 if (maxStringLength == 0 || | 654 if (maxStringLength == 0 || |
659 content.size() <= maxStringLength) | 655 value.GetContent().size() <= maxStringLength) |
660 { | 656 { |
661 target["Type"] = "String"; | 657 target["Type"] = "String"; |
662 target["Value"] = content; | 658 target["Value"] = value.GetContent(); |
663 } | 659 } |
664 else | 660 else |
665 { | 661 { |
666 target["Type"] = "TooLong"; | 662 target["Type"] = "TooLong"; |
667 target["Value"] = Json::nullValue; | 663 target["Value"] = Json::nullValue; |
864 DcmTag tmp(tag.GetGroup(), tag.GetElement()); | 860 DcmTag tmp(tag.GetGroup(), tag.GetElement()); |
865 return tmp.isUnknownVR(); | 861 return tmp.isUnknownVR(); |
866 } | 862 } |
867 | 863 |
868 | 864 |
869 void FromDcmtkBridge::Print(FILE* fp, const DicomMap& m) | |
870 { | |
871 for (DicomMap::Map::const_iterator | |
872 it = m.map_.begin(); it != m.map_.end(); ++it) | |
873 { | |
874 DicomTag t = it->first; | |
875 std::string s = it->second->AsString(); | |
876 fprintf(fp, "0x%04x 0x%04x (%s) [%s]\n", t.GetGroup(), t.GetElement(), GetName(t).c_str(), s.c_str()); | |
877 } | |
878 } | |
879 | |
880 | |
881 void FromDcmtkBridge::ToJson(Json::Value& result, | 865 void FromDcmtkBridge::ToJson(Json::Value& result, |
882 const DicomMap& values, | 866 const DicomMap& values, |
883 bool simplify) | 867 bool simplify) |
884 { | 868 { |
885 if (result.type() != Json::objectValue) | 869 if (result.type() != Json::objectValue) |
892 for (DicomMap::Map::const_iterator | 876 for (DicomMap::Map::const_iterator |
893 it = values.map_.begin(); it != values.map_.end(); ++it) | 877 it = values.map_.begin(); it != values.map_.end(); ++it) |
894 { | 878 { |
895 if (simplify) | 879 if (simplify) |
896 { | 880 { |
897 result[GetName(it->first)] = it->second->AsString(); | 881 if (it->second->IsNull()) |
882 { | |
883 result[GetName(it->first)] = Json::nullValue; | |
884 } | |
885 else | |
886 { | |
887 // TODO IsBinary | |
888 result[GetName(it->first)] = it->second->GetContent(); | |
889 } | |
898 } | 890 } |
899 else | 891 else |
900 { | 892 { |
901 Json::Value value = Json::objectValue; | 893 Json::Value value = Json::objectValue; |
902 | 894 |
907 value["Type"] = "Null"; | 899 value["Type"] = "Null"; |
908 value["Value"] = Json::nullValue; | 900 value["Value"] = Json::nullValue; |
909 } | 901 } |
910 else | 902 else |
911 { | 903 { |
904 // TODO IsBinary | |
912 value["Type"] = "String"; | 905 value["Type"] = "String"; |
913 value["Value"] = it->second->AsString(); | 906 value["Value"] = it->second->GetContent(); |
914 } | 907 } |
915 | 908 |
916 result[it->first.Format()] = value; | 909 result[it->first.Format()] = value; |
917 } | 910 } |
918 } | 911 } |