Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp @ 1977:ba971d9082d3
cont pixel probe
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 29 Oct 2022 16:31:09 +0200 |
parents | d71acf30970a |
children | 95449b0e064a |
comparison
equal
deleted
inserted
replaced
1976:d71acf30970a | 1977:ba971d9082d3 |
---|---|
683 | 683 |
684 void SetContent(const TextSceneLayer& content) | 684 void SetContent(const TextSceneLayer& content) |
685 { | 685 { |
686 SetModified(true); | 686 SetModified(true); |
687 content_.reset(dynamic_cast<TextSceneLayer*>(content.Clone())); | 687 content_.reset(dynamic_cast<TextSceneLayer*>(content.Clone())); |
688 } | 688 } |
689 | |
690 void SetText(const std::string& text) | |
691 { | |
692 if (content_.get() == NULL) | |
693 { | |
694 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
695 } | |
696 else | |
697 { | |
698 SetModified(true); | |
699 content_->SetText(text); | |
700 } | |
701 } | |
702 | |
703 void SetPosition(double x, | |
704 double y) | |
705 { | |
706 if (content_.get() == NULL) | |
707 { | |
708 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
709 } | |
710 else | |
711 { | |
712 SetModified(true); | |
713 content_->SetPosition(x, y); | |
714 } | |
715 } | |
689 | 716 |
690 virtual bool IsHit(const ScenePoint2D& p, | 717 virtual bool IsHit(const ScenePoint2D& p, |
691 const Scene2D& scene) const ORTHANC_OVERRIDE | 718 const Scene2D& scene) const ORTHANC_OVERRIDE |
692 { | 719 { |
693 return false; | 720 return false; |
925 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an segment annotation"); | 952 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an segment annotation"); |
926 } | 953 } |
927 } | 954 } |
928 }; | 955 }; |
929 | 956 |
930 | 957 |
931 class AnnotationsSceneLayer::PixelProbeAnnotation : public Annotation | 958 class AnnotationsSceneLayer::PixelProbeAnnotation : public Annotation |
932 { | 959 { |
933 private: | 960 private: |
934 int probedLayer_; | 961 int probedLayer_; |
935 Handle& handle_; | 962 Handle& handle_; |
943 Annotation(that, units), | 970 Annotation(that, units), |
944 probedLayer_(probedLayer), | 971 probedLayer_(probedLayer), |
945 handle_(AddTypedPrimitive<Handle>(new Handle(*this, p))), | 972 handle_(AddTypedPrimitive<Handle>(new Handle(*this, p))), |
946 label_(AddTypedPrimitive<Text>(new Text(that, *this))) | 973 label_(AddTypedPrimitive<Text>(new Text(that, *this))) |
947 { | 974 { |
948 label_.SetColor(COLOR_TEXT); | |
949 } | |
950 | |
951 Handle& GetHandle() const | |
952 { | |
953 return handle_; | |
954 } | |
955 | |
956 virtual void SignalMove(GeometricPrimitive& primitive, | |
957 const Scene2D& scene) ORTHANC_OVERRIDE | |
958 { | |
959 UpdateProbe(scene); | |
960 } | |
961 | |
962 virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE | |
963 { | |
964 TextSceneLayer content; | 975 TextSceneLayer content; |
965 | |
966 content.SetPosition(handle_.GetCenter().GetX(), handle_.GetCenter().GetY()); | 976 content.SetPosition(handle_.GetCenter().GetX(), handle_.GetCenter().GetY()); |
967 content.SetAnchor(BitmapAnchor_CenterLeft); | 977 content.SetAnchor(BitmapAnchor_CenterLeft); |
968 content.SetBorder(10); | 978 content.SetBorder(10); |
969 | 979 content.SetText("?"); |
980 | |
981 label_.SetContent(content); | |
982 label_.SetColor(COLOR_TEXT); | |
983 } | |
984 | |
985 Handle& GetHandle() const | |
986 { | |
987 return handle_; | |
988 } | |
989 | |
990 virtual void SignalMove(GeometricPrimitive& primitive, | |
991 const Scene2D& scene) ORTHANC_OVERRIDE | |
992 { | |
993 label_.SetPosition(handle_.GetCenter().GetX(), handle_.GetCenter().GetY()); | |
994 } | |
995 | |
996 virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE | |
997 { | |
970 if (scene.HasLayer(probedLayer_)) | 998 if (scene.HasLayer(probedLayer_)) |
971 { | 999 { |
972 const TextureBaseSceneLayer& layer = dynamic_cast<TextureBaseSceneLayer&>(scene.GetLayer(probedLayer_)); | 1000 const ISceneLayer& layer = scene.GetLayer(probedLayer_); |
973 const AffineTransform2D sceneToTexture = AffineTransform2D::Invert(layer.GetTransform()); | 1001 if (layer.GetType() == ISceneLayer::Type_FloatTexture || |
974 | 1002 layer.GetType() == ISceneLayer::Type_ColorTexture) |
975 double x = handle_.GetCenter().GetX(); | 1003 { |
976 double y = handle_.GetCenter().GetY(); | 1004 const TextureBaseSceneLayer& texture = dynamic_cast<TextureBaseSceneLayer&>(scene.GetLayer(probedLayer_)); |
977 sceneToTexture.Apply(x, y); | 1005 const AffineTransform2D sceneToTexture = AffineTransform2D::Invert(texture.GetTransform()); |
978 | 1006 |
979 int textureX = static_cast<int>(std::floor(x)); | 1007 double x = handle_.GetCenter().GetX(); |
980 int textureY = static_cast<int>(std::floor(y)); | 1008 double y = handle_.GetCenter().GetY(); |
981 | 1009 sceneToTexture.Apply(x, y); |
982 char buf[64]; | 1010 |
983 sprintf(buf, "Hello %d x %d / (%d,%d)\n", layer.GetTexture().GetWidth(), layer.GetTexture().GetHeight(), | 1011 int textureX = static_cast<int>(std::floor(x)); |
984 textureX, textureY); | 1012 int textureY = static_cast<int>(std::floor(y)); |
985 content.SetText(buf); | 1013 |
986 } | 1014 char buf[64]; |
987 else | 1015 sprintf(buf, "Hello %d x %d / (%d,%d)\n", texture.GetTexture().GetWidth(), texture.GetTexture().GetHeight(), |
988 { | 1016 textureX, textureY); |
989 content.SetText("????"); | 1017 label_.SetText(buf); |
990 } | 1018 } |
991 | 1019 } |
992 label_.SetContent(content); | |
993 } | 1020 } |
994 | 1021 |
995 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE | 1022 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE |
996 { | 1023 { |
997 target = Json::objectValue; | 1024 target = Json::objectValue; |
1658 } | 1685 } |
1659 | 1686 |
1660 | 1687 |
1661 void AnnotationsSceneLayer::Render(Scene2D& scene) | 1688 void AnnotationsSceneLayer::Render(Scene2D& scene) |
1662 { | 1689 { |
1690 // First, update the probes | |
1691 for (Annotations::const_iterator it = annotations_.begin(); it != annotations_.end(); ++it) | |
1692 { | |
1693 assert(*it != NULL); | |
1694 (*it)->UpdateProbe(scene); | |
1695 } | |
1696 | |
1663 MacroSceneLayer* macro = NULL; | 1697 MacroSceneLayer* macro = NULL; |
1664 | 1698 |
1665 if (scene.HasLayer(macroLayerIndex_)) | 1699 if (scene.HasLayer(macroLayerIndex_)) |
1666 { | 1700 { |
1667 macro = &dynamic_cast<MacroSceneLayer&>(scene.GetLayer(macroLayerIndex_)); | 1701 macro = &dynamic_cast<MacroSceneLayer&>(scene.GetLayer(macroLayerIndex_)); |
1909 { | 1943 { |
1910 LOG(ERROR) << "Cannot unserialize unknown type of annotation: " << type; | 1944 LOG(ERROR) << "Cannot unserialize unknown type of annotation: " << type; |
1911 } | 1945 } |
1912 } | 1946 } |
1913 } | 1947 } |
1914 | |
1915 | |
1916 void AnnotationsSceneLayer::UpdateProbes(const Scene2D& scene) | |
1917 { | |
1918 for (Annotations::const_iterator it = annotations_.begin(); it != annotations_.end(); ++it) | |
1919 { | |
1920 assert(*it != NULL); | |
1921 (*it)->UpdateProbe(scene); | |
1922 } | |
1923 } | |
1924 } | 1948 } |