Skip to content

Commit

Permalink
Add split to convex function
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs15c committed Aug 5, 2022
1 parent 2c629ac commit 716bdb9
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/axom/primal/operators/split.hpp
Expand Up @@ -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
Expand Down Expand Up @@ -78,6 +83,53 @@ void split(const Octahedron<Tp, NDIMS>& 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 <typename Tp, int NDIMS = 2>
void split_to_convex(const BezierCurve<Tp, NDIMS>& c,
axom::Array<BezierCurve<Tp, NDIMS>>& out)
{
// Implemented for two dimensions
SLIC_ASSERT(NDIMS == 2);

using Poly = Polygon<Tp, NDIMS>;
using Bez = BezierCurve<Tp, NDIMS>;

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 <typename Tp, int NDIMS = 2>
void split_to_convex(const CurvedPolygon<Tp, NDIMS>& cpoly,
axom::Array<BezierCurve<Tp, NDIMS>>& out)
{
// Implemented for two dimensions
SLIC_ASSERT(NDIMS == 2);

using Poly = Polygon<Tp, NDIMS>;
using Bez = BezierCurve<Tp, NDIMS>;

for(int i = 0; i < cpoly.numEdges(); i++) split_to_convex(cpoly[i], out);
}

} // namespace primal
} // namespace axom

Expand Down

0 comments on commit 716bdb9

Please sign in to comment.