changeset 2095:ec676dbe85ac

partial integration dicom-sr->mainline
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 08 Nov 2023 15:13:21 +0100
parents 7c3d65166c26
children 79e984a89a38 67db5afb305d
files Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp
diffstat 1 files changed, 50 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Wed Nov 08 14:54:15 2023 +0100
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Wed Nov 08 15:13:21 2023 +0100
@@ -819,32 +819,31 @@
     }
   }
 
-  bool SortSeriesFrames(OrthancStone::SortedFrames& target,
-                        const std::string& seriesInstanceUid) const
+  IFramesCollection* GetSeriesFrames(const std::string& seriesInstanceUid) const
   {
     OrthancStone::SeriesMetadataLoader::Accessor accessor(*metadataLoader_, seriesInstanceUid);
     
     if (accessor.IsComplete())
     {
-      target.Clear();
+      std::unique_ptr<OrthancStone::SortedFrames> target(new OrthancStone::SortedFrames);
+      target->Clear();
 
       for (size_t i = 0; i < accessor.GetInstancesCount(); i++)
       {
-        target.AddInstance(accessor.GetInstance(i));
+        target->AddInstance(accessor.GetInstance(i));
       }
 
-      target.Sort();
+      target->Sort();
       
-      return true;
+      return new SortedFramesCollection(target.release());
     }
     else
     {
-      return false;
+      return NULL;
     }
   }
 
-  bool SortVirtualSeriesFrames(OrthancStone::SortedFrames& target,
-                               const std::string& virtualSeriesId) const
+  IFramesCollection* GetVirtualSeriesFrames(const std::string& virtualSeriesId) const
   {
     const std::string& seriesInstanceUid = virtualSeries_.GetSeriesInstanceUid(virtualSeriesId);
     
@@ -854,7 +853,8 @@
     {
       const std::list<std::string>& sopInstanceUids = virtualSeries_.GetSopInstanceUids(virtualSeriesId);
 
-      target.Clear();
+      std::unique_ptr<OrthancStone::SortedFrames> target(new OrthancStone::SortedFrames);
+      target->Clear();
 
       for (std::list<std::string>::const_iterator
              it = sopInstanceUids.begin(); it != sopInstanceUids.end(); ++it)
@@ -862,7 +862,7 @@
         Orthanc::DicomMap instance;
         if (accessor.LookupInstance(instance, *it))
         {
-          target.AddInstance(instance);
+          target->AddInstance(instance);
         }
         else
         {
@@ -870,12 +870,13 @@
         }
       }
       
-      target.Sort();
-      return true;
+      target->Sort();
+
+      return new SortedFramesCollection(target.release());
     }
     else
     {
-      return false;
+      return NULL;
     }
   }
 
@@ -1635,7 +1636,6 @@
 
 
 
-
 class ViewerViewport : public OrthancStone::ObserverBase<ViewerViewport>
 {
 public:
@@ -1917,6 +1917,8 @@
   class SetFullDicomFrame : public ICommand
   {
   private:
+    std::string   studyInstanceUid_;
+    std::string   seriesInstanceUid_;
     std::string   sopInstanceUid_;
     unsigned int  frameNumber_;
     int           priority_;
@@ -1925,12 +1927,16 @@
     
   public:
     SetFullDicomFrame(boost::shared_ptr<ViewerViewport> viewport,
+                      const std::string& studyInstanceUid,
+                      const std::string& seriesInstanceUid,
                       const std::string& sopInstanceUid,
                       unsigned int frameNumber,
                       int priority,
                       bool isPrefetch,
                       bool serverSideTranscoding) :
       ICommand(viewport),
+      studyInstanceUid_(studyInstanceUid),
+      seriesInstanceUid_(seriesInstanceUid),
       sopInstanceUid_(sopInstanceUid),
       frameNumber_(frameNumber),
       priority_(priority),
@@ -1956,7 +1962,7 @@
             // If we haven't tried server-side rendering yet, give it a try
             LOG(INFO) << "Switching to server-side transcoding";
             GetViewport().serverSideTranscoding_ = true;
-            GetViewport().ScheduleLoadFullDicomFrame(sopInstanceUid_, frameNumber_, priority_, isPrefetch_);
+            GetViewport().ScheduleLoadFullDicomFrame(studyInstanceUid_, seriesInstanceUid_, sopInstanceUid_, frameNumber_, priority_, isPrefetch_);
           }
           return;
         }
