From 716bdb9e3e9609075533906f07d2fbf6a489e86b Mon Sep 17 00:00:00 2001 From: Jacob Spainhour Date: Fri, 5 Aug 2022 16:55:08 -0700 Subject: [PATCH] Add split to convex function --- src/axom/primal/operators/split.hpp | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/axom/primal/operators/split.hpp b/src/axom/primal/operators/split.hpp index 044edcdf58..eb5b5b9be3 100644 --- a/src/axom/primal/operators/split.hpp +++ b/src/axom/primal/operators/split.hpp @@ -17,6 +17,11 @@ #include "axom/primal/geometry/Octahedron.hpp" #include "axom/primal/geometry/Tetrahedron.hpp" +#include "axom/primal/geometry/BezierCurve.hpp" +#include "axom/primal/geometry/Polygon.hpp" +#include "axom/primal/geometry/CurvedPolygon.hpp" +#include "axom/primal/operators/is_convex.hpp" + #include "axom/slic.hpp" // perhaps #include split_impl.hpp here @@ -78,6 +83,53 @@ void split(const Octahedron& oct, out.push_back(Tet(oct[Q], oct[S], oct[U], C)); }; +/*! + * \brief Splits a BezierCurve object into convex Bezier Curves + * + * \param [in] c BezierCurve to split + * \param [out] out The \a axom::Array of BezierCurve objects; a set of convex + * components of c are appended to out. + * + * \pre NDIMS == 2 + * + * Uses a bisection method, splitting the curve recursively until each section + * is convex. + * + */ +template +void split_to_convex(const BezierCurve& c, + axom::Array>& out) +{ + // Implemented for two dimensions + SLIC_ASSERT(NDIMS == 2); + + using Poly = Polygon; + using Bez = BezierCurve; + + if(is_convex(Poly(c.getControlPoints()))) + out.push_back(Bez(c)); + else + { + Bez c1, c2; + c.split(0.5, c1, c2); + split_to_convex(c1, out); + split_to_convex(c2, out); + } +} + +template +void split_to_convex(const CurvedPolygon& cpoly, + axom::Array>& out) +{ + // Implemented for two dimensions + SLIC_ASSERT(NDIMS == 2); + + using Poly = Polygon; + using Bez = BezierCurve; + + for(int i = 0; i < cpoly.numEdges(); i++) split_to_convex(cpoly[i], out); +} + } // namespace primal } // namespace axom