changeset 587:848170ca4351 am-dev

more export functions
author Alain Mazy <alain@mazy.be>
date Tue, 23 Apr 2019 10:15:54 +0200
parents e77cbe4bb4c8
children 8432926e9db9
files Framework/Radiography/RadiographyScene.cpp Framework/Radiography/RadiographyScene.h
diffstat 2 files changed, 60 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Radiography/RadiographyScene.cpp	Thu Apr 18 15:46:07 2019 +0200
+++ b/Framework/Radiography/RadiographyScene.cpp	Tue Apr 23 10:15:54 2019 +0200
@@ -349,7 +349,7 @@
     layer.SetPreferredPhotomotricDisplayMode(preferredPhotometricDisplayMode);
 
     return layer;
- }
+  }
 
   RadiographyLayer& RadiographyScene::LoadDicomFrame(OrthancApiClient& orthanc,
                                                      const std::string& instance,
@@ -615,41 +615,18 @@
   }
 
 
-  void RadiographyScene::ExportToCreateDicomRequest(Json::Value& createDicomRequestContent,
-                                                    const Json::Value& dicomTags,
-                                                    const std::string& parentOrthancId,
-                                                    double pixelSpacingX,
-                                                    double pixelSpacingY,
-                                                    bool invert,
-                                                    ImageInterpolation interpolation,
-                                                    bool usePam)
+  Orthanc::Image* RadiographyScene::ExportToCreateDicomRequestAndImage(Json::Value& createDicomRequestContent,
+                                                                       const Json::Value& dicomTags,
+                                                                       const std::string& parentOrthancId,
+                                                                       double pixelSpacingX,
+                                                                       double pixelSpacingY,
+                                                                       bool invert,
+                                                                       ImageInterpolation interpolation)
   {
     LOG(INFO) << "Exporting RadiographyScene to DICOM";
-    VLOG(1) << "Exporting RadiographyScene to: export to image";
 
     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
 
-    std::string base64;
-
-    {
-      std::string content;
-
-      if (usePam)
-      {
-        VLOG(1) << "Exporting RadiographyScene: convert to PAM";
-        Orthanc::PamWriter writer;
-        writer.WriteToMemory(content, *rendered);
-      }
-      else
-      {
-        Orthanc::PngWriter writer;
-        writer.WriteToMemory(content, *rendered);
-      }
-
-      VLOG(1) << "Exporting RadiographyScene: encoding to base64";
-      Orthanc::Toolbox::EncodeBase64(base64, content);
-    }
-
     createDicomRequestContent["Tags"] = dicomTags;
 
     PhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode();
@@ -682,17 +659,56 @@
           boost::lexical_cast<std::string>(boost::math::iround(width));
     }
 
+    if (!parentOrthancId.empty())
+    {
+      createDicomRequestContent["Parent"] = parentOrthancId;
+    }
+
+    return rendered.release();
+  }
+
+
+  void RadiographyScene::ExportToCreateDicomRequest(Json::Value& createDicomRequestContent,
+                                                    const Json::Value& dicomTags,
+                                                    const std::string& parentOrthancId,
+                                                    double pixelSpacingX,
+                                                    double pixelSpacingY,
+                                                    bool invert,
+                                                    ImageInterpolation interpolation,
+                                                    bool usePam)
+  {
+    LOG(INFO) << "Exporting RadiographyScene to DICOM";
+    VLOG(1) << "Exporting RadiographyScene to: export to image";
+
+    std::auto_ptr<Orthanc::Image> rendered(ExportToCreateDicomRequestAndImage(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation));
+
+    // convert the image into base64 for inclusing in the createDicomRequest
+    std::string base64;
+
+    {
+      std::string content;
+
+      if (usePam)
+      {
+        VLOG(1) << "Exporting RadiographyScene: convert to PAM";
+        Orthanc::PamWriter writer;
+        writer.WriteToMemory(content, *rendered);
+      }
+      else
+      {
+        Orthanc::PngWriter writer;
+        writer.WriteToMemory(content, *rendered);
+      }
+
+      VLOG(1) << "Exporting RadiographyScene: encoding to base64";
+      Orthanc::Toolbox::EncodeBase64(base64, content);
+    }
 
     // This is Data URI scheme: https://en.wikipedia.org/wiki/Data_URI_scheme
     createDicomRequestContent["Content"] = ("data:" +
                                             std::string(usePam ? Orthanc::MIME_PAM : Orthanc::MIME_PNG) +
                                             ";base64," + base64);
 
-    if (!parentOrthancId.empty())
-    {
-      createDicomRequestContent["Parent"] = parentOrthancId;
-    }
-
     VLOG(1) << "Exporting RadiographyScene: create-dicom request is ready";
   }
 
--- a/Framework/Radiography/RadiographyScene.h	Thu Apr 18 15:46:07 2019 +0200
+++ b/Framework/Radiography/RadiographyScene.h	Tue Apr 23 10:15:54 2019 +0200
@@ -310,6 +310,14 @@
                                     ImageInterpolation interpolation,
                                     bool usePam);
 
+    Orthanc::Image* ExportToCreateDicomRequestAndImage(Json::Value& createDicomRequestContent,
+                                                       const Json::Value& dicomTags,
+                                                       const std::string& parentOrthancId,
+                                                       double pixelSpacingX,
+                                                       double pixelSpacingY,
+                                                       bool invert,
+                                                       ImageInterpolation interpolation);
+
     Orthanc::Image* ExportToImage(double pixelSpacingX,
                                   double pixelSpacingY,
                                   ImageInterpolation interpolation)