[Paraview] VTK XML Binary Output
David Mulholland
d.t.mulholland at googlemail.com
Wed Apr 1 21:32:27 EDT 2009
Well, I kept working and took a few guesses and I've got it all working now.
Thank you all for your help! Much appreciated and I now have some very fast binary output working compared to my previous ASCII output.
David
From: Hom Nath Gharti
Sent: Wednesday, April 01, 2009 1:59 PM
To: David Mulholland
Cc: Thorsten Hater ; paraview at paraview.org
Subject: Re: [Paraview] VTK XML Binary Output
I thought my C code may be helpful to you. I have 5 data array of different size, and I do like this:
nvar=5;
/* Bytes and offsets for ParaView file */
bytes[0] = (ndim*nnod)*sizeof(float); /* Coordinates */
bytes[1] = (nenod*nelmt)*sizeof(int); /* Connectivity */
bytes[2] = (nelmt)*sizeof(int); /* Offsets */
bytes[3] = (nelmt)*sizeof(int); /* Types */
bytes[4] = (nelmt)*sizeof(float); /* Cell data */
off[0]=0; /* 1st offset */
for (i=0; i<nvar; i++){
if(i<nvar-1)off[i+1]=off[i]+sizeof(int)+bytes[i];
bytes[i]=bytes[i]+sizeof(int); /* For each byte we must also add the sizeof(int) for itself also */
}
Best wishes,
Hom Nath
2009/4/1 David Mulholland <d.t.mulholland at googlemail.com>
Hi Thorsten,
I just tried that and it is now giving me a segmentation fault... I am using the following line:
file.write(reinterpret_cast<const char*>(size), 4);
My size is calculated as - int size = idim*jdim*sizeof(float). idim is currently in the region of 400 and jdim 200. I am outputting big files and it is likely to get bigger.
Also, I intend to include more data arrays each timestep, I just want to get it working with pressure first and then I will include then which is why I want to calculate the offset... I assuming it is just the number of bytes to the start of the next datafield...
Thanks David
From: Thorsten Hater
Sent: Wednesday, April 01, 2009 10:55 AM
To: David Mulholland
Cc: paraview at paraview.org
Subject: Re: [Paraview] VTK XML Binary Output
Hello David,
the offset parameter is relevant if you append mulitple data sections into a single file.
Every DataArray tag with append format specifies the offset as the position in the
binary data in bytes.
To write the integer I use the following:
std::ofstream os; // binary mode (for windows ...) ofstream to your file
int N; // size in bytes
os.write(reinterpret_cast<const char*>(N), 4);
Thorsten
David Mulholland schrieb:
Hi Thorsten,
That's really helpful. I don't quite know how to write out the number of bits as a char? If you could explain a way of how to do that it would be greatly appreciated.
Also, how do I calculate what value goes in for the offset? I had a look at a couple of output files from paraview and it wasnt obvious how it was calculated.
Thanks
David
From: Thorsten Hater
Sent: Tuesday, March 31, 2009 2:23 PM
To: David Mulholland
Cc: paraview at paraview.org
Subject: Re: [Paraview] VTK XML Binary Output
Hello,
the solution might be to append your data as
< DataArray ... format="appended">
</DataArray>
< AppendedData encoding="raw">
_NNNNData
</AppendedData>
where you should replace NNNN with a four
byte integer containing the number of bytes
in the data array as 4 chars.
Setting the encoding to "raw" tells ParaView, that
the data is simply a stream of bytes rather than
base64 encoded.
If you want to write Image I can supply a small
writer project for 2D data.
Thorsten
David Mulholland schrieb:
Hello,
I am currently trying to write my own quick output routine to generate a
binary file using C++. I am currently trying to avoid having to use the vtk
libraries because I only need a very basic output that doesn't change much.
I so far have the ASCII output working no problem but I can't get the binary
working.
I am using file.write() function to output the binary data and that seems to
be working no problem and when used in a legacy format application it works
perfectly except that the data is LittleEndian instead of BigEndian. That's
why I have moved to BigEndian because I don't want to have to make the
output routine for the data anymore complicated that file.write.
I started using the xml format and considering my output is raw binary and
not base64 I changed it to be in the AppendedData section instead of
DataArray. It still isn't working right, I get the following error when I
try to load in ParaView:
ERROR: In ..\..\..\ParaView3\VTK\IO\vtkXMLStructuredDataReader.cxx, line 349
vtkXMLImageDataReader (0ADEC7F8): Error reading extent 0 422 0 242 0 1 from
piece 0
ERROR: In ..\..\..\ParaView3\VTK\IO\vtkXMLDataReader.cxx, line 537
vtkXMLImageDataReader (0ADEC7F8): Cannot read cell data array "pressure"
from PointData in piece 0. The data array in the element may be too short.
The format of my output file is as follows:
<?xml version="1.0"?>
<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian">
<ImageData WholeExtent="0 422 0 242 0 1" Origin="0 0 0" Spacing="1 1 1">
<Piece Extent="0 422 0 242 0 1">
<PointData>
</PointData>
<CellData Scalars="pressure">
<DataArray type="Float32" Name="pressure" format="appended" offset="0"/>
</CellData>
</Piece>
</ImageData>
<AppendedData encoding="raw">
_BINARYDATA
</AppendedData>
</VTKFile>
Note following an error message I have added an _ at the start of the binary
data. Is this required?
One final thing, when using appended data, how do you calculate what the
offset should be?
Thanks
David
--------------------------------------------------------------------------
_______________________________________________
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
_______________________________________________
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20090402/70c503be/attachment-0001.htm>
More information about the ParaView
mailing list