mymesh.implicit.VoxelMesh#

mymesh.implicit.VoxelMesh(func, bounds, h, threshold=0, threshold_direction=-1, mode='any', args=(), kwargs={})[source]#

Generate voxel 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. 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.

  • mode (str, optional) – Mode for determining which elements are kept, by default ‘any’. Voxels will be kept if: ‘any’ - if any node of a voxel is inside the surface, ‘all’ - if all nodes of a voxel are inside the surface, ‘centroid’ - if the centroid of the voxel is inside the surface. Centroids performs additional evaluation of the function, which could slow mesh generation for expensive to evaluate functions, ‘boundary’ - if the voxel contains values above and below the threshold, ‘notrim’ - all voxels are kept

  • args (tuple, optional) – Tuple of additional positional arguments for func, by default ().

  • kwargs (dict, optional) – Dictionary of additional keyword arguments for func, by default {}

Returns:

voxel – Mesh object containing the voxel mesh. The values of the function at each node are stored in voxel.NodeData[‘func’]

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.VoxelMesh(...)

Return type:

mymesh.mesh

Examples

voxel = implicit.VoxelMesh(implicit.gyroid, [0,1,0,1,0,1], 0.05)
voxel.plot(bgcolor='w', scalars=voxel.NodeData['func'])
../../_images/mymesh-implicit-VoxelMesh-1.png