changeset 620:fd9b9d993fc7 am-dev

added flip to RadiographyLayer
author Alain Mazy <alain@mazy.be>
date Tue, 07 May 2019 11:15:57 +0200
parents 8432926e9db9
children b7fd0471281c
files Framework/Radiography/RadiographyLayer.cpp Framework/Radiography/RadiographyLayer.h Framework/Radiography/RadiographyScene.h Framework/Radiography/RadiographySceneReader.cpp Framework/Radiography/RadiographySceneWriter.cpp
diffstat 5 files changed, 68 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Radiography/RadiographyLayer.cpp	Mon Apr 29 12:01:55 2019 +0200
+++ b/Framework/Radiography/RadiographyLayer.cpp	Tue May 07 11:15:57 2019 +0200
@@ -34,6 +34,8 @@
 
   RadiographyLayer::Geometry::Geometry() :
     hasCrop_(false),
+    verticalFlip_(false),
+    horizontalFlip_(false),
     panX_(0),
     panY_(0),
     angle_(0),
@@ -57,7 +59,7 @@
 
   void RadiographyLayer::UpdateTransform()
   {
-    transform_ = AffineTransform2D::CreateScaling(geometry_.GetPixelSpacingX(), geometry_.GetPixelSpacingY());
+    transform_ = AffineTransform2D::CreateScaling(geometry_.GetScalingX(), geometry_.GetScalingY());
 
     double centerX, centerY;
     GetCenter(centerX, centerY);
@@ -204,6 +206,21 @@
     EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
   }
 
+  void RadiographyLayer::SetVerticalFlip(bool flip)
+  {
+    geometry_.SetVerticalFlip(flip);
+    UpdateTransform();
+
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
+  }
+
+  void RadiographyLayer::SetHorizontalFlip(bool flip)
+  {
+    geometry_.SetHorizontalFlip(flip);
+    UpdateTransform();
+
+    EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
+  }
 
   void RadiographyLayer::SetSize(unsigned int width,
                                  unsigned int height)
--- a/Framework/Radiography/RadiographyLayer.h	Mon Apr 29 12:01:55 2019 +0200
+++ b/Framework/Radiography/RadiographyLayer.h	Tue May 07 11:15:57 2019 +0200
@@ -75,6 +75,8 @@
       unsigned int       cropY_;
       unsigned int       cropWidth_;
       unsigned int       cropHeight_;
+      bool               verticalFlip_;
+      bool               horizontalFlip_;
       double             panX_;
       double             panY_;
       double             angle_;
@@ -166,6 +168,35 @@
         return pixelSpacingY_;
       }
 
+      void SetVerticalFlip(bool flip) //  mirrors image around an horizontal axis (note: flip is applied before the rotation !)
+      {
+        verticalFlip_ = flip;
+      }
+
+      void SetHorizontalFlip(bool flip) //  mirrors image around a vertical axis (note: flip is applied before the rotation !)
+      {
+        horizontalFlip_ = flip;
+      }
+
+      bool GetVerticalFlip() const
+      {
+        return verticalFlip_;
+      }
+
+      bool GetHorizontalFlip() const
+      {
+        return horizontalFlip_;
+      }
+
+      double GetScalingX() const
+      {
+        return (horizontalFlip_ ? - pixelSpacingX_: pixelSpacingX_);
+      }
+
+      double GetScalingY() const
+      {
+        return (verticalFlip_ ? - pixelSpacingY_: pixelSpacingY_);
+      }
     };
 
   private:
@@ -251,6 +282,10 @@
     void SetPan(double x,
                 double y);
 
+    void SetVerticalFlip(bool flip); //  mirrors image around an horizontal axis (note: flip is applied before the rotation !)
+
+    void SetHorizontalFlip(bool flip); //  mirrors image around a vertical axis (note: flip is applied before the rotation !)
+
     void SetResizeable(bool resizeable)
     {
       geometry_.SetResizeable(resizeable);
--- a/Framework/Radiography/RadiographyScene.h	Mon Apr 29 12:01:55 2019 +0200
+++ b/Framework/Radiography/RadiographyScene.h	Tue May 07 11:15:57 2019 +0200
@@ -156,7 +156,7 @@
 
     void OnTagsReceived(const OrthancApiClient::BinaryResponseReadyMessage& message);
 
-    void OnFrameReceived(const OrthancApiClient::BinaryResponseReadyMessage& message);
+    virtual void OnFrameReceived(const OrthancApiClient::BinaryResponseReadyMessage& message);
     
     void OnDicomExported(const OrthancApiClient::JsonResponseReadyMessage& message);
 
--- a/Framework/Radiography/RadiographySceneReader.cpp	Mon Apr 29 12:01:55 2019 +0200
+++ b/Framework/Radiography/RadiographySceneReader.cpp	Tue May 07 11:15:57 2019 +0200
@@ -234,5 +234,16 @@
     geometry.SetResizeable(jsonLayer["isResizable"].asBool());
     geometry.SetPan(jsonLayer["pan"]["x"].asDouble(), jsonLayer["pan"]["y"].asDouble());
     geometry.SetPixelSpacing(jsonLayer["pixelSpacing"]["x"].asDouble(), jsonLayer["pixelSpacing"]["y"].asDouble());
+
+    // these fields were introduced later -> they might not exist
+    if (jsonLayer.isMember("verticalFlip"))
+    {
+      geometry.SetVerticalFlip(jsonLayer["verticalFlip"].asBool());
+    }
+    if (jsonLayer.isMember("horizontalFlip"))
+    {
+      geometry.SetHorizontalFlip(jsonLayer["horizontalFlip"].asBool());
+    }
+
   }
 }
--- a/Framework/Radiography/RadiographySceneWriter.cpp	Mon Apr 29 12:01:55 2019 +0200
+++ b/Framework/Radiography/RadiographySceneWriter.cpp	Tue May 07 11:15:57 2019 +0200
@@ -132,6 +132,9 @@
       output["pixelSpacing"] = pan;
     }
 
+    output["verticalFlip"] = geometry.GetVerticalFlip();
+    output["horizontalFlip"] = geometry.GetHorizontalFlip();
+
     if (dynamic_cast<const RadiographyTextLayer*>(&layer) != NULL)
     {
       WriteLayer(output, dynamic_cast<const RadiographyTextLayer&>(layer));