Skip to content

Improved iterators for marching though images with stencils.

David Gobbi requested to merge dgobbi/vtk:image-point-iterator into master

This commit adds two new stencil-aware iterators and one new filter.

vtkImagePointDataIterator marches through an extent, using an optional stencil to allow for arbitrarily-shaped regions of the image, and provides the point Id and IJK index of each data point. vtkImagePointIterator, which is a subclass of vtkImagePointDataIterator, also provides the (x,y,z) coordinate of each point.

The new filter, vtkImageToPoints, uses these iterators to convert an image to a point data set, using only the points that are within a stencil, while keeping the attributes for each point. In combination with a stencil-generation filter like vtkPolyDataToImageStencil, it can efficiently extract all image points that lie within the volume enclosed by a polydata surface.

Both of the iterators can be used from python (the "stencil" is optional):

iter = vtkImagePointIterator(image, image.GetExtent(), stencil)
scalars = image.GetPointData().GetScalars()
while not iter.IsAtEnd():
    point = iter.GetPosition()
    idx = iter.GetIndex()
    value = scalars.GetTuple(iter.GetId())
    iter.Next()

Merge request reports