comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 3712:2a170a8f1faf

replacing std::auto_ptr by std::unique_ptr
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 02 Mar 2020 15:32:45 +0100
parents a9ce35d67c3c
children 09f091b6b569
comparison
equal deleted inserted replaced
3709:1f4910999fe7 3712:2a170a8f1faf
386 namespace 386 namespace
387 { 387 {
388 class ImageToEncode 388 class ImageToEncode
389 { 389 {
390 private: 390 private:
391 std::auto_ptr<ImageAccessor>& image_; 391 std::unique_ptr<ImageAccessor>& image_;
392 ImageExtractionMode mode_; 392 ImageExtractionMode mode_;
393 bool invert_; 393 bool invert_;
394 MimeType format_; 394 MimeType format_;
395 std::string answer_; 395 std::string answer_;
396 396
397 public: 397 public:
398 ImageToEncode(std::auto_ptr<ImageAccessor>& image, 398 ImageToEncode(std::unique_ptr<ImageAccessor>& image,
399 ImageExtractionMode mode, 399 ImageExtractionMode mode,
400 bool invert) : 400 bool invert) :
401 image_(image), 401 image_(image),
402 mode_(mode), 402 mode_(mode),
403 invert_(invert) 403 invert_(invert)
516 virtual ~IDecodedFrameHandler() 516 virtual ~IDecodedFrameHandler()
517 { 517 {
518 } 518 }
519 519
520 virtual void Handle(RestApiGetCall& call, 520 virtual void Handle(RestApiGetCall& call,
521 std::auto_ptr<ImageAccessor>& decoded, 521 std::unique_ptr<ImageAccessor>& decoded,
522 const DicomMap& dicom) = 0; 522 const DicomMap& dicom) = 0;
523 523
524 virtual bool RequiresDicomTags() const = 0; 524 virtual bool RequiresDicomTags() const = 0;
525 525
526 static void Apply(RestApiGetCall& call, 526 static void Apply(RestApiGetCall& call,
539 { 539 {
540 return; 540 return;
541 } 541 }
542 542
543 DicomMap dicom; 543 DicomMap dicom;
544 std::auto_ptr<ImageAccessor> decoded; 544 std::unique_ptr<ImageAccessor> decoded;
545 545
546 try 546 try
547 { 547 {
548 std::string publicId = call.GetUriComponent("id", ""); 548 std::string publicId = call.GetUriComponent("id", "");
549 549
611 handler.Handle(call, decoded, dicom); 611 handler.Handle(call, decoded, dicom);
612 } 612 }
613 613
614 614
615 static void DefaultHandler(RestApiGetCall& call, 615 static void DefaultHandler(RestApiGetCall& call,
616 std::auto_ptr<ImageAccessor>& decoded, 616 std::unique_ptr<ImageAccessor>& decoded,
617 ImageExtractionMode mode, 617 ImageExtractionMode mode,
618 bool invert) 618 bool invert)
619 { 619 {
620 ImageToEncode image(decoded, mode, invert); 620 ImageToEncode image(decoded, mode, invert);
621 621
647 mode_(mode) 647 mode_(mode)
648 { 648 {
649 } 649 }
650 650
651 virtual void Handle(RestApiGetCall& call, 651 virtual void Handle(RestApiGetCall& call,
652 std::auto_ptr<ImageAccessor>& decoded, 652 std::unique_ptr<ImageAccessor>& decoded,
653 const DicomMap& dicom) ORTHANC_OVERRIDE 653 const DicomMap& dicom) ORTHANC_OVERRIDE
654 { 654 {
655 bool invert = false; 655 bool invert = false;
656 656
657 if (mode_ == ImageExtractionMode_Preview) 657 if (mode_ == ImageExtractionMode_Preview)
815 } 815 }
816 816
817 817
818 public: 818 public:
819 virtual void Handle(RestApiGetCall& call, 819 virtual void Handle(RestApiGetCall& call,
820 std::auto_ptr<ImageAccessor>& decoded, 820 std::unique_ptr<ImageAccessor>& decoded,
821 const DicomMap& dicom) ORTHANC_OVERRIDE 821 const DicomMap& dicom) ORTHANC_OVERRIDE
822 { 822 {
823 bool invert; 823 bool invert;
824 float rescaleSlope, rescaleIntercept, windowWidth, windowCenter; 824 float rescaleSlope, rescaleIntercept, windowWidth, windowCenter;
825 GetDicomParameters(invert, rescaleSlope, rescaleIntercept, windowWidth, windowCenter, dicom); 825 GetDicomParameters(invert, rescaleSlope, rescaleIntercept, windowWidth, windowCenter, dicom);
863 { 863 {
864 DefaultHandler(call, decoded, ImageExtractionMode_Preview, false); 864 DefaultHandler(call, decoded, ImageExtractionMode_Preview, false);
865 } 865 }
866 else 866 else
867 { 867 {
868 std::auto_ptr<ImageAccessor> resized( 868 std::unique_ptr<ImageAccessor> resized(
869 new Image(decoded->GetFormat(), targetWidth, targetHeight, false)); 869 new Image(decoded->GetFormat(), targetWidth, targetHeight, false));
870 870
871 if (smooth && 871 if (smooth &&
872 (targetWidth < decoded->GetWidth() || 872 (targetWidth < decoded->GetWidth() ||
873 targetHeight < decoded->GetHeight())) 873 targetHeight < decoded->GetHeight()))
899 } 899 }
900 900
901 const float scaling = 255.0f * rescaleSlope / windowWidth; 901 const float scaling = 255.0f * rescaleSlope / windowWidth;
902 const float offset = (rescaleIntercept - windowCenter + windowWidth / 2.0f) / rescaleSlope; 902 const float offset = (rescaleIntercept - windowCenter + windowWidth / 2.0f) / rescaleSlope;
903 903
904 std::auto_ptr<ImageAccessor> rescaled(new Image(PixelFormat_Grayscale8, decoded->GetWidth(), decoded->GetHeight(), false)); 904 std::unique_ptr<ImageAccessor> rescaled(new Image(PixelFormat_Grayscale8, decoded->GetWidth(), decoded->GetHeight(), false));
905 ImageProcessing::ShiftScale(*rescaled, converted, offset, scaling, false); 905 ImageProcessing::ShiftScale(*rescaled, converted, offset, scaling, false);
906 906
907 if (targetWidth == decoded->GetWidth() && 907 if (targetWidth == decoded->GetWidth() &&
908 targetHeight == decoded->GetHeight()) 908 targetHeight == decoded->GetHeight())
909 { 909 {
910 DefaultHandler(call, rescaled, ImageExtractionMode_UInt8, invert); 910 DefaultHandler(call, rescaled, ImageExtractionMode_UInt8, invert);
911 } 911 }
912 else 912 else
913 { 913 {
914 std::auto_ptr<ImageAccessor> resized( 914 std::unique_ptr<ImageAccessor> resized(
915 new Image(PixelFormat_Grayscale8, targetWidth, targetHeight, false)); 915 new Image(PixelFormat_Grayscale8, targetWidth, targetHeight, false));
916 916
917 if (smooth && 917 if (smooth &&
918 (targetWidth < decoded->GetWidth() || 918 (targetWidth < decoded->GetWidth() ||
919 targetHeight < decoded->GetHeight())) 919 targetHeight < decoded->GetHeight()))
974 IDicomImageDecoder& decoder = context.GetPlugins(); 974 IDicomImageDecoder& decoder = context.GetPlugins();
975 #else 975 #else
976 DefaultDicomImageDecoder decoder; // This is Orthanc's built-in decoder 976 DefaultDicomImageDecoder decoder; // This is Orthanc's built-in decoder
977 #endif 977 #endif
978 978
979 std::auto_ptr<ImageAccessor> decoded(decoder.Decode(dicomContent.c_str(), dicomContent.size(), frame)); 979 std::unique_ptr<ImageAccessor> decoded(decoder.Decode(dicomContent.c_str(), dicomContent.size(), frame));
980 980
981 std::string result; 981 std::string result;
982 decoded->ToMatlabString(result); 982 decoded->ToMatlabString(result);
983 983
984 call.GetOutput().AnswerBuffer(result, MimeType_PlainText); 984 call.GetOutput().AnswerBuffer(result, MimeType_PlainText);