# HG changeset patch # User am@osimis.io # Date 1529479539 -7200 # Node ID 126c9c0c9333196513e35b890971a0ecc0bbe2b8 # Parent b4642964c355acd1ba5aead7d81181be112a8d21 SimpleViewer demo running both with SDL and Wasm diff -r b4642964c355 -r 126c9c0c9333 Applications/Samples/SampleList.h --- /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 diff -r b4642964c355 -r 126c9c0c9333 Applications/Samples/SampleMainWasm.cpp --- /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 . + **/ + +#include "Platforms/Wasm/WasmWebService.h" +#include "Platforms/Wasm/WasmViewport.h" + +#include + +#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 diff -r b4642964c355 -r 126c9c0c9333 Applications/Samples/Web/index.html --- /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 @@ + + + + + + + + + + + + Wasm Samples + + + + + + + \ No newline at end of file diff -r b4642964c355 -r 126c9c0c9333 Applications/Samples/Web/samples-styles.css diff -r b4642964c355 -r 126c9c0c9333 Applications/Samples/Web/simple-viewer.html --- /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 @@ + + + + + + + + + + + + Simple Viewer + + + +
+ + +
+ + + + \ No newline at end of file diff -r b4642964c355 -r 126c9c0c9333 Applications/Samples/Web/simple-viewer.ts --- /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 @@ +/// + +InitializeWasmApplication("OrthancStoneSimpleViewer"); diff -r b4642964c355 -r 126c9c0c9333 Applications/Samples/Web/tsconfig-simple-viewer.json --- /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 diff -r b4642964c355 -r 126c9c0c9333 Applications/Samples/samples-library.js --- /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 diff -r b4642964c355 -r 126c9c0c9333 Platforms/Wasm/defaults.js diff -r b4642964c355 -r 126c9c0c9333 Platforms/Wasm/stone-framework-loader.ts --- 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'); ( 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); } diff -r b4642964c355 -r 126c9c0c9333 Platforms/Wasm/wasm-application.ts --- 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 @@ /// 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