Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp @ 1924:f4050908c6bc
display of overlays
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Mar 2022 12:24:35 +0100 |
parents | ed4831e08961 |
children | d84bdcbd8bf1 |
comparison
equal
deleted
inserted
replaced
1923:f4cdcba8c32a | 1924:f4050908c6bc |
---|---|
353 if (image.GetFormat() != Orthanc::PixelFormat_Float32) | 353 if (image.GetFormat() != Orthanc::PixelFormat_Float32) |
354 { | 354 { |
355 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | 355 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
356 } | 356 } |
357 | 357 |
358 double factor = data_.doseGridScaling_; | 358 double scaling = data_.doseGridScaling_; |
359 double offset = 0.0; | 359 double offset = 0.0; |
360 | 360 |
361 if (data_.hasRescale_) | 361 if (data_.hasRescale_) |
362 { | 362 { |
363 factor *= data_.rescaleSlope_; | 363 scaling *= data_.rescaleSlope_; |
364 offset = data_.rescaleIntercept_; | 364 offset = data_.rescaleIntercept_; |
365 } | 365 } |
366 | 366 |
367 if (!LinearAlgebra::IsNear(factor, 1) || | 367 Orthanc::ImageProcessing::ShiftScale2(image, offset, scaling, false); |
368 !LinearAlgebra::IsNear(offset, 0)) | 368 } |
369 { | 369 |
370 const unsigned int width = image.GetWidth(); | |
371 const unsigned int height = image.GetHeight(); | |
372 | |
373 for (unsigned int y = 0; y < height; y++) | |
374 { | |
375 float* p = reinterpret_cast<float*>(image.GetRow(y)); | |
376 | |
377 if (useDouble) | |
378 { | |
379 // Slower, accurate implementation using double | |
380 for (unsigned int x = 0; x < width; x++, p++) | |
381 { | |
382 double value = static_cast<double>(*p); | |
383 *p = static_cast<float>(value * factor + offset); | |
384 } | |
385 } | |
386 else | |
387 { | |
388 // Fast, approximate implementation using float | |
389 for (unsigned int x = 0; x < width; x++, p++) | |
390 { | |
391 *p = (*p) * static_cast<float>(factor) + static_cast<float>(offset); | |
392 } | |
393 } | |
394 } | |
395 } | |
396 } | |
397 | 370 |
398 double DicomInstanceParameters::GetRescaleIntercept() const | 371 double DicomInstanceParameters::GetRescaleIntercept() const |
399 { | 372 { |
400 if (data_.hasRescale_) | 373 if (data_.hasRescale_) |
401 { | 374 { |
684 std::unique_ptr<LookupTableTextureSceneLayer> texture(CreateLookupTableTexture(overlay)); | 657 std::unique_ptr<LookupTableTextureSceneLayer> texture(CreateLookupTableTexture(overlay)); |
685 | 658 |
686 texture->SetOrigin(static_cast<double>(originX - 1) * texture->GetPixelSpacingX(), | 659 texture->SetOrigin(static_cast<double>(originX - 1) * texture->GetPixelSpacingX(), |
687 static_cast<double>(originY - 1) * texture->GetPixelSpacingY()); | 660 static_cast<double>(originY - 1) * texture->GetPixelSpacingY()); |
688 | 661 |
662 std::vector<uint8_t> lut(4 * 256); | |
663 for (size_t i = 0; i < 256; i++) | |
664 { | |
665 if (i < 127) | |
666 { | |
667 // Black pixels are converted to transparent pixels | |
668 lut[4 * i] = 0; | |
669 lut[4 * i + 1] = 0; | |
670 lut[4 * i + 2] = 0; | |
671 lut[4 * i + 3] = 0; // alpha | |
672 } | |
673 else | |
674 { | |
675 // White pixels are converted to opaque white | |
676 lut[4 * i] = 255; | |
677 lut[4 * i + 1] = 255; | |
678 lut[4 * i + 2] = 255; | |
679 lut[4 * i + 3] = 255; // alpha | |
680 } | |
681 } | |
682 | |
683 texture->SetLookupTable(lut); | |
684 | |
689 return texture.release(); | 685 return texture.release(); |
690 } | 686 } |
691 | 687 |
692 | 688 |
693 unsigned int DicomInstanceParameters::GetIndexInSeries() const | 689 unsigned int DicomInstanceParameters::GetIndexInSeries() const |
704 } | 700 } |
705 | 701 |
706 | 702 |
707 double DicomInstanceParameters::ApplyRescale(double value) const | 703 double DicomInstanceParameters::ApplyRescale(double value) const |
708 { | 704 { |
709 double factor = data_.doseGridScaling_; | 705 double scaling = data_.doseGridScaling_; |
710 double offset = 0.0; | 706 double offset = 0.0; |
711 | 707 |
712 if (data_.hasRescale_) | 708 if (data_.hasRescale_) |
713 { | 709 { |
714 factor *= data_.rescaleSlope_; | 710 scaling *= data_.rescaleSlope_; |
715 offset = data_.rescaleIntercept_; | 711 offset = data_.rescaleIntercept_; |
716 } | 712 } |
717 | 713 |
718 return (value * factor + offset); | 714 return (value * scaling + offset); |
719 } | 715 } |
720 | 716 |
721 | 717 |
722 bool DicomInstanceParameters::ComputeRegularSpacing(double& spacing) const | 718 bool DicomInstanceParameters::ComputeRegularSpacing(double& spacing) const |
723 { | 719 { |