annotate Applications/Samples/WebAssembly/SingleFrameViewer/SingleFrameViewerApp.js @ 1870:3889ae96d2e9

added copyright UCLouvain
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Jan 2022 11:04:09 +0100
parents 9ac2a65d4172
children 7053b8a0aaec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1589
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
1 /**
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
2 * Stone of Orthanc
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
4 * Department, University Hospital of Liege, Belgium
1739
9ac2a65d4172 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
1870
3889ae96d2e9 added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
6 * Copyright (C) 2021-2021 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1589
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
7 *
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
8 * This program is free software: you can redistribute it and/or
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
9 * modify it under the terms of the GNU Affero General Public License
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
11 * the License, or (at your option) any later version.
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
12 *
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
13 * This program is distributed in the hope that it will be useful, but
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
16 * Affero General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1589
diff changeset
17 *
1589
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
18 * You should have received a copy of the GNU Affero General Public License
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
20 **/
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
21
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
22
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
23 // This object wraps the functions exposed by the wasm module
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
24
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
25 const WasmModuleWrapper = function() {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
26 this._InitializeViewport = undefined;
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1388
diff changeset
27 this._LoadFromOrthanc = undefined;
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
28 };
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
29
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
30 WasmModuleWrapper.prototype.Setup = function(Module) {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
31 this._InitializeViewport = Module.cwrap('InitializeViewport', null, [ 'string' ]);
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
32 this._LoadFromOrthanc = Module.cwrap('LoadFromOrthanc', null, [ 'string', 'int' ]);
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
33 };
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
34
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
35 WasmModuleWrapper.prototype.InitializeViewport = function(canvasId) {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
36 this._InitializeViewport(canvasId);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
37 };
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
38
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
39 WasmModuleWrapper.prototype.LoadFromOrthanc = function(instance, frame) {
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
40 this._LoadFromOrthanc(instance, frame);
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
41 };
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
42
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
43 var wasmModuleWrapper = new WasmModuleWrapper();
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
44
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
45 $(document).ready(function() {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
46
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
47 window.addEventListener('WasmModuleInitialized', function() {
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
48 wasmModuleWrapper.Setup(Module);
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
49 console.warn('Native C++ module initialized');
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
51 wasmModuleWrapper.InitializeViewport('viewport');
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
52 });
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
53
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54 window.addEventListener('StoneException', function() {
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
55 alert('Exception caught in C++ code');
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
56 });
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
57
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
58 var scriptSource;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
59
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60 if ('WebAssembly' in window) {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
61 console.warn('Loading WebAssembly');
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
62 scriptSource = 'SingleFrameViewerWasm.js';
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
63 } else {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
64 console.error('Your browser does not support WebAssembly!');
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
65 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
66
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
67 // Option 1: Loading script using plain HTML
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
68
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
69 /*
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
70 var script = document.createElement('script');
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
71 script.src = scriptSource;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
72 script.type = 'text/javascript';
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
73 document.body.appendChild(script);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
74 */
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
75
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
76 // Option 2: Loading script using AJAX (gives the opportunity to
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
77 // report explicit errors)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
78
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
79 axios.get(scriptSource)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
80 .then(function (response) {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
81 var script = document.createElement('script');
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
82 script.innerHTML = response.data;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
83 script.type = 'text/javascript';
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
84 document.body.appendChild(script);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
85 })
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
86 .catch(function (error) {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
87 alert('Cannot load the WebAssembly framework');
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
88 });
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
89 });
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
90
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
91
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
92 $('#orthancLoad').click(function() {
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
93 wasmModuleWrapper.LoadFromOrthanc($('#orthancInstance').val(),
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
94 $('#orthancFrame').val());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
95 });