[Paraview] Paraview crashes when reading binary VTK file

David E DeMarle dave.demarle at kitware.com
Wed Aug 1 06:57:31 EDT 2012


If you can post the file, and/or a stack trace. Someone may be better
able to help.

David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909


On Thu, Jul 26, 2012 at 11:27 PM, Petr Krysl <pkrysl at ucsd.edu> wrote:
> Hello,
>
> 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.
>
> % Export mesh to a VTK 1.0 file as an unstructured grid.
> %
> % function vtk_export_mesh (theFile,Connectivity,Points,Cell_types,options)
> %
> % theFile= File name as a string,
> % Connectivity= connectivity array, one row per cell,
> % Points= Coordinate array, one row per point,
> % Cell_types= Cell type code: L2=3, T3=5, Q4=9, T4=10, H8=12
> function vtk_export_mesh (theFile,Connectivity,Points,Cell_types,options)
>     binary= ~true;
>     scalars=[]; scalars_name= ['Data'];
>     if ( exist ( 'options', 'var') )
>         if (isfield(options, 'binary'))
>             binary= options.binary;
>         end
>         if (isfield(options, 'scalars'))
>             scalars= options.scalars;
>         end
>         if (isfield(options, 'scalars_name'))
>             scalars_name= options.scalars_name;
>         end
>     end
>     if (~iscell(Connectivity))
>         Connectivity={Connectivity};
>     end
>     if (~iscell(Cell_types))
>         Cell_types={Cell_types};
>     end
>     [pathstr, name, ext] = fileparts(theFile);
>     if (~strcmp(ext,'vtk'))
>         theFile = [theFile '.vtk'];
>     end
>     fid=fopen(theFile,'w');
>     if (fid==-1)
>         warning (['Could not open ' theFile])
>         return
>     end
>     fprintf(fid,'# vtk DataFile Version 3.0\n');
>     fprintf(fid,'Really cool data\n');
>     if (~binary)
>         fprintf(fid,'ASCII\n');
>     else
>         fprintf(fid,'BINARY\n');
>     end
>     fprintf(fid,'\n');
>     fprintf(fid,'DATASET UNSTRUCTURED_GRID\n');
>     fprintf(fid,'POINTS %d double\n',size(Points,1));%
>     if (~binary)
>         for i= 1:size(Points, 1)
>             fprintf(fid,'%g %g %g\n',Points(i,:));
>         end
>     else
>         fwrite(fid,cast(Points,'double'),'double');
>     end
>     fprintf(fid,'\n');
>     fprintf(fid,'\n');
>
>     for k=1:length(Connectivity)
>         f=Connectivity{k};
>         ctype=zeros(size(f, 1),1)+Cell_types{k};
>         fprintf(fid,'CELLS %d %d\n',size(f,1),(size(f,1)*(size(f,2)+1)));%
>         if (~binary)
>             for i= 1:size(f, 1)
>                 fprintf(fid,'%d ',size(f,2));
>                 for j= 1: size(f,2)
>                     fprintf(fid,'%d ',f(i,j)-1);
>                 end
>                 fprintf(fid,'\n');
>             end
>         else
>
> fwrite(fid,cast([zeros(size(f,1),1)+size(f,2),f-1],'int32'),'int32');
>         end
>         fprintf(fid,'\n');
>         fprintf(fid,'\n');
>         fprintf(fid,'CELL_TYPES %d\n',size(f,1));%
>         if (~binary)
>             for i= 1:size(f, 1)
>                 fprintf(fid,'%d\n',ctype(i));
>             end
>         else
>             fwrite(fid,cast(ctype,'int32'),'int32');
>         end
>         fprintf(fid,'\n');
>         fprintf(fid,'\n');
>     end
>
>     if (~isempty(scalars))
>         fprintf(fid,'point_data %d\n',length(scalars));%
>         fprintf(fid,'SCALARS %s float\n',scalars_name);%
>         fprintf(fid,'LOOKUP_TABLE default\n');%
>         if (~binary)
>             for j= 1:length(scalars)
>                     fprintf(fid,'%s\n',scalars(j));
>                 end
>         else
>             fwrite(fid,cast(scalars,'single'),'single');
>         end
>     end
>     fprintf(fid,'\n');
>     fid=fclose(fid);
> end
>
> --
> Petr Krysl
> University of California, San Diego
> Skype: Petr.Krysl.UCSD.EDU
> http://hogwarts.ucsd.edu/~pkrysl/
>
>
> _______________________________________________
> 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 ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://www.paraview.org/mailman/listinfo/paraview
>


More information about the ParaView mailing list