Loss of precision in vtkPoints InsertNextPoint, SetPoint using Python
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
First bug report I've submitted, so please let me know if I need to include more information.
I'm using vtk (5.5.0 - under python 2.6 + Windows 7, but also the same problem under Vista Business x64).
I was losing precision when I added double precision points to a vtkPoints object as a tuple instead of unpacked coordinates:
points = vtk.vtkPoints() points.InsertNextPoint((0.12345678901,98765432.10987,0.0)) points.GetPoint(0) (0.12345679104328156, 98765432.0,0.0)
The same problem occurs with SetPoint and using a tuple instead of unpacked values.
When I looked at the file vtkPointsPython.cxx in my build directory (auto generated file), I noticed that the way tuples are unpacked is that it checks for a tuple of (f,f,f) first, then (d,d,d), and then for 3 doubles. It looks to me that the double is getting cast as a float and that's where the precision loss is happening. I switched the order that the tuple is checked - (d,d,d) and then (f,f,f) and it turns out that the double precision is retained.
I'm not certain if the ordering of float->double in the tuple check is intentional or there for another reason. For my purposes it's a problem, if it's appropriate to change the code in vtkWrapPython.c to reorder the way tuples are checked for unpacking, then that would be great.