[vtkusers] Writing point cloud to .vtk using MATLAB

rakesh patil prakeshofficial at gmail.com
Wed Sep 14 12:21:10 EDT 2011


Hi,

As mentioned in the pdf file

http://www.vtk.org/VTK/img/file-formats.pdf

There must be some scalar values for the POINT_DATA. Check for the example
on page number 8 in that file. Your code only writes the x,y,z points in the
file. Scalar values should follow after POINT_DATA.

Hope that helps.

Regards
Rakesh Patil

On Wed, Sep 14, 2011 at 9:08 PM, Haluk Noyan Tokgozoglu <htokgoz1 at jhu.edu>wrote:

> 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
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110914/aa426607/attachment.htm>


More information about the vtkusers mailing list