Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographyScene.cpp @ 1196:a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Wed, 27 Nov 2019 17:51:33 +0100 |
parents | f417a0ae282b |
children | 922d2e61aa5d |
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 | |
439 | 5 * Copyright (C) 2017-2019 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 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
409
diff
changeset
|
128 RadiographyLayer& RadiographyScene::RegisterLayer(RadiographyLayer* layer) |
408 | 129 { |
130 if (layer == NULL) | |
131 { | |
132 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
133 } | |
134 | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
409
diff
changeset
|
135 std::auto_ptr<RadiographyLayer> raii(layer); |
426 | 136 |
1112
d33ae2b0db9d
less logs + allow changing the size of the RadiographyLayer (to replace a low res image by a high res image)
Alain Mazy <alain@mazy.be>
parents:
928
diff
changeset
|
137 // LOG(INFO) << "Registering layer: " << countLayers_; |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
426
diff
changeset
|
138 |
408 | 139 size_t index = countLayers_++; |
140 raii->SetIndex(index); | |
141 layers_[index] = raii.release(); | |
142 | |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
605
diff
changeset
|
143 BroadcastMessage(GeometryChangedMessage(*this, *layer)); |
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
605
diff
changeset
|
144 BroadcastMessage(ContentChangedMessage(*this, *layer)); |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
145 layer->RegisterObserverCallback(new Callable<RadiographyScene, RadiographyLayer::LayerEditedMessage>(*this, &RadiographyScene::OnLayerEdited)); |
408 | 146 |
147 return *layer; | |
148 } | |
426 | 149 |
876 | 150 size_t RadiographyScene::GetApproximateMemoryUsage() const |
151 { | |
152 size_t size = 0; | |
153 for (Layers::const_iterator it = layers_.begin(); it != layers_.end(); it++) | |
154 { | |
155 size += it->second->GetApproximateMemoryUsage(); | |
156 } | |
157 return size; | |
158 } | |
159 | |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
160 void RadiographyScene::OnLayerEdited(const RadiographyLayer::LayerEditedMessage& message) |
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
161 { |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
605
diff
changeset
|
162 BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, message.GetOrigin())); |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
163 } |
408 | 164 |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
165 RadiographyScene::RadiographyScene(MessageBroker& broker) : |
408 | 166 IObserver(broker), |
167 IObservable(broker), | |
168 countLayers_(0), | |
169 hasWindowing_(false), | |
170 windowingCenter_(0), // Dummy initialization | |
171 windowingWidth_(0) // Dummy initialization | |
172 { | |
173 } | |
174 | |
175 | |
176 RadiographyScene::~RadiographyScene() | |
177 { | |
178 for (Layers::iterator it = layers_.begin(); it != layers_.end(); it++) | |
179 { | |
180 assert(it->second != NULL); | |
181 delete it->second; | |
182 } | |
183 } | |
184 | |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
185 RadiographyPhotometricDisplayMode RadiographyScene::GetPreferredPhotomotricDisplayMode() const |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
186 { |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
187 // 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
|
188 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
|
189 { |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
190 if (it->second->GetPreferredPhotomotricDisplayMode() != RadiographyPhotometricDisplayMode_Default) |
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 it->second->GetPreferredPhotomotricDisplayMode(); |
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 } |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
195 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
196 return RadiographyPhotometricDisplayMode_Default; |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
197 } |
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 |
430 | 200 void RadiographyScene::GetLayersIndexes(std::vector<size_t>& output) const |
201 { | |
202 for (Layers::const_iterator it = layers_.begin(); it != layers_.end(); it++) | |
203 { | |
204 output.push_back(it->first); | |
205 } | |
206 } | |
207 | |
425 | 208 void RadiographyScene::RemoveLayer(size_t layerIndex) |
209 { | |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
426
diff
changeset
|
210 LOG(INFO) << "Removing layer: " << layerIndex; |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
426
diff
changeset
|
211 |
571
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
212 Layers::iterator found = layers_.find(layerIndex); |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
213 |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
214 if (found == layers_.end()) |
425 | 215 { |
216 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
217 } | |
571
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
218 else |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
219 { |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
220 assert(found->second != NULL); |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
221 delete found->second; |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
222 |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
223 layers_.erase(found); |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
224 countLayers_--; |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
225 |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
226 LOG(INFO) << "Removing layer, there are now : " << countLayers_ << " layers"; |
1131
4663f158c748
RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents:
1112
diff
changeset
|
227 |
4663f158c748
RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents:
1112
diff
changeset
|
228 BroadcastMessage(RadiographyScene::LayerRemovedMessage(*this, layerIndex)); |
571
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
229 } |
425 | 230 } |
231 | |
430 | 232 const RadiographyLayer& RadiographyScene::GetLayer(size_t layerIndex) const |
425 | 233 { |
571
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
234 Layers::const_iterator found = layers_.find(layerIndex); |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
235 |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
236 if (found == layers_.end()) |
425 | 237 { |
238 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
239 } | |
571
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
240 else |
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 assert(found->second != NULL); |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
243 return *found->second; |
a29f9628369e
fix build on visual studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
244 } |
425 | 245 } |
408 | 246 |
247 bool RadiographyScene::GetWindowing(float& center, | |
248 float& width) const | |
249 { | |
250 if (hasWindowing_) | |
251 { | |
252 center = windowingCenter_; | |
253 width = windowingWidth_; | |
254 return true; | |
255 } | |
256 else | |
257 { | |
258 return false; | |
259 } | |
260 } | |
261 | |
262 | |
263 void RadiographyScene::GetWindowingWithDefault(float& center, | |
264 float& width) const | |
265 { | |
266 if (!GetWindowing(center, width)) | |
267 { | |
268 center = 128; | |
269 width = 256; | |
270 } | |
271 } | |
272 | |
273 | |
274 void RadiographyScene::SetWindowing(float center, | |
275 float width) | |
276 { | |
277 hasWindowing_ = true; | |
278 windowingCenter_ = center; | |
279 windowingWidth_ = width; | |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
280 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
605
diff
changeset
|
281 BroadcastMessage(RadiographyScene::WindowingChangedMessage(*this)); |
408 | 282 } |
283 | |
284 | |
1190 | 285 RadiographyLayer& RadiographyScene::LoadText(const std::string& utf8, |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
286 unsigned int fontSize, |
1190 | 287 uint8_t foreground, |
430 | 288 RadiographyLayer::Geometry* geometry) |
408 | 289 { |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
290 std::auto_ptr<RadiographyTextLayer> alpha(new RadiographyTextLayer(IObservable::GetBroker(), *this)); |
1190 | 291 alpha->LoadText(utf8, fontSize, foreground); |
430 | 292 if (geometry != NULL) |
293 { | |
294 alpha->SetGeometry(*geometry); | |
295 } | |
408 | 296 |
297 return RegisterLayer(alpha.release()); | |
298 } | |
299 | |
426 | 300 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
409
diff
changeset
|
301 RadiographyLayer& RadiographyScene::LoadTestBlock(unsigned int width, |
430 | 302 unsigned int height, |
303 RadiographyLayer::Geometry* geometry) | |
408 | 304 { |
305 std::auto_ptr<Orthanc::Image> block(new Orthanc::Image(Orthanc::PixelFormat_Grayscale8, width, height, false)); | |
306 | |
307 for (unsigned int padding = 0; | |
308 (width > 2 * padding) && (height > 2 * padding); | |
309 padding++) | |
310 { | |
311 uint8_t color; | |
312 if (255 > 10 * padding) | |
313 { | |
314 color = 255 - 10 * padding; | |
315 } | |
316 else | |
317 { | |
318 color = 0; | |
319 } | |
320 | |
321 Orthanc::ImageAccessor region; | |
322 block->GetRegion(region, padding, padding, width - 2 * padding, height - 2 * padding); | |
323 Orthanc::ImageProcessing::Set(region, color); | |
324 } | |
325 | |
430 | 326 return LoadAlphaBitmap(block.release(), geometry); |
327 } | |
328 | |
488 | 329 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
|
330 const RadiographyDicomLayer& dicomLayer, |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
331 float foreground, |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
332 RadiographyLayer::Geometry* geometry) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
333 { |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
334 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
|
335 mask->SetCorners(corners); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
336 if (geometry != NULL) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
337 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
338 mask->SetGeometry(*geometry); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
339 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
340 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
341 return RegisterLayer(mask.release()); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
342 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
343 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
440
diff
changeset
|
344 |
430 | 345 RadiographyLayer& RadiographyScene::LoadAlphaBitmap(Orthanc::ImageAccessor* bitmap, RadiographyLayer::Geometry *geometry) |
346 { | |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
347 std::auto_ptr<RadiographyAlphaLayer> alpha(new RadiographyAlphaLayer(IObservable::GetBroker(), *this)); |
430 | 348 alpha->SetAlpha(bitmap); |
349 if (geometry != NULL) | |
350 { | |
351 alpha->SetGeometry(*geometry); | |
352 } | |
408 | 353 |
354 return RegisterLayer(alpha.release()); | |
355 } | |
356 | |
553
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
357 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
|
358 const std::string& instance, |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
359 unsigned int frame, |
714
d2c0e347ddc2
deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
360 Deprecated::DicomFrameConverter* converter, // takes ownership |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
361 RadiographyPhotometricDisplayMode preferredPhotometricDisplayMode, |
553
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
362 RadiographyLayer::Geometry* geometry) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
363 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
364 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
|
365 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
366 layer.SetInstance(instance, frame); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
367 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
368 if (geometry != NULL) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
369 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
370 layer.SetGeometry(*geometry); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
371 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
372 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
373 layer.SetDicomFrameConverter(converter); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
374 layer.SetSourceImage(dicomImage); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
375 layer.SetPreferredPhotomotricDisplayMode(preferredPhotometricDisplayMode); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
376 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
377 return layer; |
587 | 378 } |
553
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
541
diff
changeset
|
379 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
380 RadiographyLayer& RadiographyScene::LoadDicomFrame(Deprecated::OrthancApiClient& orthanc, |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
381 const std::string& instance, |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
409
diff
changeset
|
382 unsigned int frame, |
430 | 383 bool httpCompression, |
384 RadiographyLayer::Geometry* geometry) | |
408 | 385 { |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
386 RadiographyDicomLayer& layer = dynamic_cast<RadiographyDicomLayer&>(RegisterLayer(new RadiographyDicomLayer(IObservable::GetBroker(), *this))); |
430 | 387 layer.SetInstance(instance, frame); |
388 | |
389 if (geometry != NULL) | |
390 { | |
391 layer.SetGeometry(*geometry); | |
392 } | |
408 | 393 |
394 { | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
395 Deprecated::IWebService::HttpHeaders headers; |
408 | 396 std::string uri = "/instances/" + instance + "/tags"; |
426 | 397 |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
398 orthanc.GetBinaryAsync( |
426 | 399 uri, headers, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
400 new Callable<RadiographyScene, Deprecated::OrthancApiClient::BinaryResponseReadyMessage> |
426 | 401 (*this, &RadiographyScene::OnTagsReceived), NULL, |
402 new Orthanc::SingleValueObject<size_t>(layer.GetIndex())); | |
408 | 403 } |
404 | |
405 { | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
406 Deprecated::IWebService::HttpHeaders headers; |
408 | 407 headers["Accept"] = "image/x-portable-arbitrarymap"; |
408 | |
409 if (httpCompression) | |
410 { | |
411 headers["Accept-Encoding"] = "gzip"; | |
412 } | |
426 | 413 |
408 | 414 std::string uri = ("/instances/" + instance + "/frames/" + |
415 boost::lexical_cast<std::string>(frame) + "/image-uint16"); | |
426 | 416 |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
417 orthanc.GetBinaryAsync( |
426 | 418 uri, headers, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
419 new Callable<RadiographyScene, Deprecated::OrthancApiClient::BinaryResponseReadyMessage> |
426 | 420 (*this, &RadiographyScene::OnFrameReceived), NULL, |
421 new Orthanc::SingleValueObject<size_t>(layer.GetIndex())); | |
408 | 422 } |
423 | |
424 return layer; | |
425 } | |
426 | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
427 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
428 RadiographyLayer& RadiographyScene::LoadDicomWebFrame(Deprecated::IWebService& web) |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
429 { |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
430 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
|
431 |
426 | 432 |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
433 return layer; |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
434 } |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
435 |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
436 |
426 | 437 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
438 void RadiographyScene::OnTagsReceived(const Deprecated::OrthancApiClient::BinaryResponseReadyMessage& message) |
408 | 439 { |
440 size_t index = dynamic_cast<const Orthanc::SingleValueObject<size_t>&> | |
426 | 441 (message.GetPayload()).GetValue(); |
408 | 442 |
443 LOG(INFO) << "JSON received: " << message.GetUri().c_str() | |
444 << " (" << message.GetAnswerSize() << " bytes) for layer " << index; | |
426 | 445 |
408 | 446 Layers::iterator layer = layers_.find(index); |
447 if (layer != layers_.end()) | |
448 { | |
449 assert(layer->second != NULL); | |
426 | 450 |
408 | 451 OrthancPlugins::FullOrthancDataset dicom(message.GetAnswer(), message.GetAnswerSize()); |
430 | 452 dynamic_cast<RadiographyDicomLayer*>(layer->second)->SetDicomTags(dicom); |
408 | 453 |
454 float c, w; | |
455 if (!hasWindowing_ && | |
456 layer->second->GetDefaultWindowing(c, w)) | |
457 { | |
458 hasWindowing_ = true; | |
459 windowingCenter_ = c; | |
460 windowingWidth_ = w; | |
461 } | |
462 | |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
605
diff
changeset
|
463 BroadcastMessage(GeometryChangedMessage(*this, *(layer->second))); |
408 | 464 } |
465 } | |
426 | 466 |
408 | 467 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
468 void RadiographyScene::OnFrameReceived(const Deprecated::OrthancApiClient::BinaryResponseReadyMessage& message) |
408 | 469 { |
470 size_t index = dynamic_cast<const Orthanc::SingleValueObject<size_t>&>(message.GetPayload()).GetValue(); | |
426 | 471 |
408 | 472 LOG(INFO) << "DICOM frame received: " << message.GetUri().c_str() |
473 << " (" << message.GetAnswerSize() << " bytes) for layer " << index; | |
426 | 474 |
408 | 475 Layers::iterator layer = layers_.find(index); |
476 if (layer != layers_.end()) | |
477 { | |
478 assert(layer->second != NULL); | |
479 | |
480 std::string content; | |
481 if (message.GetAnswerSize() > 0) | |
482 { | |
483 content.assign(reinterpret_cast<const char*>(message.GetAnswer()), message.GetAnswerSize()); | |
484 } | |
426 | 485 |
408 | 486 std::auto_ptr<Orthanc::PamReader> reader(new Orthanc::PamReader); |
487 reader->ReadFromMemory(content); | |
430 | 488 dynamic_cast<RadiographyDicomLayer*>(layer->second)->SetSourceImage(reader.release()); |
408 | 489 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
605
diff
changeset
|
490 BroadcastMessage(ContentChangedMessage(*this, *(layer->second))); |
408 | 491 } |
492 } | |
493 | |
494 | |
495 Extent2D RadiographyScene::GetSceneExtent() const | |
496 { | |
497 Extent2D extent; | |
498 | |
499 for (Layers::const_iterator it = layers_.begin(); | |
500 it != layers_.end(); ++it) | |
501 { | |
502 assert(it->second != NULL); | |
503 extent.Union(it->second->GetExtent()); | |
504 } | |
505 | |
506 return extent; | |
507 } | |
426 | 508 |
408 | 509 |
510 void RadiographyScene::Render(Orthanc::ImageAccessor& buffer, | |
409 | 511 const AffineTransform2D& viewTransform, |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
512 ImageInterpolation interpolation, |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
513 bool applyWindowing) const |
408 | 514 { |
515 // Render layers in the background-to-foreground order | |
516 for (size_t index = 0; index < countLayers_; index++) | |
517 { | |
518 Layers::const_iterator it = layers_.find(index); | |
519 if (it != layers_.end()) | |
520 { | |
521 assert(it->second != NULL); | |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
522 it->second->Render(buffer, viewTransform, interpolation, windowingCenter_, windowingWidth_, applyWindowing); |
408 | 523 } |
524 } | |
525 } | |
526 | |
527 | |
528 bool RadiographyScene::LookupLayer(size_t& index /* out */, | |
529 double x, | |
530 double y) const | |
531 { | |
532 // Render layers in the foreground-to-background order | |
533 for (size_t i = countLayers_; i > 0; i--) | |
534 { | |
535 index = i - 1; | |
536 Layers::const_iterator it = layers_.find(index); | |
537 if (it != layers_.end()) | |
538 { | |
539 assert(it->second != NULL); | |
540 if (it->second->Contains(x, y)) | |
541 { | |
542 return true; | |
543 } | |
544 } | |
545 } | |
546 | |
547 return false; | |
548 } | |
549 | |
426 | 550 |
408 | 551 void RadiographyScene::DrawBorder(CairoContext& context, |
552 unsigned int layer, | |
553 double zoom) | |
554 { | |
555 Layers::const_iterator found = layers_.find(layer); | |
426 | 556 |
408 | 557 if (found != layers_.end()) |
558 { | |
559 context.SetSourceColor(255, 0, 0); | |
560 found->second->DrawBorders(context, zoom); | |
561 } | |
562 } | |
563 | |
564 | |
565 void RadiographyScene::GetRange(float& minValue, | |
566 float& maxValue) const | |
567 { | |
568 bool first = true; | |
426 | 569 |
408 | 570 for (Layers::const_iterator it = layers_.begin(); |
571 it != layers_.end(); it++) | |
572 { | |
573 assert(it->second != NULL); | |
574 | |
575 float a, b; | |
576 if (it->second->GetRange(a, b)) | |
577 { | |
578 if (first) | |
579 { | |
580 minValue = a; | |
581 maxValue = b; | |
582 first = false; | |
583 } | |
584 else | |
585 { | |
586 minValue = std::min(a, minValue); | |
587 maxValue = std::max(b, maxValue); | |
588 } | |
589 } | |
590 } | |
591 | |
592 if (first) | |
593 { | |
594 minValue = 0; | |
595 maxValue = 0; | |
596 } | |
597 } | |
598 | |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
599 Orthanc::Image* RadiographyScene::ExportToImage(double pixelSpacingX, |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
600 double pixelSpacingY, |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
601 ImageInterpolation interpolation, |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
602 bool invert, |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
603 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
|
604 bool applyWindowing) |
426 | 605 { |
408 | 606 if (pixelSpacingX <= 0 || |
607 pixelSpacingY <= 0) | |
608 { | |
609 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
610 } | |
426 | 611 |
408 | 612 Extent2D extent = GetSceneExtent(); |
613 | |
928
1b49e78d91d0
fix for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
923
diff
changeset
|
614 int w = boost::math::iround(extent.GetWidth() / pixelSpacingX); |
1b49e78d91d0
fix for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
923
diff
changeset
|
615 int h = boost::math::iround(extent.GetHeight() / pixelSpacingY); |
408 | 616 |
617 if (w < 0 || h < 0) | |
618 { | |
619 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
620 } | |
621 | |
622 Orthanc::Image layers(Orthanc::PixelFormat_Float32, | |
623 static_cast<unsigned int>(w), | |
624 static_cast<unsigned int>(h), false); | |
625 | |
409 | 626 AffineTransform2D view = AffineTransform2D::Combine( |
426 | 627 AffineTransform2D::CreateScaling(1.0 / pixelSpacingX, 1.0 / pixelSpacingY), |
628 AffineTransform2D::CreateOffset(-extent.GetX1(), -extent.GetY1())); | |
629 | |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
630 // wipe background before rendering |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
631 Orthanc::ImageProcessing::Set(layers, 0); |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
431
diff
changeset
|
632 |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
633 Render(layers, view, interpolation, applyWindowing); |
408 | 634 |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
635 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
|
636 layers.GetWidth(), layers.GetHeight(), false)); |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
637 |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
638 Orthanc::ImageProcessing::Convert(*rendered, layers); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
639 if (invert) |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
640 Orthanc::ImageProcessing::Invert(*rendered, maxValue); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
641 |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
642 return rendered.release(); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
643 } |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
644 |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
645 |
587 | 646 Orthanc::Image* RadiographyScene::ExportToCreateDicomRequestAndImage(Json::Value& createDicomRequestContent, |
647 const Json::Value& dicomTags, | |
648 const std::string& parentOrthancId, | |
649 double pixelSpacingX, | |
650 double pixelSpacingY, | |
651 bool invert, | |
652 ImageInterpolation interpolation) | |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
653 { |
541 | 654 LOG(INFO) << "Exporting RadiographyScene to DICOM"; |
655 | |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
1190
diff
changeset
|
656 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 | 657 |
483 | 658 createDicomRequestContent["Tags"] = dicomTags; |
408 | 659 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
660 RadiographyPhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode(); |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
661 if ((invert && photometricMode != RadiographyPhotometricDisplayMode_Monochrome2) || |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
662 (!invert && photometricMode == RadiographyPhotometricDisplayMode_Monochrome1)) |
436
04711a2e12cd
fix crop + export photometric interpretation correctly
am@osimis.io
parents:
432
diff
changeset
|
663 { |
483 | 664 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME1"; |
436
04711a2e12cd
fix crop + export photometric interpretation correctly
am@osimis.io
parents:
432
diff
changeset
|
665 } |
04711a2e12cd
fix crop + export photometric interpretation correctly
am@osimis.io
parents:
432
diff
changeset
|
666 else |
04711a2e12cd
fix crop + export photometric interpretation correctly
am@osimis.io
parents:
432
diff
changeset
|
667 { |
483 | 668 createDicomRequestContent["Tags"]["PhotometricInterpretation"] = "MONOCHROME2"; |
436
04711a2e12cd
fix crop + export photometric interpretation correctly
am@osimis.io
parents:
432
diff
changeset
|
669 } |
408 | 670 |
671 // WARNING: The order of PixelSpacing is Y/X. We use "%0.8f" to | |
672 // avoid floating-point numbers to grow over 16 characters, | |
673 // which would be invalid according to DICOM standard | |
674 // ("dciodvfy" would complain). | |
675 char buf[32]; | |
676 sprintf(buf, "%0.8f\\%0.8f", pixelSpacingY, pixelSpacingX); | |
426 | 677 |
483 | 678 createDicomRequestContent["Tags"]["PixelSpacing"] = buf; |
408 | 679 |
680 float center, width; | |
681 if (GetWindowing(center, width)) | |
682 { | |
483 | 683 createDicomRequestContent["Tags"]["WindowCenter"] = |
426 | 684 boost::lexical_cast<std::string>(boost::math::iround(center)); |
408 | 685 |
483 | 686 createDicomRequestContent["Tags"]["WindowWidth"] = |
426 | 687 boost::lexical_cast<std::string>(boost::math::iround(width)); |
408 | 688 } |
689 | |
587 | 690 if (!parentOrthancId.empty()) |
691 { | |
692 createDicomRequestContent["Parent"] = parentOrthancId; | |
693 } | |
694 | |
695 return rendered.release(); | |
696 } | |
697 | |
698 | |
699 void RadiographyScene::ExportToCreateDicomRequest(Json::Value& createDicomRequestContent, | |
700 const Json::Value& dicomTags, | |
701 const std::string& parentOrthancId, | |
702 double pixelSpacingX, | |
703 double pixelSpacingY, | |
704 bool invert, | |
705 ImageInterpolation interpolation, | |
706 bool usePam) | |
707 { | |
708 LOG(INFO) << "Exporting RadiographyScene to DICOM"; | |
709 VLOG(1) << "Exporting RadiographyScene to: export to image"; | |
710 | |
711 std::auto_ptr<Orthanc::Image> rendered(ExportToCreateDicomRequestAndImage(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation)); | |
712 | |
713 // convert the image into base64 for inclusing in the createDicomRequest | |
714 std::string base64; | |
715 | |
716 { | |
717 std::string content; | |
718 | |
719 if (usePam) | |
720 { | |
721 VLOG(1) << "Exporting RadiographyScene: convert to PAM"; | |
722 Orthanc::PamWriter writer; | |
723 writer.WriteToMemory(content, *rendered); | |
724 } | |
725 else | |
726 { | |
727 Orthanc::PngWriter writer; | |
728 writer.WriteToMemory(content, *rendered); | |
729 } | |
730 | |
731 VLOG(1) << "Exporting RadiographyScene: encoding to base64"; | |
732 Orthanc::Toolbox::EncodeBase64(base64, content); | |
733 } | |
426 | 734 |
408 | 735 // This is Data URI scheme: https://en.wikipedia.org/wiki/Data_URI_scheme |
426 | 736 createDicomRequestContent["Content"] = ("data:" + |
737 std::string(usePam ? Orthanc::MIME_PAM : Orthanc::MIME_PNG) + | |
738 ";base64," + base64); | |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
739 |
541 | 740 VLOG(1) << "Exporting RadiographyScene: create-dicom request is ready"; |
484
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
741 } |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
742 |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
743 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
744 void RadiographyScene::ExportDicom(Deprecated::OrthancApiClient& orthanc, |
484
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
745 const Json::Value& dicomTags, |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
746 const std::string& parentOrthancId, |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
747 double pixelSpacingX, |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
748 double pixelSpacingY, |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
749 bool invert, |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
750 ImageInterpolation interpolation, |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
751 bool usePam) |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
752 { |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
753 Json::Value createDicomRequestContent; |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
754 |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
755 ExportToCreateDicomRequest(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation, usePam); |
7bf001b9d244
re-added ExportToCreateDicomRequest
Alain Mazy <alain@mazy.be>
parents:
483
diff
changeset
|
756 |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
757 orthanc.PostJsonAsyncExpectJson( |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
758 "/tools/create-dicom", createDicomRequestContent, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
759 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
|
760 (*this, &RadiographyScene::OnDicomExported), |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
475
diff
changeset
|
761 NULL, NULL); |
483 | 762 |
763 } | |
764 | |
765 | |
766 // Export using PAM is faster than using PNG, but requires Orthanc | |
767 // core >= 1.4.3 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
768 void RadiographyScene::ExportDicom(Deprecated::OrthancApiClient& orthanc, |
483 | 769 const Orthanc::DicomMap& dicom, |
770 const std::string& parentOrthancId, | |
771 double pixelSpacingX, | |
772 double pixelSpacingY, | |
773 bool invert, | |
774 ImageInterpolation interpolation, | |
775 bool usePam) | |
776 { | |
777 std::set<Orthanc::DicomTag> tags; | |
778 dicom.GetTags(tags); | |
779 | |
780 Json::Value jsonTags = Json::objectValue; | |
781 | |
782 for (std::set<Orthanc::DicomTag>::const_iterator | |
783 tag = tags.begin(); tag != tags.end(); ++tag) | |
784 { | |
785 const Orthanc::DicomValue& value = dicom.GetValue(*tag); | |
786 if (!value.IsNull() && | |
787 !value.IsBinary()) | |
788 { | |
789 jsonTags[tag->Format()] = value.GetContent(); | |
790 } | |
791 } | |
792 | |
793 ExportDicom(orthanc, jsonTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation, usePam); | |
408 | 794 } |
795 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
796 void RadiographyScene::OnDicomExported(const Deprecated::OrthancApiClient::JsonResponseReadyMessage& message) |
408 | 797 { |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
798 LOG(INFO) << "DICOM export was successful: " |
408 | 799 << message.GetJson().toStyledString(); |
800 } | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
801 |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
802 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
803 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
|
804 { |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
805 LOG(INFO) << "DICOMweb WADO-RS received: " << message.GetAnswerSize() << " bytes"; |
418 | 806 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
807 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
|
808 for (Deprecated::IWebService::HttpHeaders::const_iterator |
426 | 809 it = h.begin(); it != h.end(); ++it) |
418 | 810 { |
811 printf("[%s] = [%s]\n", it->first.c_str(), it->second.c_str()); | |
812 } | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
813 } |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
412
diff
changeset
|
814 |
408 | 815 } |