diff OrthancStone/Sources/Toolbox/DicomStructuredReport.cpp @ 2098:4288d635d77e dicom-sr

first rendering of dicom-sr
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 08 Nov 2023 17:23:31 +0100
parents a9e23ef9ee09
children 129cb165ea8d
line wrap: on
line diff
--- a/OrthancStone/Sources/Toolbox/DicomStructuredReport.cpp	Wed Nov 08 16:31:49 2023 +0100
+++ b/OrthancStone/Sources/Toolbox/DicomStructuredReport.cpp	Wed Nov 08 17:23:31 2023 +0100
@@ -118,193 +118,138 @@
 
 namespace OrthancStone
 {
-  void DicomStructuredReport::ReferencedInstance::AddFrame(unsigned int frame)
+  void DicomStructuredReport::Structure::Copy(const Structure& other)
+  {
+    if (other.HasFrameNumber())
+    {
+      SetFrameNumber(other.GetFrameNumber());
+    }
+
+    if (other.HasProbabilityOfCancer())
+    {
+      SetProbabilityOfCancer(other.GetProbabilityOfCancer());
+    }
+  }
+
+
+  DicomStructuredReport::Structure::Structure(const std::string& sopInstanceUid) :
+    sopInstanceUid_(sopInstanceUid),
+    hasFrameNumber_(false),
+    hasProbabilityOfCancer_(false)
   {
-    frames_.insert(frame);
+  }
+
+
+  void DicomStructuredReport::Structure::SetFrameNumber(unsigned int frame)
+  {
+    hasFrameNumber_ = true;
+    frameNumber_ = frame;
+  }
+
+
+  void DicomStructuredReport::Structure::SetProbabilityOfCancer(float probability)
+  {
+    if (probability < 0 ||
+        probability > 100)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+    }
+    else
+    {
+      hasProbabilityOfCancer_ = true;
+      probabilityOfCancer_ = probability;
+    }
   }
 
 
-  class DicomStructuredReport::Structure : public boost::noncopyable
+  unsigned int DicomStructuredReport::Structure::GetFrameNumber() const
   {
-  private:
-    std::string   sopInstanceUid_;
-    bool          hasFrameNumber_;
-    unsigned int  frameNumber_;
-    bool          hasProbabilityOfCancer_;
-    float         probabilityOfCancer_;
-
-  protected:
-    void Copy(const Structure& other)
+    if (hasFrameNumber_)
     {
-      if (other.HasFrameNumber())
-      {
-        SetFrameNumber(other.GetFrameNumber());
-      }
+      return frameNumber_;
+    }
+    else
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+    }
+  }
 
-      if (other.HasProbabilityOfCancer())
-      {
-        SetProbabilityOfCancer(other.GetProbabilityOfCancer());
-      }
-    }
-
-  public:
-    Structure(const std::string& sopInstanceUid) :
-      sopInstanceUid_(sopInstanceUid),
-      hasFrameNumber_(false),
-      hasProbabilityOfCancer_(false)
+  float DicomStructuredReport::Structure::GetProbabilityOfCancer() const
+  {
+    if (hasProbabilityOfCancer_)
     {
-    }
-
-    virtual ~Structure()
-    {
+      return probabilityOfCancer_;
     }
-
-    virtual Structure* Clone() const = 0;
-
-    const std::string& GetSopInstanceUid() const
+    else
     {
-      return sopInstanceUid_;
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
     }
+  }
 
-    void SetFrameNumber(unsigned int frame)
-    {
-      hasFrameNumber_ = true;
-      frameNumber_ = frame;
-    }
 
-    void SetProbabilityOfCancer(float probability)
-    {
-      if (probability < 0 ||
-          probability > 100)
-      {
-        throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
-      }
-      else
-      {
-        hasProbabilityOfCancer_ = true;
-        probabilityOfCancer_ = probability;
-      }
-    }
+  DicomStructuredReport::Point::Point(const std::string& sopInstanceUid,
+                                      double x,
+                                      double y) :
+    Structure(sopInstanceUid),
+    point_(x, y)
+  {
+  }
+
 
-    bool HasFrameNumber() const
-    {
-      return hasFrameNumber_;
-    }
+  DicomStructuredReport::Structure* DicomStructuredReport::Point::Clone() const
+  {
+    std::unique_ptr<Point> cloned(new Point(GetSopInstanceUid(), point_.GetX(), point_.GetY()));
+    cloned->Copy(*this);
+    return cloned.release();
+  }
 
