# HG changeset patch # User Sebastien Jodogne # Date 1643222524 -3600 # Node ID a5e54bd87b25506bee16683e9032d98422820639 # Parent 144f8f82c15a27d9cb10ae4498b68207c50c3686 try to use UnionOfRectangles in DicomStructureSet diff -r 144f8f82c15a -r a5e54bd87b25 OrthancStone/Sources/Toolbox/DicomStructureSet.cpp --- a/OrthancStone/Sources/Toolbox/DicomStructureSet.cpp Wed Jan 26 17:28:47 2022 +0100 +++ b/OrthancStone/Sources/Toolbox/DicomStructureSet.cpp Wed Jan 26 19:42:04 2022 +0100 @@ -21,10 +21,9 @@ **/ -#define USE_BOOST_UNION_FOR_POLYGONS 1 +#define USE_BOOST_UNION_FOR_POLYGONS 0 #include "DicomStructureSet.h" -#include "DicomStructureSetUtils.h" // TODO REMOVE #include "BucketAccumulator2D.h" #include "GenericToolbox.h" @@ -57,6 +56,9 @@ # include # include # include +#else +# include "DicomStructureSetUtils.h" // TODO REMOVE +# include "UnionOfRectangles.h" #endif #if defined(_MSC_VER) @@ -190,28 +192,6 @@ GenericToolbox::FastParseVector(target, value)); } - void DicomStructureSet::Polygon::CheckPointIsOnSlice(const Vector& v) const - { - if (hasSlice_) - { - double magnitude = - GeometryToolbox::ProjectAlongNormal(v, geometry_.GetNormal()); - if(!LinearAlgebra::IsNear( - magnitude, - projectionAlongNormal_, - sliceThickness_ / 2.0 /* in mm */ )) - { - LOG(ERROR) << "This RT-STRUCT contains a point that is off the " - << "slice of its instance | " - << "magnitude = " << magnitude << " | " - << "projectionAlongNormal_ = " << projectionAlongNormal_ << " | " - << "tolerance (sliceThickness_ / 2.0) = " << (sliceThickness_ / 2.0); - - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); - } - } - } - bool DicomStructureSet::Polygon::IsPointOnSliceIfAny(const Vector& v) const { if (hasSlice_) @@ -269,6 +249,8 @@ } else { + // return true; // TODO - TEST + const CoordinateSystem3D& geometry = it->second.geometry_; hasSlice_ = true; @@ -315,8 +297,6 @@ double& y2, const CoordinateSystem3D& slice) const { - // TODO: optimize this method using a sweep-line algorithm for polygons - if (!hasSlice_ || points_.size() <= 1) { @@ -916,6 +896,36 @@ chains[i][j] = ScenePoint2D(outer[j].x(), outer[j].y()); } } + +#elif 0 + + // TODO - Fix possible infinite loop in UnionOfRectangles + + std::list rectangles; + + for (Polygons::const_iterator polygon = structure.polygons_.begin(); + polygon != structure.polygons_.end(); ++polygon) + { + double x1, y1, x2, y2; + + if (polygon->Project(x1, y1, x2, y2, slice)) + { + rectangles.push_back(Extent2D(x1, y1, x2, y2)); + } + } + + typedef std::list< std::vector > Contours; + + Contours contours; + UnionOfRectangles::Apply(contours, rectangles); + + chains.reserve(contours.size()); + + for (Contours::const_iterator it = contours.begin(); it != contours.end(); ++it) + { + chains.push_back(*it); + } + #else // this will contain the intersection of the polygon slab with // the cutting plane, projected on the cutting plane coord system diff -r 144f8f82c15a -r a5e54bd87b25 OrthancStone/Sources/Toolbox/DicomStructureSet.h --- a/OrthancStone/Sources/Toolbox/DicomStructureSet.h Wed Jan 26 17:28:47 2022 +0100 +++ b/OrthancStone/Sources/Toolbox/DicomStructureSet.h Wed Jan 26 19:42:04 2022 +0100 @@ -83,7 +83,6 @@ Points points_; Extent2D extent_; - void CheckPointIsOnSlice(const Vector& v) const; bool IsPointOnSliceIfAny(const Vector& v) const; public: