mVTK

VTK library for MATLAB

mVTK: a MATLAB VTK library

mVTK is a MATLAB library to export data in the VTK file format. Exported data can then be displayed in the open source ParaView visualisation software. The export function supports legacy and XML file formats, both ASCII and binary.

It relies on external libraries or functions:

  • Base64, by Peter J. Acklam,
  • miniz, by Rich Geldreich.

Note that these tools are already included in the mVTK library provided here, so you don't need to install them separately.

This library is also part of SPM.

Installation

Unpack the archive and add the output folder to the MATLAB path.

Optional compression requires a compiled MEX file that is provided for all 64 bit platforms.

Example

  >> % to export a patch structure into file mri.vtp using binary XML encoding:
  >> load mri
  >> Ds = smooth3(squeeze(D));
  >> M = isosurface(Ds,5)
  
  M =
  
      vertices: [16565x3 double]
         faces: [32314x3 double]
  
  >> M.vertices(:,3) = M.vertices(:,3) / 0.4;
  >> mvtk_write(M,'mri.vtp','xml-binary');

The file mri.vtp can then be opened in ParaView.

MRI VTK file
  >> % to export a vector field into file wind.vtk using ascii legacy encoding:
  >> load wind
  >> M = struct('vertices',[x(:) y(:) z(:)],'vector',[u(:) v(:) w(:)]);
  >> mvtk_write(M,'wind.vtk');
wind VTK file