Mercurial > hg > orthanc-stone
comparison Framework/Deprecated/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp @ 1320:7702ad9b7011 broker
OrthancSeriesVolumeProgressiveLoader : PNG quality only!
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 17 Mar 2020 19:21:01 +0100 |
parents | cbfdba08e039 |
children | 4f8db2d202c8 |
comparison
equal
deleted
inserted
replaced
1319:0290b7060167 | 1320:7702ad9b7011 |
---|---|
190 | 190 |
191 double spacingZ; | 191 double spacingZ; |
192 | 192 |
193 if (slices.ComputeSpacingBetweenSlices(spacingZ)) | 193 if (slices.ComputeSpacingBetweenSlices(spacingZ)) |
194 { | 194 { |
195 LOG(INFO) << "Computed spacing between slices: " << spacingZ << "mm"; | 195 LOG(TRACE) << "Computed spacing between slices: " << spacingZ << "mm"; |
196 | 196 |
197 const OrthancStone::DicomInstanceParameters& parameters = *slices_[0]; | 197 const OrthancStone::DicomInstanceParameters& parameters = *slices_[0]; |
198 | 198 |
199 geometry_.reset(new OrthancStone::VolumeImageGeometry); | 199 geometry_.reset(new OrthancStone::VolumeImageGeometry); |
200 geometry_->SetSizeInVoxels(parameters.GetImageInformation().GetWidth(), | 200 geometry_->SetSizeInVoxels(parameters.GetImageInformation().GetWidth(), |
262 | 262 |
263 unsigned int sliceIndex, quality; | 263 unsigned int sliceIndex, quality; |
264 | 264 |
265 if (strategy_->GetNext(sliceIndex, quality)) | 265 if (strategy_->GetNext(sliceIndex, quality)) |
266 { | 266 { |
267 | |
268 #if USE_SINGLE_QUALITY | |
269 assert(quality == SINGLE_QUALITY); | |
270 #else | |
267 assert(quality <= BEST_QUALITY); | 271 assert(quality <= BEST_QUALITY); |
272 #endif | |
268 | 273 |
269 const OrthancStone::DicomInstanceParameters& slice = seriesGeometry_.GetSliceParameters(sliceIndex); | 274 const OrthancStone::DicomInstanceParameters& slice = seriesGeometry_.GetSliceParameters(sliceIndex); |
270 | 275 |
271 const std::string& instance = slice.GetOrthancInstanceIdentifier(); | 276 const std::string& instance = slice.GetOrthancInstanceIdentifier(); |
272 if (instance.empty()) | 277 if (instance.empty()) |
274 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | 279 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
275 } | 280 } |
276 | 281 |
277 std::unique_ptr<OrthancStone::OracleCommandBase> command; | 282 std::unique_ptr<OrthancStone::OracleCommandBase> command; |
278 | 283 |
284 #if USE_SINGLE_QUALITY | |
285 #else | |
279 if (quality == BEST_QUALITY) | 286 if (quality == BEST_QUALITY) |
287 #endif | |
280 { | 288 { |
281 std::unique_ptr<OrthancStone::GetOrthancImageCommand> tmp(new OrthancStone::GetOrthancImageCommand); | 289 std::unique_ptr<OrthancStone::GetOrthancImageCommand> tmp(new OrthancStone::GetOrthancImageCommand); |
282 // TODO: review the following comment. | 290 // TODO: review the following comment. |
283 // - Commented out by bgo on 2019-07-19 | reason: Alain has seen cases | 291 // - Commented out by bgo on 2019-07-19 | reason: Alain has seen cases |
284 // where gzipping the uint16 image took 11 sec to produce 5mb. | 292 // where gzipping the uint16 image took 11 sec to produce 5mb. |
288 // compression. Furthermore, NOT | 296 // compression. Furthermore, NOT |
289 tmp->SetHttpHeader("Accept-Encoding", "gzip"); | 297 tmp->SetHttpHeader("Accept-Encoding", "gzip"); |
290 tmp->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Pam))); | 298 tmp->SetHttpHeader("Accept", std::string(Orthanc::EnumerationToString(Orthanc::MimeType_Pam))); |
291 tmp->SetInstanceUri(instance, slice.GetExpectedPixelFormat()); | 299 tmp->SetInstanceUri(instance, slice.GetExpectedPixelFormat()); |
292 tmp->SetExpectedPixelFormat(slice.GetExpectedPixelFormat()); | 300 tmp->SetExpectedPixelFormat(slice.GetExpectedPixelFormat()); |
301 //LOG(INFO) | |
302 // << "OrthancSeriesVolumeProgressiveLoader.ScheduleNextSliceDownload()" | |
303 // << " sliceIndex = " << sliceIndex << " slice quality = " << quality | |
304 // << " URI = " << tmp->GetUri(); | |
293 command.reset(tmp.release()); | 305 command.reset(tmp.release()); |
294 } | 306 } |
307 #if USE_SINGLE_QUALITY | |
308 #else | |
295 else | 309 else |
296 { | 310 { |
297 std::unique_ptr<OrthancStone::GetOrthancWebViewerJpegCommand> tmp(new OrthancStone::GetOrthancWebViewerJpegCommand); | 311 std::unique_ptr<OrthancStone::GetOrthancWebViewerJpegCommand> tmp(new OrthancStone::GetOrthancWebViewerJpegCommand); |
298 // TODO: review the following comment. Commented out by bgo on 2019-07-19 | 312 // TODO: review the following comment. Commented out by bgo on 2019-07-19 |
299 // (gzip for jpeg seems overkill) | 313 // (gzip for jpeg seems overkill) |
300 //tmp->SetHttpHeader("Accept-Encoding", "gzip"); | 314 //tmp->SetHttpHeader("Accept-Encoding", "gzip"); |
301 tmp->SetInstance(instance); | 315 tmp->SetInstance(instance); |
302 tmp->SetQuality((quality == 0 ? 50 : 90)); | 316 tmp->SetQuality((quality == 0 ? 50 : 90)); |
303 tmp->SetExpectedPixelFormat(slice.GetExpectedPixelFormat()); | 317 tmp->SetExpectedPixelFormat(slice.GetExpectedPixelFormat()); |
318 LOG(TRACE) | |
319 << "OrthancSeriesVolumeProgressiveLoader.ScheduleNextSliceDownload()" | |
320 << " sliceIndex = " << sliceIndex << " slice quality = " << quality; | |
304 command.reset(tmp.release()); | 321 command.reset(tmp.release()); |
305 } | 322 } |
323 #endif | |
306 | 324 |
307 command->AcquirePayload(new Orthanc::SingleValueObject<unsigned int>(sliceIndex)); | 325 command->AcquirePayload(new Orthanc::SingleValueObject<unsigned int>(sliceIndex)); |
308 | 326 |
309 { | 327 { |
310 std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock()); | 328 std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock()); |
366 | 384 |
367 volume_->Initialize(seriesGeometry_.GetImageGeometry(), parameters.GetExpectedPixelFormat()); | 385 volume_->Initialize(seriesGeometry_.GetImageGeometry(), parameters.GetExpectedPixelFormat()); |
368 volume_->SetDicomParameters(parameters); | 386 volume_->SetDicomParameters(parameters); |
369 volume_->GetPixelData().Clear(); | 387 volume_->GetPixelData().Clear(); |
370 | 388 |
371 strategy_.reset(new OrthancStone::BasicFetchingStrategy(sorter_->CreateSorter(static_cast<unsigned int>(slicesCount)), BEST_QUALITY)); | 389 #if USE_SINGLE_QUALITY |
372 | 390 strategy_.reset(new OrthancStone::BasicFetchingStrategy( |
391 sorter_->CreateSorter(static_cast<unsigned int>(slicesCount)), | |
392 SINGLE_QUALITY)); | |
393 #else | |
394 strategy_.reset(new OrthancStone::BasicFetchingStrategy( | |
395 sorter_->CreateSorter(static_cast<unsigned int>(slicesCount)), | |
396 BEST_QUALITY)); | |
397 #endif | |
398 | |
373 assert(simultaneousDownloads_ != 0); | 399 assert(simultaneousDownloads_ != 0); |
374 for (unsigned int i = 0; i < simultaneousDownloads_; i++) | 400 for (unsigned int i = 0; i < simultaneousDownloads_; i++) |
375 { | 401 { |
376 ScheduleNextSliceDownload(); | 402 ScheduleNextSliceDownload(); |
377 } | 403 } |
385 | 411 |
386 void OrthancSeriesVolumeProgressiveLoader::SetSliceContent(unsigned int sliceIndex, | 412 void OrthancSeriesVolumeProgressiveLoader::SetSliceContent(unsigned int sliceIndex, |
387 const Orthanc::ImageAccessor& image, | 413 const Orthanc::ImageAccessor& image, |
388 unsigned int quality) | 414 unsigned int quality) |
389 { | 415 { |
390 LOG(ERROR) << "SetSliceContent sliceIndex = " << sliceIndex; | |
391 assert(sliceIndex < slicesQuality_.size() && | 416 assert(sliceIndex < slicesQuality_.size() && |
392 slicesQuality_.size() == volume_->GetPixelData().GetDepth()); | 417 slicesQuality_.size() == volume_->GetPixelData().GetDepth()); |
393 | 418 |
394 if (quality >= slicesQuality_[sliceIndex]) | 419 if (quality >= slicesQuality_[sliceIndex]) |
395 { | 420 { |
402 seriesGeometry_.IncrementSliceRevision(sliceIndex); | 427 seriesGeometry_.IncrementSliceRevision(sliceIndex); |
403 slicesQuality_[sliceIndex] = quality; | 428 slicesQuality_[sliceIndex] = quality; |
404 | 429 |
405 BroadcastMessage(OrthancStone::DicomVolumeImage::ContentUpdatedMessage(*volume_)); | 430 BroadcastMessage(OrthancStone::DicomVolumeImage::ContentUpdatedMessage(*volume_)); |
406 } | 431 } |
407 | 432 LOG(TRACE) << "SetSliceContent sliceIndex = " << sliceIndex << " -- will " |
433 << " now call ScheduleNextSliceDownload()"; | |
408 ScheduleNextSliceDownload(); | 434 ScheduleNextSliceDownload(); |
409 } | 435 } |
410 | 436 |
411 | |
412 void OrthancSeriesVolumeProgressiveLoader::LoadBestQualitySliceContent(const OrthancStone::GetOrthancImageCommand::SuccessMessage& message) | 437 void OrthancSeriesVolumeProgressiveLoader::LoadBestQualitySliceContent(const OrthancStone::GetOrthancImageCommand::SuccessMessage& message) |
413 { | 438 { |
439 #if USE_SINGLE_QUALITY | |
440 SetSliceContent(GetSliceIndexPayload(message.GetOrigin()), message.GetImage(), SINGLE_QUALITY); | |
441 #else | |
414 SetSliceContent(GetSliceIndexPayload(message.GetOrigin()), message.GetImage(), BEST_QUALITY); | 442 SetSliceContent(GetSliceIndexPayload(message.GetOrigin()), message.GetImage(), BEST_QUALITY); |
415 } | 443 #endif |
416 | 444 } |
417 | 445 |
446 #if USE_SINGLE_QUALITY | |
447 #else | |
418 void OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent(const OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage& message) | 448 void OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent(const OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage& message) |
419 { | 449 { |
420 LOG(ERROR) << "OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent"; | 450 LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent"; |
421 unsigned int quality; | 451 unsigned int quality; |
422 | 452 |
423 switch (dynamic_cast<const OrthancStone::GetOrthancWebViewerJpegCommand&>(message.GetOrigin()).GetQuality()) | 453 switch (dynamic_cast<const OrthancStone::GetOrthancWebViewerJpegCommand&>(message.GetOrigin()).GetQuality()) |
424 { | 454 { |
425 case 50: | 455 case 50: |
434 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | 464 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
435 } | 465 } |
436 | 466 |
437 SetSliceContent(GetSliceIndexPayload(message.GetOrigin()), message.GetImage(), quality); | 467 SetSliceContent(GetSliceIndexPayload(message.GetOrigin()), message.GetImage(), quality); |
438 } | 468 } |
439 | 469 #endif |
440 | 470 |
441 OrthancSeriesVolumeProgressiveLoader::OrthancSeriesVolumeProgressiveLoader( | 471 OrthancSeriesVolumeProgressiveLoader::OrthancSeriesVolumeProgressiveLoader( |
442 OrthancStone::ILoadersContext& loadersContext, | 472 OrthancStone::ILoadersContext& loadersContext, |
443 const boost::shared_ptr<OrthancStone::DicomVolumeImage>& volume) | 473 const boost::shared_ptr<OrthancStone::DicomVolumeImage>& volume) |
444 : loadersContext_(loadersContext) | 474 : loadersContext_(loadersContext) |
466 | 496 |
467 obj->Register<OrthancStone::GetOrthancImageCommand::SuccessMessage>( | 497 obj->Register<OrthancStone::GetOrthancImageCommand::SuccessMessage>( |
468 lock->GetOracleObservable(), | 498 lock->GetOracleObservable(), |
469 &OrthancSeriesVolumeProgressiveLoader::LoadBestQualitySliceContent); | 499 &OrthancSeriesVolumeProgressiveLoader::LoadBestQualitySliceContent); |
470 | 500 |
501 #if USE_SINGLE_QUALITY | |
502 #else | |
471 obj->Register<OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage>( | 503 obj->Register<OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage>( |
472 lock->GetOracleObservable(), | 504 lock->GetOracleObservable(), |
473 &OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent); | 505 &OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent); |
474 | 506 #endif |
475 return obj; | 507 return obj; |
476 } | 508 } |
477 | 509 |
478 | 510 |
479 OrthancSeriesVolumeProgressiveLoader::~OrthancSeriesVolumeProgressiveLoader() | 511 OrthancSeriesVolumeProgressiveLoader::~OrthancSeriesVolumeProgressiveLoader() |