vtkSampleFunction normals using a mask
03:49 08 Apr 2026

I have a PolyData mesh from which I computed a vtkImplicitPolyDataDistance. Then I use a vtkSampleFunction() to compute normals to the mesh on all the voxels of a regular 3D grid.
My code is the following :

sampler = vtk.vtkSampleFunction()
sampler.SetImplicitFunction(implicit)
sampler.SetModelBounds(bounds)
sampler.SetSampleDimensions(nx,ny,nz)
sampler.ComputeNormalsOn()
sampler.Update()

normals = vtk_to_numpy(sampler.GetOutput().GetPointData().GetNormals())[mask]

My issue is that I only need to know the normals on a specific set of voxels, as determined by a mask.

Is there any way to compute the normals from the sampler only for this mask, in order to have a faster computation?

It should be noted that this mask is sparse, and cannot be equivalent to a manipulation of bounds and spacing.

python mesh vtk normals