-    bool HasProbabilityOfCancer() const
-    {
-      return hasProbabilityOfCancer_;
-    }
 
-    unsigned int GetFrameNumber() const
+  DicomStructuredReport::Polyline::Polyline(const std::string& sopInstanceUid,
+                                            const float* points,
+                                            unsigned long pointsCount) :
+    Structure(sopInstanceUid)
+  {
+    if (pointsCount % 2 != 0)
     {
-      if (hasFrameNumber_)
-      {
-        return frameNumber_;
-      }
-      else
-      {
-        throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
-      }
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
     }
 
-    float GetProbabilityOfCancer() const
+    points_.reserve(pointsCount / 2);
+
+    for (unsigned long i = 0; i < pointsCount; i += 2)
     {
-      if (hasProbabilityOfCancer_)
-      {
-        return probabilityOfCancer_;
-      }
-      else
-      {
-        throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
-      }
+      points_.push_back(ScenePoint2D(points[i], points[i + 1]));
     }
-  };
+  }
 
 
-  class DicomStructuredReport::Point : public Structure
+  DicomStructuredReport::Polyline::Polyline(const std::string& sopInstanceUid,
+                                            const std::vector<ScenePoint2D>& points) :
+    Structure(sopInstanceUid),
+    points_(points)
   {
-  private:
-    ScenePoint2D  point_;
-
-  public:
-    Point(const std::string& sopInstanceUid,
-          double x,
-          double y) :
-      Structure(sopInstanceUid),
-      point_(x, y)
-    {
-    }
-
-    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_;
-    }
-  };
+  }
 
 
-  class DicomStructuredReport::Polyline : public Structure
+  DicomStructuredReport::Structure* DicomStructuredReport::Polyline::Clone() const
   {
-  private:
-    std::vector<ScenePoint2D>  points_;
+    std::unique_ptr<Polyline> cloned(new Polyline(GetSopInstanceUid(), points_));
+    cloned->Copy(*this);
+    return cloned.release();
+  }
 
-  public:
-    Polyline(const std::string& sopInstanceUid,
-             const float* points,
-             unsigned long pointsCount) :
-      Structure(sopInstanceUid)
-    {
-      if (pointsCount % 2 != 0)
-      {
-        throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
-      }
-
-      points_.reserve(pointsCount / 2);
-
-      for (unsigned long i = 0; i < pointsCount; i += 2)
-      {
-        points_.push_back(ScenePoint2D(points[i], points[i + 1]));
-      }
-    }
 
-    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
+  const ScenePoint2D& DicomStructuredReport::Polyline::GetPoint(size_t i) const
+  {
+    if (i >= points_.size())
     {
-      return points_.size();
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
-
-    const ScenePoint2D& GetPoint(size_t i) const
+    else
     {
-      if (i >= points_.size())
-      {
-        throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
-      }
-      else
-      {
-        return points_[i];
-      }
+      return points_[i];
     }
-  };
+  }
 
 
   void DicomStructuredReport::AddStructure(const std::string& sopInstanceUid,
@@ -573,7 +518,7 @@
       instancesInformation_[it->first] = new ReferencedInstance(*it->second);
     }
 
-    for (std::list<Structure*>::const_iterator it = other.structures_.begin(); it != other.structures_.end(); ++it)
+    for (std::deque<Structure*>::const_iterator it = other.structures_.begin(); it != other.structures_.end(); ++it)
     {
       assert(*it != NULL);
       structures_.push_back((*it)->Clone());
@@ -583,7 +528,7 @@
 
   DicomStructuredReport::~DicomStructuredReport()
   {
-    for (std::list<Structure*>::iterator it = structures_.begin(); it != structures_.end(); ++it)
+    for (std::deque<Structure*>::iterator it = structures_.begin(); it != structures_.end(); ++it)
     {
       assert(*it != NULL);
       delete *it;
@@ -648,4 +593,18 @@
       }
     }
   }
+
+
+  const DicomStructuredReport::Structure& DicomStructuredReport::GetStructure(size_t index) const
+  {
+    if (index >= structures_.size())
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+    }
+    else
+    {
+      assert(structures_[index] != NULL);
+      return *structures_[index];
+    }
+  }
 }