[vtk-developers] Call for Comments: Ascii representation of floats and doubles in files

Bill Lorensen bill.lorensen at gmail.com
Thu Mar 1 17:55:30 EST 2018


Sometimes it us good to see the ascii values.

On Mar 1, 2018 2:31 PM, "Todd via vtk-developers" <vtk-developers at vtk.org>
wrote:

Hi Andras

I wasn't suggesting base64 encoding the whole file. Just the double/float
values.

On 2 Mar 2018 11:19 a.m., Andras Lasso <lasso at queensu.ca> wrote:

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.).

Andras

------------------------------
*From:* Todd via vtk-developers <vtk-developers at vtk.org>
*Sent:* Thursday, March 1, 2018 5:05 PM
*To:* David Gobbi; vtk-developers at vtk.org
*Subject:* Re: [vtk-developers] Call for Comments: Ascii representation of
floats and doubles in files

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?

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.

On 2 Mar 2018 5:32 a.m., David Gobbi <david.gobbi at gmail.com> wrote:

I agree that floats should be printed so that conversion is lossless.
Python's console output does this and I find it incredibly useful.

Not sure if we need to add a new third-party library for this, though,
especially one that duplicates so much of C++'s built-in machinery.
Isn't it just a matter of printing enough digits?  That's basically what
I do in my own code (plus checks for isnan(x) and isinf(x), and a
check of the size of fabs(x) for whether to force scientific notation.)

 - David


On Thu, Mar 1, 2018 at 8:48 AM, Bill Lorensen <bill.lorensen at gmail.com>
wrote:

Will,

It would go in Common/Core I think. The vtk class would be very small.

Bill

On Thu, Mar 1, 2018 at 7:36 AM, Will Schroeder
<will.schroeder at kitware.com> wrote:
> If it works why mess with success? Where would this class
> (vtkNumberToString) be placed, in Common/Core (like vtkIndent) or in some
IO
> directory like VTK/IO/Core?
>
> On Thu, Mar 1, 2018 at 10:06 AM, Bill Lorensen <bill.lorensen at gmail.com>
> wrote:
>>
>> Folks,
>>
>> I'm working on some examples to save/restore camera, polydata,
>> property, etc. in XML files. The files can be saved as binary or
>> ascii. If I save/restore the info in binary, I get the same values for
>> the saved info. But, to no surprise, when I save the same data in
>> ascii, I don't get the same values. This is because the file writing
>> code does not write enough significant digits.
>>
>> In ITK we solved this problem many years ago. ITK uses a reduced
>> version of the Google double-conversion library,
>> https://github.com/google/double-conversion
<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>
.
>>
>> We added a small class to ITK that uses the library. The class,
>> itkNumberToString, has a simple API. To convert floating and fixed
>> point numbers to ascii without numerical precision erros,
>>
>> For example, to convert a float,
>> #include "itkNumberToString.h:
>> itk::NumberToString<float> convert;
>> float a = 1.0f/3.0f;
>> std::cout << convert(a) << std::endl;
>>
>> I propose a similar approach in VTK.
>>
>> Comments please,
>>
>> Bill




_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/
opensource/opensource.html

Search the list archives at: http://markmail.org/search/?q=vtk-developers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtk-developers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtk-developers/attachments/20180301/00db969d/attachment.html>


More information about the vtk-developers mailing list