changeset 1757:28979b77ce90

Suppressed one pass on the dose distribution computation
author bgo@SHARKNADO.localdomain
date Mon, 26 Apr 2021 17:37:54 +0200
parents 1a775f4ee672
children 4ee11b8773e2
files OrthancStone/Sources/Loaders/OrthancMultiframeVolumeLoader.cpp OrthancStone/Sources/Loaders/OrthancMultiframeVolumeLoader.h
diffstat 2 files changed, 20 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancStone/Sources/Loaders/OrthancMultiframeVolumeLoader.cpp	Mon Apr 26 12:05:40 2021 +0200
+++ b/OrthancStone/Sources/Loaders/OrthancMultiframeVolumeLoader.cpp	Mon Apr 26 17:37:54 2021 +0200
@@ -269,7 +269,7 @@
 
   template <typename T>
   void OrthancMultiframeVolumeLoader::CopyPixelDataAndComputeDistribution(
-    const std::string& pixelData, std::map<T,uint64_t>& distribution)
+    const std::string& pixelData, std::map<T, PixelCount>& distribution)
   {
 #if STONE_TIME_BLOCKING_OPS
     boost::posix_time::ptime timerStart = boost::posix_time::microsec_clock::universal_time();
@@ -294,6 +294,7 @@
     }
 
     // first pass to initialize map
+#if 0
     {
       const uint8_t* source = reinterpret_cast<const uint8_t*>(pixelData.c_str());
 
@@ -311,6 +312,7 @@
         }
       }
     }
+#endif
 
     {
       const uint8_t* source = reinterpret_cast<const uint8_t*>(pixelData.c_str());
@@ -351,7 +353,7 @@
           {
             CopyPixel(*targetAddrPix, source);
 
-            distribution[*targetAddrPix] += 1;
+            distribution[*targetAddrPix].count_ += 1;
 
             targetAddrPix++;
             source += bpp;
@@ -372,7 +374,7 @@
 
   template <typename T>
   void OrthancMultiframeVolumeLoader::ComputeMinMaxWithOutlierRejection(
-    const std::map<T, uint64_t>& distribution)
+    const std::map<T, PixelCount>& distribution)
   {
     if (distribution.size() == 0)
     {
@@ -391,15 +393,14 @@
       // compute number of values and check (assertion) that it is equal to 
       // width * height * depth 
       {
-        typename std::map<T, uint64_t>::const_iterator it = distribution.begin();
+        typename std::map<T, PixelCount>::const_iterator it = distribution.begin();
         uint64_t totalCount = 0;
         distributionRawMin_ = static_cast<float>(it->first);
 
         while (it != distribution.end())
         {
           T pixelValue = it->first;
-          uint64_t count = it->second;
-          totalCount += count;
+          totalCount += it->second.count_;
           ++it;
           if (it == distribution.end())
             distributionRawMax_ = static_cast<float>(pixelValue);
@@ -436,14 +437,14 @@
       // then start from start and remove pixel values up to 
       // endRejectionCount voxels rejected
       {
-        typename std::map<T, uint64_t>::const_iterator it = distribution.begin();
+        typename std::map<T, PixelCount>::const_iterator it = distribution.begin();
         
         uint64_t currentCount = 0;
 
         while (it != distribution.end())
         {
           T pixelValue = it->first;
-          uint64_t count = it->second;
+          uint64_t count = it->second.count_;
 
           // if this pixelValue crosses the rejection threshold, let's set it
           // and exit the loop
@@ -468,14 +469,14 @@
       // now start from END and remove pixel values up to 
       // endRejectionCount voxels rejected
       {
-        typename std::map<T, uint64_t>::const_reverse_iterator it = distribution.rbegin();
+        typename std::map<T, PixelCount>::const_reverse_iterator it = distribution.rbegin();
 
         uint64_t currentCount = 0;
 
         while (it != distribution.rend())
         {
           T pixelValue = it->first;
-          uint64_t count = it->second;
+          uint64_t count = it->second.count_;
 
           if ((currentCount <= endRejectionCount) &&
               (currentCount + count > endRejectionCount))
@@ -506,7 +507,7 @@
   void OrthancMultiframeVolumeLoader::CopyPixelDataAndComputeMinMax(
     const std::string& pixelData)
   {
-    std::map<T, uint64_t> distribution;
+    std::map<T, PixelCount> distribution;
     CopyPixelDataAndComputeDistribution(pixelData, distribution);
     ComputeMinMaxWithOutlierRejection(distribution);
   }
--- a/OrthancStone/Sources/Loaders/OrthancMultiframeVolumeLoader.h	Mon Apr 26 12:05:40 2021 +0200
+++ b/OrthancStone/Sources/Loaders/OrthancMultiframeVolumeLoader.h	Mon Apr 26 17:37:54 2021 +0200
@@ -41,6 +41,12 @@
     class LoadTransferSyntax;    
     class LoadUncompressedPixelData;
 
+    struct PixelCount
+    {
+        uint64_t count_;
+        PixelCount() { count_ = 0; }
+    };
+
     boost::shared_ptr<DicomVolumeImage>  volume_;
     std::string                          instanceId_;
     std::string                          transferSyntaxUid_;
@@ -81,11 +87,11 @@
     /** Service method for CopyPixelDataAndComputeMinMax*/
     template <typename T>
     void CopyPixelDataAndComputeDistribution(const std::string& pixelData, 
-                                             std::map<T, uint64_t>& distribution);
+                                             std::map<T, PixelCount>& distribution);
 
     /** Service method for CopyPixelDataAndComputeMinMax*/
     template <typename T>
-    void ComputeMinMaxWithOutlierRejection(const std::map<T, uint64_t>& distribution);
+    void ComputeMinMaxWithOutlierRejection(const std::map<T, PixelCount>& distribution);
 
     void SetUncompressedPixelData(const std::string& pixelData);