forked from gacevedobolton/myVTKPythonLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
findPointsInCell.py
51 lines (41 loc) · 2.05 KB
/
findPointsInCell.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#coding=utf8
########################################################################
### ###
### Created by Martin Genet, 2012-2016 ###
### ###
### University of California at San Francisco (UCSF), USA ###
### Swiss Federal Institute of Technology (ETH), Zurich, Switzerland ###
### École Polytechnique, Palaiseau, France ###
### ###
########################################################################
import vtk
import myVTKPythonLibrary as myVTK
########################################################################
def findPointsInCell(points,
cell,
verbose=0):
ugrid_cell = vtk.vtkUnstructuredGrid()
ugrid_cell.SetPoints(cell.GetPoints())
cell = vtk.vtkHexahedron()
for k_point in xrange(8): cell.GetPointIds().SetId(k_point, k_point)
cell_array_cell = vtk.vtkCellArray()
cell_array_cell.InsertNextCell(cell)
ugrid_cell.SetCells(vtk.VTK_HEXAHEDRON, cell_array_cell)
geometry_filter = vtk.vtkGeometryFilter()
if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
geometry_filter.SetInputData(ugrid_cell)
else:
geometry_filter.SetInput(ugrid_cell)
geometry_filter.Update()
cell_boundary = geometry_filter.GetOutput()
pdata_points = vtk.vtkPolyData()
pdata_points.SetPoints(points)
enclosed_points_filter = vtk.vtkSelectEnclosedPoints()
enclosed_points_filter.SetSurfaceData(cell_boundary)
if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
enclosed_points_filter.SetInputData(pdata_points)
else:
enclosed_points_filter.SetInput(pdata_points)
enclosed_points_filter.Update()
points_in_cell = [k_point for k_point in xrange(points.GetNumberOfPoints()) if enclosed_points_filter.GetOutput().GetPointData().GetArray('SelectedPoints').GetTuple1(k_point)]
return points_in_cell