Mercurial > hg > orthanc-stone
annotate Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp @ 1090:71c2dc28a85b broker
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Oct 2019 11:43:29 +0200 |
parents | 81b29bc7c3d4 |
children | 8e3763d1736a |
rev | line source |
---|---|
814 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
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 "OrthancSeriesVolumeProgressiveLoader.h" | |
23 | |
24 #include "../Toolbox/GeometryToolbox.h" | |
25 #include "../Volumes/DicomVolumeImageMPRSlicer.h" | |
26 #include "BasicFetchingItemsSorter.h" | |
27 #include "BasicFetchingStrategy.h" | |
28 | |
29 #include <Core/Images/ImageProcessing.h> | |
30 #include <Core/OrthancException.h> | |
31 | |
32 namespace OrthancStone | |
33 { | |
34 class OrthancSeriesVolumeProgressiveLoader::ExtractedSlice : public DicomVolumeImageMPRSlicer::Slice | |
35 { | |
36 private: | |
37 const OrthancSeriesVolumeProgressiveLoader& that_; | |
38 | |
39 public: | |
40 ExtractedSlice(const OrthancSeriesVolumeProgressiveLoader& that, | |
41 const CoordinateSystem3D& plane) : | |
42 DicomVolumeImageMPRSlicer::Slice(*that.volume_, plane), | |
43 that_(that) | |
44 { | |
819 | 45 if (IsValid()) |
817
68f888812af4
simplification of DicomVolumeImageMPRSlicer::ExtractedSlice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
814
diff
changeset
|
46 { |
819 | 47 if (GetProjection() == VolumeProjection_Axial) |
48 { | |
49 // For coronal and sagittal projections, we take the global | |
50 // revision of the volume because even if a single slice changes, | |
51 // this means the projection will yield a different result --> | |
52 // we must increase the revision as soon as any slice changes | |
53 SetRevision(that_.seriesGeometry_.GetSliceRevision(GetSliceIndex())); | |
54 } | |
817
68f888812af4
simplification of DicomVolumeImageMPRSlicer::ExtractedSlice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
814
diff
changeset
|
55 |
819 | 56 if (that_.strategy_.get() != NULL && |
57 GetProjection() == VolumeProjection_Axial) | |
58 { | |
59 that_.strategy_->SetCurrent(GetSliceIndex()); | |
60 } | |
814 | 61 } |
62 } | |
63 }; | |
64 | |
65 | |
66 | |
67 void OrthancSeriesVolumeProgressiveLoader::SeriesGeometry::CheckSlice(size_t index, | |
68 const DicomInstanceParameters& reference) const | |
69 { | |
70 const DicomInstanceParameters& slice = *slices_[index]; | |
71 | |
72 if (!GeometryToolbox::IsParallel( | |
73 reference.GetGeometry().GetNormal(), | |
74 slice.GetGeometry().GetNormal())) | |
75 { | |
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadGeometry, | |
77 "A slice in the volume image is not parallel to the others"); | |
78 } | |
79 | |
80 if (reference.GetExpectedPixelFormat() != slice.GetExpectedPixelFormat()) | |
81 { | |
82 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat, | |
83 "The pixel format changes across the slices of the volume image"); | |
84 } | |
85 | |
86 if (reference.GetImageInformation().GetWidth() != slice.GetImageInformation().GetWidth() || | |
87 reference.GetImageInformation().GetHeight() != slice.GetImageInformation().GetHeight()) | |
88 { | |
89 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize, | |
90 "The width/height of slices are not constant in the volume image"); | |
91 } | |
92 | |
93 if (!LinearAlgebra::IsNear(reference.GetPixelSpacingX(), slice.GetPixelSpacingX()) || | |
94 !LinearAlgebra::IsNear(reference.GetPixelSpacingY(), slice.GetPixelSpacingY())) | |
95 { | |
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadGeometry, | |
97 "The pixel spacing of the slices change across the volume image"); | |
98 } | |
99 } | |
100 | |
101 | |
102 void OrthancSeriesVolumeProgressiveLoader::SeriesGeometry::CheckVolume() const | |
103 { | |
104 for (size_t i = 0; i < slices_.size(); i++) | |
105 { | |
106 assert(slices_[i] != NULL); | |
107 if (slices_[i]->GetImageInformation().GetNumberOfFrames() != 1) | |
108 { | |
109 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadGeometry, | |
110 "This class does not support multi-frame images"); | |
111 } | |
112 } | |
113 | |
114 if (slices_.size() != 0) | |
115 { | |
116 const DicomInstanceParameters& reference = *slices_[0]; | |
117 | |
118 for (size_t i = 1; i < slices_.size(); i++) | |
119 { | |
120 CheckSlice(i, reference); | |
121 } | |
122 } | |
123 } | |
124 | |
125 | |
126 void OrthancSeriesVolumeProgressiveLoader::SeriesGeometry::Clear() | |
127 { | |
128 for (size_t i = 0; i < slices_.size(); i++) | |
129 { | |
130 assert(slices_[i] != NULL); | |
131 delete slices_[i]; | |
132 } | |
133 | |
134 slices_.clear(); | |
135 slicesRevision_.clear(); | |
136 } | |
137 | |
138 | |
139 void OrthancSeriesVolumeProgressiveLoader::SeriesGeometry::CheckSliceIndex(size_t index) const | |
140 { | |
141 if (!HasGeometry()) | |
142 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
949
diff
changeset
|
143 LOG(ERROR) << "OrthancSeriesVolumeProgressiveLoader::SeriesGeometry::CheckSliceIndex(size_t index): (!HasGeometry())"; |
814 | 144 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
145 } | |
146 else if (index >= slices_.size()) | |
147 { | |
148 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
149 } | |
150 else | |
151 { | |
152 assert(slices_.size() == GetImageGeometry().GetDepth() && | |
153 slices_.size() == slicesRevision_.size()); | |
154 } | |
155 } | |
156 | |
157 | |
158 // WARNING: The payload of "slices" must be of class "DicomInstanceParameters" | |
159 // (called with the slices created in LoadGeometry) | |
160 void OrthancSeriesVolumeProgressiveLoader::SeriesGeometry::ComputeGeometry(SlicesSorter& slices) | |
161 { | |
162 Clear(); | |
163 | |
164 if (!slices.Sort()) | |
165 { | |
166 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, | |
167 "Cannot sort the 3D slices of a DICOM series"); | |
168 } | |
169 | |
170 if (slices.GetSlicesCount() == 0) | |
171 { | |
172 geometry_.reset(new VolumeImageGeometry); | |
173 } | |
174 else | |
175 { | |
176 slices_.reserve(slices.GetSlicesCount()); | |
177 slicesRevision_.resize(slices.GetSlicesCount(), 0); | |
178 | |
179 for (size_t i = 0; i < slices.GetSlicesCount(); i++) | |
180 { | |
181 const DicomInstanceParameters& slice = | |
182 dynamic_cast<const DicomInstanceParameters&>(slices.GetSlicePayload(i)); | |
183 slices_.push_back(new DicomInstanceParameters(slice)); | |
184 } | |
185 | |
186 CheckVolume(); | |
187 | |
188 const double spacingZ = slices.ComputeSpacingBetweenSlices(); | |
189 LOG(INFO) << "Computed spacing between slices: " << spacingZ << "mm"; | |
190 | |
191 const DicomInstanceParameters& parameters = *slices_[0]; | |
192 | |
193 geometry_.reset(new VolumeImageGeometry); | |
949
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
937
diff
changeset
|
194 geometry_->SetSizeInVoxels(parameters.GetImageInformation().GetWidth(), |
814 | 195 parameters.GetImageInformation().GetHeight(), |
196 static_cast<unsigned int>(slices.GetSlicesCount())); | |
197 geometry_->SetAxialGeometry(slices.GetSliceGeometry(0)); | |
198 geometry_->SetVoxelDimensions(parameters.GetPixelSpacingX(), | |
199 parameters.GetPixelSpacingY(), spacingZ); | |
200 } | |
201 } | |
202 | |
203 | |
204 const VolumeImageGeometry& OrthancSeriesVolumeProgressiveLoader::SeriesGeometry::GetImageGeometry() const | |
205 { | |
206 if (!HasGeometry()) | |
207 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
949
diff
changeset
|
208 LOG(ERROR) << "OrthancSeriesVolumeProgressiveLoader::SeriesGeometry::GetImageGeometry(): (!HasGeometry())"; |
814 | 209 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
210 } | |
211 else | |
212 { | |
213 assert(slices_.size() == geometry_->GetDepth()); | |
214 return *geometry_; | |
215 } | |
216 } | |
217 | |
218 | |
219 const DicomInstanceParameters& OrthancSeriesVolumeProgressiveLoader::SeriesGeometry::GetSliceParameters(size_t index) const | |
220 { | |
221 CheckSliceIndex(index); | |
222 return *slices_[index]; | |
223 } | |
224 | |
225 | |
226 uint64_t OrthancSeriesVolumeProgressiveLoader::SeriesGeometry::GetSliceRevision(size_t index) const | |
227 { | |
228 CheckSliceIndex(index); | |
229 return slicesRevision_[index]; | |
230 } | |
231 | |
232 | |
233 void OrthancSeriesVolumeProgressiveLoader::SeriesGeometry::IncrementSliceRevision(size_t index) | |
234 { | |
235 CheckSliceIndex(index); | |
236 slicesRevision_[index] ++; | |
237 } | |
238 | |
239 | |
240 static unsigned int GetSliceIndexPayload(const OracleCommandWithPayload& command) | |
241 { | |
242 return dynamic_cast< const Orthanc::SingleValueObject<unsigned int>& >(command.GetPayload()).GetValue(); | |
243 } | |
244 | |
245 | |
246 void OrthancSeriesVolumeProgressiveLoader::ScheduleNextSliceDownload() | |
247 { | |
248 assert(strategy_.get() != NULL); | |
249 | |
250 unsigned int sliceIndex, quality; | |
251 | |
252 if (strategy_->GetNext(sliceIndex, quality)) | |
253 { | |
254 assert(quality <= BEST_QUALITY); | |
255 | |
256 const DicomInstanceParameters& slice = seriesGeometry_.GetSliceParameters(sliceIndex); | |
257 | |
258 const std::string& instance = slice.GetOrthancInstanceIdentifier(); | |
259 if (instance.empty()) | |
260 { | |
261 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
262 } | |
263 | |
264 std::auto_ptr<OracleCommandWithPayload> command; | |
265 | |
266 if (quality == BEST_QUALITY) | |
267 { | |
268 std::auto_ptr<GetOrthancImageCommand> tmp(new GetOrthancImageCommand); | |
937
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
269 // TODO: review the following comment. |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
270 // - Commented out by bgo on 2019-07-19 | reason: Alain has seen cases |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
271 // where gzipping the uint16 image took 11 sec to produce 5mb. |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
272 // The unzipped request was much much faster. |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
273 // - Re-enabled on 2019-07-30. Reason: in Web Assembly, the browser |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
274 // does not use the Accept-Encoding header and always requests |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
275 // compression. Furthermore, NOT |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
276 tmp->SetHttpHeader("Accept-Encoding", "gzip"); |
814 | 277 tmp->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Pam))); |
819 | 278 tmp->SetInstanceUri(instance, slice.GetExpectedPixelFormat()); |
814 | 279 tmp->SetExpectedPixelFormat(slice.GetExpectedPixelFormat()); |
280 command.reset(tmp.release()); | |
281 } | |
282 else | |
283 { | |
284 std::auto_ptr<GetOrthancWebViewerJpegCommand> tmp(new GetOrthancWebViewerJpegCommand); | |
913
2b4b6b86520a
Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents:
819
diff
changeset
|
285 // TODO: review the following comment. Commented out by bgo on 2019-07-19 |
2b4b6b86520a
Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents:
819
diff
changeset
|
286 // (gzip for jpeg seems overkill) |
2b4b6b86520a
Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents:
819
diff
changeset
|
287 //tmp->SetHttpHeader("Accept-Encoding", "gzip"); |
814 | 288 tmp->SetInstance(instance); |
289 tmp->SetQuality((quality == 0 ? 50 : 90)); | |
290 tmp->SetExpectedPixelFormat(slice.GetExpectedPixelFormat()); | |
291 command.reset(tmp.release()); | |
292 } | |
293 | |
294 command->SetPayload(new Orthanc::SingleValueObject<unsigned int>(sliceIndex)); | |
1075 | 295 |
296 boost::shared_ptr<IObserver> observer(GetSharedObserver()); | |
297 oracle_.Schedule(observer, command.release()); | |
814 | 298 } |
937
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
299 else |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
300 { |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
301 // loading is finished! |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
302 volumeImageReadyInHighQuality_ = true; |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
303 BroadcastMessage(OrthancSeriesVolumeProgressiveLoader::VolumeImageReadyInHighQuality(*this)); |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
304 } |
814 | 305 } |
306 | |
307 /** | |
308 This is called in response to GET "/series/XXXXXXXXXXXXX/instances-tags" | |
309 */ | |
310 void OrthancSeriesVolumeProgressiveLoader::LoadGeometry(const OrthancRestApiCommand::SuccessMessage& message) | |
311 { | |
312 Json::Value body; | |
313 message.ParseJsonBody(body); | |
314 | |
315 if (body.type() != Json::objectValue) | |
316 { | |
317 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); | |
318 } | |
319 | |
320 { | |
321 Json::Value::Members instances = body.getMemberNames(); | |
322 | |
323 SlicesSorter slices; | |
324 | |
325 for (size_t i = 0; i < instances.size(); i++) | |
326 { | |
327 Orthanc::DicomMap dicom; | |
328 dicom.FromDicomAsJson(body[instances[i]]); | |
329 | |
330 std::auto_ptr<DicomInstanceParameters> instance(new DicomInstanceParameters(dicom)); | |
331 instance->SetOrthancInstanceIdentifier(instances[i]); | |
332 | |
333 // the 3D plane corresponding to the slice | |
334 CoordinateSystem3D geometry = instance->GetGeometry(); | |
335 slices.AddSlice(geometry, instance.release()); | |
336 } | |
337 | |
338 seriesGeometry_.ComputeGeometry(slices); | |
339 } | |
340 | |
341 size_t slicesCount = seriesGeometry_.GetImageGeometry().GetDepth(); | |
342 | |
343 if (slicesCount == 0) | |
344 { | |
345 volume_->Initialize(seriesGeometry_.GetImageGeometry(), Orthanc::PixelFormat_Grayscale8); | |
346 } | |
347 else | |
348 { | |
349 const DicomInstanceParameters& parameters = seriesGeometry_.GetSliceParameters(0); | |
350 | |
351 volume_->Initialize(seriesGeometry_.GetImageGeometry(), parameters.GetExpectedPixelFormat()); | |
352 volume_->SetDicomParameters(parameters); | |
353 volume_->GetPixelData().Clear(); | |
354 | |
355 strategy_.reset(new BasicFetchingStrategy(sorter_->CreateSorter(static_cast<unsigned int>(slicesCount)), BEST_QUALITY)); | |
356 | |
357 assert(simultaneousDownloads_ != 0); | |
358 for (unsigned int i = 0; i < simultaneousDownloads_; i++) | |
359 { | |
360 ScheduleNextSliceDownload(); | |
361 } | |
362 } | |
363 | |
364 slicesQuality_.resize(slicesCount, 0); | |
365 | |
366 BroadcastMessage(DicomVolumeImage::GeometryReadyMessage(*volume_)); | |
367 } | |
368 | |
369 | |
370 void OrthancSeriesVolumeProgressiveLoader::SetSliceContent(unsigned int sliceIndex, | |
371 const Orthanc::ImageAccessor& image, | |
372 unsigned int quality) | |
373 { | |
374 assert(sliceIndex < slicesQuality_.size() && | |
375 slicesQuality_.size() == volume_->GetPixelData().GetDepth()); | |
376 | |
377 if (quality >= slicesQuality_[sliceIndex]) | |
378 { | |
379 { | |
380 ImageBuffer3D::SliceWriter writer(volume_->GetPixelData(), VolumeProjection_Axial, sliceIndex); | |
381 Orthanc::ImageProcessing::Copy(writer.GetAccessor(), image); | |
382 } | |
383 | |
384 volume_->IncrementRevision(); | |
385 seriesGeometry_.IncrementSliceRevision(sliceIndex); | |
386 slicesQuality_[sliceIndex] = quality; | |
387 | |
388 BroadcastMessage(DicomVolumeImage::ContentUpdatedMessage(*volume_)); | |
389 } | |
390 | |
391 ScheduleNextSliceDownload(); | |
392 } | |
393 | |
394 | |
395 void OrthancSeriesVolumeProgressiveLoader::LoadBestQualitySliceContent(const GetOrthancImageCommand::SuccessMessage& message) | |
396 { | |
397 SetSliceContent(GetSliceIndexPayload(message.GetOrigin()), message.GetImage(), BEST_QUALITY); | |
398 } | |
399 | |
400 | |
401 void OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent(const GetOrthancWebViewerJpegCommand::SuccessMessage& message) | |
402 { | |
403 unsigned int quality; | |
404 | |
405 switch (message.GetOrigin().GetQuality()) | |
406 { | |
407 case 50: | |
408 quality = LOW_QUALITY; | |
409 break; | |
410 | |
411 case 90: | |
412 quality = MIDDLE_QUALITY; | |
413 break; | |
414 | |
415 default: | |
416 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
417 } | |
418 | |
419 SetSliceContent(GetSliceIndexPayload(message.GetOrigin()), message.GetImage(), quality); | |
420 } | |
421 | |
422 | |
423 OrthancSeriesVolumeProgressiveLoader::OrthancSeriesVolumeProgressiveLoader(const boost::shared_ptr<DicomVolumeImage>& volume, | |
424 IOracle& oracle, | |
425 IObservable& oracleObservable) : | |
426 oracle_(oracle), | |
427 active_(false), | |
428 simultaneousDownloads_(4), | |
429 volume_(volume), | |
937
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
430 sorter_(new BasicFetchingItemsSorter::Factory), |
86ac61a040c9
Added getters and notifications to allow clients of the loaders (DicomStructureSetLoader, OrthancSeriesVolumeProgressiveLoader and OrthancMultiframeVolumeLoader) to know when the loading is finished + added ability for SDL event loop to execute a callback repeatedly (used to check the view loading state)
Benjamin Golinvaux <bgo@osimis.io>
parents:
935
diff
changeset
|
431 volumeImageReadyInHighQuality_(false) |
814 | 432 { |
1065
9d42f89b8c3c
improved readability
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1064
diff
changeset
|
433 // TODO => Move this out of constructor |
9d42f89b8c3c
improved readability
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1064
diff
changeset
|
434 Register<OrthancRestApiCommand::SuccessMessage> |
9d42f89b8c3c
improved readability
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1064
diff
changeset
|
435 (oracleObservable, &OrthancSeriesVolumeProgressiveLoader::LoadGeometry); |
9d42f89b8c3c
improved readability
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1064
diff
changeset
|
436 |
9d42f89b8c3c
improved readability
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1064
diff
changeset
|
437 Register<GetOrthancImageCommand::SuccessMessage> |
9d42f89b8c3c
improved readability
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1064
diff
changeset
|
438 (oracleObservable, &OrthancSeriesVolumeProgressiveLoader::LoadBestQualitySliceContent); |
9d42f89b8c3c
improved readability
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1064
diff
changeset
|
439 |
9d42f89b8c3c
improved readability
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1064
diff
changeset
|
440 Register<GetOrthancWebViewerJpegCommand::SuccessMessage> |
9d42f89b8c3c
improved readability
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1064
diff
changeset
|
441 (oracleObservable, &OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent); |
814 | 442 } |
443 | |
935
401808e7ff2e
Added traces in LoaderCache objects dtors + fuse to prevent dead weak ptrs to be calleds in VisitWdigets (in GuiAdapter.h)
Benjamin Golinvaux <bgo@osimis.io>
parents:
933
diff
changeset
|
444 OrthancSeriesVolumeProgressiveLoader::~OrthancSeriesVolumeProgressiveLoader() |
401808e7ff2e
Added traces in LoaderCache objects dtors + fuse to prevent dead weak ptrs to be calleds in VisitWdigets (in GuiAdapter.h)
Benjamin Golinvaux <bgo@osimis.io>
parents:
933
diff
changeset
|
445 { |
401808e7ff2e
Added traces in LoaderCache objects dtors + fuse to prevent dead weak ptrs to be calleds in VisitWdigets (in GuiAdapter.h)
Benjamin Golinvaux <bgo@osimis.io>
parents:
933
diff
changeset
|
446 LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::~OrthancSeriesVolumeProgressiveLoader()"; |
401808e7ff2e
Added traces in LoaderCache objects dtors + fuse to prevent dead weak ptrs to be calleds in VisitWdigets (in GuiAdapter.h)
Benjamin Golinvaux <bgo@osimis.io>
parents:
933
diff
changeset
|
447 } |
814 | 448 |
449 void OrthancSeriesVolumeProgressiveLoader::SetSimultaneousDownloads(unsigned int count) | |
450 { | |
451 if (active_) | |
452 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
949
diff
changeset
|
453 LOG(ERROR) << "OrthancSeriesVolumeProgressiveLoader::SetSimultaneousDownloads(): (active_)"; |
814 | 454 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
455 } | |
456 else if (count == 0) | |
457 { | |
458 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
459 } | |
460 else | |
461 { | |
462 simultaneousDownloads_ = count; | |
463 } | |
464 } | |
465 | |
466 | |
467 void OrthancSeriesVolumeProgressiveLoader::LoadSeries(const std::string& seriesId) | |
468 { | |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
913
diff
changeset
|
469 // LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries seriesId=" << seriesId; |
814 | 470 if (active_) |
471 { | |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
913
diff
changeset
|
472 // LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries NOT ACTIVE! --> ERROR"; |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
949
diff
changeset
|
473 LOG(ERROR) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries(const std::string& seriesId): (active_)"; |
814 | 474 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
475 } | |
476 else | |
477 { | |
478 active_ = true; | |
479 | |
480 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); | |
481 command->SetUri("/series/" + seriesId + "/instances-tags"); | |
482 | |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
913
diff
changeset
|
483 // LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries about to call oracle_.Schedule"; |
1075 | 484 boost::shared_ptr<IObserver> observer(GetSharedObserver()); |
485 oracle_.Schedule(observer, command.release()); | |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
913
diff
changeset
|
486 // LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries called oracle_.Schedule"; |
814 | 487 } |
488 } | |
489 | |
490 | |
491 IVolumeSlicer::IExtractedSlice* | |
492 OrthancSeriesVolumeProgressiveLoader::ExtractSlice(const CoordinateSystem3D& cuttingPlane) | |
493 { | |
494 if (volume_->HasGeometry()) | |
495 { | |
496 return new ExtractedSlice(*this, cuttingPlane); | |
497 } | |
498 else | |
499 { | |
500 return new IVolumeSlicer::InvalidSlice; | |
501 } | |
502 } | |
503 } |