@@ -2074,7 +2080,7 @@
   boost::shared_ptr<OrthancStone::DicomResourcesLoader> loader_;
   OrthancStone::DicomSource                    source_;
   boost::shared_ptr<FramesCache>               framesCache_;  
-  std::unique_ptr<OrthancStone::SortedFrames>  frames_;
+  std::unique_ptr<IFramesCollection>           frames_;
   std::unique_ptr<SeriesCursor>                cursor_;
   float                                        windowingCenter_;
   float                                        windowingWidth_;
@@ -2432,7 +2438,7 @@
       if (instance.GetSopInstanceUid() == loadedSopInstanceUid &&
           frameNumber == loadedFrameNumber)
       {
-        const OrthancStone::CoordinateSystem3D plane = frames_->GetFrameGeometry(cursorIndex);
+        const OrthancStone::CoordinateSystem3D plane = IFramesCollection::GetFrameGeometry(*frames_, cursorIndex);
         
         if (quality == DisplayedFrameQuality_Low)
         {
@@ -2471,7 +2477,9 @@
     }
   }
 
-  void ScheduleLoadFullDicomFrame(const std::string& sopInstanceUid,
+  void ScheduleLoadFullDicomFrame(const std::string& studyInstanceUid,
+                                  const std::string& seriesInstanceUid,
+                                  const std::string& sopInstanceUid,
                                   unsigned int frameNumber,
                                   int priority,
                                   bool isPrefetch)
@@ -2481,10 +2489,10 @@
       std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(context_.Lock());
       lock->Schedule(
         GetSharedObserver(), priority, OrthancStone::ParseDicomFromWadoCommand::Create(
-          source_, frames_->GetStudyInstanceUid(), frames_->GetSeriesInstanceUid(),
-          sopInstanceUid, serverSideTranscoding_,
+          source_, studyInstanceUid, seriesInstanceUid, sopInstanceUid, serverSideTranscoding_,
           Orthanc::DicomTransferSyntax_LittleEndianExplicit,
-          new SetFullDicomFrame(GetSharedObserver(), sopInstanceUid, frameNumber, priority, isPrefetch, serverSideTranscoding_)));
+          new SetFullDicomFrame(GetSharedObserver(), studyInstanceUid, seriesInstanceUid,
+                                sopInstanceUid, frameNumber, priority, isPrefetch, serverSideTranscoding_)));
     }
   }
 
@@ -2494,9 +2502,11 @@
   {
     if (frames_.get() != NULL)
     {
+      std::string studyInstanceUid = frames_->GetInstanceOfFrame(cursorIndex).GetStudyInstanceUid();
+      std::string seriesInstanceUid = frames_->GetInstanceOfFrame(cursorIndex).GetSeriesInstanceUid();
       std::string sopInstanceUid = frames_->GetInstanceOfFrame(cursorIndex).GetSopInstanceUid();
       unsigned int frameNumber = frames_->GetFrameNumberInInstance(cursorIndex);
-      ScheduleLoadFullDicomFrame(sopInstanceUid, frameNumber, priority, isPrefetch);
+      ScheduleLoadFullDicomFrame(studyInstanceUid, seriesInstanceUid, sopInstanceUid, frameNumber, priority, isPrefetch);
     }
   }
 
@@ -2545,8 +2555,8 @@
       bool isMonochrome1 = (instance.GetImageInformation().GetPhotometricInterpretation() ==
                             Orthanc::PhotometricInterpretation_Monochrome1);
 
-      const std::string uri = ("studies/" + frames_->GetStudyInstanceUid() +
-                               "/series/" + frames_->GetSeriesInstanceUid() +
+      const std::string uri = ("studies/" + instance.GetStudyInstanceUid() +
+                               "/series/" + instance.GetSeriesInstanceUid() +
                                "/instances/" + instance.GetSopInstanceUid() +
                                "/frames/" + boost::lexical_cast<std::string>(frameNumber + 1) + "/rendered");
 
@@ -2587,7 +2597,6 @@
     }
   }
   
