diff Framework/Toolbox/GeometryToolbox.cpp @ 32:517c46f527cd

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 19 Dec 2016 11:00:23 +0100
parents ff1e935768e7
children 7207a407bcd8
line wrap: on
line diff
--- a/Framework/Toolbox/GeometryToolbox.cpp	Fri Dec 16 15:41:20 2016 +0100
+++ b/Framework/Toolbox/GeometryToolbox.cpp	Mon Dec 19 11:00:23 2016 +0100
@@ -32,6 +32,7 @@
 
 #include "GeometryToolbox.h"
 
+#include "../../Resources/Orthanc/Core/Logging.h"
 #include "../../Resources/Orthanc/Core/OrthancException.h"
 #include "../../Resources/Orthanc/Core/Toolbox.h"
 
@@ -77,6 +78,16 @@
     }
 
 
+    bool ParseVector(Vector& target,
+                     const OrthancPlugins::IDicomDataset& dataset,
+                     const OrthancPlugins::DicomPath& tag)
+    {
+      std::string value;
+      return (dataset.GetStringValue(value, tag) &&
+              ParseVector(target, value));
+    }
+
+
     void AssignVector(Vector& v,
                       double v1,
                       double v2)
@@ -347,5 +358,36 @@
         return true;
       }
     }
+
+
+    void GetPixelSpacing(double& spacingX, 
+                         double& spacingY,
+                         const OrthancPlugins::IDicomDataset& dicom)
+    {
+      Vector v;
+
+      if (ParseVector(v, dicom, OrthancPlugins::DICOM_TAG_PIXEL_SPACING))
+      {
+        if (v.size() != 2 ||
+            v[0] <= 0 ||
+            v[1] <= 0)
+        {
+          LOG(ERROR) << "Bad value for PixelSpacing tag";
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
+        }
+        else
+        {
+          spacingX = v[0];
+          spacingY = v[1];
+        }
+      }
+      else
+      {
+        // The "PixelSpacing" is of type 1C: It could be absent, use
+        // default value in such a case
+        spacingX = 1;
+        spacingY = 1;
+      }
+    }
   }
 }