changeset 1911:898774b4e02d

DicomInstanceParameters::CreateTexture() now sets pixel spacing
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 20 Mar 2022 15:13:57 +0100
parents f81cdf283859
children 7947565ed2b7
files Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewerApplication.h OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp
diffstat 2 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewerApplication.h	Tue Feb 01 10:40:35 2022 +0100
+++ b/Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewerApplication.h	Sun Mar 20 15:13:57 2022 +0100
@@ -131,8 +131,6 @@
     std::unique_ptr<TextureBaseSceneLayer> layer(
       message.GetInstanceParameters().CreateTexture(message.GetImage()));
     layer->SetLinearInterpolation(true);
-    layer->SetPixelSpacing(message.GetInstanceParameters().GetPixelSpacingX(),
-                           message.GetInstanceParameters().GetPixelSpacingY());
 
     {
       std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
--- a/OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp	Tue Feb 01 10:40:35 2022 +0100
+++ b/OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp	Sun Mar 20 15:13:57 2022 +0100
@@ -596,16 +596,16 @@
       throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
     }
 
+    std::unique_ptr<TextureBaseSceneLayer> texture;
+
     if (sourceFormat == Orthanc::PixelFormat_RGB24)
     {
       // This is the case of a color image. No conversion has to be done.
-      return new ColorTextureSceneLayer(pixelData);
+      texture.reset(new ColorTextureSceneLayer(pixelData));
     }
     else
     {
       // This is the case of a grayscale frame. Convert it to Float32.
-      std::unique_ptr<FloatTextureSceneLayer> texture;
-
       if (pixelData.GetFormat() == Orthanc::PixelFormat_Float32)
       {
         texture.reset(new FloatTextureSceneLayer(pixelData));
@@ -616,27 +616,34 @@
         texture.reset(new FloatTextureSceneLayer(*converted));
       }
 
+      FloatTextureSceneLayer& floatTexture = dynamic_cast<FloatTextureSceneLayer&>(*texture);
+
       if (GetWindowingPresetsCount() > 0)
       {
-        texture->SetCustomWindowing(GetWindowingPresetCenter(0), GetWindowingPresetWidth(0));
+        floatTexture.SetCustomWindowing(GetWindowingPresetCenter(0), GetWindowingPresetWidth(0));
       }
       
       switch (GetImageInformation().GetPhotometricInterpretation())
       {
         case Orthanc::PhotometricInterpretation_Monochrome1:
-          texture->SetInverted(true);
+          floatTexture.SetInverted(true);
           break;
           
         case Orthanc::PhotometricInterpretation_Monochrome2:
-          texture->SetInverted(false);
+          floatTexture.SetInverted(false);
           break;
 
         default:
           break;
       }
+    }
 
-      return texture.release();
+    if (HasPixelSpacing())
+    {
+      texture->SetPixelSpacing(GetPixelSpacingX(), GetPixelSpacingY());
     }
+    
+    return texture.release();
   }