<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"></p>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
Hello again Mark,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
I have been working on implementing the binary "inline" option for my VTK XML files. <font size="3"><span style="font-size: 12pt;">I looked through the OpenFOAM code that you suggested and am having trouble interpreting it.</span></font></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
Would you be able to give me a hint as to where I should be looking in <i>foamVtkBase64Layer</i>? For example, in my current code I write the array data like this:</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
 </div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px;">  int i,j;</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px;">  ofstream lfile;</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px;"><br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px;">
<div>  lfile << "\t\t\t\t<DataArray type=\"Float32\" Name=\"rho\" format=\"ascii\">\n";</div>
<div>  lfile << "\t\t\t\t\t";</div>
<div>    for (j = firsty-1; j <= lasty+1; j++){</div>
<div>    for (i = firstx-1; i <= lastx+1; i++){</div>
<div>      lfile << rho[j][i][t] << " ";</div>
<div>    }</div>
<div>    }</div>
<div>  lfile << "\n";</div>
<div>  lfile << "\t\t\t\t</DataArray>\n";</div>
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px;"> I have not used the <i>write</i> function in C++ before. Is there a quick way to explain how the above code would be modified (with the contents of "rho" being written to the file)?
 I wonder if I will run into a problem because of how I have set up the array with the 't' index last.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
 </div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
Thank you so much for your help so far.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
Nicholas Stegmeier</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
Graduate Student</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
Mathematics and Statistics</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
South Dakota State University</div>
<br>
<p></p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Mark Olesen <Mark.Olesen@esi-group.com><br>
<b>Sent:</b> Friday, December 1, 2017 1:34:58 AM<br>
<b>To:</b> Stegmeier, Nicholas; paraview@paraview.org<br>
<b>Subject:</b> Re: [Paraview] Writing XML VTK Binary files from C++</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:10pt;">
<div class="PlainText">When you say "writing binary", you need to distinguish between three
<br>
possibilities.<br>
1) writing binary "inline" (actually base64 encoded)<br>
2) writing binary "append" (actually base64 encoded)<br>
3) writing raw binary "append" (really raw binary)<br>
<br>
Since you already have ASCII writing working and its content is <br>
"inline", it won't take much more to get binary inline working.<br>
By "inline", I mean when the output is placed between the <xxx> </xxx> <br>
markers. Eg,<br>
     <DataArray ...><br>
         content<br>
     </DataArray><br>
<br>
For the binary case, the content is written as base64-encoded data, <br>
which means that your output writer for these sections needs to pass the <br>
content through a base64 layer to do the encoding for you.<br>
<br>
If it helps as reference, we have the same thing in OpenFOAM, except <br>
that we only write vtu and vtp files (we don't have rectilinear meshes).<br>
<br>
In the repo <a href="https://develop.openfoam.com/Development/OpenFOAM-plus">https://develop.openfoam.com/Development/OpenFOAM-plus</a><br>
we have a foamVtkBase64Formatter and a foamVtkBase64Layer (both under <br>
src/fileFormats/vtk/format/) that add a base64Layer to encode and output <br>
as base64 (src/OpenFOAM/db/IOstreams/hashes/base64Layer.[CH]).<br>
<br>
You'll see that the foamVtkBase64Layer and base64Layer are quite low <br>
level means of adding an tiny encoding buffer (3 chars size) to <br>
intercept output prior to sending through to a std::ostream. It take <br>
very little effort to adopt for your output and thus quite easy to drop <br>
in instead of your current ASCII outputter.  For it too work easily, <br>
however, you should make sure that you need to generate your output <br>
content with a write() method instead of using '<<'. This allows <br>
somewhat easy switching between something like a foamVtkAsciiFormatter <br>
and the binary version, but more importantly it makes it easier to track <br>
the output state.<br>
<br>
When browsing through the code, you may also notice that we have support <br>
for writing in appended format (raw and base64). However, I would not <br>
advise you to tackle that immediately. There are a few more things to <br>
watch out for here, but more importantly it will change many more things <br>
on the calling side.<br>
<br>
I hope this information helps you.<br>
/mark<br>
<br>
-- <br>
Dr Mark OLESEN<br>
Principal Engineer, ESI-OpenCFD<br>
ESI GmbH | Einsteinring 24 | 85609 Munich | GERMANY<br>
<a href="http://www.openfoam.com">www.openfoam.com</a> | <a href="http://www.esi-group.com">
www.esi-group.com</a> | mark.olesen@esi-group.com<br>
<br>
<br>
On 11/30/17 18:00, Stegmeier, Nicholas wrote:<br>
> Hello,<br>
><br>
> I am new to Paraview and C++ coming from a mostly mathematics <br>
> background. I am emailing to get resources or help on writing binary XML <br>
> VTK files from C++.<br>
><br>
> I have finally succeeded in using the ASCII XML VTK format for a 2D <br>
> rectilinear CFD application. My ".pvtr" file is shown below.<br>
><br>
> How can I write this file and my other XML VTK files in binary from C++? <br>
> Do I need a special C++ library?<br>
</div>
</span></font></div>
</body>
</html>