changeset 1714:a878e807cd96

configuration option "DicomCacheSize", warning if cache should be larger
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 30 Nov 2020 17:57:10 +0100
parents aec45e0b2528
children 1952162474c3
files Applications/StoneWebViewer/WebApplication/app.js Applications/StoneWebViewer/WebApplication/configuration.json Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp OrthancStone/Sources/Toolbox/ParsedDicomCache.cpp OrthancStone/Sources/Toolbox/ParsedDicomCache.h
diffstat 5 files changed, 75 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebApplication/app.js	Mon Nov 30 17:09:46 2020 +0100
+++ b/Applications/StoneWebViewer/WebApplication/app.js	Mon Nov 30 17:57:10 2020 +0100
@@ -1023,6 +1023,11 @@
   stone.SetDicomWebRoot(app.globalConfiguration.DicomWebRoot,
                         true /* assume "/rendered" is available in DICOMweb (could be a configuration option) */);
   stone.SetSoftwareRendering(localStorage.settingSoftwareRendering == '1');
+
+  if ('DicomCacheSize' in app.globalConfiguration) {
+    stone.SetDicomCacheSize(app.globalConfiguration.DicomCacheSize);
+  }
+  
   console.warn('Stone properly initialized');
 
   app.SetCombinedToolActions();
@@ -1176,29 +1181,30 @@
 
 
 window.addEventListener('message', function(e) {
-  if ('type' in e.data &&
-      (e.data.type == 'show-osirix-annotations')) {
-    var expectedOrigin = app.globalConfiguration['ExpectedMessageOrigin'];
-    
-    if (expectedOrigin === undefined) {
-      alert('Dynamic actions are disabled in the Stone Web viewer, ' +
-            'set the configuration option "ExpectedMessageOrigin".');
-    }    
-    else if (expectedOrigin != '*' &&
-             e.origin !== expectedOrigin) {
-      alert('Bad origin for a dynamic action in the Stone Web viewer: "' + e.origin +
-            '", whereas the message must have origin: "' + expectedOrigin + '"');
+  if ('type' in e.data) {
+    if (e.data.type == 'show-osirix-annotations') {
+      var expectedOrigin = app.globalConfiguration['ExpectedMessageOrigin'];
+      
+      if (expectedOrigin === undefined) {
+        alert('Dynamic actions are disabled in the Stone Web viewer, ' +
+              'set the configuration option "ExpectedMessageOrigin".');
+      }    
+      else if (expectedOrigin != '*' &&
+               e.origin !== expectedOrigin) {
+        alert('Bad origin for a dynamic action in the Stone Web viewer: "' + e.origin +
+              '", whereas the message must have origin: "' + expectedOrigin + '"');
+      }
+      else if (e.data.type == 'show-osirix-annotations') {
+        var clear = true;  // Whether to clear previous annotations
+        if ('clear' in e.data) {
+          clear = e.data.clear;
+        }
+        
+        app.LoadOsiriXAnnotations(e.data.xml, clear);
+      }
     }
-    else if (e.data.type == 'show-osirix-annotations') {
-      var clear = true;  // Whether to clear previous annotations
-      if ('clear' in e.data) {
-        clear = e.data.clear;
-      }
-      
-      app.LoadOsiriXAnnotations(e.data.xml, clear);
+    else {
+      console.log('Unknown type of dynamic action in the Stone Web viewer: ' + e.data.type);
     }
   }
-  else {
-    console.log('Unknown type of dynamic action in the Stone Web viewer: ' + e.data.type);
-  }
 });
--- a/Applications/StoneWebViewer/WebApplication/configuration.json	Mon Nov 30 17:09:46 2020 +0100
+++ b/Applications/StoneWebViewer/WebApplication/configuration.json	Mon Nov 30 17:57:10 2020 +0100
@@ -69,6 +69,16 @@
      * set by the Orthanc plugin if missing.
      **/
     "DicomWebRoot" : "../dicom-web",
+
+    /**
+     * Set the size of the cache that stores the DICOM files. This
+     * size is expressed in megabytes. The default value of 128MB
+     * should work in most setups, except if very large multiframe
+     * instances are encountered, which might for instance be the case
+     * for mammography. Setting this parameter to zero will disable
+     * the cache, which should only be done for testing.
+     **/
+    "DicomCacheSize" : 128,
     
     /**
      * The following parameter can be set if running the Stone Web
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Mon Nov 30 17:09:46 2020 +0100
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Mon Nov 30 17:57:10 2020 +0100
@@ -2922,6 +2922,29 @@
   
 
   EMSCRIPTEN_KEEPALIVE
+  void SetDicomCacheSize(int sizeMB)
+  {
+    try
+    {
+      if (sizeMB == 0)
+      {
+        LOG(WARNING) << "The DICOM cache is disabled";
+      }
+      else
+      {
+        LOG(INFO) << "The DICOM cache size is set to " << sizeMB << "MB";
+      }
+
+      if (sizeMB >= 0)
+      {
+        context_->SetDicomCacheSize(sizeMB * 1024 * 1024);
+      }
+    }
+    EXTERN_CATCH_EXCEPTIONS;
+  }
+  
+
+  EMSCRIPTEN_KEEPALIVE
   void FetchAllStudies()
   {
     try
--- a/OrthancStone/Sources/Toolbox/ParsedDicomCache.cpp	Mon Nov 30 17:09:46 2020 +0100
+++ b/OrthancStone/Sources/Toolbox/ParsedDicomCache.cpp	Mon Nov 30 17:57:10 2020 +0100
@@ -82,6 +82,17 @@
                                  bool hasPixelData)
   {
     LOG(TRACE) << "new item stored in cache: bucket " << bucket << ", key " << bucketKey;
+
+    if (lowCacheSizeWarning_ < fileSize &&
+        cache_.GetMaximumSize() > 0 &&
+        fileSize >= cache_.GetMaximumSize())
+    {
+      lowCacheSizeWarning_ = fileSize;
+      LOG(WARNING) << "The DICOM cache size should be larger: Storing a DICOM instance of "
+                   << (fileSize / (1024 * 1024)) << "MB, whereas the cache size is only "
+                   << (cache_.GetMaximumSize() / (1024 * 1024)) << "MB wide";
+    }
+    
     cache_.Acquire(GetIndex(bucket, bucketKey), new Item(dicom, fileSize, hasPixelData));
   }
 
--- a/OrthancStone/Sources/Toolbox/ParsedDicomCache.h	Mon Nov 30 17:09:46 2020 +0100
+++ b/OrthancStone/Sources/Toolbox/ParsedDicomCache.h	Mon Nov 30 17:57:10 2020 +0100
@@ -36,9 +36,11 @@
                                 const std::string& bucketKey);
     
     Orthanc::MemoryObjectCache  cache_;
+    size_t                      lowCacheSizeWarning_;
 
   public:
-    explicit ParsedDicomCache(size_t size)
+    explicit ParsedDicomCache(size_t size) :
+      lowCacheSizeWarning_(0)
     {
       cache_.SetMaximumSize(size);
     }