changeset 1904:738814c24574

speed up rendering of axial slices of RT-STRUCT
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 31 Jan 2022 18:22:57 +0100
parents c7bc9e1776a6
children e318b524ad3f
files OrthancStone/Sources/Toolbox/DicomStructureSet.cpp OrthancStone/Sources/Toolbox/DicomStructureSet.h
diffstat 2 files changed, 42 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancStone/Sources/Toolbox/DicomStructureSet.cpp	Mon Jan 31 18:00:10 2022 +0100
+++ b/OrthancStone/Sources/Toolbox/DicomStructureSet.cpp	Mon Jan 31 18:22:57 2022 +0100
@@ -274,28 +274,52 @@
     }
   }
 
-  bool DicomStructureSet::Polygon::IsOnSlice(const CoordinateSystem3D& slice) const
+  bool DicomStructureSet::Polygon::IsOnSlice(const CoordinateSystem3D& slice,
+                                             const Vector& estimatedNormal,
+                                             double estimatedSliceThickness) const
   {
     bool isOpposite = false;
 
-    if (points_.empty() ||
-        !hasSlice_ ||
-        !GeometryToolbox::IsParallelOrOpposite(isOpposite, slice.GetNormal(), geometry_.GetNormal()))
+    if (points_.empty())
     {
       return false;
     }
-    
-    double d = GeometryToolbox::ProjectAlongNormal(slice.GetOrigin(), geometry_.GetNormal());
-
-    return (LinearAlgebra::IsNear(d, projectionAlongNormal_,
-                                  sliceThickness_ / 2.0));
+    else if (hasSlice_)
+    {
+      // Use the actual geometry of this specific slice
+      if (!GeometryToolbox::IsParallelOrOpposite(isOpposite, slice.GetNormal(), geometry_.GetNormal()))
+      {
+        return false;
+      }
+      else
+      {
+        double d = GeometryToolbox::ProjectAlongNormal(slice.GetOrigin(), geometry_.GetNormal());
+        return (LinearAlgebra::IsNear(d, projectionAlongNormal_, sliceThickness_ / 2.0));
+      }
+    }
+    else
+    {
+      // Use the estimated geometry for the global RT-STRUCT volume
+      if (!GeometryToolbox::IsParallelOrOpposite(isOpposite, slice.GetNormal(), estimatedNormal))
+      {
+        return false;
+      }
+      else
+      {
+        double d1 = GeometryToolbox::ProjectAlongNormal(slice.GetOrigin(), estimatedNormal);
+        double d2 = GeometryToolbox::ProjectAlongNormal(points_.front(), estimatedNormal);
+        return (LinearAlgebra::IsNear(d1, d2, estimatedSliceThickness / 2.0));
+      }
+    }
   }
     
   bool DicomStructureSet::Polygon::Project(double& x1,
                                            double& y1,
                                            double& x2,
                                            double& y2,
-                                           const CoordinateSystem3D& slice) const
+                                           const CoordinateSystem3D& slice,
+                                           const Vector& estimatedNormal,
+                                           double estimatedSliceThickness) const
   {
     if (!hasSlice_ ||
         points_.size() <= 1)
@@ -841,7 +865,7 @@
       {
         const Points& points = polygon->GetPoints();
         
-        if (polygon->IsOnSlice(slice) &&
+        if (polygon->IsOnSlice(slice, GetEstimatedNormal(), GetEstimatedSliceThickness()) &&
             !points.empty())
         {
           chains.push_back(std::vector<ScenePoint2D>());
@@ -938,7 +962,7 @@
       {
         double x1, y1, x2, y2;
 
-        if (polygon->Project(x1, y1, x2, y2, slice))
+        if (polygon->Project(x1, y1, x2, y2, slice, GetEstimatedNormal(), GetEstimatedSliceThickness()))
         {
           double curZ = polygon->GetGeometryOrigin()[2];
 
--- a/OrthancStone/Sources/Toolbox/DicomStructureSet.h	Mon Jan 31 18:00:10 2022 +0100
+++ b/OrthancStone/Sources/Toolbox/DicomStructureSet.h	Mon Jan 31 18:22:57 2022 +0100
@@ -103,7 +103,9 @@
 
       bool UpdateReferencedSlice(const ReferencedSlices& slices);
 
-      bool IsOnSlice(const CoordinateSystem3D& geometry) const;
+      bool IsOnSlice(const CoordinateSystem3D& geometry,
+                     const Vector& estimatedNormal,
+                     double estimatedSliceThickness) const;
 
       const Vector& GetGeometryOrigin() const
       {
@@ -129,7 +131,9 @@
                    double& y1,
                    double& x2,
                    double& y2,
-                   const CoordinateSystem3D& slice) const;
+                   const CoordinateSystem3D& slice,
+                   const Vector& estimatedNormal,
+                   double estimatedSliceThickness) const;
     };
 
     typedef std::list<Polygon>  Polygons;