Mercurial > hg > orthanc-stone
annotate Framework/Scene2D/TextureBaseSceneLayer.cpp @ 1455:30deba7bc8e2
simplifying include_directories
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 11 Jun 2020 20:54:01 +0200 |
parents | 2d8ab34c8c91 |
children |
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 | |
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 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
24 #include <OrthancException.h> |
590 | 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 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
590
diff
changeset
|
114 LOG(ERROR) << "TextureBaseSceneLayer::GetTexture(): (!HasTexture())"; |
590 | 115 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
116 } | |
117 else | |
118 { | |
119 return *texture_; | |
120 } | |
121 } | |
122 | |
123 | |
124 AffineTransform2D TextureBaseSceneLayer::GetTransform() const | |
125 { | |
126 return AffineTransform2D::Combine( | |
127 AffineTransform2D::CreateOffset(originX_, originY_), | |
128 AffineTransform2D::CreateRotation(angle_), | |
129 AffineTransform2D::CreateScaling(pixelSpacingX_, pixelSpacingY_), | |
130 AffineTransform2D::CreateOffset(-0.5, -0.5)); | |
131 } | |
132 | |
133 | |
134 bool TextureBaseSceneLayer::GetBoundingBox(Extent2D& target) const | |
135 { | |
136 if (texture_.get() == NULL) | |
137 { | |
138 return false; | |
139 } | |
140 else | |
141 { | |
142 const AffineTransform2D t = GetTransform(); | |
143 | |
144 target.Reset(); | |
145 | |
146 double x, y; | |
147 | |
148 x = 0; | |
149 y = 0; | |
150 t.Apply(x, y); | |
151 target.AddPoint(x, y); | |
152 | |
153 x = static_cast<double>(texture_->GetWidth()); | |
154 y = 0; | |
155 t.Apply(x, y); | |
156 target.AddPoint(x, y); | |
157 | |
158 x = 0; | |
159 y = static_cast<double>(texture_->GetHeight()); | |
160 t.Apply(x, y); | |
161 target.AddPoint(x, y); | |
162 | |
163 x = static_cast<double>(texture_->GetWidth()); | |
164 y = static_cast<double>(texture_->GetHeight()); | |
165 t.Apply(x, y); | |
166 target.AddPoint(x, y); | |
167 | |
168 return true; | |
169 } | |
170 } | |
171 } |