<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
Hi Nico,<br>
<br>
I can confirm that I see the same behavior. I added the following
lines to the end of your script:<br>
<br>
'''<br>
rdr = vtk.vtkUnstructuredGridReader()<br>
rdr.SetFileName('test.vtk')<br>
rdr.Update()<br>
loc = rdr.GetOutput()<br>
pts = numpy_support.vtk_to_numpy( loc.GetPoints().GetData() )<br>
print pts<br>
print pts.dtype<br>
'''<br>
and regardless of whether I called writer.SetFileTypeToASCII(), the
dtype was always float64, but there was a loss in precision.<br>
<br>
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).<br>
<br>
Cheers,<br>
Nishad.<br>
<br>
<br>
On 17/12/2015 10:40, Nico Schlömer wrote:
<blockquote
cite="mid:CAK6Z60c6KN68yC4JTUxaPOZ=Z=hWbDsNhSAV4PJYQ2tzdDQoXg@mail.gmail.com"
type="cite">
<div dir="ltr">This smells very much like the vtk_array data being
interpreted as single precision even though
<div>```</div>
<div> Data type: double<br>
</div>
<div>```</div>
<div>Cheers,</div>
<div>Nico</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr">On Thu, Dec 17, 2015 at 2:23 AM Nico Schlömer
<<a moz-do-not-send="true"
href="mailto:nico.schloemer@gmail.com">nico.schloemer@gmail.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">
<div dir="ltr">Hi everyone,
<div><br>
</div>
<div>with</div>
<div>```</div>
<div>
<div>import numpy</div>
<div>import vtk</div>
<div>from vtk.util import numpy_support</div>
<div><br>
</div>
<div>mesh = vtk.vtkUnstructuredGrid()</div>
<div><br>
</div>
<div># add points to mesh</div>
<div>points = numpy.array([</div>
<div> [0.123456789, 3.14159265, 0.0]</div>
<div> ])</div>
<div>vtk_points = vtk.vtkPoints()</div>
<div>vtk_array = numpy_support.numpy_to_vtk(points)</div>
<div>vtk_points.SetData(vtk_array)</div>
<div>mesh.SetPoints(vtk_points)</div>
<div><br>
</div>
<div># write to VTK</div>
<div>writer = vtk.vtkUnstructuredGridWriter()</div>
<div>writer.SetFileTypeToASCII()</div>
<div>writer.SetFileName('test.vtk')</div>
<div>writer.SetInputData(mesh)</div>
<div>writer.Write()</div>
</div>
<div>```</div>
<div>I noticed that, although the `point` is given with some
precision, the output `test.vtk` file only contains 6
digits of accuracy,</div>
<div>```</div>
<div>0.123457 3.14159 0<br>
</div>
<div>```</div>
<div>The numpy data type hosts 8 digits.</div>
<div><br>
</div>
<div>Is this a bug or expected? How to mitigate?</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Nico</div>
</div>
</blockquote>
</div>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Powered by <a class="moz-txt-link-abbreviated" href="http://www.kitware.com">www.kitware.com</a>
Visit other Kitware open-source projects at <a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a>
Please keep messages on-topic and check the VTK FAQ at: <a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a>
Search the list archives at: <a class="moz-txt-link-freetext" href="http://markmail.org/search/?q=vtkusers">http://markmail.org/search/?q=vtkusers</a>
Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://public.kitware.com/mailman/listinfo/vtkusers">http://public.kitware.com/mailman/listinfo/vtkusers</a>
</pre>
</blockquote>
</body>
</html>