Mercurial > hg > orthanc-stone
comparison Framework/Radiography/RadiographyScene.cpp @ 605:7a7e36c52d62
Merged am-dev into default
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 29 Apr 2019 15:24:59 +0200 |
parents | a29f9628369e 848170ca4351 |
children | 42dadae61fa9 |
comparison
equal
deleted
inserted
replaced
604:86dfde451f4c | 605:7a7e36c52d62 |
---|---|
360 layer.SetDicomFrameConverter(converter); | 360 layer.SetDicomFrameConverter(converter); |
361 layer.SetSourceImage(dicomImage); | 361 layer.SetSourceImage(dicomImage); |
362 layer.SetPreferredPhotomotricDisplayMode(preferredPhotometricDisplayMode); | 362 layer.SetPreferredPhotomotricDisplayMode(preferredPhotometricDisplayMode); |
363 | 363 |
364 return layer; | 364 return layer; |
365 } | 365 } |
366 | 366 |
367 RadiographyLayer& RadiographyScene::LoadDicomFrame(OrthancApiClient& orthanc, | 367 RadiographyLayer& RadiographyScene::LoadDicomFrame(OrthancApiClient& orthanc, |
368 const std::string& instance, | 368 const std::string& instance, |
369 unsigned int frame, | 369 unsigned int frame, |
370 bool httpCompression, | 370 bool httpCompression, |
626 | 626 |
627 return rendered.release(); | 627 return rendered.release(); |
628 } | 628 } |
629 | 629 |
630 | 630 |
631 Orthanc::Image* RadiographyScene::ExportToCreateDicomRequestAndImage(Json::Value& createDicomRequestContent, | |
632 const Json::Value& dicomTags, | |
633 const std::string& parentOrthancId, | |
634 double pixelSpacingX, | |
635 double pixelSpacingY, | |
636 bool invert, | |
637 ImageInterpolation interpolation) | |
638 { | |
639 LOG(INFO) << "Exporting RadiographyScene to DICOM"; | |
640 | |
641 std::auto_ptr<Orthanc::Image> rendered(ExportToImage(pixelSpacingX, pixelSpacingY, interpolation)); // note: we don't invert the image in the pixels data because we'll set the PhotometricDisplayMode correctly in the DICOM tags | |
642 | |
643 createDicomRequestContent["Tags"] = dicomTags; | |
644 | |
645 PhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode(); | |
646 if ((invert && photometricMode != PhotometricDisplayMode_Monochrome2) || | |
647 (!invert && photometricMode == PhotometricDisplayMode_Monochrome1)) | |
648 { | |
649 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME1"; | |
650 } | |
651 else | |
652 { | |
653 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME2"; | |
654 } | |
655 | |
656 // WARNING: The order of PixelSpacing is Y/X. We use "%0.8f" to | |
657 // avoid floating-point numbers to grow over 16 characters, | |
658 // which would be invalid according to DICOM standard | |
659 // ("dciodvfy" would complain). | |
660 char buf[32]; | |
661 sprintf(buf, "%0.8f\\%0.8f", pixelSpacingY, pixelSpacingX); | |
662 | |
663 createDicomRequestContent["Tags"]["PixelSpacing"] = buf; | |
664 | |
665 float center, width; | |
666 if (GetWindowing(center, width)) | |
667 { | |
668 createDicomRequestContent["Tags"]["WindowCenter"] = | |
669 boost::lexical_cast<std::string>(boost::math::iround(center)); | |
670 | |
671 createDicomRequestContent["Tags"]["WindowWidth"] = | |
672 boost::lexical_cast<std::string>(boost::math::iround(width)); | |
673 } | |
674 | |
675 if (!parentOrthancId.empty()) | |
676 { | |
677 createDicomRequestContent["Parent"] = parentOrthancId; | |
678 } | |
679 | |
680 return rendered.release(); | |
681 } | |
682 | |
683 | |
631 void RadiographyScene::ExportToCreateDicomRequest(Json::Value& createDicomRequestContent, | 684 void RadiographyScene::ExportToCreateDicomRequest(Json::Value& createDicomRequestContent, |
632 const Json::Value& dicomTags, | 685 const Json::Value& dicomTags, |
633 const std::string& parentOrthancId, | 686 const std::string& parentOrthancId, |
634 double pixelSpacingX, | 687 double pixelSpacingX, |
635 double pixelSpacingY, | 688 double pixelSpacingY, |
638 bool usePam) | 691 bool usePam) |
639 { | 692 { |
640 LOG(INFO) << "Exporting RadiographyScene to DICOM"; | 693 LOG(INFO) << "Exporting RadiographyScene to DICOM"; |
641 VLOG(1) << "Exporting RadiographyScene to: export to image"; | 694 VLOG(1) << "Exporting RadiographyScene to: export to image"; |
642 | 695 |
643 std::auto_ptr<Orthanc::Image> rendered(ExportToImage(pixelSpacingX, pixelSpacingY, interpolation)); // note: we don't invert the image in the pixels data because we'll set the PhotometricDisplayMode correctly in the DICOM tags | 696 std::auto_ptr<Orthanc::Image> rendered(ExportToCreateDicomRequestAndImage(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation)); |
644 | 697 |
698 // convert the image into base64 for inclusing in the createDicomRequest | |
645 std::string base64; | 699 std::string base64; |
646 | 700 |
647 { | 701 { |
648 std::string content; | 702 std::string content; |
649 | 703 |
660 } | 714 } |
661 | 715 |
662 VLOG(1) << "Exporting RadiographyScene: encoding to base64"; | 716 VLOG(1) << "Exporting RadiographyScene: encoding to base64"; |
663 Orthanc::Toolbox::EncodeBase64(base64, content); | 717 Orthanc::Toolbox::EncodeBase64(base64, content); |
664 } | 718 } |
665 | |
666 createDicomRequestContent["Tags"] = dicomTags; | |
667 | |
668 PhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode(); | |
669 if ((invert && photometricMode != PhotometricDisplayMode_Monochrome2) || | |
670 (!invert && photometricMode == PhotometricDisplayMode_Monochrome1)) | |
671 { | |
672 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME1"; | |
673 } | |
674 else | |
675 { | |
676 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME2"; | |
677 } | |
678 | |
679 // WARNING: The order of PixelSpacing is Y/X. We use "%0.8f" to | |
680 // avoid floating-point numbers to grow over 16 characters, | |
681 // which would be invalid according to DICOM standard | |
682 // ("dciodvfy" would complain). | |
683 char buf[32]; | |
684 sprintf(buf, "%0.8f\\%0.8f", pixelSpacingY, pixelSpacingX); | |
685 | |
686 createDicomRequestContent["Tags"]["PixelSpacing"] = buf; | |
687 | |
688 float center, width; | |
689 if (GetWindowing(center, width)) | |
690 { | |
691 createDicomRequestContent["Tags"]["WindowCenter"] = | |
692 boost::lexical_cast<std::string>(boost::math::iround(center)); | |
693 | |
694 createDicomRequestContent["Tags"]["WindowWidth"] = | |
695 boost::lexical_cast<std::string>(boost::math::iround(width)); | |
696 } | |
697 | |
698 | 719 |
699 // This is Data URI scheme: https://en.wikipedia.org/wiki/Data_URI_scheme | 720 // This is Data URI scheme: https://en.wikipedia.org/wiki/Data_URI_scheme |
700 createDicomRequestContent["Content"] = ("data:" + | 721 createDicomRequestContent["Content"] = ("data:" + |
701 std::string(usePam ? Orthanc::MIME_PAM : Orthanc::MIME_PNG) + | 722 std::string(usePam ? Orthanc::MIME_PAM : Orthanc::MIME_PNG) + |
702 ";base64," + base64); | 723 ";base64," + base64); |
703 | |
704 if (!parentOrthancId.empty()) | |
705 { | |
706 createDicomRequestContent["Parent"] = parentOrthancId; | |
707 } | |
708 | 724 |
709 VLOG(1) << "Exporting RadiographyScene: create-dicom request is ready"; | 725 VLOG(1) << "Exporting RadiographyScene: create-dicom request is ready"; |
710 } | 726 } |
711 | 727 |
712 | 728 |