# HG changeset patch # User Sebastien Jodogne # Date 1643649777 -3600 # Node ID 738814c24574e426ec1b1dde70d500e591233478 # Parent c7bc9e1776a66f5ac164503ff28a53771bfe4024 speed up rendering of axial slices of RT-STRUCT diff -r c7bc9e1776a6 -r 738814c24574 OrthancStone/Sources/Toolbox/DicomStructureSet.cpp --- 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()); @@ -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]; diff -r c7bc9e1776a6 -r 738814c24574 OrthancStone/Sources/Toolbox/DicomStructureSet.h --- 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 Polygons;