diff Framework/Radiography/RadiographyScene.cpp @ 410:6decc0ba9da5

rename RadiographyScene::Layer as RadiographyLayer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 12 Nov 2018 15:52:03 +0100
parents 99c9b3238008
children 71c16998fcc8
line wrap: on
line diff
--- a/Framework/Radiography/RadiographyScene.cpp	Mon Nov 12 15:38:11 2018 +0100
+++ b/Framework/Radiography/RadiographyScene.cpp	Mon Nov 12 15:52:03 2018 +0100
@@ -21,7 +21,6 @@
 
 #include "RadiographyScene.h"
 
-#include "../Toolbox/ImageGeometry.h"
 #include "../Toolbox/DicomFrameConverter.h"
 
 #include <Core/Images/Image.h>
@@ -37,371 +36,6 @@
 
 namespace OrthancStone
 {
-  static double Square(double x)
-  {
-    return x * x;
-  }
-
-
-  void RadiographyScene::Layer::UpdateTransform()
-  {
-    transform_ = AffineTransform2D::CreateScaling(pixelSpacingX_, pixelSpacingY_);
-
-    double centerX, centerY;
-    GetCenter(centerX, centerY);
-
-    transform_ = AffineTransform2D::Combine(
-      AffineTransform2D::CreateOffset(panX_ + centerX, panY_ + centerY),
-      AffineTransform2D::CreateRotation(angle_),
-      AffineTransform2D::CreateOffset(-centerX, -centerY),
-      transform_);
-
-    transformInverse_ = AffineTransform2D::Invert(transform_);
-  }
-
-
-  void RadiographyScene::Layer::AddToExtent(Extent2D& extent,
-                                            double x,
-                                            double y) const
-  {
-    transform_.Apply(x, y);
-    extent.AddPoint(x, y);
-  }
-
-
-  void RadiographyScene::Layer::GetCornerInternal(double& x,
-                                                  double& y,
-                                                  Corner corner,
-                                                  unsigned int cropX,
-                                                  unsigned int cropY,
-                                                  unsigned int cropWidth,
-                                                  unsigned int cropHeight) const
-  {
-    double dx = static_cast<double>(cropX);
-    double dy = static_cast<double>(cropY);
-    double dwidth = static_cast<double>(cropWidth);
-    double dheight = static_cast<double>(cropHeight);
-
-    switch (corner)
-    {
-      case Corner_TopLeft:
-        x = dx;
-        y = dy;
-        break;
-
-      case Corner_TopRight:
-        x = dx + dwidth;
-        y = dy;
-        break;
-
-      case Corner_BottomLeft:
-        x = dx;
-        y = dy + dheight;
-        break;
-
-      case Corner_BottomRight:
-        x = dx + dwidth;
-        y = dy + dheight;
-        break;
-
-      default:
-        throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
-    }
-
-    transform_.Apply(x, y);
-  }
-
-
-  bool RadiographyScene::Layer::Contains(double x,
-                                         double y) const
-  {
-    transformInverse_.Apply(x, y);
-        
-    unsigned int cropX, cropY, cropWidth, cropHeight;
-    GetCrop(cropX, cropY, cropWidth, cropHeight);
-
-    return (x >= cropX && x <= cropX + cropWidth &&
-            y >= cropY && y <= cropY + cropHeight);
-  }
-
-
-  void RadiographyScene::Layer::DrawBorders(CairoContext& context,
-                                            double zoom)
-  {
-    unsigned int cx, cy, width, height;
-    GetCrop(cx, cy, width, height);
-
-    double dx = static_cast<double>(cx);
-    double dy = static_cast<double>(cy);
-    double dwidth = static_cast<double>(width);
-    double dheight = static_cast<double>(height);
-
-    cairo_t* cr = context.GetObject();
-    cairo_set_line_width(cr, 2.0 / zoom);
-        
-    double x, y;
-    x = dx;
-    y = dy;
-    transform_.Apply(x, y);
-    cairo_move_to(cr, x, y);
-
-    x = dx + dwidth;
-    y = dy;
-    transform_.Apply(x, y);
-    cairo_line_to(cr, x, y);
-
-    x = dx + dwidth;
-    y = dy + dheight;
-    transform_.Apply(x, y);
-    cairo_line_to(cr, x, y);
-
-    x = dx;
-    y = dy + dheight;
-    transform_.Apply(x, y);
-    cairo_line_to(cr, x, y);
-
-    x = dx;
-    y = dy;
-    transform_.Apply(x, y);
-    cairo_line_to(cr, x, y);
-
-    cairo_stroke(cr);
-  }
-
-
-  RadiographyScene::Layer::Layer() :
-    index_(0),
-    hasSize_(false),
-    width_(0),
-    height_(0),
-    hasCrop_(false),
-    pixelSpacingX_(1),
-    pixelSpacingY_(1),
-    panX_(0),
-    panY_(0),
-    angle_(0),
-    resizeable_(false)
-  {
-    UpdateTransform();
-  }
-
-
-  void RadiographyScene::Layer::SetCrop(unsigned int x,
-                                        unsigned int y,
-                                        unsigned int width,
-                                        unsigned int height)
-  {
-    if (!hasSize_)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
-    }
-        
-    if (x + width > width_ ||
-        y + height > height_)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
-    }
-        
-    hasCrop_ = true;
-    cropX_ = x;
-    cropY_ = y;
-    cropWidth_ = width;
-    cropHeight_ = height;
-
-    UpdateTransform();
-  }
-
-      
-  void RadiographyScene::Layer::GetCrop(unsigned int& x,
-                                        unsigned int& y,
-                                        unsigned int& width,
-                                        unsigned int& height) const
-  {
-    if (hasCrop_)
-    {
-      x = cropX_;
-      y = cropY_;
-      width = cropWidth_;
-      height = cropHeight_;
-    }
-    else 
-    {
-      x = 0;
-      y = 0;
-      width = width_;
-      height = height_;
-    }
-  }
-
-      
-  void RadiographyScene::Layer::SetAngle(double angle)
-  {
-    angle_ = angle;
-    UpdateTransform();
-  }
-
-
-  void RadiographyScene::Layer::SetSize(unsigned int width,
-                                        unsigned int height)
-  {
-    if (hasSize_ &&
-        (width != width_ ||
-         height != height_))
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
-    }
-        
-    hasSize_ = true;
-    width_ = width;
-    height_ = height;
-
-    UpdateTransform();
-  }
-
-
-  Extent2D RadiographyScene::Layer::GetExtent() const
-  {
-    Extent2D extent;
-       
-    unsigned int x, y, width, height;
-    GetCrop(x, y, width, height);
-
-    double dx = static_cast<double>(x);
-    double dy = static_cast<double>(y);
-    double dwidth = static_cast<double>(width);
-    double dheight = static_cast<double>(height);
-
-    AddToExtent(extent, dx, dy);
-    AddToExtent(extent, dx + dwidth, dy);
-    AddToExtent(extent, dx, dy + dheight);
-    AddToExtent(extent, dx + dwidth, dy + dheight);
-        
-    return extent;
-  }
-
-
-  bool RadiographyScene::Layer::GetPixel(unsigned int& imageX,
-                                         unsigned int& imageY,
-                                         double sceneX,
-                                         double sceneY) const
-  {
-    if (width_ == 0 ||
-        height_ == 0)
-    {
-      return false;
-    }
-    else
-    {
-      transformInverse_.Apply(sceneX, sceneY);
-        
-      int x = static_cast<int>(std::floor(sceneX));
-      int y = static_cast<int>(std::floor(sceneY));
-
-      if (x < 0)
-      {
-        imageX = 0;
-      }
-      else if (x >= static_cast<int>(width_))
-      {
-        imageX = width_;
-      }
-      else
-      {
-        imageX = static_cast<unsigned int>(x);
-      }
-
-      if (y < 0)
-      {
-        imageY = 0;
-      }
-      else if (y >= static_cast<int>(height_))
-      {
-        imageY = height_;
-      }
-      else
-      {
-        imageY = static_cast<unsigned int>(y);
-      }
-
-      return true;
-    }
-  }
-
-
-  void RadiographyScene::Layer::SetPan(double x,
-                                       double y)
-  {
-    panX_ = x;
-    panY_ = y;
-    UpdateTransform();
-  }
-
-
-  void RadiographyScene::Layer::SetPixelSpacing(double x,
-                                                double y)
-  {
-    pixelSpacingX_ = x;
-    pixelSpacingY_ = y;
-    UpdateTransform();
-  }
-
-
-  void RadiographyScene::Layer::GetCenter(double& centerX,
-                                          double& centerY) const
-  {
-    centerX = static_cast<double>(width_) / 2.0;
-    centerY = static_cast<double>(height_) / 2.0;
-    transform_.Apply(centerX, centerY);
-  }
-
-
-  void RadiographyScene::Layer::GetCorner(double& x /* out */,
-                                          double& y /* out */,
-                                          Corner corner) const
-  {
-    unsigned int cropX, cropY, cropWidth, cropHeight;
-    GetCrop(cropX, cropY, cropWidth, cropHeight);
-    GetCornerInternal(x, y, corner, cropX, cropY, cropWidth, cropHeight);
-  }
-      
-      
-  bool RadiographyScene::Layer::LookupCorner(Corner& corner /* out */,
-                                             double x,
-                                             double y,
-                                             double zoom,
-                                             double viewportDistance) const
-  {
-    static const Corner CORNERS[] = {
-      Corner_TopLeft,
-      Corner_TopRight,
-      Corner_BottomLeft,
-      Corner_BottomRight
-    };
-        
-    unsigned int cropX, cropY, cropWidth, cropHeight;
-    GetCrop(cropX, cropY, cropWidth, cropHeight);
-
-    double threshold = Square(viewportDistance / zoom);
-        
-    for (size_t i = 0; i < 4; i++)
-    {
-      double cx, cy;
-      GetCornerInternal(cx, cy, CORNERS[i], cropX, cropY, cropWidth, cropHeight);
-
-      double d = Square(cx - x) + Square(cy - y);
-        
-      if (d <= threshold)
-      {
-        corner = CORNERS[i];
-        return true;
-      }
-    }
-        
-    return false;
-  }
-
-      
-
   RadiographyScene::LayerAccessor::LayerAccessor(RadiographyScene& scene,
                                                  size_t index) :
     scene_(scene),
