changeset 279:8f5d7495076d am-2

SimpleViewer sample working in SDL, Qt and WASM
author am@osimis.io
date Mon, 27 Aug 2018 15:40:13 +0200
parents 8a86695fcbc3
children 829163c6efc1
files Applications/Samples/SimpleViewerApplication.h Applications/Sdl/BasicSdlApplication.cpp Framework/SmartLoader.h Platforms/Generic/CMakeLists.txt
diffstat 4 files changed, 35 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Samples/SimpleViewerApplication.h	Mon Aug 27 14:58:37 2018 +0200
+++ b/Applications/Samples/SimpleViewerApplication.h	Mon Aug 27 15:40:13 2018 +0200
@@ -59,7 +59,9 @@
         {
           if (button == MouseButton_Left)
           {
-            statusBar->SetMessage("trying to drag the thumbnail from " + widget.GetName());
+            statusBar->SetMessage("selected thumbnail " + widget.GetName());
+            std::string seriesId = widget.GetName().substr(strlen("thumbnail-series-"));
+            application_.SelectSeriesInMainViewport(seriesId);
           }
           return NULL;
         }
@@ -156,9 +158,6 @@
           case 's':
             widget.SetDefaultView();
             break;
-          case 'n':
-            application_.NextImage(widget);
-            break;
 
           default:
             break;
@@ -173,7 +172,7 @@
       LayoutWidget*                   thumbnailsLayout_;
       LayerWidget*                    mainWidget_;
       std::vector<LayerWidget*>       thumbnails_;
-      std::vector<std::string>        instances_;
+      std::map<std::string, std::vector<std::string>> instancesIdsPerSeriesId_;
 
       unsigned int                    currentInstanceIndex_;
       OrthancStone::WidgetViewport*   wasmViewport1_;
@@ -292,7 +291,23 @@
       {
         if (response.isObject() && response["Instances"].isArray() && response["Instances"].size() > 0)
         {
-          LoadThumbnailForSeries(response["ID"].asString(), response["Instances"][0].asString());
+          // keep track of all instances IDs
+          const std::string& seriesId = response["ID"].asString();
+          instancesIdsPerSeriesId_[seriesId] = std::vector<std::string>();
+          for (size_t i = 0; i < response["Instances"].size(); i++)
+          {
+            const std::string& instanceId = response["Instances"][static_cast<int>(i)].asString();
+            instancesIdsPerSeriesId_[seriesId].push_back(instanceId);
+          }
+
+          // load the first instance in the thumbnail
+          LoadThumbnailForSeries(seriesId, instancesIdsPerSeriesId_[seriesId][0]);
+
+          // if this is the first thumbnail loaded, load the first instance in the mainWidget
+          if (mainWidget_->GetLayerCount() == 0)
+          {
+              mainWidget_->AddLayer(smartLoader_->GetFrame(instancesIdsPerSeriesId_[seriesId][0], 0));
+          }
         }
       }
 
@@ -304,7 +319,7 @@
         thumbnailsLayout_->AddWidget(thumbnailWidget);
         thumbnailWidget->RegisterObserver(*this);
         thumbnailWidget->AddLayer(smartLoader_->GetFrame(instanceId, 0));
-        //thumbnailWidget->SetInteractor(*thumbnailInteractor_);
+        thumbnailWidget->SetInteractor(*thumbnailInteractor_);
       }
 
       void SelectStudy(const std::string& studyId)
@@ -340,14 +355,9 @@
       }
 #endif
 
-      void NextImage(WorldSceneWidget& widget) {
-        assert(context_);
-        statusBar_->SetMessage("displaying next image");
-
-        currentInstanceIndex_ = (currentInstanceIndex_ + 1) % instances_.size();
-
-        mainWidget_->ReplaceLayer(0, smartLoader_->GetFrame(instances_[currentInstanceIndex_], 0));
-
+      void SelectSeriesInMainViewport(const std::string& seriesId)
+      {
+        mainWidget_->ReplaceLayer(0, smartLoader_->GetFrame(instancesIdsPerSeriesId_[seriesId][0], 0));
       }
     };
 
--- a/Applications/Sdl/BasicSdlApplication.cpp	Mon Aug 27 14:58:37 2018 +0200
+++ b/Applications/Sdl/BasicSdlApplication.cpp	Mon Aug 27 15:40:13 2018 +0200
@@ -61,7 +61,7 @@
         !parameters.count("opengl"))
     {
       LOG(ERROR) << "Parameter \"width\", \"height\" or \"opengl\" is missing";
-      return -1;
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
 
     int w = parameters["width"].as<int>();
@@ -69,15 +69,15 @@
     if (w <= 0 || h <= 0)
     {
       LOG(ERROR) << "Parameters \"width\" and \"height\" must be positive";
-      return -1;
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
 
     width_ = static_cast<unsigned int>(w);
     height_ = static_cast<unsigned int>(h);
     LOG(WARNING) << "Initial display size: " << width_ << "x" << height_;
 
-    opengl_ = parameters["opengl"].as<bool>();
-    if (opengl_)
+    enableOpenGl_ = parameters["opengl"].as<bool>();
+    if (enableOpenGl_)
     {
       LOG(WARNING) << "OpenGL is enabled, disable it with option \"--opengl=off\" if the application crashes";
     }
--- a/Framework/SmartLoader.h	Mon Aug 27 14:58:37 2018 +0200
+++ b/Framework/SmartLoader.h	Mon Aug 27 15:40:13 2018 +0200
@@ -20,6 +20,7 @@
 
 
 #pragma once
+#include <map>
 
 #include "Layers/ILayerSource.h"
 #include "Messages/IObservable.h"
@@ -35,6 +36,7 @@
     OrthancApiClient      orthancApiClient_;
 
     int studyListRequest_;
+
   public:
     SmartLoader(MessageBroker& broker, IWebService& webService);  // TODO: add maxPreloadStorageSizeInBytes
 
@@ -48,6 +50,8 @@
 
     ILayerSource* GetFrame(const std::string& instanceId, unsigned int frame);
 
+    void GetFirstInstanceIdForSeries(std::string& output, const std::string& seriesId);
+
   };
 
 }
--- a/Platforms/Generic/CMakeLists.txt	Mon Aug 27 14:58:37 2018 +0200
+++ b/Platforms/Generic/CMakeLists.txt	Mon Aug 27 15:40:13 2018 +0200
@@ -29,8 +29,8 @@
 
 LIST(APPEND ORTHANC_BOOST_COMPONENTS program_options)
 
-SET(ENABLE_SDL OFF)
-SET(ENABLE_QT ON)
+SET(ENABLE_SDL ON)
+SET(ENABLE_QT OFF)
 SET(ORTHANC_SANDBOXED OFF)
 SET(ENABLE_CRYPTO_OPTIONS ON)
 SET(ENABLE_GOOGLE_TEST ON)