Mercurial > hg > orthanc-stone
comparison 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 |
comparison
equal
deleted
inserted
replaced
589:3080ec4ec6b9 | 590:5430bcffba57 |
---|---|
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 #include "ColorTextureSceneLayer.h" | 22 #include "ColorTextureSceneLayer.h" |
23 | 23 |
24 #include <Core/OrthancException.h> | |
24 #include <Core/Images/Image.h> | 25 #include <Core/Images/Image.h> |
25 #include <Core/OrthancException.h> | 26 |
26 | 27 |
27 namespace OrthancStone | 28 namespace OrthancStone |
28 { | 29 { |
29 ColorTextureSceneLayer::ColorTextureSceneLayer(const Orthanc::ImageAccessor& texture, | 30 ColorTextureSceneLayer::ColorTextureSceneLayer(const Orthanc::ImageAccessor& texture) |
30 double originX, // Center of the top-left pixel | |
31 double originY, | |
32 double pixelSpacingX, | |
33 double pixelSpacingY, | |
34 double angle, | |
35 bool isLinearInterpolation) : | |
36 texture_(Orthanc::Image::Clone(texture)), | |
37 originX_(originX), | |
38 originY_(originY), | |
39 pixelSpacingX_(pixelSpacingX), | |
40 pixelSpacingY_(pixelSpacingY), | |
41 angle_(angle), | |
42 isLinearInterpolation_(isLinearInterpolation) | |
43 { | 31 { |
44 if (texture_->GetFormat() != Orthanc::PixelFormat_Grayscale8 && | 32 if (texture.GetFormat() != Orthanc::PixelFormat_Grayscale8 && |
45 texture_->GetFormat() != Orthanc::PixelFormat_RGBA32 && | 33 texture.GetFormat() != Orthanc::PixelFormat_RGBA32 && |
46 texture_->GetFormat() != Orthanc::PixelFormat_RGB24) | 34 texture.GetFormat() != Orthanc::PixelFormat_RGB24) |
47 { | 35 { |
48 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | 36 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
49 } | 37 } |
50 | 38 |
51 if (pixelSpacingX_ <= 0 || | 39 SetTexture(Orthanc::Image::Clone(texture)); |
52 pixelSpacingY_ <= 0) | |
53 { | |
54 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
55 } | |
56 } | 40 } |
57 | 41 |
58 | 42 |
59 ISceneLayer* ColorTextureSceneLayer::Clone() const | 43 ISceneLayer* ColorTextureSceneLayer::Clone() const |
60 { | 44 { |
61 return new ColorTextureSceneLayer(*texture_, originX_, originY_, | 45 std::auto_ptr<ColorTextureSceneLayer> cloned(new ColorTextureSceneLayer(GetTexture())); |
62 pixelSpacingX_, pixelSpacingY_, angle_, | 46 cloned->CopyParameters(*this); |
63 isLinearInterpolation_); | 47 return cloned.release(); |
64 } | |
65 | |
66 | |
67 AffineTransform2D ColorTextureSceneLayer::GetTransform() const | |
68 { | |
69 return AffineTransform2D::Combine( | |
70 AffineTransform2D::CreateOffset(originX_, originY_), | |
71 AffineTransform2D::CreateRotation(angle_), | |
72 AffineTransform2D::CreateScaling(pixelSpacingX_, pixelSpacingY_), | |
73 AffineTransform2D::CreateOffset(-0.5, -0.5)); | |
74 } | |
75 | |
76 | |
77 bool ColorTextureSceneLayer::GetBoundingBox(Extent2D& target) const | |
78 { | |
79 const AffineTransform2D t = GetTransform(); | |
80 | |
81 target.Reset(); | |
82 | |
83 double x, y; | |
84 | |
85 x = 0; | |
86 y = 0; | |
87 t.Apply(x, y); | |
88 target.AddPoint(x, y); | |
89 | |
90 x = static_cast<double>(texture_->GetWidth()); | |
91 y = 0; | |
92 t.Apply(x, y); | |
93 target.AddPoint(x, y); | |
94 | |
95 x = 0; | |
96 y = static_cast<double>(texture_->GetHeight()); | |
97 t.Apply(x, y); | |
98 target.AddPoint(x, y); | |
99 | |
100 x = static_cast<double>(texture_->GetWidth()); | |
101 y = static_cast<double>(texture_->GetHeight()); | |
102 t.Apply(x, y); | |
103 target.AddPoint(x, y); | |
104 | |
105 return true; | |
106 } | 48 } |
107 } | 49 } |