changeset 1811:fdc6a8089eb9

hovering of annotations in Stone Web viewer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 May 2021 11:29:53 +0200
parents b05d5f0d014f
children db341679dc9f
files Applications/Platforms/WebAssembly/WebAssemblyViewport.cpp Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp OrthancStone/Sources/Viewport/DefaultViewportInteractor.cpp OrthancStone/Sources/Viewport/DefaultViewportInteractor.h OrthancStone/Sources/Viewport/IViewportInteractor.h
diffstat 5 files changed, 69 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Platforms/WebAssembly/WebAssemblyViewport.cpp	Thu May 20 19:11:44 2021 +0200
+++ b/Applications/Platforms/WebAssembly/WebAssemblyViewport.cpp	Tue May 25 11:29:53 2021 +0200
@@ -174,8 +174,8 @@
       ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_);
 
       that->controller_->HandleMousePress(*that->interactor_, pointer,
-                                         that->compositor_->GetCanvasWidth(),
-                                         that->compositor_->GetCanvasHeight());        
+                                          that->compositor_->GetCanvasWidth(),
+                                          that->compositor_->GetCanvasHeight());        
       that->Invalidate();
     }
 
@@ -188,14 +188,25 @@
   {
     WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData);
 
-    if (that->compositor_.get() != NULL &&
-        that->controller_->HasActiveTracker())
+    if (that->compositor_.get() != NULL)
     {
-      PointerEvent pointer;
-      ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_);
-      if (that->controller_->HandleMouseMove(pointer))
+      if (that->controller_->HasActiveTracker())
       {
-        that->Invalidate();
+        PointerEvent pointer;
+        ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_);
+      
+        if (that->controller_->HandleMouseMove(pointer))
+        {
+          that->Invalidate();
+        }
+      }
+      else if (that->interactor_.get() != NULL &&
+               that->interactor_->HasMouseHover())
+      {
+        // New in Stone Web viewer 2.0
+        PointerEvent pointer;
+        ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_);      
+        that->interactor_->HandleMouseHover(*that, pointer);
       }
     }
 
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Thu May 20 19:11:44 2021 +0200
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Tue May 25 11:29:53 2021 +0200
@@ -1190,6 +1190,7 @@
                                     DisplayedFrameQuality quality,
                                     unsigned int instanceNumber) = 0;
 
+    // "click" is a 3D vector in world coordinates
     virtual void SignalCrosshair(const ViewerViewport& viewport,
                                  const OrthancStone::Vector& click) = 0;
 
@@ -1577,8 +1578,13 @@
   bool         hasFocusOnInstance_;
   std::string  focusSopInstanceUid_;
   size_t       focusFrameNumber_;
-  
+
+  // The coordinates of OsiriX annotations are expressed in 3D world coordinates
   boost::shared_ptr<OrthancStone::OsiriX::CollectionOfAnnotations>  annotations_;
+
+  // The coordinates of Stone annotations are expressed in 2D
+  // coordinates of the current texture, with (0,0) corresponding to
+  // the center of the top-left pixel
   boost::shared_ptr<OrthancStone::AnnotationsSceneLayer>            annotationsStone_;
 
   void ScheduleNextPrefetch()
@@ -2645,6 +2651,23 @@
           viewport, event, viewportWidth, viewportHeight);
       }
     }
+
+    virtual bool HasMouseHover() const ORTHANC_OVERRIDE
+    {
+      return true;
+    }
+
+    virtual void HandleMouseHover(OrthancStone::IViewport& viewport,
+                                  const OrthancStone::PointerEvent& event) ORTHANC_OVERRIDE
+    {
+      std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport.Lock());
+
+      if (viewer_.annotationsStone_->SetMouseHover(event.GetMainPosition(), lock->GetController().GetScene()))
+      {
+        viewer_.annotationsStone_->Render(lock->GetController().GetScene());
+        lock->Invalidate();
+      }
+    }
   };
   
 
@@ -2875,6 +2898,11 @@
   virtual void SignalCrosshair(const ViewerViewport& viewport,
                                const OrthancStone::Vector& click) ORTHANC_OVERRIDE
   {
+    if (click.size() != 3u)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+    }
+    
     for (Viewports::const_iterator it = allViewports_.begin(); it != allViewports_.end(); ++it)
     {
       // TODO - One could check the "Frame Of Reference UID" here
--- a/OrthancStone/Sources/Viewport/DefaultViewportInteractor.cpp	Thu May 20 19:11:44 2021 +0200
+++ b/OrthancStone/Sources/Viewport/DefaultViewportInteractor.cpp	Tue May 25 11:29:53 2021 +0200
@@ -89,4 +89,12 @@
 
     return CreateTrackerInternal(viewport, action, event, viewportWidth, viewportHeight);
   }
+
+
+  void DefaultViewportInteractor::HandleMouseHover(IViewport& viewport,
+                                                   const PointerEvent& event)
+  {
+    // "HasMouseOver()" returns "false"
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+  }
 }
--- a/OrthancStone/Sources/Viewport/DefaultViewportInteractor.h	Thu May 20 19:11:44 2021 +0200
+++ b/OrthancStone/Sources/Viewport/DefaultViewportInteractor.h	Tue May 25 11:29:53 2021 +0200
@@ -95,5 +95,13 @@
                                                    const PointerEvent& event,
                                                    unsigned int viewportWidth,
                                                    unsigned int viewportHeight) ORTHANC_OVERRIDE;
+
+    virtual bool HasMouseHover() const ORTHANC_OVERRIDE
+    {
+      return false;
+    }
+
+    virtual void HandleMouseHover(IViewport& viewport,
+                                  const PointerEvent& event) ORTHANC_OVERRIDE;
   };
 }
--- a/OrthancStone/Sources/Viewport/IViewportInteractor.h	Thu May 20 19:11:44 2021 +0200
+++ b/OrthancStone/Sources/Viewport/IViewportInteractor.h	Tue May 25 11:29:53 2021 +0200
@@ -37,5 +37,10 @@
                                                    const PointerEvent& event,
                                                    unsigned int viewportWidth,
                                                    unsigned int viewportHeight) = 0;
+
+    virtual bool HasMouseHover() const = 0;
+
+    virtual void HandleMouseHover(IViewport& viewport,
+                                  const PointerEvent& event) = 0;
   };
 }