annotate Framework/Radiography/RadiographyScene.cpp @ 1195:bdc6837d5917 broker

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