Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Toolbox/OrthancSlicesLoader.cpp @ 1227:a1c0c9c9f9af broker
deprecating SliceImageQuality enum
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 08 Dec 2019 12:06:44 +0100 |
parents | 21c2b0eee53c |
children | 0ca50d275b9a |
rev | line source |
---|---|
73 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
73 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
252 | 16 * |
73 | 17 * You should have received a copy of the GNU Affero General Public License |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "OrthancSlicesLoader.h" | |
23 | |
792
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
739
diff
changeset
|
24 #include "../Toolbox/MessagingToolbox.h" |
73 | 25 |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
26 #include <Core/Compression/GzipCompressor.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
27 #include <Core/Endianness.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
28 #include <Core/Images/Image.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
29 #include <Core/Images/ImageProcessing.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
30 #include <Core/Images/JpegReader.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
31 #include <Core/Images/PngReader.h> |
257 | 32 #include <Core/Images/PamReader.h> |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
33 #include <Core/Logging.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
34 #include <Core/OrthancException.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
35 #include <Core/Toolbox.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
36 #include <Plugins/Samples/Common/FullOrthancDataset.h> |
73 | 37 |
38 #include <boost/lexical_cast.hpp> | |
39 | |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
40 |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
41 |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
42 /** |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
43 * TODO This is a SLOW implementation of base64 decoding, because |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
44 * "Orthanc::Toolbox::DecodeBase64()" does not work properly with |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
45 * WASM. UNDERSTAND WHY. |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
46 * https://stackoverflow.com/a/34571089/881731 |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
47 **/ |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
48 static std::string base64_decode(const std::string &in) |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
49 { |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
50 std::string out; |
252 | 51 |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
52 std::vector<int> T(256,-1); |
252 | 53 for (int i=0; i<64; i++) T["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i]] = i; |
54 | |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
55 int val=0, valb=-8; |
128 | 56 for (size_t i = 0; i < in.size(); i++) { |
57 unsigned char c = in[i]; | |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
58 if (T[c] == -1) break; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
59 val = (val<<6) + T[c]; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
60 valb += 6; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
61 if (valb>=0) { |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
62 out.push_back(char((val>>valb)&0xFF)); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
63 valb-=8; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
64 } |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
65 } |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
66 return out; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
67 } |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
68 |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
69 |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
70 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
71 namespace Deprecated |
73 | 72 { |
73 class OrthancSlicesLoader::Operation : public Orthanc::IDynamicObject | |
74 { | |
75 private: | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
76 Mode mode_; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
77 unsigned int frame_; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
78 unsigned int sliceIndex_; |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
79 const Slice* slice_; |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
80 std::string instanceId_; |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
81 SliceImageQuality quality_; |
73 | 82 |
83 Operation(Mode mode) : | |
84 mode_(mode) | |
85 { | |
86 } | |
87 | |
88 public: | |
89 Mode GetMode() const | |
90 { | |
91 return mode_; | |
92 } | |
93 | |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
94 SliceImageQuality GetQuality() const |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
95 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
96 assert(mode_ == Mode_LoadImage || |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
97 mode_ == Mode_LoadRawImage); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
98 return quality_; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
99 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
100 |
73 | 101 unsigned int GetSliceIndex() const |
102 { | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
103 assert(mode_ == Mode_LoadImage || |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
104 mode_ == Mode_LoadRawImage); |
73 | 105 return sliceIndex_; |
106 } | |
107 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
108 const Slice& GetSlice() const |
73 | 109 { |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
110 assert(mode_ == Mode_LoadImage || |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
111 mode_ == Mode_LoadRawImage); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
112 assert(slice_ != NULL); |
73 | 113 return *slice_; |
114 } | |
115 | |
116 unsigned int GetFrame() const | |
117 { | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
118 assert(mode_ == Mode_FrameGeometry); |
73 | 119 return frame_; |
120 } | |
252 | 121 |
73 | 122 const std::string& GetInstanceId() const |
123 { | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
124 assert(mode_ == Mode_FrameGeometry || |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
125 mode_ == Mode_InstanceGeometry); |
73 | 126 return instanceId_; |
127 } | |
128 | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
129 static Operation* DownloadInstanceGeometry(const std::string& instanceId) |
73 | 130 { |
131 std::auto_ptr<Operation> operation(new Operation(Mode_InstanceGeometry)); | |
132 operation->instanceId_ = instanceId; | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
133 return operation.release(); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
134 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
135 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
136 static Operation* DownloadFrameGeometry(const std::string& instanceId, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
137 unsigned int frame) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
138 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
139 std::auto_ptr<Operation> operation(new Operation(Mode_FrameGeometry)); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
140 operation->instanceId_ = instanceId; |
73 | 141 operation->frame_ = frame; |
142 return operation.release(); | |
143 } | |
144 | |
145 static Operation* DownloadSliceImage(unsigned int sliceIndex, | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
146 const Slice& slice, |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
147 SliceImageQuality quality) |
73 | 148 { |
149 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadImage)); | |
150 tmp->sliceIndex_ = sliceIndex; | |
151 tmp->slice_ = &slice; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
152 tmp->quality_ = quality; |
73 | 153 return tmp.release(); |
154 } | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
155 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
156 static Operation* DownloadSliceRawImage(unsigned int sliceIndex, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
157 const Slice& slice) |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
158 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
159 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadRawImage)); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
160 tmp->sliceIndex_ = sliceIndex; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
161 tmp->slice_ = &slice; |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
162 tmp->quality_ = SliceImageQuality_InternalRaw; |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
163 return tmp.release(); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
164 } |
73 | 165 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
166 static Operation* DownloadDicomFile(const Slice& slice) |
73 | 167 { |
257 | 168 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadDicomFile)); |
169 tmp->slice_ = &slice; | |
170 return tmp.release(); | |
73 | 171 } |
172 | |
173 }; | |
174 | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
175 void OrthancSlicesLoader::NotifySliceImageSuccess(const Operation& operation, |
378 | 176 const Orthanc::ImageAccessor& image) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
177 { |
406
5d359b115b29
use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
178 OrthancSlicesLoader::SliceImageReadyMessage msg |
5d359b115b29
use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
179 (*this, operation.GetSliceIndex(), operation.GetSlice(), image, operation.GetQuality()); |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
180 BroadcastMessage(msg); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
181 } |
252 | 182 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
183 |
268
5bd4161bf11b
removed constness of the observable when emitting a message
am@osimis.io
parents:
267
diff
changeset
|
184 void OrthancSlicesLoader::NotifySliceImageError(const Operation& operation) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
185 { |
406
5d359b115b29
use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
186 OrthancSlicesLoader::SliceImageErrorMessage msg |
5d359b115b29
use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
187 (*this, operation.GetSliceIndex(), operation.GetSlice(), operation.GetQuality()); |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
188 BroadcastMessage(msg); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
189 } |
252 | 190 |
191 | |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
192 void OrthancSlicesLoader::SortAndFinalizeSlices() |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
193 { |
648 | 194 bool ok = slices_.Sort(); |
252 | 195 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
196 state_ = State_GeometryReady; |
252 | 197 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
198 if (ok) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
199 { |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
200 LOG(INFO) << "Loaded a series with " << slices_.GetSlicesCount() << " slice(s)"; |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
201 BroadcastMessage(SliceGeometryReadyMessage(*this)); |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
202 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
203 else |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
204 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
205 LOG(ERROR) << "This series is empty"; |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
206 BroadcastMessage(SliceGeometryErrorMessage(*this)); |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
207 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
208 } |
252 | 209 |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
210 void OrthancSlicesLoader::OnGeometryError(const IWebService::HttpRequestErrorMessage& message) |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
211 { |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
212 BroadcastMessage(SliceGeometryErrorMessage(*this)); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
213 state_ = State_Error; |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
214 } |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
215 |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
216 void OrthancSlicesLoader::OnSliceImageError(const IWebService::HttpRequestErrorMessage& message) |
73 | 217 { |
377 | 218 NotifySliceImageError(dynamic_cast<const Operation&>(message.GetPayload())); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
219 state_ = State_Error; |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
220 } |
73 | 221 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
222 void OrthancSlicesLoader::ParseSeriesGeometry(const OrthancApiClient::JsonResponseReadyMessage& message) |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
223 { |
377 | 224 const Json::Value& series = message.GetJson(); |
73 | 225 Json::Value::Members instances = series.getMemberNames(); |
252 | 226 |
73 | 227 slices_.Reserve(instances.size()); |
252 | 228 |
73 | 229 for (size_t i = 0; i < instances.size(); i++) |
230 { | |
231 OrthancPlugins::FullOrthancDataset dataset(series[instances[i]]); | |
252 | 232 |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
233 Orthanc::DicomMap dicom; |
792
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
739
diff
changeset
|
234 MessagingToolbox::ConvertDataset(dicom, dataset); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
235 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
236 unsigned int frames; |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
237 if (!dicom.ParseUnsignedInteger32(frames, Orthanc::DICOM_TAG_NUMBER_OF_FRAMES)) |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
238 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
239 frames = 1; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
240 } |
252 | 241 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
242 for (unsigned int frame = 0; frame < frames; frame++) |
73 | 243 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
244 std::auto_ptr<Slice> slice(new Slice); |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
245 if (slice->ParseOrthancFrame(dicom, instances[i], frame)) |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
246 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
247 OrthancStone::CoordinateSystem3D geometry = slice->GetGeometry(); |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
248 slices_.AddSlice(geometry, slice.release()); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
249 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
250 else |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
251 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
252 LOG(WARNING) << "Skipping invalid frame " << frame << " within instance " << instances[i]; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
253 } |
73 | 254 } |
255 } | |
252 | 256 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
257 SortAndFinalizeSlices(); |
73 | 258 } |
252 | 259 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
260 void OrthancSlicesLoader::ParseInstanceGeometry(const OrthancApiClient::JsonResponseReadyMessage& message) |
73 | 261 { |
377 | 262 const Json::Value& tags = message.GetJson(); |
263 const std::string& instanceId = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()).GetInstanceId(); | |
73 | 264 |
265 OrthancPlugins::FullOrthancDataset dataset(tags); | |
252 | 266 |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
267 Orthanc::DicomMap dicom; |
792
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
739
diff
changeset
|
268 MessagingToolbox::ConvertDataset(dicom, dataset); |
252 | 269 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
270 unsigned int frames; |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
271 if (!dicom.ParseUnsignedInteger32(frames, Orthanc::DICOM_TAG_NUMBER_OF_FRAMES)) |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
272 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
273 frames = 1; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
274 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
275 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
276 LOG(INFO) << "Instance " << instanceId << " contains " << frames << " frame(s)"; |
252 | 277 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
278 for (unsigned int frame = 0; frame < frames; frame++) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
279 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
280 std::auto_ptr<Slice> slice(new Slice); |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
281 if (slice->ParseOrthancFrame(dicom, instanceId, frame)) |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
282 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
283 OrthancStone::CoordinateSystem3D geometry = slice->GetGeometry(); |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
284 slices_.AddSlice(geometry, slice.release()); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
285 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
286 else |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
287 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
288 LOG(WARNING) << "Skipping invalid multi-frame instance " << instanceId; |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
289 BroadcastMessage(SliceGeometryErrorMessage(*this)); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
290 return; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
291 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
292 } |
252 | 293 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
294 SortAndFinalizeSlices(); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
295 } |
252 | 296 |
297 | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
298 void OrthancSlicesLoader::ParseFrameGeometry(const OrthancApiClient::JsonResponseReadyMessage& message) |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
299 { |
377 | 300 const Json::Value& tags = message.GetJson(); |
301 const std::string& instanceId = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()).GetInstanceId(); | |
302 unsigned int frame = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()).GetFrame(); | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
303 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
304 OrthancPlugins::FullOrthancDataset dataset(tags); |
252 | 305 |
73 | 306 state_ = State_GeometryReady; |
252 | 307 |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
308 Orthanc::DicomMap dicom; |
792
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
739
diff
changeset
|
309 MessagingToolbox::ConvertDataset(dicom, dataset); |
252 | 310 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
311 std::auto_ptr<Slice> slice(new Slice); |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
312 if (slice->ParseOrthancFrame(dicom, instanceId, frame)) |
73 | 313 { |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
257
diff
changeset
|
314 LOG(INFO) << "Loaded instance geometry " << instanceId; |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
315 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
316 OrthancStone::CoordinateSystem3D geometry = slice->GetGeometry(); |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
317 slices_.AddSlice(geometry, slice.release()); |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
318 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
319 BroadcastMessage(SliceGeometryReadyMessage(*this)); |
73 | 320 } |
321 else | |
322 { | |
323 LOG(WARNING) << "Skipping invalid instance " << instanceId; | |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
324 BroadcastMessage(SliceGeometryErrorMessage(*this)); |
73 | 325 } |
326 } | |
252 | 327 |
328 | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
329 void OrthancSlicesLoader::ParseSliceImagePng(const OrthancApiClient::BinaryResponseReadyMessage& message) |
73 | 330 { |
377 | 331 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()); |
378 | 332 std::auto_ptr<Orthanc::ImageAccessor> image; |
252 | 333 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
334 try |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
335 { |
99 | 336 image.reset(new Orthanc::PngReader); |
377 | 337 dynamic_cast<Orthanc::PngReader&>(*image).ReadFromMemory(message.GetAnswer(), message.GetAnswerSize()); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
338 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
339 catch (Orthanc::OrthancException&) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
340 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
341 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
342 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
343 } |
252 | 344 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
345 if (image->GetWidth() != operation.GetSlice().GetWidth() || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
346 image->GetHeight() != operation.GetSlice().GetHeight()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
347 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
348 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
349 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
350 } |
73 | 351 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
352 if (operation.GetSlice().GetConverter().GetExpectedPixelFormat() == |
73 | 353 Orthanc::PixelFormat_SignedGrayscale16) |
354 { | |
355 if (image->GetFormat() == Orthanc::PixelFormat_Grayscale16) | |
356 { | |
357 image->SetFormat(Orthanc::PixelFormat_SignedGrayscale16); | |
358 } | |
359 else | |
360 { | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
361 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
362 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
363 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
364 } |
252 | 365 |
378 | 366 NotifySliceImageSuccess(operation, *image); |
252 | 367 } |
368 | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
369 void OrthancSlicesLoader::ParseSliceImagePam(const OrthancApiClient::BinaryResponseReadyMessage& message) |
73 | 370 { |
377 | 371 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()); |
378 | 372 std::auto_ptr<Orthanc::ImageAccessor> image; |
73 | 373 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
374 try |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
375 { |
257 | 376 image.reset(new Orthanc::PamReader); |
378 | 377 dynamic_cast<Orthanc::PamReader&>(*image).ReadFromMemory(message.GetAnswer(), message.GetAnswerSize()); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
378 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
379 catch (Orthanc::OrthancException&) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
380 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
381 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
382 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
383 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
384 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
385 if (image->GetWidth() != operation.GetSlice().GetWidth() || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
386 image->GetHeight() != operation.GetSlice().GetHeight()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
387 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
388 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
389 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
390 } |
257 | 391 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
392 if (operation.GetSlice().GetConverter().GetExpectedPixelFormat() == |
73 | 393 Orthanc::PixelFormat_SignedGrayscale16) |
394 { | |
395 if (image->GetFormat() == Orthanc::PixelFormat_Grayscale16) | |
396 { | |
397 image->SetFormat(Orthanc::PixelFormat_SignedGrayscale16); | |
398 } | |
399 else | |
400 { | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
401 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
402 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
403 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
404 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
405 |
378 | 406 NotifySliceImageSuccess(operation, *image); |
257 | 407 } |
408 | |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
409 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
410 void OrthancSlicesLoader::ParseSliceImageJpeg(const OrthancApiClient::JsonResponseReadyMessage& message) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
411 { |
377 | 412 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
413 |
377 | 414 const Json::Value& encoded = message.GetJson(); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
415 if (encoded.type() != Json::objectValue || |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
416 !encoded.isMember("Orthanc") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
417 encoded["Orthanc"].type() != Json::objectValue) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
418 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
419 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
420 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
421 } |
252 | 422 |
377 | 423 const Json::Value& info = encoded["Orthanc"]; |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
424 if (!info.isMember("PixelData") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
425 !info.isMember("Stretched") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
426 !info.isMember("Compression") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
427 info["Compression"].type() != Json::stringValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
428 info["PixelData"].type() != Json::stringValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
429 info["Stretched"].type() != Json::booleanValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
430 info["Compression"].asString() != "Jpeg") |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
431 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
432 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
433 return; |
94 | 434 } |
252 | 435 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
436 bool isSigned = false; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
437 bool isStretched = info["Stretched"].asBool(); |
252 | 438 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
439 if (info.isMember("IsSigned")) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
440 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
441 if (info["IsSigned"].type() != Json::booleanValue) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
442 { |
94 | 443 NotifySliceImageError(operation); |
444 return; | |
252 | 445 } |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
446 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
447 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
448 isSigned = info["IsSigned"].asBool(); |
73 | 449 } |
450 } | |
252 | 451 |
378 | 452 std::auto_ptr<Orthanc::ImageAccessor> reader; |
252 | 453 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
454 { |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
455 std::string jpeg; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
456 //Orthanc::Toolbox::DecodeBase64(jpeg, info["PixelData"].asString()); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
457 jpeg = base64_decode(info["PixelData"].asString()); |
252 | 458 |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
459 try |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
460 { |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
461 reader.reset(new Orthanc::JpegReader); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
462 dynamic_cast<Orthanc::JpegReader&>(*reader).ReadFromMemory(jpeg); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
463 } |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
464 catch (Orthanc::OrthancException&) |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
465 { |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
466 NotifySliceImageError(operation); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
467 return; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
468 } |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
469 } |
252 | 470 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
471 Orthanc::PixelFormat expectedFormat = |
378 | 472 operation.GetSlice().GetConverter().GetExpectedPixelFormat(); |
252 | 473 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
474 if (reader->GetFormat() == Orthanc::PixelFormat_RGB24) // This is a color image |
73 | 475 { |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
476 if (expectedFormat != Orthanc::PixelFormat_RGB24) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
477 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
478 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
479 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
480 } |
252 | 481 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
482 if (isSigned || isStretched) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
483 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
484 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
485 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
486 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
487 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
488 { |
378 | 489 NotifySliceImageSuccess(operation, *reader); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
490 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
491 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
492 } |
252 | 493 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
494 if (reader->GetFormat() != Orthanc::PixelFormat_Grayscale8) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
495 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
496 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
497 return; |
73 | 498 } |
252 | 499 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
500 if (!isStretched) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
501 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
502 if (expectedFormat != reader->GetFormat()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
503 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
504 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
505 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
506 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
507 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
508 { |
378 | 509 NotifySliceImageSuccess(operation, *reader); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
510 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
511 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
512 } |
252 | 513 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
514 int32_t stretchLow = 0; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
515 int32_t stretchHigh = 0; |
252 | 516 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
517 if (!info.isMember("StretchLow") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
518 !info.isMember("StretchHigh") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
519 info["StretchLow"].type() != Json::intValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
520 info["StretchHigh"].type() != Json::intValue) |
73 | 521 { |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
522 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
523 return; |
73 | 524 } |
252 | 525 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
526 stretchLow = info["StretchLow"].asInt(); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
527 stretchHigh = info["StretchHigh"].asInt(); |
252 | 528 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
529 if (stretchLow < -32768 || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
530 stretchHigh > 65535 || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
531 (stretchLow < 0 && stretchHigh > 32767)) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
532 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
533 // This range cannot be represented with a uint16_t or an int16_t |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
534 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
535 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
536 } |
252 | 537 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
538 // Decode a grayscale JPEG 8bpp image coming from the Web viewer |
378 | 539 std::auto_ptr<Orthanc::ImageAccessor> image |
540 (new Orthanc::Image(expectedFormat, reader->GetWidth(), reader->GetHeight(), false)); | |
252 | 541 |
203 | 542 Orthanc::ImageProcessing::Convert(*image, *reader); |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
318
diff
changeset
|
543 reader.reset(); |
252 | 544 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
545 float scaling = static_cast<float>(stretchHigh - stretchLow) / 255.0f; |
252 | 546 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
547 if (!OrthancStone::LinearAlgebra::IsCloseToZero(scaling)) |
203 | 548 { |
549 float offset = static_cast<float>(stretchLow) / scaling; | |
550 Orthanc::ImageProcessing::ShiftScale(*image, offset, scaling, true); | |
551 } | |
252 | 552 |
378 | 553 NotifySliceImageSuccess(operation, *image); |
73 | 554 } |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
555 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
556 |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
557 class StringImage : public Orthanc::ImageAccessor |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
558 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
559 private: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
560 std::string buffer_; |
73 | 561 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
562 public: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
563 StringImage(Orthanc::PixelFormat format, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
564 unsigned int width, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
565 unsigned int height, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
566 std::string& buffer) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
567 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
568 if (buffer.size() != Orthanc::GetBytesPerPixel(format) * width * height) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
569 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
570 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
571 } |
252 | 572 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
573 buffer_.swap(buffer); // The source buffer is now empty |
252 | 574 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
575 void* data = (buffer_.empty() ? NULL : &buffer_[0]); |
252 | 576 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
577 AssignWritable(format, width, height, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
578 Orthanc::GetBytesPerPixel(format) * width, data); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
579 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
580 }; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
581 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
582 void OrthancSlicesLoader::ParseSliceRawImage(const OrthancApiClient::BinaryResponseReadyMessage& message) |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
583 { |
377 | 584 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
585 Orthanc::GzipCompressor compressor; |
252 | 586 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
587 std::string raw; |
377 | 588 compressor.Uncompress(raw, message.GetAnswer(), message.GetAnswerSize()); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
589 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
590 const Orthanc::DicomImageInformation& info = operation.GetSlice().GetImageInformation(); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
591 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
592 if (info.GetBitsAllocated() == 32 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
593 info.GetBitsStored() == 32 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
594 info.GetHighBit() == 31 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
595 info.GetChannelCount() == 1 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
596 !info.IsSigned() && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
597 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
598 raw.size() == info.GetWidth() * info.GetHeight() * 4) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
599 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
600 // This is the case of RT-DOSE (uint32_t values) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
601 |
378 | 602 std::auto_ptr<Orthanc::ImageAccessor> image |
603 (new StringImage(Orthanc::PixelFormat_Grayscale32, info.GetWidth(), | |
604 info.GetHeight(), raw)); | |
252 | 605 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
606 // TODO - Only for big endian |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
607 for (unsigned int y = 0; y < image->GetHeight(); y++) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
608 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
609 uint32_t *p = reinterpret_cast<uint32_t*>(image->GetRow(y)); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
610 for (unsigned int x = 0; x < image->GetWidth(); x++, p++) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
611 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
612 *p = le32toh(*p); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
613 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
614 } |
252 | 615 |
378 | 616 NotifySliceImageSuccess(operation, *image); |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
617 } |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
618 else if (info.GetBitsAllocated() == 16 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
619 info.GetBitsStored() == 16 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
620 info.GetHighBit() == 15 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
621 info.GetChannelCount() == 1 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
622 !info.IsSigned() && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
623 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
624 raw.size() == info.GetWidth() * info.GetHeight() * 2) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
625 { |
378 | 626 std::auto_ptr<Orthanc::ImageAccessor> image |
627 (new StringImage(Orthanc::PixelFormat_Grayscale16, info.GetWidth(), | |
628 info.GetHeight(), raw)); | |
252 | 629 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
630 // TODO - Big endian ? |
252 | 631 |
378 | 632 NotifySliceImageSuccess(operation, *image); |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
633 } |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
634 else |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
635 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
636 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
637 } |
252 | 638 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
639 } |
252 | 640 |
641 | |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
642 OrthancSlicesLoader::OrthancSlicesLoader(boost::shared_ptr<OrthancApiClient> orthanc) : |
73 | 643 orthanc_(orthanc), |
644 state_(State_Initialization) | |
645 { | |
646 } | |
252 | 647 |
73 | 648 |
649 void OrthancSlicesLoader::ScheduleLoadSeries(const std::string& seriesId) | |
650 { | |
651 if (state_ != State_Initialization) | |
652 { | |
653 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
654 } | |
655 else | |
656 { | |
657 state_ = State_LoadingGeometry; | |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
658 orthanc_->GetJsonAsync("/series/" + seriesId + "/instances-tags", |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
659 new DeprecatedCallable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(GetSharedObserver(), &OrthancSlicesLoader::ParseSeriesGeometry), |
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
660 new DeprecatedCallable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(GetSharedObserver(), &OrthancSlicesLoader::OnGeometryError), |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
661 NULL); |
73 | 662 } |
663 } | |
252 | 664 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
665 void OrthancSlicesLoader::ScheduleLoadInstance(const std::string& instanceId) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
666 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
667 if (state_ != State_Initialization) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
668 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
669 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
670 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
671 else |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
672 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
673 state_ = State_LoadingGeometry; |
252 | 674 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
675 // Tag "3004-000c" is "Grid Frame Offset Vector", which is |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
676 // mandatory to read RT DOSE, but is too long to be returned by default |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
677 orthanc_->GetJsonAsync("/instances/" + instanceId + "/tags?ignore-length=3004-000c", |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
678 new DeprecatedCallable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(GetSharedObserver(), &OrthancSlicesLoader::ParseInstanceGeometry), |
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
679 new DeprecatedCallable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(GetSharedObserver(), &OrthancSlicesLoader::OnGeometryError), |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
680 Operation::DownloadInstanceGeometry(instanceId)); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
681 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
682 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
683 |
252 | 684 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
685 void OrthancSlicesLoader::ScheduleLoadFrame(const std::string& instanceId, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
686 unsigned int frame) |
73 | 687 { |
688 if (state_ != State_Initialization) | |
689 { | |
690 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
691 } | |
692 else | |
693 { | |
694 state_ = State_LoadingGeometry; | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
695 |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
696 orthanc_->GetJsonAsync("/instances/" + instanceId + "/tags", |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
697 new DeprecatedCallable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(GetSharedObserver(), &OrthancSlicesLoader::ParseFrameGeometry), |
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
698 new DeprecatedCallable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(GetSharedObserver(), &OrthancSlicesLoader::OnGeometryError), |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
699 Operation::DownloadFrameGeometry(instanceId, frame)); |
73 | 700 } |
701 } | |
702 | |
252 | 703 |
77 | 704 bool OrthancSlicesLoader::IsGeometryReady() const |
705 { | |
706 return state_ == State_GeometryReady; | |
707 } | |
252 | 708 |
709 | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
710 size_t OrthancSlicesLoader::GetSlicesCount() const |
73 | 711 { |
712 if (state_ != State_GeometryReady) | |
713 { | |
714 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
715 } | |
252 | 716 |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
717 return slices_.GetSlicesCount(); |
73 | 718 } |
252 | 719 |
73 | 720 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
721 const Slice& OrthancSlicesLoader::GetSlice(size_t index) const |
73 | 722 { |
723 if (state_ != State_GeometryReady) | |
724 { | |
725 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
726 } | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
727 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
728 return dynamic_cast<const Slice&>(slices_.GetSlicePayload(index)); |
73 | 729 } |
730 | |
252 | 731 |
77 | 732 bool OrthancSlicesLoader::LookupSlice(size_t& index, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
733 const OrthancStone::CoordinateSystem3D& plane) const |
77 | 734 { |
735 if (state_ != State_GeometryReady) | |
736 { | |
737 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
738 } | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
739 |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
740 double distance; |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
741 return (slices_.LookupClosestSlice(index, distance, plane) && |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
742 distance <= GetSlice(index).GetThickness() / 2.0); |
77 | 743 } |
744 | |
252 | 745 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
746 void OrthancSlicesLoader::ScheduleSliceImagePng(const Slice& slice, |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
747 size_t index) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
748 { |
252 | 749 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
750 boost::lexical_cast<std::string>(slice.GetFrame())); |
252 | 751 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
752 switch (slice.GetConverter().GetExpectedPixelFormat()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
753 { |
378 | 754 case Orthanc::PixelFormat_RGB24: |
755 uri += "/preview"; | |
756 break; | |
252 | 757 |
378 | 758 case Orthanc::PixelFormat_Grayscale16: |
759 uri += "/image-uint16"; | |
760 break; | |
252 | 761 |
378 | 762 case Orthanc::PixelFormat_SignedGrayscale16: |
763 uri += "/image-int16"; | |
764 break; | |
252 | 765 |
378 | 766 default: |
767 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
768 } |
252 | 769 |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
770 orthanc_->GetBinaryAsync(uri, "image/png", |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
771 new DeprecatedCallable<OrthancSlicesLoader, |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
772 OrthancApiClient::BinaryResponseReadyMessage> |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
773 (GetSharedObserver(), &OrthancSlicesLoader::ParseSliceImagePng), |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
774 new DeprecatedCallable<OrthancSlicesLoader, |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
775 IWebService::HttpRequestErrorMessage> |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
776 (GetSharedObserver(), &OrthancSlicesLoader::OnSliceImageError), |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
777 Operation::DownloadSliceImage( |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
778 static_cast<unsigned int>(index), slice, SliceImageQuality_FullPng)); |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
792
diff
changeset
|
779 } |
252 | 780 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
781 void OrthancSlicesLoader::ScheduleSliceImagePam(const Slice& slice, |
257 | 782 size_t index) |
783 { | |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
648
diff
changeset
|
784 std::string uri = |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
648
diff
changeset
|
785 ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
792
diff
changeset
|
786 boost::lexical_cast<std::string>(slice.GetFrame())); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
787 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
788 switch (slice.GetConverter().GetExpectedPixelFormat()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
789 { |
378 | 790 case Orthanc::PixelFormat_RGB24: |
791 uri += "/preview"; | |
792 break; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
793 |
378 | 794 case Orthanc::PixelFormat_Grayscale16: |
795 uri += "/image-uint16"; | |
796 break; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
797 |
378 | 798 case Orthanc::PixelFormat_SignedGrayscale16: |
799 uri += "/image-int16"; | |
800 break; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
801 |
378 | 802 default: |
803 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
804 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
805 |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
806 orthanc_->GetBinaryAsync(uri, "image/x-portable-arbitrarymap", |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
807 new DeprecatedCallable<OrthancSlicesLoader, |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
808 OrthancApiClient::BinaryResponseReadyMessage> |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
809 (GetSharedObserver(), &OrthancSlicesLoader::ParseSliceImagePam), |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
810 new DeprecatedCallable<OrthancSlicesLoader, |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
811 IWebService::HttpRequestErrorMessage> |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
812 (GetSharedObserver(), &OrthancSlicesLoader::OnSliceImageError), |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
813 Operation::DownloadSliceImage(static_cast<unsigned int>(index), |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
814 slice, SliceImageQuality_FullPam)); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
815 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
816 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
817 |
252 | 818 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
819 void OrthancSlicesLoader::ScheduleSliceImageJpeg(const Slice& slice, |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
820 size_t index, |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
821 SliceImageQuality quality) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
822 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
823 unsigned int value; |
252 | 824 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
825 switch (quality) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
826 { |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
827 case SliceImageQuality_Jpeg50: |
378 | 828 value = 50; |
829 break; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
830 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
831 case SliceImageQuality_Jpeg90: |
378 | 832 value = 90; |
833 break; | |
252 | 834 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
835 case SliceImageQuality_Jpeg95: |
378 | 836 value = 95; |
837 break; | |
252 | 838 |
378 | 839 default: |
840 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
841 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
842 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
843 // This requires the official Web viewer plugin to be installed! |
252 | 844 std::string uri = ("/web-viewer/instances/jpeg" + |
845 boost::lexical_cast<std::string>(value) + | |
846 "-" + slice.GetOrthancInstanceId() + "_" + | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
847 boost::lexical_cast<std::string>(slice.GetFrame())); |
252 | 848 |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
849 orthanc_->GetJsonAsync(uri, |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
850 new DeprecatedCallable<OrthancSlicesLoader, |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
851 OrthancApiClient::JsonResponseReadyMessage> |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
852 (GetSharedObserver(), &OrthancSlicesLoader::ParseSliceImageJpeg), |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
853 new DeprecatedCallable<OrthancSlicesLoader, |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
854 IWebService::HttpRequestErrorMessage> |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
855 (GetSharedObserver(), &OrthancSlicesLoader::OnSliceImageError), |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
856 Operation::DownloadSliceImage( |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
857 static_cast<unsigned int>(index), slice, quality)); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
858 } |
252 | 859 |
860 | |
861 | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
862 void OrthancSlicesLoader::ScheduleLoadSliceImage(size_t index, |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
863 SliceImageQuality quality) |
73 | 864 { |
865 if (state_ != State_GeometryReady) | |
866 { | |
867 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
868 } | |
252 | 869 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
870 const Slice& slice = GetSlice(index); |
252 | 871 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
872 if (slice.HasOrthancDecoding()) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
873 { |
257 | 874 switch (quality) |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
875 { |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
876 case SliceImageQuality_FullPng: |
378 | 877 ScheduleSliceImagePng(slice, index); |
878 break; | |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
879 case SliceImageQuality_FullPam: |
378 | 880 ScheduleSliceImagePam(slice, index); |
881 break; | |
882 default: | |
883 ScheduleSliceImageJpeg(slice, index, quality); | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
884 } |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
885 } |
73 | 886 else |
887 { | |
252 | 888 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
889 boost::lexical_cast<std::string>(slice.GetFrame()) + "/raw.gz"); |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
890 orthanc_->GetBinaryAsync(uri, IWebService::HttpHeaders(), |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
891 new DeprecatedCallable<OrthancSlicesLoader, |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
892 OrthancApiClient::BinaryResponseReadyMessage> |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
893 (GetSharedObserver(), &OrthancSlicesLoader::ParseSliceRawImage), |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
894 new DeprecatedCallable<OrthancSlicesLoader, |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
895 IWebService::HttpRequestErrorMessage> |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
896 (GetSharedObserver(), &OrthancSlicesLoader::OnSliceImageError), |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
897 Operation::DownloadSliceRawImage( |
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
898 static_cast<unsigned int>(index), slice)); |
73 | 899 } |
900 } | |
901 } |