[Paraview] Matlab, VTK XML & Paraview

Craig Warren Craig.Warren at ed.ac.uk
Thu Jan 25 09:18:23 EST 2007


Thanks for the replies folks. I believe I a) have enough data, b) am  
writing in 4-byte blocks c) have written the underscore and number of  
4-byte blocks of data before wiriting the actual data itself. I have  
created a simple test case. Attached is the .vti produced from the  
Matlab script .m file.

<?xml version="1.0"?>
<VTKFile type="ImageData" version="0.1" byte_order="BigEndian">
<ImageData WholeExtent="0 1 0 1 0 1" Origin="0 0 0" Spacing="1 1 1">
<Piece Extent="0 1 0 1 0 1">
<PointData Scalars="material">
<DataArray type="UInt32" Name="material" format="appended" offset="0" />
</PointData>
</Piece>
</ImageData>
<AppendedData encoding="raw">
_^@^@^^@^@^@^G^@^@^^@^@^@^E^@^@^@^F^@^@^@^C^@^@^@^D^@^@^@^A^@^@^@^B
</AppendedData>
</VTKFile>

% VTK file output from a simple matrix in binary format
% Craig Warren 23/01/2007

clear all;

[machine,maxsize,endian]=computer;
if endian=='L'
     endian='ieee-le';
     endiantext='LittleEndian';
else
     endian='ieee-be';
     endiantext='BigEndian';
end
if strcmp(machine,'MAC')
     cd('/Volumes/CWARREN/myhome/GprMax-work')
elseif strcmp(machine,'PCWIN')
     cd('N:\myhome\GprMax-work');
end
rehash path

test=ones(2,2,2);
test(:,:,1)=[1 2; 3 4];
test(:,:,2)=[5 6; 7 8];

test_info=whos('test');

fid=fopen(strcat('basic_test_',upper(endian 
(end-1:end)),'.vti'),'w',endian);     % Open VTK for writing with  
appropriate endianness

fprintf(fid,'%s\n','<?xml version="1.0"?>');
fprintf(fid,'%s%s%s\n','<VTKFile type="ImageData" version="0.1"  
byte_order="',endiantext,'">');
fprintf(fid,'%s%d%s%d%s%d%s\n','<ImageData WholeExtent="0 ',1,' 0 ', 
1,' 0 ',1,'" Origin="0 0 0" Spacing="1 1 1">');
fprintf(fid,'%s%d%s%d%s%d%s\n','<Piece Extent="0 ',1,' 0 ',1,' 0 ', 
1,'">');
fprintf(fid,'%s\n','<PointData Scalars="material">');
fprintf(fid,'%s\n','<DataArray type="UInt32" Name="material"  
format="appended" offset="0" />');
fprintf(fid,'%s\n%s\n%s\n%s\n%s','</PointData>','</Piece>','</ 
ImageData>','<AppendedData encoding="raw">','_');

sizeData=test_info.size(1)*test_info.size(2)*test_info.size(3);
fwrite(fid,sizeData,'uint32');

for pages=1:test_info.size(3)
     for cols=1:test_info.size(2)
         for rows=1:test_info.size(1)
             fwrite(fid,test(rows,cols,pages),'uint32');
         end
     end
end

fprintf(fid,'\n%s\n%s','</AppendedData>','</VTKFile>');

fclose(fid);



  
-------------- next part --------------
Skipped content of type multipart/mixed


More information about the ParaView mailing list