[vtkusers] Adding points to vtkPointLocator (with python)

Charles Monty Burns ch.monty.burns at googlemail.com
Tue Apr 7 17:55:44 EDT 2009


Hello,

I want to add a point to the locators input-dataset and this point should be
findable to the locator-methods. I construct a little example below with
python.

#!/usr/bin/env python
#-*- coding:utf-8 -*-

import vtk

def _compress_vtk_points(points):
    vtk_points = vtk.vtkPoints()
    map(vtk_points.InsertNextPoint, points)

    return vtk_points

def main():
    pts = [
        [1, 1, 0],
        [2.75, 2, 0],
        [1.5, 3, 0],
    ]

    pd_pts = _compress_vtk_points(pts)

    pd = vtk.vtkPolyData()
    pd.SetPoints(pd_pts)

    insert_box = [
        [0, 0, -5],
        [0, 0, 5],

        [10, 0, -5],
        [10, 0, 5],

        [0, 10, -5],
        [0, 10, 5],

        [10, 10, -5],
        [10, 10, 5],
    ]

    box_pts = _compress_vtk_points(insert_box)

    loc = vtk.vtkPointLocator()
    loc.SetDataSet(pd)
    loc.InitPointInsertion(pd_pts, box_pts.GetBounds())
    loc.BuildLocator()

if __name__ == '__main__':
    main()

I add the following to the end of the main function:

    new_pt = pd_pts.InsertNextPoint((8, 8, 1))

    loc.Update()

    found_index = loc.FindClosestPoint((8.5, 8.5, .5))

The locator should return 3 in found_index, but 1 is returned.

What I'm doing wrong???

Greetings
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090407/a996cded/attachment.htm>


More information about the vtkusers mailing list