fsl.data.vtk

This module provides the VTKMesh class, for loading triangle meshes from VTK files.

A handful of convenience functions are also in this module:

loadVTKPolydataFile

Loads a vtk legacy file containing a POLYDATA data set.

getFIRSTPrefix

If the given vtk file was generated by FIRST, this function will return the file prefix.

findReferenceImage

Given a vtk file, attempts to find a corresponding NIFTI image file.

Note

I/O support is very limited - currently, the only supported file type is the VTK legacy file format, containing the POLYDATA dataset. the TriangleMesh class assumes that every polygon defined in an input file is a triangle (i.e. refers to three vertices).

See http://www.vtk.org/wp-content/uploads/2015/04/file-formats.pdf for an overview of the VTK legacy file format.

In the future, I may or may not add support for more complex meshes.

fsl.data.vtk.ALLOWED_EXTENSIONS = ['.vtk']

A list of file extensions which could contain VTKMesh data.

fsl.data.vtk.EXTENSION_DESCRIPTIONS = ['VTK polygon model file']

A description for each of the extensions in ALLOWED_EXTENSIONS.

class fsl.data.vtk.VTKMesh(*args, **kwargs)[source]

Bases: Mesh

The VTKMesh class represents a triangle mesh loaded from a VTK file. Typically only one set of vertices will be associated with a VTKMesh.

__init__(infile, fixWinding=False)[source]

Create a VTKMesh.

Parameters:
  • infile – VTK file to load mesh from.

  • fixWinding – See the Mesh.addVertices() method.

__annotations__ = {}
__module__ = 'fsl.data.vtk'
fsl.data.vtk.loadVTKPolydataFile(infile)[source]

Loads a vtk legacy file containing a POLYDATA data set.

Parameters:

infile – Name of a file to load from.

Returns:

a tuple containing three values:

  • A \(N\times 3\) numpy array containing \(N\) vertices.

  • A 1D numpy array containing the lengths of each polygon.

  • A 1D numpy array containing the vertex indices for all polygons.

fsl.data.vtk.getFIRSTPrefix(modelfile)[source]

If the given vtk file was generated by FIRST, this function will return the file prefix. Otherwise a ValueError will be raised.

fsl.data.vtk.findReferenceImage(modelfile)[source]

Given a vtk file, attempts to find a corresponding NIFTI image file. Return the path to the image, or None if no image was found.

Currently this function will only return an image for vtk files generated by FIRST.