-
   ViewerViewport(OrthancStone::WebAssemblyLoadersContext& context,
                  const OrthancStone::DicomSource& source,
                  const std::string& canvas,
@@ -2682,14 +2691,12 @@
       {
         const size_t currentCursorIndex = that.cursor_->GetCurrentIndex();
 
-        const OrthancStone::CoordinateSystem3D current =
-          that.frames_->GetFrameGeometry(currentCursorIndex);
+        const OrthancStone::CoordinateSystem3D current = IFramesCollection::GetFrameGeometry(*that.frames_, currentCursorIndex);
       
         if (isShift &&
             previousCursorIndex != currentCursorIndex)
         {
-          const OrthancStone::CoordinateSystem3D previous =
-            that.frames_->GetFrameGeometry(previousCursorIndex);
+          const OrthancStone::CoordinateSystem3D previous = IFramesCollection::GetFrameGeometry(*that.frames_, previousCursorIndex);
           that.synchronizationOffset_ += previous.GetOrigin() - current.GetOrigin();
         }
 
@@ -2836,7 +2843,7 @@
     return viewport;    
   }
 
-  void SetFrames(OrthancStone::SortedFrames* frames)
+  void SetFrames(IFramesCollection* frames)
   {
     if (frames == NULL)
     {
@@ -2906,8 +2913,8 @@
           GetSeriesThumbnailType(uid) != OrthancStone::SeriesThumbnailType_Video)
       {
         // Fetch the details of the series from the central instance
-        const std::string uri = ("studies/" + frames_->GetStudyInstanceUid() +
-                                 "/series/" + frames_->GetSeriesInstanceUid() +
+        const std::string uri = ("studies/" + centralInstance.GetStudyInstanceUid() +
+                                 "/series/" + centralInstance.GetSeriesInstanceUid() +
                                  "/instances/" + centralInstance.GetSopInstanceUid() + "/metadata");
         
         loader_->ScheduleGetDicomWeb(
@@ -2963,7 +2970,7 @@
       FramesCache::Accessor accessor(*framesCache_, instance.GetSopInstanceUid(), frameNumber);
       if (accessor.IsValid())
       {
-        RenderCurrentScene(accessor.GetImage(), instance, frameNumber, frames_->GetFrameGeometry(cursorIndex));
+        RenderCurrentScene(accessor.GetImage(), instance, frameNumber, IFramesCollection::GetFrameGeometry(*frames_, cursorIndex));
 
         DisplayedFrameQuality quality;
         
@@ -3074,7 +3081,7 @@
     if (cursor_.get() != NULL &&
         frames_.get() != NULL)
     {
-      plane = frames_->GetFrameGeometry(cursor_->GetCurrentIndex());      
+      plane = IFramesCollection::GetFrameGeometry(*frames_, cursor_->GetCurrentIndex());
       return true;
     }
     else
@@ -3148,7 +3155,7 @@
   void SetWindowingPreset()
   {
     assert(windowingPresetCenters_.size() == windowingPresetWidths_.size());
-    
+
     if (windowingPresetCenters_.empty())
     {
       SetWindowing(128, 256);
@@ -3574,8 +3581,7 @@
     {
       const size_t currentCursorIndex = cursor_->GetCurrentIndex();
 
-      const OrthancStone::CoordinateSystem3D current =
-        frames_->GetFrameGeometry(currentCursorIndex);
+      const OrthancStone::CoordinateSystem3D current = IFramesCollection::GetFrameGeometry(*frames_, currentCursorIndex);
       
       observer_->SignalSynchronizedBrowsing(
         *this, current.GetOrigin() + synchronizationOffset_, current.GetNormal());
@@ -4226,9 +4232,9 @@
   {
     try
     {
-      std::unique_ptr<OrthancStone::SortedFrames> frames(new OrthancStone::SortedFrames);
-      
-      if (GetResourcesLoader().SortSeriesFrames(*frames, seriesInstanceUid))
+      std::unique_ptr<IFramesCollection> frames(GetResourcesLoader().GetSeriesFrames(seriesInstanceUid));
+
+      if (frames.get() != NULL)
       {
         GetViewport(canvas)->SetFrames(frames.release());
         return 1;
@@ -4249,9 +4255,9 @@
   {
     try
     {
-      std::unique_ptr<OrthancStone::SortedFrames> frames(new OrthancStone::SortedFrames);
-
-      if (GetResourcesLoader().SortVirtualSeriesFrames(*frames, virtualSeriesId))
+      std::unique_ptr<IFramesCollection> frames(GetResourcesLoader().GetVirtualSeriesFrames(virtualSeriesId));
+
+      if (frames.get() != NULL)
       {
         GetViewport(canvas)->SetFrames(frames.release());
         return 1;