changeset 370:5fb0dfa5c155

do not fill the imaged volume width/height tags without information
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Mar 2025 13:59:23 +0100
parents 3adb57efc32f
children 9ff5782c6a8b
files Applications/Dicomizer.cpp NEWS
diffstat 2 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Dicomizer.cpp	Mon Mar 17 13:27:36 2025 +0100
+++ b/Applications/Dicomizer.cpp	Mon Mar 17 13:59:23 2025 +0100
@@ -481,8 +481,14 @@
     OrthancWSI::DicomToolbox::SetStringTag(dataset, DCM_LossyImageCompression, "00");
   }
 
-  OrthancWSI::DicomToolbox::SetStringTag(dataset, DCM_ImagedVolumeWidth, boost::lexical_cast<std::string>(volume.GetWidth()));
-  OrthancWSI::DicomToolbox::SetStringTag(dataset, DCM_ImagedVolumeHeight, boost::lexical_cast<std::string>(volume.GetHeight()));
+  if (volume.HasWidth() ||
+      volume.HasHeight())
+  {
+    // In WSI <= 3.0, these two fields were filled even if no information about the imaged volume size was available
+    OrthancWSI::DicomToolbox::SetStringTag(dataset, DCM_ImagedVolumeWidth, boost::lexical_cast<std::string>(volume.GetWidth()));
+    OrthancWSI::DicomToolbox::SetStringTag(dataset, DCM_ImagedVolumeHeight, boost::lexical_cast<std::string>(volume.GetHeight()));
+  }
+
   OrthancWSI::DicomToolbox::SetStringTag(dataset, DCM_ImagedVolumeDepth, boost::lexical_cast<std::string>(volume.GetDepth()));
 
   std::unique_ptr<DcmItem> origin(new DcmItem);
@@ -1222,14 +1228,23 @@
         throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
       }
 
-      // In the 2 lines below, remember to switch X/Y when going from physical to pixel coordinates!
-      float pixelSpacingX = volume.GetWidth() / static_cast<float>(source->GetLevelHeight(0));
-      float pixelSpacingY = volume.GetHeight() / static_cast<float>(source->GetLevelWidth(0));
-      if (std::abs(pixelSpacingX - pixelSpacingY) >= 100.0f * std::numeric_limits<float>::epsilon())
+      if (volume.HasWidth() ||
+          volume.HasHeight())
       {
-        LOG(WARNING) << "Your pixel spacing is different along the X and Y axes, make sure that "
-                     << "you have not inversed the --" << OPTION_IMAGED_WIDTH << " and the --"
-                     << OPTION_IMAGED_HEIGHT << " options: " << pixelSpacingX << " vs. " << pixelSpacingY;
+        // In the 2 lines below, remember to switch X/Y when going from physical to pixel coordinates!
+        float pixelSpacingX = volume.GetWidth() / static_cast<float>(source->GetLevelHeight(0));
+        float pixelSpacingY = volume.GetHeight() / static_cast<float>(source->GetLevelWidth(0));
+        if (std::abs(pixelSpacingX - pixelSpacingY) >= 100.0f * std::numeric_limits<float>::epsilon())
+        {
+          LOG(WARNING) << "Your pixel spacing is different along the X and Y axes, make sure that "
+                       << "you have not inversed the --" << OPTION_IMAGED_WIDTH << " and the --"
+                       << OPTION_IMAGED_HEIGHT << " options: " << pixelSpacingX << " vs. " << pixelSpacingY;
+        }
+      }
+      else
+      {
+        LOG(WARNING) << "Unknown imaged volume size, use the --" << OPTION_IMAGED_WIDTH << " and the --"
+                     << OPTION_IMAGED_HEIGHT << " options to fill the (0048,0001) and (0048,0002) DICOM tags";
       }
 
       LOG(WARNING) << "Compression of the individual source tiles: " << OrthancWSI::EnumerationToString(sourceCompression);
--- a/NEWS	Mon Mar 17 13:27:36 2025 +0100
+++ b/NEWS	Mon Mar 17 13:59:23 2025 +0100
@@ -3,6 +3,8 @@
 
 * Upgraded to OpenLayers 10.4.0 (was previously 3.19.0)
 * The viewer now displays the scale if the imaged volume size is available
+* OrthancWSIDicomizer does not fill anymore the imaged volume width/height
+  tags if no information is available
 * Fix handling of "Image Type" in the viewer for compatibility with other vendors
 
 Compatibility notes about the viewer