changeset 876:580dd82e13f5 am-dev

added GetApproximateMemoryUsage
author Alain Mazy <alain@mazy.be>
date Wed, 03 Jul 2019 10:15:29 +0200
parents 200b4e0dddfc
children f7e5ee59ba17
files Framework/Radiography/RadiographyDicomLayer.h Framework/Radiography/RadiographyLayer.h Framework/Radiography/RadiographyMaskLayer.h Framework/Radiography/RadiographyScene.cpp Framework/Radiography/RadiographyScene.h
diffstat 5 files changed, 45 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Radiography/RadiographyDicomLayer.h	Wed Jul 03 10:12:09 2019 +0200
+++ b/Framework/Radiography/RadiographyDicomLayer.h	Wed Jul 03 10:15:29 2019 +0200
@@ -60,6 +60,22 @@
       return frame_;
     }
 
+    virtual size_t GetApproximateMemoryUsage() const
+    {
+      size_t size = 0;
+      if (source_.get() != NULL)
+      {
+        size += source_->GetPitch() * source_->GetHeight();
+      }
+      if (converted_.get() != NULL)
+      {
+        size += converted_->GetPitch() * converted_->GetHeight();
+      }
+
+      return size;
+    }
+
+
     void SetDicomTags(const OrthancPlugins::FullOrthancDataset& dataset);
 
     void SetSourceImage(Orthanc::ImageAccessor* image);   // Takes ownership
--- a/Framework/Radiography/RadiographyLayer.h	Wed Jul 03 10:12:09 2019 +0200
+++ b/Framework/Radiography/RadiographyLayer.h	Wed Jul 03 10:15:29 2019 +0200
@@ -355,5 +355,10 @@
                           float& maxValue) const = 0;
 
     friend class RadiographyMaskLayer; // because it needs to GetTransform on the dicomLayer it relates to
+
+    virtual size_t GetApproximateMemoryUsage() const // this is used to limit the number of scenes loaded in RAM when resources are limited (we actually only count the size used by the images, not the C structs)
+    {
+      return 0;
+    }
   };
 }
--- a/Framework/Radiography/RadiographyMaskLayer.h	Wed Jul 03 10:12:09 2019 +0200
+++ b/Framework/Radiography/RadiographyMaskLayer.h	Wed Jul 03 10:15:29 2019 +0200
@@ -49,6 +49,18 @@
     {
     }
 
+    virtual size_t GetApproximateMemoryUsage() const
+    {
+      size_t size = 0;
+      if (mask_.get() != NULL)
+      {
+        size += mask_->GetPitch() * mask_->GetHeight();
+      }
+
+      return size;
+    }
+
+
     void SetCorners(const std::vector<Orthanc::ImageProcessing::ImagePoint>& corners);
     void SetCorner(const Orthanc::ImageProcessing::ImagePoint& corner, size_t index);
 
--- a/Framework/Radiography/RadiographyScene.cpp	Wed Jul 03 10:12:09 2019 +0200
+++ b/Framework/Radiography/RadiographyScene.cpp	Wed Jul 03 10:15:29 2019 +0200
@@ -147,6 +147,16 @@
     return *layer;
   }
 
+  size_t RadiographyScene::GetApproximateMemoryUsage() const
+  {
+    size_t size = 0;
+    for (Layers::const_iterator it = layers_.begin(); it != layers_.end(); it++)
+    {
+      size += it->second->GetApproximateMemoryUsage();
+    }
+    return size;
+  }
+
   void RadiographyScene::OnLayerEdited(const RadiographyLayer::LayerEditedMessage& message)
   {
     BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, message.GetOrigin()));
--- a/Framework/Radiography/RadiographyScene.h	Wed Jul 03 10:12:09 2019 +0200
+++ b/Framework/Radiography/RadiographyScene.h	Wed Jul 03 10:15:29 2019 +0200
@@ -163,6 +163,8 @@
     
     virtual ~RadiographyScene();
 
+    virtual size_t GetApproximateMemoryUsage() const;
+
     bool GetWindowing(float& center,
                       float& width) const;