mymesh.implicit.SurfaceMesh#
- mymesh.implicit.SurfaceMesh(func, bounds, h, threshold=0, threshold_direction=-1, method='mc', interpolation='linear', mixed_elements=False, args=(), kwargs={}, snap2surf=None)[source]#
Generate a surface mesh of an implicit function
- Parameters:
func (function) – Implicit function that describes the geometry of the object to be meshed. The function should be of the form v = f(x,y,z,*args,**kwargs) where x, y, and z are 1D numpy arrays of x, y and z coordinates and v is a 1D numpy array of function values. For method=’mc’, x, y, and z will be 3D coordinate arrays and v must be 3D as well. Additional arguments and keyword arguments may be passed through args and kwargs.
bounds (array_like) – 6 element array, list, or tuple with the minimum and maximum bounds in each direction that the function will be evaluated. This should be formatted as: [xmin, xmax, ymin, ymax, zmin, zmax]
h (scalar, tuple) – Element side length. Can be specified as a single scalar value, or a three element tuple (or array_like).
threshold (scalar) – Isovalue threshold to use for keeping/removing elements, by default 0.
threshold_direction (signed integer) – If threshold_direction is negative (default), values less than or equal to the threshold will be considered “inside” the mesh and the opposite if threshold_direction is positive, by default -1.
method (str, optional) –
Surface triangulation method, by default ‘mc’. ‘mc’ : Marching cubes (see contour.MarchingCubesImage) (default)
’mc33’ : Marching cubes 33 (see contour.MarchingCubes)
’mt’ : Marching tetrahedra (see contour.MarchingTetrahedra)
interpolation (str, optional) – Method of interpolation used for placing the vertices on the approximated isosurface. This can be ‘midpoint’, ‘linear’, or ‘cubic’, by default ‘linear’. If ‘cubic’ is selected, method is overridden to be ‘mc’.
mixed_elements (bool, optional) – If marching tetrahedra is used, setting mixed_elements to True will allow for a surface mesh with a combination of quads and tris, by default False.
args (tuple, optional) – Tuple of additional positional arguments for func, by default ().
kwargs (dict, optional) – Dictionary of additional keyword arguments for func, by default {}.
snap2surf (bool or float, optional) – Option to use
SnapGrid2Surf()
which moves points of the background mesh to lie on the surface. If specified as a float in the range [0, 0.5], sets the snapping parameter which indicates the relative distance within which a point is snapped (0 = no snapping, 0.5 = all possible points are snapped). If True, default snapping parameter of 0.2 is used. Snapping isn’t compatible with method == ‘mc’ or interpolation==’cubic’, if either of these options are selected, no snapping will occur, regardless of the snap2surf input. By default, True.
- Returns:
surface – Mesh object containing the surface mesh.
Note
Due to the ability to unpack the mesh object to NodeCoords and NodeConn, the NodeCoords and NodeConn array can be returned directly (instead of the mesh object) by running:
NodeCoords, NodeConn = implicit.SurfaceMesh(...)
- Return type:
Examples
surface = implicit.SurfaceMesh(implicit.gyroid, [0,1,0,1,0,1], 0.05) surface.plot(bgcolor='w')