VTK 检查多数据点对象的交集
VTK check polydata point objects for intersection
我有两个带有点数据的 VTK 多数据对象,我想检查它们的交点。本质上,我想把点做成多边形然后使用它。
有人告诉我这样做的方法是 convert the point data into a triangular mesh and then use a 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
错误提到细分点的事实,我尝试输入 contour1
和 contour2
对象,但它随后在 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
我不确定从这里到哪里去,关于 Delaunay
和 IntersectonPolyDataFilter
的 VTK 文档在这里对我来说不是最有用的。
如果交集是指点云的重叠,您可以试试:
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 多数据对象,我想检查它们的交点。本质上,我想把点做成多边形然后使用它。
有人告诉我这样做的方法是 convert the point data into a triangular mesh and then use a 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
错误提到细分点的事实,我尝试输入 contour1
和 contour2
对象,但它随后在 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
我不确定从这里到哪里去,关于 Delaunay
和 IntersectonPolyDataFilter
的 VTK 文档在这里对我来说不是最有用的。
如果交集是指点云的重叠,您可以试试:
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)