[vtkusers] Tolerance of InsertNextPoint in python

David Gobbi david.gobbi at gmail.com
Mon Apr 30 13:14:03 EDT 2012


I can see that maybe in VTK 5.6 or earlier you might see results like
that, but not in VTK 5.8 or 5.10.  I just tested VTK 5.10 to be sure.
What version of VTK are you using?

 - David



On Mon, Apr 30, 2012 at 10:33 AM, Brett Tully <brett.tully at oxyntix.com> wrote:
> I am not sure if this is a bug, by design, or just an intricacy of Python
> wrappers, but I have found a difference between VTK points depending on if
> they are created by passing in x, y, z coordinates, or by passing a 3
> element array [x, y, z]. The first method gives a true double precision
> point as requested by SetDataTypeToDouble, where as the second method still
> results in a single precision point. I have fixed our code to ensure double
> precision, but I thought I would post it here for future reference.
>
> Brett
>
> import vtk
> vtk_points = vtk.vtkPoints()
> vtk_points.SetDataTypeToDouble()
> e = [0.0, 0.0065, 0.0]
>
> # pass in the point using its individual components
> e1_id = vtk_points.InsertNextPoint(e[0], e[1], e[2])
> p_e1 = vtk_points.GetPoint(e1_id)
>
> # pass in the point as an array
> e2_id = vtk_points.InsertNextPoint(e)
> p_e2 = vtk_points.GetPoint(e2_id)
>
> # check the difference between the two methods
> print p_e1, p_e2
> print (p_e1[0] - p_e2[0]), (p_e1[1] - p_e2[1]), (p_e1[2] - p_e2[2])
>
> # gives
> # (0.0, 0.0065, 0.0) (0.0, 0.006500000134110451, 0.0)
> # 0.0 -1.34110451043e-10 0.0
>
> On Tue, Apr 3, 2012 at 1:43 PM, David Gobbi <david.gobbi at gmail.com> wrote:
>>
>> Hi Brett,
>>
>> The default type of vtkPoints is "float".  If you need more precision,
>> then you can change the precision to "double":
>>
>> vtk_points = vtk.vtkPoints()
>> vtk_points.SetDataTypeToDouble()
>>
>> This is true in both C++ and Python.
>>
>>  - David
>>
>>
>> On Tue, Apr 3, 2012 at 6:22 AM, Brett Tully <brett.tully at oxyntix.com>
>> wrote:
>> > Dear all,
>> >
>> > I am finding that vtkPoints.InsertNextPoint when called from python does
>> > not
>> > return a point where I want it -- it seems to be out by ~1e-10 -- is
>> > there a
>> > way to set the tolerance of this function or improve its location to be
>> > more
>> > precise than 1e-10? Or is this due to python floats?
>> >
>> > Thanks,
>> > Brett.
>> >
>> > I.e. the following python:
>> >
>> > import vtk
>> > vtk_points = vtk.vtkPoints()
>> > e = [0.0, 0.0065, 0.0]
>> > e_id = vtk_points.InsertNextPoint(*e)
>> > p_e = vtk_points.GetPoint(e_id)
>> > print p_e, e
>> > print (e[0] - p_e[0]), (e[1] - p_e[1]), (e[2] - p_e[2])
>> >
>> > # gives
>> > # (0.0, 0.006500000134110451, 0.0) [0.0, 0.0065, 0.0]
>> > # 0.0 -1.34110451043e-10 0.0
>
>



More information about the vtkusers mailing list