@@ -473,7 +107,7 @@
   }
 
   
-  RadiographyScene::Layer& RadiographyScene::LayerAccessor::GetLayer() const
+  RadiographyLayer& RadiographyScene::LayerAccessor::GetLayer() const
   {
     if (IsValid())
     {
@@ -487,7 +121,7 @@
 
 
 
-  class RadiographyScene::AlphaLayer : public Layer
+  class RadiographyScene::AlphaLayer : public RadiographyLayer
   {
   private:
     const RadiographyScene&                scene_;
@@ -631,7 +265,7 @@
     
     
 
-  class RadiographyScene::DicomLayer : public Layer
+  class RadiographyScene::DicomLayer : public RadiographyLayer
   {
   private:
     std::auto_ptr<Orthanc::ImageAccessor>  source_;  // Content of PixelData
@@ -767,14 +401,14 @@
   };
 
 
-  RadiographyScene::Layer& RadiographyScene::RegisterLayer(RadiographyScene::Layer* layer)
+  RadiographyLayer& RadiographyScene::RegisterLayer(RadiographyLayer* layer)
   {
     if (layer == NULL)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
     }
 
-    std::auto_ptr<Layer> raii(layer);
+    std::auto_ptr<RadiographyLayer> raii(layer);
       
     size_t index = countLayers_++;
     raii->SetIndex(index);
@@ -846,8 +480,8 @@
   }
 
 
-  RadiographyScene::Layer& RadiographyScene::LoadText(const Orthanc::Font& font,
-                                                      const std::string& utf8)
+  RadiographyLayer& RadiographyScene::LoadText(const Orthanc::Font& font,
+                                               const std::string& utf8)
   {
     std::auto_ptr<AlphaLayer>  alpha(new AlphaLayer(*this));
     alpha->LoadText(font, utf8);
@@ -856,8 +490,8 @@
   }
 
     
-  RadiographyScene::Layer& RadiographyScene::LoadTestBlock(unsigned int width,
-                                                           unsigned int height)
+  RadiographyLayer& RadiographyScene::LoadTestBlock(unsigned int width,
+                                                    unsigned int height)
   {
     std::auto_ptr<Orthanc::Image>  block(new Orthanc::Image(Orthanc::PixelFormat_Grayscale8, width, height, false));
 
@@ -887,11 +521,11 @@
   }
 
     
-  RadiographyScene::Layer& RadiographyScene::LoadDicomFrame(const std::string& instance,
-                                                            unsigned int frame,
-                                                            bool httpCompression)
+  RadiographyLayer& RadiographyScene::LoadDicomFrame(const std::string& instance,
+                                                     unsigned int frame,
+                                                     bool httpCompression)
   {
-    Layer& layer = RegisterLayer(new DicomLayer);
+    RadiographyLayer& layer = RegisterLayer(new DicomLayer);
 
     {
       IWebService::Headers headers;