# HG changeset patch # User Sebastien Jodogne # Date 1745338710 -7200 # Node ID a10b7a6ec86900011d44f5eac99007bf7929ed38 # Parent c098f0f16eb1e54f1bd9177f29bbc813d3504a59 cached projected segments to speed up DicomStructureSet diff -r c098f0f16eb1 -r a10b7a6ec869 OrthancStone/Sources/Toolbox/DicomStructureSet.cpp --- a/OrthancStone/Sources/Toolbox/DicomStructureSet.cpp Tue Apr 22 18:09:13 2025 +0200 +++ b/OrthancStone/Sources/Toolbox/DicomStructureSet.cpp Tue Apr 22 18:18:30 2025 +0200 @@ -274,7 +274,7 @@ void DicomStructureSet::Polygon::Project(std::list& target, const CoordinateSystem3D& cuttingPlane, const Vector& estimatedNormal, - double estimatedSliceThickness) const + double estimatedSliceThickness) { CoordinateSystem3D geometry; double thickness = estimatedSliceThickness; @@ -362,14 +362,33 @@ return; // Should never happen } + if (cachedProjectedSegments_.get() == NULL || + !cachedGeometry_.Equals(geometry)) + { + cachedGeometry_ = geometry; + + cachedProjectedSegments_.reset(new std::vector()); + cachedProjectedSegments_->resize(2 * points_.size()); + + for (size_t i = 0; i < points_.size(); i++) + { + double x, y; + geometry.ProjectPoint(x, y, points_[i]); + (*cachedProjectedSegments_) [2 * i] = x; + (*cachedProjectedSegments_) [2 * i + 1] = y; + } + } + std::vector intersections; intersections.reserve(points_.size()); for (size_t i = 0; i < points_.size(); i++) { - double segmentX1, segmentY1, segmentX2, segmentY2; - geometry.ProjectPoint(segmentX1, segmentY1, points_[i]); - geometry.ProjectPoint(segmentX2, segmentY2, points_[(i + 1) % points_.size()]); + const size_t next = (i + 1) % points_.size(); + const double segmentX1 = (*cachedProjectedSegments_) [2 * i]; + const double segmentY1 = (*cachedProjectedSegments_) [2 * i + 1]; + const double segmentX2 = (*cachedProjectedSegments_) [2 * next]; + const double segmentY2 = (*cachedProjectedSegments_) [2 * next + 1]; double x, y; if (GeometryToolbox::IntersectLineAndSegment(x, y, cuttingX1, cuttingY1, cuttingX2, cuttingY2, diff -r c098f0f16eb1 -r a10b7a6ec869 OrthancStone/Sources/Toolbox/DicomStructureSet.h --- a/OrthancStone/Sources/Toolbox/DicomStructureSet.h Tue Apr 22 18:09:13 2025 +0200 +++ b/OrthancStone/Sources/Toolbox/DicomStructureSet.h Tue Apr 22 18:18:30 2025 +0200 @@ -82,6 +82,9 @@ double sliceThickness_; // In millimeters Points points_; + CoordinateSystem3D cachedGeometry_; + std::unique_ptr< std::vector > cachedProjectedSegments_; + bool IsPointOnSliceIfAny(const Vector& v) const; public: @@ -129,7 +132,7 @@ void Project(std::list& target, const CoordinateSystem3D& cuttingPlane, const Vector& estimatedNormal, - double estimatedSliceThickness) const; + double estimatedSliceThickness); }; typedef std::list Polygons;