diff OrthancStone/Sources/Toolbox/DicomStructuredReport.cpp @ 2097:a9e23ef9ee09 dicom-sr

preparing to extract dicom-sr annotations
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 08 Nov 2023 16:31:49 +0100
parents 79e984a89a38
children 4288d635d77e
line wrap: on
line diff
--- a/OrthancStone/Sources/Toolbox/DicomStructuredReport.cpp	Wed Nov 08 15:15:48 2023 +0100
+++ b/OrthancStone/Sources/Toolbox/DicomStructuredReport.cpp	Wed Nov 08 16:31:49 2023 +0100
@@ -120,14 +120,7 @@
 {
   void DicomStructuredReport::ReferencedInstance::AddFrame(unsigned int frame)
   {
-    if (frame == 0)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
-    }
-    else
-    {
-      frames_.insert(frame - 1);
-    }
+    frames_.insert(frame);
   }
 
 
@@ -140,6 +133,20 @@
     bool          hasProbabilityOfCancer_;
     float         probabilityOfCancer_;
 
+  protected:
+    void Copy(const Structure& other)
+    {
+      if (other.HasFrameNumber())
+      {
+        SetFrameNumber(other.GetFrameNumber());
+      }
+
+      if (other.HasProbabilityOfCancer())
+      {
+        SetProbabilityOfCancer(other.GetProbabilityOfCancer());
+      }
+    }
+
   public:
     Structure(const std::string& sopInstanceUid) :
       sopInstanceUid_(sopInstanceUid),
@@ -152,17 +159,17 @@
     {
     }
 
+    virtual Structure* Clone() const = 0;
+
+    const std::string& GetSopInstanceUid() const
+    {
+      return sopInstanceUid_;
+    }
+
     void SetFrameNumber(unsigned int frame)
     {
-      if (frame <= 0)
-      {
-        throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
-      }
-      else
-      {
-        hasFrameNumber_ = true;
-        frameNumber_ = frame - 1;
-      }
+      hasFrameNumber_ = true;
+      frameNumber_ = frame;
     }
 
     void SetProbabilityOfCancer(float probability)
@@ -229,6 +236,13 @@
     {
     }
 
+    virtual Structure* Clone() const
+    {
+      std::unique_ptr<Point> cloned(new Point(GetSopInstanceUid(), point_.GetX(), point_.GetY()));
+      cloned->Copy(*this);
+      return cloned.release();
+    }
+
     const ScenePoint2D& GetPoint() const
     {
       return point_;
@@ -260,6 +274,20 @@
       }
     }
 
+    Polyline(const std::string& sopInstanceUid,
+             const std::vector<ScenePoint2D>& points) :
+      Structure(sopInstanceUid),
+      points_(points)
+    {
+    }
+
+    virtual Structure* Clone() const
+    {
+      std::unique_ptr<Polyline> cloned(new Polyline(GetSopInstanceUid(), points_));
+      cloned->Copy(*this);
+      return cloned.release();
+    }
+
     size_t GetSize() const
     {
       return points_.size();
@@ -504,21 +532,22 @@
                       for (size_t m = 0; m < tokens.size(); m++)
                       {
                         uint32_t frame;
-                        if (!Orthanc::SerializationToolbox::ParseUnsignedInteger32(frame, tokens[m]))
+                        if (!Orthanc::SerializationToolbox::ParseUnsignedInteger32(frame, tokens[m]) ||
+                            frame <= 0)
                         {
                           throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
                         }
                         else
                         {
-                          AddStructure(sopInstanceUid, group, true, frame, hasProbabilityOfCancer, probabilityOfCancer);
-                          instanceInformation->second->AddFrame(frame);
+                          AddStructure(sopInstanceUid, group, true, frame - 1, hasProbabilityOfCancer, probabilityOfCancer);
+                          instanceInformation->second->AddFrame(frame - 1);
                         }
                       }
                     }
                     else
                     {
                       AddStructure(sopInstanceUid, group, false, 0, hasProbabilityOfCancer, probabilityOfCancer);
-                      instanceInformation->second->AddFrame(1);
+                      instanceInformation->second->AddFrame(0);
                     }
                   }
                 }
@@ -531,6 +560,27 @@
   }
 
 
+  DicomStructuredReport::DicomStructuredReport(const DicomStructuredReport& other) :
+    studyInstanceUid_(other.studyInstanceUid_),
+    seriesInstanceUid_(other.seriesInstanceUid_),
+    sopInstanceUid_(other.sopInstanceUid_),
+    orderedInstances_(other.orderedInstances_)
+  {
+    for (std::map<std::string, ReferencedInstance*>::const_iterator
+           it = other.instancesInformation_.begin(); it != other.instancesInformation_.end(); ++it)
+    {
+      assert(it->second != NULL);
+      instancesInformation_[it->first] = new ReferencedInstance(*it->second);
+    }
+
+    for (std::list<Structure*>::const_iterator it = other.structures_.begin(); it != other.structures_.end(); ++it)
+    {
+      assert(*it != NULL);
+      structures_.push_back((*it)->Clone());
+    }
+  }
+
+
   DicomStructuredReport::~DicomStructuredReport()
   {
     for (std::list<Structure*>::iterator it = structures_.begin(); it != structures_.end(); ++it)