annotate Applications/Samples/WebAssembly/SingleFrameViewer/SingleFrameViewerApp.js @ 1787:6e8105942146

safeguard in TextureBaseSceneLayer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 15 May 2021 11:47:55 +0200
parents 9ac2a65d4172
children 3889ae96d2e9
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
1589
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
6 *
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
7 * 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
8 * 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
9 * 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
10 * the License, or (at your option) any later version.
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
11 *
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
12 * 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
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
15 * Affero General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1589
diff changeset
16 *
1589
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
17 * 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
18 * 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
19 **/
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
20
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
21
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
22 // This object wraps the functions exposed by the wasm module
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
23
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
24 const WasmModuleWrapper = function() {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
25 this._InitializeViewport = undefined;
1393
27e0a00bd3e8 RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1388
diff changeset
26 this._LoadFromOrthanc = undefined;
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
27 };
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 WasmModuleWrapper.prototype.Setup = function(Module) {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
30 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
31 this._LoadFromOrthanc = Module.cwrap('LoadFromOrthanc', null, [ 'string', 'int' ]);
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
32 };
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 WasmModuleWrapper.prototype.InitializeViewport = function(canvasId) {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
35 this._InitializeViewport(canvasId);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
36 };
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
37
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
38 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
39 this._LoadFromOrthanc(instance, frame);
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
40 };
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
41
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
42 var wasmModuleWrapper = new WasmModuleWrapper();
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
43
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
44 $(document).ready(function() {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
45
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
46 window.addEventListener('WasmModuleInitialized', function() {
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
47 wasmModuleWrapper.Setup(Module);
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
48 console.warn('Native C++ module initialized');
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
49
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
50 wasmModuleWrapper.InitializeViewport('viewport');
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
51 });
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 window.addEventListener('StoneException', function() {
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
54 alert('Exception caught in C++ code');
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55 });
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 var scriptSource;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
58
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
59 if ('WebAssembly' in window) {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60 console.warn('Loading WebAssembly');
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
61 scriptSource = 'SingleFrameViewerWasm.js';
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
62 } else {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
63 console.error('Your browser does not support WebAssembly!');
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
64 }
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 // Option 1: Loading script using plain HTML
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
67
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 var script = document.createElement('script');
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
70 script.src = scriptSource;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
71 script.type = 'text/javascript';
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
72 document.body.appendChild(script);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
73 */
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 // Option 2: Loading script using AJAX (gives the opportunity to
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
76 // report explicit errors)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
77
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
78 axios.get(scriptSource)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
79 .then(function (response) {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
80 var script = document.createElement('script');
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
81 script.innerHTML = response.data;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
82 script.type = 'text/javascript';
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
83 document.body.appendChild(script);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
84 })
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
85 .catch(function (error) {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
86 alert('Cannot load the WebAssembly framework');
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
87 });
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 $('#orthancLoad').click(function() {
1388
240531afdd2d Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1354
diff changeset
92 wasmModuleWrapper.LoadFromOrthanc($('#orthancInstance').val(),
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
93 $('#orthancFrame').val());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
94 });