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