[vtkusers] Precision Loss During PolyData File Manipulation

Cory Quammen cory.quammen at kitware.com
Tue Nov 10 18:05:00 EST 2015


Thomas,

Saving as BINARY saves the bits that represent the binary floating point
number in RAM exactly to disk. When you load those bits back, you get
exactly the same number in RAM again.

Saving as ASCII requires that the binary float point number be converted to
a base-10 string representation, and loading the ASCII file requires
conversion from a base-10 string back to binary. This conversion isn't
always perfect (consider the number 0.1 [1]), hence the differences you see.

HTH,
Cory

[1]
http://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/

On Tue, Nov 10, 2015 at 12:40 PM, Fastl, Thomas <thomas.fastl at kcl.ac.uk>
wrote:

> Hello Sancho,
>
> storing data as BINARY rather then ASCII solved the precision problem,
> thanks! But honestly, I don't understand why this is an issue when storing
> as ASCII, this should be possible since this can be quite convenient
> especially during code development for checking outputs. I'm still
> struggling with the vtkPolyDataReader() and associated precisions,
> therefore I want to provide a test example here:
>
> def readPolyData(fileName):
>
>     reader = vtk.vtkPolyDataReader()
>     reader.SetFileName(fileName)
>     reader.Update()
>
>     return (reader.GetOutput())
>
> personalizedMesh = readPolyData('test.vtk')
>
> The first vertex in the file 'test.vtk' is specified to be at
> [32376.558590  16410.828120  19045.751950], however, running the provided
> test example leads to (32376.55859375  16410.828125  19045.751953125). I
> don't understand why random digits are added (would expect that only 0 are
> added) and therefore played around with DOUBLE, but couldn't get this to
> work. Can anybody help me on that? I read that more people had this
> problem, but couldn't find a solution, thanks!
>
> Best, Thomas
>
> ________________________________________
> From: vtkusers <vtkusers-bounces at vtk.org> on behalf of oyster <
> sancho at whu.edu.cn>
> Sent: Tuesday, November 10, 2015 12:09 AM
> To: vtkusers at vtk.org
> Subject: Re: [vtkusers] Precision Loss During PolyData File Manipulation
>
> Hi, Thomas
> The precision loss is caused by the polydatawriter, since you stored it as
> ASCII. Using BINARY would cure this usually.
>
> BTW, is you are not sure float will be as precise as it, set vtkPoints'
> datatype to DOUBLE. Some vtkAlgorithm also has similar settings.
>
> Regards,
> Sancho.
>
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/Precision-Loss-During-PolyData-File-Manipulation-tp5734888p5734889.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>



-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151110/5627fabb/attachment.html>


More information about the vtkusers mailing list