[vtkusers] Writing point cloud to .vtk using MATLAB
Haluk Noyan Tokgozoglu
htokgoz1 at jhu.edu
Wed Sep 14 11:38:29 EDT 2011
Hi,
I have point cloud data in the form of 3 vectors, x y z which are n-by-1 and
contain the 3 coordinates of the points. I am trying to swiftly generate a
.vtk file in MATLAB so I can view it in Paraview, but I am having trouble
understanding the documentation at
http://www.vtk.org/VTK/img/file-formats.pdf
I have written some code, where I write the points as an unstructred grid,
but paraview doesn't show anything when I try to view the file.
Here's my code:
function [] = write_vtk(x,y,z)
n=size(x);
delete('data.vtk');
fid=fopen('data.vtk','w');
fprintf(fid,'# vtk DataFile Version 2.0\n');
fprintf(fid,'blah\n');
fprintf(fid,'ASCII\n');
fprintf(fid,'DATASET UNSTRUCTURED_GRID\n');
fprintf(fid,'POINTS %d float\n',n);
for i=1:n
fprintf(fid,'%f %f %f\n',x(i),y(i),z(i));
end
fprintf(fid,'POINT_DATA %d\n',n);
fclose(fid);
end
What am I doing wrong?
Haluk Noyan Tokgozoglu
Johns Hopkins University
Computer Science PhD Student
Computational Interaction and Robotics Library
Secretary of the GRO
Treasurer of UPE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110914/62b4289d/attachment.htm>
More information about the vtkusers
mailing list