Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Deprecated/Radiography/RadiographyScene.cpp @ 1556:8898f8f755c8
typo
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 18 Aug 2020 11:58:47 +0200 |
parents | 244ad1e4e76a |
children |
rev | line source |
---|---|
408 | 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:
1259
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
408 | 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 "RadiographyScene.h" | |
23 | |
430 | 24 #include "RadiographyAlphaLayer.h" |
25 #include "RadiographyDicomLayer.h" | |
26 #include "RadiographyTextLayer.h" | |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
27 #include "RadiographyMaskLayer.h" |
732
c35e98d22764
move Deprecated classes to a separate folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
28 #include "../Deprecated/Toolbox/DicomFrameConverter.h" |
1373
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
29 #include "../Scene2D/CairoCompositor.h" |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
30 #include "../Scene2D/FloatTextureSceneLayer.h" |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
31 #include "../Scene2D/TextSceneLayer.h" |
408 | 32 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1398
diff
changeset
|
33 #include <Images/Image.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1398
diff
changeset
|
34 #include <Images/ImageProcessing.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1398
diff
changeset
|
35 #include <Images/PamReader.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1398
diff
changeset
|
36 #include <Images/PamWriter.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1398
diff
changeset
|
37 #include <Images/PngWriter.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1398
diff
changeset
|
38 #include <OrthancException.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1398
diff
changeset
|
39 #include <Toolbox.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1398
diff
changeset
|
40 #include <DicomDatasetReader.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1398
diff
changeset
|
41 #include <FullOrthancDataset.h> |
408 | 42 |
412 | 43 #include <boost/math/special_functions/round.hpp> |
44 | |
408 | 45 |
46 namespace OrthancStone | |
47 { | |
48 RadiographyScene::LayerAccessor::LayerAccessor(RadiographyScene& scene, | |
49 size_t index) : | |
50 scene_(scene), | |
51 index_(index) | |
52 { | |
53 Layers::iterator layer = scene.layers_.find(index); | |
54 if (layer == scene.layers_.end()) | |
55 { | |
56 layer_ = NULL; | |
57 } | |
58 else | |
59 { | |
60 assert(layer->second != NULL); | |
61 layer_ = layer->second; | |
62 } | |
63 } | |
64 | |
426 | 65 |
408 | 66 RadiographyScene::LayerAccessor::LayerAccessor(RadiographyScene& scene, |
67 double x, | |
68 double y) : | |
69 scene_(scene), | |
70 index_(0) // Dummy initialization | |
71 { | |
72 if (scene.LookupLayer(index_, x, y)) | |
73 { | |
74 Layers::iterator layer = scene.layers_.find(index_); | |
426 | 75 |
408 | 76 if (layer == scene.layers_.end()) |
77 { | |
78 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
79 } | |
80 else | |
81 { | |
82 assert(layer->second != NULL); | |
83 layer_ = layer->second; | |
84 } | |
85 } | |
86 else | |
87 { | |
88 layer_ = NULL; | |
89 } | |
90 } | |
91 | |
92 | |
93 RadiographyScene& RadiographyScene::LayerAccessor::GetScene() const | |
94 { | |
95 if (IsValid()) | |
96 { | |
97 return scene_; | |
98 } | |
99 else | |
100 { | |
101 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
102 } | |
103 } | |
104 | |
105 | |
106 size_t RadiographyScene::LayerAccessor::GetIndex() const | |
107 { | |
108 if (IsValid()) | |
109 { | |
110 return index_; | |
111 } | |
112 else | |
113 { | |
114 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
115 } | |
116 } | |
117 | |
118 | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
409
diff
changeset
|
119 RadiographyLayer& RadiographyScene::LayerAccessor::GetLayer() const |
408 | 120 { |
121 if (IsValid()) | |
122 { | |
123 return *layer_; | |
124 } | |
125 else | |
126 { | |
127 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
128 } | |
426 | 129 } |
408 | 130 |
1257
6af941a68472
RadiographyScene: virtual methods to use in derived class
Alain Mazy <alain@mazy.be>
parents:
1220
diff
changeset
|
131 void RadiographyScene::_RegisterLayer(RadiographyLayer* layer) |
6af941a68472
RadiographyScene: virtual methods to use in derived class
Alain Mazy <alain@mazy.be>
parents:
1220
diff
changeset
|
132 { |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1285
diff
changeset
|
133 std::unique_ptr<RadiographyLayer> raii(layer); |
1257
6af941a68472
RadiographyScene: virtual methods to use in derived class
Alain Mazy <alain@mazy.be>
parents:
1220
diff
changeset
|
134 |
6af941a68472
RadiographyScene: virtual methods to use in derived class
Alain Mazy <alain@mazy.be>
parents:
1220
diff
changeset
|
135 // LOG(INFO) << "Registering layer: " << countLayers_; |
6af941a68472
RadiographyScene: virtual methods to use in derived class
Alain Mazy <alain@mazy.be>
parents:
1220
diff
changeset
|
136 |
6af941a68472
RadiographyScene: virtual methods to use in derived class
Alain Mazy <alain@mazy.be>
parents:
1220
diff
changeset
|
137 size_t index = nextLayerIndex_++; |
6af941a68472
RadiographyScene: virtual methods to use in derived class
Alain Mazy <alain@mazy.be>
parents:
1220
diff
changeset
|
138 raii->SetIndex(index); |
6af941a68472
RadiographyScene: virtual methods to use in derived class
Alain Mazy <alain@mazy.be>
parents:
1220
diff
changeset
|
139 layers_[index] = raii.release(); |
6af941a68472
RadiographyScene: virtual methods to use in derived class
Alain Mazy <alain@mazy.be>
parents:
1220
diff
changeset
|
140 } |
6af941a68472
RadiographyScene: virtual methods to use in derived class
Alain Mazy <alain@mazy.be>
parents:
1220
diff
changeset
|
141 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
409
diff
changeset
|
142 RadiographyLayer& RadiographyScene::RegisterLayer(RadiographyLayer* layer) |
408 | 143 { |
144 if (layer == NULL) | |
145 { | |
146 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
147 } | |
148 | |
1257
6af941a68472
RadiographyScene: virtual methods to use in derived class
Alain Mazy <alain@mazy.be>
parents:
1220
diff
changeset
|
149 _RegisterLayer(layer); |
408 | 150 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
605
diff
changeset
|
151 BroadcastMessage(GeometryChangedMessage(*this, *layer)); |
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
605
diff
changeset
|
152 BroadcastMessage(ContentChangedMessage(*this, *layer)); |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
928
diff
changeset
|
153 Register<RadiographyLayer::LayerEditedMessage>(*layer, &RadiographyScene::OnLayerEdited); |
408 | 154 |
155 return *layer; | |
156 } | |
426 | 157 |
876 | 158 size_t RadiographyScene::GetApproximateMemoryUsage() const |
159 { | |
160 size_t size = 0; | |
161 for (Layers::const_iterator it = layers_.begin(); it != layers_.end(); it++) | |
162 { | |
163 size += it->second->GetApproximateMemoryUsage(); | |
164 } | |
165 return size; | |
166 } | |
167 | |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
168 void RadiographyScene::OnLayerEdited(const RadiographyLayer::LayerEditedMessage& message) |
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
169 { |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
605
diff
changeset
|
170 BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, message.GetOrigin())); |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
171 } |
408 | 172 |
1200 | 173 |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
928
diff
changeset
|
174 RadiographyScene::RadiographyScene() : |
1199
922d2e61aa5d
RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents:
1196
diff
changeset
|
175 nextLayerIndex_(0), |
408 | 176 hasWindowing_(false), |
177 windowingCenter_(0), // Dummy initialization | |
178 windowingWidth_(0) // Dummy initialization | |
179 { | |
180 } | |
181 | |
182 | |
183 RadiographyScene::~RadiographyScene() | |
184 { | |
185 for (Layers::iterator it = layers_.begin(); it != layers_.end(); it++) | |
186 { | |
187 assert(it->second != NULL); | |
188 delete it->second; | |
189 } | |
190 } | |
191 | |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
192 RadiographyPhotometricDisplayMode RadiographyScene::GetPreferredPhotomotricDisplayMode() const |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
193 { |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
194 // return the mode of the first layer who "cares" about its display mode (normaly, the one and only layer that is a DicomLayer) |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
195 for (Layers::const_iterator it = layers_.begin(); it != layers_.end(); it++) |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
196 { |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
197 if (it->second->GetPreferredPhotomotricDisplayMode() != RadiographyPhotometricDisplayMode_Default) |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
198 { |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
199 return it->second->GetPreferredPhotomotricDisplayMode(); |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
200 } |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
201 } |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
202 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
203 return RadiographyPhotometricDisplayMode_Default; |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
204 } |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
205 |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
206 |
430 | 207 void RadiographyScene::GetLayersIndexes(std::vector<size_t>& output) const |
208 { | |
209 for (Layers::const_iterator it = layers_.begin(); it != layers_.end(); it++) | |
210 { | |
211 output.push_back(it->first); | |
212 } | |
213 } | |
214 | |
425 | 215 void RadiographyScene::RemoveLayer(size_t layerIndex) |
216 { | |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
426
diff
changeset
|
217 LOG(INFO) << "Removing layer: " << layerIndex; |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
426
diff
changeset
|
218 |
571
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
219 Layers::iterator found = layers_.find(layerIndex); |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
220 |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
221 if (found == layers_.end()) |
425 | 222 { |
223 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
224 } | |
571
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
225 else |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
226 { |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
227 assert(found->second != NULL); |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
228 delete found->second; |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
229 |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
230 layers_.erase(found); |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
231 |
1199
922d2e61aa5d
RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents:
1196
diff
changeset
|
232 LOG(INFO) << "Removing layer, there are now : " << layers_.size() << " layers"; |
1131
4663f158c748
RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents:
1112
diff
changeset
|
233 |
1272
a989c7d46b9a
options to avoid multiple LayerEditedMessage
Alain Mazy <alain@mazy.be>
parents:
1259
diff
changeset
|
234 _OnLayerRemoved(); |
a989c7d46b9a
options to avoid multiple LayerEditedMessage
Alain Mazy <alain@mazy.be>
parents:
1259
diff
changeset
|
235 |
1131
4663f158c748
RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents:
1112
diff
changeset
|
236 BroadcastMessage(RadiographyScene::LayerRemovedMessage(*this, layerIndex)); |
571
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
237 } |
425 | 238 } |
239 | |
430 | 240 const RadiographyLayer& RadiographyScene::GetLayer(size_t layerIndex) const |
425 | 241 { |
571
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
242 Layers::const_iterator found = layers_.find(layerIndex); |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
243 |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
244 if (found == layers_.end()) |
425 | 245 { |
246 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
247 } | |
571
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
248 else |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
249 { |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
250 assert(found->second != NULL); |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
251 return *found->second; |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
252 } |
425 | 253 } |
408 | 254 |
1201 | 255 RadiographyLayer& RadiographyScene::GetLayer(size_t layerIndex) |
256 { | |
257 Layers::const_iterator found = layers_.find(layerIndex); | |
258 | |
259 if (found == layers_.end()) | |
260 { | |
261 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
262 } | |
263 else | |
264 { | |
265 assert(found->second != NULL); | |
266 return *found->second; | |
267 } | |
268 } | |
269 | |
408 | 270 bool RadiographyScene::GetWindowing(float& center, |
271 float& width) const | |
272 { | |
273 if (hasWindowing_) | |
274 { | |
275 center = windowingCenter_; | |
276 width = windowingWidth_; | |
277 return true; | |
278 } | |
279 else | |
280 { | |
281 return false; | |
282 } | |
283 } | |
284 | |
285 | |
286 void RadiographyScene::GetWindowingWithDefault(float& center, | |
287 float& width) const | |
288 { | |
289 if (!GetWindowing(center, width)) | |
290 { | |
291 center = 128; | |
292 width = 256; | |
293 } | |
294 } | |
295 | |
296 | |
297 void RadiographyScene::SetWindowing(float center, | |
298 float width) | |
299 { | |
300 hasWindowing_ = true; | |
301 windowingCenter_ = center; | |
302 windowingWidth_ = width; | |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
303 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
605
diff
changeset
|
304 BroadcastMessage(RadiographyScene::WindowingChangedMessage(*this)); |
408 | 305 } |
306 | |
307 | |
1201 | 308 RadiographyLayer& RadiographyScene::UpdateText(size_t layerIndex, |
309 const std::string& utf8, | |
1220
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
310 const std::string& font, |
1201 | 311 unsigned int fontSize, |
312 uint8_t foreground) | |
313 { | |
314 RadiographyTextLayer& textLayer = dynamic_cast<RadiographyTextLayer&>(GetLayer(layerIndex)); | |
1220
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
315 textLayer.SetText(utf8, font, fontSize, foreground); |
1201 | 316 |
317 BroadcastMessage(RadiographyScene::ContentChangedMessage(*this, textLayer)); | |
318 BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, textLayer)); | |
319 return textLayer; | |
320 } | |
321 | |
322 | |
1190 | 323 RadiographyLayer& RadiographyScene::LoadText(const std::string& utf8, |
1220
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
324 const std::string& font, |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
325 unsigned int fontSize, |
1190 | 326 uint8_t foreground, |
1220
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
327 RadiographyLayer::Geometry* centerGeometry, |
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
328 bool isCenterGeometry) |
408 | 329 { |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1297
diff
changeset
|
330 std::unique_ptr<RadiographyTextLayer> alpha(new RadiographyTextLayer(*this)); |
1220
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
331 alpha->SetText(utf8, font, fontSize, foreground); |
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
332 if (centerGeometry != NULL) |
430 | 333 { |
1220
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
334 if (isCenterGeometry) |
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
335 { |
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
336 // modify geometry to reference the top left corner |
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
337 double tlx = centerGeometry->GetPanX(); |
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
338 double tly = centerGeometry->GetPanY(); |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
339 Extent2D textExtent = alpha->GetSceneExtent(false); |
1220
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
340 tlx = tlx - (textExtent.GetWidth() / 2) * centerGeometry->GetPixelSpacingX(); |
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
341 tly = tly - (textExtent.GetHeight() / 2) * centerGeometry->GetPixelSpacingY(); |
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
342 centerGeometry->SetPan(tlx, tly); |
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
343 } |
9ee6b28f53e8
RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
344 alpha->SetGeometry(*centerGeometry); |
430 | 345 } |
408 | 346 |
1199
922d2e61aa5d
RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents:
1196
diff
changeset
|
347 RadiographyLayer& registeredLayer = RegisterLayer(alpha.release()); |
922d2e61aa5d
RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents:
1196
diff
changeset
|
348 |
922d2e61aa5d
RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents:
1196
diff
changeset
|
349 BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, registeredLayer)); |
922d2e61aa5d
RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents:
1196
diff
changeset
|
350 return registeredLayer; |
408 | 351 } |
352 | |
426 | 353 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
409
diff
changeset
|
354 RadiographyLayer& RadiographyScene::LoadTestBlock(unsigned int width, |
430 | 355 unsigned int height, |
356 RadiographyLayer::Geometry* geometry) | |
408 | 357 { |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1285
diff
changeset
|
358 std::unique_ptr<Orthanc::Image> block(new Orthanc::Image(Orthanc::PixelFormat_Grayscale8, width, height, false)); |
408 | 359 |
360 for (unsigned int padding = 0; | |
361 (width > 2 * padding) && (height > 2 * padding); | |
362 padding++) | |
363 { | |
364 uint8_t color; | |
365 if (255 > 10 * padding) | |
366 { | |
367 color = 255 - 10 * padding; | |
368 } | |
369 else | |
370 { | |
371 color = 0; | |
372 } | |
373 | |
374 Orthanc::ImageAccessor region; | |
375 block->GetRegion(region, padding, padding, width - 2 * padding, height - 2 * padding); | |
376 Orthanc::ImageProcessing::Set(region, color); | |
377 } | |
378 | |
430 | 379 return LoadAlphaBitmap(block.release(), geometry); |
380 } | |
381 | |
488 | 382 RadiographyLayer& RadiographyScene::LoadMask(const std::vector<Orthanc::ImageProcessing::ImagePoint>& corners, |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
383 const RadiographyDicomLayer& dicomLayer, |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
384 float foreground, |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
385 RadiographyLayer::Geometry* geometry) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
386 { |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1297
diff
changeset
|
387 std::unique_ptr<RadiographyMaskLayer> mask(new RadiographyMaskLayer(*this, dicomLayer, foreground)); |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
388 mask->SetCorners(corners); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
389 if (geometry != NULL) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
390 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
391 mask->SetGeometry(*geometry); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
392 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
393 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
394 return RegisterLayer(mask.release()); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
395 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
396 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
397 |
430 | 398 RadiographyLayer& RadiographyScene::LoadAlphaBitmap(Orthanc::ImageAccessor* bitmap, RadiographyLayer::Geometry *geometry) |
399 { | |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1297
diff
changeset
|
400 std::unique_ptr<RadiographyAlphaLayer> alpha(new RadiographyAlphaLayer(*this)); |
430 | 401 alpha->SetAlpha(bitmap); |
402 if (geometry != NULL) | |
403 { | |
404 alpha->SetGeometry(*geometry); | |
405 } | |
408 | 406 |
407 return RegisterLayer(alpha.release()); | |
408 } | |
409 | |
553
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
410 RadiographyLayer& RadiographyScene::LoadDicomImage(Orthanc::ImageAccessor* dicomImage, // takes ownership |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
411 const std::string& instance, |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
412 unsigned int frame, |
714
d2c0e347ddc2
deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
413 Deprecated::DicomFrameConverter* converter, // takes ownership |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
414 RadiographyPhotometricDisplayMode preferredPhotometricDisplayMode, |
553
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
415 RadiographyLayer::Geometry* geometry) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
416 { |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
928
diff
changeset
|
417 RadiographyDicomLayer& layer = dynamic_cast<RadiographyDicomLayer&>(RegisterLayer(new RadiographyDicomLayer(*this))); |
553
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
418 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
419 layer.SetInstance(instance, frame); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
420 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
421 if (geometry != NULL) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
422 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
423 layer.SetGeometry(*geometry); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
424 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
425 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
426 layer.SetDicomFrameConverter(converter); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
427 layer.SetSourceImage(dicomImage); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
428 layer.SetPreferredPhotomotricDisplayMode(preferredPhotometricDisplayMode); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
429 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
430 return layer; |
587 | 431 } |
553
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
432 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
433 RadiographyLayer& RadiographyScene::LoadDicomFrame(Deprecated::OrthancApiClient& orthanc, |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
434 const std::string& instance, |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
409
diff
changeset
|
435 unsigned int frame, |
430 | 436 bool httpCompression, |
437 RadiographyLayer::Geometry* geometry) | |
408 | 438 { |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
928
diff
changeset
|
439 RadiographyDicomLayer& layer = dynamic_cast<RadiographyDicomLayer&>(RegisterLayer(new RadiographyDicomLayer( *this))); |
430 | 440 layer.SetInstance(instance, frame); |
441 | |
442 if (geometry != NULL) | |
443 { | |
444 layer.SetGeometry(*geometry); | |
445 } | |
408 | 446 |
447 { | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
448 Deprecated::IWebService::HttpHeaders headers; |
408 | 449 std::string uri = "/instances/" + instance + "/tags"; |
426 | 450 |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
451 orthanc.GetBinaryAsync( |
426 | 452 uri, headers, |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1204
diff
changeset
|
453 new Deprecated::DeprecatedCallable<RadiographyScene, Deprecated::OrthancApiClient::BinaryResponseReadyMessage> |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
928
diff
changeset
|
454 (GetSharedObserver(), &RadiographyScene::OnTagsReceived), NULL, |
426 | 455 new Orthanc::SingleValueObject<size_t>(layer.GetIndex())); |
408 | 456 } |
457 | |
458 { | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
459 Deprecated::IWebService::HttpHeaders headers; |
408 | 460 headers["Accept"] = "image/x-portable-arbitrarymap"; |
461 | |
462 if (httpCompression) | |
463 { | |
464 headers["Accept-Encoding"] = "gzip"; | |
465 } | |
426 | 466 |
408 | 467 std::string uri = ("/instances/" + instance + "/frames/" + |
468 boost::lexical_cast<std::string>(frame) + "/image-uint16"); | |
426 | 469 |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
470 orthanc.GetBinaryAsync( |
426 | 471 uri, headers, |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1204
diff
changeset
|
472 new Deprecated::DeprecatedCallable<RadiographyScene, Deprecated::OrthancApiClient::BinaryResponseReadyMessage> |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
928
diff
changeset
|
473 (GetSharedObserver(), &RadiographyScene::OnFrameReceived), NULL, |
426 | 474 new Orthanc::SingleValueObject<size_t>(layer.GetIndex())); |
408 | 475 } |
476 | |
477 return layer; | |
478 } | |
479 | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
480 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
481 RadiographyLayer& RadiographyScene::LoadDicomWebFrame(Deprecated::IWebService& web) |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
482 { |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
928
diff
changeset
|
483 RadiographyLayer& layer = RegisterLayer(new RadiographyDicomLayer(*this)); |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
484 |
426 | 485 |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
486 return layer; |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
487 } |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
488 |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
489 |
426 | 490 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
491 void RadiographyScene::OnTagsReceived(const Deprecated::OrthancApiClient::BinaryResponseReadyMessage& message) |
408 | 492 { |
493 size_t index = dynamic_cast<const Orthanc::SingleValueObject<size_t>&> | |
426 | 494 (message.GetPayload()).GetValue(); |
408 | 495 |
1285 | 496 VLOG(1) << "JSON received: " << message.GetUri().c_str() |
497 << " (" << message.GetAnswerSize() << " bytes) for layer " << index; | |
426 | 498 |
408 | 499 Layers::iterator layer = layers_.find(index); |
500 if (layer != layers_.end()) | |
501 { | |
502 assert(layer->second != NULL); | |
426 | 503 |
408 | 504 OrthancPlugins::FullOrthancDataset dicom(message.GetAnswer(), message.GetAnswerSize()); |
430 | 505 dynamic_cast<RadiographyDicomLayer*>(layer->second)->SetDicomTags(dicom); |
408 | 506 |
507 float c, w; | |
508 if (!hasWindowing_ && | |
509 layer->second->GetDefaultWindowing(c, w)) | |
510 { | |
511 hasWindowing_ = true; | |
512 windowingCenter_ = c; | |
513 windowingWidth_ = w; | |
514 } | |
515 | |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
605
diff
changeset
|
516 BroadcastMessage(GeometryChangedMessage(*this, *(layer->second))); |
408 | 517 } |
518 } | |
426 | 519 |
408 | 520 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
521 void RadiographyScene::OnFrameReceived(const Deprecated::OrthancApiClient::BinaryResponseReadyMessage& message) |
408 | 522 { |
523 size_t index = dynamic_cast<const Orthanc::SingleValueObject<size_t>&>(message.GetPayload()).GetValue(); | |
426 | 524 |
1285 | 525 VLOG(1) << "DICOM frame received: " << message.GetUri().c_str() |
526 << " (" << message.GetAnswerSize() << " bytes) for layer " << index; | |
426 | 527 |
408 | 528 Layers::iterator layer = layers_.find(index); |
529 if (layer != layers_.end()) | |
530 { | |
531 assert(layer->second != NULL); | |
532 | |
533 std::string content; | |
534 if (message.GetAnswerSize() > 0) | |
535 { | |
536 content.assign(reinterpret_cast<const char*>(message.GetAnswer()), message.GetAnswerSize()); | |
537 } | |
426 | 538 |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1285
diff
changeset
|
539 std::unique_ptr<Orthanc::PamReader> reader(new Orthanc::PamReader); |
408 | 540 reader->ReadFromMemory(content); |
430 | 541 dynamic_cast<RadiographyDicomLayer*>(layer->second)->SetSourceImage(reader.release()); |
408 | 542 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
605
diff
changeset
|
543 BroadcastMessage(ContentChangedMessage(*this, *(layer->second))); |
408 | 544 } |
545 } | |
546 | |
547 | |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
548 Extent2D RadiographyScene::GetSceneExtent(bool minimal) const |
408 | 549 { |
550 Extent2D extent; | |
551 | |
552 for (Layers::const_iterator it = layers_.begin(); | |
553 it != layers_.end(); ++it) | |
554 { | |
555 assert(it->second != NULL); | |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
556 extent.Union(it->second->GetSceneExtent(minimal)); |
408 | 557 } |
558 | |
559 return extent; | |
560 } | |
426 | 561 |
408 | 562 |
563 void RadiographyScene::Render(Orthanc::ImageAccessor& buffer, | |
409 | 564 const AffineTransform2D& viewTransform, |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
565 ImageInterpolation interpolation, |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
566 bool applyWindowing) const |
408 | 567 { |
568 // Render layers in the background-to-foreground order | |
1199
922d2e61aa5d
RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents:
1196
diff
changeset
|
569 for (size_t index = 0; index < nextLayerIndex_; index++) |
408 | 570 { |
1258
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
571 try |
408 | 572 { |
1258
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
573 Layers::const_iterator it = layers_.find(index); |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
574 if (it != layers_.end()) |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
575 { |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
576 assert(it->second != NULL); |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
577 it->second->Render(buffer, viewTransform, interpolation, windowingCenter_, windowingWidth_, applyWindowing); |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
578 } |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
579 } |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
580 catch (Orthanc::OrthancException& ex) |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
581 { |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
582 LOG(ERROR) << "RadiographyScene::Render: " << index << ", OrthancException: " << ex.GetDetails(); |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
583 throw ex; // rethrow because we want it to crash to see there's a problem ! |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
584 } |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
585 catch (...) |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
586 { |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
587 LOG(ERROR) << "RadiographyScene::Render: " << index << ", unkown exception: "; |
9c20ae049669
more logs to debug exceptions in Render
Alain Mazy <alain@mazy.be>
parents:
1257
diff
changeset
|
588 throw; // rethrow because we want it to crash to see there's a problem ! |
408 | 589 } |
590 } | |
591 } | |
592 | |
593 | |
594 bool RadiographyScene::LookupLayer(size_t& index /* out */, | |
595 double x, | |
596 double y) const | |
597 { | |
598 // Render layers in the foreground-to-background order | |
1199
922d2e61aa5d
RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents:
1196
diff
changeset
|
599 for (size_t i = nextLayerIndex_; i > 0; i--) |
408 | 600 { |
601 index = i - 1; | |
602 Layers::const_iterator it = layers_.find(index); | |
603 if (it != layers_.end()) | |
604 { | |
605 assert(it->second != NULL); | |
606 if (it->second->Contains(x, y)) | |
607 { | |
608 return true; | |
609 } | |
610 } | |
611 } | |
612 | |
613 return false; | |
614 } | |
615 | |
426 | 616 |
408 | 617 void RadiographyScene::DrawBorder(CairoContext& context, |
618 unsigned int layer, | |
619 double zoom) | |
620 { | |
621 Layers::const_iterator found = layers_.find(layer); | |
426 | 622 |
408 | 623 if (found != layers_.end()) |
624 { | |
625 context.SetSourceColor(255, 0, 0); | |
626 found->second->DrawBorders(context, zoom); | |
627 } | |
628 } | |
629 | |
630 | |
631 void RadiographyScene::GetRange(float& minValue, | |
632 float& maxValue) const | |
633 { | |
634 bool first = true; | |
426 | 635 |
408 | 636 for (Layers::const_iterator it = layers_.begin(); |
637 it != layers_.end(); it++) | |
638 { | |
639 assert(it->second != NULL); | |
640 | |
641 float a, b; | |
642 if (it->second->GetRange(a, b)) | |
643 { | |
644 if (first) | |
645 { | |
646 minValue = a; | |
647 maxValue = b; | |
648 first = false; | |
649 } | |
650 else | |
651 { | |
652 minValue = std::min(a, minValue); | |
653 maxValue = std::max(b, maxValue); | |
654 } | |
655 } | |
656 } | |
657 | |
658 if (first) | |
659 { | |
660 minValue = 0; | |
661 maxValue = 0; | |
662 } | |
663 } | |
664 | |
1259
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
665 void RadiographyScene::ExtractLayerFromRenderedScene(Orthanc::ImageAccessor& layer, |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
666 const Orthanc::ImageAccessor& renderedScene, |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
667 size_t layerIndex, |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
668 bool isCropped, |
1259
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
669 ImageInterpolation interpolation) |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
670 { |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
671 Extent2D sceneExtent = GetSceneExtent(isCropped); |
1259
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
672 |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
673 double pixelSpacingX = sceneExtent.GetWidth() / renderedScene.GetWidth(); |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
674 double pixelSpacingY = sceneExtent.GetHeight() / renderedScene.GetHeight(); |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
675 |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
676 AffineTransform2D view = AffineTransform2D::Combine( |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
677 AffineTransform2D::CreateScaling(1.0 / pixelSpacingX, 1.0 / pixelSpacingY), |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
678 AffineTransform2D::CreateOffset(-sceneExtent.GetX1(), -sceneExtent.GetY1())); |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
679 |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
680 AffineTransform2D layerToSceneTransform = AffineTransform2D::Combine( |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
681 view, |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
682 GetLayer(layerIndex).GetTransform()); |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
683 |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
684 AffineTransform2D sceneToLayerTransform = AffineTransform2D::Invert(layerToSceneTransform); |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
685 sceneToLayerTransform.Apply(layer, renderedScene, interpolation, false); |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
686 } |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
687 |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
688 Orthanc::Image* RadiographyScene::ExportToImage(double pixelSpacingX, |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
689 double pixelSpacingY, |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
690 ImageInterpolation interpolation, |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
691 bool invert, |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
692 int64_t maxValue /* for inversion */, |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
693 bool autoCrop, |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
694 bool applyWindowing) |
426 | 695 { |
408 | 696 if (pixelSpacingX <= 0 || |
697 pixelSpacingY <= 0) | |
698 { | |
699 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
700 } | |
426 | 701 |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
702 Extent2D extent = GetSceneExtent(autoCrop); |
408 | 703 |
928
1b49e78d91d0
fix for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
923
diff
changeset
|
704 int w = boost::math::iround(extent.GetWidth() / pixelSpacingX); |
1b49e78d91d0
fix for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
923
diff
changeset
|
705 int h = boost::math::iround(extent.GetHeight() / pixelSpacingY); |
408 | 706 |
707 if (w < 0 || h < 0) | |
708 { | |
709 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
710 } | |
711 | |
712 Orthanc::Image layers(Orthanc::PixelFormat_Float32, | |
713 static_cast<unsigned int>(w), | |
714 static_cast<unsigned int>(h), false); | |
715 | |
409 | 716 AffineTransform2D view = AffineTransform2D::Combine( |
426 | 717 AffineTransform2D::CreateScaling(1.0 / pixelSpacingX, 1.0 / pixelSpacingY), |
718 AffineTransform2D::CreateOffset(-extent.GetX1(), -extent.GetY1())); | |
719 | |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
720 // wipe background before rendering |
1259
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
721 if (GetPreferredPhotomotricDisplayMode() == RadiographyPhotometricDisplayMode_Monochrome1) |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
722 { |
1321
d4e6cd35107b
Clarified GetExtent/GetSceneExtent
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
723 Orthanc::ImageProcessing::Set(layers, 65535); |
1259
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
724 } |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
725 else |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
726 { |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
727 Orthanc::ImageProcessing::Set(layers, 0); |
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1258
diff
changeset
|
728 } |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
729 |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
730 Render(layers, view, interpolation, applyWindowing); |
408 | 731 |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1285
diff
changeset
|
732 std::unique_ptr<Orthanc::Image> rendered(new Orthanc::Image(Orthanc::PixelFormat_Grayscale16, |
553
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
733 layers.GetWidth(), layers.GetHeight(), false)); |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
734 |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
735 Orthanc::ImageProcessing::Convert(*rendered, layers); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
736 if (invert) |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
737 Orthanc::ImageProcessing::Invert(*rendered, maxValue); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
738 |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
739 return rendered.release(); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
740 } |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
741 |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
742 |
587 | 743 Orthanc::Image* RadiographyScene::ExportToCreateDicomRequestAndImage(Json::Value& createDicomRequestContent, |
744 const Json::Value& dicomTags, | |
745 const std::string& parentOrthancId, | |
746 double pixelSpacingX, | |
747 double pixelSpacingY, | |
748 bool invert, | |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
749 bool autoCrop, |
587 | 750 ImageInterpolation interpolation) |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
751 { |
541 | 752 LOG(INFO) << "Exporting RadiographyScene to DICOM"; |
753 | |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
754 std::unique_ptr<Orthanc::Image> rendered(ExportToImage(pixelSpacingX, pixelSpacingY, interpolation, autoCrop, false)); // note: we don't invert the image in the pixels data because we'll set the PhotometricDisplayMode correctly in the DICOM tags |
408 | 755 |
483 | 756 createDicomRequestContent["Tags"] = dicomTags; |
408 | 757 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
758 RadiographyPhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode(); |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
759 if ((invert && photometricMode != RadiographyPhotometricDisplayMode_Monochrome2) || |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
760 (!invert && photometricMode == RadiographyPhotometricDisplayMode_Monochrome1)) |
436
04711a2e12cd
fix crop + export photometric interpretation correctly
am@osimis.io
parents:
432
diff
changeset
|
761 { |
483 | 762 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME1"; |
436
04711a2e12cd
fix crop + export photometric interpretation correctly
am@osimis.io
parents:
432
diff
changeset
|
763 } |
04711a2e12cd
fix crop + export photometric interpretation correctly
am@osimis.io
parents:
432
diff
changeset
|
764 else |
04711a2e12cd
fix crop + export photometric interpretation correctly
am@osimis.io
parents:
432
diff
changeset
|
765 { |
483 | 766 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME2"; |
436
04711a2e12cd
fix crop + export photometric interpretation correctly
am@osimis.io
parents:
432
diff
changeset
|
767 } |
408 | 768 |
769 // WARNING: The order of PixelSpacing is Y/X. We use "%0.8f" to | |
770 // avoid floating-point numbers to grow over 16 characters, | |
771 // which would be invalid according to DICOM standard | |
772 // ("dciodvfy" would complain). | |
773 char buf[32]; | |
774 sprintf(buf, "%0.8f\\%0.8f", pixelSpacingY, pixelSpacingX); | |
426 | 775 |
483 | 776 createDicomRequestContent["Tags"]["PixelSpacing"] = buf; |
408 | 777 |
778 float center, width; | |
779 if (GetWindowing(center, width)) | |
780 { | |
483 | 781 createDicomRequestContent["Tags"]["WindowCenter"] = |
426 | 782 boost::lexical_cast<std::string>(boost::math::iround(center)); |
408 | 783 |
483 | 784 createDicomRequestContent["Tags"]["WindowWidth"] = |
426 | 785 boost::lexical_cast<std::string>(boost::math::iround(width)); |
408 | 786 } |
787 | |
587 | 788 if (!parentOrthancId.empty()) |
789 { | |
790 createDicomRequestContent["Parent"] = parentOrthancId; | |
791 } | |
792 | |
793 return rendered.release(); | |
794 } | |
795 | |
796 | |
797 void RadiographyScene::ExportToCreateDicomRequest(Json::Value& createDicomRequestContent, | |
798 const Json::Value& dicomTags, | |
799 const std::string& parentOrthancId, | |
800 double pixelSpacingX, | |
801 double pixelSpacingY, | |
802 bool invert, | |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
803 bool autoCrop, |
587 | 804 ImageInterpolation interpolation, |
805 bool usePam) | |
806 { | |
807 LOG(INFO) << "Exporting RadiographyScene to DICOM"; | |
808 VLOG(1) << "Exporting RadiographyScene to: export to image"; | |
809 | |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
810 std::unique_ptr<Orthanc::Image> rendered(ExportToCreateDicomRequestAndImage(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, autoCrop, interpolation)); |
587 | 811 |
812 // convert the image into base64 for inclusing in the createDicomRequest | |
813 std::string base64; | |
814 | |
815 { | |
816 std::string content; | |
817 | |
818 if (usePam) | |
819 { | |
820 VLOG(1) << "Exporting RadiographyScene: convert to PAM"; | |
821 Orthanc::PamWriter writer; | |
822 writer.WriteToMemory(content, *rendered); | |
823 } | |
824 else | |
825 { | |
826 Orthanc::PngWriter writer; | |
827 writer.WriteToMemory(content, *rendered); | |
828 } | |
829 | |
830 VLOG(1) << "Exporting RadiographyScene: encoding to base64"; | |
831 Orthanc::Toolbox::EncodeBase64(base64, content); | |
832 } | |
426 | 833 |
408 | 834 // This is Data URI scheme: https://en.wikipedia.org/wiki/Data_URI_scheme |
426 | 835 createDicomRequestContent["Content"] = ("data:" + |
836 std::string(usePam ? Orthanc::MIME_PAM : Orthanc::MIME_PNG) + | |
837 ";base64," + base64); | |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
838 |
541 | 839 VLOG(1) << "Exporting RadiographyScene: create-dicom request is ready"; |
484
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
840 } |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
841 |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
842 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
843 void RadiographyScene::ExportDicom(Deprecated::OrthancApiClient& orthanc, |
484
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
844 const Json::Value& dicomTags, |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
845 const std::string& parentOrthancId, |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
846 double pixelSpacingX, |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
847 double pixelSpacingY, |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
848 bool invert, |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
849 bool autoCrop, |
484
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
850 ImageInterpolation interpolation, |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
851 bool usePam) |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
852 { |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
853 Json::Value createDicomRequestContent; |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
854 |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
855 ExportToCreateDicomRequest(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, autoCrop, interpolation, usePam); |
484
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
856 |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
857 orthanc.PostJsonAsyncExpectJson( |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
858 "/tools/create-dicom", createDicomRequestContent, |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1204
diff
changeset
|
859 new Deprecated::DeprecatedCallable<RadiographyScene, Deprecated::OrthancApiClient::JsonResponseReadyMessage> |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
928
diff
changeset
|
860 (GetSharedObserver(), &RadiographyScene::OnDicomExported), |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
861 NULL, NULL); |
483 | 862 |
863 } | |
864 | |
865 | |
866 // Export using PAM is faster than using PNG, but requires Orthanc | |
867 // core >= 1.4.3 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
868 void RadiographyScene::ExportDicom(Deprecated::OrthancApiClient& orthanc, |
483 | 869 const Orthanc::DicomMap& dicom, |
870 const std::string& parentOrthancId, | |
871 double pixelSpacingX, | |
872 double pixelSpacingY, | |
873 bool invert, | |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
874 bool autoCrop, |
483 | 875 ImageInterpolation interpolation, |
876 bool usePam) | |
877 { | |
878 std::set<Orthanc::DicomTag> tags; | |
879 dicom.GetTags(tags); | |
880 | |
881 Json::Value jsonTags = Json::objectValue; | |
882 | |
883 for (std::set<Orthanc::DicomTag>::const_iterator | |
884 tag = tags.begin(); tag != tags.end(); ++tag) | |
885 { | |
886 const Orthanc::DicomValue& value = dicom.GetValue(*tag); | |
887 if (!value.IsNull() && | |
888 !value.IsBinary()) | |
889 { | |
890 jsonTags[tag->Format()] = value.GetContent(); | |
891 } | |
892 } | |
893 | |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
894 ExportDicom(orthanc, jsonTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, autoCrop, interpolation, usePam); |
408 | 895 } |
896 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
897 void RadiographyScene::OnDicomExported(const Deprecated::OrthancApiClient::JsonResponseReadyMessage& message) |
408 | 898 { |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
899 LOG(INFO) << "DICOM export was successful: " |
408 | 900 << message.GetJson().toStyledString(); |
901 } | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
902 |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
903 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
904 void RadiographyScene::OnDicomWebReceived(const Deprecated::IWebService::HttpRequestSuccessMessage& message) |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
905 { |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
906 LOG(INFO) << "DICOMweb WADO-RS received: " << message.GetAnswerSize() << " bytes"; |
418 | 907 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
908 const Deprecated::IWebService::HttpHeaders& h = message.GetAnswerHttpHeaders(); |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
909 for (Deprecated::IWebService::HttpHeaders::const_iterator |
426 | 910 it = h.begin(); it != h.end(); ++it) |
418 | 911 { |
912 printf("[%s] = [%s]\n", it->first.c_str(), it->second.c_str()); | |
913 } | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
914 } |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
915 |
1373
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
916 void RadiographyScene::ExportToScene2D(Scene2D& output) const |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
917 { |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
918 int depth = 0; |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
919 for (Layers::const_iterator it = layers_.begin(); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
920 it != layers_.end(); ++it) |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
921 { |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
922 assert(it->second != NULL); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
923 |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
924 std::unique_ptr<ISceneLayer> layer; |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
925 if (dynamic_cast<RadiographyDicomLayer*>(it->second)) |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
926 { |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
927 RadiographyDicomLayer* oldLayer = dynamic_cast<RadiographyDicomLayer*>(it->second); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
928 |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
929 std::unique_ptr<FloatTextureSceneLayer> newLayer(new FloatTextureSceneLayer(*(oldLayer->GetSourceImage()))); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
930 |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
931 newLayer->SetOrigin(oldLayer->GetGeometry().GetPanX(), |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
932 oldLayer->GetGeometry().GetPanY() |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
933 ); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
934 newLayer->SetAngle(oldLayer->GetGeometry().GetAngle()); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
935 |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
936 layer.reset(newLayer.release()); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
937 |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
938 // TODO: windowing dynamic_cast |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
939 } |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
940 else if (dynamic_cast<RadiographyTextLayer*>(it->second)) |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
941 { |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
942 RadiographyTextLayer* oldLayer = dynamic_cast<RadiographyTextLayer*>(it->second); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
943 |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
944 std::unique_ptr<TextSceneLayer> newLayer(new TextSceneLayer()); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
945 |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
946 newLayer->SetText(oldLayer->GetText()); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
947 newLayer->SetColor(oldLayer->GetForegroundGreyLevel(), |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
948 oldLayer->GetForegroundGreyLevel(), |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
949 oldLayer->GetForegroundGreyLevel() |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
950 ); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
951 newLayer->SetPosition(oldLayer->GetGeometry().GetPanX(), |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
952 oldLayer->GetGeometry().GetPanY() |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
953 ); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
954 newLayer->SetFontIndex(1); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
955 newLayer->SetAnchor(BitmapAnchor_TopLeft); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
956 //newLayer->SetAngle(oldLayer->GetGeometry().GetAngle()); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
957 |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
958 layer.reset(newLayer.release()); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
959 } |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
960 |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
961 output.SetLayer(depth++, layer.release()); |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
962 |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
963 } |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
964 |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
965 } |
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
966 |
408 | 967 } |
1373
e0cdf8688d56
wip: from RadiographyScene to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1330
diff
changeset
|
968 |