# HG changeset patch # User Sebastien Jodogne # Date 1667053869 -7200 # Node ID ba971d9082d344c01f1060ccb36f9c78aa4d770c # Parent d71acf30970ac3202a796e95bcf51412234833a4 cont pixel probe diff -r d71acf30970a -r ba971d9082d3 Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp --- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp Sat Oct 29 13:02:21 2022 +0200 +++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp Sat Oct 29 16:31:09 2022 +0200 @@ -2307,7 +2307,6 @@ scene.DeleteLayer(LAYER_ORIENTATION_MARKERS); } - stoneAnnotations_->UpdateProbes(scene); stoneAnnotations_->Render(scene); // Necessary for "FitContent()" to work if (fitNextContent_) diff -r d71acf30970a -r ba971d9082d3 OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp --- a/OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp Sat Oct 29 13:02:21 2022 +0200 +++ b/OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp Sat Oct 29 16:31:09 2022 +0200 @@ -685,7 +685,34 @@ { SetModified(true); content_.reset(dynamic_cast(content.Clone())); - } + } + + void SetText(const std::string& text) + { + if (content_.get() == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + else + { + SetModified(true); + content_->SetText(text); + } + } + + void SetPosition(double x, + double y) + { + if (content_.get() == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + else + { + SetModified(true); + content_->SetPosition(x, y); + } + } virtual bool IsHit(const ScenePoint2D& p, const Scene2D& scene) const ORTHANC_OVERRIDE @@ -927,7 +954,7 @@ } }; - + class AnnotationsSceneLayer::PixelProbeAnnotation : public Annotation { private: @@ -945,6 +972,13 @@ handle_(AddTypedPrimitive(new Handle(*this, p))), label_(AddTypedPrimitive(new Text(that, *this))) { + TextSceneLayer content; + content.SetPosition(handle_.GetCenter().GetX(), handle_.GetCenter().GetY()); + content.SetAnchor(BitmapAnchor_CenterLeft); + content.SetBorder(10); + content.SetText("?"); + + label_.SetContent(content); label_.SetColor(COLOR_TEXT); } @@ -956,40 +990,33 @@ virtual void SignalMove(GeometricPrimitive& primitive, const Scene2D& scene) ORTHANC_OVERRIDE { - UpdateProbe(scene); + label_.SetPosition(handle_.GetCenter().GetX(), handle_.GetCenter().GetY()); } virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE { - TextSceneLayer content; - - content.SetPosition(handle_.GetCenter().GetX(), handle_.GetCenter().GetY()); - content.SetAnchor(BitmapAnchor_CenterLeft); - content.SetBorder(10); - if (scene.HasLayer(probedLayer_)) { - const TextureBaseSceneLayer& layer = dynamic_cast(scene.GetLayer(probedLayer_)); - const AffineTransform2D sceneToTexture = AffineTransform2D::Invert(layer.GetTransform()); + const ISceneLayer& layer = scene.GetLayer(probedLayer_); + if (layer.GetType() == ISceneLayer::Type_FloatTexture || + layer.GetType() == ISceneLayer::Type_ColorTexture) + { + const TextureBaseSceneLayer& texture = dynamic_cast(scene.GetLayer(probedLayer_)); + const AffineTransform2D sceneToTexture = AffineTransform2D::Invert(texture.GetTransform()); - double x = handle_.GetCenter().GetX(); - double y = handle_.GetCenter().GetY(); - sceneToTexture.Apply(x, y); - - int textureX = static_cast(std::floor(x)); - int textureY = static_cast(std::floor(y)); - - char buf[64]; - sprintf(buf, "Hello %d x %d / (%d,%d)\n", layer.GetTexture().GetWidth(), layer.GetTexture().GetHeight(), - textureX, textureY); - content.SetText(buf); + double x = handle_.GetCenter().GetX(); + double y = handle_.GetCenter().GetY(); + sceneToTexture.Apply(x, y); + + int textureX = static_cast(std::floor(x)); + int textureY = static_cast(std::floor(y)); + + char buf[64]; + sprintf(buf, "Hello %d x %d / (%d,%d)\n", texture.GetTexture().GetWidth(), texture.GetTexture().GetHeight(), + textureX, textureY); + label_.SetText(buf); + } } - else - { - content.SetText("????"); - } - - label_.SetContent(content); } virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE @@ -1660,6 +1687,13 @@ void AnnotationsSceneLayer::Render(Scene2D& scene) { + // First, update the probes + for (Annotations::const_iterator it = annotations_.begin(); it != annotations_.end(); ++it) + { + assert(*it != NULL); + (*it)->UpdateProbe(scene); + } + MacroSceneLayer* macro = NULL; if (scene.HasLayer(macroLayerIndex_)) @@ -1911,14 +1945,4 @@ } } } - - - void AnnotationsSceneLayer::UpdateProbes(const Scene2D& scene) - { - for (Annotations::const_iterator it = annotations_.begin(); it != annotations_.end(); ++it) - { - assert(*it != NULL); - (*it)->UpdateProbe(scene); - } - } } diff -r d71acf30970a -r ba971d9082d3 OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.h --- a/OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.h Sat Oct 29 13:02:21 2022 +0200 +++ b/OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.h Sat Oct 29 16:31:09 2022 +0200 @@ -146,7 +146,5 @@ { return probedLayer_; } - - void UpdateProbes(const Scene2D& scene); }; }