diff Framework/Scene2D/ColorTextureSceneLayer.cpp @ 590:5430bcffba57

FloatTextureSceneLayer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Apr 2019 11:33:57 +0200
parents 2a8ac2d426db
children 2d8ab34c8c91
line wrap: on
line diff
--- a/Framework/Scene2D/ColorTextureSceneLayer.cpp	Thu Apr 25 14:00:55 2019 +0200
+++ b/Framework/Scene2D/ColorTextureSceneLayer.cpp	Fri Apr 26 11:33:57 2019 +0200
@@ -21,87 +21,29 @@
 
 #include "ColorTextureSceneLayer.h"
 
+#include <Core/OrthancException.h>
 #include <Core/Images/Image.h>
-#include <Core/OrthancException.h>
+
 
 namespace OrthancStone
 {
-  ColorTextureSceneLayer::ColorTextureSceneLayer(const Orthanc::ImageAccessor& texture,
-                                                 double originX,  // Center of the top-left pixel
-                                                 double originY,
-                                                 double pixelSpacingX,
-                                                 double pixelSpacingY,
-                                                 double angle,
-                                                 bool isLinearInterpolation) :
-    texture_(Orthanc::Image::Clone(texture)),
-    originX_(originX),
-    originY_(originY),
-    pixelSpacingX_(pixelSpacingX),
-    pixelSpacingY_(pixelSpacingY),
-    angle_(angle),
-    isLinearInterpolation_(isLinearInterpolation)
+  ColorTextureSceneLayer::ColorTextureSceneLayer(const Orthanc::ImageAccessor& texture)
   {
-    if (texture_->GetFormat() != Orthanc::PixelFormat_Grayscale8 &&
-        texture_->GetFormat() != Orthanc::PixelFormat_RGBA32 &&
-        texture_->GetFormat() != Orthanc::PixelFormat_RGB24)
+    if (texture.GetFormat() != Orthanc::PixelFormat_Grayscale8 &&
+        texture.GetFormat() != Orthanc::PixelFormat_RGBA32 &&
+        texture.GetFormat() != Orthanc::PixelFormat_RGB24)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
     }
-
-    if (pixelSpacingX_ <= 0 ||
-        pixelSpacingY_ <= 0)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
-    }
+      
+    SetTexture(Orthanc::Image::Clone(texture));
   }
 
 
   ISceneLayer* ColorTextureSceneLayer::Clone() const
   {
-    return new ColorTextureSceneLayer(*texture_, originX_, originY_, 
-                                      pixelSpacingX_, pixelSpacingY_, angle_, 
-                                      isLinearInterpolation_);
-  }
-
-
-  AffineTransform2D ColorTextureSceneLayer::GetTransform() const
-  {
-    return AffineTransform2D::Combine(
-      AffineTransform2D::CreateOffset(originX_, originY_),
-      AffineTransform2D::CreateRotation(angle_),
-      AffineTransform2D::CreateScaling(pixelSpacingX_, pixelSpacingY_),
-      AffineTransform2D::CreateOffset(-0.5, -0.5));
-  }
-
-
-  bool ColorTextureSceneLayer::GetBoundingBox(Extent2D& target) const
-  {
-    const AffineTransform2D t = GetTransform();
-
-    target.Reset();
-    
-    double x, y;
-
-    x = 0;
-    y = 0;
-    t.Apply(x, y);
-    target.AddPoint(x, y);
-
-    x = static_cast<double>(texture_->GetWidth());
-    y = 0;
-    t.Apply(x, y);
-    target.AddPoint(x, y);
-
-    x = 0;
-    y = static_cast<double>(texture_->GetHeight());
-    t.Apply(x, y);
-    target.AddPoint(x, y);
-
-    x = static_cast<double>(texture_->GetWidth());
-    y = static_cast<double>(texture_->GetHeight());
-    t.Apply(x, y);
-    target.AddPoint(x, y);    
-
-    return true;
+    std::auto_ptr<ColorTextureSceneLayer> cloned(new ColorTextureSceneLayer(GetTexture()));
+    cloned->CopyParameters(*this);
+    return cloned.release();
   }
 }