changeset 2186:e90ddb89c3ae

Fix loading of US images with a negative PhyiscalDeltaX value
author Alain Mazy <am@orthanc.team>
date Wed, 26 Mar 2025 17:18:33 +0100 (5 weeks ago)
parents 115628b0651d
children d3ae05435296
files Applications/StoneWebViewer/NEWS Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp OrthancStone/Sources/Messages/IObservable.cpp OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp
diffstat 4 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/NEWS	Thu Jan 23 11:59:11 2025 +0100
+++ b/Applications/StoneWebViewer/NEWS	Wed Mar 26 17:18:33 2025 +0100
@@ -9,6 +9,7 @@
 * New configuration "ScreenshotTemplate" to define the filename of the
   "download as JPEG" function.  New default value is:
   "{PatientID}-{PatientName}-{StudyDate}-{SeriesDescription}-{InstanceNumber}-{CurrentFrame}.jpg"
+* Fix loading of US images with a negative PhyiscalDeltaX value.
 
 
 Version 2.6 (2024-08-31)
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Thu Jan 23 11:59:11 2025 +0100
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Wed Mar 26 17:18:33 2025 +0100
@@ -2461,6 +2461,17 @@
       pixelSpacingY = centralPixelSpacingY_;
     }
 
+    // This hack has been introduced to fix an issue where the first US image of a series had negative PhysicalDeltaX value 
+    // while the other images from the series had different geometries.  layer->SetOrigin was failing later.
+    // At the end, it appears that the measures are corrects although we have set the pixelSpacing to 1m so the values are likely
+    // overwritten later on...
+    if (pixelSpacingX < 0 || pixelSpacingY < 0)
+    {
+      LOG(ERROR) << "Pixel spacings are invalid: " << pixelSpacingX << " " << pixelSpacingY << " setting dummy values to 1000, 1000 -> measures might be invalid !";
+      pixelSpacingX = 1000;
+      pixelSpacingY = 1000;
+    }
+
     if (FIX_LSD_479)
     {
       /**
--- a/OrthancStone/Sources/Messages/IObservable.cpp	Thu Jan 23 11:59:11 2025 +0100
+++ b/OrthancStone/Sources/Messages/IObservable.cpp	Wed Mar 26 17:18:33 2025 +0100
@@ -80,15 +80,17 @@
           {
             try
             {
+              // LOG(INFO) << "IN Handling message : " << message.GetIdentifier().AsString();
               (*it)->Apply(message);
+              // LOG(INFO) << "OUT Handling message : " << message.GetIdentifier().AsString();
             }
             catch (Orthanc::OrthancException& e)
             {
-              LOG(ERROR) << "Exception on callable: " << e.What();
+              LOG(ERROR) << "OrthancException on callable: " << e.What() << " " << message.GetIdentifier().AsString();
             }
             catch (StoneException& e)
             {
-              LOG(ERROR) << "Exception on callable: " << e.What();
+              LOG(ERROR) << "StoneException on callable: " << e.What();
             }
             catch (std::exception& e)
             {
--- a/OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp	Thu Jan 23 11:59:11 2025 +0100
+++ b/OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp	Wed Mar 26 17:18:33 2025 +0100
@@ -256,7 +256,7 @@
 
     if (!data_.hasPixelSpacing_ &&
         dataset.GetSequenceSize(size, Orthanc::DicomPath(DICOM_TAG_SEQUENCE_OF_ULTRASOUND_REGIONS)) &&
-        size == 1)
+        size >= 1)
     {
       int directionX, directionY;
       double deltaX, deltaY;