changeset 1976:d71acf30970a

fixed serialization of pixel probes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 29 Oct 2022 13:02:21 +0200
parents 5a434f5889f8
children ba971d9082d3
files Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.h
diffstat 3 files changed, 55 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Sat Oct 29 11:57:00 2022 +0200
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Sat Oct 29 13:02:21 2022 +0200
@@ -2307,6 +2307,7 @@
         scene.DeleteLayer(LAYER_ORIENTATION_MARKERS);
       }
 
+      stoneAnnotations_->UpdateProbes(scene);
       stoneAnnotations_->Render(scene);  // Necessary for "FitContent()" to work
 
       if (fitNextContent_)
--- a/OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp	Sat Oct 29 11:57:00 2022 +0200
+++ b/OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp	Sat Oct 29 13:02:21 2022 +0200
@@ -225,6 +225,8 @@
     virtual void SignalMove(GeometricPrimitive& primitive,
                             const Scene2D& scene) = 0;
 
+    virtual void UpdateProbe(const Scene2D& scene) = 0;
+
     virtual void Serialize(Json::Value& target) = 0;
   };
 
@@ -887,6 +889,10 @@
       UpdateLabel();
     }
 
+    virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE
+    {
+    }
+
     virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE
     {
       target = Json::objectValue;
@@ -929,7 +935,31 @@
     Handle&   handle_;
     Text&     label_;
 
-    void UpdateLabel(const Scene2D& scene)
+  public:
+    PixelProbeAnnotation(AnnotationsSceneLayer& that,
+                         Units units,
+                         const ScenePoint2D& p,
+                         int probedLayer) :
+      Annotation(that, units),
+      probedLayer_(probedLayer),
+      handle_(AddTypedPrimitive<Handle>(new Handle(*this, p))),
+      label_(AddTypedPrimitive<Text>(new Text(that, *this)))
+    {
+      label_.SetColor(COLOR_TEXT);
+    }
+
+    Handle& GetHandle() const
+    {
+      return handle_;
+    }
+
+    virtual void SignalMove(GeometricPrimitive& primitive,
+                            const Scene2D& scene) ORTHANC_OVERRIDE
+    {
+      UpdateProbe(scene);
+    }
+
+    virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE
     {
       TextSceneLayer content;
 
@@ -962,32 +992,6 @@
       label_.SetContent(content);
     }
 
-  public:
-    PixelProbeAnnotation(AnnotationsSceneLayer& that,
-                         Units units,
-                         const ScenePoint2D& p,
-                         const Scene2D& scene,
-                         int probedLayer) :
-      Annotation(that, units),
-      probedLayer_(probedLayer),
-      handle_(AddTypedPrimitive<Handle>(new Handle(*this, p))),
-      label_(AddTypedPrimitive<Text>(new Text(that, *this)))
-    {
-      label_.SetColor(COLOR_TEXT);
-      UpdateLabel(scene);
-    }
-
-    Handle& GetHandle() const
-    {
-      return handle_;
-    }
-
-    virtual void SignalMove(GeometricPrimitive& primitive,
-                            const Scene2D& scene) ORTHANC_OVERRIDE
-    {
-      UpdateLabel(scene);
-    }
-
     virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE
     {
       target = Json::objectValue;
@@ -1006,10 +1010,9 @@
           source[KEY_X].isNumeric() &&
           source[KEY_Y].isNumeric())
       {
-        Scene2D dummyScene;  // TODO
         new PixelProbeAnnotation(target, units,
                                  ScenePoint2D(source[KEY_X].asDouble(), source[KEY_Y].asDouble()),
-                                 dummyScene, probedLayer);
+                                 probedLayer);
       }
       else
       {
@@ -1123,6 +1126,10 @@
       UpdateLabel();
     }
 
+    virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE
+    {
+    }
+    
     virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE
     {
       target = Json::objectValue;
@@ -1273,6 +1280,10 @@
       UpdateLabel();
     }
 
+    virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE
+    {
+    }
+
     virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE
     {
       target = Json::objectValue;
@@ -1488,7 +1499,8 @@
                             int probedLayer) :
       that_(that)
     {
-      new PixelProbeAnnotation(that, units, sceneClick, scene, probedLayer);
+      PixelProbeAnnotation* annotation = new PixelProbeAnnotation(that, units, sceneClick, probedLayer);
+      annotation->UpdateProbe(scene);
     }
 
     virtual void PointerMove(const PointerEvent& event,
@@ -1899,4 +1911,14 @@
       }
     }
   }
+
+
+  void AnnotationsSceneLayer::UpdateProbes(const Scene2D& scene)
+  {
+    for (Annotations::const_iterator it = annotations_.begin(); it != annotations_.end(); ++it)
+    {
+      assert(*it != NULL);
+      (*it)->UpdateProbe(scene);
+    }
+  }
 }
--- a/OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.h	Sat Oct 29 11:57:00 2022 +0200
+++ b/OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.h	Sat Oct 29 13:02:21 2022 +0200
@@ -146,5 +146,7 @@
     {
       return probedLayer_;
     }
+
+    void UpdateProbes(const Scene2D& scene);
   };
 }