changeset 1001:e704a53c9d0a

LoaderCache : support for the second set of structure set handling classes
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 20 Sep 2019 11:59:54 +0200
parents 50e5acf5553b
children 341e68752354
files Framework/Loaders/LoaderCache.cpp Framework/Loaders/LoaderCache.h
diffstat 2 files changed, 91 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Loaders/LoaderCache.cpp	Fri Sep 20 11:59:29 2019 +0200
+++ b/Framework/Loaders/LoaderCache.cpp	Fri Sep 20 11:59:54 2019 +0200
@@ -23,6 +23,7 @@
 #include "OrthancSeriesVolumeProgressiveLoader.h"
 #include "OrthancMultiframeVolumeLoader.h"
 #include "DicomStructureSetLoader.h"
+#include "DicomStructureSetLoader2.h"
 
 #if ORTHANC_ENABLE_WASM == 1
 # include <unistd.h>
@@ -32,8 +33,10 @@
 #endif
 
 #include "../Messages/LockingEmitter.h"
+#include "../Toolbox/DicomStructureSet2.h"
 #include "../Volumes/DicomVolumeImage.h"
 #include "../Volumes/DicomVolumeImageMPRSlicer.h"
+#include "../Volumes/DicomStructureSetSlicer2.h"
 
 #include <Core/OrthancException.h>
 #include <Core/Toolbox.h>
@@ -184,6 +187,18 @@
     }
   }
   
+  boost::shared_ptr<DicomStructureSetSlicer2> LoaderCache::GetDicomStructureSetSlicer2(std::string instanceUuid)
+  {
+    // if the loader is not available, let's trigger its creation
+    if (dicomStructureSetSlicers2_.find(instanceUuid) == dicomStructureSetSlicers2_.end())
+    {
+      GetDicomStructureSetLoader2(instanceUuid);
+    }
+    ORTHANC_ASSERT(dicomStructureSetSlicers2_.find(instanceUuid) != dicomStructureSetSlicers2_.end());
+
+    return dicomStructureSetSlicers2_[instanceUuid];
+  }
+
   boost::shared_ptr<DicomStructureSetLoader> LoaderCache::GetDicomStructureSetLoader(std::string instanceUuid)
   {
     try
@@ -235,6 +250,60 @@
   }
 
 
+  boost::shared_ptr<DicomStructureSetLoader2> LoaderCache::GetDicomStructureSetLoader2(std::string instanceUuid)
+  {
+    try
+    {
+      // normalize keys a little
+      instanceUuid = Orthanc::Toolbox::StripSpaces(instanceUuid);
+      Orthanc::Toolbox::ToLowerCase(instanceUuid);
+
+      // find in cache
+      if (dicomStructureSetLoaders2_.find(instanceUuid) == dicomStructureSetLoaders2_.end())
+      {
+        boost::shared_ptr<DicomStructureSetLoader2> loader;
+        boost::shared_ptr<DicomStructureSet2> structureSet(new DicomStructureSet2());
+        boost::shared_ptr<DicomStructureSetSlicer2> rtSlicer(new DicomStructureSetSlicer2(structureSet));
+        dicomStructureSetSlicers2_[instanceUuid] = rtSlicer;
+        dicomStructureSets2_[instanceUuid] = structureSet; // to prevent it from being deleted
+        {
+#if ORTHANC_ENABLE_WASM == 1
+          loader.reset(new DicomStructureSetLoader2(*(structureSet.get()), oracle_, oracle_));
+#else
+          LockingEmitter::WriterLock lock(lockingEmitter_);
+          // TODO: clarify lifetimes... this is DANGEROUS!
+          loader.reset(new DicomStructureSetLoader2(*(structureSet.get()), oracle_, lock.GetOracleObservable()));
+#endif
+          loader->LoadInstance(instanceUuid);
+        }
+        dicomStructureSetLoaders2_[instanceUuid] = loader;
+      }
+      return dicomStructureSetLoaders2_[instanceUuid];
+    }
+    catch (const Orthanc::OrthancException& e)
+    {
+      if (e.HasDetails())
+      {
+        LOG(ERROR) << "OrthancException in GetDicomStructureSetLoader2: " << e.What() << " Details: " << e.GetDetails();
+      }
+      else
+      {
+        LOG(ERROR) << "OrthancException in GetDicomStructureSetLoader2: " << e.What();
+      }
+      throw;
+    }
+    catch (const std::exception& e)
+    {
+      LOG(ERROR) << "std::exception in GetDicomStructureSetLoader2: " << e.what();
+      throw;
+    }
+    catch (...)
+    {
+      LOG(ERROR) << "Unknown exception in GetDicomStructureSetLoader2";
+      throw;
+    }
+  }
+
   void LoaderCache::ClearCache()
   {
 #if ORTHANC_ENABLE_WASM != 1
@@ -249,9 +318,13 @@
     multiframeVolumeLoaders_.clear();
     dicomVolumeImageMPRSlicers_.clear();
     dicomStructureSetLoaders_.clear();
+
+    // order is important!
+    dicomStructureSetLoaders2_.clear();
+    dicomStructureSetSlicers2_.clear();
+    dicomStructureSets2_.clear();
   }
 
