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

Andras Lasso lasso at queensu.ca
Thu Mar 1 10:42:10 EST 2018


This would be very useful. Lack of precision in decimal strings written by VTK has caused problems several times. We ended up implementing various workarounds, such as using custom XML writer instead of VTK's and set the number of decimals to a large number. Your proposed solution would be much better: it would produce nicer file content, while ensuring that no information is lost.

Andras

-----Original Message-----
From: vtk-developers [mailto:vtk-developers-bounces at vtk.org] On Behalf Of Bill Lorensen
Sent: Thursday, March 1, 2018 10:07 AM
To: VTK Developers <vtk-developers at vtk.org>
Subject: [vtk-developers] Call for Comments: Ascii representation of floats and doubles in files

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://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgoogle%2Fdouble-conversion&data=02%7C01%7Classo%40queensu.ca%7C0d926d4a58ef424b435208d57f86156d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636555136211177940&sdata=UnprTyNNEDtcE6ojCBrtz0gC8cHbBF%2FkRJP%2BUh9TDdQ%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 https://na01.safelinks.protection.outlook.com/?url=www.kitware.com&data=02%7C01%7Classo%40queensu.ca%7C0d926d4a58ef424b435208d57f86156d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636555136211177940&sdata=Qlv1B4seLIxmirkXiApA4KMB1KsVj9oDfkxBZcx5%2FZE%3D&reserved=0

Visit other Kitware open-source projects at https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.html&data=02%7C01%7Classo%40queensu.ca%7C0d926d4a58ef424b435208d57f86156d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636555136211177940&sdata=rrA48KPBb5EU8V5IdFuzDdCbIkZ0ff3AbHhuySyLFSs%3D&reserved=0

Search the list archives at: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmarkmail.org%2Fsearch%2F%3Fq%3Dvtk-developers&data=02%7C01%7Classo%40queensu.ca%7C0d926d4a58ef424b435208d57f86156d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636555136211177940&sdata=FqIUKRjcwQo8cgmaTCL28ZEvD%2F30ottePni8lBKS7lc%3D&reserved=0

Follow this link to subscribe/unsubscribe:
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fvtk.org%2Fmailman%2Flistinfo%2Fvtk-developers&data=02%7C01%7Classo%40queensu.ca%7C0d926d4a58ef424b435208d57f86156d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636555136211177940&sdata=%2BJwRkYOZwcN%2FpXut5PaMYGbIMu94i%2FQgjhco%2FJNCEg4%3D&reserved=0



More information about the vtk-developers mailing list