<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta content="text/html; charset=utf-8">
</head>
<body>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12.0pt; line-height:1.3; color:#1F497D">
Base64 encoding is often not feasible or desirable. Usually you don't have the option to change a standard file format (metaimage, nrrd image file headers, ASCII STL files, CSV files, etc.).<br>
<div><br>
</div>
<div id="signature-x" class="signature_editor" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12.0pt; color:#1F497D">
Andras<br>
<br>
</div>
</div>
<hr style="border:none; height:1px; color:#E1E1E1; background-color:#E1E1E1">
<div style="border:none; padding:3.0pt 0cm 0cm 0cm"><span style="font-size:11.0pt; font-family:Calibri,Arial,Helvetica,sans-serif"><b>From:</b> Todd via vtk-developers <vtk-developers@vtk.org><br>
<b>Sent:</b> Thursday, March 1, 2018 5:05 PM<br>
<b>To:</b> David Gobbi; vtk-developers@vtk.org<br>
<b>Subject:</b> Re: [vtk-developers] Call for Comments: Ascii representation of floats and doubles in files<br>
</span></div>
<br type="attribution">
<div>
<div dir="auto">
<div dir="auto">Can this not be simply achieved by base64 encoding the value as bytes and saving as a string? Isn't a float always 10 bytes? </div>
<div dir="auto"><br>
</div>
<div dir="auto">It is more verbose, but there would be no loss of precision. It looks like VTK already has base64 utilities, so another library would not be needed.</div>
<div><br>
<div class="elided-text">On 2 Mar 2018 5:32 a.m., David Gobbi <david.gobbi@gmail.com> wrote:<br>
<blockquote style="margin:0 0 0 0.8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">I agree that floats should be printed so that conversion is lossless.
<div>Python's console output does this and I find it incredibly useful.</div>
<div><br>
<div>Not sure if we need to add a new third-party library for this, though,</div>
<div>especially one that duplicates so much of C++'s built-in machinery.</div>
<div>Isn't it just a matter of printing enough digits? That's basically what</div>
<div>I do in my own code (plus checks for isnan(x) and isinf(x), and a</div>
<div>check of the size of fabs(x) for whether to force scientific notation.)</div>
<div><br>
</div>
<div> - David</div>
<div><br>
</div>
<div>
<div>
<div><br>
<div>On Thu, Mar 1, 2018 at 8:48 AM, Bill Lorensen <span dir="ltr"><<a href="mailto:bill.lorensen@gmail.com">bill.lorensen@gmail.com</a>></span> wrote:<br>
<blockquote style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204 ,204 ,204); padding-left:1ex">
Will,<br>
<br>
It would go in Common/Core I think. The vtk class would be very small.<br>
<br>
Bill<br>
<br>
On Thu, Mar 1, 2018 at 7:36 AM, Will Schroeder<br>
<<a href="mailto:will.schroeder@kitware.com">will.schroeder@kitware.com</a>> wrote:<br>
> If it works why mess with success? Where would this class<br>
> (vtkNumberToString) be placed, in Common/Core (like vtkIndent) or in some IO<br>
> directory like VTK/IO/Core?<br>
><br>
> On Thu, Mar 1, 2018 at 10:06 AM, Bill Lorensen <<a href="mailto:bill.lorensen@gmail.com">bill.lorensen@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Folks,<br>
>><br>
>> I'm working on some examples to save/restore camera, polydata,<br>
>> property, etc. in XML files. The files can be saved as binary or<br>
>> ascii. If I save/restore the info in binary, I get the same values for<br>
>> the saved info. But, to no surprise, when I save the same data in<br>
>> ascii, I don't get the same values. This is because the file writing<br>
>> code does not write enough significant digits.<br>
>><br>
>> In ITK we solved this problem many years ago. ITK uses a reduced<br>
>> version of the Google double-conversion library,<br>
>> <a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgoogle%2Fdouble-conversion&data=02%7C01%7Classo%40queensu.ca%7Ce246e174a2d646ebb8ef08d57fc091ff%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636555387414799974&sdata=HtBoj1m03YEF6JixOrvANeIAnZuStEPxWCevD0%2FuAps%3D&reserved=0">
https://github.com/google/<wbr>double-conversion</a>.<br>
>><br>
>> We added a small class to ITK that uses the library. The class,<br>
>> itkNumberToString, has a simple API. To convert floating and fixed<br>
>> point numbers to ascii without numerical precision erros,<br>
>><br>
>> For example, to convert a float,<br>
>> #include "itkNumberToString.h:<br>
>> itk::NumberToString<float> convert;<br>
>> float a = 1.0f/3.0f;<br>
>> std::cout << convert(a) << std::endl;<br>
>><br>
>> I propose a similar approach in VTK.<br>
>><br>
>> Comments please,<br>
>><br>
>> Bill<br>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</body>
</html>