Utilities

Curves

Implementation of various curve utilities

splipy.utils.curve.curve_length_parametrization(pts, normalize=False)[source]

Calculate knots corresponding to a curvelength parametrization of a set of points.

Parameters:
  • pts (numpy.array) – A set of points
  • normalize (bool) – Whether to normalize the parametrization
Returns:

The parametrization

Return type:

[float]

splipy.utils.curve.get_curve_points(curve)[source]

Evaluate the curve in all its knots.

Parameters:curve (splipy.Curve) – The curve
Returns:The curve points
Type:numpy.array

Images

Implementation of image based mesh generation.

splipy.utils.image.get_corners(X, L=50, R=30, D=15)[source]

Detects corners of traced outlines using the SAM04 algorithm.

The outline is assumed to constitute a discrete closed curve where each point is included just once. Increasing D and R will give the same number of corners or fewer corners.

Parameters:
  • X (numpy.array) – A traced outline forming a discrete closed curve (size n × 2)
  • L (float) – Controls the scale at which corners are measured.
  • R (float) – Controls how close corners can appear.
  • D (float) – The lower bound for the corner metric. Corner candidates with lower metric than this are rejected.
Returns:

The indices of X that consitute corner points

Return type:

numpy.array

splipy.utils.image.image_convex_surface(filename)[source]

Generate a single B-spline surface corresponding to convex black domain of a black/white mask image. The algorithm traces the boundary and searches for 4 natural corner points. It will then generate 4 boundary curves which will be used to create the surface by Coons Patch.

Parameters:filename (str) – Name of image file to read
Returns:B-spline surface
Return type:splipy.Surface
splipy.utils.image.image_curves(filename)[source]

Generate B-spline curves corresponding to the edges in a black/white mask image.

Parameters:filename (str) – Name of image file to read
Returns:All curves generated by tracing the black/white edges
Return type:[splipy.Curve]
splipy.utils.image.image_height(filename, N=[30, 30], p=[4, 4])[source]

Generate a B-spline surface approximation given by the heightmap in a grayscale image.

Parameters:
  • filename (str) – Name of image file to read
  • N ((int,int)) – Number of controlpoints in u-direction
  • p ((int,int)) – Polynomial order (degree+1)
Returns:

Normalized (all values between 0 and 1) heightmap approximation

Return type:

splipy.Surface

Refinement

Implementation of various refinement schemes.

splipy.utils.refinement.edge_refine(obj, S, n[, direction=0])[source]

Refine an object towards both edges in a direction, by sampling an arctan function.

Parameters:
  • obj (splipy.SplineObject) – The object to refine
  • S (float) – The slope of the arctan function.
  • n (int) – The number of knots to insert
  • direction – The direction to refine in
splipy.utils.refinement.geometric_refine(obj, alpha, n[, direction=0][, reverse=False])[source]

Refine a spline object by making a geometric distribution of element sizes.

Parameters:
  • obj (splipy.SplineObject) – The object to refine
  • alpha (float) – The length ratio between two sequential knot segments
  • n (int) – The number of knots to insert
  • direction – The direction to refine in
  • reverse (bool) – Set to True to refine towards the other end
splipy.utils.refinement.subdivide(objs, n)[source]

Subdivide a list of objects by splitting them up along existing knot lines. The resulting partition will roughly the same number of elements on all pieces. By splitting along n lines, we generate n + 1 new blocks.

The number of subdivisions can be a list of integers: one for each direction, or a single integer for uniform sudivision.

Parameters:
  • objs – Objects to split
  • n (int or [int]) – Number of subdivisions to perform
Returns:

New objects

Return type:

[splipy.SplineObject]

Smoothing

Implementation of various smoothing operations on a per-controlpoint level.

splipy.utils.smooth.smooth(obj)[source]

Smooth an object by setting the interior control points to the average of itself and all neighbours (e.g. 9 for surfaces, 27 for volumes). The edges are kept unchanged, and any rational weights are kept unchanged.

Parameters:obj (splipy.SplineObject) – The object to smooth

Nutils

Implementation of convenience methods with respect to nutils integration.

splipy.utils.nutils.controlpoints(spline)[source]

Return controlpoints according to nutils ordering

splipy.utils.nutils.degree(spline)[source]

Returns polynomial degree (splipy order - 1) for all parametric directions

splipy.utils.nutils.multiplicities(spline)[source]

Returns the multiplicity of the knots at all knot values as a 2D array for all parametric directions, for all knots

splipy.utils.nutils.splipy_to_nutils(spline)[source]

Returns nutils domain and geometry object for spline mapping given by the argument