changeset 1600:b253b79906fa

clarifying variable names: frameIndex vs numberIndex
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Oct 2020 15:23:26 +0100
parents 73cd85d7da6a
children 1704341bb96e
files Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp OrthancStone/Sources/Toolbox/SortedFrames.cpp OrthancStone/Sources/Toolbox/SortedFrames.h
diffstat 3 files changed, 92 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Wed Oct 28 10:55:45 2020 +0100
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Wed Oct 28 15:23:26 2020 +0100
@@ -441,9 +441,9 @@
 
 
   static std::string GetKey(const std::string& sopInstanceUid,
-                            size_t frameIndex)
+                            size_t frameNumber)
   {
-    return sopInstanceUid + "|" + boost::lexical_cast<std::string>(frameIndex);
+    return sopInstanceUid + "|" + boost::lexical_cast<std::string>(frameNumber);
   }
   
 
@@ -470,7 +470,7 @@
    * previously cached one, or if no cache was previously available.
    **/
   bool Acquire(const std::string& sopInstanceUid,
-               size_t frameIndex,
+               size_t frameNumber,
                Orthanc::ImageAccessor* image /* transfer ownership */,
                unsigned int quality)
   {
@@ -486,7 +486,7 @@
       throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
     }
 
-    const std::string& key = GetKey(sopInstanceUid, frameIndex);
+    const std::string& key = GetKey(sopInstanceUid, frameNumber);
 
     bool invalidate = false;
     
@@ -548,8 +548,8 @@
   public:
     Accessor(FramesCache& that,
              const std::string& sopInstanceUid,
-             size_t frameIndex) :
-      accessor_(that.cache_, GetKey(sopInstanceUid, frameIndex), false /* shared lock */)
+             size_t frameNumber) :
+      accessor_(that.cache_, GetKey(sopInstanceUid, frameNumber), false /* shared lock */)
     {
     }
 
@@ -1082,7 +1082,7 @@
   {
   private:
     std::string   sopInstanceUid_;
-    unsigned int  frameIndex_;
+    unsigned int  frameNumber_;
     float         windowCenter_;
     float         windowWidth_;
     bool          isMonochrome1_;
@@ -1091,14 +1091,14 @@
   public:
     SetLowQualityFrame(boost::shared_ptr<ViewerViewport> viewport,
                        const std::string& sopInstanceUid,
-                       unsigned int frameIndex,
+                       unsigned int frameNumber,
                        float windowCenter,
                        float windowWidth,
                        bool isMonochrome1,
                        bool isPrefetch) :
       ICommand(viewport),
       sopInstanceUid_(sopInstanceUid),
-      frameIndex_(frameIndex),
+      frameNumber_(frameNumber),
       windowCenter_(windowCenter),
       windowWidth_(windowWidth),
       isMonochrome1_(isMonochrome1),
@@ -1117,7 +1117,7 @@
       {
         case Orthanc::PixelFormat_RGB24:
           updatedCache = GetViewport().cache_->Acquire(
-            sopInstanceUid_, frameIndex_, jpeg.release(), QUALITY_JPEG);
+            sopInstanceUid_, frameNumber_, jpeg.release(), QUALITY_JPEG);
           break;
 
         case Orthanc::PixelFormat_Grayscale8:
@@ -1154,7 +1154,7 @@
 
           Orthanc::ImageProcessing::ShiftScale(*converted, offset, scaling, false);
           updatedCache = GetViewport().cache_->Acquire(
-            sopInstanceUid_, frameIndex_, converted.release(), QUALITY_JPEG);
+            sopInstanceUid_, frameNumber_, converted.release(), QUALITY_JPEG);
           break;
         }
 
@@ -1164,7 +1164,7 @@
 
       if (updatedCache)
       {
-        GetViewport().SignalUpdatedFrame(sopInstanceUid_, frameIndex_);
+        GetViewport().SignalUpdatedFrame(sopInstanceUid_, frameNumber_);
       }
 
       if (isPrefetch_)
@@ -1179,17 +1179,17 @@
   {
   private:
     std::string   sopInstanceUid_;
-    unsigned int  frameIndex_;
+    unsigned int  frameNumber_;
     bool          isPrefetch_;
     
   public:
     SetFullDicomFrame(boost::shared_ptr<ViewerViewport> viewport,
                       const std::string& sopInstanceUid,
-                      unsigned int frameIndex,
+                      unsigned int frameNumber,
                       bool isPrefetch) :
       ICommand(viewport),
       sopInstanceUid_(sopInstanceUid),
-      frameIndex_(frameIndex),
+      frameNumber_(frameNumber),
       isPrefetch_(isPrefetch)
     {
     }
@@ -1206,7 +1206,7 @@
         throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
       }      
       
