gpt4 book ai didi

python - vtkCellLocator : FindClosestPoint usage in python

转载 作者:太空宇宙 更新时间:2023-11-04 08:34:10 25 4
gpt4 key购买 nike

“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)

关于python - vtkCellLocator : FindClosestPoint usage in python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50468069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com