Mercurial > hg > orthanc-stone
changeset 1310:9bea7e15b519 broker
- first pass at changes to cope with the refactoring of the loading system
- global loader-related data accessible through ILoadersContext::ILock
- many changes in legacy loaders (CT, RTSTRUCT, DOSE) + loader cache
- NOT FINISHED! there are shared_from_this calls in ctors! this will crash!
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 09 Mar 2020 14:53:22 +0100 |
parents | 1f877e0846fe |
children | 3d26447ddd28 |
files | Framework/Deprecated/Loaders/DicomStructureSetLoader.cpp Framework/Deprecated/Loaders/DicomStructureSetLoader.h Framework/Deprecated/Loaders/LoaderCache.cpp Framework/Deprecated/Loaders/LoaderCache.h Framework/Deprecated/Loaders/LoaderStateMachine.cpp Framework/Deprecated/Loaders/LoaderStateMachine.h Framework/Deprecated/Loaders/OrthancMultiframeVolumeLoader.cpp Framework/Deprecated/Loaders/OrthancMultiframeVolumeLoader.h Framework/Deprecated/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp Framework/Deprecated/Loaders/OrthancSeriesVolumeProgressiveLoader.h |
diffstat | 10 files changed, 138 insertions(+), 145 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Deprecated/Loaders/DicomStructureSetLoader.cpp Wed Mar 04 13:20:12 2020 +0100 +++ b/Framework/Deprecated/Loaders/DicomStructureSetLoader.cpp Mon Mar 09 14:53:22 2020 +0100 @@ -345,16 +345,17 @@ }; - DicomStructureSetLoader::DicomStructureSetLoader(OrthancStone::IOracle& oracle, - OrthancStone::IObservable& oracleObservable) : - LoaderStateMachine(oracle, oracleObservable), - revision_(0), - countProcessedInstances_(0), - countReferencedInstances_(0), - structuresReady_(false) + DicomStructureSetLoader::DicomStructureSetLoader( + OrthancStone::ILoadersContext& loadersContext) + : LoaderStateMachine(loadersContext) + , loadersContext_(loadersContext) + , revision_(0) + , countProcessedInstances_(0) + , countReferencedInstances_(0) + , structuresReady_(false) { } - + void DicomStructureSetLoader::SetStructureDisplayState(size_t structureIndex, bool display) {
--- a/Framework/Deprecated/Loaders/DicomStructureSetLoader.h Wed Mar 04 13:20:12 2020 +0100 +++ b/Framework/Deprecated/Loaders/DicomStructureSetLoader.h Mon Mar 09 14:53:22 2020 +0100 @@ -42,14 +42,15 @@ class LookupInstance; // 2nd state class LoadStructure; // 1st state + OrthancStone::ILoadersContext& loadersContext_; std::unique_ptr<OrthancStone::DicomStructureSet> content_; - uint64_t revision_; - std::string instanceId_; - unsigned int countProcessedInstances_; - unsigned int countReferencedInstances_; + uint64_t revision_; + std::string instanceId_; + unsigned int countProcessedInstances_; + unsigned int countReferencedInstances_; // will be set to true once the loading is finished - bool structuresReady_; + bool structuresReady_; /** At load time, these strings are used to initialize the structureVisibility_ @@ -71,8 +72,7 @@ public: ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, StructuresReady, DicomStructureSetLoader); - DicomStructureSetLoader(OrthancStone::IOracle& oracle, - OrthancStone::IObservable& oracleObservable); + DicomStructureSetLoader(OrthancStone::ILoadersContext& loadersContext); OrthancStone::DicomStructureSet* GetContent() {
--- a/Framework/Deprecated/Loaders/LoaderCache.cpp Wed Mar 04 13:20:12 2020 +0100 +++ b/Framework/Deprecated/Loaders/LoaderCache.cpp Mon Mar 09 14:53:22 2020 +0100 @@ -25,6 +25,9 @@ #include "OrthancMultiframeVolumeLoader.h" #include "DicomStructureSetLoader.h" +#include "../../Loaders/ILoadersContext.h" + + #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 #include "DicomStructureSetLoader2.h" #endif @@ -56,20 +59,11 @@ namespace Deprecated { -#if ORTHANC_ENABLE_WASM == 1 - LoaderCache::LoaderCache(OrthancStone::WebAssemblyOracle& oracle) - : oracle_(oracle) + LoaderCache::LoaderCache(OrthancStone::ILoadersContext& loadersContext) + : loadersContext_(loadersContext) { } -#else - LoaderCache::LoaderCache(OrthancStone::ThreadedOracle& oracle, - LockingEmitter& lockingEmitter) - : oracle_(oracle) - , lockingEmitter_(lockingEmitter) - { - } -#endif boost::shared_ptr<OrthancSeriesVolumeProgressiveLoader> LoaderCache::GetSeriesVolumeProgressiveLoader(std::string seriesUuid) @@ -84,26 +78,13 @@ // find in cache if (seriesVolumeProgressiveLoaders_.find(seriesUuid) == seriesVolumeProgressiveLoaders_.end()) { -// LOG(TRACE) << "LoaderCache::GetSeriesVolumeProgressiveLoader : CACHEMISS --> need to load seriesUUid = " << seriesUuid; -#if ORTHANC_ENABLE_WASM == 1 -// LOG(TRACE) << "Performing request for series " << seriesUuid << " sbrk(0) = " << sbrk(0); -#else -// LOG(TRACE) << "Performing request for series " << seriesUuid; -#endif + std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock()); + boost::shared_ptr<OrthancStone::DicomVolumeImage> volumeImage(new OrthancStone::DicomVolumeImage); boost::shared_ptr<OrthancSeriesVolumeProgressiveLoader> loader; -// LOG(TRACE) << "volumeImage = " << volumeImage.get(); - { -#if ORTHANC_ENABLE_WASM == 1 - loader.reset(new OrthancSeriesVolumeProgressiveLoader(volumeImage, oracle_, oracle_)); -#else - LockingEmitter::WriterLock lock(lockingEmitter_); - loader.reset(new OrthancSeriesVolumeProgressiveLoader(volumeImage, oracle_, lock.GetOracleObservable())); -#endif -// LOG(TRACE) << "LoaderCache::GetSeriesVolumeProgressiveLoader : loader = " << loader.get(); - loader->LoadSeries(seriesUuid); -// LOG(TRACE) << "LoaderCache::GetSeriesVolumeProgressiveLoader : loader->LoadSeries successful"; - } + + loader.reset(new OrthancSeriesVolumeProgressiveLoader(loadersContext_, volumeImage)); + loader->LoadSeries(seriesUuid); seriesVolumeProgressiveLoaders_[seriesUuid] = loader; } else @@ -159,16 +140,11 @@ // find in cache if (dicomVolumeImageMPRSlicers_.find(instanceUuid) == dicomVolumeImageMPRSlicers_.end()) { + std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock()); boost::shared_ptr<OrthancStone::DicomVolumeImage> volumeImage(new OrthancStone::DicomVolumeImage); boost::shared_ptr<OrthancMultiframeVolumeLoader> loader; - { -#if ORTHANC_ENABLE_WASM == 1 - loader.reset(new OrthancMultiframeVolumeLoader(volumeImage, oracle_, oracle_)); -#else - LockingEmitter::WriterLock lock(lockingEmitter_); - loader.reset(new OrthancMultiframeVolumeLoader(volumeImage, oracle_, lock.GetOracleObservable())); -#endif + loader.reset(new OrthancMultiframeVolumeLoader(loadersContext_, volumeImage)); loader->LoadInstance(instanceUuid); } multiframeVolumeLoaders_[instanceUuid] = loader; @@ -261,15 +237,11 @@ // find in cache if (dicomStructureSetLoaders_.find(entryKey) == dicomStructureSetLoaders_.end()) { + std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock()); + boost::shared_ptr<DicomStructureSetLoader> loader; - { -#if ORTHANC_ENABLE_WASM == 1 - loader.reset(new DicomStructureSetLoader(oracle_, oracle_)); -#else - LockingEmitter::WriterLock lock(lockingEmitter_); - loader.reset(new DicomStructureSetLoader(oracle_, lock.GetOracleObservable())); -#endif + loader.reset(new DicomStructureSetLoader(loadersContext_)); loader->LoadInstance(inInstanceUuid, initiallyVisibleStructures); } dicomStructureSetLoaders_[entryKey] = loader; @@ -362,14 +334,12 @@ void LoaderCache::ClearCache() { -#if ORTHANC_ENABLE_WASM != 1 - LockingEmitter::WriterLock lock(lockingEmitter_); -#endif + std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock()); -//#ifndef NDEBUG +#ifndef NDEBUG // ISO way of checking for debug builds DebugDisplayObjRefCounts(); -//#endif +#endif seriesVolumeProgressiveLoaders_.clear(); multiframeVolumeLoaders_.clear(); dicomVolumeImageMPRSlicers_.clear();
--- a/Framework/Deprecated/Loaders/LoaderCache.h Wed Mar 04 13:20:12 2020 +0100 +++ b/Framework/Deprecated/Loaders/LoaderCache.h Mon Mar 09 14:53:22 2020 +0100 @@ -34,11 +34,7 @@ namespace OrthancStone { -#if ORTHANC_ENABLE_WASM == 1 - class WebAssemblyOracle; -#else - class ThreadedOracle; -#endif + class ILoadersContext; } namespace Deprecated @@ -46,11 +42,7 @@ class LoaderCache { public: -#if ORTHANC_ENABLE_WASM == 1 - LoaderCache(OrthancStone::WebAssemblyOracle& oracle); -#else - LoaderCache(OrthancStone::ThreadedOracle& oracle, LockingEmitter& lockingEmitter); -#endif + LoaderCache(OrthancStone::ILoadersContext& loadersContext); boost::shared_ptr<OrthancSeriesVolumeProgressiveLoader> GetSeriesVolumeProgressiveLoader (std::string seriesUuid); @@ -80,12 +72,8 @@ private: void DebugDisplayObjRefCounts(); -#if ORTHANC_ENABLE_WASM == 1 - OrthancStone::WebAssemblyOracle& oracle_; -#else - OrthancStone::ThreadedOracle& oracle_; - LockingEmitter& lockingEmitter_; -#endif + + OrthancStone::ILoadersContext& loadersContext_; std::map<std::string, boost::shared_ptr<OrthancSeriesVolumeProgressiveLoader> > seriesVolumeProgressiveLoaders_;
--- a/Framework/Deprecated/Loaders/LoaderStateMachine.cpp Wed Mar 04 13:20:12 2020 +0100 +++ b/Framework/Deprecated/Loaders/LoaderStateMachine.cpp Mon Mar 09 14:53:22 2020 +0100 @@ -21,6 +21,8 @@ #include "LoaderStateMachine.h" +#include "../../Loaders/ILoadersContext.h" + #include <Core/OrthancException.h> namespace Deprecated @@ -97,8 +99,11 @@ ") < simultaneousDownloads_ (" << simultaneousDownloads_ << ") --> will Schedule command addr " << std::hex << nextCommand << std::dec; - boost::shared_ptr<IObserver> observer(GetSharedObserver()); - oracle_.Schedule(observer, nextCommand); + { + std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock()); + boost::shared_ptr<IObserver> observer(GetSharedObserver()); + lock->Schedule(observer, 0, nextCommand); // TODO: priority! + } pendingCommands_.pop_front(); activeCommands_++; @@ -157,20 +162,32 @@ } - LoaderStateMachine::LoaderStateMachine(OrthancStone::IOracle& oracle, - OrthancStone::IObservable& oracleObservable) : - oracle_(oracle), - active_(false), - simultaneousDownloads_(4), - activeCommands_(0) + LoaderStateMachine::LoaderStateMachine( + OrthancStone::ILoadersContext& loadersContext) + : loadersContext_(loadersContext) + , active_(false) + , simultaneousDownloads_(4) + , activeCommands_(0) { - LOG(TRACE) << "LoaderStateMachine(" << std::hex << this << std::dec << ")::LoaderStateMachine()"; + using OrthancStone::ILoadersContext; + + LOG(TRACE) + << "LoaderStateMachine(" << std::hex << this + << std::dec << ")::LoaderStateMachine()"; + + std::unique_ptr<ILoadersContext::ILock> lock(loadersContext_.Lock()); + + OrthancStone::IObservable& observable = lock->GetOracleObservable(); - // TODO => Move this out of constructor - Register<OrthancStone::OrthancRestApiCommand::SuccessMessage>(oracleObservable, &LoaderStateMachine::HandleSuccessMessage); - Register<OrthancStone::GetOrthancImageCommand::SuccessMessage>(oracleObservable, &LoaderStateMachine::HandleSuccessMessage); - Register<OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage>(oracleObservable, &LoaderStateMachine::HandleSuccessMessage); - Register<OrthancStone::OracleCommandExceptionMessage>(oracleObservable, &LoaderStateMachine::HandleExceptionMessage); + // TODO => Move this out of constructor WHY? + Register<OrthancStone::OrthancRestApiCommand::SuccessMessage>( + observable, &LoaderStateMachine::HandleSuccessMessage); + Register<OrthancStone::GetOrthancImageCommand::SuccessMessage>( + observable, &LoaderStateMachine::HandleSuccessMessage); + Register<OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage>( + observable, &LoaderStateMachine::HandleSuccessMessage); + Register<OrthancStone::OracleCommandExceptionMessage>( + observable, &LoaderStateMachine::HandleExceptionMessage); } LoaderStateMachine::~LoaderStateMachine()
--- a/Framework/Deprecated/Loaders/LoaderStateMachine.h Wed Mar 04 13:20:12 2020 +0100 +++ b/Framework/Deprecated/Loaders/LoaderStateMachine.h Mon Mar 09 14:53:22 2020 +0100 @@ -33,6 +33,11 @@ #include <list> +namespace OrthancStone +{ + class ILoadersContext; +} + namespace Deprecated { /** @@ -94,15 +99,14 @@ typedef std::list<OrthancStone::IOracleCommand*> PendingCommands; - OrthancStone::IOracle& oracle_; - bool active_; - unsigned int simultaneousDownloads_; - PendingCommands pendingCommands_; - unsigned int activeCommands_; + OrthancStone::ILoadersContext& loadersContext_; + bool active_; + unsigned int simultaneousDownloads_; + PendingCommands pendingCommands_; + unsigned int activeCommands_; public: - LoaderStateMachine(OrthancStone::IOracle& oracle, - OrthancStone::IObservable& oracleObservable); + LoaderStateMachine(OrthancStone::ILoadersContext& loadersContext); virtual ~LoaderStateMachine();
--- a/Framework/Deprecated/Loaders/OrthancMultiframeVolumeLoader.cpp Wed Mar 04 13:20:12 2020 +0100 +++ b/Framework/Deprecated/Loaders/OrthancMultiframeVolumeLoader.cpp Mon Mar 09 14:53:22 2020 +0100 @@ -508,18 +508,17 @@ } OrthancMultiframeVolumeLoader::OrthancMultiframeVolumeLoader( + OrthancStone::ILoadersContext& loadersContext, boost::shared_ptr<OrthancStone::DicomVolumeImage> volume, - OrthancStone::IOracle& oracle, - OrthancStone::IObservable& oracleObservable, - float outliersHalfRejectionRate) : - LoaderStateMachine(oracle, oracleObservable), - volume_(volume), - pixelDataLoaded_(false), - outliersHalfRejectionRate_(outliersHalfRejectionRate), - distributionRawMin_(0), - distributionRawMax_(0), - computedDistributionMin_(0), - computedDistributionMax_(0) + float outliersHalfRejectionRate) + : LoaderStateMachine(loadersContext) + , volume_(volume) + , pixelDataLoaded_(false) + , outliersHalfRejectionRate_(outliersHalfRejectionRate) + , distributionRawMin_(0) + , distributionRawMax_(0) + , computedDistributionMin_(0) + , computedDistributionMax_(0) { if (volume.get() == NULL) {
--- a/Framework/Deprecated/Loaders/OrthancMultiframeVolumeLoader.h Wed Mar 04 13:20:12 2020 +0100 +++ b/Framework/Deprecated/Loaders/OrthancMultiframeVolumeLoader.h Mon Mar 09 14:53:22 2020 +0100 @@ -94,10 +94,10 @@ const OrthancStone::VolumeImageGeometry& GetImageGeometry() const; public: - OrthancMultiframeVolumeLoader(boost::shared_ptr<OrthancStone::DicomVolumeImage> volume, - OrthancStone::IOracle& oracle, - OrthancStone::IObservable& oracleObservable, - float outliersHalfRejectionRate = 0.0005); + OrthancMultiframeVolumeLoader( + OrthancStone::ILoadersContext& loadersContext, + boost::shared_ptr<OrthancStone::DicomVolumeImage> volume, + float outliersHalfRejectionRate = 0.0005); virtual ~OrthancMultiframeVolumeLoader();
--- a/Framework/Deprecated/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp Wed Mar 04 13:20:12 2020 +0100 +++ b/Framework/Deprecated/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp Mon Mar 09 14:53:22 2020 +0100 @@ -21,6 +21,7 @@ #include "OrthancSeriesVolumeProgressiveLoader.h" +#include "../../Loaders/ILoadersContext.h" #include "../../Loaders/BasicFetchingItemsSorter.h" #include "../../Loaders/BasicFetchingStrategy.h" #include "../../Toolbox/GeometryToolbox.h" @@ -31,6 +32,8 @@ namespace Deprecated { + using OrthancStone::ILoadersContext; + class OrthancSeriesVolumeProgressiveLoader::ExtractedSlice : public OrthancStone::DicomVolumeImageMPRSlicer::Slice { private: @@ -302,9 +305,12 @@ } command->AcquirePayload(new Orthanc::SingleValueObject<unsigned int>(sliceIndex)); - - boost::shared_ptr<IObserver> observer(GetSharedObserver()); - oracle_.Schedule(observer, command.release()); + + { + std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock()); + boost::shared_ptr<IObserver> observer(GetSharedObserver()); + lock->Schedule(observer, 0, command.release()); // TODO: priority! + } } else { @@ -430,25 +436,30 @@ } - OrthancSeriesVolumeProgressiveLoader::OrthancSeriesVolumeProgressiveLoader(const boost::shared_ptr<OrthancStone::DicomVolumeImage>& volume, - OrthancStone::IOracle& oracle, - OrthancStone::IObservable& oracleObservable) : - oracle_(oracle), - active_(false), - simultaneousDownloads_(4), - volume_(volume), - sorter_(new OrthancStone::BasicFetchingItemsSorter::Factory), - volumeImageReadyInHighQuality_(false) + OrthancSeriesVolumeProgressiveLoader::OrthancSeriesVolumeProgressiveLoader( + OrthancStone::ILoadersContext& loadersContext, + const boost::shared_ptr<OrthancStone::DicomVolumeImage>& volume) + : loadersContext_(loadersContext) + , active_(false) + , simultaneousDownloads_(4) + , volume_(volume) + , sorter_(new OrthancStone::BasicFetchingItemsSorter::Factory) + , volumeImageReadyInHighQuality_(false) { - // TODO => Move this out of constructor - Register<OrthancStone::OrthancRestApiCommand::SuccessMessage> - (oracleObservable, &OrthancSeriesVolumeProgressiveLoader::LoadGeometry); + std::auto_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext.Lock()); + + // TODO => Move this out of constructor WHY? + Register<OrthancStone::OrthancRestApiCommand::SuccessMessage>( + lock->GetOracleObservable(), + &OrthancSeriesVolumeProgressiveLoader::LoadGeometry); - Register<OrthancStone::GetOrthancImageCommand::SuccessMessage> - (oracleObservable, &OrthancSeriesVolumeProgressiveLoader::LoadBestQualitySliceContent); + Register<OrthancStone::GetOrthancImageCommand::SuccessMessage>( + lock->GetOracleObservable(), + &OrthancSeriesVolumeProgressiveLoader::LoadBestQualitySliceContent); - Register<OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage> - (oracleObservable, &OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent); + Register<OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage>( + lock->GetOracleObservable(), + &OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent); } OrthancSeriesVolumeProgressiveLoader::~OrthancSeriesVolumeProgressiveLoader() @@ -489,11 +500,11 @@ std::unique_ptr<OrthancStone::OrthancRestApiCommand> command(new OrthancStone::OrthancRestApiCommand); command->SetUri("/series/" + seriesId + "/instances-tags"); - -// LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries about to call oracle_.Schedule"; - boost::shared_ptr<IObserver> observer(GetSharedObserver()); - oracle_.Schedule(observer, command.release()); -// LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries called oracle_.Schedule"; + { + std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock()); + boost::shared_ptr<IObserver> observer(GetSharedObserver()); + lock->Schedule(observer, 0, command.release()); //TODO: priority! + } } }
--- a/Framework/Deprecated/Loaders/OrthancSeriesVolumeProgressiveLoader.h Wed Mar 04 13:20:12 2020 +0100 +++ b/Framework/Deprecated/Loaders/OrthancSeriesVolumeProgressiveLoader.h Mon Mar 09 14:53:22 2020 +0100 @@ -38,6 +38,11 @@ #include <boost/shared_ptr.hpp> +namespace OrthancStone +{ + class ILoadersContext; +} + namespace Deprecated { /** @@ -108,7 +113,7 @@ void LoadJpegSliceContent(const OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage& message); - OrthancStone::IOracle& oracle_; + OrthancStone::ILoadersContext& loadersContext_; bool active_; unsigned int simultaneousDownloads_; SeriesGeometry seriesGeometry_; @@ -118,14 +123,12 @@ std::vector<unsigned int> slicesQuality_; bool volumeImageReadyInHighQuality_; - public: ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, VolumeImageReadyInHighQuality, OrthancSeriesVolumeProgressiveLoader); - - OrthancSeriesVolumeProgressiveLoader(const boost::shared_ptr<OrthancStone::DicomVolumeImage>& volume, - OrthancStone::IOracle& oracle, - OrthancStone::IObservable& oracleObservable); + OrthancSeriesVolumeProgressiveLoader( + OrthancStone::ILoadersContext& context, + const boost::shared_ptr<OrthancStone::DicomVolumeImage>& volume); virtual ~OrthancSeriesVolumeProgressiveLoader();