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