[vtkusers] Writing point cloud to .vtk using MATLAB

Florian Bruckner e0425375 at gmail.com
Thu Sep 15 00:45:24 EDT 2011


i used to following code to output some magnetization vectors defined
on the points of an unstructured grid. remember that X and Mag are
3byNN arrays.

file = fopen ("mag.vtk", "w");
fprintf(file, "# vtk DataFile Version 2.0\n");
fprintf(file, "Cube example\n");
fprintf(file, "ASCII\n");
fprintf(file, "DATASET UNSTRUCTURED_GRID\n");
fprintf(file, "POINTS %i float\n", NN);
fprintf(file, "%.15e %.15e %.15e\n", X);
fprintf(file, "POINT_DATA %i VECTORS magnetization float\n", NN);
fprintf(file, "%.15e %.15e %.15e\n", Mag);


hth
FloB


On Wed, Sep 14, 2011 at 6:59 PM, Haluk Noyan Tokgozoglu
<htokgoz1 at jhu.edu> wrote:
> Hi,
> What are those scalar values supposed to denote?
> Haluk Noyan Tokgozoglu
> Johns Hopkins University
> Computer Science PhD Student
> Computational Interaction and Robotics Library
> Secretary of the GRO
> Treasurer of UPE
>
>
> On Wed, Sep 14, 2011 at 12:21, rakesh patil <prakeshofficial at gmail.com>
> wrote:
>>
>> 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
>>>
>>
>
>
> _______________________________________________
> 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
>
>



More information about the vtkusers mailing list