Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/OrthancSlicesLoader.cpp @ 598:a806abb497b8
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 26 Apr 2019 17:57:57 +0200 |
parents | b70e9be013e4 |
children | 42dadae61fa9 |
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 | |
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_; |
73 | 82 |
83 Operation(Mode mode) : | |
84 mode_(mode) | |
85 { | |
86 } | |
87 | |
88 public: | |
89 Mode GetMode() const | |
90 { | |
91 return mode_; | |
92 } | |
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 } |
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 | |
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 } | |
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, | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
146 const Slice& slice, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
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, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
157 const Slice& slice) |
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; |
257 | 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 |
257 | 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()); |
378 | 180 EmitMessage(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()); |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
257
diff
changeset
|
188 EmitMessage(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 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
194 bool ok = false; |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
195 |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
196 if (slices_.GetSliceCount() > 0) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
197 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
198 Vector normal; |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
199 if (slices_.SelectNormal(normal)) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
200 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
201 slices_.FilterNormal(normal); |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
202 slices_.SetNormal(normal); |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
203 slices_.Sort(); |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
204 ok = true; |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
205 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
206 } |
252 | 207 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
208 state_ = State_GeometryReady; |
252 | 209 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
210 if (ok) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
211 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
212 LOG(INFO) << "Loaded a series with " << slices_.GetSliceCount() << " slice(s)"; |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
268
diff
changeset
|
213 EmitMessage(SliceGeometryReadyMessage(*this)); |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
214 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
215 else |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
216 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
217 LOG(ERROR) << "This series is empty"; |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
268
diff
changeset
|
218 EmitMessage(SliceGeometryErrorMessage(*this)); |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
219 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
220 } |
252 | 221 |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
222 void OrthancSlicesLoader::OnGeometryError(const IWebService::HttpRequestErrorMessage& message) |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
223 { |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
224 EmitMessage(SliceGeometryErrorMessage(*this)); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
225 state_ = State_Error; |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
226 } |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
227 |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
228 void OrthancSlicesLoader::OnSliceImageError(const IWebService::HttpRequestErrorMessage& message) |
73 | 229 { |
377 | 230 NotifySliceImageError(dynamic_cast<const Operation&>(message.GetPayload())); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
231 state_ = State_Error; |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
232 } |
73 | 233 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
234 void OrthancSlicesLoader::ParseSeriesGeometry(const OrthancApiClient::JsonResponseReadyMessage& message) |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
235 { |
377 | 236 const Json::Value& series = message.GetJson(); |
73 | 237 Json::Value::Members instances = series.getMemberNames(); |
252 | 238 |
73 | 239 slices_.Reserve(instances.size()); |
252 | 240 |
73 | 241 for (size_t i = 0; i < instances.size(); i++) |
242 { | |
243 OrthancPlugins::FullOrthancDataset dataset(series[instances[i]]); | |
252 | 244 |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
245 Orthanc::DicomMap dicom; |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
246 MessagingToolbox::ConvertDataset(dicom, dataset); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
247 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
248 unsigned int frames; |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
249 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
|
250 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
251 frames = 1; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
252 } |
252 | 253 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
254 for (unsigned int frame = 0; frame < frames; frame++) |
73 | 255 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
256 std::auto_ptr<Slice> slice(new Slice); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
257 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
|
258 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
259 slices_.AddSlice(slice.release()); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
260 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
261 else |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
262 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
263 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
|
264 } |
73 | 265 } |
266 } | |
252 | 267 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
268 SortAndFinalizeSlices(); |
73 | 269 } |
252 | 270 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
271 void OrthancSlicesLoader::ParseInstanceGeometry(const OrthancApiClient::JsonResponseReadyMessage& message) |
73 | 272 { |
377 | 273 const Json::Value& tags = message.GetJson(); |
274 const std::string& instanceId = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()).GetInstanceId(); | |
73 | 275 |
276 OrthancPlugins::FullOrthancDataset dataset(tags); | |
252 | 277 |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
278 Orthanc::DicomMap dicom; |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
279 MessagingToolbox::ConvertDataset(dicom, dataset); |
252 | 280 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
281 unsigned int frames; |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
282 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
|
283 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
284 frames = 1; |
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 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
287 LOG(INFO) << "Instance " << instanceId << " contains " << frames << " frame(s)"; |
252 | 288 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
289 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
|
290 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
291 std::auto_ptr<Slice> slice(new Slice); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
292 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
|
293 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
294 slices_.AddSlice(slice.release()); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
295 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
296 else |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
297 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
298 LOG(WARNING) << "Skipping invalid multi-frame instance " << instanceId; |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
268
diff
changeset
|
299 EmitMessage(SliceGeometryErrorMessage(*this)); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
300 return; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
301 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
302 } |
252 | 303 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
304 SortAndFinalizeSlices(); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
305 } |
252 | 306 |
307 | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
308 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
|
309 { |
377 | 310 const Json::Value& tags = message.GetJson(); |
311 const std::string& instanceId = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()).GetInstanceId(); | |
312 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
|
313 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
314 OrthancPlugins::FullOrthancDataset dataset(tags); |
252 | 315 |
73 | 316 state_ = State_GeometryReady; |
252 | 317 |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
318 Orthanc::DicomMap dicom; |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
319 MessagingToolbox::ConvertDataset(dicom, dataset); |
252 | 320 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
321 std::auto_ptr<Slice> slice(new Slice); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
322 if (slice->ParseOrthancFrame(dicom, instanceId, frame)) |
73 | 323 { |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
257
diff
changeset
|
324 LOG(INFO) << "Loaded instance geometry " << instanceId; |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
325 slices_.AddSlice(slice.release()); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
326 EmitMessage(SliceGeometryReadyMessage(*this)); |
73 | 327 } |
328 else | |
329 { | |
330 LOG(WARNING) << "Skipping invalid instance " << instanceId; | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
268
diff
changeset
|
331 EmitMessage(SliceGeometryErrorMessage(*this)); |
73 | 332 } |
333 } | |
252 | 334 |
335 | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
336 void OrthancSlicesLoader::ParseSliceImagePng(const OrthancApiClient::BinaryResponseReadyMessage& message) |
73 | 337 { |
377 | 338 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()); |
378 | 339 std::auto_ptr<Orthanc::ImageAccessor> image; |
252 | 340 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
341 try |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
342 { |
99 | 343 image.reset(new Orthanc::PngReader); |
377 | 344 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
|
345 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
346 catch (Orthanc::OrthancException&) |
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 } |
252 | 351 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
352 if (image->GetWidth() != operation.GetSlice().GetWidth() || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
353 image->GetHeight() != operation.GetSlice().GetHeight()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
354 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
355 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
356 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
357 } |
73 | 358 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
359 if (operation.GetSlice().GetConverter().GetExpectedPixelFormat() == |
73 | 360 Orthanc::PixelFormat_SignedGrayscale16) |
361 { | |
362 if (image->GetFormat() == Orthanc::PixelFormat_Grayscale16) | |
363 { | |
364 image->SetFormat(Orthanc::PixelFormat_SignedGrayscale16); | |
365 } | |
366 else | |
367 { | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
368 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
369 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
370 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
371 } |
252 | 372 |
378 | 373 NotifySliceImageSuccess(operation, *image); |
252 | 374 } |
375 | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
376 void OrthancSlicesLoader::ParseSliceImagePam(const OrthancApiClient::BinaryResponseReadyMessage& message) |
73 | 377 { |
377 | 378 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()); |
378 | 379 std::auto_ptr<Orthanc::ImageAccessor> image; |
73 | 380 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
381 try |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
382 { |
257 | 383 image.reset(new Orthanc::PamReader); |
378 | 384 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
|
385 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
386 catch (Orthanc::OrthancException&) |
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 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
391 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
392 if (image->GetWidth() != operation.GetSlice().GetWidth() || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
393 image->GetHeight() != operation.GetSlice().GetHeight()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
394 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
395 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
396 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
397 } |
257 | 398 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
399 if (operation.GetSlice().GetConverter().GetExpectedPixelFormat() == |
73 | 400 Orthanc::PixelFormat_SignedGrayscale16) |
401 { | |
402 if (image->GetFormat() == Orthanc::PixelFormat_Grayscale16) | |
403 { | |
404 image->SetFormat(Orthanc::PixelFormat_SignedGrayscale16); | |
405 } | |
406 else | |
407 { | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
408 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
409 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
410 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
411 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
412 |
378 | 413 NotifySliceImageSuccess(operation, *image); |
257 | 414 } |
415 | |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
416 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
417 void OrthancSlicesLoader::ParseSliceImageJpeg(const OrthancApiClient::JsonResponseReadyMessage& message) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
418 { |
377 | 419 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
|
420 |
377 | 421 const Json::Value& encoded = message.GetJson(); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
422 if (encoded.type() != Json::objectValue || |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
423 !encoded.isMember("Orthanc") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
424 encoded["Orthanc"].type() != Json::objectValue) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
425 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
426 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
427 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
428 } |
252 | 429 |
377 | 430 const Json::Value& info = encoded["Orthanc"]; |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
431 if (!info.isMember("PixelData") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
432 !info.isMember("Stretched") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
433 !info.isMember("Compression") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
434 info["Compression"].type() != Json::stringValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
435 info["PixelData"].type() != Json::stringValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
436 info["Stretched"].type() != Json::booleanValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
437 info["Compression"].asString() != "Jpeg") |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
438 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
439 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
440 return; |
94 | 441 } |
252 | 442 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
443 bool isSigned = false; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
444 bool isStretched = info["Stretched"].asBool(); |
252 | 445 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
446 if (info.isMember("IsSigned")) |
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 if (info["IsSigned"].type() != Json::booleanValue) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
449 { |
94 | 450 NotifySliceImageError(operation); |
451 return; | |
252 | 452 } |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
453 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
454 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
455 isSigned = info["IsSigned"].asBool(); |
73 | 456 } |
457 } | |
252 | 458 |
378 | 459 std::auto_ptr<Orthanc::ImageAccessor> reader; |
252 | 460 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
461 { |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
462 std::string jpeg; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
463 //Orthanc::Toolbox::DecodeBase64(jpeg, info["PixelData"].asString()); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
464 jpeg = base64_decode(info["PixelData"].asString()); |
252 | 465 |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
466 try |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
467 { |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
468 reader.reset(new Orthanc::JpegReader); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
469 dynamic_cast<Orthanc::JpegReader&>(*reader).ReadFromMemory(jpeg); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
470 } |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
471 catch (Orthanc::OrthancException&) |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
472 { |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
473 NotifySliceImageError(operation); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
474 return; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
475 } |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
476 } |
252 | 477 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
478 Orthanc::PixelFormat expectedFormat = |
378 | 479 operation.GetSlice().GetConverter().GetExpectedPixelFormat(); |
252 | 480 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
481 if (reader->GetFormat() == Orthanc::PixelFormat_RGB24) // This is a color image |
73 | 482 { |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
483 if (expectedFormat != Orthanc::PixelFormat_RGB24) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
484 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
485 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
486 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
487 } |
252 | 488 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
489 if (isSigned || isStretched) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
490 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
491 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
492 return; |
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 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
495 { |
378 | 496 NotifySliceImageSuccess(operation, *reader); |
93
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 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
499 } |
252 | 500 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
501 if (reader->GetFormat() != Orthanc::PixelFormat_Grayscale8) |
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; |
73 | 505 } |
252 | 506 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
507 if (!isStretched) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
508 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
509 if (expectedFormat != reader->GetFormat()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
510 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
511 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
512 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
513 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
514 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
515 { |
378 | 516 NotifySliceImageSuccess(operation, *reader); |
93
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 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
521 int32_t stretchLow = 0; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
522 int32_t stretchHigh = 0; |
252 | 523 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
524 if (!info.isMember("StretchLow") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
525 !info.isMember("StretchHigh") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
526 info["StretchLow"].type() != Json::intValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
527 info["StretchHigh"].type() != Json::intValue) |
73 | 528 { |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
529 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
530 return; |
73 | 531 } |
252 | 532 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
533 stretchLow = info["StretchLow"].asInt(); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
534 stretchHigh = info["StretchHigh"].asInt(); |
252 | 535 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
536 if (stretchLow < -32768 || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
537 stretchHigh > 65535 || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
538 (stretchLow < 0 && stretchHigh > 32767)) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
539 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
540 // 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
|
541 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
542 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
543 } |
252 | 544 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
545 // Decode a grayscale JPEG 8bpp image coming from the Web viewer |
378 | 546 std::auto_ptr<Orthanc::ImageAccessor> image |
547 (new Orthanc::Image(expectedFormat, reader->GetWidth(), reader->GetHeight(), false)); | |
252 | 548 |
203 | 549 Orthanc::ImageProcessing::Convert(*image, *reader); |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
318
diff
changeset
|
550 reader.reset(); |
252 | 551 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
552 float scaling = static_cast<float>(stretchHigh - stretchLow) / 255.0f; |
252 | 553 |
203 | 554 if (!LinearAlgebra::IsCloseToZero(scaling)) |
555 { | |
556 float offset = static_cast<float>(stretchLow) / scaling; | |
557 Orthanc::ImageProcessing::ShiftScale(*image, offset, scaling, true); | |
558 } | |
252 | 559 |
378 | 560 NotifySliceImageSuccess(operation, *image); |
73 | 561 } |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
562 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
563 |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
564 class StringImage : public Orthanc::ImageAccessor |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
565 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
566 private: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
567 std::string buffer_; |
73 | 568 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
569 public: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
570 StringImage(Orthanc::PixelFormat format, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
571 unsigned int width, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
572 unsigned int height, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
573 std::string& buffer) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
574 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
575 if (buffer.size() != Orthanc::GetBytesPerPixel(format) * width * height) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
576 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
577 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
578 } |
252 | 579 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
580 buffer_.swap(buffer); // The source buffer is now empty |
252 | 581 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
582 void* data = (buffer_.empty() ? NULL : &buffer_[0]); |
252 | 583 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
584 AssignWritable(format, width, height, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
585 Orthanc::GetBytesPerPixel(format) * width, data); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
586 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
587 }; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
588 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
589 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
|
590 { |
377 | 591 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
|
592 Orthanc::GzipCompressor compressor; |
252 | 593 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
594 std::string raw; |
377 | 595 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
|
596 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
597 const Orthanc::DicomImageInformation& info = operation.GetSlice().GetImageInformation(); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
598 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
599 if (info.GetBitsAllocated() == 32 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
600 info.GetBitsStored() == 32 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
601 info.GetHighBit() == 31 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
602 info.GetChannelCount() == 1 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
603 !info.IsSigned() && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
604 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
605 raw.size() == info.GetWidth() * info.GetHeight() * 4) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
606 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
607 // 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
|
608 |
378 | 609 std::auto_ptr<Orthanc::ImageAccessor> image |
610 (new StringImage(Orthanc::PixelFormat_Grayscale32, info.GetWidth(), | |
611 info.GetHeight(), raw)); | |
252 | 612 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
613 // TODO - Only for big endian |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
614 for (unsigned int y = 0; y < image->GetHeight(); y++) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
615 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
616 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
|
617 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
|
618 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
619 *p = le32toh(*p); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
620 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
621 } |
252 | 622 |
378 | 623 NotifySliceImageSuccess(operation, *image); |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
624 } |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
625 else if (info.GetBitsAllocated() == 16 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
626 info.GetBitsStored() == 16 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
627 info.GetHighBit() == 15 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
628 info.GetChannelCount() == 1 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
629 !info.IsSigned() && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
630 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
631 raw.size() == info.GetWidth() * info.GetHeight() * 2) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
632 { |
378 | 633 std::auto_ptr<Orthanc::ImageAccessor> image |
634 (new StringImage(Orthanc::PixelFormat_Grayscale16, info.GetWidth(), | |
635 info.GetHeight(), raw)); | |
252 | 636 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
637 // TODO - Big endian ? |
252 | 638 |
378 | 639 NotifySliceImageSuccess(operation, *image); |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
640 } |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
641 else |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
642 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
643 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
644 } |
252 | 645 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
646 } |
252 | 647 |
648 | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
649 OrthancSlicesLoader::OrthancSlicesLoader(MessageBroker& broker, |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
650 OrthancApiClient& orthanc) : |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
257
diff
changeset
|
651 IObservable(broker), |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
652 IObserver(broker), |
73 | 653 orthanc_(orthanc), |
654 state_(State_Initialization) | |
655 { | |
656 } | |
252 | 657 |
73 | 658 |
659 void OrthancSlicesLoader::ScheduleLoadSeries(const std::string& seriesId) | |
660 { | |
661 if (state_ != State_Initialization) | |
662 { | |
663 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
664 } | |
665 else | |
666 { | |
667 state_ = State_LoadingGeometry; | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
668 orthanc_.GetJsonAsync("/series/" + seriesId + "/instances-tags", |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
669 new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSeriesGeometry), |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
670 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError), |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
671 NULL); |
73 | 672 } |
673 } | |
252 | 674 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
675 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
|
676 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
677 if (state_ != State_Initialization) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
678 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
679 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
680 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
681 else |
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 state_ = State_LoadingGeometry; |
252 | 684 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
685 // 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
|
686 // mandatory to read RT DOSE, but is too long to be returned by default |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
687 orthanc_.GetJsonAsync("/instances/" + instanceId + "/tags?ignore-length=3004-000c", |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
688 new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseInstanceGeometry), |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
689 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError), |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
690 Operation::DownloadInstanceGeometry(instanceId)); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
691 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
692 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
693 |
252 | 694 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
695 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
|
696 unsigned int frame) |
73 | 697 { |
698 if (state_ != State_Initialization) | |
699 { | |
700 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
701 } | |
702 else | |
703 { | |
704 state_ = State_LoadingGeometry; | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
705 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
706 orthanc_.GetJsonAsync("/instances/" + instanceId + "/tags", |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
707 new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseFrameGeometry), |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
708 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError), |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
709 Operation::DownloadFrameGeometry(instanceId, frame)); |
73 | 710 } |
711 } | |
712 | |
252 | 713 |
77 | 714 bool OrthancSlicesLoader::IsGeometryReady() const |
715 { | |
716 return state_ == State_GeometryReady; | |
717 } | |
252 | 718 |
719 | |
73 | 720 size_t OrthancSlicesLoader::GetSliceCount() const |
721 { | |
722 if (state_ != State_GeometryReady) | |
723 { | |
724 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
725 } | |
252 | 726 |
73 | 727 return slices_.GetSliceCount(); |
728 } | |
252 | 729 |
73 | 730 |
731 const Slice& OrthancSlicesLoader::GetSlice(size_t index) const | |
732 { | |
733 if (state_ != State_GeometryReady) | |
734 { | |
735 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
736 } | |
252 | 737 |
73 | 738 return slices_.GetSlice(index); |
739 } | |
740 | |
252 | 741 |
77 | 742 bool OrthancSlicesLoader::LookupSlice(size_t& index, |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
743 const CoordinateSystem3D& plane) const |
77 | 744 { |
745 if (state_ != State_GeometryReady) | |
746 { | |
747 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
748 } | |
252 | 749 |
77 | 750 return slices_.LookupSlice(index, plane); |
751 } | |
752 | |
252 | 753 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
754 void OrthancSlicesLoader::ScheduleSliceImagePng(const Slice& slice, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
755 size_t index) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
756 { |
252 | 757 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
758 boost::lexical_cast<std::string>(slice.GetFrame())); |
252 | 759 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
760 switch (slice.GetConverter().GetExpectedPixelFormat()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
761 { |
378 | 762 case Orthanc::PixelFormat_RGB24: |
763 uri += "/preview"; | |
764 break; | |
252 | 765 |
378 | 766 case Orthanc::PixelFormat_Grayscale16: |
767 uri += "/image-uint16"; | |
768 break; | |
252 | 769 |
378 | 770 case Orthanc::PixelFormat_SignedGrayscale16: |
771 uri += "/image-int16"; | |
772 break; | |
252 | 773 |
378 | 774 default: |
775 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
776 } |
252 | 777 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
778 orthanc_.GetBinaryAsync(uri, "image/png", |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
779 new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImagePng), |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
780 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
781 Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPng)); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
782 } |
252 | 783 |
257 | 784 void OrthancSlicesLoader::ScheduleSliceImagePam(const Slice& slice, |
785 size_t index) | |
786 { | |
787 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
788 boost::lexical_cast<std::string>(slice.GetFrame())); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
789 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
790 switch (slice.GetConverter().GetExpectedPixelFormat()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
791 { |
378 | 792 case Orthanc::PixelFormat_RGB24: |
793 uri += "/preview"; | |
794 break; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
795 |
378 | 796 case Orthanc::PixelFormat_Grayscale16: |
797 uri += "/image-uint16"; | |
798 break; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
799 |
378 | 800 case Orthanc::PixelFormat_SignedGrayscale16: |
801 uri += "/image-int16"; | |
802 break; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
803 |
378 | 804 default: |
805 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
806 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
807 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
808 orthanc_.GetBinaryAsync(uri, "image/x-portable-arbitrarymap", |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
809 new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImagePam), |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
810 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
811 Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPam)); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
812 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
813 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
814 |
252 | 815 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
816 void OrthancSlicesLoader::ScheduleSliceImageJpeg(const Slice& slice, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
817 size_t index, |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
818 SliceImageQuality quality) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
819 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
820 unsigned int value; |
252 | 821 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
822 switch (quality) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
823 { |
378 | 824 case SliceImageQuality_Jpeg50: |
825 value = 50; | |
826 break; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
827 |
378 | 828 case SliceImageQuality_Jpeg90: |
829 value = 90; | |
830 break; | |
252 | 831 |
378 | 832 case SliceImageQuality_Jpeg95: |
833 value = 95; | |
834 break; | |
252 | 835 |
378 | 836 default: |
837 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
838 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
839 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
840 // This requires the official Web viewer plugin to be installed! |
252 | 841 std::string uri = ("/web-viewer/instances/jpeg" + |
842 boost::lexical_cast<std::string>(value) + | |
843 "-" + slice.GetOrthancInstanceId() + "_" + | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
844 boost::lexical_cast<std::string>(slice.GetFrame())); |
252 | 845 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
846 orthanc_.GetJsonAsync(uri, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
847 new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImageJpeg), |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
848 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
849 Operation::DownloadSliceImage(index, slice, quality)); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
850 } |
252 | 851 |
852 | |
853 | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
854 void OrthancSlicesLoader::ScheduleLoadSliceImage(size_t index, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
855 SliceImageQuality quality) |
73 | 856 { |
857 if (state_ != State_GeometryReady) | |
858 { | |
859 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
860 } | |
252 | 861 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
862 const Slice& slice = GetSlice(index); |
252 | 863 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
864 if (slice.HasOrthancDecoding()) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
865 { |
257 | 866 switch (quality) |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
867 { |
378 | 868 case SliceImageQuality_FullPng: |
869 ScheduleSliceImagePng(slice, index); | |
870 break; | |
871 case SliceImageQuality_FullPam: | |
872 ScheduleSliceImagePam(slice, index); | |
873 break; | |
874 default: | |
875 ScheduleSliceImageJpeg(slice, index, quality); | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
876 } |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
877 } |
73 | 878 else |
879 { | |
252 | 880 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
|
881 boost::lexical_cast<std::string>(slice.GetFrame()) + "/raw.gz"); |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
406
diff
changeset
|
882 orthanc_.GetBinaryAsync(uri, IWebService::HttpHeaders(), |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
883 new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceRawImage), |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
884 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
885 Operation::DownloadSliceRawImage(index, slice)); |
73 | 886 } |
887 } | |
888 } |