[vtkusers] vtkUnstructuredGridWriter only stores 6 digits?
Nishad Sohoni
ns451 at srcf.net
Thu Dec 17 12:11:54 EST 2015
Hi Nico,
I can confirm that I see the same behavior. I added the following lines
to the end of your script:
'''
rdr = vtk.vtkUnstructuredGridReader()
rdr.SetFileName('test.vtk')
rdr.Update()
loc = rdr.GetOutput()
pts = numpy_support.vtk_to_numpy( loc.GetPoints().GetData() )
print pts
print pts.dtype
'''
and regardless of whether I called writer.SetFileTypeToASCII(), the
dtype was always float64, but there was a loss in precision.
If you can get away with writing a binary file, might I suggest using
vtkXMLUnstructuredGridWriter? With the above code, python printed with
the correct precision and dtype (obviously changing to
vtkXMLUnstructuredGridReader).
Cheers,
Nishad.
On 17/12/2015 10:40, Nico Schlömer wrote:
> This smells very much like the vtk_array data being interpreted as
> single precision even though
> ```
> Data type: double
> ```
> Cheers,
> Nico
>
> On Thu, Dec 17, 2015 at 2:23 AM Nico Schlömer
> <nico.schloemer at gmail.com <mailto:nico.schloemer at gmail.com>> wrote:
>
> Hi everyone,
>
> with
> ```
> import numpy
> import vtk
> from vtk.util import numpy_support
>
> mesh = vtk.vtkUnstructuredGrid()
>
> # add points to mesh
> points = numpy.array([
> [0.123456789, 3.14159265, 0.0]
> ])
> vtk_points = vtk.vtkPoints()
> vtk_array = numpy_support.numpy_to_vtk(points)
> vtk_points.SetData(vtk_array)
> mesh.SetPoints(vtk_points)
>
> # write to VTK
> writer = vtk.vtkUnstructuredGridWriter()
> writer.SetFileTypeToASCII()
> writer.SetFileName('test.vtk')
> writer.SetInputData(mesh)
> writer.Write()
> ```
> I noticed that, although the `point` is given with some precision,
> the output `test.vtk` file only contains 6 digits of accuracy,
> ```
> 0.123457 3.14159 0
> ```
> The numpy data type hosts 8 digits.
>
> Is this a bug or expected? How to mitigate?
>
> Cheers,
> Nico
>
>
> _______________________________________________
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151217/1c4218ce/attachment.html>
More information about the vtkusers
mailing list