Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/OrthancSlicesLoader.cpp @ 300:b4abaeb783b1 am-callable-and-promise
messaging refactoring almost complete: works fine in native
author | am@osimis.io |
---|---|
date | Tue, 18 Sep 2018 15:23:21 +0200 |
parents | 3897f9f28cfa |
children | 3a4ca166fafa |
comparison
equal
deleted
inserted
replaced
299:3897f9f28cfa | 300:b4abaeb783b1 |
---|---|
77 unsigned int frame_; | 77 unsigned int frame_; |
78 unsigned int sliceIndex_; | 78 unsigned int sliceIndex_; |
79 const Slice* slice_; | 79 const Slice* slice_; |
80 std::string instanceId_; | 80 std::string instanceId_; |
81 SliceImageQuality quality_; | 81 SliceImageQuality quality_; |
82 | 82 |
83 Operation(Mode mode) : | 83 Operation(Mode mode) : |
84 mode_(mode) | 84 mode_(mode) |
85 { | 85 { |
86 } | 86 } |
87 | 87 |
88 public: | 88 public: |
89 Mode GetMode() const | 89 Mode GetMode() const |
90 { | 90 { |
91 return mode_; | 91 return mode_; |
92 } | 92 } |
93 | 93 |
94 SliceImageQuality GetQuality() const | 94 SliceImageQuality GetQuality() const |
95 { | 95 { |
96 assert(mode_ == Mode_LoadImage || | 96 assert(mode_ == Mode_LoadImage || |
97 mode_ == Mode_LoadRawImage); | 97 mode_ == Mode_LoadRawImage); |
98 return quality_; | 98 return quality_; |
99 } | 99 } |
100 | 100 |
101 unsigned int GetSliceIndex() const | 101 unsigned int GetSliceIndex() const |
102 { | 102 { |
103 assert(mode_ == Mode_LoadImage || | 103 assert(mode_ == Mode_LoadImage || |
104 mode_ == Mode_LoadRawImage); | 104 mode_ == Mode_LoadRawImage); |
105 return sliceIndex_; | 105 return sliceIndex_; |
106 } | 106 } |
107 | 107 |
108 const Slice& GetSlice() const | 108 const Slice& GetSlice() const |
109 { | 109 { |
110 assert(mode_ == Mode_LoadImage || | 110 assert(mode_ == Mode_LoadImage || |
111 mode_ == Mode_LoadRawImage); | 111 mode_ == Mode_LoadRawImage); |
112 assert(slice_ != NULL); | 112 assert(slice_ != NULL); |
113 return *slice_; | 113 return *slice_; |
114 } | 114 } |
115 | 115 |
116 unsigned int GetFrame() const | 116 unsigned int GetFrame() const |
117 { | 117 { |
118 assert(mode_ == Mode_FrameGeometry); | 118 assert(mode_ == Mode_FrameGeometry); |
119 return frame_; | 119 return frame_; |
120 } | 120 } |
124 assert(mode_ == Mode_FrameGeometry || | 124 assert(mode_ == Mode_FrameGeometry || |
125 mode_ == Mode_InstanceGeometry); | 125 mode_ == Mode_InstanceGeometry); |
126 return instanceId_; | 126 return instanceId_; |
127 } | 127 } |
128 | 128 |
129 static Operation* DownloadSeriesGeometry() | |
130 { | |
131 return new Operation(Mode_SeriesGeometry); | |
132 } | |
133 | |
134 static Operation* DownloadInstanceGeometry(const std::string& instanceId) | 129 static Operation* DownloadInstanceGeometry(const std::string& instanceId) |
135 { | 130 { |
136 std::auto_ptr<Operation> operation(new Operation(Mode_InstanceGeometry)); | 131 std::auto_ptr<Operation> operation(new Operation(Mode_InstanceGeometry)); |
137 operation->instanceId_ = instanceId; | 132 operation->instanceId_ = instanceId; |
138 return operation.release(); | 133 return operation.release(); |
139 } | 134 } |
140 | 135 |
141 static Operation* DownloadFrameGeometry(const std::string& instanceId, | 136 static Operation* DownloadFrameGeometry(const std::string& instanceId, |
142 unsigned int frame) | 137 unsigned int frame) |
143 { | 138 { |
144 std::auto_ptr<Operation> operation(new Operation(Mode_FrameGeometry)); | 139 std::auto_ptr<Operation> operation(new Operation(Mode_FrameGeometry)); |
145 operation->instanceId_ = instanceId; | 140 operation->instanceId_ = instanceId; |
146 operation->frame_ = frame; | 141 operation->frame_ = frame; |
147 return operation.release(); | 142 return operation.release(); |
148 } | 143 } |
149 | 144 |
150 static Operation* DownloadSliceImage(unsigned int sliceIndex, | 145 static Operation* DownloadSliceImage(unsigned int sliceIndex, |
151 const Slice& slice, | 146 const Slice& slice, |
152 SliceImageQuality quality) | 147 SliceImageQuality quality) |
153 { | 148 { |
154 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadImage)); | 149 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadImage)); |
155 tmp->sliceIndex_ = sliceIndex; | 150 tmp->sliceIndex_ = sliceIndex; |
156 tmp->slice_ = &slice; | 151 tmp->slice_ = &slice; |
157 tmp->quality_ = quality; | 152 tmp->quality_ = quality; |
158 return tmp.release(); | 153 return tmp.release(); |
159 } | 154 } |
160 | 155 |
161 static Operation* DownloadSliceRawImage(unsigned int sliceIndex, | 156 static Operation* DownloadSliceRawImage(unsigned int sliceIndex, |
162 const Slice& slice) | 157 const Slice& slice) |
163 { | 158 { |
164 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadRawImage)); | 159 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadRawImage)); |
165 tmp->sliceIndex_ = sliceIndex; | 160 tmp->sliceIndex_ = sliceIndex; |
175 return tmp.release(); | 170 return tmp.release(); |
176 } | 171 } |
177 | 172 |
178 }; | 173 }; |
179 | 174 |
180 | |
181 class OrthancSlicesLoader::WebCallback : public IWebService::ICallback | |
182 { | |
183 private: | |
184 OrthancSlicesLoader& that_; | |
185 | |
186 public: | |
187 WebCallback(MessageBroker& broker, OrthancSlicesLoader& that) : | |
188 IWebService::ICallback(broker), | |
189 that_(that) | |
190 { | |
191 } | |
192 | |
193 virtual void OnHttpRequestSuccess(const std::string& uri, | |
194 const void* answer, | |
195 size_t answerSize, | |
196 Orthanc::IDynamicObject* payload) | |
197 { | |
198 std::auto_ptr<Operation> operation(dynamic_cast<Operation*>(payload)); | |
199 | |
200 switch (operation->GetMode()) | |
201 { | |
202 case Mode_SeriesGeometry: | |
203 that_.ParseSeriesGeometry(answer, answerSize); | |
204 break; | |
205 | |
206 case Mode_InstanceGeometry: | |
207 that_.ParseInstanceGeometry(operation->GetInstanceId(), answer, answerSize); | |
208 break; | |
209 | |
210 case Mode_FrameGeometry: | |
211 that_.ParseFrameGeometry(operation->GetInstanceId(), | |
212 operation->GetFrame(), answer, answerSize); | |
213 break; | |
214 | |
215 case Mode_LoadImage: | |
216 switch (operation->GetQuality()) | |
217 { | |
218 case SliceImageQuality_FullPng: | |
219 that_.ParseSliceImagePng(*operation, answer, answerSize); | |
220 break; | |
221 case SliceImageQuality_FullPam: | |
222 that_.ParseSliceImagePam(*operation, answer, answerSize); | |
223 break; | |
224 | |
225 case SliceImageQuality_Jpeg50: | |
226 case SliceImageQuality_Jpeg90: | |
227 case SliceImageQuality_Jpeg95: | |
228 that_.ParseSliceImageJpeg(*operation, answer, answerSize); | |
229 break; | |
230 | |
231 default: | |
232 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
233 } | |
234 | |
235 break; | |
236 | |
237 case Mode_LoadRawImage: | |
238 that_.ParseSliceRawImage(*operation, answer, answerSize); | |
239 break; | |
240 | |
241 default: | |
242 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
243 } | |
244 } | |
245 | |
246 virtual void OnHttpRequestError(const std::string& uri, | |
247 Orthanc::IDynamicObject* payload) | |
248 { | |
249 std::auto_ptr<Operation> operation(dynamic_cast<Operation*>(payload)); | |
250 LOG(ERROR) << "Cannot download " << uri; | |
251 | |
252 switch (operation->GetMode()) | |
253 { | |
254 case Mode_FrameGeometry: | |
255 case Mode_SeriesGeometry: | |
256 that_.EmitMessage(SliceGeometryErrorMessage(that_)); | |
257 that_.state_ = State_Error; | |
258 break; | |
259 | |
260 case Mode_LoadImage: | |
261 { | |
262 OrthancSlicesLoader::SliceImageErrorMessage msg(operation->GetSliceIndex(), | |
263 operation->GetSlice(), | |
264 operation->GetQuality()); | |
265 that_.EmitMessage(msg); | |
266 }; break; | |
267 | |
268 default: | |
269 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
270 } | |
271 } | |
272 }; | |
273 | |
274 // void OrthancSlicesLoader::HandleMessage(IObservable& from, const IMessage& message) | |
275 // { | |
276 // // forward messages to its own observers | |
277 // IObservable::broker_.EmitMessage(from, IObservable::observers_, message); | |
278 // } | |
279 | |
280 | |
281 void OrthancSlicesLoader::NotifySliceImageSuccess(const Operation& operation, | 175 void OrthancSlicesLoader::NotifySliceImageSuccess(const Operation& operation, |
282 std::auto_ptr<Orthanc::ImageAccessor>& image) | 176 std::auto_ptr<Orthanc::ImageAccessor>& image) |
283 { | 177 { |
284 if (image.get() == NULL) | 178 if (image.get() == NULL) |
285 { | 179 { |
328 LOG(ERROR) << "This series is empty"; | 222 LOG(ERROR) << "This series is empty"; |
329 EmitMessage(SliceGeometryErrorMessage(*this)); | 223 EmitMessage(SliceGeometryErrorMessage(*this)); |
330 } | 224 } |
331 } | 225 } |
332 | 226 |
333 | 227 void OrthancSlicesLoader::OnGeometryError(const OrthancApiClient::HttpErrorMessage& message) |
334 void OrthancSlicesLoader::ParseSeriesGeometry(const void* answer, | 228 { |
335 size_t size) | 229 EmitMessage(SliceGeometryErrorMessage(*this)); |
336 { | 230 state_ = State_Error; |
337 Json::Value series; | 231 } |
338 if (!MessagingToolbox::ParseJson(series, answer, size) || | 232 |
339 series.type() != Json::objectValue) | 233 void OrthancSlicesLoader::OnSliceImageError(const OrthancApiClient::HttpErrorMessage& message) |
340 { | 234 { |
341 EmitMessage(SliceGeometryErrorMessage(*this)); | 235 NotifySliceImageError(dynamic_cast<const Operation&>(*(message.Payload))); |
342 return; | 236 state_ = State_Error; |
343 } | 237 } |
344 | 238 |
239 void OrthancSlicesLoader::ParseSeriesGeometry(const OrthancApiClient::JsonResponseReadyMessage& message) | |
240 { | |
241 Json::Value series = message.Response; | |
345 Json::Value::Members instances = series.getMemberNames(); | 242 Json::Value::Members instances = series.getMemberNames(); |
346 | 243 |
347 slices_.Reserve(instances.size()); | 244 slices_.Reserve(instances.size()); |
348 | 245 |
349 for (size_t i = 0; i < instances.size(); i++) | 246 for (size_t i = 0; i < instances.size(); i++) |
374 } | 271 } |
375 | 272 |
376 SortAndFinalizeSlices(); | 273 SortAndFinalizeSlices(); |
377 } | 274 } |
378 | 275 |
379 | 276 void OrthancSlicesLoader::ParseInstanceGeometry(const OrthancApiClient::JsonResponseReadyMessage& message) |
380 void OrthancSlicesLoader::ParseInstanceGeometry(const std::string& instanceId, | 277 { |
381 const void* answer, | 278 Json::Value tags = message.Response; |
382 size_t size) | 279 const std::string& instanceId = dynamic_cast<OrthancSlicesLoader::Operation*>(message.Payload)->GetInstanceId(); |
383 { | 280 |
384 Json::Value tags; | |
385 if (!MessagingToolbox::ParseJson(tags, answer, size) || | |
386 tags.type() != Json::objectValue) | |
387 { | |
388 EmitMessage(SliceGeometryErrorMessage(*this)); | |
389 return; | |
390 } | |
391 | |
392 OrthancPlugins::FullOrthancDataset dataset(tags); | 281 OrthancPlugins::FullOrthancDataset dataset(tags); |
393 | 282 |
394 Orthanc::DicomMap dicom; | 283 Orthanc::DicomMap dicom; |
395 MessagingToolbox::ConvertDataset(dicom, dataset); | 284 MessagingToolbox::ConvertDataset(dicom, dataset); |
396 | 285 |
419 | 308 |
420 SortAndFinalizeSlices(); | 309 SortAndFinalizeSlices(); |
421 } | 310 } |
422 | 311 |
423 | 312 |
424 void OrthancSlicesLoader::ParseFrameGeometry(const std::string& instanceId, | 313 void OrthancSlicesLoader::ParseFrameGeometry(const OrthancApiClient::JsonResponseReadyMessage& message) |
425 unsigned int frame, | 314 { |
426 const void* answer, | 315 Json::Value tags = message.Response; |
427 size_t size) | 316 const std::string& instanceId = dynamic_cast<OrthancSlicesLoader::Operation*>(message.Payload)->GetInstanceId(); |
428 { | 317 unsigned int frame = dynamic_cast<OrthancSlicesLoader::Operation*>(message.Payload)->GetFrame(); |
429 Json::Value tags; | 318 |
430 if (!MessagingToolbox::ParseJson(tags, answer, size) || | |
431 tags.type() != Json::objectValue) | |
432 { | |
433 EmitMessage(SliceGeometryErrorMessage(*this)); | |
434 return; | |
435 } | |
436 | |
437 OrthancPlugins::FullOrthancDataset dataset(tags); | 319 OrthancPlugins::FullOrthancDataset dataset(tags); |
438 | 320 |
439 state_ = State_GeometryReady; | 321 state_ = State_GeometryReady; |
440 | 322 |
441 Orthanc::DicomMap dicom; | 323 Orthanc::DicomMap dicom; |
444 std::auto_ptr<Slice> slice(new Slice); | 326 std::auto_ptr<Slice> slice(new Slice); |
445 if (slice->ParseOrthancFrame(dicom, instanceId, frame)) | 327 if (slice->ParseOrthancFrame(dicom, instanceId, frame)) |
446 { | 328 { |
447 LOG(INFO) << "Loaded instance geometry " << instanceId; | 329 LOG(INFO) << "Loaded instance geometry " << instanceId; |
448 slices_.AddSlice(slice.release()); | 330 slices_.AddSlice(slice.release()); |
449 EmitMessage(SliceGeometryErrorMessage(*this)); | 331 EmitMessage(SliceGeometryReadyMessage(*this)); |
450 } | 332 } |
451 else | 333 else |
452 { | 334 { |
453 LOG(WARNING) << "Skipping invalid instance " << instanceId; | 335 LOG(WARNING) << "Skipping invalid instance " << instanceId; |
454 EmitMessage(SliceGeometryErrorMessage(*this)); | 336 EmitMessage(SliceGeometryErrorMessage(*this)); |
455 } | 337 } |
456 } | 338 } |
457 | 339 |
458 | 340 |
459 void OrthancSlicesLoader::ParseSliceImagePng(const Operation& operation, | 341 void OrthancSlicesLoader::ParseSliceImagePng(const OrthancApiClient::BinaryResponseReadyMessage& message) |
460 const void* answer, | 342 { |
461 size_t size) | 343 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(*message.Payload); |
462 { | |
463 std::auto_ptr<Orthanc::ImageAccessor> image; | 344 std::auto_ptr<Orthanc::ImageAccessor> image; |
464 | 345 |
465 try | 346 try |
466 { | 347 { |
467 image.reset(new Orthanc::PngReader); | 348 image.reset(new Orthanc::PngReader); |
468 dynamic_cast<Orthanc::PngReader&>(*image).ReadFromMemory(answer, size); | 349 dynamic_cast<Orthanc::PngReader&>(*image).ReadFromMemory(message.Answer, message.AnswerSize); |
469 } | 350 } |
470 catch (Orthanc::OrthancException&) | 351 catch (Orthanc::OrthancException&) |
471 { | 352 { |
472 NotifySliceImageError(operation); | 353 NotifySliceImageError(operation); |
473 return; | 354 return; |
495 } | 376 } |
496 | 377 |
497 NotifySliceImageSuccess(operation, image); | 378 NotifySliceImageSuccess(operation, image); |
498 } | 379 } |
499 | 380 |
500 void OrthancSlicesLoader::ParseSliceImagePam(const Operation& operation, | 381 void OrthancSlicesLoader::ParseSliceImagePam(const OrthancApiClient::BinaryResponseReadyMessage& message) |
501 const void* answer, | 382 { |
502 size_t size) | 383 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(*message.Payload); |
503 { | |
504 std::auto_ptr<Orthanc::ImageAccessor> image; | 384 std::auto_ptr<Orthanc::ImageAccessor> image; |
505 | 385 |
506 try | 386 try |
507 { | 387 { |
508 image.reset(new Orthanc::PamReader); | 388 image.reset(new Orthanc::PamReader); |
509 dynamic_cast<Orthanc::PamReader&>(*image).ReadFromMemory(std::string(reinterpret_cast<const char*>(answer), size)); | 389 dynamic_cast<Orthanc::PamReader&>(*image).ReadFromMemory(std::string(reinterpret_cast<const char*>(message.Answer), message.AnswerSize)); |
510 } | 390 } |
511 catch (Orthanc::OrthancException&) | 391 catch (Orthanc::OrthancException&) |
512 { | 392 { |
513 NotifySliceImageError(operation); | 393 NotifySliceImageError(operation); |
514 return; | 394 return; |
537 | 417 |
538 NotifySliceImageSuccess(operation, image); | 418 NotifySliceImageSuccess(operation, image); |
539 } | 419 } |
540 | 420 |
541 | 421 |
542 void OrthancSlicesLoader::ParseSliceImageJpeg(const Operation& operation, | 422 void OrthancSlicesLoader::ParseSliceImageJpeg(const OrthancApiClient::JsonResponseReadyMessage& message) |
543 const void* answer, | 423 { |
544 size_t size) | 424 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(*message.Payload); |
545 { | 425 |
546 Json::Value encoded; | 426 Json::Value encoded = message.Response; |
547 if (!MessagingToolbox::ParseJson(encoded, answer, size) || | 427 if (encoded.type() != Json::objectValue || |
548 encoded.type() != Json::objectValue || | |
549 !encoded.isMember("Orthanc") || | 428 !encoded.isMember("Orthanc") || |
550 encoded["Orthanc"].type() != Json::objectValue) | 429 encoded["Orthanc"].type() != Json::objectValue) |
551 { | 430 { |
552 NotifySliceImageError(operation); | 431 NotifySliceImageError(operation); |
553 return; | 432 return; |
712 AssignWritable(format, width, height, | 591 AssignWritable(format, width, height, |
713 Orthanc::GetBytesPerPixel(format) * width, data); | 592 Orthanc::GetBytesPerPixel(format) * width, data); |
714 } | 593 } |
715 }; | 594 }; |
716 | 595 |
717 void OrthancSlicesLoader::ParseSliceRawImage(const Operation& operation, | 596 void OrthancSlicesLoader::ParseSliceRawImage(const OrthancApiClient::BinaryResponseReadyMessage& message) |
718 const void* answer, | 597 { |
719 size_t size) | 598 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(*message.Payload); |
720 { | |
721 Orthanc::GzipCompressor compressor; | 599 Orthanc::GzipCompressor compressor; |
722 | 600 |
723 std::string raw; | 601 std::string raw; |
724 compressor.Uncompress(raw, answer, size); | 602 compressor.Uncompress(raw, message.Answer, message.AnswerSize); |
725 | 603 |
726 const Orthanc::DicomImageInformation& info = operation.GetSlice().GetImageInformation(); | 604 const Orthanc::DicomImageInformation& info = operation.GetSlice().GetImageInformation(); |
727 | 605 |
728 if (info.GetBitsAllocated() == 32 && | 606 if (info.GetBitsAllocated() == 32 && |
729 info.GetBitsStored() == 32 && | 607 info.GetBitsStored() == 32 && |
774 | 652 |
775 } | 653 } |
776 | 654 |
777 | 655 |
778 OrthancSlicesLoader::OrthancSlicesLoader(MessageBroker& broker, | 656 OrthancSlicesLoader::OrthancSlicesLoader(MessageBroker& broker, |
779 //ISliceLoaderObserver& callback, | 657 OrthancApiClient& orthanc) : |
780 IWebService& orthanc) : | |
781 IObservable(broker), | 658 IObservable(broker), |
782 webCallback_(new WebCallback(broker, *this)), | 659 IObserver(broker), |
783 //userCallback_(callback), | |
784 orthanc_(orthanc), | 660 orthanc_(orthanc), |
785 state_(State_Initialization) | 661 state_(State_Initialization) |
786 { | 662 { |
787 DeclareEmittableMessage(MessageType_SliceLoader_GeometryReady); | |
788 DeclareEmittableMessage(MessageType_SliceLoader_GeometryError); | |
789 DeclareEmittableMessage(MessageType_SliceLoader_ImageError); | |
790 DeclareEmittableMessage(MessageType_SliceLoader_ImageReady); | |
791 } | 663 } |
792 | 664 |
793 | 665 |
794 void OrthancSlicesLoader::ScheduleLoadSeries(const std::string& seriesId) | 666 void OrthancSlicesLoader::ScheduleLoadSeries(const std::string& seriesId) |
795 { | 667 { |
798 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 670 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
799 } | 671 } |
800 else | 672 else |
801 { | 673 { |
802 state_ = State_LoadingGeometry; | 674 state_ = State_LoadingGeometry; |
803 std::string uri = "/series/" + seriesId + "/instances-tags"; | 675 orthanc_.GetJsonAsync("/series/" + seriesId + "/instances-tags", |
804 orthanc_.ScheduleGetRequest(*webCallback_, uri, IWebService::Headers(), Operation::DownloadSeriesGeometry()); | 676 new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSeriesGeometry), |
805 } | 677 new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError), |
806 } | 678 NULL); |
807 | 679 } |
680 } | |
808 | 681 |
809 void OrthancSlicesLoader::ScheduleLoadInstance(const std::string& instanceId) | 682 void OrthancSlicesLoader::ScheduleLoadInstance(const std::string& instanceId) |
810 { | 683 { |
811 if (state_ != State_Initialization) | 684 if (state_ != State_Initialization) |
812 { | 685 { |
816 { | 689 { |
817 state_ = State_LoadingGeometry; | 690 state_ = State_LoadingGeometry; |
818 | 691 |
819 // Tag "3004-000c" is "Grid Frame Offset Vector", which is | 692 // Tag "3004-000c" is "Grid Frame Offset Vector", which is |
820 // mandatory to read RT DOSE, but is too long to be returned by default | 693 // mandatory to read RT DOSE, but is too long to be returned by default |
821 std::string uri = "/instances/" + instanceId + "/tags?ignore-length=3004-000c"; | 694 orthanc_.GetJsonAsync("/instances/" + instanceId + "/tags?ignore-length=3004-000c", |
822 orthanc_.ScheduleGetRequest | 695 new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseInstanceGeometry), |
823 (*webCallback_, uri, IWebService::Headers(), Operation::DownloadInstanceGeometry(instanceId)); | 696 new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError), |
697 Operation::DownloadInstanceGeometry(instanceId)); | |
824 } | 698 } |
825 } | 699 } |
826 | 700 |
827 | 701 |
828 void OrthancSlicesLoader::ScheduleLoadFrame(const std::string& instanceId, | 702 void OrthancSlicesLoader::ScheduleLoadFrame(const std::string& instanceId, |
833 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 707 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
834 } | 708 } |
835 else | 709 else |
836 { | 710 { |
837 state_ = State_LoadingGeometry; | 711 state_ = State_LoadingGeometry; |
838 std::string uri = "/instances/" + instanceId + "/tags"; | 712 |
839 orthanc_.ScheduleGetRequest | 713 orthanc_.GetJsonAsync("/instances/" + instanceId + "/tags", |
840 (*webCallback_, uri, IWebService::Headers(), Operation::DownloadFrameGeometry(instanceId, frame)); | 714 new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseFrameGeometry), |
715 new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError), | |
716 Operation::DownloadFrameGeometry(instanceId, frame)); | |
841 } | 717 } |
842 } | 718 } |
843 | 719 |
844 | 720 |
845 bool OrthancSlicesLoader::IsGeometryReady() const | 721 bool OrthancSlicesLoader::IsGeometryReady() const |
904 | 780 |
905 default: | 781 default: |
906 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 782 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
907 } | 783 } |
908 | 784 |
909 IWebService::Headers headers; | 785 orthanc_.GetBinaryAsync(uri, "image/png", |
910 headers["Accept"] = "image/png"; | 786 new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImagePng), |
911 orthanc_.ScheduleGetRequest(*webCallback_, uri, IWebService::Headers(), | 787 new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), |
912 Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPng)); | 788 Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPng)); |
913 } | 789 } |
914 | 790 |
915 void OrthancSlicesLoader::ScheduleSliceImagePam(const Slice& slice, | 791 void OrthancSlicesLoader::ScheduleSliceImagePam(const Slice& slice, |
916 size_t index) | 792 size_t index) |
917 { | 793 { |
934 | 810 |
935 default: | 811 default: |
936 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 812 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
937 } | 813 } |
938 | 814 |
939 IWebService::Headers headers; | 815 orthanc_.GetBinaryAsync(uri, "image/x-portable-arbitrarymap", |
940 headers["Accept"] = "image/x-portable-arbitrarymap"; | 816 new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImagePam), |
941 orthanc_.ScheduleGetRequest(*webCallback_, uri, headers, | 817 new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), |
942 Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPam)); | 818 Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPam)); |
943 } | 819 } |
944 | 820 |
945 | 821 |
946 | 822 |
947 void OrthancSlicesLoader::ScheduleSliceImageJpeg(const Slice& slice, | 823 void OrthancSlicesLoader::ScheduleSliceImageJpeg(const Slice& slice, |
972 std::string uri = ("/web-viewer/instances/jpeg" + | 848 std::string uri = ("/web-viewer/instances/jpeg" + |
973 boost::lexical_cast<std::string>(value) + | 849 boost::lexical_cast<std::string>(value) + |
974 "-" + slice.GetOrthancInstanceId() + "_" + | 850 "-" + slice.GetOrthancInstanceId() + "_" + |
975 boost::lexical_cast<std::string>(slice.GetFrame())); | 851 boost::lexical_cast<std::string>(slice.GetFrame())); |
976 | 852 |
977 orthanc_.ScheduleGetRequest(*webCallback_, uri, IWebService::Headers(), | 853 orthanc_.GetJsonAsync(uri, |
978 Operation::DownloadSliceImage(index, slice, quality)); | 854 new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImageJpeg), |
855 new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), | |
856 Operation::DownloadSliceImage(index, slice, quality)); | |
979 } | 857 } |
980 | 858 |
981 | 859 |
982 | 860 |
983 void OrthancSlicesLoader::ScheduleLoadSliceImage(size_t index, | 861 void OrthancSlicesLoader::ScheduleLoadSliceImage(size_t index, |
1006 } | 884 } |
1007 else | 885 else |
1008 { | 886 { |
1009 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + | 887 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + |
1010 boost::lexical_cast<std::string>(slice.GetFrame()) + "/raw.gz"); | 888 boost::lexical_cast<std::string>(slice.GetFrame()) + "/raw.gz"); |
1011 orthanc_.ScheduleGetRequest(*webCallback_, uri, IWebService::Headers(), | 889 orthanc_.GetBinaryAsync(uri, IWebService::Headers(), |
1012 Operation::DownloadSliceRawImage(index, slice)); | 890 new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceRawImage), |
891 new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), | |
892 Operation::DownloadSliceRawImage(index, slice)); | |
1013 } | 893 } |
1014 } | 894 } |
1015 } | 895 } |