-      std::unique_ptr<Orthanc::ImageAccessor> frame(message.GetDicom().DecodeFrame(frameIndex_));
+      std::unique_ptr<Orthanc::ImageAccessor> frame(message.GetDicom().DecodeFrame(frameNumber_));
 
       if (frame.get() == NULL)
       {
@@ -1218,7 +1218,7 @@
       if (frame->GetFormat() == Orthanc::PixelFormat_RGB24)
       {
         updatedCache = GetViewport().cache_->Acquire(
-          sopInstanceUid_, frameIndex_, frame.release(), QUALITY_FULL);
+          sopInstanceUid_, frameNumber_, frame.release(), QUALITY_FULL);
       }
       else
       {
@@ -1245,12 +1245,12 @@
         Orthanc::ImageProcessing::ShiftScale2(*converted, b, a, false);
 
         updatedCache = GetViewport().cache_->Acquire(
-          sopInstanceUid_, frameIndex_, converted.release(), QUALITY_FULL);
+          sopInstanceUid_, frameNumber_, converted.release(), QUALITY_FULL);
       }
       
       if (updatedCache)
       {
-        GetViewport().SignalUpdatedFrame(sopInstanceUid_, frameIndex_);
+        GetViewport().SignalUpdatedFrame(sopInstanceUid_, frameNumber_);
       }
 
       if (isPrefetch_)
@@ -1287,7 +1287,7 @@
   };
   
 
-  std::unique_ptr<IObserver>                    observer_;
+  std::unique_ptr<IObserver>                   observer_;
   OrthancStone::ILoadersContext&               context_;
   boost::shared_ptr<OrthancStone::WebAssemblyViewport>   viewport_;
   boost::shared_ptr<OrthancStone::DicomResourcesLoader> loader_;
@@ -1307,7 +1307,11 @@
   FrameGeometry                                currentFrameGeometry_;
   std::list<PrefetchItem>                      prefetchQueue_;
 
-  boost::shared_ptr<OrthancStone::OsiriX::CollectionOfAnnotations>  annotations_;  
+
+  bool         hasFocusOnInstance_;
+  std::string  focusSopInstanceUid_;
+  
+  boost::shared_ptr<OrthancStone::OsiriX::CollectionOfAnnotations>  annotations_;
 
   void ScheduleNextPrefetch()
   {
@@ -1318,10 +1322,10 @@
       prefetchQueue_.pop_front();
       
       const std::string sopInstanceUid = frames_->GetFrameSopInstanceUid(index);
-      unsigned int frame = frames_->GetFrameIndex(index);
+      unsigned int frameNumber = frames_->GetFrameNumberInInstance(index);
 
       {
-        FramesCache::Accessor accessor(*cache_, sopInstanceUid, frame);
+        FramesCache::Accessor accessor(*cache_, sopInstanceUid, frameNumber);
         if (!accessor.IsValid() ||
             (isFull && accessor.GetQuality() == 0))
         {
@@ -1352,7 +1356,7 @@
   }
 
   void SignalUpdatedFrame(const std::string& sopInstanceUid,
-                          unsigned int frameIndex)
+                          unsigned int frameNumber)
   {
     if (cursor_.get() != NULL &&
         frames_.get() != NULL)
@@ -1360,7 +1364,7 @@
       size_t index = cursor_->GetCurrentIndex();
 
       if (frames_->GetFrameSopInstanceUid(index) == sopInstanceUid &&
-          frames_->GetFrameIndex(index) == frameIndex)
+          frames_->GetFrameNumberInInstance(index) == frameNumber)
       {
         DisplayCurrentFrame();
       }
@@ -1471,9 +1475,9 @@
     }
 
     const std::string sopInstanceUid = frames_->GetFrameSopInstanceUid(index);
-    unsigned int frame = frames_->GetFrameIndex(index);
+    size_t frameNumber = frames_->GetFrameNumberInInstance(index);
 
-    FramesCache::Accessor accessor(*cache_, sopInstanceUid, frame);
+    FramesCache::Accessor accessor(*cache_, sopInstanceUid, frameNumber);
     if (accessor.IsValid())
     {
       SaveCurrentWindowing();
@@ -1656,7 +1660,7 @@
     if (frames_.get() != NULL)
     {
       std::string sopInstanceUid = frames_->GetFrameSopInstanceUid(index);
-      unsigned int frame = frames_->GetFrameIndex(index);
+      unsigned int frameNumber = frames_->GetFrameNumberInInstance(index);
       
       {
         std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(context_.Lock());
@@ -1665,7 +1669,7 @@
             source_, frames_->GetStudyInstanceUid(), frames_->GetSeriesInstanceUid(),
             sopInstanceUid, false /* transcoding (TODO) */,
             Orthanc::DicomTransferSyntax_LittleEndianExplicit /* TODO */,
-            new SetFullDicomFrame(GetSharedObserver(), sopInstanceUid, frame, isPrefetch)));
+            new SetFullDicomFrame(GetSharedObserver(), sopInstanceUid, frameNumber, isPrefetch)));
       }
     }
   }
