Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.cpp @ 1653:2e3b2ed239b9
Fixed usage of object cookie
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 16 Nov 2020 22:17:01 +0100 |
parents | 59f95b9ea858 |
children | 9ac2a65d4172 |
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 | |
1624 | 25 #include <Logging.h> |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
26 #include <OrthancException.h> |
590 | 27 |
28 namespace OrthancStone | |
29 { | |
30 void TextureBaseSceneLayer::SetTexture(Orthanc::ImageAccessor* texture) | |
31 { | |
32 if (texture == NULL) | |
33 { | |
34 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
35 } | |
36 else | |
37 { | |
38 texture_.reset(texture); | |
39 IncrementRevision(); | |
40 } | |
41 } | |
42 | |
43 | |
44 void TextureBaseSceneLayer::CopyParameters(const TextureBaseSceneLayer& other) | |
45 { | |
46 originX_ = other.originX_; | |
47 originY_ = other.originY_; | |
48 pixelSpacingX_ = other.pixelSpacingX_; | |
49 pixelSpacingY_ = other.pixelSpacingY_; | |
50 angle_ = other.angle_; | |
51 isLinearInterpolation_ = other.isLinearInterpolation_; | |
1554
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
52 flipX_ = other.flipX_; |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
53 flipY_ = other.flipY_; |
590 | 54 } |
55 | |
56 | |
57 TextureBaseSceneLayer::TextureBaseSceneLayer() : | |
58 originX_(0), | |
59 originY_(0), | |
60 pixelSpacingX_(1), | |
61 pixelSpacingY_(1), | |
62 angle_(0), | |
63 isLinearInterpolation_(false), | |
1554
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
64 flipX_(false), |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
65 flipY_(false), |
590 | 66 revision_(0) |
67 { | |
68 if (pixelSpacingX_ <= 0 || | |
69 pixelSpacingY_ <= 0) | |
70 { | |
71 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
72 } | |
73 } | |
74 | |
75 | |
76 void TextureBaseSceneLayer::SetOrigin(double x, | |
77 double y) | |
78 { | |
79 originX_ = x; | |
80 originY_ = y; | |
81 IncrementRevision(); | |
82 } | |
83 | |
84 | |
85 void TextureBaseSceneLayer::SetPixelSpacing(double sx, | |
86 double sy) | |
87 { | |
88 if (sx <= 0 || | |
89 sy <= 0) | |
90 { | |
91 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
92 } | |
93 else | |
94 { | |
95 pixelSpacingX_ = sx; | |
96 pixelSpacingY_ = sy; | |
97 IncrementRevision(); | |
98 } | |
99 } | |
100 | |
101 | |
102 void TextureBaseSceneLayer::SetAngle(double angle) | |
103 { | |
104 angle_ = angle; | |
105 IncrementRevision(); | |
106 } | |
107 | |
108 | |
109 void TextureBaseSceneLayer::SetLinearInterpolation(bool isLinearInterpolation) | |
110 { | |
111 isLinearInterpolation_ = isLinearInterpolation; | |
112 IncrementRevision(); | |
113 } | |
114 | |
115 | |
1554
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
116 void TextureBaseSceneLayer::SetFlipX(bool flip) |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
117 { |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
118 flipX_ = flip; |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
119 IncrementRevision(); |
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 |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
123 void TextureBaseSceneLayer::SetFlipY(bool flip) |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
124 { |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
125 flipY_ = flip; |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
126 IncrementRevision(); |
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 |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
129 |
590 | 130 const Orthanc::ImageAccessor& TextureBaseSceneLayer::GetTexture() const |
131 { | |
132 if (!HasTexture()) | |
133 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
590
diff
changeset
|
134 LOG(ERROR) << "TextureBaseSceneLayer::GetTexture(): (!HasTexture())"; |
590 | 135 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
136 } | |
137 else | |
138 { | |
139 return *texture_; | |
140 } | |
141 } | |
142 | |
143 | |
144 AffineTransform2D TextureBaseSceneLayer::GetTransform() const | |
145 { | |
1554
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
146 unsigned int width = 0; |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
147 unsigned int height = 0; |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
148 |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
149 if (texture_.get() != NULL) |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
150 { |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
151 width = texture_->GetWidth(); |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
152 height = texture_->GetHeight(); |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
153 } |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
154 |
590 | 155 return AffineTransform2D::Combine( |
156 AffineTransform2D::CreateOffset(originX_, originY_), | |
157 AffineTransform2D::CreateRotation(angle_), | |
158 AffineTransform2D::CreateScaling(pixelSpacingX_, pixelSpacingY_), | |
1554
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
159 AffineTransform2D::CreateOffset(-0.5, -0.5), |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
160 AffineTransform2D::CreateFlip(flipX_, flipY_, width, height)); |
590 | 161 } |
162 | |
163 | |
1610
b7630b1a0253
ISceneLayer::GetBoundingBox() returns void
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
164 void TextureBaseSceneLayer::GetBoundingBox(Extent2D& target) const |
590 | 165 { |
1610
b7630b1a0253
ISceneLayer::GetBoundingBox() returns void
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
166 target.Clear(); |
b7630b1a0253
ISceneLayer::GetBoundingBox() returns void
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
167 |
b7630b1a0253
ISceneLayer::GetBoundingBox() returns void
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
168 if (texture_.get() != NULL) |
590 | 169 { |
170 const AffineTransform2D t = GetTransform(); | |
171 | |
172 double x, y; | |
173 | |
174 x = 0; | |
175 y = 0; | |
176 t.Apply(x, y); | |
177 target.AddPoint(x, y); | |
178 | |
179 x = static_cast<double>(texture_->GetWidth()); | |
180 y = 0; | |
181 t.Apply(x, y); | |
182 target.AddPoint(x, y); | |
183 | |
184 x = 0; | |
185 y = static_cast<double>(texture_->GetHeight()); | |
186 t.Apply(x, y); | |
187 target.AddPoint(x, y); | |
188 | |
189 x = static_cast<double>(texture_->GetWidth()); | |
190 y = static_cast<double>(texture_->GetHeight()); | |
191 t.Apply(x, y); | |
192 target.AddPoint(x, y); | |
193 } | |
194 } | |
195 } |