comparison Framework/Scene2D/TextureSceneLayer.cpp @ 584:434ceeb0bcab

layers: InfoPanel, Polyline, Texture
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 19 Apr 2019 17:36:00 +0200
parents
children
comparison
equal deleted inserted replaced
583:f9ac154c5a63 584:434ceeb0bcab
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "TextureSceneLayer.h"
23
24 #include <Core/Images/Image.h>
25 #include <Core/OrthancException.h>
26
27 namespace OrthancStone
28 {
29 TextureSceneLayer::TextureSceneLayer(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 {
44 if (texture_->GetFormat() != Orthanc::PixelFormat_Grayscale8 &&
45 texture_->GetFormat() != Orthanc::PixelFormat_RGBA32 &&
46 texture_->GetFormat() != Orthanc::PixelFormat_RGB24)
47 {
48 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
49 }
50
51 if (pixelSpacingX_ <= 0 ||
52 pixelSpacingY_ <= 0)
53 {
54 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
55 }
56 }
57
58
59 ISceneLayer* TextureSceneLayer::Clone() const
60 {
61 return new TextureSceneLayer(*texture_, originX_, originY_,
62 pixelSpacingX_, pixelSpacingY_, angle_,
63 isLinearInterpolation_);
64 }
65
66
67 AffineTransform2D TextureSceneLayer::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 TextureSceneLayer::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 }
107 }