mymesh.contour.MarchingTetrahedra#
- mymesh.contour.MarchingTetrahedra(TetNodeCoords, TetNodeConn, NodeValues, threshold=0, interpolation='linear', Type='surf', mixed_elements=False, flip=False, return_NodeValues=False, return_ParentIds=False, cleanup_tol=1e-10, cleanup=True)[source]#
Marching tetrahedra algorithm [Blo94] for extracting an isosurface from a tetrahedral mesh. This can be used to generate either a surface mesh or a volume mesh, with either simplex elements (triangles, tetrahedra) or mixed elements (triangles/quadrilaterals, tetrahedra/wedges).
- Parameters:
TetNodeCoords (array_like) – Node coordinates for the input tetrahedral mesh
TetNodeConn (array_like) – Node connectivity for the input tetrahedral mesh. All elements must be tetrahedra.
NodeValues (array_like) – Values at each node in the mesh that are used to extract the isosurface
threshold (int, optional) – Isosurface level, by default 0
interpolation (str, optional) –
Interpolation to interpolate the position of the new nodes along the edges of the input mesh, by default ‘linear’.
’midpoint’ - No interpolation is performed, new nodes are placed at the midpoint of edges
’linear’ - Linear interpolation is performed between adjacent nodes on the input mesh.
’quadratic’ - Quadratic interpolation is performed. This requires that the provided tetrahedral mesh has quadratic elements (10 node tetrahedra).
Type (str, optional) – Determines whether to generate a surface mesh (‘surf’) or volume mesh (‘vol’), by default ‘surf’
mixed_elements (bool, optional) – If True, the generated mesh will have mixed element types (triangles/quadrilaterals, tetrahedra/wedges), otherwise a single element type (triangles, tetrahedra), by default False. For surface meshes, either version is generated directly. For a volume mesh, a mixed mesh is generated initially and then converted to tetrahedra using converter.solid2tets() which results in additional computational cost.
flip (bool, optional) – Flip the interior/exterior of the mesh, by default False. By default, values less than the threshold are assumed to be the “inside” of the mesh. If the inside is denoted by values greater than the threshold, set flip=True.
return_NodeValues (bool, optional) – Return the node values for each node in the tetrahedral mesh. If method=’surface’, these will all be threshold, if method=’volume’, these will be threshold for the surface nodes and the original grid values for the interior nodes
return_ParentIds (bool, optional) – Return Ids that refer to the original tetrahedra that each of the new elements is connected to, by default False.
cleanup_tol (float, optional) – Tolerance value used to classify whether two nodes are sufficiently close to be considered a single node (see
mymesh.utils.DeleteDuplicateNodes()
), by default 1e-12.
- Returns:
NodeCoords (np.ndarray) – Node coordinates of the generated mesh
NodeConn (list) – Node connetivity for the generated mesh
NewValues (np.ndarray, optional) – Node values transfered to the generated mesh, returned if return_NodeValues=True
ParentIds (np.ndarray, optional) – Element ids that refer to the original tetrahedra that each of the new elements is connected to, returned if return_ParentIds=True
Examples
>>> # Create a uniform tetrahedral grid >>> Grid = primitives.Grid([0,2,0,2,0,2],0.1,ElemType='tet') >>> # Define an implicit function for two spheres and evaluate on the grid >>> func = lambda x,y,z : implicit.union(implicit.sphere(x,y,z,0.3,[0.7,0.7,0.7]),implicit.sphere(x,y,z,0.3,[1.2,1.2,1.2])) >>> NodeValues = func(Grid.NodeCoords[:,0],Grid.NodeCoords[:,1],Grid.NodeCoords[:,2]) >>> # Perform marching tetrahedra >>> NodeCoords, NodeConn = contour.MarchingTetrahedra(Grid.NodeCoords,Grid.NodeConn,NodeValues, method='surface')