Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/OrthancSlicesLoader.cpp @ 247:3d523c9a8f0d am
trying to use boost::signals2 even more.
author | am@osimis.io |
---|---|
date | Mon, 02 Jul 2018 12:32:02 +0200 |
parents | 5412adf19980 |
children |
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. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "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> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
32 #include <Core/Logging.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
33 #include <Core/OrthancException.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
34 #include <Core/Toolbox.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
35 #include <Plugins/Samples/Common/FullOrthancDataset.h> |
73 | 36 |
37 #include <boost/lexical_cast.hpp> | |
38 | |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
39 |
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 * 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
|
43 * "Orthanc::Toolbox::DecodeBase64()" does not work properly with |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
44 * WASM. UNDERSTAND WHY. |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
45 * https://stackoverflow.com/a/34571089/881731 |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
46 **/ |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
47 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
|
48 { |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
49 std::string out; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
50 |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
51 std::vector<int> T(256,-1); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
52 for (int i=0; i<64; i++) T["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i]] = i; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
53 |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
54 int val=0, valb=-8; |
128 | 55 for (size_t i = 0; i < in.size(); i++) { |
56 unsigned char c = in[i]; | |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
57 if (T[c] == -1) break; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
58 val = (val<<6) + T[c]; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
59 valb += 6; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
60 if (valb>=0) { |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
61 out.push_back(char((val>>valb)&0xFF)); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
62 valb-=8; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
63 } |
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 return out; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
66 } |
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 |
73 | 70 namespace OrthancStone |
71 { | |
72 class OrthancSlicesLoader::Operation : public Orthanc::IDynamicObject | |
73 { | |
74 private: | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
75 Mode mode_; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
76 unsigned int frame_; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
77 unsigned int sliceIndex_; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
78 const Slice* slice_; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
79 std::string instanceId_; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
80 SliceImageQuality quality_; |
73 | 81 |
82 Operation(Mode mode) : | |
83 mode_(mode) | |
84 { | |
85 } | |
86 | |
87 public: | |
88 Mode GetMode() const | |
89 { | |
90 return mode_; | |
91 } | |
92 | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
93 SliceImageQuality GetQuality() const |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
94 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
95 assert(mode_ == Mode_LoadImage || |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
96 mode_ == Mode_LoadRawImage); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
97 return quality_; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
98 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
99 |
73 | 100 unsigned int GetSliceIndex() const |
101 { | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
102 assert(mode_ == Mode_LoadImage || |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
103 mode_ == Mode_LoadRawImage); |
73 | 104 return sliceIndex_; |
105 } | |
106 | |
107 const Slice& GetSlice() const | |
108 { | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
109 assert(mode_ == Mode_LoadImage || |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
110 mode_ == Mode_LoadRawImage); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
111 assert(slice_ != NULL); |
73 | 112 return *slice_; |
113 } | |
114 | |
115 unsigned int GetFrame() const | |
116 { | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
117 assert(mode_ == Mode_FrameGeometry); |
73 | 118 return frame_; |
119 } | |
120 | |
121 const std::string& GetInstanceId() const | |
122 { | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
123 assert(mode_ == Mode_FrameGeometry || |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
124 mode_ == Mode_InstanceGeometry); |
73 | 125 return instanceId_; |
126 } | |
127 | |
128 static Operation* DownloadSeriesGeometry() | |
129 { | |
130 return new Operation(Mode_SeriesGeometry); | |
131 } | |
132 | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
133 static Operation* DownloadInstanceGeometry(const std::string& instanceId) |
73 | 134 { |
135 std::auto_ptr<Operation> operation(new Operation(Mode_InstanceGeometry)); | |
136 operation->instanceId_ = instanceId; | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
137 return operation.release(); |
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 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
140 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
|
141 unsigned int frame) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
142 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
143 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
|
144 operation->instanceId_ = instanceId; |
73 | 145 operation->frame_ = frame; |
146 return operation.release(); | |
147 } | |
148 | |
149 static Operation* DownloadSliceImage(unsigned int sliceIndex, | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
150 const Slice& slice, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
151 SliceImageQuality quality) |
73 | 152 { |
153 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadImage)); | |
154 tmp->sliceIndex_ = sliceIndex; | |
155 tmp->slice_ = &slice; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
156 tmp->quality_ = quality; |
73 | 157 return tmp.release(); |
158 } | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
159 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
160 static Operation* DownloadSliceRawImage(unsigned int sliceIndex, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
161 const Slice& slice) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
162 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
163 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
|
164 tmp->sliceIndex_ = sliceIndex; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
165 tmp->slice_ = &slice; |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
166 tmp->quality_ = SliceImageQuality_Full; |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
167 return tmp.release(); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
168 } |
73 | 169 }; |
170 | |
171 | |
247 | 172 // class OrthancSlicesLoader::WebCallback : public IWebService::ICallback |
173 // { | |
174 // private: | |
175 // OrthancSlicesLoader& that_; | |
73 | 176 |
247 | 177 // public: |
178 // WebCallback(OrthancSlicesLoader& that) : | |
179 // that_(that) | |
180 // { | |
181 // } | |
73 | 182 |
247 | 183 void OrthancSlicesLoader::OnRequestSuccess(const std::string& uri, |
73 | 184 const void* answer, |
185 size_t answerSize, | |
186 Orthanc::IDynamicObject* payload) | |
187 { | |
188 std::auto_ptr<Operation> operation(dynamic_cast<Operation*>(payload)); | |
189 | |
190 switch (operation->GetMode()) | |
191 { | |
192 case Mode_SeriesGeometry: | |
247 | 193 ParseSeriesGeometry(answer, answerSize); |
73 | 194 break; |
195 | |
196 case Mode_InstanceGeometry: | |
247 | 197 ParseInstanceGeometry(operation->GetInstanceId(), answer, answerSize); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
198 break; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
199 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
200 case Mode_FrameGeometry: |
247 | 201 ParseFrameGeometry(operation->GetInstanceId(), |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
202 operation->GetFrame(), answer, answerSize); |
73 | 203 break; |
204 | |
205 case Mode_LoadImage: | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
206 switch (operation->GetQuality()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
207 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
208 case SliceImageQuality_Full: |
247 | 209 ParseSliceImagePng(*operation, answer, answerSize); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
210 break; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
211 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
212 case SliceImageQuality_Jpeg50: |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
213 case SliceImageQuality_Jpeg90: |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
214 case SliceImageQuality_Jpeg95: |
247 | 215 ParseSliceImageJpeg(*operation, answer, answerSize); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
216 break; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
217 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
218 default: |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
219 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
220 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
221 |
73 | 222 break; |
223 | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
224 case Mode_LoadRawImage: |
247 | 225 ParseSliceRawImage(*operation, answer, answerSize); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
226 break; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
227 |
73 | 228 default: |
229 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
230 } | |
231 } | |
232 | |
247 | 233 void OrthancSlicesLoader::OnRequestError(const std::string& uri, |
73 | 234 Orthanc::IDynamicObject* payload) |
235 { | |
236 std::auto_ptr<Operation> operation(dynamic_cast<Operation*>(payload)); | |
237 LOG(ERROR) << "Cannot download " << uri; | |
238 | |
239 switch (operation->GetMode()) | |
240 { | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
241 case Mode_FrameGeometry: |
73 | 242 case Mode_SeriesGeometry: |
247 | 243 SignalGeometryError(*this); |
244 state_ = State_Error; | |
73 | 245 break; |
246 | |
247 case Mode_LoadImage: | |
247 | 248 SignalSliceImageError(*this, operation->GetSliceIndex(), |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
249 operation->GetSlice(), |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
250 operation->GetQuality()); |
73 | 251 break; |
252 | |
253 default: | |
254 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
255 } | |
256 } | |
247 | 257 // }; |
73 | 258 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
259 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
260 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
261 void OrthancSlicesLoader::NotifySliceImageSuccess(const Operation& operation, |
99 | 262 std::auto_ptr<Orthanc::ImageAccessor>& image) const |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
263 { |
99 | 264 if (image.get() == NULL) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
265 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
266 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
267 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
268 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
269 { |
247 | 270 SignalSliceImageReady(*this, operation.GetSliceIndex(), operation.GetSlice(), image, operation.GetQuality()); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
271 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
272 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
273 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
274 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
275 void OrthancSlicesLoader::NotifySliceImageError(const Operation& operation) const |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
276 { |
247 | 277 SignalSliceImageError(*this, operation.GetSliceIndex(), operation.GetSlice(), operation.GetQuality()); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
278 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
279 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
280 |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
281 void OrthancSlicesLoader::SortAndFinalizeSlices() |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
282 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
283 bool ok = false; |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
284 |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
285 if (slices_.GetSliceCount() > 0) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
286 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
287 Vector normal; |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
288 if (slices_.SelectNormal(normal)) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
289 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
290 slices_.FilterNormal(normal); |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
291 slices_.SetNormal(normal); |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
292 slices_.Sort(); |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
293 ok = true; |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
294 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
295 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
296 |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
297 state_ = State_GeometryReady; |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
298 |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
299 if (ok) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
300 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
301 LOG(INFO) << "Loaded a series with " << slices_.GetSliceCount() << " slice(s)"; |
247 | 302 SignalGeometryReady(*this); |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
303 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
304 else |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
305 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
306 LOG(ERROR) << "This series is empty"; |
247 | 307 SignalGeometryError(*this); |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
308 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
309 } |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
310 |
73 | 311 |
312 void OrthancSlicesLoader::ParseSeriesGeometry(const void* answer, | |
313 size_t size) | |
314 { | |
315 Json::Value series; | |
316 if (!MessagingToolbox::ParseJson(series, answer, size) || | |
317 series.type() != Json::objectValue) | |
318 { | |
247 | 319 SignalGeometryError(*this); |
73 | 320 return; |
321 } | |
322 | |
323 Json::Value::Members instances = series.getMemberNames(); | |
324 | |
325 slices_.Reserve(instances.size()); | |
326 | |
327 for (size_t i = 0; i < instances.size(); i++) | |
328 { | |
329 OrthancPlugins::FullOrthancDataset dataset(series[instances[i]]); | |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
330 |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
331 Orthanc::DicomMap dicom; |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
332 MessagingToolbox::ConvertDataset(dicom, dataset); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
333 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
334 unsigned int frames; |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
335 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
|
336 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
337 frames = 1; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
338 } |
73 | 339 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
340 for (unsigned int frame = 0; frame < frames; frame++) |
73 | 341 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
342 std::auto_ptr<Slice> slice(new Slice); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
343 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
|
344 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
345 slices_.AddSlice(slice.release()); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
346 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
347 else |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
348 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
349 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
|
350 } |
73 | 351 } |
352 } | |
353 | |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
354 SortAndFinalizeSlices(); |
73 | 355 } |
356 | |
357 | |
358 void OrthancSlicesLoader::ParseInstanceGeometry(const std::string& instanceId, | |
359 const void* answer, | |
360 size_t size) | |
361 { | |
362 Json::Value tags; | |
363 if (!MessagingToolbox::ParseJson(tags, answer, size) || | |
364 tags.type() != Json::objectValue) | |
365 { | |
247 | 366 SignalGeometryError(*this); |
73 | 367 return; |
368 } | |
369 | |
370 OrthancPlugins::FullOrthancDataset dataset(tags); | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
371 |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
372 Orthanc::DicomMap dicom; |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
373 MessagingToolbox::ConvertDataset(dicom, dataset); |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
374 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
375 unsigned int frames; |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
376 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
|
377 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
378 frames = 1; |
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 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
381 LOG(INFO) << "Instance " << instanceId << " contains " << frames << " frame(s)"; |
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 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
|
384 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
385 std::auto_ptr<Slice> slice(new Slice); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
386 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
|
387 { |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
388 slices_.AddSlice(slice.release()); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
389 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
390 else |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
391 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
392 LOG(WARNING) << "Skipping invalid multi-frame instance " << instanceId; |
247 | 393 SignalGeometryError(*this); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
394 return; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
395 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
396 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
397 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
398 SortAndFinalizeSlices(); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
399 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
400 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
401 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
402 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
|
403 unsigned int frame, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
404 const void* answer, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
405 size_t size) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
406 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
407 Json::Value tags; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
408 if (!MessagingToolbox::ParseJson(tags, answer, size) || |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
409 tags.type() != Json::objectValue) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
410 { |
247 | 411 SignalGeometryError(*this); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
412 return; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
413 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
414 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
415 OrthancPlugins::FullOrthancDataset dataset(tags); |
73 | 416 |
417 state_ = State_GeometryReady; | |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
418 |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
419 Orthanc::DicomMap dicom; |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
420 MessagingToolbox::ConvertDataset(dicom, dataset); |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
117
diff
changeset
|
421 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
422 std::auto_ptr<Slice> slice(new Slice); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
423 if (slice->ParseOrthancFrame(dicom, instanceId, frame)) |
73 | 424 { |
425 LOG(INFO) << "Loaded instance " << instanceId; | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
426 slices_.AddSlice(slice.release()); |
247 | 427 SignalGeometryReady(*this); |
73 | 428 } |
429 else | |
430 { | |
431 LOG(WARNING) << "Skipping invalid instance " << instanceId; | |
247 | 432 SignalGeometryError(*this); |
73 | 433 } |
434 } | |
435 | |
436 | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
437 void OrthancSlicesLoader::ParseSliceImagePng(const Operation& operation, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
438 const void* answer, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
439 size_t size) |
73 | 440 { |
99 | 441 std::auto_ptr<Orthanc::ImageAccessor> image; |
73 | 442 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
443 try |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
444 { |
99 | 445 image.reset(new Orthanc::PngReader); |
446 dynamic_cast<Orthanc::PngReader&>(*image).ReadFromMemory(answer, size); | |
93
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 catch (Orthanc::OrthancException&) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
449 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
450 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
451 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
452 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
453 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
454 if (image->GetWidth() != operation.GetSlice().GetWidth() || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
455 image->GetHeight() != operation.GetSlice().GetHeight()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
456 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
457 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
458 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
459 } |
73 | 460 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
461 if (operation.GetSlice().GetConverter().GetExpectedPixelFormat() == |
73 | 462 Orthanc::PixelFormat_SignedGrayscale16) |
463 { | |
464 if (image->GetFormat() == Orthanc::PixelFormat_Grayscale16) | |
465 { | |
466 image->SetFormat(Orthanc::PixelFormat_SignedGrayscale16); | |
467 } | |
468 else | |
469 { | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
470 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
471 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
472 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
473 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
474 |
99 | 475 NotifySliceImageSuccess(operation, image); |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
476 } |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
477 |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
478 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
479 void OrthancSlicesLoader::ParseSliceImageJpeg(const Operation& operation, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
480 const void* answer, |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
481 size_t size) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
482 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
483 Json::Value encoded; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
484 if (!MessagingToolbox::ParseJson(encoded, answer, size) || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
485 encoded.type() != Json::objectValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
486 !encoded.isMember("Orthanc") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
487 encoded["Orthanc"].type() != Json::objectValue) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
488 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
489 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
490 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
491 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
492 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
493 Json::Value& info = encoded["Orthanc"]; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
494 if (!info.isMember("PixelData") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
495 !info.isMember("Stretched") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
496 !info.isMember("Compression") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
497 info["Compression"].type() != Json::stringValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
498 info["PixelData"].type() != Json::stringValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
499 info["Stretched"].type() != Json::booleanValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
500 info["Compression"].asString() != "Jpeg") |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
501 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
502 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
503 return; |
94 | 504 } |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
505 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
506 bool isSigned = false; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
507 bool isStretched = info["Stretched"].asBool(); |
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 (info.isMember("IsSigned")) |
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 if (info["IsSigned"].type() != Json::booleanValue) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
512 { |
94 | 513 NotifySliceImageError(operation); |
514 return; | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
515 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
516 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
517 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
518 isSigned = info["IsSigned"].asBool(); |
73 | 519 } |
520 } | |
521 | |
99 | 522 std::auto_ptr<Orthanc::ImageAccessor> reader; |
94 | 523 |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
524 { |
100
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
525 std::string jpeg; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
526 //Orthanc::Toolbox::DecodeBase64(jpeg, info["PixelData"].asString()); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
527 jpeg = base64_decode(info["PixelData"].asString()); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
528 |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
529 try |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
530 { |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
531 reader.reset(new Orthanc::JpegReader); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
532 dynamic_cast<Orthanc::JpegReader&>(*reader).ReadFromMemory(jpeg); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
533 } |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
534 catch (Orthanc::OrthancException&) |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
535 { |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
536 NotifySliceImageError(operation); |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
537 return; |
166a555becbf
fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
538 } |
93
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 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
541 Orthanc::PixelFormat expectedFormat = |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
542 operation.GetSlice().GetConverter().GetExpectedPixelFormat(); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
543 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
544 if (reader->GetFormat() == Orthanc::PixelFormat_RGB24) // This is a color image |
73 | 545 { |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
546 if (expectedFormat != Orthanc::PixelFormat_RGB24) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
547 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
548 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
549 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
550 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
551 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
552 if (isSigned || isStretched) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
553 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
554 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
555 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
556 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
557 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
558 { |
99 | 559 NotifySliceImageSuccess(operation, reader); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
560 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
561 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
562 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
563 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
564 if (reader->GetFormat() != Orthanc::PixelFormat_Grayscale8) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
565 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
566 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
567 return; |
73 | 568 } |
93
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 if (!isStretched) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
571 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
572 if (expectedFormat != reader->GetFormat()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
573 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
574 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
575 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
576 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
577 else |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
578 { |
99 | 579 NotifySliceImageSuccess(operation, reader); |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
580 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
581 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
582 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
583 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
584 int32_t stretchLow = 0; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
585 int32_t stretchHigh = 0; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
586 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
587 if (!info.isMember("StretchLow") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
588 !info.isMember("StretchHigh") || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
589 info["StretchLow"].type() != Json::intValue || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
590 info["StretchHigh"].type() != Json::intValue) |
73 | 591 { |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
592 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
593 return; |
73 | 594 } |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
595 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
596 stretchLow = info["StretchLow"].asInt(); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
597 stretchHigh = info["StretchHigh"].asInt(); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
598 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
599 if (stretchLow < -32768 || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
600 stretchHigh > 65535 || |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
601 (stretchLow < 0 && stretchHigh > 32767)) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
602 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
603 // 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
|
604 NotifySliceImageError(operation); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
605 return; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
606 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
607 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
608 // 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
|
609 std::auto_ptr<Orthanc::ImageAccessor> image |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
610 (new Orthanc::Image(expectedFormat, reader->GetWidth(), reader->GetHeight(), false)); |
203 | 611 |
612 Orthanc::ImageProcessing::Convert(*image, *reader); | |
613 reader.reset(NULL); | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
614 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
615 float scaling = static_cast<float>(stretchHigh - stretchLow) / 255.0f; |
203 | 616 |
617 if (!LinearAlgebra::IsCloseToZero(scaling)) | |
618 { | |
619 float offset = static_cast<float>(stretchLow) / scaling; | |
620 Orthanc::ImageProcessing::ShiftScale(*image, offset, scaling, true); | |
621 } | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
622 |
99 | 623 NotifySliceImageSuccess(operation, image); |
73 | 624 } |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
625 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
626 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
627 class StringImage : |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
628 public Orthanc::ImageAccessor, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
629 public boost::noncopyable |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
630 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
631 private: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
632 std::string buffer_; |
73 | 633 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
634 public: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
635 StringImage(Orthanc::PixelFormat format, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
636 unsigned int width, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
637 unsigned int height, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
638 std::string& buffer) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
639 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
640 if (buffer.size() != Orthanc::GetBytesPerPixel(format) * width * height) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
641 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
642 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
643 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
644 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
645 buffer_.swap(buffer); // The source buffer is now empty |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
646 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
647 void* data = (buffer_.empty() ? NULL : &buffer_[0]); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
648 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
649 AssignWritable(format, width, height, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
650 Orthanc::GetBytesPerPixel(format) * width, data); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
651 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
652 }; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
653 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
654 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
655 void OrthancSlicesLoader::ParseSliceRawImage(const Operation& operation, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
656 const void* answer, |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
657 size_t size) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
658 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
659 Orthanc::GzipCompressor compressor; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
660 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
661 std::string raw; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
662 compressor.Uncompress(raw, answer, size); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
663 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
664 const Orthanc::DicomImageInformation& info = operation.GetSlice().GetImageInformation(); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
665 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
666 if (info.GetBitsAllocated() == 32 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
667 info.GetBitsStored() == 32 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
668 info.GetHighBit() == 31 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
669 info.GetChannelCount() == 1 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
670 !info.IsSigned() && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
671 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 && |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
672 raw.size() == info.GetWidth() * info.GetHeight() * 4) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
673 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
674 // 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
|
675 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
676 std::auto_ptr<Orthanc::ImageAccessor> image |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
677 (new StringImage(Orthanc::PixelFormat_Grayscale32, info.GetWidth(), |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
678 info.GetHeight(), raw)); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
679 |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
680 // TODO - Only for big endian |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
681 for (unsigned int y = 0; y < image->GetHeight(); y++) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
682 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
683 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
|
684 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
|
685 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
686 *p = le32toh(*p); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
687 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
688 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
689 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
690 NotifySliceImageSuccess(operation, image); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
691 } |
120
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
692 else if (info.GetBitsAllocated() == 16 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
693 info.GetBitsStored() == 16 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
694 info.GetHighBit() == 15 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
695 info.GetChannelCount() == 1 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
696 !info.IsSigned() && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
697 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 && |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
698 raw.size() == info.GetWidth() * info.GetHeight() * 2) |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
699 { |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
700 std::auto_ptr<Orthanc::ImageAccessor> image |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
701 (new StringImage(Orthanc::PixelFormat_Grayscale16, info.GetWidth(), |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
702 info.GetHeight(), raw)); |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
703 |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
704 // TODO - Big endian ? |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
705 |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
706 NotifySliceImageSuccess(operation, image); |
063f7f3d9f14
fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
707 } |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
708 else |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
709 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
710 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
711 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
712 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
713 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
714 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
715 |
247 | 716 OrthancSlicesLoader::OrthancSlicesLoader(boost::shared_ptr<OrthancSlicesLoader::IObserver> observer, |
73 | 717 IWebService& orthanc) : |
247 | 718 //webCallback_(new WebCallback(*this)), |
719 // userCallback_(callback), | |
720 observer_(observer), | |
73 | 721 orthanc_(orthanc), |
722 state_(State_Initialization) | |
723 { | |
247 | 724 SignalGeometryReady.connect(OrthancSlicesLoader::IObserver::SignalGeometryReadyType::slot_type(&OrthancSlicesLoader::IObserver::NotifyGeometryReady, observer.get(), _1).track(observer)); |
725 SignalGeometryError.connect(OrthancSlicesLoader::IObserver::SignalGeometryErrorType::slot_type(&OrthancSlicesLoader::IObserver::NotifyGeometryError, observer.get(), _1).track(observer)); | |
726 SignalSliceImageReady.connect(OrthancSlicesLoader::IObserver::SignalSliceImageReadyType::slot_type(&OrthancSlicesLoader::IObserver::NotifySliceImageReady, observer.get(), _1, _2, _3, _4, _5).track(observer)); | |
727 SignalSliceImageError.connect(OrthancSlicesLoader::IObserver::SignalSliceImageErrorType::slot_type(&OrthancSlicesLoader::IObserver::NotifySliceImageError, observer.get(), _1, _2, _3, _4).track(observer)); | |
73 | 728 } |
729 | |
730 | |
247 | 731 void OrthancSlicesLoader::ScheduleLoadSeries(boost::shared_ptr<boost::noncopyable> tracker, const std::string& seriesId) |
73 | 732 { |
733 if (state_ != State_Initialization) | |
734 { | |
735 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
736 } | |
737 else | |
738 { | |
739 state_ = State_LoadingGeometry; | |
740 std::string uri = "/series/" + seriesId + "/instances-tags"; | |
247 | 741 orthanc_.ScheduleGetRequest(this, tracker, uri, Operation::DownloadSeriesGeometry()); |
73 | 742 } |
743 } | |
744 | |
745 | |
247 | 746 void OrthancSlicesLoader::ScheduleLoadInstance(boost::shared_ptr<boost::noncopyable> tracker, const std::string& instanceId) |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
747 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
748 if (state_ != State_Initialization) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
749 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
750 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
751 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
752 else |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
753 { |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
754 state_ = State_LoadingGeometry; |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
755 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
756 // 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
|
757 // 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
|
758 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
|
759 orthanc_.ScheduleGetRequest |
247 | 760 (this, tracker, uri, Operation::DownloadInstanceGeometry(instanceId)); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
761 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
762 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
763 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
764 |
247 | 765 void OrthancSlicesLoader::ScheduleLoadFrame(boost::shared_ptr<boost::noncopyable> tracker, const std::string& instanceId, |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
766 unsigned int frame) |
73 | 767 { |
768 if (state_ != State_Initialization) | |
769 { | |
770 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
771 } | |
772 else | |
773 { | |
774 state_ = State_LoadingGeometry; | |
775 std::string uri = "/instances/" + instanceId + "/tags"; | |
776 orthanc_.ScheduleGetRequest | |
247 | 777 (this, tracker, uri, Operation::DownloadFrameGeometry(instanceId, frame)); |
73 | 778 } |
779 } | |
780 | |
781 | |
77 | 782 bool OrthancSlicesLoader::IsGeometryReady() const |
783 { | |
784 return state_ == State_GeometryReady; | |
785 } | |
786 | |
787 | |
73 | 788 size_t OrthancSlicesLoader::GetSliceCount() const |
789 { | |
790 if (state_ != State_GeometryReady) | |
791 { | |
792 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
793 } | |
794 | |
795 return slices_.GetSliceCount(); | |
796 } | |
797 | |
798 | |
799 const Slice& OrthancSlicesLoader::GetSlice(size_t index) const | |
800 { | |
801 if (state_ != State_GeometryReady) | |
802 { | |
803 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
804 } | |
805 | |
806 return slices_.GetSlice(index); | |
807 } | |
808 | |
809 | |
77 | 810 bool OrthancSlicesLoader::LookupSlice(size_t& index, |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
811 const CoordinateSystem3D& plane) const |
77 | 812 { |
813 if (state_ != State_GeometryReady) | |
814 { | |
815 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
816 } | |
817 | |
818 return slices_.LookupSlice(index, plane); | |
819 } | |
820 | |
821 | |
247 | 822 void OrthancSlicesLoader::ScheduleSliceImagePng(boost::shared_ptr<boost::noncopyable> tracker, const Slice& slice, |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
823 size_t index) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
824 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
825 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
826 boost::lexical_cast<std::string>(slice.GetFrame())); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
827 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
828 switch (slice.GetConverter().GetExpectedPixelFormat()) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
829 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
830 case Orthanc::PixelFormat_RGB24: |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
831 uri += "/preview"; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
832 break; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
833 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
834 case Orthanc::PixelFormat_Grayscale16: |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
835 uri += "/image-uint16"; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
836 break; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
837 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
838 case Orthanc::PixelFormat_SignedGrayscale16: |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
839 uri += "/image-int16"; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
840 break; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
841 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
842 default: |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
843 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
844 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
845 |
247 | 846 orthanc_.ScheduleGetRequest(this, tracker, uri, |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
847 Operation::DownloadSliceImage(index, slice, SliceImageQuality_Full)); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
848 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
849 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
850 |
247 | 851 void OrthancSlicesLoader::ScheduleSliceImageJpeg(boost::shared_ptr<boost::noncopyable> tracker, const Slice& slice, |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
852 size_t index, |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
853 SliceImageQuality quality) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
854 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
855 unsigned int value; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
856 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
857 switch (quality) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
858 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
859 case SliceImageQuality_Jpeg50: |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
860 value = 50; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
861 break; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
862 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
863 case SliceImageQuality_Jpeg90: |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
864 value = 90; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
865 break; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
866 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
867 case SliceImageQuality_Jpeg95: |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
868 value = 95; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
869 break; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
870 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
871 default: |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
872 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
873 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
874 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
875 // This requires the official Web viewer plugin to be installed! |
94 | 876 std::string uri = ("/web-viewer/instances/jpeg" + |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
877 boost::lexical_cast<std::string>(value) + |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
878 "-" + slice.GetOrthancInstanceId() + "_" + |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
879 boost::lexical_cast<std::string>(slice.GetFrame())); |
128 | 880 |
247 | 881 orthanc_.ScheduleGetRequest(this, tracker, uri, |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
882 Operation::DownloadSliceImage(index, slice, quality)); |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
883 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
884 |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
885 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
886 |
247 | 887 void OrthancSlicesLoader::ScheduleLoadSliceImage(boost::shared_ptr<boost::noncopyable> tracker, size_t index, |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
888 SliceImageQuality quality) |
73 | 889 { |
890 if (state_ != State_GeometryReady) | |
891 { | |
892 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
893 } | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
894 |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
895 const Slice& slice = GetSlice(index); |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
896 |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
897 if (slice.HasOrthancDecoding()) |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
898 { |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
899 if (quality == SliceImageQuality_Full) |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
900 { |
247 | 901 ScheduleSliceImagePng(tracker, slice, index); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
902 } |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
903 else |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
904 { |
247 | 905 ScheduleSliceImageJpeg(tracker, slice, index, quality); |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
906 } |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
907 } |
73 | 908 else |
909 { | |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
910 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + |
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
911 boost::lexical_cast<std::string>(slice.GetFrame()) + "/raw.gz"); |
247 | 912 orthanc_.ScheduleGetRequest(this, tracker, uri, |
117
42c05a3baee3
loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
913 Operation::DownloadSliceRawImage(index, slice)); |
73 | 914 } |
915 } | |
916 } |