Mercurial > hg > orthanc-stone
comparison Framework/Radiography/RadiographyScene.cpp @ 484:7bf001b9d244 am-touch-events
re-added ExportToCreateDicomRequest
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Fri, 15 Feb 2019 11:08:44 +0100 |
parents | 29fc066b6f65 |
children | aede9b042cb7 |
comparison
equal
deleted
inserted
replaced
483:29fc066b6f65 | 484:7bf001b9d244 |
---|---|
585 | 585 |
586 return rendered.release(); | 586 return rendered.release(); |
587 } | 587 } |
588 | 588 |
589 | 589 |
590 void RadiographyScene::ExportToCreateDicomRequest(Json::Value& createDicomRequestContent, | |
591 const Json::Value& dicomTags, | |
592 const std::string& parentOrthancId, | |
593 double pixelSpacingX, | |
594 double pixelSpacingY, | |
595 bool invert, | |
596 ImageInterpolation interpolation, | |
597 bool usePam) | |
598 { | |
599 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 | |
600 | |
601 std::string base64; | |
602 | |
603 { | |
604 std::string content; | |
605 | |
606 if (usePam) | |
607 { | |
608 Orthanc::PamWriter writer; | |
609 writer.WriteToMemory(content, *rendered); | |
610 } | |
611 else | |
612 { | |
613 Orthanc::PngWriter writer; | |
614 writer.WriteToMemory(content, *rendered); | |
615 } | |
616 | |
617 Orthanc::Toolbox::EncodeBase64(base64, content); | |
618 } | |
619 | |
620 createDicomRequestContent["Tags"] = dicomTags; | |
621 | |
622 PhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode(); | |
623 if ((invert && photometricMode != PhotometricDisplayMode_Monochrome2) || | |
624 (!invert && photometricMode == PhotometricDisplayMode_Monochrome1)) | |
625 { | |
626 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME1"; | |
627 } | |
628 else | |
629 { | |
630 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME2"; | |
631 } | |
632 | |
633 // WARNING: The order of PixelSpacing is Y/X. We use "%0.8f" to | |
634 // avoid floating-point numbers to grow over 16 characters, | |
635 // which would be invalid according to DICOM standard | |
636 // ("dciodvfy" would complain). | |
637 char buf[32]; | |
638 sprintf(buf, "%0.8f\\%0.8f", pixelSpacingY, pixelSpacingX); | |
639 | |
640 createDicomRequestContent["Tags"]["PixelSpacing"] = buf; | |
641 | |
642 float center, width; | |
643 if (GetWindowing(center, width)) | |
644 { | |
645 createDicomRequestContent["Tags"]["WindowCenter"] = | |
646 boost::lexical_cast<std::string>(boost::math::iround(center)); | |
647 | |
648 createDicomRequestContent["Tags"]["WindowWidth"] = | |
649 boost::lexical_cast<std::string>(boost::math::iround(width)); | |
650 } | |
651 | |
652 | |
653 // This is Data URI scheme: https://en.wikipedia.org/wiki/Data_URI_scheme | |
654 createDicomRequestContent["Content"] = ("data:" + | |
655 std::string(usePam ? Orthanc::MIME_PAM : Orthanc::MIME_PNG) + | |
656 ";base64," + base64); | |
657 | |
658 if (!parentOrthancId.empty()) | |
659 { | |
660 createDicomRequestContent["Parent"] = parentOrthancId; | |
661 } | |
662 | |
663 } | |
664 | |
665 | |
590 void RadiographyScene::ExportDicom(OrthancApiClient& orthanc, | 666 void RadiographyScene::ExportDicom(OrthancApiClient& orthanc, |
591 const Json::Value& dicomTags, | 667 const Json::Value& dicomTags, |
592 const std::string& parentOrthancId, | 668 const std::string& parentOrthancId, |
593 double pixelSpacingX, | 669 double pixelSpacingX, |
594 double pixelSpacingY, | 670 double pixelSpacingY, |
596 ImageInterpolation interpolation, | 672 ImageInterpolation interpolation, |
597 bool usePam) | 673 bool usePam) |
598 { | 674 { |
599 Json::Value createDicomRequestContent; | 675 Json::Value createDicomRequestContent; |
600 | 676 |
601 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 | 677 ExportToCreateDicomRequest(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation, usePam); |
602 | |
603 std::string base64; | |
604 | |
605 { | |
606 std::string content; | |
607 | |
608 if (usePam) | |
609 { | |
610 Orthanc::PamWriter writer; | |
611 writer.WriteToMemory(content, *rendered); | |
612 } | |
613 else | |
614 { | |
615 Orthanc::PngWriter writer; | |
616 writer.WriteToMemory(content, *rendered); | |
617 } | |
618 | |
619 Orthanc::Toolbox::EncodeBase64(base64, content); | |
620 } | |
621 | |
622 createDicomRequestContent["Tags"] = dicomTags; | |
623 | |
624 PhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode(); | |
625 if ((invert && photometricMode != PhotometricDisplayMode_Monochrome2) || | |
626 (!invert && photometricMode == PhotometricDisplayMode_Monochrome1)) | |
627 { | |
628 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME1"; | |
629 } | |
630 else | |
631 { | |
632 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME2"; | |
633 } | |
634 | |
635 // WARNING: The order of PixelSpacing is Y/X. We use "%0.8f" to | |
636 // avoid floating-point numbers to grow over 16 characters, | |
637 // which would be invalid according to DICOM standard | |
638 // ("dciodvfy" would complain). | |
639 char buf[32]; | |
640 sprintf(buf, "%0.8f\\%0.8f", pixelSpacingY, pixelSpacingX); | |
641 | |
642 createDicomRequestContent["Tags"]["PixelSpacing"] = buf; | |
643 | |
644 float center, width; | |
645 if (GetWindowing(center, width)) | |
646 { | |
647 createDicomRequestContent["Tags"]["WindowCenter"] = | |
648 boost::lexical_cast<std::string>(boost::math::iround(center)); | |
649 | |
650 createDicomRequestContent["Tags"]["WindowWidth"] = | |
651 boost::lexical_cast<std::string>(boost::math::iround(width)); | |
652 } | |
653 | |
654 | |
655 // This is Data URI scheme: https://en.wikipedia.org/wiki/Data_URI_scheme | |
656 createDicomRequestContent["Content"] = ("data:" + | |
657 std::string(usePam ? Orthanc::MIME_PAM : Orthanc::MIME_PNG) + | |
658 ";base64," + base64); | |
659 | |
660 if (!parentOrthancId.empty()) | |
661 { | |
662 createDicomRequestContent["Parent"] = parentOrthancId; | |
663 } | |
664 | 678 |
665 orthanc.PostJsonAsyncExpectJson( | 679 orthanc.PostJsonAsyncExpectJson( |
666 "/tools/create-dicom", createDicomRequestContent, | 680 "/tools/create-dicom", createDicomRequestContent, |
667 new Callable<RadiographyScene, OrthancApiClient::JsonResponseReadyMessage> | 681 new Callable<RadiographyScene, OrthancApiClient::JsonResponseReadyMessage> |
668 (*this, &RadiographyScene::OnDicomExported), | 682 (*this, &RadiographyScene::OnDicomExported), |