Mercurial > hg > orthanc-stone
comparison Applications/Samples/SingleFrameEditorApplication.h @ 361:f559ac66ef55 am-2
first export of a dicom image
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 Oct 2018 16:34:56 +0100 |
parents | 8262e4e9826d |
children | 12cec26d08ce |
comparison
equal
deleted
inserted
replaced
360:8262e4e9826d | 361:f559ac66ef55 |
---|---|
29 | 29 |
30 #include <Core/Images/FontRegistry.h> | 30 #include <Core/Images/FontRegistry.h> |
31 #include <Core/Images/Image.h> | 31 #include <Core/Images/Image.h> |
32 #include <Core/Images/ImageProcessing.h> | 32 #include <Core/Images/ImageProcessing.h> |
33 #include <Core/Images/PamReader.h> | 33 #include <Core/Images/PamReader.h> |
34 #include <Core/Images/PamWriter.h> | |
34 #include <Core/Logging.h> | 35 #include <Core/Logging.h> |
36 #include <Core/Toolbox.h> | |
37 #include <Core/SystemToolbox.h> | |
35 #include <Plugins/Samples/Common/DicomDatasetReader.h> | 38 #include <Plugins/Samples/Common/DicomDatasetReader.h> |
36 #include <Plugins/Samples/Common/FullOrthancDataset.h> | 39 #include <Plugins/Samples/Common/FullOrthancDataset.h> |
37 | |
38 #include <Core/Images/PngWriter.h> | |
39 | 40 |
40 | 41 |
41 #include <boost/math/constants/constants.hpp> | 42 #include <boost/math/constants/constants.hpp> |
42 | 43 |
43 namespace OrthancStone | 44 namespace OrthancStone |
2601 case 'c': | 2602 case 'c': |
2602 tool_ = Tool_Crop; | 2603 tool_ = Tool_Crop; |
2603 break; | 2604 break; |
2604 | 2605 |
2605 case 'e': | 2606 case 'e': |
2606 Export(GetStack(widget), 0.1, 0.1, GetWidget(widget).GetInterpolation()); | 2607 { |
2608 Orthanc::DicomMap tags; | |
2609 tags.SetValue(Orthanc::DICOM_TAG_PATIENT_ID, "hello", false); | |
2610 tags.SetValue(Orthanc::DICOM_TAG_PATIENT_NAME, "HELLO^WORLD", false); | |
2611 Export(GetStack(widget), 0.1, 0.1, GetWidget(widget).GetInterpolation(), tags); | |
2607 break; | 2612 break; |
2613 } | |
2608 | 2614 |
2609 case 'i': | 2615 case 'i': |
2610 GetWidget(widget).SwitchInvert(); | 2616 GetWidget(widget).SwitchInvert(); |
2611 break; | 2617 break; |
2612 | 2618 |
2676 | 2682 |
2677 | 2683 |
2678 void Export(const BitmapStack& stack, | 2684 void Export(const BitmapStack& stack, |
2679 double pixelSpacingX, | 2685 double pixelSpacingX, |
2680 double pixelSpacingY, | 2686 double pixelSpacingY, |
2681 ImageInterpolation interpolation) | 2687 ImageInterpolation interpolation, |
2688 const Orthanc::DicomMap& dicom) | |
2682 { | 2689 { |
2683 if (pixelSpacingX <= 0 || | 2690 if (pixelSpacingX <= 0 || |
2684 pixelSpacingY <= 0) | 2691 pixelSpacingY <= 0) |
2685 { | 2692 { |
2686 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 2693 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
2716 | 2723 |
2717 Orthanc::Image rendered(Orthanc::PixelFormat_Grayscale16, | 2724 Orthanc::Image rendered(Orthanc::PixelFormat_Grayscale16, |
2718 layers.GetWidth(), layers.GetHeight(), false); | 2725 layers.GetWidth(), layers.GetHeight(), false); |
2719 Orthanc::ImageProcessing::Convert(rendered, layers); | 2726 Orthanc::ImageProcessing::Convert(rendered, layers); |
2720 | 2727 |
2721 Orthanc::PngWriter png; | 2728 std::string pam; |
2722 png.WriteToFile("/tmp/a.png", rendered); | 2729 { |
2730 Orthanc::PamWriter writer; | |
2731 writer.WriteToMemory(pam, rendered); | |
2732 } | |
2733 | |
2734 std::string content; | |
2735 Orthanc::Toolbox::EncodeBase64(content, pam); | |
2736 | |
2737 std::set<Orthanc::DicomTag> tags; | |
2738 dicom.GetTags(tags); | |
2739 | |
2740 Json::Value json = Json::objectValue; | |
2741 json["Tags"] = Json::objectValue; | |
2742 | |
2743 for (std::set<Orthanc::DicomTag>::const_iterator | |
2744 tag = tags.begin(); tag != tags.end(); ++tag) | |
2745 { | |
2746 const Orthanc::DicomValue& value = dicom.GetValue(*tag); | |
2747 if (!value.IsNull() && | |
2748 !value.IsBinary()) | |
2749 { | |
2750 json["Tags"][tag->Format()] = value.GetContent(); | |
2751 } | |
2752 } | |
2753 | |
2754 json["Content"] = "data:" + std::string(Orthanc::MIME_PAM) + ";base64," + content; | |
2755 | |
2756 orthanc_->PostJsonAsyncExpectJson("/tools/create-dicom", json, NULL, NULL, NULL); | |
2723 } | 2757 } |
2724 }; | 2758 }; |
2725 | 2759 |
2726 | 2760 |
2727 | 2761 |
2791 | 2825 |
2792 Orthanc::FontRegistry fonts; | 2826 Orthanc::FontRegistry fonts; |
2793 fonts.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16); | 2827 fonts.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16); |
2794 | 2828 |
2795 stack_.reset(new BitmapStack(IObserver::broker_, *orthancApiClient_)); | 2829 stack_.reset(new BitmapStack(IObserver::broker_, *orthancApiClient_)); |
2796 stack_->LoadFrame(instance, frame, false).SetPan(200, 0); | 2830 stack_->LoadFrame(instance, frame, false); //.SetPan(200, 0); |
2797 //stack_->LoadFrame("61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", 0, false); | 2831 //stack_->LoadFrame("61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", 0, false); |
2798 | 2832 |
2799 { | 2833 { |
2800 BitmapStack::Bitmap& bitmap = stack_->LoadText(fonts.GetFont(0), "Hello\nworld"); | 2834 BitmapStack::Bitmap& bitmap = stack_->LoadText(fonts.GetFont(0), "Hello\nworld"); |
2801 //dynamic_cast<BitmapStack::AlphaBitmap&>(bitmap).SetForegroundValue(256); | 2835 //dynamic_cast<BitmapStack::AlphaBitmap&>(bitmap).SetForegroundValue(256); |