Extracting isosurface from a vtkImageData

71 Views Asked by At

I am trying to create an isosurface plot from a vtkImageData. I have a numpy array which has the scalar fields. I kept the scalar field as 0 and 1 for testing. Given below is my pipeline:

import vtk
from vtk.util import numpy_support
import numpy as np

# Load scalar data from npy file
scalars=np.load("Scalar.npy")

# Convert numpy array to vtk
scalars=numpy_support.numpy_to_vtk(scalars)
scalars.SetName("Scalar")

# Create a vtkImageData 
grid =vtk.vtkImageData()
grid.SetDimensions(251, 251, 101)
grid.SetSpacing(0.1, 0.1, 0.25)
grid.SetOrigin(0,0,0)

# Add scalar field to the ImageData
grid.GetPointData().SetScalars(scalars)

# Get Isosurface using contour filter
contourFilter = vtk.vtkContourFilter()
contourFilter.SetInputData(grid)
contourFilter.SetArrayComponent (0)
contourFilter.SetValue(0, 1)
contourFilter.Update()
outData=contourFilter.GetOutput()

However, I am unable to get the isosurface from the contour filter. The number of points in outData outData.GetNumberOfPoints() is giving 0. However, I have value 1 at 211573 places. np.count_nonzero(scalars[scalars==1]) gives 211573. I have saved the numpy array used in the above code here.

Please help me to solve this issue and understand what I am doing wrong here.

0

There are 0 best solutions below