Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/OrthancSlicesLoader.cpp @ 258:e5a9b3d03478 am-2
first very basic version of SmartLoader
author | am@osimis.io |
---|---|
date | Tue, 10 Jul 2018 14:48:13 +0200 |
parents | 9afafb192180 |
children | c9cf95b49a86 |
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 | |
135
e2fe9352f240
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
128
diff
changeset
|
5 * Copyright (C) 2017-2018 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 | |
24 #include "MessagingToolbox.h" | |
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 |
73 | 71 namespace OrthancStone |
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_; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
79 const Slice* slice_; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
80 std::string instanceId_; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
81 SliceImageQuality quality_; |
252 | 82 |
73 | 83 Operation(Mode mode) : |
84 mode_(mode) | |
85 { | |
86 } | |
252 | 87 |
73 | 88 public: |
89 Mode GetMode() const | |
90 { | |
91 return mode_; | |
92 } | |
252 | 93 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
94 SliceImageQuality GetQuality() const |
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 } |
252 | 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 } | |
252 | 107 |
73 | 108 const Slice& GetSlice() const |
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 } | |
252 | 115 |
73 | 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 } | |
252 | 128 |
73 | 129 static Operation* DownloadSeriesGeometry() |
130 { | |
131 return new Operation(Mode_SeriesGeometry); | |
132 } | |
252 | 133 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
134 static Operation* DownloadInstanceGeometry(const std::string& instanceId) |
73 | 135 { |
136 std::auto_ptr<Operation> operation(new Operation(Mode_InstanceGeometry)); | |
137 operation->instanceId_ = instanceId; | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
138 return operation.release(); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
139 } |
252 | 140 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
141 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
|
142 unsigned int frame) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
143 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
144 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
|
145 operation->instanceId_ = instanceId; |
73 | 146 operation->frame_ = frame; |
147 return operation.release(); | |
148 } | |
252 | 149 |
73 | 150 static Operation* DownloadSliceImage(unsigned int sliceIndex, |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
151 const Slice& slice, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
152 SliceImageQuality quality) |
73 | 153 { |
154 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadImage)); | |
155 tmp->sliceIndex_ = sliceIndex; | |
156 tmp->slice_ = &slice; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
157 tmp->quality_ = quality; |
73 | 158 return tmp.release(); |
159 } | |
252 | 160 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
161 static Operation* DownloadSliceRawImage(unsigned int sliceIndex, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
162 const Slice& slice) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
163 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
164 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
|
165 tmp->sliceIndex_ = sliceIndex; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
166 tmp->slice_ = &slice; |
257 | 167 tmp->quality_ = SliceImageQuality_InternalRaw; |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
168 return tmp.release(); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
169 } |
257 | 170 |
171 static Operation* DownloadDicomFile(const Slice& slice) | |
172 { | |
173 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadDicomFile)); | |
174 tmp->slice_ = &slice; | |
175 return tmp.release(); | |
176 } | |
177 | |
73 | 178 }; |
179 | |
252 | 180 |
73 | 181 class OrthancSlicesLoader::WebCallback : public IWebService::ICallback |
182 { | |
183 private: | |
184 OrthancSlicesLoader& that_; | |
252 | 185 |
73 | 186 public: |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
187 WebCallback(MessageBroker& broker, OrthancSlicesLoader& that) : |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
188 IWebService::ICallback(broker), |
73 | 189 that_(that) |
190 { | |
191 } | |
252 | 192 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
193 virtual void OnHttpRequestSuccess(const std::string& uri, |
252 | 194 const void* answer, |
195 size_t answerSize, | |
196 Orthanc::IDynamicObject* payload) | |
73 | 197 { |
198 std::auto_ptr<Operation> operation(dynamic_cast<Operation*>(payload)); | |
252 | 199 |
73 | 200 switch (operation->GetMode()) |
201 { | |
252 | 202 case Mode_SeriesGeometry: |
203 that_.ParseSeriesGeometry(answer, answerSize); | |
204 break; | |
205 | |
206 case Mode_InstanceGeometry: | |
207 that_.ParseInstanceGeometry(operation->GetInstanceId(), answer, answerSize); | |
208 break; | |
209 | |
210 case Mode_FrameGeometry: | |
211 that_.ParseFrameGeometry(operation->GetInstanceId(), | |
212 operation->GetFrame(), answer, answerSize); | |
213 break; | |
214 | |
215 case Mode_LoadImage: | |
216 switch (operation->GetQuality()) | |
217 { | |
257 | 218 case SliceImageQuality_FullPng: |
252 | 219 that_.ParseSliceImagePng(*operation, answer, answerSize); |
73 | 220 break; |
257 | 221 case SliceImageQuality_FullPam: |
222 that_.ParseSliceImagePam(*operation, answer, answerSize); | |
223 break; | |
224 | |
252 | 225 case SliceImageQuality_Jpeg50: |
226 case SliceImageQuality_Jpeg90: | |
227 case SliceImageQuality_Jpeg95: | |
228 that_.ParseSliceImageJpeg(*operation, answer, answerSize); | |
73 | 229 break; |
230 | |
231 default: | |
232 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
252 | 233 } |
234 | |
235 break; | |
236 | |
237 case Mode_LoadRawImage: | |
238 that_.ParseSliceRawImage(*operation, answer, answerSize); | |
239 break; | |
240 | |
241 default: | |
242 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
73 | 243 } |
252 | 244 } |
245 | |
246 virtual void OnHttpRequestError(const std::string& uri, | |
247 Orthanc::IDynamicObject* payload) | |
248 { | |
249 std::auto_ptr<Operation> operation(dynamic_cast<Operation*>(payload)); | |
250 LOG(ERROR) << "Cannot download " << uri; | |
251 | |
252 switch (operation->GetMode()) | |
253 { | |
254 case Mode_FrameGeometry: | |
255 case Mode_SeriesGeometry: | |
256 that_.userCallback_.OnSliceGeometryError(that_); | |
257 that_.state_ = State_Error; | |
258 break; | |
259 | |
260 case Mode_LoadImage: | |
261 that_.userCallback_.OnSliceImageError(that_, operation->GetSliceIndex(), | |
262 operation->GetSlice(), | |
263 operation->GetQuality()); | |
264 break; | |
265 | |
266 default: | |
267 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
268 } | |
269 } | |
73 | 270 }; |
252 | 271 |
272 void OrthancSlicesLoader::ISliceLoaderObserver::HandleMessage(IObservable& from, const IMessage& message) | |
273 { | |
274 switch (message.GetType()) | |
275 { | |
276 case MessageType_SliceGeometryReady: | |
277 OnSliceGeometryReady(dynamic_cast<OrthancSlicesLoader&>(from)); | |
278 break; | |
279 case MessageType_SliceGeometryError: | |
280 OnSliceGeometryError(dynamic_cast<OrthancSlicesLoader&>(from)); | |
281 break; | |
282 case MessageType_SliceImageReady: | |
283 { | |
284 const SliceImageReadyMessage& msg = dynamic_cast<const SliceImageReadyMessage&>(message); | |
285 OnSliceImageReady(dynamic_cast<OrthancSlicesLoader&>(from), | |
286 msg.sliceIndex_, | |
287 msg.slice_, | |
288 msg.image_, | |
289 msg.effectiveQuality_); | |
290 }; break; | |
291 case MessageType_SliceImageError: | |
292 { | |
293 const SliceImageErrorMessage& msg = dynamic_cast<const SliceImageErrorMessage&>(message); | |
294 OnSliceImageError(dynamic_cast<OrthancSlicesLoader&>(from), | |
295 msg.sliceIndex_, | |
296 msg.slice_, | |
297 msg.effectiveQuality_); | |
298 }; break; | |
299 default: | |
300 VLOG("unhandled message type" << message.GetType()); | |
301 } | |
302 } | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
303 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
304 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
305 void OrthancSlicesLoader::NotifySliceImageSuccess(const Operation& operation, |
99 | 306 std::auto_ptr<Orthanc::ImageAccessor>& image) const |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
307 { |
99 | 308 if (image.get() == NULL) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
309 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
310 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
311 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
312 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
313 { |
252 | 314 userCallback_.OnSliceImageReady |
315 (*this, operation.GetSliceIndex(), operation.GetSlice(), image, operation.GetQuality()); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
316 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
317 } |
252 | 318 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
319 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
320 void OrthancSlicesLoader::NotifySliceImageError(const Operation& operation) const |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
321 { |
252 | 322 userCallback_.OnSliceImageError |
323 (*this, operation.GetSliceIndex(), operation.GetSlice(), operation.GetQuality()); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
324 } |
252 | 325 |
326 | |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
327 void OrthancSlicesLoader::SortAndFinalizeSlices() |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
328 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
329 bool ok = false; |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
330 |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
331 if (slices_.GetSliceCount() > 0) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
332 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
333 Vector normal; |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
334 if (slices_.SelectNormal(normal)) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
335 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
336 slices_.FilterNormal(normal); |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
337 slices_.SetNormal(normal); |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
338 slices_.Sort(); |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
339 ok = true; |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
340 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
341 } |
252 | 342 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
343 state_ = State_GeometryReady; |
252 | 344 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
345 if (ok) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
346 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
347 LOG(INFO) << "Loaded a series with " << slices_.GetSliceCount() << " slice(s)"; |
252 | 348 userCallback_.OnSliceGeometryReady(*this); |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
349 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
350 else |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
351 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
352 LOG(ERROR) << "This series is empty"; |
252 | 353 userCallback_.OnSliceGeometryError(*this); |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
354 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
355 } |
252 | 356 |
73 | 357 |
358 void OrthancSlicesLoader::ParseSeriesGeometry(const void* answer, | |
359 size_t size) | |
360 { | |
361 Json::Value series; | |
362 if (!MessagingToolbox::ParseJson(series, answer, size) || | |
363 series.type() != Json::objectValue) | |
364 { | |
252 | 365 userCallback_.OnSliceGeometryError(*this); |
73 | 366 return; |
367 } | |
252 | 368 |
73 | 369 Json::Value::Members instances = series.getMemberNames(); |
252 | 370 |
73 | 371 slices_.Reserve(instances.size()); |
252 | 372 |
73 | 373 for (size_t i = 0; i < instances.size(); i++) |
374 { | |
375 OrthancPlugins::FullOrthancDataset dataset(series[instances[i]]); | |
252 | 376 |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
377 Orthanc::DicomMap dicom; |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
378 MessagingToolbox::ConvertDataset(dicom, dataset); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
379 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
380 unsigned int frames; |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
381 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
|
382 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
383 frames = 1; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
384 } |
252 | 385 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
386 for (unsigned int frame = 0; frame < frames; frame++) |
73 | 387 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
388 std::auto_ptr<Slice> slice(new Slice); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
389 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
|
390 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
391 slices_.AddSlice(slice.release()); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
392 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
393 else |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
394 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
395 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
|
396 } |
73 | 397 } |
398 } | |
252 | 399 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
400 SortAndFinalizeSlices(); |
73 | 401 } |
252 | 402 |
403 | |
73 | 404 void OrthancSlicesLoader::ParseInstanceGeometry(const std::string& instanceId, |
405 const void* answer, | |
406 size_t size) | |
407 { | |
408 Json::Value tags; | |
409 if (!MessagingToolbox::ParseJson(tags, answer, size) || | |
410 tags.type() != Json::objectValue) | |
411 { | |
252 | 412 userCallback_.OnSliceGeometryError(*this); |
73 | 413 return; |
414 } | |
252 | 415 |
73 | 416 OrthancPlugins::FullOrthancDataset dataset(tags); |
252 | 417 |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
418 Orthanc::DicomMap dicom; |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
419 MessagingToolbox::ConvertDataset(dicom, dataset); |
252 | 420 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
421 unsigned int frames; |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
422 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
|
423 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
424 frames = 1; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
425 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
426 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
427 LOG(INFO) << "Instance " << instanceId << " contains " << frames << " frame(s)"; |
252 | 428 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
429 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
|
430 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
431 std::auto_ptr<Slice> slice(new Slice); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
432 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
|
433 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
434 slices_.AddSlice(slice.release()); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
435 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
436 else |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
437 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
438 LOG(WARNING) << "Skipping invalid multi-frame instance " << instanceId; |
252 | 439 userCallback_.OnSliceGeometryError(*this); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
440 return; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
441 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
442 } |
252 | 443 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
444 SortAndFinalizeSlices(); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
445 } |
252 | 446 |
447 | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
448 void OrthancSlicesLoader::ParseFrameGeometry(const std::string& instanceId, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
449 unsigned int frame, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
450 const void* answer, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
451 size_t size) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
452 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
453 Json::Value tags; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
454 if (!MessagingToolbox::ParseJson(tags, answer, size) || |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
455 tags.type() != Json::objectValue) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
456 { |
252 | 457 userCallback_.OnSliceGeometryError(*this); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
458 return; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
459 } |
252 | 460 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
461 OrthancPlugins::FullOrthancDataset dataset(tags); |
252 | 462 |
73 | 463 state_ = State_GeometryReady; |
252 | 464 |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
465 Orthanc::DicomMap dicom; |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
466 MessagingToolbox::ConvertDataset(dicom, dataset); |
252 | 467 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
468 std::auto_ptr<Slice> slice(new Slice); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
469 if (slice->ParseOrthancFrame(dicom, instanceId, frame)) |
73 | 470 { |
471 LOG(INFO) << "Loaded instance " << instanceId; | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
472 slices_.AddSlice(slice.release()); |
252 | 473 userCallback_.OnSliceGeometryReady(*this); |
73 | 474 } |
475 else | |
476 { | |
477 LOG(WARNING) << "Skipping invalid instance " << instanceId; | |
252 | 478 userCallback_.OnSliceGeometryError(*this); |
73 | 479 } |
480 } | |
252 | 481 |
482 | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
483 void OrthancSlicesLoader::ParseSliceImagePng(const Operation& operation, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
484 const void* answer, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
485 size_t size) |
73 | 486 { |
99 | 487 std::auto_ptr<Orthanc::ImageAccessor> image; |
252 | 488 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
489 try |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
490 { |
99 | 491 image.reset(new Orthanc::PngReader); |
492 dynamic_cast<Orthanc::PngReader&>(*image).ReadFromMemory(answer, size); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
493 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
494 catch (Orthanc::OrthancException&) |
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; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
498 } |
252 | 499 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
500 if (image->GetWidth() != operation.GetSlice().GetWidth() || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
501 image->GetHeight() != operation.GetSlice().GetHeight()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
502 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
503 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
504 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
505 } |
252 | 506 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
507 if (operation.GetSlice().GetConverter().GetExpectedPixelFormat() == |
73 | 508 Orthanc::PixelFormat_SignedGrayscale16) |
509 { | |
510 if (image->GetFormat() == Orthanc::PixelFormat_Grayscale16) | |
511 { | |
512 image->SetFormat(Orthanc::PixelFormat_SignedGrayscale16); | |
513 } | |
514 else | |
515 { | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
516 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
517 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
518 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
519 } |
252 | 520 |
99 | 521 NotifySliceImageSuccess(operation, image); |
252 | 522 } |
523 | |
257 | 524 void OrthancSlicesLoader::ParseSliceImagePam(const Operation& operation, |
525 const void* answer, | |
526 size_t size) | |
527 { | |
528 std::auto_ptr<Orthanc::ImageAccessor> image; | |
529 | |
530 try | |
531 { | |
532 image.reset(new Orthanc::PamReader); | |
533 dynamic_cast<Orthanc::PamReader&>(*image).ReadFromMemory(std::string(reinterpret_cast<const char*>(answer), size)); | |
534 } | |
535 catch (Orthanc::OrthancException&) | |
536 { | |
537 NotifySliceImageError(operation); | |
538 return; | |
539 } | |
540 | |
541 if (image->GetWidth() != operation.GetSlice().GetWidth() || | |
542 image->GetHeight() != operation.GetSlice().GetHeight()) | |
543 { | |
544 NotifySliceImageError(operation); | |
545 return; | |
546 } | |
547 | |
548 if (operation.GetSlice().GetConverter().GetExpectedPixelFormat() == | |
549 Orthanc::PixelFormat_SignedGrayscale16) | |
550 { | |
551 if (image->GetFormat() == Orthanc::PixelFormat_Grayscale16) | |
552 { | |
553 image->SetFormat(Orthanc::PixelFormat_SignedGrayscale16); | |
554 } | |
555 else | |
556 { | |
557 NotifySliceImageError(operation); | |
558 return; | |
559 } | |
560 } | |
561 | |
562 NotifySliceImageSuccess(operation, image); | |
563 } | |
564 | |
565 | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
566 void OrthancSlicesLoader::ParseSliceImageJpeg(const Operation& operation, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
567 const void* answer, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
568 size_t size) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
569 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
570 Json::Value encoded; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
571 if (!MessagingToolbox::ParseJson(encoded, answer, size) || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
572 encoded.type() != Json::objectValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
573 !encoded.isMember("Orthanc") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
574 encoded["Orthanc"].type() != Json::objectValue) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
575 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
576 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
577 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
578 } |
252 | 579 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
580 Json::Value& info = encoded["Orthanc"]; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
581 if (!info.isMember("PixelData") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
582 !info.isMember("Stretched") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
583 !info.isMember("Compression") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
584 info["Compression"].type() != Json::stringValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
585 info["PixelData"].type() != Json::stringValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
586 info["Stretched"].type() != Json::booleanValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
587 info["Compression"].asString() != "Jpeg") |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
588 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
589 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
590 return; |
94 | 591 } |
252 | 592 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
593 bool isSigned = false; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
594 bool isStretched = info["Stretched"].asBool(); |
252 | 595 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
596 if (info.isMember("IsSigned")) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
597 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
598 if (info["IsSigned"].type() != Json::booleanValue) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
599 { |
94 | 600 NotifySliceImageError(operation); |
601 return; | |
252 | 602 } |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
603 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
604 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
605 isSigned = info["IsSigned"].asBool(); |
73 | 606 } |
607 } | |
252 | 608 |
99 | 609 std::auto_ptr<Orthanc::ImageAccessor> reader; |
252 | 610 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
611 { |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
612 std::string jpeg; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
613 //Orthanc::Toolbox::DecodeBase64(jpeg, info["PixelData"].asString()); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
614 jpeg = base64_decode(info["PixelData"].asString()); |
252 | 615 |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
616 try |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
617 { |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
618 reader.reset(new Orthanc::JpegReader); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
619 dynamic_cast<Orthanc::JpegReader&>(*reader).ReadFromMemory(jpeg); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
620 } |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
621 catch (Orthanc::OrthancException&) |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
622 { |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
623 NotifySliceImageError(operation); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
624 return; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
625 } |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
626 } |
252 | 627 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
628 Orthanc::PixelFormat expectedFormat = |
252 | 629 operation.GetSlice().GetConverter().GetExpectedPixelFormat(); |
630 | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
631 if (reader->GetFormat() == Orthanc::PixelFormat_RGB24) // This is a color image |
73 | 632 { |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
633 if (expectedFormat != Orthanc::PixelFormat_RGB24) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
634 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
635 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
636 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
637 } |
252 | 638 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
639 if (isSigned || isStretched) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
640 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
641 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
642 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
643 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
644 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
645 { |
99 | 646 NotifySliceImageSuccess(operation, reader); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
647 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
648 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
649 } |
252 | 650 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
651 if (reader->GetFormat() != Orthanc::PixelFormat_Grayscale8) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
652 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
653 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
654 return; |
73 | 655 } |
252 | 656 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
657 if (!isStretched) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
658 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
659 if (expectedFormat != reader->GetFormat()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
660 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
661 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
662 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
663 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
664 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
665 { |
99 | 666 NotifySliceImageSuccess(operation, reader); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
667 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
668 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
669 } |
252 | 670 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
671 int32_t stretchLow = 0; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
672 int32_t stretchHigh = 0; |
252 | 673 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
674 if (!info.isMember("StretchLow") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
675 !info.isMember("StretchHigh") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
676 info["StretchLow"].type() != Json::intValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
677 info["StretchHigh"].type() != Json::intValue) |
73 | 678 { |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
679 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
680 return; |
73 | 681 } |
252 | 682 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
683 stretchLow = info["StretchLow"].asInt(); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
684 stretchHigh = info["StretchHigh"].asInt(); |
252 | 685 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
686 if (stretchLow < -32768 || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
687 stretchHigh > 65535 || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
688 (stretchLow < 0 && stretchHigh > 32767)) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
689 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
690 // 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
|
691 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
692 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
693 } |
252 | 694 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
695 // Decode a grayscale JPEG 8bpp image coming from the Web viewer |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
696 std::auto_ptr<Orthanc::ImageAccessor> image |
252 | 697 (new Orthanc::Image(expectedFormat, reader->GetWidth(), reader->GetHeight(), false)); |
698 | |
203 | 699 Orthanc::ImageProcessing::Convert(*image, *reader); |
700 reader.reset(NULL); | |
252 | 701 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
702 float scaling = static_cast<float>(stretchHigh - stretchLow) / 255.0f; |
252 | 703 |
203 | 704 if (!LinearAlgebra::IsCloseToZero(scaling)) |
705 { | |
706 float offset = static_cast<float>(stretchLow) / scaling; | |
707 Orthanc::ImageProcessing::ShiftScale(*image, offset, scaling, true); | |
708 } | |
252 | 709 |
99 | 710 NotifySliceImageSuccess(operation, image); |
73 | 711 } |
252 | 712 |
713 | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
714 class StringImage : |
252 | 715 public Orthanc::ImageAccessor, |
716 public boost::noncopyable | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
717 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
718 private: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
719 std::string buffer_; |
73 | 720 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
721 public: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
722 StringImage(Orthanc::PixelFormat format, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
723 unsigned int width, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
724 unsigned int height, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
725 std::string& buffer) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
726 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
727 if (buffer.size() != Orthanc::GetBytesPerPixel(format) * width * height) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
728 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
729 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
730 } |
252 | 731 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
732 buffer_.swap(buffer); // The source buffer is now empty |
252 | 733 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
734 void* data = (buffer_.empty() ? NULL : &buffer_[0]); |
252 | 735 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
736 AssignWritable(format, width, height, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
737 Orthanc::GetBytesPerPixel(format) * width, data); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
738 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
739 }; |
252 | 740 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
741 void OrthancSlicesLoader::ParseSliceRawImage(const Operation& operation, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
742 const void* answer, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
743 size_t size) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
744 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
745 Orthanc::GzipCompressor compressor; |
252 | 746 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
747 std::string raw; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
748 compressor.Uncompress(raw, answer, size); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
749 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
750 const Orthanc::DicomImageInformation& info = operation.GetSlice().GetImageInformation(); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
751 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
752 if (info.GetBitsAllocated() == 32 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
753 info.GetBitsStored() == 32 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
754 info.GetHighBit() == 31 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
755 info.GetChannelCount() == 1 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
756 !info.IsSigned() && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
757 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
758 raw.size() == info.GetWidth() * info.GetHeight() * 4) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
759 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
760 // 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
|
761 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
762 std::auto_ptr<Orthanc::ImageAccessor> image |
252 | 763 (new StringImage(Orthanc::PixelFormat_Grayscale32, info.GetWidth(), |
764 info.GetHeight(), raw)); | |
765 | |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
766 // TODO - Only for big endian |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
767 for (unsigned int y = 0; y < image->GetHeight(); y++) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
768 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
769 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
|
770 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
|
771 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
772 *p = le32toh(*p); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
773 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
774 } |
252 | 775 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
776 NotifySliceImageSuccess(operation, image); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
777 } |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
778 else if (info.GetBitsAllocated() == 16 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
779 info.GetBitsStored() == 16 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
780 info.GetHighBit() == 15 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
781 info.GetChannelCount() == 1 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
782 !info.IsSigned() && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
783 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
784 raw.size() == info.GetWidth() * info.GetHeight() * 2) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
785 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
786 std::auto_ptr<Orthanc::ImageAccessor> image |
252 | 787 (new StringImage(Orthanc::PixelFormat_Grayscale16, info.GetWidth(), |
788 info.GetHeight(), raw)); | |
789 | |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
790 // TODO - Big endian ? |
252 | 791 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
792 NotifySliceImageSuccess(operation, image); |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
793 } |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
794 else |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
795 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
796 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
797 } |
252 | 798 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
799 } |
252 | 800 |
801 | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
802 OrthancSlicesLoader::OrthancSlicesLoader(MessageBroker& broker, |
252 | 803 ISliceLoaderObserver& callback, |
73 | 804 IWebService& orthanc) : |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
805 webCallback_(new WebCallback(broker, *this)), |
73 | 806 userCallback_(callback), |
807 orthanc_(orthanc), | |
808 state_(State_Initialization) | |
809 { | |
810 } | |
252 | 811 |
73 | 812 |
813 void OrthancSlicesLoader::ScheduleLoadSeries(const std::string& seriesId) | |
814 { | |
815 if (state_ != State_Initialization) | |
816 { | |
817 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
818 } | |
819 else | |
820 { | |
821 state_ = State_LoadingGeometry; | |
822 std::string uri = "/series/" + seriesId + "/instances-tags"; | |
257 | 823 orthanc_.ScheduleGetRequest(*webCallback_, uri, IWebService::Headers(), Operation::DownloadSeriesGeometry()); |
73 | 824 } |
825 } | |
252 | 826 |
827 | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
828 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
|
829 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
830 if (state_ != State_Initialization) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
831 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
832 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
833 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
834 else |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
835 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
836 state_ = State_LoadingGeometry; |
252 | 837 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
838 // 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
|
839 // mandatory to read RT DOSE, but is too long to be returned by default |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
840 std::string uri = "/instances/" + instanceId + "/tags?ignore-length=3004-000c"; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
841 orthanc_.ScheduleGetRequest |
257 | 842 (*webCallback_, uri, IWebService::Headers(), Operation::DownloadInstanceGeometry(instanceId)); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
843 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
844 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
845 |
252 | 846 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
847 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
|
848 unsigned int frame) |
73 | 849 { |
850 if (state_ != State_Initialization) | |
851 { | |
852 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
853 } | |
854 else | |
855 { | |
856 state_ = State_LoadingGeometry; | |
857 std::string uri = "/instances/" + instanceId + "/tags"; | |
858 orthanc_.ScheduleGetRequest | |
257 | 859 (*webCallback_, uri, IWebService::Headers(), Operation::DownloadFrameGeometry(instanceId, frame)); |
73 | 860 } |
861 } | |
862 | |
252 | 863 |
77 | 864 bool OrthancSlicesLoader::IsGeometryReady() const |
865 { | |
866 return state_ == State_GeometryReady; | |
867 } | |
252 | 868 |
869 | |
73 | 870 size_t OrthancSlicesLoader::GetSliceCount() const |
871 { | |
872 if (state_ != State_GeometryReady) | |
873 { | |
874 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
875 } | |
252 | 876 |
73 | 877 return slices_.GetSliceCount(); |
878 } | |
252 | 879 |
73 | 880 |
881 const Slice& OrthancSlicesLoader::GetSlice(size_t index) const | |
882 { | |
883 if (state_ != State_GeometryReady) | |
884 { | |
885 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
886 } | |
252 | 887 |
73 | 888 return slices_.GetSlice(index); |
889 } | |
890 | |
252 | 891 |
77 | 892 bool OrthancSlicesLoader::LookupSlice(size_t& index, |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
893 const CoordinateSystem3D& plane) const |
77 | 894 { |
895 if (state_ != State_GeometryReady) | |
896 { | |
897 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
898 } | |
252 | 899 |
77 | 900 return slices_.LookupSlice(index, plane); |
901 } | |
902 | |
252 | 903 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
904 void OrthancSlicesLoader::ScheduleSliceImagePng(const Slice& slice, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
905 size_t index) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
906 { |
252 | 907 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
908 boost::lexical_cast<std::string>(slice.GetFrame())); |
252 | 909 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
910 switch (slice.GetConverter().GetExpectedPixelFormat()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
911 { |
252 | 912 case Orthanc::PixelFormat_RGB24: |
913 uri += "/preview"; | |
914 break; | |
915 | |
916 case Orthanc::PixelFormat_Grayscale16: | |
917 uri += "/image-uint16"; | |
918 break; | |
919 | |
920 case Orthanc::PixelFormat_SignedGrayscale16: | |
921 uri += "/image-int16"; | |
922 break; | |
923 | |
924 default: | |
925 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
926 } |
252 | 927 |
257 | 928 IWebService::Headers headers; |
929 headers["Accept"] = "image/png"; | |
930 orthanc_.ScheduleGetRequest(*webCallback_, uri, IWebService::Headers(), | |
931 Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPng)); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
932 } |
252 | 933 |
257 | 934 void OrthancSlicesLoader::ScheduleSliceImagePam(const Slice& slice, |
935 size_t index) | |
936 { | |
937 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + | |
938 boost::lexical_cast<std::string>(slice.GetFrame())); | |
939 | |
940 switch (slice.GetConverter().GetExpectedPixelFormat()) | |
941 { | |
942 case Orthanc::PixelFormat_RGB24: | |
943 uri += "/preview"; | |
944 break; | |
945 | |
946 case Orthanc::PixelFormat_Grayscale16: | |
947 uri += "/image-uint16"; | |
948 break; | |
949 | |
950 case Orthanc::PixelFormat_SignedGrayscale16: | |
951 uri += "/image-int16"; | |
952 break; | |
953 | |
954 default: | |
955 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
956 } | |
957 | |
958 IWebService::Headers headers; | |
959 headers["Accept"] = "image/x-portable-arbitrarymap"; | |
960 orthanc_.ScheduleGetRequest(*webCallback_, uri, headers, | |
961 Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPam)); | |
962 } | |
963 | |
964 | |
252 | 965 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
966 void OrthancSlicesLoader::ScheduleSliceImageJpeg(const Slice& slice, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
967 size_t index, |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
968 SliceImageQuality quality) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
969 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
970 unsigned int value; |
252 | 971 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
972 switch (quality) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
973 { |
252 | 974 case SliceImageQuality_Jpeg50: |
975 value = 50; | |
976 break; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
977 |
252 | 978 case SliceImageQuality_Jpeg90: |
979 value = 90; | |
980 break; | |
981 | |
982 case SliceImageQuality_Jpeg95: | |
983 value = 95; | |
984 break; | |
985 | |
986 default: | |
987 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
988 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
989 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
990 // This requires the official Web viewer plugin to be installed! |
252 | 991 std::string uri = ("/web-viewer/instances/jpeg" + |
992 boost::lexical_cast<std::string>(value) + | |
993 "-" + slice.GetOrthancInstanceId() + "_" + | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
994 boost::lexical_cast<std::string>(slice.GetFrame())); |
252 | 995 |
257 | 996 orthanc_.ScheduleGetRequest(*webCallback_, uri, IWebService::Headers(), |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
997 Operation::DownloadSliceImage(index, slice, quality)); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
998 } |
252 | 999 |
1000 | |
1001 | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
1002 void OrthancSlicesLoader::ScheduleLoadSliceImage(size_t index, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
1003 SliceImageQuality quality) |
73 | 1004 { |
1005 if (state_ != State_GeometryReady) | |
1006 { | |
1007 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
1008 } | |
252 | 1009 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
1010 const Slice& slice = GetSlice(index); |
252 | 1011 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
1012 if (slice.HasOrthancDecoding()) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
1013 { |
257 | 1014 switch (quality) |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
1015 { |
257 | 1016 case SliceImageQuality_FullPng: |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
1017 ScheduleSliceImagePng(slice, index); |
257 | 1018 break; |
1019 case SliceImageQuality_FullPam: | |
1020 ScheduleSliceImagePam(slice, index); | |
1021 break; | |
1022 default: | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
1023 ScheduleSliceImageJpeg(slice, index, quality); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
1024 } |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
1025 } |
73 | 1026 else |
1027 { | |
252 | 1028 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
|
1029 boost::lexical_cast<std::string>(slice.GetFrame()) + "/raw.gz"); |
257 | 1030 orthanc_.ScheduleGetRequest(*webCallback_, uri, IWebService::Headers(), |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
1031 Operation::DownloadSliceRawImage(index, slice)); |
73 | 1032 } |
1033 } | |
1034 } |