Mercurial > hg > orthanc-stone
diff Framework/Deprecated/Layers/RenderStyle.cpp @ 734:be3671662eec
moved FitWindowingToRange() from ImageBuffer3D to RenderStyle
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 21 May 2019 15:20:04 +0200 |
parents | c35e98d22764 |
children | 2d8ab34c8c91 |
line wrap: on
line diff
--- a/Framework/Deprecated/Layers/RenderStyle.cpp Tue May 21 14:27:52 2019 +0200 +++ b/Framework/Deprecated/Layers/RenderStyle.cpp Tue May 21 15:20:04 2019 +0200 @@ -21,6 +21,9 @@ #include "RenderStyle.h" +#include "../../Volumes/ImageBuffer3D.h" +#include "../Toolbox/DicomFrameConverter.h" + #include <Core/OrthancException.h> namespace Deprecated @@ -70,4 +73,34 @@ drawColor_[1] = green; drawColor_[2] = blue; } + + + bool RenderStyle::FitRange(const OrthancStone::ImageBuffer3D& image, + const DicomFrameConverter& converter) + { + float minValue, maxValue; + + windowing_ = OrthancStone::ImageWindowing_Custom; + + if (image.GetRange(minValue, maxValue)) + { + // casting the narrower type to wider before calling the + operator + // will prevent overflowing (this is why the cast to double is only + // done on the first operand) + customWindowCenter_ = static_cast<float>( + converter.Apply((static_cast<double>(minValue) + maxValue) / 2.0)); + + customWindowWidth_ = static_cast<float>( + converter.Apply(static_cast<double>(maxValue) - minValue)); + + if (customWindowWidth_ > 1) + { + return true; + } + } + + customWindowCenter_ = 128.0; + customWindowWidth_ = 256.0; + return false; + } }