changeset 834:c51b12fb4f34

Merge
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 31 May 2019 15:21:50 +0200
parents d492c3b71c65 (current diff) d71cf8504159 (diff)
children 0965b665c653
files
diffstat 6 files changed, 85 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Oracle/WebAssemblyOracle.cpp	Fri May 31 15:21:27 2019 +0200
+++ b/Framework/Oracle/WebAssemblyOracle.cpp	Fri May 31 15:21:50 2019 +0200
@@ -279,7 +279,7 @@
 
     void SetUri(const std::string& uri)
     {
-      uri_ = uri;
+      uri_ = oracle_.orthancRoot_ + uri;
     }
 
     void SetBody(std::string& body /* will be swapped */)
--- a/Framework/Oracle/WebAssemblyOracle.h	Fri May 31 15:21:27 2019 +0200
+++ b/Framework/Oracle/WebAssemblyOracle.h	Fri May 31 15:21:50 2019 +0200
@@ -59,11 +59,18 @@
     void Execute(const IObserver& receiver,
                  GetOrthancWebViewerJpegCommand* command);
 
+    std::string orthancRoot_;
+
   public:
     WebAssemblyOracle(MessageBroker& broker) :
       IObservable(broker)
     {
     }
+
+    void SetOrthancRoot(const std::string& root)
+    {
+      orthancRoot_ = root;
+    }
     
     virtual void Schedule(const IObserver& receiver,
                           IOracleCommand* command);
--- a/Samples/WebAssembly/BasicMPR.cpp	Fri May 31 15:21:27 2019 +0200
+++ b/Samples/WebAssembly/BasicMPR.cpp	Fri May 31 15:21:50 2019 +0200
@@ -318,7 +318,27 @@
     }
   };
 
-  static TestSleep testSleep(broker_, oracle_);
+  //static TestSleep testSleep(broker_, oracle_);
+}
+
+
+
+static std::map<std::string, std::string> arguments_;
+
+static bool GetArgument(std::string& value,
+                        const std::string& key)
+{
+  std::map<std::string, std::string>::const_iterator found = arguments_.find(key);
+
+  if (found == arguments_.end())
+  {
+    return false;
+  }
+  else
+  {
+    value = found->second;
+    return true;
+  }
 }
 
 
@@ -333,10 +353,20 @@
   }
 
   EMSCRIPTEN_KEEPALIVE
+  void SetArgument(const char* key, const char* value)
+  {
+    // This is called for each GET argument (cf. "app.js")
+    LOG(INFO) << "Received GET argument: [" << key << "] = [" << value << "]";
+    arguments_[key] = value;
+  }
+
+  EMSCRIPTEN_KEEPALIVE
   void Initialize()
   {
     try
     {
+      oracle_.SetOrthancRoot("..");
+      
       loader_.reset(new OrthancStone::OrthancSeriesVolumeProgressiveLoader(ct_, oracle_, oracle_));
     
       widget1_.reset(new OrthancStone::VolumeSlicerWidget(broker_, "mycanvas1", OrthancStone::VolumeProjection_Axial));
@@ -362,7 +392,17 @@
     
       emscripten_request_animation_frame_loop(OnAnimationFrame, NULL);
 
-      loader_->LoadSeries("a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa");
+
+      std::string ct;
+      if (GetArgument(ct, "ct"))
+      {
+        //loader_->LoadSeries("a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa");
+        loader_->LoadSeries(ct);
+      }
+      else
+      {
+        LOG(ERROR) << "No Orthanc identifier for the CT series was provided";
+      }
     }
     catch (Orthanc::OrthancException& e)
     {
--- a/Samples/WebAssembly/BasicMPR.html	Fri May 31 15:21:27 2019 +0200
+++ b/Samples/WebAssembly/BasicMPR.html	Fri May 31 15:21:50 2019 +0200
@@ -54,16 +54,7 @@
     <canvas id="mycanvas2" oncontextmenu="return false;"></canvas>
     <canvas id="mycanvas3" oncontextmenu="return false;"></canvas>
 
-    <script type="text/javascript">
-      if (!('WebAssembly' in window)) {
-      alert('Sorry, your browser does not support WebAssembly :(');
-      } else {
-      window.addEventListener('WebAssemblyLoaded', function() {
-      Module.ccall('Initialize', null, null, null);
-      });
-      }
-    </script>
-
+    <script type="text/javascript" src="app.js"></script>
     <script type="text/javascript" async src="BasicMPR.js"></script>
   </body>
 </html>
--- a/Samples/WebAssembly/CMakeLists.txt	Fri May 31 15:21:27 2019 +0200
+++ b/Samples/WebAssembly/CMakeLists.txt	Fri May 31 15:21:50 2019 +0200
@@ -105,6 +105,7 @@
   ${CMAKE_SOURCE_DIR}/BasicMPR.html
   ${CMAKE_SOURCE_DIR}/BasicScene.html
   ${CMAKE_SOURCE_DIR}/Configuration.json
+  ${CMAKE_SOURCE_DIR}/app.js
   ${CMAKE_SOURCE_DIR}/index.html
   DESTINATION ${CMAKE_INSTALL_PREFIX}
   )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/WebAssembly/app.js	Fri May 31 15:21:50 2019 +0200
@@ -0,0 +1,33 @@
+/**
+ * This is a generic bootstrap code that is shared by all the Stone
+ * sample applications.
+ **/
+
+// Check support for WebAssembly
+if (!('WebAssembly' in window)) {
+  alert('Sorry, your browser does not support WebAssembly :(');
+} else {
+
+  // Wait for the module to be loaded (the event "WebAssemblyLoaded"
+  // must be emitted by the "main" function)
+  window.addEventListener('WebAssemblyLoaded', function() {
+
+    // Loop over the GET arguments
+    var parameters = window.location.search.substr(1);
+    if (parameters != null && parameters != '') {
+      var tokens = parameters.split('&');
+      for (var i = 0; i < tokens.length; i++) {
+        var arg = tokens[i].split('=');
+        if (arg.length == 2) {
+
+          // Send each GET argument to WebAssembly
+          Module.ccall('SetArgument', null, [ 'string', 'string' ],
+                       [ arg[0], decodeURIComponent(arg[1]) ]);
+        }
+      }
+    }
+
+    // Inform the WebAssembly module that it can start
+    Module.ccall('Initialize', null, null, null);
+  });
+}