Mercurial > hg > orthanc-wsi
changeset 353:c36a1fee7a7d
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 20 Dec 2024 12:33:10 +0100 |
parents | 25630706f4ed |
children | 5d3672320879 |
files | ViewerPlugin/CMakeLists.txt ViewerPlugin/OrthancPyramidFrameFetcher.cpp ViewerPlugin/OrthancPyramidFrameFetcher.h ViewerPlugin/Plugin.cpp |
diffstat | 4 files changed, 179 insertions(+), 103 deletions(-) [+] |
line wrap: on
line diff
--- a/ViewerPlugin/CMakeLists.txt Fri Dec 20 12:25:37 2024 +0100 +++ b/ViewerPlugin/CMakeLists.txt Fri Dec 20 12:33:10 2024 +0100 @@ -188,6 +188,7 @@ DicomPyramidCache.cpp IIIF.cpp OrthancPluginConnection.cpp + OrthancPyramidFrameFetcher.cpp Plugin.cpp RawTile.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ViewerPlugin/OrthancPyramidFrameFetcher.cpp Fri Dec 20 12:33:10 2024 +0100 @@ -0,0 +1,129 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2023 Osimis S.A., Belgium + * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium + * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "../Framework/PrecompiledHeadersWSI.h" +#include "OrthancPyramidFrameFetcher.h" + +#include "../Framework/Inputs/OnTheFlyPyramid.h" + +#include <Images/Image.h> +#include <Images/ImageProcessing.h> + +#include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" + + +namespace OrthancWSI +{ + void OrthancPyramidFrameFetcher::RenderGrayscale(Orthanc::ImageAccessor& target, + const Orthanc::ImageAccessor& source) + { + Orthanc::Image converted(Orthanc::PixelFormat_Float32, source.GetWidth(), source.GetHeight(), false); + Orthanc::ImageProcessing::Convert(converted, source); + + float minValue, maxValue; + Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, converted); + + assert(minValue <= maxValue); + if (std::abs(maxValue - minValue) < 0.0001) + { + Orthanc::ImageProcessing::Set(target, 0); + } + else + { + const float scaling = 255.0f / (maxValue - minValue); + const float offset = -minValue; + + Orthanc::Image rescaled(Orthanc::PixelFormat_Grayscale8, source.GetWidth(), source.GetHeight(), false); + Orthanc::ImageProcessing::ShiftScale(rescaled, converted, static_cast<float>(offset), static_cast<float>(scaling), false); + Orthanc::ImageProcessing::Convert(target, rescaled); + } + } + + + OrthancPyramidFrameFetcher::OrthancPyramidFrameFetcher(OrthancStone::IOrthancConnection* orthanc, + bool smooth) : + orthanc_(orthanc), + smooth_(smooth) + { + if (orthanc == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); + } + } + + + DecodedTiledPyramid* OrthancPyramidFrameFetcher::Fetch(const std::string &instanceId, + unsigned frameNumber) + { + OrthancPlugins::MemoryBuffer buffer; + buffer.GetDicomInstance(instanceId.c_str()); + + OrthancPlugins::DicomInstance dicom(buffer.GetData(), buffer.GetSize()); + + std::unique_ptr<OrthancPlugins::OrthancImage> frame(dicom.GetDecodedFrame(frameNumber)); + + Orthanc::PixelFormat format; + switch (frame->GetPixelFormat()) + { + case OrthancPluginPixelFormat_RGB24: + format = Orthanc::PixelFormat_RGB24; + break; + + case OrthancPluginPixelFormat_Grayscale8: + format = Orthanc::PixelFormat_Grayscale8; + break; + + case OrthancPluginPixelFormat_Grayscale16: + format = Orthanc::PixelFormat_Grayscale16; + break; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); + } + + Orthanc::ImageAccessor source; + source.AssignReadOnly(format, frame->GetWidth(), frame->GetHeight(), frame->GetPitch(), frame->GetBuffer()); + + std::unique_ptr<Orthanc::ImageAccessor> rendered(new Orthanc::Image(Orthanc::PixelFormat_RGB24, source.GetWidth(), source.GetHeight(), false)); + + switch (format) + { + case Orthanc::PixelFormat_RGB24: + Orthanc::ImageProcessing::Copy(*rendered, source); + break; + + case Orthanc::PixelFormat_Grayscale8: + Orthanc::ImageProcessing::Convert(*rendered, source); + break; + + case Orthanc::PixelFormat_Grayscale16: + RenderGrayscale(*rendered, source); + break; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); + } + + return new OnTheFlyPyramid(rendered.release(), 512, 512, smooth_); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ViewerPlugin/OrthancPyramidFrameFetcher.h Fri Dec 20 12:33:10 2024 +0100 @@ -0,0 +1,48 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2023 Osimis S.A., Belgium + * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium + * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "../Framework/Inputs/DecodedPyramidCache.h" +#include "../Resources/Orthanc/Stone/IOrthancConnection.h" + + +namespace OrthancWSI +{ + class OrthancPyramidFrameFetcher : public DecodedPyramidCache::IPyramidFetcher + { + private: + std::unique_ptr<OrthancStone::IOrthancConnection> orthanc_; + bool smooth_; + + static void RenderGrayscale(Orthanc::ImageAccessor& target, + const Orthanc::ImageAccessor& source); + + public: + OrthancPyramidFrameFetcher(OrthancStone::IOrthancConnection* orthanc, + bool smooth); + + DecodedTiledPyramid* Fetch(const std::string &instanceId, + unsigned frameNumber) ORTHANC_OVERRIDE; + }; +}
--- a/ViewerPlugin/Plugin.cpp Fri Dec 20 12:25:37 2024 +0100 +++ b/ViewerPlugin/Plugin.cpp Fri Dec 20 12:33:10 2024 +0100 @@ -23,6 +23,7 @@ #include "../Framework/PrecompiledHeadersWSI.h" +#include "OrthancPyramidFrameFetcher.h" #include "DicomPyramidCache.h" #include "IIIF.h" #include "RawTile.h" @@ -51,109 +52,6 @@ #define ORTHANC_PLUGIN_NAME "wsi" -namespace OrthancWSI -{ - class OrthancPyramidFrameFetcher : public DecodedPyramidCache::IPyramidFetcher - { - private: - std::unique_ptr<OrthancStone::IOrthancConnection> orthanc_; - bool smooth_; - - static void RenderGrayscale(Orthanc::ImageAccessor& target, - const Orthanc::ImageAccessor& source) - { - Orthanc::Image converted(Orthanc::PixelFormat_Float32, source.GetWidth(), source.GetHeight(), false); - Orthanc::ImageProcessing::Convert(converted, source); - - float minValue, maxValue; - Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, converted); - - assert(minValue <= maxValue); - if (std::abs(maxValue - minValue) < 0.0001) - { - Orthanc::ImageProcessing::Set(target, 0); - } - else - { - const float scaling = 255.0f / (maxValue - minValue); - const float offset = -minValue; - - Orthanc::Image rescaled(Orthanc::PixelFormat_Grayscale8, source.GetWidth(), source.GetHeight(), false); - Orthanc::ImageProcessing::ShiftScale(rescaled, converted, static_cast<float>(offset), static_cast<float>(scaling), false); - Orthanc::ImageProcessing::Convert(target, rescaled); - } - } - - public: - explicit OrthancPyramidFrameFetcher(OrthancStone::IOrthancConnection* orthanc, - bool smooth) : - orthanc_(orthanc), - smooth_(smooth) - { - if (orthanc == NULL) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); - } - } - - DecodedTiledPyramid* Fetch(const std::string &instanceId, - unsigned frameNumber) ORTHANC_OVERRIDE - { - OrthancPlugins::MemoryBuffer buffer; - buffer.GetDicomInstance(instanceId.c_str()); - - OrthancPlugins::DicomInstance dicom(buffer.GetData(), buffer.GetSize()); - - std::unique_ptr<OrthancPlugins::OrthancImage> frame(dicom.GetDecodedFrame(frameNumber)); - - Orthanc::PixelFormat format; - switch (frame->GetPixelFormat()) - { - case OrthancPluginPixelFormat_RGB24: - format = Orthanc::PixelFormat_RGB24; - break; - - case OrthancPluginPixelFormat_Grayscale8: - format = Orthanc::PixelFormat_Grayscale8; - break; - - case OrthancPluginPixelFormat_Grayscale16: - format = Orthanc::PixelFormat_Grayscale16; - break; - - default: - throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); - } - - Orthanc::ImageAccessor source; - source.AssignReadOnly(format, frame->GetWidth(), frame->GetHeight(), frame->GetPitch(), frame->GetBuffer()); - - std::unique_ptr<Orthanc::ImageAccessor> rendered(new Orthanc::Image(Orthanc::PixelFormat_RGB24, source.GetWidth(), source.GetHeight(), false)); - - switch (format) - { - case Orthanc::PixelFormat_RGB24: - Orthanc::ImageProcessing::Copy(*rendered, source); - break; - - case Orthanc::PixelFormat_Grayscale8: - Orthanc::ImageProcessing::Convert(*rendered, source); - break; - - case Orthanc::PixelFormat_Grayscale16: - RenderGrayscale(*rendered, source); - break; - - default: - throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); - } - - return new OnTheFlyPyramid(rendered.release(), 512, 512, smooth_); - } - }; -} - - static bool DisplayPerformanceWarning() { (void) DisplayPerformanceWarning; // Disable warning about unused function