Created
June 18, 2021 07:51
-
-
Save agramfort/87069a5ebe43f7140322df6c3d228cbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import vtk | |
import pyvista as pv | |
from vtk.util import numpy_support | |
# from vtk.numpy_interface import dataset_adapter as dsa | |
data = np.zeros((50, 50, 50)) | |
data[20:30, 20:30, 20:30] = 1 | |
data_vtk = numpy_support.numpy_to_vtk( | |
data.ravel(), deep=True, array_type=vtk.VTK_DOUBLE | |
) | |
imdata = vtk.vtkImageData() | |
imdata.SetDimensions(data.shape) | |
imdata.SetSpacing([1, 1, 1]) | |
imdata.SetOrigin([0, 0, 0]) | |
imdata.GetPointData().SetScalars(data_vtk) | |
mc = vtk.vtkMarchingCubes() | |
mc.SetInputData(imdata) | |
mc.SetValue(0, 0.5) | |
mc.Update() | |
polydata = mc.GetOutput() | |
# points = dsa.WrapDataObject(polydata).Points | |
mesh = pv.PolyData(polydata) | |
mesh.plot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment