# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import marching_cubes [as 别名]
def compute_marching_cubes_regular_grid(self, level: float, scalar_field,
mask_array=None,
rescale=False, **kwargs):
"""Compute the surface (vertices and edges) of a given surface by computing
marching cubes (by skimage)
Args:
level (float): value of the scalar field at the surface
scalar_field (np.array): scalar_field vector objects
mask_array (np.array): mask vector with trues where marching cubes has to be performed
rescale (bool): if True surfaces will be located between 0 and 1
**kwargs: skimage.measure.marching_cubes_lewiner args (see below)
Returns:
list: vertices, simplices, normals, values
See Also:
:func:`skimage.measure.marching_cubes`
vertices, simplices, normals, values = measure.marching_cubes(
scalar_field.reshape(self.grid.regular_grid.resolution[0],
self.grid.regular_grid.resolution[1],
self.grid.regular_grid.resolution[2]),
level,
spacing=self.grid.regular_grid.get_dx_dy_dz(rescale=rescale),
mask=mask_array,
**kwargs)
if rescale is True:
loc_0 = self.grid.regular_grid.extent_r[[0, 2, 4]] + \
np.array(self.grid.regular_grid.get_dx_dy_dz(rescale=True)) / 2
vertices += np.array(loc_0).reshape(1, 3)
else:
loc_0 = self.grid.regular_grid.extent[[0, 2, 4]] + \
np.array(self.grid.regular_grid.get_dx_dy_dz(rescale=False)) / 2
vertices += np.array(loc_0).reshape(1, 3)
return [vertices, simplices, normals, values]
# def mask_topo(self, mask_matrix):
# """Add the masked elements of the topography to the masking matrix"""
# x = ~self.grid.regular_grid.mask_topo
# a = (np.swapaxes(x, 0, 1) * mask_matrix)
# return a