changeset 128:c993693e9e63 wasm

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 14 Nov 2017 17:26:10 +0100
parents b963f3a9a86c
children a823122db53d
files Applications/Samples/SingleVolumeApplication.h Framework/Layers/DicomStructureSetRendererFactory.cpp Framework/Layers/DicomStructureSetRendererFactory.h Framework/Toolbox/OrthancSlicesLoader.cpp Platforms/WebAssembly/CMakeLists.txt Resources/CMake/OrthancStoneParameters.cmake
diffstat 6 files changed, 60 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Samples/SingleVolumeApplication.h	Wed Nov 08 17:53:55 2017 +0100
+++ b/Applications/Samples/SingleVolumeApplication.h	Tue Nov 14 17:26:10 2017 +0100
@@ -211,12 +211,13 @@
         //pet->ScheduleLoadInstance("830a69ff-8e4b5ee3-b7f966c8-bccc20fb-d322dceb");  // IBA 3
         //pet->ScheduleLoadInstance("269f26f4-0c83eeeb-2e67abbd-5467a40f-f1bec90c");  // 0522c0001 TCIA
 
-        const std::string s = "54460695-ba3885ee-ddf61ac0-f028e31d-a6e474d9";  // IBA
-        //const std::string s = "17cd032b-ad92a438-ca05f06a-f9e96668-7e3e9e20";  // 0522c0001 TCIA
+        std::auto_ptr<DicomStructureSetRendererFactory> rtStruct(new DicomStructureSetRendererFactory(context.GetWebService()));
+        rtStruct->ScheduleLoadInstance("54460695-ba3885ee-ddf61ac0-f028e31d-a6e474d9");  // IBA
+        //rtStruct->ScheduleLoadInstance("17cd032b-ad92a438-ca05f06a-f9e96668-7e3e9e20");  // 0522c0001 TCIA
         
         widget->AddLayer(new VolumeImageSource(*ct));
         widget->AddLayer(new VolumeImageSource(*pet));
-        widget->AddLayer(new DicomStructureSetRendererFactory(context.GetWebService(), s));
+        widget->AddLayer(rtStruct.release());
         
         context.AddInteractor(new Interactor(*pet, *widget, projection, 1));
         //context.AddInteractor(new VolumeImageInteractor(*ct, *widget, projection));
--- a/Framework/Layers/DicomStructureSetRendererFactory.cpp	Wed Nov 08 17:53:55 2017 +0100
+++ b/Framework/Layers/DicomStructureSetRendererFactory.cpp	Tue Nov 14 17:26:10 2017 +0100
@@ -164,7 +164,7 @@
         for (std::set<std::string>::const_iterator it = instances.begin();
              it != instances.end(); ++it)
         {
-          orthanc_.SchedulePostRequest(*this, "/tools/lookup", *it,
+          orthanc_.SchedulePostRequest(loader_, "/tools/lookup", *it,
                                        new Operation(Operation::Type_LookupSopInstanceUid, *it));
         }
         
@@ -189,7 +189,7 @@
           }
 
           const std::string& instance = lookup[0]["ID"].asString();
-          orthanc_.ScheduleGetRequest(*this, "/instances/" + instance + "/tags",
+          orthanc_.ScheduleGetRequest(loader_, "/instances/" + instance + "/tags",
                                       new Operation(Operation::Type_LoadReferencedSlice, instance));
         }
         else
@@ -219,15 +219,27 @@
   } 
 
   
-  DicomStructureSetRendererFactory::DicomStructureSetRendererFactory(IWebService& orthanc,
-                                                                     const std::string& instance) :
+  DicomStructureSetRendererFactory::DicomStructureSetRendererFactory(IWebService& orthanc) :
+    loader_(*this),
     orthanc_(orthanc)
   {
-    const std::string uri = "/instances/" + instance + "/tags?ignore-length=3006-0050";
-    orthanc_.ScheduleGetRequest(*this, uri, new Operation(Operation::Type_LoadStructureSet, instance));
   }
   
+
+  void DicomStructureSetRendererFactory::ScheduleLoadInstance(const std::string& instance)
+  {
+    if (structureSet_.get() != NULL)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      const std::string uri = "/instances/" + instance + "/tags?ignore-length=3006-0050";
+      orthanc_.ScheduleGetRequest(loader_, uri, new Operation(Operation::Type_LoadStructureSet, instance));
+    }
+  }
   
