vtkCellLocator:python 中的 FindClosestPoint 用法

vtkCellLocator: FindClosestPoint usage in python

"FindClosestPoint"函数的定义如下:

   def FindClosestPoint(self, p_float=None, p_float=None_1, p_float=None_2, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 
    """
    V.FindClosestPoint([float, float, float], [float, float, float],
        vtkGenericCell, int, int, float)
    C++: void FindClosestPoint(double x[3], double closestPoint[3],
        vtkGenericCell *cell, vtkIdType &cellId, int &subId,
        double &dist2) override;
    V.FindClosestPoint([float, float, float], [float, float, float],
        int, int, float)
    C++: virtual void FindClosestPoint(double x[3],
        double closestPoint[3], vtkIdType &cellId, int &subId,
        double &dist2)

    Return the closest point and the cell which is closest to the
    point x. The closest point is somewhere on a cell, it need not be
    one of the vertices of the cell.  This version takes in a
    vtkGenericCell to avoid allocating and deallocating the cell. 
    This is much faster than the version which does not take a *cell,
    especially when this function is called many times in a row such
    as by a for loop, where the allocation and deallocation can be
    done only once outside the for loop.  If a cell is found, "cell"
    contains the points and ptIds for the cell "cellId" upon exit.
    """
    pass

在我的代码中,我使用这样的函数:

my_cell_locator = vtk.vtkCellLocator()
my_cell_locator.SetDataSet(reverse.GetOutput()) # reverse.GetOutput() --> vtkPolyData
cellId = 0
c = [0.0, 0.0, 0.0]
subId = 0
d = 0.0
my_cell_locator.FindClosestPoint([-23.7, -48.4, -1096.4], c, cellId, subId, d)

这会导致以下错误:

进程已完成,退出代码为 -1073741819 (0xC0000005)

我不知道如何正确使用这个功能。怎么了? 正确的用法是什么?

我不得不将代码更改为以下内容:

reverse.Update()
my_cell_locator = vtk.vtkCellLocator()
my_cell_locator.SetDataSet(reverse.GetOutput())  # reverse.GetOutput() --> vtkPolyData
my_cell_locator.BuildLocator()

cellId = vtk.reference(0)
c = [0.0, 0.0, 0.0]
subId = vtk.reference(0)
d = vtk.reference(0.0)
my_cell_locator.FindClosestPoint([-23.7, -48.4, -906.4], c, cellId, subId, d)

我添加了以下行:

reverse.Update()

my_cell_locator.BuildLocator()

然后我更改了以下几行:

cellId = 0
subId = 0
d = 0.0

到...

cellId = vtk.reference(0)
subId = vtk.reference(0)
d = vtk.reference(0.0)

对于 vtk 版本 8 必须将 vtk.reference 更改为 vtk.mutable