Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.cpp @ 1599:73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Oct 2020 10:55:45 +0100 |
parents | 8563ea5d8ae4 |
children | b7630b1a0253 |
rev | line source |
---|---|
590 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
590 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
590 | 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 | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1554
diff
changeset
|
16 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
590 | 20 **/ |
21 | |
22 | |
23 #include "TextureBaseSceneLayer.h" | |
24 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
25 #include <OrthancException.h> |
590 | 26 |
27 namespace OrthancStone | |
28 { | |
29 void TextureBaseSceneLayer::SetTexture(Orthanc::ImageAccessor* texture) | |
30 { | |
31 if (texture == NULL) | |
32 { | |
33 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
34 } | |
35 else | |
36 { | |
37 texture_.reset(texture); | |
38 IncrementRevision(); | |
39 } | |
40 } | |
41 | |
42 | |
43 void TextureBaseSceneLayer::CopyParameters(const TextureBaseSceneLayer& other) | |
44 { | |
45 originX_ = other.originX_; | |
46 originY_ = other.originY_; | |
47 pixelSpacingX_ = other.pixelSpacingX_; | |
48 pixelSpacingY_ = other.pixelSpacingY_; | |
49 angle_ = other.angle_; | |
50 isLinearInterpolation_ = other.isLinearInterpolation_; | |
1554
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
51 flipX_ = other.flipX_; |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
52 flipY_ = other.flipY_; |
590 | 53 } |
54 | |
55 | |
56 TextureBaseSceneLayer::TextureBaseSceneLayer() : | |
57 originX_(0), | |
58 originY_(0), | |
59 pixelSpacingX_(1), | |
60 pixelSpacingY_(1), | |
61 angle_(0), | |
62 isLinearInterpolation_(false), | |
1554
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
63 flipX_(false), |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
64 flipY_(false), |
590 | 65 revision_(0) |
66 { | |
67 if (pixelSpacingX_ <= 0 || | |
68 pixelSpacingY_ <= 0) | |
69 { | |
70 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
71 } | |
72 } | |
73 | |
74 | |
75 void TextureBaseSceneLayer::SetOrigin(double x, | |
76 double y) | |
77 { | |
78 originX_ = x; | |
79 originY_ = y; | |
80 IncrementRevision(); | |
81 } | |
82 | |
83 | |
84 void TextureBaseSceneLayer::SetPixelSpacing(double sx, | |
85 double sy) | |
86 { | |
87 if (sx <= 0 || | |
88 sy <= 0) | |
89 { | |
90 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
91 } | |
92 else | |
93 { | |
94 pixelSpacingX_ = sx; | |
95 pixelSpacingY_ = sy; | |
96 IncrementRevision(); | |
97 } | |
98 } | |
99 | |
100 | |
101 void TextureBaseSceneLayer::SetAngle(double angle) | |
102 { | |
103 angle_ = angle; | |
104 IncrementRevision(); | |
105 } | |
106 | |
107 | |
108 void TextureBaseSceneLayer::SetLinearInterpolation(bool isLinearInterpolation) | |
109 { | |
110 isLinearInterpolation_ = isLinearInterpolation; | |
111 IncrementRevision(); | |
112 } | |
113 | |
114 | |
1554
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
115 void TextureBaseSceneLayer::SetFlipX(bool flip) |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
116 { |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
117 flipX_ = flip; |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
118 IncrementRevision(); |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
119 } |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
120 |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
121 |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
122 void TextureBaseSceneLayer::SetFlipY(bool flip) |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
123 { |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
124 flipY_ = flip; |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
125 IncrementRevision(); |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
126 } |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
127 |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
128 |
590 | 129 const Orthanc::ImageAccessor& TextureBaseSceneLayer::GetTexture() const |
130 { | |
131 if (!HasTexture()) | |
132 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
590
diff
changeset
|
133 LOG(ERROR) << "TextureBaseSceneLayer::GetTexture(): (!HasTexture())"; |
590 | 134 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
135 } | |
136 else | |
137 { | |
138 return *texture_; | |
139 } | |
140 } | |
141 | |
142 | |
143 AffineTransform2D TextureBaseSceneLayer::GetTransform() const | |
144 { | |
1554
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
145 unsigned int width = 0; |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
146 unsigned int height = 0; |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
147 |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
148 if (texture_.get() != NULL) |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
149 { |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
150 width = texture_->GetWidth(); |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
151 height = texture_->GetHeight(); |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
152 } |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
153 |
590 | 154 return AffineTransform2D::Combine( |
155 AffineTransform2D::CreateOffset(originX_, originY_), | |
156 AffineTransform2D::CreateRotation(angle_), | |
157 AffineTransform2D::CreateScaling(pixelSpacingX_, pixelSpacingY_), | |
1554
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
158 AffineTransform2D::CreateOffset(-0.5, -0.5), |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
159 AffineTransform2D::CreateFlip(flipX_, flipY_, width, height)); |
590 | 160 } |
161 | |
162 | |
163 bool TextureBaseSceneLayer::GetBoundingBox(Extent2D& target) const | |
164 { | |
165 if (texture_.get() == NULL) | |
166 { | |
167 return false; | |
168 } | |
169 else | |
170 { | |
171 const AffineTransform2D t = GetTransform(); | |
172 | |
173 target.Reset(); | |
174 | |
175 double x, y; | |
176 | |
177 x = 0; | |
178 y = 0; | |
179 t.Apply(x, y); | |
180 target.AddPoint(x, y); | |
181 | |
182 x = static_cast<double>(texture_->GetWidth()); | |
183 y = 0; | |
184 t.Apply(x, y); | |
185 target.AddPoint(x, y); | |
186 | |
187 x = 0; | |
188 y = static_cast<double>(texture_->GetHeight()); | |
189 t.Apply(x, y); | |
190 target.AddPoint(x, y); | |
191 | |
192 x = static_cast<double>(texture_->GetWidth()); | |
193 y = static_cast<double>(texture_->GetHeight()); | |
194 t.Apply(x, y); | |
195 target.AddPoint(x, y); | |
196 | |
197 return true; | |
198 } | |
199 } | |
200 } |