我有一个非结构化网格,混合了2d和3d单元,可以共享点。我需要按位置查找特定的单元格。有没有一种干净的方法可以强制vtkCellLocator在搜索时忽略特定的单元格(例如按类型)?在本例中,我希望顶部选择拾取十六进制单元格,而不是四边形单元格
import vtk
# Create points
points = vtk.vtkPoints()
points.SetNumberOfPoints(8)
points.SetPoint(0,[-.5,-.5,-.5])
points.SetPoint(1,[ .5,-.5,-.5])
points.SetPoint(2,[ .5, .5,-.5])
points.SetPoint(3,[-.5, .5,-.5])
points.SetPoint(4,[-.5,-.5, .5])
points.SetPoint(5,[ .5,-.5, .5])
points.SetPoint(6,[ .5, .5, .5])
points.SetPoint(7,[-.5, .5, .5])
# Create Unstructured Grid and add Cells
ugrid = vtk.vtkUnstructuredGrid()
if vtk.VTK_MAJOR_VERSION <= 9:
ugrid.Allocate(2)
else:
ugrid.AllocateExact(2,8)
ugrid.InsertNextCell(vtk.VTK_QUAD,4,[4,5,6,7])
ugrid.InsertNextCell(vtk.VTK_HEXAHEDRON,8,[0,1,2,3,4,5,6,7])
ugrid.SetPoints(points)
# Create a locator
locator = vtk.vtkCellLocator()
locator.SetDataSet(ugrid)
locator.BuildLocator()
# Pick a point at the top
quad_cell_id = locator.FindCell([0,0,.5])
quad_cell = ugrid.GetCell(quad_cell_id)
# Pick a point close to the top
hex_cell_id = locator.FindCell([0,0,.49])
hex_cell = ugrid.GetCell(hex_cell_id)
我能想到的唯一方法是将数据拆分为二维和三维非结构化网格,并为其他操作合并网格,但这似乎是浪费
目前没有回答
相关问题 更多 >
编程相关推荐