changeset 238:126c9c0c9333 am

SimpleViewer demo running both with SDL and Wasm
author am@osimis.io
date Wed, 20 Jun 2018 09:25:39 +0200
parents b4642964c355
children 72b711f22a2b
files Applications/Samples/SampleList.h Applications/Samples/SampleMainWasm.cpp Applications/Samples/Web/index.html Applications/Samples/Web/samples-styles.css Applications/Samples/Web/simple-viewer.html Applications/Samples/Web/simple-viewer.ts Applications/Samples/Web/tsconfig-simple-viewer.json Applications/Samples/samples-library.js Platforms/Wasm/defaults.js Platforms/Wasm/stone-framework-loader.ts Platforms/Wasm/wasm-application.ts
diffstat 9 files changed, 205 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Applications/Samples/SampleList.h	Wed Jun 20 09:25:39 2018 +0200
@@ -0,0 +1,37 @@
+// The macro "ORTHANC_STONE_SAMPLE" must be set by the CMake script
+
+#if ORTHANC_STONE_SAMPLE == 1
+#include "EmptyApplication.h"
+typedef OrthancStone::Samples::EmptyApplication Application;
+
+#elif ORTHANC_STONE_SAMPLE == 2
+#include "TestPatternApplication.h"
+typedef OrthancStone::Samples::TestPatternApplication Application;
+
+#elif ORTHANC_STONE_SAMPLE == 3
+#include "SingleFrameApplication.h"
+typedef OrthancStone::Samples::SingleFrameApplication Application;
+
+#elif ORTHANC_STONE_SAMPLE == 4
+#include "SingleVolumeApplication.h"
+typedef OrthancStone::Samples::SingleVolumeApplication Application;
+
+#elif ORTHANC_STONE_SAMPLE == 5
+#include "BasicPetCtFusionApplication.h"
+typedef OrthancStone::Samples::BasicPetCtFusionApplication Application;
+
+#elif ORTHANC_STONE_SAMPLE == 6
+#include "SynchronizedSeriesApplication.h"
+typedef OrthancStone::Samples::SynchronizedSeriesApplication Application;
+
+#elif ORTHANC_STONE_SAMPLE == 7
+#include "LayoutPetCtFusionApplication.h"
+typedef OrthancStone::Samples::LayoutPetCtFusionApplication Application;
+
+#elif ORTHANC_STONE_SAMPLE == 8
+#include "SimpleViewerApplication.h"
+typedef OrthancStone::Samples::SimpleViewerApplication Application;
+
+#else
+#error Please set the ORTHANC_STONE_SAMPLE macro
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Applications/Samples/SampleMainWasm.cpp	Wed Jun 20 09:25:39 2018 +0200
@@ -0,0 +1,37 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2018 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "Platforms/Wasm/WasmWebService.h"
+#include "Platforms/Wasm/WasmViewport.h"
+
+#include <emscripten/emscripten.h>
+
+#include "SampleList.h"
+
+
+OrthancStone::BasicWasmApplication* CreateUserApplication() {
+  
+  printf("C++: CreateUserApplication\n");
+  OrthancStone::WidgetViewport* viewport = CreateWasmViewportFromCpp("canvas");  
+  OrthancStone::WidgetViewport* viewport2 = CreateWasmViewportFromCpp("canvas2");  
+  printf("C++: CreateUserApplication - wasm viewport created\n");
+  
+  return new Application(viewport, viewport2);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Applications/Samples/Web/index.html	Wed Jun 20 09:25:39 2018 +0200
@@ -0,0 +1,21 @@
+<!doctype html>
+
+<html lang="us">
+  <head>
+    <meta charset="utf-8" />
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+
+    <!-- Disable pinch zoom on mobile devices -->
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
+    <meta name="HandheldFriendly" content="true" />
+
+    <title>Wasm Samples</title>
+    <link href="samples-styles.css" rel="stylesheet" />
+
+<body>
+    <ul>
+        <li><a href="simple-viewer.html">Simple Viewer</a></li>
+    </ul>
+</body>
+
+</html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Applications/Samples/Web/simple-viewer.html	Wed Jun 20 09:25:39 2018 +0200
@@ -0,0 +1,23 @@
+<!doctype html>
+
+<html lang="us">
+  <head>
+    <meta charset="utf-8" />
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+
+    <!-- Disable pinch zoom on mobile devices -->
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
+    <meta name="HandheldFriendly" content="true" />
+
+    <title>Simple Viewer</title>
+    <link href="samples-styles.css" rel="stylesheet" />
+
+<body>
+  <div>
+    <canvas id="canvas" data-width-ratio="20" data-height-ratio="50"></canvas>
+    <canvas id="canvas2" data-width-ratio="70" data-height-ratio="50"></canvas>
+  </div>
+  <script type="text/javascript" src="app-simple-viewer.js"></script>
+</body>
+
+</html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Applications/Samples/Web/simple-viewer.ts	Wed Jun 20 09:25:39 2018 +0200
@@ -0,0 +1,3 @@
+///<reference path='../../../Platforms/Wasm/wasm-application.ts'/>
+
+InitializeWasmApplication("OrthancStoneSimpleViewer");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Applications/Samples/Web/tsconfig-simple-viewer.json	Wed Jun 20 09:25:39 2018 +0200
@@ -0,0 +1,16 @@
+{
+    "compilerOptions": {
+        "outFile": "../../../Platforms/Wasm/build-web/app-simple-viewer.js",
+        "sourceMap": false,
+        "lib" : [
+            "es2017",
+            "dom"
+        ]
+    },
+    "include" : [
+        "simple-viewer.ts",
+        "../../../Platforms/Wasm/stone-framework-loader.ts",
+        "../../../Platforms/Wasm/wasm-application.ts",
+        "../../../Platforms/Wasm/wasm-viewport.ts"
+    ]
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Applications/Samples/samples-library.js	Wed Jun 20 09:25:39 2018 +0200
@@ -0,0 +1,8 @@
+// this file contains the JS method you want to expose to C++ code
+
+// mergeInto(LibraryManager.library, {
+//    ScheduleRedraw: function() {
+//      ScheduleRedraw();
+//    }
+//  });
+  
\ No newline at end of file
--- a/Platforms/Wasm/stone-framework-loader.ts	Wed Jun 20 09:03:48 2018 +0200
+++ b/Platforms/Wasm/stone-framework-loader.ts	Wed Jun 20 09:25:39 2018 +0200
@@ -15,7 +15,12 @@
     export class Framework
     {
       private static singleton_ : Framework = null;
-    
+      private static wasmModuleName_ : string = null;
+
+      public static Configure(wasmModuleName: string) {
+        this.wasmModuleName_ = wasmModuleName;
+      }
+
       private constructor(verbose : boolean) 
       {
         //this.ccall('Initialize', null, [ 'number' ], [ verbose ]);
@@ -52,7 +57,7 @@
       public static Initialize(verbose: boolean,
                                callback: InitializationCallback)
       {
-        console.log('Initializing WebAssembly');
+        console.log('Initializing WebAssembly Module');
     
         (<any> window).StoneFrameworkModule = {
           preRun: [ 
@@ -83,7 +88,7 @@
         var script = document.createElement('script');
         script.type = 'application/javascript';
         //script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
-        script.src = "OrthancStoneSimpleViewer.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
+        script.src = this.wasmModuleName_ + ".js";//  "OrthancStoneSimpleViewer.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
         script.async = true;
         document.head.appendChild(script);
       }
--- a/Platforms/Wasm/wasm-application.ts	Wed Jun 20 09:03:48 2018 +0200
+++ b/Platforms/Wasm/wasm-application.ts	Wed Jun 20 09:25:39 2018 +0200
@@ -2,7 +2,7 @@
 ///<reference path='wasm-viewport.ts'/>
 
 if (!('WebAssembly' in window)) {
-    alert('Sorry, your browser does not support WebAssembly :(');
+  alert('Sorry, your browser does not support WebAssembly :(');
 }
 
 declare var StoneFrameworkModule : Stone.Framework;
@@ -19,83 +19,80 @@
 
 
 function UpdateContentThread() {
-    if (NotifyUpdateContent != null) {
-        NotifyUpdateContent();
-    }
+  if (NotifyUpdateContent != null) {
+    NotifyUpdateContent();
+  }
 
-    setTimeout(UpdateContentThread, 100);  // Update the viewport content every 100ms if need be
+  setTimeout(UpdateContentThread, 100);  // Update the viewport content every 100ms if need be
 }
 
 
 function GetUriParameters() {
-    var parameters = window.location.search.substr(1);
+  var parameters = window.location.search.substr(1);
 
-    if (parameters != null &&
-        parameters != '') {
-        var result = {};
-        var tokens = parameters.split('&');
+  if (parameters != null &&
+    parameters != '') {
+    var result = {};
+    var tokens = parameters.split('&');
 
-        for (var i = 0; i < tokens.length; i++) {
-            var tmp = tokens[i].split('=');
-            if (tmp.length == 2) {
-                result[tmp[0]] = decodeURIComponent(tmp[1]);
-            }
-        }
+    for (var i = 0; i < tokens.length; i++) {
+      var tmp = tokens[i].split('=');
+      if (tmp.length == 2) {
+        result[tmp[0]] = decodeURIComponent(tmp[1]);
+      }
+    }
 
-        return result;
-    }
-    else {
-        return {};
-    }
+    return result;
+  }
+  else {
+    return {};
+  }
 }
 
 module Stone {
 
-    //  export declare type InitializationCallback = () => void;
-
-    //  export declare var StoneFrameworkModule : any;
+  export class WasmApplication {
 
-    //const ASSETS_FOLDER : string = "assets/lib";
-    //const WASM_FILENAME : string = "orthanc-framework";
-
-    export class WasmApplication {
+    private viewport_: WasmViewport;
+    private canvasId_: string;
 
-        private viewport_: WasmViewport;
-        private canvasId_: string;
-
-        private pimpl_: any; // Private pointer to the underlying WebAssembly C++ object
+    private pimpl_: any; // Private pointer to the underlying WebAssembly C++ object
 
-        public constructor(canvasId: string) {
-            this.canvasId_ = canvasId;
-            //this.module_ = module;
-        }
+    public constructor(canvasId: string) {
+      this.canvasId_ = canvasId;
+      //this.module_ = module;
     }
+  }
 }
 
 
-function InitializeWasmApplication(canvasId: string): void {
+function _InitializeWasmApplication(canvasId: string): void {
 
-    /************************************** */
-    CreateWasmApplication();
+  /************************************** */
+  CreateWasmApplication();
 
-    // parse uri and transmit the parameters to the app before initializing it
-    var parameters = GetUriParameters();
+  // parse uri and transmit the parameters to the app before initializing it
+  var parameters = GetUriParameters();
 
-    for (var key in parameters) {
-        if (parameters.hasOwnProperty(key)) {
-            SetStartupParameter(key, parameters[key]);
-        }
+  for (var key in parameters) {
+    if (parameters.hasOwnProperty(key)) {
+      SetStartupParameter(key, parameters[key]);
     }
+  }
 
-    StartWasmApplication();
-    /************************************** */
+  StartWasmApplication();
+  /************************************** */
 
-    UpdateContentThread();
+  UpdateContentThread();
 }
 
-// Wait for the Orthanc Framework to be initialized (this initializes
-// the WebAssembly environment) and then, create and initialize the Wasm application
-Stone.Framework.Initialize(true, function () {
+function InitializeWasmApplication(wasmModuleName: string) {
+  
+  Stone.Framework.Configure(wasmModuleName);
+
+  // Wait for the Orthanc Framework to be initialized (this initializes
+  // the WebAssembly environment) and then, create and initialize the Wasm application
+  Stone.Framework.Initialize(true, function () {
 
     console.log("Connecting C++ methods to JS methods");
     
@@ -111,9 +108,9 @@
 
     // Prevent scrolling
     document.body.addEventListener('touchmove', function (event) {
-        event.preventDefault();
+      event.preventDefault();
     }, false);
 
-
-    InitializeWasmApplication("canvas");
-});
\ No newline at end of file
+    _InitializeWasmApplication("canvas");
+  });
+}
\ No newline at end of file