diff Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp @ 1679:5b8b88e5bfd6

successfully running unit tests in WebAssembly
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 24 Nov 2020 12:59:10 +0100
parents 51bab5188a13
children 03afa09cfcf1
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Tue Nov 24 07:40:19 2020 +0100
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Tue Nov 24 12:59:10 2020 +0100
@@ -1102,21 +1102,26 @@
       {
         OrthancStone::DicomInstanceParameters params(dicom);
 
-        // TODO - WINDOWING
-        if (params.GetPresetWindowingsCount() > 0)
+        for (size_t i = 0; i < params.GetWindowingPresetsCount(); i++)
         {
-          GetViewport().presetWindowingCenter_ = params.GetPresetWindowingCenter(0);
-          GetViewport().presetWindowingWidth_ = params.GetPresetWindowingWidth(0);
-          LOG(INFO) << "Preset windowing: " << params.GetPresetWindowingCenter(0)
-                    << "," << params.GetPresetWindowingWidth(0);
-
-          GetViewport().windowingCenter_ = params.GetPresetWindowingCenter(0);
-          GetViewport().windowingWidth_ = params.GetPresetWindowingWidth(0);
+          LOG(INFO) << "Preset windowing " << i << "/" << params.GetWindowingPresetsCount()
+                    << ": " << params.GetWindowingPresetCenter(i)
+                    << "," << params.GetWindowingPresetWidth(i);
+        }
+
+        // TODO - WINDOWING
+        if (params.GetWindowingPresetsCount() > 0)
+        {
+          GetViewport().presetWindowingCenter_ = params.GetWindowingPresetCenter(0);
+          GetViewport().presetWindowingWidth_ = params.GetWindowingPresetWidth(0);
+
+          GetViewport().windowingCenter_ = params.GetWindowingPresetCenter(0);
+          GetViewport().windowingWidth_ = params.GetWindowingPresetWidth(0);
         }
         else
         {
           LOG(INFO) << "No preset windowing";
-          GetViewport().ResetPresetWindowing();
+          GetViewport().ResetWindowingPreset();
         }
       }
 
@@ -1411,7 +1416,7 @@
   }
   
   
-  void ResetPresetWindowing()
+  void ResetWindowingPreset()
   {
     presetWindowingCenter_ = 128;
     presetWindowingWidth_ = 256;
@@ -1790,7 +1795,7 @@
     emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, OnKey);
     emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, OnKey);
 
-    ResetPresetWindowing();
+    ResetWindowingPreset();
   }
 
   static EM_BOOL OnKey(int eventType,
@@ -1898,7 +1903,7 @@
 
     LOG(INFO) << "Number of frames in series: " << frames_->GetFramesCount();
 
-    ResetPresetWindowing();
+    ResetWindowingPreset();
     ClearViewport();
     prefetchQueue_.clear();
 
@@ -2127,7 +2132,7 @@
   }
 
 
-  void SetPresetWindowing()
+  void SetWindowingPreset()
   {
     SetWindowing(presetWindowingCenter_, presetWindowingWidth_);
   }
@@ -2328,6 +2333,11 @@
   {
     return cineRate_;
   }
+
+  void FormatWindowingPresets(Json::Value& target) const
+  {
+    target = Json::arrayValue;
+  }
 };
 
 
@@ -2818,11 +2828,11 @@
 
 
   EMSCRIPTEN_KEEPALIVE
-  void SetPresetWindowing(const char* canvas)
+  void SetWindowingPreset(const char* canvas)
   {
     try
     {
-      GetViewport(canvas)->SetPresetWindowing();
+      GetViewport(canvas)->SetWindowingPreset();
     }
     EXTERN_CATCH_EXCEPTIONS;
   }  
@@ -3017,5 +3027,18 @@
     }
     EXTERN_CATCH_EXCEPTIONS;
     return 0;
-  }    
+  }
+
+
+  EMSCRIPTEN_KEEPALIVE
+  void LoadWindowingPresets(const char* canvas)
+  {
+    try
+    {
+      Json::Value v;
+      GetViewport(canvas)->FormatWindowingPresets(v);
+      stringBuffer_ = v.toStyledString();
+    }
+    EXTERN_CATCH_EXCEPTIONS;
+  }
 }