# HG changeset patch # User Benjamin Golinvaux # Date 1559308910 -7200 # Node ID c51b12fb4f345bc9623eb370e7539eb8186748d2 # Parent d492c3b71c65406fecebc79ea000db7944831144# Parent d71cf85041597aa79a5c113f895a25601430aed8 Merge diff -r d492c3b71c65 -r c51b12fb4f34 Framework/Oracle/WebAssemblyOracle.cpp --- a/Framework/Oracle/WebAssemblyOracle.cpp Fri May 31 15:21:27 2019 +0200 +++ b/Framework/Oracle/WebAssemblyOracle.cpp Fri May 31 15:21:50 2019 +0200 @@ -279,7 +279,7 @@ void SetUri(const std::string& uri) { - uri_ = uri; + uri_ = oracle_.orthancRoot_ + uri; } void SetBody(std::string& body /* will be swapped */) diff -r d492c3b71c65 -r c51b12fb4f34 Framework/Oracle/WebAssemblyOracle.h --- a/Framework/Oracle/WebAssemblyOracle.h Fri May 31 15:21:27 2019 +0200 +++ b/Framework/Oracle/WebAssemblyOracle.h Fri May 31 15:21:50 2019 +0200 @@ -59,11 +59,18 @@ void Execute(const IObserver& receiver, GetOrthancWebViewerJpegCommand* command); + std::string orthancRoot_; + public: WebAssemblyOracle(MessageBroker& broker) : IObservable(broker) { } + + void SetOrthancRoot(const std::string& root) + { + orthancRoot_ = root; + } virtual void Schedule(const IObserver& receiver, IOracleCommand* command); diff -r d492c3b71c65 -r c51b12fb4f34 Samples/WebAssembly/BasicMPR.cpp --- a/Samples/WebAssembly/BasicMPR.cpp Fri May 31 15:21:27 2019 +0200 +++ b/Samples/WebAssembly/BasicMPR.cpp Fri May 31 15:21:50 2019 +0200 @@ -318,7 +318,27 @@ } }; - static TestSleep testSleep(broker_, oracle_); + //static TestSleep testSleep(broker_, oracle_); +} + + + +static std::map arguments_; + +static bool GetArgument(std::string& value, + const std::string& key) +{ + std::map::const_iterator found = arguments_.find(key); + + if (found == arguments_.end()) + { + return false; + } + else + { + value = found->second; + return true; + } } @@ -333,10 +353,20 @@ } EMSCRIPTEN_KEEPALIVE + void SetArgument(const char* key, const char* value) + { + // This is called for each GET argument (cf. "app.js") + LOG(INFO) << "Received GET argument: [" << key << "] = [" << value << "]"; + arguments_[key] = value; + } + + EMSCRIPTEN_KEEPALIVE void Initialize() { try { + oracle_.SetOrthancRoot(".."); + loader_.reset(new OrthancStone::OrthancSeriesVolumeProgressiveLoader(ct_, oracle_, oracle_)); widget1_.reset(new OrthancStone::VolumeSlicerWidget(broker_, "mycanvas1", OrthancStone::VolumeProjection_Axial)); @@ -362,7 +392,17 @@ emscripten_request_animation_frame_loop(OnAnimationFrame, NULL); - loader_->LoadSeries("a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa"); + + std::string ct; + if (GetArgument(ct, "ct")) + { + //loader_->LoadSeries("a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa"); + loader_->LoadSeries(ct); + } + else + { + LOG(ERROR) << "No Orthanc identifier for the CT series was provided"; + } } catch (Orthanc::OrthancException& e) { diff -r d492c3b71c65 -r c51b12fb4f34 Samples/WebAssembly/BasicMPR.html --- a/Samples/WebAssembly/BasicMPR.html Fri May 31 15:21:27 2019 +0200 +++ b/Samples/WebAssembly/BasicMPR.html Fri May 31 15:21:50 2019 +0200 @@ -54,16 +54,7 @@ - - + diff -r d492c3b71c65 -r c51b12fb4f34 Samples/WebAssembly/CMakeLists.txt --- a/Samples/WebAssembly/CMakeLists.txt Fri May 31 15:21:27 2019 +0200 +++ b/Samples/WebAssembly/CMakeLists.txt Fri May 31 15:21:50 2019 +0200 @@ -105,6 +105,7 @@ ${CMAKE_SOURCE_DIR}/BasicMPR.html ${CMAKE_SOURCE_DIR}/BasicScene.html ${CMAKE_SOURCE_DIR}/Configuration.json + ${CMAKE_SOURCE_DIR}/app.js ${CMAKE_SOURCE_DIR}/index.html DESTINATION ${CMAKE_INSTALL_PREFIX} ) diff -r d492c3b71c65 -r c51b12fb4f34 Samples/WebAssembly/app.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/WebAssembly/app.js Fri May 31 15:21:50 2019 +0200 @@ -0,0 +1,33 @@ +/** + * This is a generic bootstrap code that is shared by all the Stone + * sample applications. + **/ + +// Check support for WebAssembly +if (!('WebAssembly' in window)) { + alert('Sorry, your browser does not support WebAssembly :('); +} else { + + // Wait for the module to be loaded (the event "WebAssemblyLoaded" + // must be emitted by the "main" function) + window.addEventListener('WebAssemblyLoaded', function() { + + // Loop over the GET arguments + var parameters = window.location.search.substr(1); + if (parameters != null && parameters != '') { + var tokens = parameters.split('&'); + for (var i = 0; i < tokens.length; i++) { + var arg = tokens[i].split('='); + if (arg.length == 2) { + + // Send each GET argument to WebAssembly + Module.ccall('SetArgument', null, [ 'string', 'string' ], + [ arg[0], decodeURIComponent(arg[1]) ]); + } + } + } + + // Inform the WebAssembly module that it can start + Module.ccall('Initialize', null, null, null); + }); +}