changeset 1144:7d23c43ba555 broker

integration mainline->broker
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 08 Nov 2019 18:14:59 +0100
parents 6333e6f7248e (current diff) e2212644eab3 (diff)
children 4f99c7905f8d
files
diffstat 3 files changed, 54 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Thu Nov 07 16:53:15 2019 +0100
+++ b/.hgtags	Fri Nov 08 18:14:59 2019 +0100
@@ -38,3 +38,4 @@
 df76d308303107cdd327790d3a92b58fa4500f76 toa2019102302
 640feb146fa8186ac4e5ecb87d18b267750ccec3 toa2019102801
 33b0a762e98ade4e1f00e26bf865b417269443fb toa2019110401
+76705b430c78d4ca0a718c6164ac4b73ce007fde toa2019110801
--- a/Framework/Toolbox/DicomInstanceParameters.cpp	Thu Nov 07 16:53:15 2019 +0100
+++ b/Framework/Toolbox/DicomInstanceParameters.cpp	Fri Nov 08 18:14:59 2019 +0100
@@ -115,33 +115,50 @@
 
       if (!dicom.LookupStringValue(doseUnits_, DICOM_TAG_DOSE_UNITS, false))
       {
-        LOG(WARNING) << "Tag DoseUnits (0x3004, 0x0002) is missing in " << sopInstanceUid_;
+        LOG(ERROR) << "Tag DoseUnits (0x3004, 0x0002) is missing in " << sopInstanceUid_;
         doseUnits_ = "";
       }
-
     }
 
     isColor_ = (imageInformation_.GetPhotometricInterpretation() != Orthanc::PhotometricInterpretation_Monochrome1 &&
                 imageInformation_.GetPhotometricInterpretation() != Orthanc::PhotometricInterpretation_Monochrome2);
 
-    double doseGridScaling;
-
     if (dicom.ParseDouble(rescaleIntercept_, Orthanc::DICOM_TAG_RESCALE_INTERCEPT) &&
         dicom.ParseDouble(rescaleSlope_, Orthanc::DICOM_TAG_RESCALE_SLOPE))
     {
-      hasRescale_ = true;
-    }
-    else if (dicom.ParseDouble(doseGridScaling, Orthanc::DICOM_TAG_DOSE_GRID_SCALING))
-    {
-      hasRescale_ = true;
-      rescaleIntercept_ = 0;
-      rescaleSlope_ = doseGridScaling;
+      if (sopClassUid_ == SopClassUid_RTDose)
+      {
+        LOG(INFO) << "DOSE HAS Rescale*: rescaleIntercept_ = " << rescaleIntercept_ << " rescaleSlope_ = " << rescaleSlope_;
+        // WE SHOULD NOT TAKE THE RESCALE VALUE INTO ACCOUNT IN THE CASE OF DOSES
+        hasRescale_ = false;
+      }
+      else
+      {
+        hasRescale_ = true;
+      }
+      
     }
     else
     {
       hasRescale_ = false;
     }
 
+    if (dicom.ParseDouble(doseGridScaling_, Orthanc::DICOM_TAG_DOSE_GRID_SCALING))
+    {
+      if (sopClassUid_ == SopClassUid_RTDose)
+      {
+        LOG(INFO) << "DOSE HAS DoseGridScaling: doseGridScaling_ = " << doseGridScaling_;
+      }
+    }
+    else
+    {
+      doseGridScaling_ = 1.0;
+      if (sopClassUid_ == SopClassUid_RTDose)
+      {
+        LOG(ERROR) << "Tag DoseGridScaling (0x3004, 0x000e) is missing in " << sopInstanceUid_ << " doseGridScaling_ will be set to 1.0";
+      }
+    }
+
     Vector c, w;
     if (LinearAlgebra::ParseVector(c, dicom, Orthanc::DICOM_TAG_WINDOW_CENTER) &&
         LinearAlgebra::ParseVector(w, dicom, Orthanc::DICOM_TAG_WINDOW_WIDTH) &&
@@ -155,6 +172,8 @@
     else
     {
       hasDefaultWindowing_ = false;
+      defaultWindowingCenter_ = 0;
+      defaultWindowingWidth_  = 0;
     }
 
     if (sopClassUid_ == SopClassUid_RTDose)
@@ -245,16 +264,25 @@
   }
 
       
-  void DicomInstanceParameters::Data::ApplyRescale(Orthanc::ImageAccessor& image,
+  void DicomInstanceParameters::Data::ApplyRescaleAndDoseScaling(Orthanc::ImageAccessor& image,
                                                    bool useDouble) const
   {
     if (image.GetFormat() != Orthanc::PixelFormat_Float32)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
     }
-    
+
+    double factor = doseGridScaling_;
+    double offset = 0.0;
+
     if (hasRescale_)
     {
+      factor *= rescaleSlope_;
+      offset = rescaleIntercept_;
+    }
+
+    if ( (factor != 1.0) || (offset != 0.0) )
+    {
       const unsigned int width = image.GetWidth();
       const unsigned int height = image.GetHeight();
         
@@ -268,7 +296,7 @@
           for (unsigned int x = 0; x < width; x++, p++)
           {
             double value = static_cast<double>(*p);
-            *p = static_cast<float>(value * rescaleSlope_ + rescaleIntercept_);
+            *p = static_cast<float>(value * factor + offset);
           }
         }
         else
@@ -276,7 +304,7 @@
           // Fast, approximate implementation using float
           for (unsigned int x = 0; x < width; x++, p++)
           {
-            *p = (*p) * static_cast<float>(rescaleSlope_) + static_cast<float>(rescaleIntercept_);
+            *p = (*p) * static_cast<float>(factor) + static_cast<float>(offset);
           }
         }
       }
@@ -348,8 +376,8 @@
     Orthanc::ImageProcessing::Convert(*converted, pixelData);
 
     // Correct rescale slope/intercept if need be
-    //data_.ApplyRescale(*converted, (pixelData.GetFormat() == Orthanc::PixelFormat_Grayscale32));
-    data_.ApplyRescale(*converted, false);
+    //data_.ApplyRescaleAndDoseScaling(*converted, (pixelData.GetFormat() == Orthanc::PixelFormat_Grayscale32));
+    data_.ApplyRescaleAndDoseScaling(*converted, false);
 
     return converted.release();
   }
--- a/Framework/Toolbox/DicomInstanceParameters.h	Thu Nov 07 16:53:15 2019 +0100
+++ b/Framework/Toolbox/DicomInstanceParameters.h	Fri Nov 08 18:14:59 2019 +0100
@@ -60,6 +60,7 @@
       bool                              hasIndexInSeries_;
       unsigned int                      indexInSeries_;
       std::string                       doseUnits_;
+      double                            doseGridScaling_;
 
       void ComputeDoseOffsets(const Orthanc::DicomMap& dicom);
 
@@ -70,8 +71,8 @@
       bool IsPlaneWithinSlice(unsigned int frame,
                               const CoordinateSystem3D& plane) const;
       
-      void ApplyRescale(Orthanc::ImageAccessor& image,
-                        bool useDouble) const;
+      void ApplyRescaleAndDoseScaling(
+        Orthanc::ImageAccessor& image, bool useDouble) const;
     };
 
     
@@ -205,5 +206,10 @@
     {
       return data_.doseUnits_;
     }
+
+    double GetDoseGridScaling() const
+    {
+      return data_.doseGridScaling_;
+    }
   };
 }