-
   template<typename T> void DebugDisplayObjRefCountsInMap(
     const std::string& name, const std::map<std::string, boost::shared_ptr<T> >& myMap)
   {
@@ -271,5 +344,7 @@
     DebugDisplayObjRefCountsInMap("multiframeVolumeLoaders_", multiframeVolumeLoaders_);
     DebugDisplayObjRefCountsInMap("dicomVolumeImageMPRSlicers_", dicomVolumeImageMPRSlicers_);
     DebugDisplayObjRefCountsInMap("dicomStructureSetLoaders_", dicomStructureSetLoaders_);
+    DebugDisplayObjRefCountsInMap("dicomStructureSetLoaders2_", dicomStructureSetLoaders2_);
+    DebugDisplayObjRefCountsInMap("dicomStructureSetSlicers2_", dicomStructureSetSlicers2_);
   }
 }
--- a/Framework/Loaders/LoaderCache.h	Fri Sep 20 11:59:29 2019 +0200
+++ b/Framework/Loaders/LoaderCache.h	Fri Sep 20 11:59:54 2019 +0200
@@ -30,6 +30,9 @@
   class OrthancSeriesVolumeProgressiveLoader;
   class DicomVolumeImageMPRSlicer;
   class DicomStructureSetLoader;
+  class DicomStructureSetLoader2;
+  class DicomStructureSetSlicer2;
+  class DicomStructureSet2;
   class OrthancMultiframeVolumeLoader;
 
 #if ORTHANC_ENABLE_WASM == 1
@@ -60,6 +63,12 @@
     boost::shared_ptr<DicomStructureSetLoader>
       GetDicomStructureSetLoader            (std::string instanceUuid);
 
+    boost::shared_ptr<DicomStructureSetLoader2>
+      GetDicomStructureSetLoader2(std::string instanceUuid);
+
+    boost::shared_ptr<DicomStructureSetSlicer2>
+      GetDicomStructureSetSlicer2(std::string instanceUuid);
+
     void ClearCache();
 
   private:
@@ -80,6 +89,12 @@
       dicomVolumeImageMPRSlicers_;
     std::map<std::string, boost::shared_ptr<DicomStructureSetLoader> >
       dicomStructureSetLoaders_;
+    std::map<std::string, boost::shared_ptr<DicomStructureSetLoader2> >
+      dicomStructureSetLoaders2_;
+    std::map<std::string, boost::shared_ptr<DicomStructureSet2> >
+      dicomStructureSets2_;
+    std::map<std::string, boost::shared_ptr<DicomStructureSetSlicer2> >
+      dicomStructureSetSlicers2_;
   };
 }