@@ -1681,13 +1685,13 @@
     else if (frames_.get() != NULL)
     {
       std::string sopInstanceUid = frames_->GetFrameSopInstanceUid(index);
-      unsigned int frame = frames_->GetFrameIndex(index);
+      unsigned int frameNumber = frames_->GetFrameNumberInInstance(index);
       bool isMonochrome1 = frames_->IsFrameMonochrome1(index);
 
       const std::string uri = ("studies/" + frames_->GetStudyInstanceUid() +
                                "/series/" + frames_->GetSeriesInstanceUid() +
                                "/instances/" + sopInstanceUid +
-                               "/frames/" + boost::lexical_cast<std::string>(frame + 1) + "/rendered");
+                               "/frames/" + boost::lexical_cast<std::string>(frameNumber + 1) + "/rendered");
 
       std::map<std::string, std::string> headers, arguments;
       arguments["window"] = (
@@ -1697,7 +1701,7 @@
       std::unique_ptr<OrthancStone::IOracleCommand> command(
         source_.CreateDicomWebCommand(
           uri, arguments, headers, new SetLowQualityFrame(
-            GetSharedObserver(), sopInstanceUid, frame,
+            GetSharedObserver(), sopInstanceUid, frameNumber,
             windowingCenter_, windowingWidth_, isMonochrome1, isPrefetch)));
 
       {
@@ -1746,7 +1750,8 @@
     fitNextContent_(true),
     isCtrlDown_(false),
     flipX_(false),
-    flipY_(false)
+    flipY_(false),
+    hasFocusOnInstance_(false)
   {
     if (!cache_)
     {
@@ -1851,6 +1856,20 @@
   {
     dynamic_cast<const ICommand&>(message.GetOrigin().GetPayload()).Handle(message);
   }
+
+  void ApplyScheduledFocus()
+  {
+    size_t instanceIndex;
+    
+    if (hasFocusOnInstance_ &&
+        frames_.get() != NULL &&
+        frames_->LookupSopInstanceUid(instanceIndex, focusSopInstanceUid_))
+    {
+      // TODO
+      
+      hasFocusOnInstance_ = false;
+    }
+  }
   
 public:
   static boost::shared_ptr<ViewerViewport> Create(OrthancStone::ILoadersContext::ILock& lock,
--- a/OrthancStone/Sources/Toolbox/SortedFrames.cpp	Wed Oct 28 10:55:45 2020 +0100
+++ b/OrthancStone/Sources/Toolbox/SortedFrames.cpp	Wed Oct 28 15:23:26 2020 +0100
@@ -93,45 +93,45 @@
 
   
   SortedFrames::Frame::Frame(const Instance& instance,
-                             unsigned int frameIndex) :
+                             unsigned int frameNumber) :
     instance_(&instance),
-    frameIndex_(frameIndex)
+    frameNumber_(frameNumber)
   {
-    if (frameIndex >= instance.GetNumberOfFrames())
+    if (frameNumber >= instance.GetNumberOfFrames())
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
   }
 
 
-  const SortedFrames::Instance& SortedFrames::GetInstance(size_t index) const
+  const SortedFrames::Instance& SortedFrames::GetInstance(size_t instanceIndex) const
   {
-    if (index >= instances_.size())
+    if (instanceIndex >= instances_.size())
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
     else
     {
-      assert(instances_[index] != NULL);
-      return *instances_[index];
+      assert(instances_[instanceIndex] != NULL);
+      return *instances_[instanceIndex];
     }
   }
 
   
-  const SortedFrames::Frame& SortedFrames::GetFrame(size_t index) const
+  const SortedFrames::Frame& SortedFrames::GetFrame(size_t frameIndex) const
   {
     if (!sorted_)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
                                       "Sort() has not been called");
     }
-    if (index >= frames_.size())
+    if (frameIndex >= frames_.size())
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
     else
     {
-      return frames_[index];
+      return frames_[frameIndex];
     }    
   }
 
@@ -211,18 +211,18 @@
 
   
   void SortedFrames::AddFramesOfInstance(std::set<size_t>& remainingInstances,
-                                         size_t index)
+                                         size_t instanceIndex)
   {
-    assert(instances_[index] != NULL);
-    const Instance& instance = *instances_[index];
+    assert(instances_[instanceIndex] != NULL);
+    const Instance& instance = *instances_[instanceIndex];
     
     for (unsigned int i = 0; i < instance.GetNumberOfFrames(); i++)
     {
       frames_.push_back(Frame(instance, i));
     }
 
-    assert(remainingInstances.find(index) != remainingInstances.end());
-    remainingInstances.erase(index);
+    assert(remainingInstances.find(instanceIndex) != remainingInstances.end());
+    remainingInstances.erase(instanceIndex);
   }
 
 
@@ -233,22 +233,22 @@
     {
     private:
       T            value_;
-      size_t       instance_;
+      size_t       instanceIndex_;
       std::string  sopInstanceUid_;
 
     public:
       SortableItem(const T& value,
-                   size_t instance,
+                   size_t instanceIndex,
                    const std::string& sopInstanceUid) :
         value_(value),
-        instance_(instance),
+        instanceIndex_(instanceIndex),
         sopInstanceUid_(sopInstanceUid)
       {
       }
 
       size_t GetInstanceIndex() const
       {
-        return instance_;
+        return instanceIndex_;
       }
 
       bool operator< (const SortableItem& other) const
--- a/OrthancStone/Sources/Toolbox/SortedFrames.h	Wed Oct 28 10:55:45 2020 +0100
+++ b/OrthancStone/Sources/Toolbox/SortedFrames.h	Wed Oct 28 15:23:26 2020 +0100
@@ -77,20 +77,20 @@
     {
     private:
       const Instance*  instance_;
-      unsigned int     frameIndex_;
+      unsigned int     frameNumber_;
 
     public:
       Frame(const Instance& instance,
-            unsigned int frameIndex);
+            unsigned int frameNumber);
 
       const Instance& GetInstance() const
       {
         return *instance_;
       }
 
-      unsigned int GetFrameIndex() const
+      unsigned int GetFrameNumberInInstance() const
       {
-        return frameIndex_;
+        return frameNumber_;
       }
     };
 
@@ -105,12 +105,12 @@
     bool                    sorted_;
     InstancesIndex          instancesIndex_;
 
-    const Instance& GetInstance(size_t index) const;
+    const Instance& GetInstance(size_t instanceIndex) const;
 
-    const Frame& GetFrame(size_t index) const;
+    const Frame& GetFrame(size_t frameIndex) const;
 
     void AddFramesOfInstance(std::set<size_t>& remainingInstances,
-                             size_t index);
+                             size_t instanceIndex);
 
     void SortUsingIntegerTag(std::set<size_t>& remainingInstances,
                              const Orthanc::DicomTag& tag);
