diff Framework/Loaders/DicomStructureSetLoader.h @ 1416:d959bc8f6c1b loader-injection-feature

Instance lookup is now performed in a separate class through an interface. Another implementation can be injected (SetInstanceLookupHandler)
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 11 May 2020 17:37:30 +0200
parents ffe9beb7c5d3
children
line wrap: on
line diff
--- a/Framework/Loaders/DicomStructureSetLoader.h	Mon May 11 09:50:02 2020 +0200
+++ b/Framework/Loaders/DicomStructureSetLoader.h	Mon May 11 17:37:30 2020 +0200
@@ -35,12 +35,76 @@
     public OrthancStone::IVolumeSlicer,
     public OrthancStone::IObservable
   {
+  public:
+    ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, StructuresReady, DicomStructureSetLoader);
+    ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, StructuresUpdated, DicomStructureSetLoader);
+
+    /**
+    
+    Once the structure set has been loaded (the LoadStructure state), we need to fill it with geometry information
+    from the referenced slices (tag (0008,1155) described here:
+    https://dicom.innolitics.com/ciods/rt-structure-set/general-reference/00081140/00081155
+
+    This interface allows to customize how this information can be gathered. By default, the RestInstanceLookupHandler
+    will perform a REST call to the Orthanc API to retrieve this information.
+
+    Injecting another implementation of this interface is useful when where this information can be supplied in 
+    another (faster) way (for instance, if a separate loader for the CT series can be used to supply the slice geometry)
+    */
+    class IInstanceLookupHandler
+    {
+    public:
+      virtual void RetrieveReferencedSlices(const std::set<std::string>& instances) = 0;
+    };
+
+    // predeclaration of the default IInstanceLookupHandler implementation
+    class RestInstanceLookupHandler;
+
+    static boost::shared_ptr<DicomStructureSetLoader> Create(
+      OrthancStone::ILoadersContext& loadersContext);
+
+    void SetInstanceLookupHandler(boost::shared_ptr<IInstanceLookupHandler> instanceLookupHandler)
+    {
+      instanceLookupHandler_ = instanceLookupHandler;
+    }
+
+    OrthancStone::DicomStructureSet* GetContent()
+    {
+      return content_.get();
+    }
+
+    void SetStructureDisplayState(size_t structureIndex, bool display);
+    
+    bool GetStructureDisplayState(size_t structureIndex) const
+    {
+      return structureVisibility_.at(structureIndex);
+    }
+
+    ~DicomStructureSetLoader();
+    
+    void LoadInstance(const std::string& instanceId, 
+                      const std::vector<std::string>& initiallyVisibleStructures = std::vector<std::string>());
+
+    void LoadInstanceFullVisibility(const std::string& instanceId);
+
+
+    virtual IExtractedSlice* ExtractSlice(const OrthancStone::CoordinateSystem3D& cuttingPlane) ORTHANC_OVERRIDE;
+
+    void SetStructuresReady();
+    void SetStructuresUpdated();
+
+    bool AreStructuresReady() const;
+
+    /**
+      Called by the IInstanceLookupHandler when slice referenced instance information is available. 
+      When the last referenced slice is received, this method will perform a final check and will warn observers
+    */
+    void AddReferencedSlice(const Orthanc::DicomMap& dicom);
+
   private:
     class Slice;
 
-    // States of LoaderStateMachine
-    class AddReferencedInstance;   // 3rd state
-    class LookupInstance;          // 2nd state
+    // Only state of LoaderStateMachine
     class LoadStructure;           // 1st state
     
     OrthancStone::ILoadersContext&                    loadersContext_;
@@ -70,41 +134,13 @@
     */
     std::vector<bool>                  structureVisibility_;
 
+
+    boost::shared_ptr<IInstanceLookupHandler> instanceLookupHandler_;
+
+  private:
+    void RetrieveReferencedSlices(const std::set<std::string>& nonEmptyInstances);
+
   protected:
     DicomStructureSetLoader(OrthancStone::ILoadersContext& loadersContext);
-
-  public:
-    ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, StructuresReady, DicomStructureSetLoader);
-    ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, StructuresUpdated, DicomStructureSetLoader);
-
-    static boost::shared_ptr<DicomStructureSetLoader> Create(
-      OrthancStone::ILoadersContext& loadersContext);
-
-    OrthancStone::DicomStructureSet* GetContent()
-    {
-      return content_.get();
-    }
-
-    void SetStructureDisplayState(size_t structureIndex, bool display);
-    
-    bool GetStructureDisplayState(size_t structureIndex) const
-    {
-      return structureVisibility_.at(structureIndex);
-    }
-
-    ~DicomStructureSetLoader();
-    
-    void LoadInstance(const std::string& instanceId, 
-                      const std::vector<std::string>& initiallyVisibleStructures = std::vector<std::string>());
-
-    void LoadInstanceFullVisibility(const std::string& instanceId);
-
-
-    virtual IExtractedSlice* ExtractSlice(const OrthancStone::CoordinateSystem3D& cuttingPlane) ORTHANC_OVERRIDE;
-
-    void SetStructuresReady();
-    void SetStructuresUpdated();
-
-    bool AreStructuresReady() const;
   };
 }