File Exchange

image thumbnail

Export triangulation to Paraview

version 1.1.0.0 (1.8 KB) by David Gingras
Function to export an unrestricted 2D triangulation to a VTK file which can be open with Paraview.

1 Download

Updated 05 May 2009

View License

Trying to visualize a huge triangulation with trisurf or triplot is often very slow and frustrating. Solution : use Paraview, a very powerful and free 3D data viewer. But it could be complicated to generate the input file specially with binary format. The function proposed takes a 2.5D unrestricted triangulation and generates the ASCII VTK file for Paraview.

function exportTriangulation2VTK(file,XYZ,tri,dir)
Input :
"dir" is the path of the directory where the file is saved (string). (Optional)
"file" is the name without extension of the file (string).
"XYZ" is the coordinate of the vertex of the triangulation (nx3 matrix).
"tri" is the list of triangles which contain indexes of XYZ (mx3 matrix).

Simple example :
[X,Y,Z]=peaks(25);
X=reshape(X,[],1);
Y=reshape(Y,[],1);
Z=0.4*reshape(Z,[],1);
tri = delaunay(X,Y);
exportTriangulation2VTK('sampleExampleTri',[X Y Z],tri)

Note : If the triangulation doesn't have Z component (a plane), put the third column of XYZ with all zeros. Paraview only deals with 3D object.

Comments and Ratings (3)

Zhijun Zhang

nice work, it works!

David Gingras

Hi Luke, exportTriangulation2VTK.m just deals with 3D shell meshes (assembly of triangles not tetrahedra). If you do have a shell mesh and you are not able to export it to Paraview, you can send me your code and I'll see what I can do. Cheers. - David

Luke

Luke (view profile)

David, I have a 3D point cloud that I am running through delaunay(x,y) on and this generates a nx3 matrix, n being the # of triangulations. I am using this to create a smooth surface in MATLAB that can accurately model the point cloud if it were a volume, not just points. When I load the VTK file into Paraview, the triangulations are not working well and Paraview makes the file look more like a surf plot rather than a triangulation. Any suggestions as to what I am doing wrong?

Updates

1.1.0.0

updated the description

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux

MATLAB Online Live Editor Challenge

View the winning live scripts from faculty and students who participated in the recent challenge.

Learn more

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video