【问题标题】:VTK check polydata point objects for intersectionVTK 检查多数据点对象的交叉点
【发布时间】:2019-07-26 00:44:48
【问题描述】:

我有两个 VTK 多数据对象,其中包含要检查交叉点的点数据。本质上,我想将这些点做成多边形,然后使用它。

我被告知这样做的方法是convert the point data into a triangular mesh,然后使用vtkIntersectionPolyDataFilter 进行检查。这是我目前拥有的:

def convert_pts_to_mesh(polydata):
    aCellArray = vtk.vtkCellArray()

    boundary = vtk.vtkPolyData()
    boundary.SetPoints(polydata.GetPoints())
    boundary.SetPolys(aCellArray)
    delaunay = vtk.vtkDelaunay2D()
    delaunay.SetInputData(polydata)
    delaunay.SetSourceData(boundary)
    delaunay.Update()

    result_polydata = delaunay.GetOutput()

    # print("result_polydata:")
    # print(result_polydata)
    return result_polydata

...

contour1 = ... # Source of polydata point object
contour2 = ... # Source of polydata point object

# Convert them to triangle meshes.
result_polydata1 = convert_pts_to_mesh(contour1)
result_polydata2 = convert_pts_to_mesh(contour2)

intersection_operation = vtk.vtkIntersectionPolyDataFilter()
intersection_operation.SetInputData(0, result_polydata1)
intersection_operation.SetInputData(1, result_polydata2)
intersection_operation.Update()

print("# of crosses: " + str(intersection_operation.GetNumberOfIntersectionPoints()))

但是,这会吐出我认为与 intersection_operation.Update() 调用中的失败有关的错误。

#121.040# [VtkError] ERROR: ERROR: In /usr/local/sv/ext/2019.02/release/gl2/src/vtk-8.1.1/Common/DataModel/vtkPointLocator.cxx, line 867
vtkPointLocator (0x555d26925800): No points to subdivide
!121.041! [VtkGenericWarning] WARNING: Generic Warning: In /usr/local/sv/ext/2019.02/release/gl2/src/vtk-8.1.1/Filters/General/vtkIntersectionPolyDataFilter.cxx, line 2518
No Intersection between objects
# of crosses: 0

事实上,错误提到了细分点,我尝试输入 contour1contour2 对象,但随后在 SetInputData 行上出错:

!126.179! [VtkGenericWarning] WARNING: Generic Warning: In /usr/local/sv/ext/2019.02/release/gl2/src/vtk-8.1.1/Common/Core/vtkMath.cxx, line 779
vtkMath::Jacobi: Error extracting eigenfunctions

我不知道从哪里开始,DelaunayIntersectonPolyDataFilter 上的 VTK 文档对我来说并不是最有用的。

【问题讨论】:

    标签: python vtk


    【解决方案1】:

    如果你所说的交点是指点云的重叠,你可以试试:

    import numpy as np
    from vedo import Points, ConvexHull, show
    
    pts = np.random.rand(1000, 3)
    
    # Points() creates a vtkActor (with extended functionalities) from
    # the original cloud of points pts:
    pts1 = Points(pts, r=5).c('red') # r=radius of points
    
    # create a second cloud displaced by a constant
    pts2 = Points(pts+[0.6,0.8,0], r=2).c('green')
    
    # create the convex hull which wraps the pts2 cloud.
    # ch2 is also a vtkActor. Note that you can concatenate commands
    # like .alpha() and .c() to change transparency and color..
    ch2 = ConvexHull(pts2).alpha(0.2).c('green')
    
    # extract the points of the original cloud (pts) which are inside
    # the convex hull of the second (ch2) as a list of points:
    print("# of crosses:", len(ch2.insidePoints(pts).points()))
    
    # show() will render all the indicated objects:
    show(pts1, pts2, ch2, axes=1)
    

    【讨论】:

    • 我对 VTK 很陌生...您能否评论您的代码以解释您在做什么?
    • 我在上面的代码中添加了一些 cmets,如果有不清楚的地方请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-08
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多