@@ -149,14 +149,14 @@
       return instances_.size();
     }
 
-    const Orthanc::DicomMap& GetInstanceTags(size_t index) const
+    const Orthanc::DicomMap& GetInstanceTags(size_t instanceIndex) const
     {
-      return GetInstance(index).GetTags();
+      return GetInstance(instanceIndex).GetTags();
     }
 
-    const std::string& GetSopInstanceUid(size_t index) const
+    const std::string& GetSopInstanceUid(size_t instanceIndex) const
     {
-      return GetInstance(index).GetSopInstanceUid();
+      return GetInstance(instanceIndex).GetSopInstanceUid();
     }
 
     bool LookupSopInstanceUid(size_t& instanceIndex,
@@ -169,29 +169,29 @@
 
     size_t GetFramesCount() const;
 
-    const Orthanc::DicomMap& GetFrameTags(size_t index) const
+    const Orthanc::DicomMap& GetFrameTags(size_t frameIndex) const
     {
-      return GetFrame(index).GetInstance().GetTags();
+      return GetFrame(frameIndex).GetInstance().GetTags();
     }
 
-    const std::string& GetFrameSopInstanceUid(size_t index) const
+    const std::string& GetFrameSopInstanceUid(size_t frameIndex) const
     {
-      return GetFrame(index).GetInstance().GetSopInstanceUid();
+      return GetFrame(frameIndex).GetInstance().GetSopInstanceUid();
     }
 
-    unsigned int GetFrameSiblingsCount(size_t index) const
+    unsigned int GetFrameSiblingsCount(size_t frameIndex) const
     {
-      return GetFrame(index).GetInstance().GetNumberOfFrames();
+      return GetFrame(frameIndex).GetInstance().GetNumberOfFrames();
     }
 
-    unsigned int GetFrameIndex(size_t index) const
+    unsigned int GetFrameNumberInInstance(size_t frameIndex) const
     {
-      return GetFrame(index).GetFrameIndex();
+      return GetFrame(frameIndex).GetFrameNumberInInstance();
     }
 
-    bool IsFrameMonochrome1(size_t index) const
+    bool IsFrameMonochrome1(size_t frameIndex) const
     {
-      return GetFrame(index).GetInstance().IsMonochrome1();
+      return GetFrame(frameIndex).GetInstance().IsMonochrome1();
     }
 
     void Sort();