diff Framework/Toolbox/DicomStructureSet2.h @ 998:38b6bb0bdd72

added a new set of classes that correctly handle non-convex polygons (not used yet because of limitations in coordinates computing): DicomStructure2, DicomStructureSet2, DicomStructurePolygon2, DicomStructureSetSlicer2. Too many shortcuts have been taken when computing the actual position.
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 20 Sep 2019 11:58:00 +0200
parents 4c9b4c4de814
children 29f5f2031310
line wrap: on
line diff
--- a/Framework/Toolbox/DicomStructureSet2.h	Sat Sep 14 17:27:41 2019 +0200
+++ b/Framework/Toolbox/DicomStructureSet2.h	Fri Sep 20 11:58:00 2019 +0200
@@ -18,9 +18,9 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  **/
 
-
 #pragma once
 
+#include "DicomStructure2.h"
 #include "CoordinateSystem3D.h"
 #include "Extent2D.h"
 #include "../Scene2D/Color.h"
@@ -31,155 +31,34 @@
 
 namespace OrthancStone
 {
-   class DicomStructureSet2 : public boost::noncopyable
+  class DicomStructureSet2 : public boost::noncopyable
   {
   public:
-    typedef std::pair<double, double> PolygonPoint2D;
-    
-  private:
-    struct ReferencedSlice
-    {
-      std::string          seriesInstanceUid_;
-      CoordinateSystem3D   geometry_;
-      double               thickness_;
-
-      ReferencedSlice()
-      {
-      }
-      
-      ReferencedSlice(const std::string& seriesInstanceUid,
-                      const CoordinateSystem3D& geometry,
-                      double thickness) :
-        seriesInstanceUid_(seriesInstanceUid),
-        geometry_(geometry),
-        thickness_(thickness)
-      {
-      }
-    };
-
-    typedef std::map<std::string, ReferencedSlice>  ReferencedSlices;
-    
-    typedef std::vector<Vector>  Points;
-
-    class Polygon
-    {
-    private:
-      std::string         sopInstanceUid_;
-      bool                hasSlice_;
-      CoordinateSystem3D  geometry_;
-      double              projectionAlongNormal_;
-      double              sliceThickness_;  // In millimeters
-      Points              points_;
-      Extent2D            extent_;
-
-      void CheckPointIsOnSlice(const Vector& v) const;
-      bool IsPointOnSliceIfAny(const Vector& v) const;
-
-    public:
-      Polygon(const std::string& sopInstanceUid) :
-        sopInstanceUid_(sopInstanceUid),
-        hasSlice_(false)
-      {
-      }
-
-      void Reserve(size_t n)
-      {
-        points_.reserve(n);
-      }
-
-      void AddPoint(const Vector& v);
-
-      bool UpdateReferencedSlice(const ReferencedSlices& slices);
-
-      bool IsOnSlice(const CoordinateSystem3D& geometry) const;
-
-      const std::string& GetSopInstanceUid() const
-      {
-        return sopInstanceUid_;
-      }
-
-      const Points& GetPoints() const
-      {
-        return points_;
-      }
-
-      double GetSliceThickness() const
-      {
-        return sliceThickness_;
-      }
-
-      bool Project(double& x1,
-                   double& y1,
-                   double& x2,
-                   double& y2,
-                   const CoordinateSystem3D& slice) const;
-    };
-
-    typedef std::list<Polygon>  Polygons;
-
-    struct Structure
-    {
-      std::string   name_;
-      std::string   interpretation_;
-      Polygons      polygons_;
-      uint8_t       red_;
-      uint8_t       green_;
-      uint8_t       blue_;
-    };
-
-    typedef std::vector<Structure>  Structures;
-
-    Structures        structures_;
-    ReferencedSlices  referencedSlices_;
-
-    const Structure& GetStructure(size_t index) const;
-
-    Structure& GetStructure(size_t index);
-  
-    bool ProjectStructure(std::vector< std::vector<PolygonPoint2D> >& polygons,
-                          const Structure& structure,
-                          const CoordinateSystem3D& slice) const;
-
-  public:
-    DicomStructureSet2(const OrthancPlugins::FullOrthancDataset& instance);
+    DicomStructureSet2();
+    ~DicomStructureSet2();
+   
+    void SetContents(const OrthancPlugins::FullOrthancDataset& tags);
 
     size_t GetStructuresCount() const
     {
       return structures_.size();
     }
 
-    Vector GetStructureCenter(size_t index) const;
-
-    const std::string& GetStructureName(size_t index) const;
-
-    const std::string& GetStructureInterpretation(size_t index) const;
-
-    Color GetStructureColor(size_t index) const;
+    void Clear();
 
-    // TODO - remove
-    void GetStructureColor(uint8_t& red,
-                           uint8_t& green,
-                           uint8_t& blue,
-                           size_t index) const;
-
-    void GetReferencedInstances(std::set<std::string>& instances);
+    const DicomStructure2& GetStructure(size_t i) const
+    {
+      // at() is like []() but with range check
+      return structures_.at(i);
+    }
 
-    void AddReferencedSlice(const std::string& sopInstanceUid,
-                            const std::string& seriesInstanceUid,
-                            const CoordinateSystem3D& geometry,
-                            double thickness);
-
-    void AddReferencedSlice(const Orthanc::DicomMap& dataset);
-
-    void CheckReferencedSlices();
+    /** Internal use only */
+    void FillStructuresFromDataset(const OrthancPlugins::FullOrthancDataset& tags);
 
-    Vector GetNormal() const;
+    /** Internal use only */
+    void ComputeDependentProperties();
 
-    bool ProjectStructure(std::vector< std::vector<PolygonPoint2D> >& polygons,
-                          size_t index,
-                          const CoordinateSystem3D& slice) const
-    {
-      return ProjectStructure(polygons, GetStructure(index), slice);
-    }
+    /** Internal use only */
+    std::vector<DicomStructure2> structures_;
   };
 }