forked from gacevedobolton/myVTKPythonLibrary
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththresholdDataSet.py
62 lines (53 loc) · 2.46 KB
/
thresholdDataSet.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
52
53
54
55
56
57
58
59
60
61
62
#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 thresholdUGrid(
ugrid_mesh,
field_support,
field_name,
threshold_value,
threshold_by_upper_or_lower,
verbose=1):
myVTK.myPrint(verbose, "*** thresholdUGrid ***")
threshold = vtk.vtkThreshold()
if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
threshold.SetInputData(ugrid_mesh)
else:
threshold.SetInput(ugrid_mesh)
if (field_support == "points"):
association = vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS
elif (field_support == "cells"):
association = vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS
threshold.SetInputArrayToProcess(0, 0, 0, association, field_name)
if (threshold_by_upper_or_lower == "upper"):
threshold.ThresholdByUpper(threshold_value)
elif (threshold_by_upper_or_lower == "lower"):
threshold.ThresholdByLower(threshold_value)
threshold.Update()
ugrid_thresholded_mesh = threshold.GetOutput()
return ugrid_thresholded_mesh
def thresholdPData(pdata_mesh,
field_support,
field_name,
threshold_value,
threshold_by_upper_or_lower,
verbose=1):
myVTK.myPrint(verbose, "*** thresholdPData ***")
ugrid_thresholded_mesh = thresholdUGrid(pdata_mesh,
field_support,
field_name,
threshold_value,
threshold_by_upper_or_lower,
False)
pdata_thresholded_mesh = filterUGridIntoPData(ugrid_thresholded_mesh, False)
return pdata_thresholded_mesh