Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/OrthancSlicesLoader.cpp @ 257:9afafb192180 am-2
using PAM
author | am@osimis.io |
---|---|
date | Tue, 10 Jul 2018 12:39:01 +0200 |
parents | 40b21c1f8b8d |
children | c9cf95b49a86 |
comparison
equal
deleted
inserted
replaced
255:65562a28fe05 | 257:9afafb192180 |
---|---|
27 #include <Core/Endianness.h> | 27 #include <Core/Endianness.h> |
28 #include <Core/Images/Image.h> | 28 #include <Core/Images/Image.h> |
29 #include <Core/Images/ImageProcessing.h> | 29 #include <Core/Images/ImageProcessing.h> |
30 #include <Core/Images/JpegReader.h> | 30 #include <Core/Images/JpegReader.h> |
31 #include <Core/Images/PngReader.h> | 31 #include <Core/Images/PngReader.h> |
32 #include <Core/Images/PamReader.h> | |
32 #include <Core/Logging.h> | 33 #include <Core/Logging.h> |
33 #include <Core/OrthancException.h> | 34 #include <Core/OrthancException.h> |
34 #include <Core/Toolbox.h> | 35 #include <Core/Toolbox.h> |
35 #include <Plugins/Samples/Common/FullOrthancDataset.h> | 36 #include <Plugins/Samples/Common/FullOrthancDataset.h> |
36 | 37 |
161 const Slice& slice) | 162 const Slice& slice) |
162 { | 163 { |
163 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadRawImage)); | 164 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadRawImage)); |
164 tmp->sliceIndex_ = sliceIndex; | 165 tmp->sliceIndex_ = sliceIndex; |
165 tmp->slice_ = &slice; | 166 tmp->slice_ = &slice; |
166 tmp->quality_ = SliceImageQuality_Full; | 167 tmp->quality_ = SliceImageQuality_InternalRaw; |
167 return tmp.release(); | 168 return tmp.release(); |
168 } | 169 } |
170 | |
171 static Operation* DownloadDicomFile(const Slice& slice) | |
172 { | |
173 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadDicomFile)); | |
174 tmp->slice_ = &slice; | |
175 return tmp.release(); | |
176 } | |
177 | |
169 }; | 178 }; |
170 | 179 |
171 | 180 |
172 class OrthancSlicesLoader::WebCallback : public IWebService::ICallback | 181 class OrthancSlicesLoader::WebCallback : public IWebService::ICallback |
173 { | 182 { |
204 break; | 213 break; |
205 | 214 |
206 case Mode_LoadImage: | 215 case Mode_LoadImage: |
207 switch (operation->GetQuality()) | 216 switch (operation->GetQuality()) |
208 { | 217 { |
209 case SliceImageQuality_Full: | 218 case SliceImageQuality_FullPng: |
210 that_.ParseSliceImagePng(*operation, answer, answerSize); | 219 that_.ParseSliceImagePng(*operation, answer, answerSize); |
211 break; | 220 break; |
212 | 221 case SliceImageQuality_FullPam: |
222 that_.ParseSliceImagePam(*operation, answer, answerSize); | |
223 break; | |
224 | |
213 case SliceImageQuality_Jpeg50: | 225 case SliceImageQuality_Jpeg50: |
214 case SliceImageQuality_Jpeg90: | 226 case SliceImageQuality_Jpeg90: |
215 case SliceImageQuality_Jpeg95: | 227 case SliceImageQuality_Jpeg95: |
216 that_.ParseSliceImageJpeg(*operation, answer, answerSize); | 228 that_.ParseSliceImageJpeg(*operation, answer, answerSize); |
217 break; | 229 break; |
507 } | 519 } |
508 | 520 |
509 NotifySliceImageSuccess(operation, image); | 521 NotifySliceImageSuccess(operation, image); |
510 } | 522 } |
511 | 523 |
512 | 524 void OrthancSlicesLoader::ParseSliceImagePam(const Operation& operation, |
525 const void* answer, | |
526 size_t size) | |
527 { | |
528 std::auto_ptr<Orthanc::ImageAccessor> image; | |
529 | |
530 try | |
531 { | |
532 image.reset(new Orthanc::PamReader); | |
533 dynamic_cast<Orthanc::PamReader&>(*image).ReadFromMemory(std::string(reinterpret_cast<const char*>(answer), size)); | |
534 } | |
535 catch (Orthanc::OrthancException&) | |
536 { | |
537 NotifySliceImageError(operation); | |
538 return; | |
539 } | |
540 | |
541 if (image->GetWidth() != operation.GetSlice().GetWidth() || | |
542 image->GetHeight() != operation.GetSlice().GetHeight()) | |
543 { | |
544 NotifySliceImageError(operation); | |
545 return; | |
546 } | |
547 | |
548 if (operation.GetSlice().GetConverter().GetExpectedPixelFormat() == | |
549 Orthanc::PixelFormat_SignedGrayscale16) | |
550 { | |
551 if (image->GetFormat() == Orthanc::PixelFormat_Grayscale16) | |
552 { | |
553 image->SetFormat(Orthanc::PixelFormat_SignedGrayscale16); | |
554 } | |
555 else | |
556 { | |
557 NotifySliceImageError(operation); | |
558 return; | |
559 } | |
560 } | |
561 | |
562 NotifySliceImageSuccess(operation, image); | |
563 } | |
564 | |
565 | |
513 void OrthancSlicesLoader::ParseSliceImageJpeg(const Operation& operation, | 566 void OrthancSlicesLoader::ParseSliceImageJpeg(const Operation& operation, |
514 const void* answer, | 567 const void* answer, |
515 size_t size) | 568 size_t size) |
516 { | 569 { |
517 Json::Value encoded; | 570 Json::Value encoded; |
683 AssignWritable(format, width, height, | 736 AssignWritable(format, width, height, |
684 Orthanc::GetBytesPerPixel(format) * width, data); | 737 Orthanc::GetBytesPerPixel(format) * width, data); |
685 } | 738 } |
686 }; | 739 }; |
687 | 740 |
688 | |
689 void OrthancSlicesLoader::ParseSliceRawImage(const Operation& operation, | 741 void OrthancSlicesLoader::ParseSliceRawImage(const Operation& operation, |
690 const void* answer, | 742 const void* answer, |
691 size_t size) | 743 size_t size) |
692 { | 744 { |
693 Orthanc::GzipCompressor compressor; | 745 Orthanc::GzipCompressor compressor; |
766 } | 818 } |
767 else | 819 else |
768 { | 820 { |
769 state_ = State_LoadingGeometry; | 821 state_ = State_LoadingGeometry; |
770 std::string uri = "/series/" + seriesId + "/instances-tags"; | 822 std::string uri = "/series/" + seriesId + "/instances-tags"; |
771 orthanc_.ScheduleGetRequest(*webCallback_, uri, Operation::DownloadSeriesGeometry()); | 823 orthanc_.ScheduleGetRequest(*webCallback_, uri, IWebService::Headers(), Operation::DownloadSeriesGeometry()); |
772 } | 824 } |
773 } | 825 } |
774 | 826 |
775 | 827 |
776 void OrthancSlicesLoader::ScheduleLoadInstance(const std::string& instanceId) | 828 void OrthancSlicesLoader::ScheduleLoadInstance(const std::string& instanceId) |
785 | 837 |
786 // Tag "3004-000c" is "Grid Frame Offset Vector", which is | 838 // Tag "3004-000c" is "Grid Frame Offset Vector", which is |
787 // mandatory to read RT DOSE, but is too long to be returned by default | 839 // mandatory to read RT DOSE, but is too long to be returned by default |
788 std::string uri = "/instances/" + instanceId + "/tags?ignore-length=3004-000c"; | 840 std::string uri = "/instances/" + instanceId + "/tags?ignore-length=3004-000c"; |
789 orthanc_.ScheduleGetRequest | 841 orthanc_.ScheduleGetRequest |
790 (*webCallback_, uri, Operation::DownloadInstanceGeometry(instanceId)); | 842 (*webCallback_, uri, IWebService::Headers(), Operation::DownloadInstanceGeometry(instanceId)); |
791 } | 843 } |
792 } | 844 } |
793 | 845 |
794 | 846 |
795 void OrthancSlicesLoader::ScheduleLoadFrame(const std::string& instanceId, | 847 void OrthancSlicesLoader::ScheduleLoadFrame(const std::string& instanceId, |
802 else | 854 else |
803 { | 855 { |
804 state_ = State_LoadingGeometry; | 856 state_ = State_LoadingGeometry; |
805 std::string uri = "/instances/" + instanceId + "/tags"; | 857 std::string uri = "/instances/" + instanceId + "/tags"; |
806 orthanc_.ScheduleGetRequest | 858 orthanc_.ScheduleGetRequest |
807 (*webCallback_, uri, Operation::DownloadFrameGeometry(instanceId, frame)); | 859 (*webCallback_, uri, IWebService::Headers(), Operation::DownloadFrameGeometry(instanceId, frame)); |
808 } | 860 } |
809 } | 861 } |
810 | 862 |
811 | 863 |
812 bool OrthancSlicesLoader::IsGeometryReady() const | 864 bool OrthancSlicesLoader::IsGeometryReady() const |
871 | 923 |
872 default: | 924 default: |
873 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 925 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
874 } | 926 } |
875 | 927 |
876 orthanc_.ScheduleGetRequest(*webCallback_, uri, | 928 IWebService::Headers headers; |
877 Operation::DownloadSliceImage(index, slice, SliceImageQuality_Full)); | 929 headers["Accept"] = "image/png"; |
878 } | 930 orthanc_.ScheduleGetRequest(*webCallback_, uri, IWebService::Headers(), |
879 | 931 Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPng)); |
932 } | |
933 | |
934 void OrthancSlicesLoader::ScheduleSliceImagePam(const Slice& slice, | |
935 size_t index) | |
936 { | |
937 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + | |
938 boost::lexical_cast<std::string>(slice.GetFrame())); | |
939 | |
940 switch (slice.GetConverter().GetExpectedPixelFormat()) | |
941 { | |
942 case Orthanc::PixelFormat_RGB24: | |
943 uri += "/preview"; | |
944 break; | |
945 | |
946 case Orthanc::PixelFormat_Grayscale16: | |
947 uri += "/image-uint16"; | |
948 break; | |
949 | |
950 case Orthanc::PixelFormat_SignedGrayscale16: | |
951 uri += "/image-int16"; | |
952 break; | |
953 | |
954 default: | |
955 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
956 } | |
957 | |
958 IWebService::Headers headers; | |
959 headers["Accept"] = "image/x-portable-arbitrarymap"; | |
960 orthanc_.ScheduleGetRequest(*webCallback_, uri, headers, | |
961 Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPam)); | |
962 } | |
963 | |
964 | |
880 | 965 |
881 void OrthancSlicesLoader::ScheduleSliceImageJpeg(const Slice& slice, | 966 void OrthancSlicesLoader::ScheduleSliceImageJpeg(const Slice& slice, |
882 size_t index, | 967 size_t index, |
883 SliceImageQuality quality) | 968 SliceImageQuality quality) |
884 { | 969 { |
906 std::string uri = ("/web-viewer/instances/jpeg" + | 991 std::string uri = ("/web-viewer/instances/jpeg" + |
907 boost::lexical_cast<std::string>(value) + | 992 boost::lexical_cast<std::string>(value) + |
908 "-" + slice.GetOrthancInstanceId() + "_" + | 993 "-" + slice.GetOrthancInstanceId() + "_" + |
909 boost::lexical_cast<std::string>(slice.GetFrame())); | 994 boost::lexical_cast<std::string>(slice.GetFrame())); |
910 | 995 |
911 orthanc_.ScheduleGetRequest(*webCallback_, uri, | 996 orthanc_.ScheduleGetRequest(*webCallback_, uri, IWebService::Headers(), |
912 Operation::DownloadSliceImage(index, slice, quality)); | 997 Operation::DownloadSliceImage(index, slice, quality)); |
913 } | 998 } |
914 | 999 |
915 | 1000 |
916 | 1001 |
924 | 1009 |
925 const Slice& slice = GetSlice(index); | 1010 const Slice& slice = GetSlice(index); |
926 | 1011 |
927 if (slice.HasOrthancDecoding()) | 1012 if (slice.HasOrthancDecoding()) |
928 { | 1013 { |
929 if (quality == SliceImageQuality_Full) | 1014 switch (quality) |
930 { | 1015 { |
1016 case SliceImageQuality_FullPng: | |
931 ScheduleSliceImagePng(slice, index); | 1017 ScheduleSliceImagePng(slice, index); |
932 } | 1018 break; |
933 else | 1019 case SliceImageQuality_FullPam: |
934 { | 1020 ScheduleSliceImagePam(slice, index); |
1021 break; | |
1022 default: | |
935 ScheduleSliceImageJpeg(slice, index, quality); | 1023 ScheduleSliceImageJpeg(slice, index, quality); |
936 } | 1024 } |
937 } | 1025 } |
938 else | 1026 else |
939 { | 1027 { |
940 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + | 1028 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + |
941 boost::lexical_cast<std::string>(slice.GetFrame()) + "/raw.gz"); | 1029 boost::lexical_cast<std::string>(slice.GetFrame()) + "/raw.gz"); |
942 orthanc_.ScheduleGetRequest(*webCallback_, uri, | 1030 orthanc_.ScheduleGetRequest(*webCallback_, uri, IWebService::Headers(), |
943 Operation::DownloadSliceRawImage(index, slice)); | 1031 Operation::DownloadSliceRawImage(index, slice)); |
944 } | 1032 } |
945 } | 1033 } |
946 } | 1034 } |