comparison Framework/Radiography/RadiographyScene.cpp @ 587:848170ca4351 am-dev

more export functions
author Alain Mazy <alain@mazy.be>
date Tue, 23 Apr 2019 10:15:54 +0200
parents 92305ee35b1c
children 7a7e36c52d62
comparison
equal deleted inserted replaced
570:e77cbe4bb4c8 587:848170ca4351
347 layer.SetDicomFrameConverter(converter); 347 layer.SetDicomFrameConverter(converter);
348 layer.SetSourceImage(dicomImage); 348 layer.SetSourceImage(dicomImage);
349 layer.SetPreferredPhotomotricDisplayMode(preferredPhotometricDisplayMode); 349 layer.SetPreferredPhotomotricDisplayMode(preferredPhotometricDisplayMode);
350 350
351 return layer; 351 return layer;
352 } 352 }
353 353
354 RadiographyLayer& RadiographyScene::LoadDicomFrame(OrthancApiClient& orthanc, 354 RadiographyLayer& RadiographyScene::LoadDicomFrame(OrthancApiClient& orthanc,
355 const std::string& instance, 355 const std::string& instance,
356 unsigned int frame, 356 unsigned int frame,
357 bool httpCompression, 357 bool httpCompression,
613 613
614 return rendered.release(); 614 return rendered.release();
615 } 615 }
616 616
617 617
618 Orthanc::Image* RadiographyScene::ExportToCreateDicomRequestAndImage(Json::Value& createDicomRequestContent,
619 const Json::Value& dicomTags,
620 const std::string& parentOrthancId,
621 double pixelSpacingX,
622 double pixelSpacingY,
623 bool invert,
624 ImageInterpolation interpolation)
625 {
626 LOG(INFO) << "Exporting RadiographyScene to DICOM";
627
628 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
629
630 createDicomRequestContent["Tags"] = dicomTags;
631
632 PhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode();
633 if ((invert && photometricMode != PhotometricDisplayMode_Monochrome2) ||
634 (!invert && photometricMode == PhotometricDisplayMode_Monochrome1))
635 {
636 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME1";
637 }
638 else
639 {
640 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME2";
641 }
642
643 // WARNING: The order of PixelSpacing is Y/X. We use "%0.8f" to
644 // avoid floating-point numbers to grow over 16 characters,
645 // which would be invalid according to DICOM standard
646 // ("dciodvfy" would complain).
647 char buf[32];
648 sprintf(buf, "%0.8f\\%0.8f", pixelSpacingY, pixelSpacingX);
649
650 createDicomRequestContent["Tags"]["PixelSpacing"] = buf;
651
652 float center, width;
653 if (GetWindowing(center, width))
654 {
655 createDicomRequestContent["Tags"]["WindowCenter"] =
656 boost::lexical_cast<std::string>(boost::math::iround(center));
657
658 createDicomRequestContent["Tags"]["WindowWidth"] =
659 boost::lexical_cast<std::string>(boost::math::iround(width));
660 }
661
662 if (!parentOrthancId.empty())
663 {
664 createDicomRequestContent["Parent"] = parentOrthancId;
665 }
666
667 return rendered.release();
668 }
669
670
618 void RadiographyScene::ExportToCreateDicomRequest(Json::Value& createDicomRequestContent, 671 void RadiographyScene::ExportToCreateDicomRequest(Json::Value& createDicomRequestContent,
619 const Json::Value& dicomTags, 672 const Json::Value& dicomTags,
620 const std::string& parentOrthancId, 673 const std::string& parentOrthancId,
621 double pixelSpacingX, 674 double pixelSpacingX,
622 double pixelSpacingY, 675 double pixelSpacingY,
625 bool usePam) 678 bool usePam)
626 { 679 {
627 LOG(INFO) << "Exporting RadiographyScene to DICOM"; 680 LOG(INFO) << "Exporting RadiographyScene to DICOM";
628 VLOG(1) << "Exporting RadiographyScene to: export to image"; 681 VLOG(1) << "Exporting RadiographyScene to: export to image";
629 682
630 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 683 std::auto_ptr<Orthanc::Image> rendered(ExportToCreateDicomRequestAndImage(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation));
631 684
685 // convert the image into base64 for inclusing in the createDicomRequest
632 std::string base64; 686 std::string base64;
633 687
634 { 688 {
635 std::string content; 689 std::string content;
636 690
647 } 701 }
648 702
649 VLOG(1) << "Exporting RadiographyScene: encoding to base64"; 703 VLOG(1) << "Exporting RadiographyScene: encoding to base64";
650 Orthanc::Toolbox::EncodeBase64(base64, content); 704 Orthanc::Toolbox::EncodeBase64(base64, content);
651 } 705 }
652
653 createDicomRequestContent["Tags"] = dicomTags;
654
655 PhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode();
656 if ((invert && photometricMode != PhotometricDisplayMode_Monochrome2) ||
657 (!invert && photometricMode == PhotometricDisplayMode_Monochrome1))
658 {
659 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME1";
660 }
661 else
662 {
663 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME2";
664 }
665
666 // WARNING: The order of PixelSpacing is Y/X. We use "%0.8f" to
667 // avoid floating-point numbers to grow over 16 characters,
668 // which would be invalid according to DICOM standard
669 // ("dciodvfy" would complain).
670 char buf[32];
671 sprintf(buf, "%0.8f\\%0.8f", pixelSpacingY, pixelSpacingX);
672
673 createDicomRequestContent["Tags"]["PixelSpacing"] = buf;
674
675 float center, width;
676 if (GetWindowing(center, width))
677 {
678 createDicomRequestContent["Tags"]["WindowCenter"] =
679 boost::lexical_cast<std::string>(boost::math::iround(center));
680
681 createDicomRequestContent["Tags"]["WindowWidth"] =
682 boost::lexical_cast<std::string>(boost::math::iround(width));
683 }
684
685 706
686 // This is Data URI scheme: https://en.wikipedia.org/wiki/Data_URI_scheme 707 // This is Data URI scheme: https://en.wikipedia.org/wiki/Data_URI_scheme
687 createDicomRequestContent["Content"] = ("data:" + 708 createDicomRequestContent["Content"] = ("data:" +
688 std::string(usePam ? Orthanc::MIME_PAM : Orthanc::MIME_PNG) + 709 std::string(usePam ? Orthanc::MIME_PAM : Orthanc::MIME_PNG) +
689 ";base64," + base64); 710 ";base64," + base64);
690
691 if (!parentOrthancId.empty())
692 {
693 createDicomRequestContent["Parent"] = parentOrthancId;
694 }
695 711
696 VLOG(1) << "Exporting RadiographyScene: create-dicom request is ready"; 712 VLOG(1) << "Exporting RadiographyScene: create-dicom request is ready";
697 } 713 }
698 714
699 715