# HG changeset patch # User Benjamin Golinvaux # Date 1563971226 -7200 # Node ID 408bcc6c15052741e58735d2b2c070e84b6daf33 # Parent 39d2a3661665506469cb5b019cf872155052c702 Added Loader cache. Not activated yet. diff -r 39d2a3661665 -r 408bcc6c1505 Framework/Loaders/LoaderCache.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Loaders/LoaderCache.cpp Wed Jul 24 14:27:06 2019 +0200 @@ -0,0 +1,217 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., 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 . + **/ + +#include "LoaderCache.h" + +#include "OrthancSeriesVolumeProgressiveLoader.h" +#include "OrthancMultiframeVolumeLoader.h" +#include "DicomStructureSetLoader.h" + +#include "../Messages/LockingEmitter.h" +#include "../Volumes/DicomVolumeImage.h" +#include "../Volumes/DicomVolumeImageMPRSlicer.h" + +#include +#include + +namespace OrthancStone +{ +#if ORTHANC_ENABLE_WASM == 1 + LoaderCache::LoaderCache(IOracle& oracle) + : oracle_(oracle) + { + + } +#else + LoaderCache::LoaderCache(IOracle& oracle, LockingEmitter& lockingEmitter) + : oracle_(oracle) + , lockingEmitter_(lockingEmitter) + { + } +#endif + + boost::shared_ptr + LoaderCache::GetSeriesVolumeProgressiveLoader(std::string seriesUuid) + { + try + { + // normalize keys a little + seriesUuid = Orthanc::Toolbox::StripSpaces(seriesUuid); + Orthanc::Toolbox::ToLowerCase(seriesUuid); + + // find in cache + if (seriesVolumeProgressiveLoaders_.find(seriesUuid) == seriesVolumeProgressiveLoaders_.end()) + { + boost::shared_ptr volumeImage(new DicomVolumeImage); + boost::shared_ptr loader; + + { +#if ORTHANC_ENABLE_WASM == 1 + loader.reset(new OrthancSeriesVolumeProgressiveLoader(volumeImage, GetParent()->GetOracleRef(), GetParent()->GetOracleRef())); +#else + LockingEmitter::WriterLock lock(lockingEmitter_); + loader.reset(new OrthancSeriesVolumeProgressiveLoader(volumeImage, oracle_, lock.GetOracleObservable())); +#endif + loader->LoadSeries(seriesUuid); + } + seriesVolumeProgressiveLoaders_[seriesUuid] = loader; + } + return seriesVolumeProgressiveLoaders_[seriesUuid]; + } + catch (const Orthanc::OrthancException& e) + { + if (e.HasDetails()) + { + LOG(ERROR) << "OrthancException in LoaderCache: " << e.What() << " Details: " << e.GetDetails(); + } + else + { + LOG(ERROR) << "OrthancException in LoaderCache: " << e.What(); + } + throw; + } + catch (const std::exception& e) + { + LOG(ERROR) << "std::exception in LoaderCache: " << e.what(); + throw; + } + catch (...) + { + LOG(ERROR) << "Unknown exception in LoaderCache"; + throw; + } + } + + boost::shared_ptr LoaderCache::GetMultiframeDicomVolumeImageMPRSlicer(std::string instanceUuid) + { + try + { + // normalize keys a little + instanceUuid = Orthanc::Toolbox::StripSpaces(instanceUuid); + Orthanc::Toolbox::ToLowerCase(instanceUuid); + + // find in cache + if (dicomVolumeImageMPRSlicers_.find(instanceUuid) == dicomVolumeImageMPRSlicers_.end()) + { + boost::shared_ptr volumeImage(new DicomVolumeImage); + boost::shared_ptr loader; + + { +#if ORTHANC_ENABLE_WASM == 1 + loader.reset(new OrthancMultiframeVolumeLoader(volumeImage, GetParent()->GetOracleRef(), GetParent()->GetOracleRef())); +#else + LockingEmitter::WriterLock lock(lockingEmitter_); + loader.reset(new OrthancMultiframeVolumeLoader(volumeImage, oracle_, lock.GetOracleObservable())); +#endif + loader->LoadInstance(instanceUuid); + } + multiframeVolumeLoaders_[instanceUuid] = loader; + boost::shared_ptr mprSlicer(new DicomVolumeImageMPRSlicer(volumeImage)); + dicomVolumeImageMPRSlicers_[instanceUuid] = mprSlicer; + } + return dicomVolumeImageMPRSlicers_[instanceUuid]; + } + catch (const Orthanc::OrthancException& e) + { + if (e.HasDetails()) + { + LOG(ERROR) << "OrthancException in LoaderCache: " << e.What() << " Details: " << e.GetDetails(); + } + else + { + LOG(ERROR) << "OrthancException in LoaderCache: " << e.What(); + } + throw; + } + catch (const std::exception& e) + { + LOG(ERROR) << "std::exception in LoaderCache: " << e.what(); + throw; + } + catch (...) + { + LOG(ERROR) << "Unknown exception in LoaderCache"; + throw; + } + } + + boost::shared_ptr LoaderCache::GetDicomStructureSetLoader(std::string instanceUuid) + { + try + { + // normalize keys a little + instanceUuid = Orthanc::Toolbox::StripSpaces(instanceUuid); + Orthanc::Toolbox::ToLowerCase(instanceUuid); + + // find in cache + if (dicomStructureSetLoaders_.find(instanceUuid) == dicomStructureSetLoaders_.end()) + { + boost::shared_ptr loader; + + { +#if ORTHANC_ENABLE_WASM == 1 + loader.reset(new DicomStructureSetLoader(volumeImage, GetParent()->GetOracleRef(), GetParent()->GetOracleRef())); +#else + LockingEmitter::WriterLock lock(lockingEmitter_); + loader.reset(new DicomStructureSetLoader(oracle_, lock.GetOracleObservable())); +#endif + loader->LoadInstance(instanceUuid); + } + dicomStructureSetLoaders_[instanceUuid] = loader; + } + return dicomStructureSetLoaders_[instanceUuid]; + } + catch (const Orthanc::OrthancException& e) + { + if (e.HasDetails()) + { + LOG(ERROR) << "OrthancException in LoaderCache: " << e.What() << " Details: " << e.GetDetails(); + } + else + { + LOG(ERROR) << "OrthancException in LoaderCache: " << e.What(); + } + throw; + } + catch (const std::exception& e) + { + LOG(ERROR) << "std::exception in LoaderCache: " << e.what(); + throw; + } + catch (...) + { + LOG(ERROR) << "Unknown exception in LoaderCache"; + throw; + } + } + + + void LoaderCache::ClearCache() + { +#if ORTHANC_ENABLE_WASM != 1 + LockingEmitter::WriterLock lock(lockingEmitter_); +#endif + seriesVolumeProgressiveLoaders_.clear(); + multiframeVolumeLoaders_.clear(); + dicomVolumeImageMPRSlicers_.clear(); + dicomStructureSetLoaders_.clear(); + } + +} diff -r 39d2a3661665 -r 408bcc6c1505 Framework/Loaders/LoaderCache.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Loaders/LoaderCache.h Wed Jul 24 14:27:06 2019 +0200 @@ -0,0 +1,80 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., 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 . + **/ + +#pragma once + +#include + +#include +#include + +namespace OrthancStone +{ + class OrthancSeriesVolumeProgressiveLoader; + class DicomVolumeImageMPRSlicer; + class DicomStructureSetLoader; + class OrthancMultiframeVolumeLoader; + class IOracle; + +#if ORTHANC_ENABLE_WASM == 1 + //class WebAssemblyOracle; +#else + //class ThreadedOracle; + class LockingEmitter; +#endif + + class LoaderCache + { + public: +#if ORTHANC_ENABLE_WASM == 1 + LoaderCache(IOracle& oracle); +#else + LoaderCache(IOracle& oracle, LockingEmitter& lockingEmitter); +#endif + + boost::shared_ptr + GetSeriesVolumeProgressiveLoader (std::string seriesUuid); + boost::shared_ptr + GetMultiframeDicomVolumeImageMPRSlicer(std::string instanceUuid); + boost::shared_ptr + GetDicomStructureSetLoader (std::string instanceUuid); + + void ClearCache(); + + private: + IOracle& oracle_; +#if ORTHANC_ENABLE_WASM == 1 + //WebAssemblyOracle& oracle_; +#else + //ThreadedOracle& oracle_; + LockingEmitter& lockingEmitter_; +#endif + + std::map > + seriesVolumeProgressiveLoaders_; + std::map > + multiframeVolumeLoaders_; + std::map > + dicomVolumeImageMPRSlicers_; + std::map > + dicomStructureSetLoaders_; + }; +} + diff -r 39d2a3661665 -r 408bcc6c1505 Resources/CMake/OrthancStoneConfiguration.cmake --- a/Resources/CMake/OrthancStoneConfiguration.cmake Mon Jul 22 16:03:10 2019 +0200 +++ b/Resources/CMake/OrthancStoneConfiguration.cmake Wed Jul 24 14:27:06 2019 +0200 @@ -410,6 +410,8 @@ ${ORTHANC_STONE_ROOT}/Framework/Loaders/BasicFetchingItemsSorter.cpp ${ORTHANC_STONE_ROOT}/Framework/Loaders/BasicFetchingStrategy.cpp ${ORTHANC_STONE_ROOT}/Framework/Loaders/DicomStructureSetLoader.cpp + ${ORTHANC_STONE_ROOT}/Framework/Loaders/LoaderCache.h + ${ORTHANC_STONE_ROOT}/Framework/Loaders/LoaderCache.cpp ${ORTHANC_STONE_ROOT}/Framework/Loaders/LoaderStateMachine.cpp ${ORTHANC_STONE_ROOT}/Framework/Loaders/OrthancMultiframeVolumeLoader.cpp ${ORTHANC_STONE_ROOT}/Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp