view Samples/WebAssembly/SingleFrameViewer/SingleFrameViewerApp.js @ 1388:240531afdd2d

Dead code removal + removed untested Dicomweb + SingleFrameViewer wasm fixes
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 28 Apr 2020 08:57:39 +0200
parents c0e4eb14c912
children 27e0a00bd3e8
line wrap: on
line source


// This object wraps the functions exposed by the wasm module

const WasmModuleWrapper = function() {
  this._InitializeViewport = undefined;
  this._LoadOrthanc = undefined;
  this._LoadDicomWeb = undefined;
};

WasmModuleWrapper.prototype.Setup = function(Module) {
  this._InitializeViewport = Module.cwrap('InitializeViewport', null, [ 'string' ]);
  this._LoadFromOrthanc = Module.cwrap('LoadFromOrthanc', null, [ 'string', 'int' ]);
  this._LoadFromDicomWeb = Module.cwrap('LoadFromDicomWeb', null, [ 'string', 'string', 'string', 'string', 'int' ]);
};

WasmModuleWrapper.prototype.InitializeViewport = function(canvasId) {
  this._InitializeViewport(canvasId);
};

WasmModuleWrapper.prototype.LoadFromOrthanc = function(instance, frame) {
  this._LoadFromOrthanc(instance, frame);
};

WasmModuleWrapper.prototype.LoadFromDicomWeb = function(server, studyInstanceUid, seriesInstanceUid, sopInstanceUid, frame) {
  this._LoadFromDicomWeb(server, studyInstanceUid, seriesInstanceUid, sopInstanceUid, frame);
};

var wasmModuleWrapper = new WasmModuleWrapper();

$(document).ready(function() {

  window.addEventListener('WasmModuleInitialized', function() {
    wasmModuleWrapper.Setup(Module);
    console.warn('Native C++ module initialized');

    wasmModuleWrapper.InitializeViewport('viewport');
  });

  window.addEventListener('StoneException', function() {
    alert('Exception caught in C++ code');
  });    

  var scriptSource;

  if ('WebAssembly' in window) {
    console.warn('Loading WebAssembly');
    scriptSource = 'SingleFrameViewerWasm.js';
  } else {
    console.error('Your browser does not support WebAssembly!');
  }

  // Option 1: Loading script using plain HTML
  
  /*
    var script = document.createElement('script');
    script.src = scriptSource;
    script.type = 'text/javascript';
    document.body.appendChild(script);
  */

  // Option 2: Loading script using AJAX (gives the opportunity to
  // report explicit errors)
  
  axios.get(scriptSource)
    .then(function (response) {
      var script = document.createElement('script');
      script.innerHTML = response.data;
      script.type = 'text/javascript';
      document.body.appendChild(script);
    })
    .catch(function (error) {
      alert('Cannot load the WebAssembly framework');
    });
});


$('#orthancLoad').click(function() {
  wasmModuleWrapper.LoadFromOrthanc($('#orthancInstance').val(),
                    $('#orthancFrame').val());
});