Hello,<div><br></div><div>Paraview crashes when reading a binary VTK file. I am writing out that file using the Matlab function below. When written out in ASCII the file is read and interpreted correctly; when written out in binary paraview just crashes without giving any details as to where and why it crashed. I hope someone has an idea: after several hours of debugging I am at a loss.</div>
<div><br></div><div><div>% Export mesh to a VTK 1.0 file as an unstructured grid.</div><div>%</div><div>% function vtk_export_mesh (theFile,Connectivity,Points,Cell_types,options)</div><div>%</div><div>% theFile= File name as a string,</div>
<div>% Connectivity= connectivity array, one row per cell,</div><div>% Points= Coordinate array, one row per point,</div><div>% Cell_types= Cell type code: L2=3, T3=5, Q4=9, T4=10, H8=12</div><div>function vtk_export_mesh (theFile,Connectivity,Points,Cell_types,options)</div>
<div> binary= ~true;</div><div> scalars=[]; scalars_name= ['Data'];</div><div> if ( exist ( 'options', 'var') )</div><div> if (isfield(options, 'binary'))</div><div> binary= options.binary;</div>
<div> end</div><div> if (isfield(options, 'scalars'))</div><div> scalars= options.scalars;</div><div> end</div><div> if (isfield(options, 'scalars_name'))</div><div> scalars_name= options.scalars_name;</div>
<div> end</div><div> end</div><div> if (~iscell(Connectivity))</div><div> Connectivity={Connectivity};</div><div> end</div><div> if (~iscell(Cell_types))</div><div> Cell_types={Cell_types};</div>
<div> end</div><div> [pathstr, name, ext] = fileparts(theFile);</div><div> if (~strcmp(ext,'vtk'))</div><div> theFile = [theFile '.vtk'];</div><div> end</div><div> fid=fopen(theFile,'w');</div>
<div> if (fid==-1)</div><div> warning (['Could not open ' theFile])</div><div> return</div><div> end</div><div> fprintf(fid,'# vtk DataFile Version 3.0\n');</div><div> fprintf(fid,'Really cool data\n');</div>
<div> if (~binary)</div><div> fprintf(fid,'ASCII\n');</div><div> else</div><div> fprintf(fid,'BINARY\n');</div><div> end</div><div> fprintf(fid,'\n');</div><div> fprintf(fid,'DATASET UNSTRUCTURED_GRID\n');</div>
<div> fprintf(fid,'POINTS %d double\n',size(Points,1));%</div><div> if (~binary)</div><div> for i= 1:size(Points, 1)</div><div> fprintf(fid,'%g %g %g\n',Points(i,:));</div><div> end</div>
<div> else</div><div> fwrite(fid,cast(Points,'double'),'double');</div><div> end</div><div> fprintf(fid,'\n');</div><div> fprintf(fid,'\n');</div><div> </div><div> for k=1:length(Connectivity)</div>
<div> f=Connectivity{k};</div><div> ctype=zeros(size(f, 1),1)+Cell_types{k};</div><div> fprintf(fid,'CELLS %d %d\n',size(f,1),(size(f,1)*(size(f,2)+1)));%</div><div> if (~binary)</div><div>
for i= 1:size(f, 1)</div><div> fprintf(fid,'%d ',size(f,2));</div><div> for j= 1: size(f,2)</div><div> fprintf(fid,'%d ',f(i,j)-1);</div><div> end</div>
<div> fprintf(fid,'\n');</div><div> end</div><div> else</div><div> fwrite(fid,cast([zeros(size(f,1),1)+size(f,2),f-1],'int32'),'int32');</div><div> end</div>
<div> fprintf(fid,'\n');</div><div> fprintf(fid,'\n');</div><div> fprintf(fid,'CELL_TYPES %d\n',size(f,1));%</div><div> if (~binary)</div><div> for i= 1:size(f, 1)</div>
<div> fprintf(fid,'%d\n',ctype(i));</div><div> end</div><div> else</div><div> fwrite(fid,cast(ctype,'int32'),'int32');</div><div> end</div><div> fprintf(fid,'\n');</div>
<div> fprintf(fid,'\n');</div><div> end</div><div> </div><div> if (~isempty(scalars))</div><div> fprintf(fid,'point_data %d\n',length(scalars));%</div><div> fprintf(fid,'SCALARS %s float\n',scalars_name);%</div>
<div> fprintf(fid,'LOOKUP_TABLE default\n');%</div><div> if (~binary)</div><div> for j= 1:length(scalars)</div><div> fprintf(fid,'%s\n',scalars(j));</div><div> end</div>
<div> else</div><div> fwrite(fid,cast(scalars,'single'),'single');</div><div> end</div><div> end</div><div> fprintf(fid,'\n');</div><div> fid=fclose(fid);</div><div>
end</div><div><br></div>-- <br>Petr Krysl<div>University of California, San Diego</div><div>Skype: <a href="http://Petr.Krysl.UCSD.EDU" target="_blank">Petr.Krysl.UCSD.EDU</a></div><div><a href="http://hogwarts.ucsd.edu/~pkrysl/" target="_blank">http://hogwarts.ucsd.edu/~pkrysl/</a></div>
<br>
</div>