mymesh.contour.Adaptive#

mymesh.contour.Adaptive(func, bounds, threshold=0, method=None, grad=None, mindepth=2, maxdepth=5, octree_strategy='EDerror', octree_eps=0.1, dualgrid_method='centroid', Type='surf')[source]#

Adaptively contour an implicit function. Uses an octree (Function2Octree()) to adaptively sample the function, then uses the chosen method to contour the dual grid (Octree2Dual()) of the octree.

Based on, but not an exact implementation of, Dual Marching Cubes [SW05].

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) and capable of handling vectorized inputs.

  • 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]

  • threshold (scalar) – Isovalue threshold to use for keeping/removing elements, by default 0.

  • method (str, optional) –

    Contouring method to be used

    • ”mc”: Marching Cubes

    • ”mc33”: Marching Cubes 33

    • ”mt”: Marching Tetrahedra

    By default, “mc33” will be chosen if Type=’surf’ and “mt” if Type=’vol’.

  • grad (function, optional) – Gradient of the function. By default, the gradient will be obtained through either symbolic differentiation or finite difference approximation.

  • mindepth (int, optional) – Minimum octree depth, by default 2

  • maxdepth (int, optional) – Maximum octree depth, by default 5

  • octree_strategy (str, optional) – Octree subdivision strategy (see Function2Octree()), by default ‘EDerror’.

  • octree_eps (float, optional) – Error tolerance for octree subdivision (see Function2Octree()), by default 0.1

  • dualgrid_method (str, optional) – Method for placing dual grid vertices (see Octree2Dual()), by default ‘centroid’.

  • Type (str, optional) – Specifies whether to generate a surface mesh (“surf”) or a volume mesh (“vol”), by default ‘surf’

Returns:

  • NodeCoords (np.ndarray) – Node Coordinates of the contour mesh.

  • NodeConn (list) – Node connectivity list.

Examples

func = implicit.unionf(implicit.box(-1.5,0,-1.5,0,-1.5,1.5),implicit.sphere([0,0,0], 1))
bounds = [-2,2,-2,2,-2,2]

S = mesh(*contour.Adaptive(func, bounds, mindepth=2, maxdepth=7))
S.plot(bgcolor='w', show_edges=True)
../../_images/mymesh-contour-Adaptive-1.png