comparison Framework/Scene2D/TextureBaseSceneLayer.cpp @ 590:5430bcffba57

FloatTextureSceneLayer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Apr 2019 11:33:57 +0200
parents
children a7351ad54960
comparison
equal deleted inserted replaced
589:3080ec4ec6b9 590:5430bcffba57
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 "TextureBaseSceneLayer.h"
23
24 #include <Core/OrthancException.h>
25
26 namespace OrthancStone
27 {
28 void TextureBaseSceneLayer::SetTexture(Orthanc::ImageAccessor* texture)
29 {
30 if (texture == NULL)
31 {
32 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
33 }
34 else
35 {
36 texture_.reset(texture);
37 IncrementRevision();
38 }
39 }
40
41
42 void TextureBaseSceneLayer::CopyParameters(const TextureBaseSceneLayer& other)
43 {
44 originX_ = other.originX_;
45 originY_ = other.originY_;
46 pixelSpacingX_ = other.pixelSpacingX_;
47 pixelSpacingY_ = other.pixelSpacingY_;
48 angle_ = other.angle_;
49 isLinearInterpolation_ = other.isLinearInterpolation_;
50 }
51
52
53 TextureBaseSceneLayer::TextureBaseSceneLayer() :
54 originX_(0),
55 originY_(0),
56 pixelSpacingX_(1),
57 pixelSpacingY_(1),
58 angle_(0),
59 isLinearInterpolation_(false),
60 revision_(0)
61 {
62 if (pixelSpacingX_ <= 0 ||
63 pixelSpacingY_ <= 0)
64 {
65 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
66 }
67 }
68
69
70 void TextureBaseSceneLayer::SetOrigin(double x,
71 double y)
72 {
73 originX_ = x;
74 originY_ = y;
75 IncrementRevision();
76 }
77
78
79 void TextureBaseSceneLayer::SetPixelSpacing(double sx,
80 double sy)
81 {
82 if (sx <= 0 ||
83 sy <= 0)
84 {
85 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
86 }
87 else
88 {
89 pixelSpacingX_ = sx;
90 pixelSpacingY_ = sy;
91 IncrementRevision();
92 }
93 }
94
95
96 void TextureBaseSceneLayer::SetAngle(double angle)
97 {
98 angle_ = angle;
99 IncrementRevision();
100 }
101
102
103 void TextureBaseSceneLayer::SetLinearInterpolation(bool isLinearInterpolation)
104 {
105 isLinearInterpolation_ = isLinearInterpolation;
106 IncrementRevision();
107 }
108
109
110 const Orthanc::ImageAccessor& TextureBaseSceneLayer::GetTexture() const
111 {
112 if (!HasTexture())
113 {
114 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
115 }
116 else
117 {
118 return *texture_;
119 }
120 }
121
122
123 AffineTransform2D TextureBaseSceneLayer::GetTransform() const
124 {
125 return AffineTransform2D::Combine(
126 AffineTransform2D::CreateOffset(originX_, originY_),
127 AffineTransform2D::CreateRotation(angle_),
128 AffineTransform2D::CreateScaling(pixelSpacingX_, pixelSpacingY_),
129 AffineTransform2D::CreateOffset(-0.5, -0.5));
130 }
131
132
133 bool TextureBaseSceneLayer::GetBoundingBox(Extent2D& target) const
134 {
135 if (texture_.get() == NULL)
136 {
137 return false;
138 }
139 else
140 {
141 const AffineTransform2D t = GetTransform();
142
143 target.Reset();
144
145 double x, y;
146
147 x = 0;
148 y = 0;
149 t.Apply(x, y);
150 target.AddPoint(x, y);
151
152 x = static_cast<double>(texture_->GetWidth());
153 y = 0;
154 t.Apply(x, y);
155 target.AddPoint(x, y);
156
157 x = 0;
158 y = static_cast<double>(texture_->GetHeight());
159 t.Apply(x, y);
160 target.AddPoint(x, y);
161
162 x = static_cast<double>(texture_->GetWidth());
163 y = static_cast<double>(texture_->GetHeight());
164 t.Apply(x, y);
165 target.AddPoint(x, y);
166
167 return true;
168 }
169 }
170 }