简体   繁体   English

VTK 检查多数据点对象的交集

[英]VTK check polydata point objects for intersection

I have two VTK polydata objects with point data that I want to check for an intersection.我有两个带有点数据的 VTK polydata 对象,我想检查它们是否相交。 Essentially, I want to make the points into a polygonal shape and then use that.本质上,我想将点变成多边形然后使用它。

I've been told that the way to do this is to convert the point data into a triangular mesh and then use a vtkIntersectionPolyDataFilter to check.有人告诉我,这样做的方法是 将点数据转换为三角形网格,然后使用vtkIntersectionPolyDataFilter进行检查。 This is what I have currently:这是我目前所拥有的:

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

However, this spits out errors which I believe are related to a failure within the intersection_operation.Update() call.但是,这会吐出错误,我认为这些错误与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

The fact that the error mentions points for subdivision, I tried to feed in the contour1 and contour2 objects, but it then errors out on the SetInputData line:事实上,错误提到了细分点,我试图输入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

I'm not sure where to go from here, the VTK documentation on both the Delaunay and the IntersectonPolyDataFilter aren't the most useful to me here.我不确定从哪里开始,关于DelaunayIntersectonPolyDataFilter的 VTK 文档对我来说并不是最有用的。

If by intersection you mean overlap of point clouds you can try out:如果交叉点是指点云的重叠,您可以尝试:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM