# HG changeset patch # User Sebastien Jodogne # Date 1558636639 -7200 # Node ID 4ba8892870a2cf33a778e77a9e54cb5486f216cd # Parent 55411e7da2f779db1eaf66f336a62b6cc86048b6 improved interface for lookup tables diff -r 55411e7da2f7 -r 4ba8892870a2 Framework/Scene2D/FloatTextureSceneLayer.h --- a/Framework/Scene2D/FloatTextureSceneLayer.h Thu May 23 20:04:33 2019 +0200 +++ b/Framework/Scene2D/FloatTextureSceneLayer.h Thu May 23 20:37:19 2019 +0200 @@ -33,7 +33,7 @@ float customWidth_; public: - // The pixel format must be "Float32" + // The pixel format must be convertible to "Float32" FloatTextureSceneLayer(const Orthanc::ImageAccessor& texture); void SetWindowing(ImageWindowing windowing); diff -r 55411e7da2f7 -r 4ba8892870a2 Framework/Scene2D/LookupTableTextureSceneLayer.cpp --- a/Framework/Scene2D/LookupTableTextureSceneLayer.cpp Thu May 23 20:04:33 2019 +0200 +++ b/Framework/Scene2D/LookupTableTextureSceneLayer.cpp Thu May 23 20:37:19 2019 +0200 @@ -52,12 +52,12 @@ SetTexture(t.release()); } - SetLookupTableGrayscale(1); + SetLookupTableGrayscale(); SetRange(0, 1); } - void LookupTableTextureSceneLayer::SetLookupTableGrayscale(float alpha) + void LookupTableTextureSceneLayer::SetLookupTableGrayscale() { std::vector rgb(3 * 256); @@ -68,18 +68,15 @@ rgb[3 * i + 2] = i; } - SetLookupTableRgb(rgb, alpha); + SetLookupTableRgb(rgb); } - void LookupTableTextureSceneLayer::SetLookupTableRgb(const std::vector& lut, - float alpha) + void LookupTableTextureSceneLayer::SetLookupTableRgb(const std::vector& lut) { - if (lut.size() != 3 * 256 || - alpha < 0 || - alpha > 1) + if (lut.size() != 3 * 256) { - throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); } lut_.resize(4 * 256); @@ -98,14 +95,16 @@ } else { - float r = static_cast(lut[3 * i]) * alpha; - float g = static_cast(lut[3 * i + 1]) * alpha; - float b = static_cast(lut[3 * i + 2]) * alpha; + float a = static_cast(i) / 255.0f; + + float r = static_cast(lut[3 * i]) * a; + float g = static_cast(lut[3 * i + 1]) * a; + float b = static_cast(lut[3 * i + 2]) * a; lut_[4 * i] = static_cast(std::floor(r)); lut_[4 * i + 1] = static_cast(std::floor(g)); lut_[4 * i + 2] = static_cast(std::floor(b)); - lut_[4 * i + 3] = static_cast(std::floor(alpha * 255.0f)); + lut_[4 * i + 3] = static_cast(std::floor(a * 255.0f)); } } @@ -113,25 +112,21 @@ } - void LookupTableTextureSceneLayer::SetLookupTableRgb(const std::string& lut, - float alpha) - { - std::vector tmp; - StringToVector(tmp, lut); - SetLookupTableRgb(tmp, alpha); - } - - void LookupTableTextureSceneLayer::SetLookupTable(const std::vector& lut) { - if (lut.size() != 4 * 256) + if (lut.size() == 4 * 256) + { + lut_ = lut; + IncrementRevision(); + } + else if (lut.size() == 3 * 256) + { + SetLookupTableRgb(lut); + } + else { throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); } - - lut_ = lut; - - IncrementRevision(); } diff -r 55411e7da2f7 -r 4ba8892870a2 Framework/Scene2D/LookupTableTextureSceneLayer.h --- a/Framework/Scene2D/LookupTableTextureSceneLayer.h Thu May 23 20:04:33 2019 +0200 +++ b/Framework/Scene2D/LookupTableTextureSceneLayer.h Thu May 23 20:37:19 2019 +0200 @@ -33,18 +33,16 @@ float maxValue_; std::vector lut_; + void SetLookupTableRgb(const std::vector& lut); + public: - // The pixel format must be "Flot32" + // The pixel format must be convertible to Float32 LookupTableTextureSceneLayer(const Orthanc::ImageAccessor& texture); - void SetLookupTableGrayscale(float alpha); - - void SetLookupTableRgb(const std::vector& lut, - float alpha); + void SetLookupTableGrayscale(); - void SetLookupTableRgb(const std::string& lut, - float alpha); - + // The vector must contain either 3 * 256 values (RGB), or 4 * 256 + // (RGBA). In the RGB case, an alpha channel will be automatically added. void SetLookupTable(const std::vector& lut); void SetLookupTable(const std::string& lut); @@ -64,6 +62,7 @@ return maxValue_; } + // This returns a vector of 4 * 256 values between 0 and 255, in RGBA. const std::vector& GetLookupTable() const { return lut_; diff -r 55411e7da2f7 -r 4ba8892870a2 Samples/Sdl/Loader.cpp --- a/Samples/Sdl/Loader.cpp Thu May 23 20:04:33 2019 +0200 +++ b/Samples/Sdl/Loader.cpp Thu May 23 20:37:19 2019 +0200 @@ -192,7 +192,7 @@ std::auto_ptr tmp(parameters.CreateLookupTableTexture(reader.GetAccessor())); tmp->FitRange(); - tmp->SetLookupTableRgb(lut, 1); + tmp->SetLookupTable(lut); texture.reset(tmp.release()); }