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