changeset 1519:22d1bd085c19

split STONE_BINARIES into two different vars for both StoneWebViewer and RtViewer + fixed docker build + embed of RtViewer files + serving of RtViewer files + Orthanc explorer extension to open a series in the RtViewer : sibling series will be traversed and the first DOSE/STRUCT will be used. WARNING: needs work for PT and to allow for missing dose
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 31 Jul 2020 12:51:28 +0200
parents 433cf964838d
children 3a79d551dd8b
files StoneWebViewer/Plugin/CMakeLists.txt StoneWebViewer/Plugin/OrthancExplorer.js StoneWebViewer/Plugin/Plugin.cpp StoneWebViewer/Plugin/docker-internal.sh
diffstat 4 files changed, 130 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/StoneWebViewer/Plugin/CMakeLists.txt	Fri Jul 31 12:47:27 2020 +0200
+++ b/StoneWebViewer/Plugin/CMakeLists.txt	Fri Jul 31 12:51:28 2020 +0200
@@ -14,7 +14,8 @@
 
 
 
-set(STONE_BINARIES CACHE PATH "Path to the binaries of the \"../WebAssembly\" folder")
+set(STONE_BINARIES_WEB_VIEWER CACHE PATH "Path to the binaries of the WebViewer \"../WebAssembly\" folder")
+set(STONE_BINARIES_RT_VIEWER CACHE PATH "Path to the binaries of the RtViewer \"../WebAssembly\" folder")
 
 # Parameters of the build
 set(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)")
@@ -70,15 +71,23 @@
 
 
 EmbedResources(
-  # Folders
-  IMAGES                 ${STONE_BINARIES}/img/
+  # Web Viewer Folders
+  IMAGES                 ${STONE_BINARIES_WEB_VIEWER}/img/
   WEB_APPLICATION        ${CMAKE_SOURCE_DIR}/../WebApplication
 
-  # Individual files
+  # Explorer extension code
   ORTHANC_EXPLORER       ${CMAKE_SOURCE_DIR}/OrthancExplorer.js
-  STONE_WEB_VIEWER_JS    ${STONE_BINARIES}/StoneWebViewer.js
-  STONE_WEB_VIEWER_WASM  ${STONE_BINARIES}/StoneWebViewer.wasm
-  STONE_WRAPPER          ${STONE_BINARIES}/stone.js
+
+  # Web viewer individual files
+  STONE_WEB_VIEWER_JS    ${STONE_BINARIES_WEB_VIEWER}/StoneWebViewer.js
+  STONE_WEB_VIEWER_WASM  ${STONE_BINARIES_WEB_VIEWER}/StoneWebViewer.wasm
+  STONE_WRAPPER          ${STONE_BINARIES_WEB_VIEWER}/stone.js
+
+  # RtViewer folder
+  RT_VIEWER_WASM_JS      ${STONE_BINARIES_RT_VIEWER}/RtViewerWasm.js
+  RT_VIEWER_WASM         ${STONE_BINARIES_RT_VIEWER}/RtViewerWasm.wasm
+  RT_VIEWER_WASM_APP_JS  ${STONE_BINARIES_RT_VIEWER}/RtViewerWasmApp.js
+  RT_VIEWER_INDEX_HTML   ${STONE_BINARIES_RT_VIEWER}/index.html
   )
 
 add_library(StoneWebViewer SHARED
--- a/StoneWebViewer/Plugin/OrthancExplorer.js	Fri Jul 31 12:47:27 2020 +0200
+++ b/StoneWebViewer/Plugin/OrthancExplorer.js	Fri Jul 31 12:51:28 2020 +0200
@@ -55,3 +55,91 @@
     }
   });
 });