+
   void DicomStructureSetRendererFactory::ScheduleLayerCreation(const CoordinateSystem3D& viewportSlice)
   {
     if (structureSet_.get() != NULL)
--- a/Framework/Layers/DicomStructureSetRendererFactory.h	Wed Nov 08 17:53:55 2017 +0100
+++ b/Framework/Layers/DicomStructureSetRendererFactory.h	Tue Nov 14 17:26:10 2017 +0100
@@ -27,13 +27,37 @@
 
 namespace OrthancStone
 {
-  class DicomStructureSetRendererFactory :
-    public LayerSourceBase,
-    private IWebService::ICallback
+  class DicomStructureSetRendererFactory : public LayerSourceBase
   {
   private:
     class Renderer;
     class Operation;
+    
+    class Loader : public IWebService::ICallback
+    {
+    private:
+      DicomStructureSetRendererFactory&  that_;
+
+    public:
+      Loader(DicomStructureSetRendererFactory& that) :
+        that_(that)
+      {
+      }
+
+      virtual void NotifyError(const std::string& uri,
+                               Orthanc::IDynamicObject* payload)
+      {
+        that_.NotifyError(uri, payload);
+      }
+
+      virtual void NotifySuccess(const std::string& uri,
+                                 const void* answer,
+                                 size_t answerSize,
+                                 Orthanc::IDynamicObject* payload)
+      {
+        that_.NotifySuccess(uri, answer, answerSize, payload);
+      }
+    };
 
     virtual void NotifyError(const std::string& uri,
                              Orthanc::IDynamicObject* payload);
@@ -43,12 +67,14 @@
                                size_t answerSize,
                                Orthanc::IDynamicObject* payload);
 
+    Loader                            loader_;
     IWebService&                      orthanc_;
     std::auto_ptr<DicomStructureSet>  structureSet_;
 
   public:
-    DicomStructureSetRendererFactory(IWebService& orthanc,
-                                     const std::string& instance);
+    DicomStructureSetRendererFactory(IWebService& orthanc);
+
+    void ScheduleLoadInstance(const std::string& instance);
 
     virtual bool GetExtent(std::vector<Vector>& points,
                            const CoordinateSystem3D& viewportSlice)
--- a/Framework/Toolbox/OrthancSlicesLoader.cpp	Wed Nov 08 17:53:55 2017 +0100
+++ b/Framework/Toolbox/OrthancSlicesLoader.cpp	Tue Nov 14 17:26:10 2017 +0100
@@ -52,7 +52,8 @@
   for (int i=0; i<64; i++) T["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i]] = i; 
 
   int val=0, valb=-8;
-  for (unsigned char c : in) {
+  for (size_t i = 0; i < in.size(); i++) {
+    unsigned char c = in[i];
     if (T[c] == -1) break;
     val = (val<<6) + T[c];
     valb += 6;
@@ -870,7 +871,7 @@
                        boost::lexical_cast<std::string>(value) + 
                        "-" + slice.GetOrthancInstanceId() + "_" + 
                        boost::lexical_cast<std::string>(slice.GetFrame()));
-
+      
     orthanc_.ScheduleGetRequest(*webCallback_, uri,
                                 Operation::DownloadSliceImage(index, slice, quality));
   }
--- a/Platforms/WebAssembly/CMakeLists.txt	Wed Nov 08 17:53:55 2017 +0100
+++ b/Platforms/WebAssembly/CMakeLists.txt	Tue Nov 14 17:26:10 2017 +0100
@@ -1,6 +1,5 @@
-# Usage:
-# cmake -DCMAKE_TOOLCHAIN_FILE=~/Downloads/emsdk/emscripten/incoming/cmake/Modules/Platform/Emscripten.cmake ~/Subversion/orthanc-stone/Platforms/WebAssembly
-
+# Usage (Linux):
+# source ~/Downloads/emsdk/emsdk_env.sh && cmake -DCMAKE_TOOLCHAIN_FILE=${EMSCRIPTEN}/cmake/Modules/Platform/Emscripten.cmake ..
 
 cmake_minimum_required(VERSION 2.8.3)
 
--- a/Resources/CMake/OrthancStoneParameters.cmake	Wed Nov 08 17:53:55 2017 +0100
+++ b/Resources/CMake/OrthancStoneParameters.cmake	Tue Nov 14 17:26:10 2017 +0100
@@ -27,6 +27,8 @@
 
 include(${ORTHANC_ROOT}/Resources/CMake/OrthancFrameworkParameters.cmake)
 
+SET(ORTHANC_STONE_ROOT ${CMAKE_CURRENT_LIST_DIR}/../..)
+
 
 #####################################################################
 ## CMake parameters tunable by the user