<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=text/html;charset=iso-8859-1 http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.7000.0"></HEAD>
<BODY style="PADDING-LEFT: 10px; PADDING-RIGHT: 10px; PADDING-TOP: 15px"
id=MailContainerBody leftMargin=0 topMargin=0 CanvasTabStop="true"
name="Compose message area">
<DIV><FONT face=Calibri>Well, I kept working and took a few guesses and I've got
it all working now.</FONT></DIV>
<DIV><FONT face=Calibri></FONT> </DIV>
<DIV><FONT face=Calibri>Thank you all for your help! Much appreciated and I now
have some very fast binary output working compared to my previous ASCII
output.</FONT></DIV>
<DIV><FONT face=Calibri></FONT> </DIV>
<DIV><FONT face=Calibri>David</FONT></DIV>
<DIV style="FONT: 10pt Tahoma">
<DIV><BR></DIV>
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><B>From:</B> <A title=hng.email@gmail.com
href="mailto:hng.email@gmail.com">Hom Nath Gharti</A> </DIV>
<DIV><B>Sent:</B> Wednesday, April 01, 2009 1:59 PM</DIV>
<DIV><B>To:</B> <A title=d.t.mulholland@googlemail.com
href="mailto:d.t.mulholland@googlemail.com">David Mulholland</A> </DIV>
<DIV><B>Cc:</B> <A title=th@tp1.rub.de href="mailto:th@tp1.rub.de">Thorsten
Hater</A> ; <A title=paraview@paraview.org
href="mailto:paraview@paraview.org">paraview@paraview.org</A> </DIV>
<DIV><B>Subject:</B> Re: [Paraview] VTK XML Binary Output</DIV></DIV></DIV>
<DIV><BR></DIV>I thought my C code may be helpful to you. I have 5 data array of
different size, and I do like this:<BR><BR>nvar=5;<BR>/* Bytes and offsets for
ParaView file */ <BR> bytes[0] =
(ndim*nnod)*sizeof(float); /* Coordinates
*/<BR> bytes[1] = (nenod*nelmt)*sizeof(int);
/* Connectivity */<BR> bytes[2] =
(nelmt)*sizeof(int); /* Offsets
*/<BR> bytes[3] = (nelmt)*sizeof(int);
/* Types */<BR> bytes[4] =
(nelmt)*sizeof(float); /* Cell data
*/<BR> <BR> off[0]=0; /* 1st offset
*/<BR> for (i=0; i<nvar; i++){
<BR>
if(i<nvar-1)off[i+1]=off[i]+sizeof(int)+bytes[i];<BR>
bytes[i]=bytes[i]+sizeof(int); /* For each byte we must also
add the sizeof(int) for itself also */ <BR>
}<BR><BR>Best wishes,<BR>Hom Nath<BR><BR>
<DIV class=gmail_quote>2009/4/1 David Mulholland <SPAN dir=ltr><<A
href="mailto:d.t.mulholland@googlemail.com">d.t.mulholland@googlemail.com</A>></SPAN><BR>
<BLOCKQUOTE
style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0pt 0pt 0pt 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote>
<DIV style="PADDING-LEFT: 10px; PADDING-RIGHT: 10px; PADDING-TOP: 15px"
name="Compose message area" bgcolor="#ffffff" text="#000000">
<DIV><FONT face=Calibri>Hi Thorsten, </FONT></DIV>
<DIV><FONT face=Calibri></FONT> </DIV>
<DIV><FONT face=Calibri>I just tried that and it is now giving me a
segmentation fault... I am using the following line: </FONT></DIV>
<DIV><FONT size=2>file.write(</FONT><FONT color=#40ffff size=2><FONT
color=#40ffff size=2>reinterpret_cast</FONT></FONT><FONT
size=2><</FONT><FONT color=#40ffff size=2><FONT color=#40ffff
size=2>const</FONT></FONT><FONT size=2> </FONT><FONT color=#00bf00
size=2><FONT color=#00bf00 size=2>char</FONT></FONT><FONT size=2>*>(size),
4);</FONT></DIV>
<DIV
style="FONT: 10pt Tahoma; font-size-adjust: none; font-stretch: normal"><FONT
size=3 face=Calibri></FONT> </DIV>
<DIV style="FONT: 10pt Tahoma; font-size-adjust: none; font-stretch: normal">
<DIV><FONT size=3 face=Calibri>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.</FONT></DIV><FONT
size=3 face=Calibri></FONT></DIV>
<DIV
style="FONT: 10pt Tahoma; font-size-adjust: none; font-stretch: normal"><FONT
size=3 face=Calibri></FONT><FONT size=3 face=Calibri></FONT> </DIV>
<DIV
style="FONT: 10pt Tahoma; font-size-adjust: none; font-stretch: normal"><FONT
size=3 face=Calibri>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...</FONT></DIV>
<DIV
style="FONT: 10pt Tahoma; font-size-adjust: none; font-stretch: normal"><FONT
size=3 face=Calibri></FONT> </DIV>
<DIV
style="FONT: 10pt Tahoma; font-size-adjust: none; font-stretch: normal"><FONT
size=3 face=Calibri>Thanks David</FONT>
<DIV><BR></DIV>
<DIV
style="BACKGROUND: rgb(245,245,245); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">
<DIV><B>From:</B> <A title=th@tp1.rub.de href="mailto:th@tp1.rub.de"
target=_blank>Thorsten Hater</A> </DIV>
<DIV><B>Sent:</B> Wednesday, April 01, 2009 10:55 AM</DIV>
<DIV>
<DIV></DIV>
<DIV class=h5>
<DIV><B>To:</B> <A title=d.t.mulholland@googlemail.com
href="mailto:d.t.mulholland@googlemail.com" target=_blank>David Mulholland</A>
</DIV>
<DIV><B>Cc:</B> <A title=paraview@paraview.org
href="mailto:paraview@paraview.org" target=_blank>paraview@paraview.org</A>
</DIV>
<DIV><B>Subject:</B> Re: [Paraview] VTK XML Binary
Output</DIV></DIV></DIV></DIV></DIV>
<DIV>
<DIV></DIV>
<DIV class=h5>
<DIV><BR></DIV>Hello David,<BR><BR>the offset parameter is relevant if you
append mulitple data sections into a single file.<BR>Every DataArray tag with
append format specifies the offset as the position in the <BR>binary data in
bytes.<BR>To write the integer I use the following:<BR><BR>std::ofstream os;
// binary mode (for windows ...) ofstream to your file<BR>int N; // size in
bytes<BR>os.write(reinterpret_cast<const char*>(N),
4);<BR><BR>Thorsten<BR><BR>David Mulholland schrieb:
<BLOCKQUOTE type="cite">
<DIV>Hi Thorsten,<BR><BR>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. <BR><BR>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.<BR><BR>Thanks<BR>David</DIV>
<DIV
style="FONT: 10pt Tahoma; font-size-adjust: none; font-stretch: normal">
<DIV><BR></DIV>
<DIV
style="BACKGROUND: rgb(245,245,245) 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">
<DIV><B>From:</B> <A title=th@tp1.rub.de href="mailto:th@tp1.rub.de"
target=_blank>Thorsten Hater</A> </DIV>
<DIV><B>Sent:</B> Tuesday, March 31, 2009 2:23 PM</DIV>
<DIV><B>To:</B> <A title=d.t.mulholland@googlemail.com
href="mailto:d.t.mulholland@googlemail.com" target=_blank>David
Mulholland</A> </DIV>
<DIV><B>Cc:</B> <A title=paraview@paraview.org
href="mailto:paraview@paraview.org" target=_blank>paraview@paraview.org</A>
</DIV>
<DIV><B>Subject:</B> Re: [Paraview] VTK XML Binary Output</DIV></DIV></DIV>
<DIV><BR></DIV>Hello,<BR><BR>the solution might be to append your data
as<BR><BR>< DataArray ...
format="appended"><BR></DataArray><BR>< AppendedData
encoding="raw"><BR>_NNNNData <BR></AppendedData><BR>where you
should replace NNNN with a four <BR>byte integer containing the number of
bytes <BR>in the data array as 4 chars.<BR>Setting the encoding to "raw"
tells ParaView, that<BR>the data is simply a stream of bytes rather than
<BR>base64 encoded.<BR>If you want to write Image I can supply a
small<BR>writer project for 2D data.<BR><BR>
Thorsten<BR> <BR>David Mulholland schrieb:
<BLOCKQUOTE type="cite">
<DIV>Hello,<BR><BR>I am currently trying to write my own quick output
routine to generate a <BR>binary file using C++. I am currently trying to
avoid having to use the vtk <BR>libraries because I only need a very basic
output that doesn't change much. <BR>I so far have the ASCII output
working no problem but I can't get the binary <BR>working.<BR><BR>I am
using file.write() function to output the binary data and that seems to
<BR>be working no problem and when used in a legacy format application it
works <BR>perfectly except that the data is LittleEndian instead of
BigEndian. That's <BR>why I have moved to BigEndian because I don't want
to have to make the <BR>output routine for the data anymore complicated
that file.write.<BR><BR>I started using the xml format and considering my
output is raw binary and <BR>not base64 I changed it to be in the
AppendedData section instead of <BR>DataArray. It still isn't working
right, I get the following error when I <BR>try to load in
ParaView:<BR><BR>ERROR: In
..\..\..\ParaView3\VTK\IO\vtkXMLStructuredDataReader.cxx, line
349<BR>vtkXMLImageDataReader (0ADEC7F8): Error reading extent 0 422 0 242
0 1 from <BR>piece 0<BR><BR><BR>ERROR: In
..\..\..\ParaView3\VTK\IO\vtkXMLDataReader.cxx, line
537<BR>vtkXMLImageDataReader (0ADEC7F8): Cannot read cell data array
"pressure" <BR>from PointData in piece 0. The data array in the
element may be too short.<BR><BR>The format of my output file is as
follows:<BR><BR><?xml version="1.0"?><BR><VTKFile
type="ImageData" version="0.1"
byte_order="LittleEndian"><BR><ImageData WholeExtent="0 422 0 242 0
1" Origin="0 0 0" Spacing="1 1 1"><BR><Piece Extent="0 422 0 242 0
1"><BR><PointData><BR></PointData><BR><CellData
Scalars="pressure"><BR><DataArray type="Float32" Name="pressure"
format="appended"
offset="0"/><BR></CellData><BR></Piece><BR></ImageData><BR><AppendedData
encoding="raw"><BR>_BINARYDATA<BR></AppendedData><BR></VTKFile><BR><BR>Note
following an error message I have added an _ at the start of the binary
<BR>data. Is this required?<BR><BR>One final thing, when using appended
data, how do you calculate what the <BR>offset should
be?<BR><BR>Thanks<BR>David</DIV><PRE><HR SIZE=4 width="90%">
_______________________________________________
Powered by <A href="http://www.kitware.com" target=_blank>www.kitware.com</A>
Visit other Kitware open-source projects at <A href="http://www.kitware.com/opensource/opensource.html" target=_blank>http://www.kitware.com/opensource/opensource.html</A>
Please keep messages on-topic and check the ParaView Wiki at: <A href="http://paraview.org/Wiki/ParaView" target=_blank>http://paraview.org/Wiki/ParaView</A>
Follow this link to subscribe/unsubscribe:
<A href="http://www.paraview.org/mailman/listinfo/paraview" target=_blank>http://www.paraview.org/mailman/listinfo/paraview</A>
</PRE></BLOCKQUOTE><BR></BLOCKQUOTE><BR></DIV></DIV></DIV><BR>_______________________________________________<BR>Powered
by <A href="http://www.kitware.com"
target=_blank>www.kitware.com</A><BR><BR>Visit other Kitware open-source
projects at <A href="http://www.kitware.com/opensource/opensource.html"
target=_blank>http://www.kitware.com/opensource/opensource.html</A><BR><BR>Please
keep messages on-topic and check the ParaView Wiki at: <A
href="http://paraview.org/Wiki/ParaView"
target=_blank>http://paraview.org/Wiki/ParaView</A><BR><BR>Follow this link to
subscribe/unsubscribe:<BR><A
href="http://www.paraview.org/mailman/listinfo/paraview"
target=_blank>http://www.paraview.org/mailman/listinfo/paraview</A><BR><BR></BLOCKQUOTE></DIV><BR></BODY></HTML>