comparison Framework/Toolbox/OrthancSlicesLoader.cpp @ 318:3a4ca166fafa am-2

ImageAccessor refactoring + implemented Image Cache in SmartLoader
author am@osimis.io
date Mon, 08 Oct 2018 17:10:08 +0200
parents b4abaeb783b1
children c34784e5f299
comparison
equal deleted inserted replaced
317:b66d13708f40 318:3a4ca166fafa
171 } 171 }
172 172
173 }; 173 };
174 174
175 void OrthancSlicesLoader::NotifySliceImageSuccess(const Operation& operation, 175 void OrthancSlicesLoader::NotifySliceImageSuccess(const Operation& operation,
176 std::auto_ptr<Orthanc::ImageAccessor>& image) 176 boost::shared_ptr<Orthanc::ImageAccessor> image)
177 { 177 {
178 if (image.get() == NULL) 178 if (image.get() == NULL)
179 { 179 {
180 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); 180 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
181 } 181 }
339 339
340 340
341 void OrthancSlicesLoader::ParseSliceImagePng(const OrthancApiClient::BinaryResponseReadyMessage& message) 341 void OrthancSlicesLoader::ParseSliceImagePng(const OrthancApiClient::BinaryResponseReadyMessage& message)
342 { 342 {
343 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(*message.Payload); 343 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(*message.Payload);
344 std::auto_ptr<Orthanc::ImageAccessor> image; 344 boost::shared_ptr<Orthanc::ImageAccessor> image;
345 345
346 try 346 try
347 { 347 {
348 image.reset(new Orthanc::PngReader); 348 image.reset(new Orthanc::PngReader);
349 dynamic_cast<Orthanc::PngReader&>(*image).ReadFromMemory(message.Answer, message.AnswerSize); 349 dynamic_cast<Orthanc::PngReader&>(*image).ReadFromMemory(message.Answer, message.AnswerSize);
379 } 379 }
380 380
381 void OrthancSlicesLoader::ParseSliceImagePam(const OrthancApiClient::BinaryResponseReadyMessage& message) 381 void OrthancSlicesLoader::ParseSliceImagePam(const OrthancApiClient::BinaryResponseReadyMessage& message)
382 { 382 {
383 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(*message.Payload); 383 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(*message.Payload);
384 std::auto_ptr<Orthanc::ImageAccessor> image; 384 boost::shared_ptr<Orthanc::ImageAccessor> image;
385 385
386 try 386 try
387 { 387 {
388 image.reset(new Orthanc::PamReader); 388 image.reset(new Orthanc::PamReader);
389 dynamic_cast<Orthanc::PamReader&>(*image).ReadFromMemory(std::string(reinterpret_cast<const char*>(message.Answer), message.AnswerSize)); 389 dynamic_cast<Orthanc::PamReader&>(*image).ReadFromMemory(std::string(reinterpret_cast<const char*>(message.Answer), message.AnswerSize));
459 { 459 {
460 isSigned = info["IsSigned"].asBool(); 460 isSigned = info["IsSigned"].asBool();
461 } 461 }
462 } 462 }
463 463
464 std::auto_ptr<Orthanc::ImageAccessor> reader; 464 boost::shared_ptr<Orthanc::ImageAccessor> reader;
465 465
466 { 466 {
467 std::string jpeg; 467 std::string jpeg;
468 //Orthanc::Toolbox::DecodeBase64(jpeg, info["PixelData"].asString()); 468 //Orthanc::Toolbox::DecodeBase64(jpeg, info["PixelData"].asString());
469 jpeg = base64_decode(info["PixelData"].asString()); 469 jpeg = base64_decode(info["PixelData"].asString());
546 NotifySliceImageError(operation); 546 NotifySliceImageError(operation);
547 return; 547 return;
548 } 548 }
549 549
550 // Decode a grayscale JPEG 8bpp image coming from the Web viewer 550 // Decode a grayscale JPEG 8bpp image coming from the Web viewer
551 std::auto_ptr<Orthanc::ImageAccessor> image 551 boost::shared_ptr<Orthanc::ImageAccessor> image
552 (new Orthanc::Image(expectedFormat, reader->GetWidth(), reader->GetHeight(), false)); 552 (new Orthanc::Image(expectedFormat, reader->GetWidth(), reader->GetHeight(), false));
553 553
554 Orthanc::ImageProcessing::Convert(*image, *reader); 554 Orthanc::ImageProcessing::Convert(*image, *reader);
555 reader.reset(NULL); 555 reader = NULL;
556 556
557 float scaling = static_cast<float>(stretchHigh - stretchLow) / 255.0f; 557 float scaling = static_cast<float>(stretchHigh - stretchLow) / 255.0f;
558 558
559 if (!LinearAlgebra::IsCloseToZero(scaling)) 559 if (!LinearAlgebra::IsCloseToZero(scaling))
560 { 560 {
565 NotifySliceImageSuccess(operation, image); 565 NotifySliceImageSuccess(operation, image);
566 } 566 }
567 567
568 568
569 class StringImage : 569 class StringImage :
570 public Orthanc::ImageAccessor, 570 public Orthanc::ImageAccessor
571 public boost::noncopyable
572 { 571 {
573 private: 572 private:
574 std::string buffer_; 573 std::string buffer_;
575 574
576 public: 575 public:
611 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 && 610 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 &&
612 raw.size() == info.GetWidth() * info.GetHeight() * 4) 611 raw.size() == info.GetWidth() * info.GetHeight() * 4)
613 { 612 {
614 // This is the case of RT-DOSE (uint32_t values) 613 // This is the case of RT-DOSE (uint32_t values)
615 614
616 std::auto_ptr<Orthanc::ImageAccessor> image 615 boost::shared_ptr<Orthanc::ImageAccessor> image
617 (new StringImage(Orthanc::PixelFormat_Grayscale32, info.GetWidth(), 616 (new StringImage(Orthanc::PixelFormat_Grayscale32, info.GetWidth(),
618 info.GetHeight(), raw)); 617 info.GetHeight(), raw));
619 618
620 // TODO - Only for big endian 619 // TODO - Only for big endian
621 for (unsigned int y = 0; y < image->GetHeight(); y++) 620 for (unsigned int y = 0; y < image->GetHeight(); y++)
635 info.GetChannelCount() == 1 && 634 info.GetChannelCount() == 1 &&
636 !info.IsSigned() && 635 !info.IsSigned() &&
637 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 && 636 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 &&
638 raw.size() == info.GetWidth() * info.GetHeight() * 2) 637 raw.size() == info.GetWidth() * info.GetHeight() * 2)
639 { 638 {
640 std::auto_ptr<Orthanc::ImageAccessor> image 639 boost::shared_ptr<Orthanc::ImageAccessor> image
641 (new StringImage(Orthanc::PixelFormat_Grayscale16, info.GetWidth(), 640 (new StringImage(Orthanc::PixelFormat_Grayscale16, info.GetWidth(),
642 info.GetHeight(), raw)); 641 info.GetHeight(), raw));
643 642
644 // TODO - Big endian ? 643 // TODO - Big endian ?
645 644