+
+$('#series').live('pagebeforecreate', function() {
+  var b = $('<a>')
+      .attr('data-role', 'button')
+      .attr('href', '#')
+      .attr('data-icon', 'search')
+      .attr('data-theme', 'e')
+      .text('Stone MPR RT Viewer');``
+
+  b.insertBefore($('#series-delete').parent().parent());
+  b.click(function() {
+    if ($.mobile.pageData) {
+      $.ajax({
+        url: '../series/' + $.mobile.pageData.uuid,
+        dataType: 'json',
+        cache: false,
+        success: function(series) {
+
+          // we consider that the imaging series to display is the 
+          // current one.
+          // we will look for RTDOSE and RTSTRUCT instances in the 
+          // sibling series from the same study. The first one of 
+          // each modality will be grabbed.
+          let ctSeries = $.mobile.pageData.uuid;
+
+          $.ajax({
+            url: '../studies/' + series.ParentStudy,
+            dataType: 'json',
+            cache: false,
+            success: function(study) {
+              // Loop on the study series and find the first RTSTRUCT and RTDOSE instances,
+              // if any.
+              let rtStructInstance = null;
+              let rtDoseInstance = null;
+              let rtPetInstance = null;
+              let seriesRequests = []
+
+              study.Series.forEach( function(studySeriesUuid) {
+                let request = $.ajax({
+                  url: '../series/' + studySeriesUuid,
+                  dataType: 'json',
+                  cache: false,
+                });
+                seriesRequests.push(request);
+              });
+
+              $.when.apply($,seriesRequests).then(function() {
+                [].forEach.call(arguments, function(response) {
+                  siblingSeries = response[0]
+                  if (siblingSeries.MainDicomTags.Modality == "RTDOSE") {
+                    // we have found an RTDOSE series. Let's grab the first instance
+                    if (siblingSeries.Instances.length > 0) {
+                      if(rtDoseInstance == null) {
+                        rtDoseInstance = siblingSeries.Instances[0];
+                      }
+                    }
+                  }
+                  if (siblingSeries.MainDicomTags.Modality == "PT") {
+                    // we have found an RTDOSE series. Let's grab the first instance
+                    if (siblingSeries.Instances.length > 0) {
+                      if(rtPetInstance == null) {
+                        rtPetInstance = siblingSeries.Instances[0];
+                      }
+                    }
+                  }
+                  if (siblingSeries.MainDicomTags.Modality == "RTSTRUCT") {
+                    // we have found an RTDOSE series. Let's grab the first instance
+                    if (siblingSeries.Instances.length > 0) {
+                      if(rtStructInstance == null) {
+                        rtStructInstance = siblingSeries.Instances[0];
+                      }
+                    }
+                  }
+                });
+                let mprViewerUrl = '../stone-rtviewer/index.html?ctseries=' + ctSeries + 
+                '&rtdose=' + rtDoseInstance + 
+                '&rtstruct=' + rtStructInstance;
+                //console.log("About to open: " + mprViewerUrl);
+                window.open(mprViewerUrl);
+              });
+            }
+          });      
+        }
+      });      
+    }
+  });
+});
+
--- a/StoneWebViewer/Plugin/Plugin.cpp	Fri Jul 31 12:47:27 2020 +0200
+++ b/StoneWebViewer/Plugin/Plugin.cpp	Fri Jul 31 12:51:28 2020 +0200
@@ -191,6 +191,8 @@
         explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER);
       OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), explorer.c_str());
       
+      // Stone Web Viewer files
+      // ---------------------
       OrthancPlugins::RegisterRestCallback
         <ServeEmbeddedFile<Orthanc::EmbeddedResources::STONE_WEB_VIEWER_WASM> >
         ("/stone-webviewer/StoneWebViewer.wasm", true);
@@ -211,6 +213,28 @@
         <ServeEmbeddedFolder<Orthanc::EmbeddedResources::WEB_APPLICATION> >
         ("/stone-webviewer/(.*)", true);
 
+      // RtViewer files below.
+      // ---------------------
+      // we do not serve the whole directory at once (with ServeEmbeddedFolder)
+      // because it contains uppercase characters that are forbidden by the
+      // resource embedding system
+
+      OrthancPlugins::RegisterRestCallback
+        <ServeEmbeddedFile<Orthanc::EmbeddedResources::RT_VIEWER_WASM_JS> >
+        ("/stone-rtviewer/RtViewerWasm.js", true);
+
+      OrthancPlugins::RegisterRestCallback
+        <ServeEmbeddedFile<Orthanc::EmbeddedResources::RT_VIEWER_WASM> >
+        ("/stone-rtviewer/RtViewerWasm.wasm", true);
+
+      OrthancPlugins::RegisterRestCallback
+        <ServeEmbeddedFile<Orthanc::EmbeddedResources::RT_VIEWER_WASM_APP_JS> >
+        ("/stone-rtviewer/RtViewerWasmApp.js", true);
+
+      OrthancPlugins::RegisterRestCallback
+        <ServeEmbeddedFile<Orthanc::EmbeddedResources::RT_VIEWER_INDEX_HTML> >
+        ("/stone-rtviewer/index.html", true);
+
       OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback);
     }
     catch (...)
--- a/StoneWebViewer/Plugin/docker-internal.sh	Fri Jul 31 12:47:27 2020 +0200
+++ b/StoneWebViewer/Plugin/docker-internal.sh	Fri Jul 31 12:51:28 2020 +0200
@@ -20,7 +20,8 @@
       -DCMAKE_TOOLCHAIN_FILE=/tmp/orthanc/OrthancFramework/Resources/Toolchains/LinuxStandardBaseToolchain.cmake \
       -DORTHANC_FRAMEWORK_ROOT=/tmp/orthanc/OrthancFramework \
       -DSTATIC_BUILD=ON \
-      -DSTONE_BINARIES=/target/StoneWebViewer/ \
+      -DSTONE_BINARIES_WEB_VIEWER=/target/StoneWebViewer/ \
+      -DSTONE_BINARIES_RT_VIEWER=/target/RtViewer/ \
       -DUSE_LEGACY_JSONCPP=ON \
       -G Ninja