forked from 541435721/myVTKPythonLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomputeRegionsForBiV.py
125 lines (105 loc) · 3.64 KB
/
computeRegionsForBiV.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#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 numpy
import myVTKPythonLibrary as myVTK
########################################################################
def computeRegionsForBiV(
points,
pdata_endLV,
pdata_endRV,
pdata_epi,
verbose=0):
myVTK.myPrint(verbose, "*** computeRegionsForBiV ***")
myVTK.myPrint(verbose-1, "Initializing cell locators...")
(cell_locator_endLV,
closest_point_endLV,
generic_cell,
cellId_endLV,
subId,
dist_endLV) = myVTK.getCellLocator(
mesh=pdata_endLV,
verbose=verbose-1)
(cell_locator_endRV,
closest_point_endRV,
generic_cell,
cellId_endRV,
subId,
dist_endRV) = myVTK.getCellLocator(
mesh=pdata_endRV,
verbose=verbose-1)
(cell_locator_epi,
closest_point_epi,
generic_cell,
cellId_epi,
subId,
dist_epi) = myVTK.getCellLocator(
mesh=pdata_epi,
verbose=verbose-1)
n_points = points.GetNumberOfPoints()
iarray_region = myVTK.createIntArray("region_id", 1, n_points)
point = numpy.empty(3)
for k_point in range(n_points):
points.GetPoint(k_point, point)
cell_locator_endLV.FindClosestPoint(
point,
closest_point_endLV,
generic_cell,
cellId_endLV,
subId,
dist_endLV)
cell_locator_endRV.FindClosestPoint(
point,
closest_point_endRV,
generic_cell,
cellId_endRV,
subId,
dist_endRV)
cell_locator_epi.FindClosestPoint(
point,
closest_point_epi,
generic_cell,
cellId_epi,
subId,
dist_epi)
if (dist_endRV == max(dist_endLV, dist_endRV, dist_epi)):
iarray_region.SetTuple1(k_point, 0)
elif (dist_epi == max(dist_endLV, dist_endRV, dist_epi)):
iarray_region.SetTuple1(k_point, 1)
elif (dist_endLV == max(dist_endLV, dist_endRV, dist_epi)):
iarray_region.SetTuple1(k_point, 2)
return iarray_region
########################################################################
def addRegionsToBiV(
ugrid_mesh,
pdata_endLV,
pdata_endRV,
pdata_epi,
verbose=0):
myVTK.myPrint(verbose, "*** addRegionsToBiV ***")
points = ugrid_mesh.GetPoints()
iarray_region = computeRegionsForBiV(
points=points,
pdata_endLV=pdata_endLV,
pdata_endRV=pdata_endRV,
pdata_epi=pdata_epi,
verbose=verbose-1)
ugrid_mesh.GetPointData().AddArray(iarray_region)
cell_centers = myVTK.getCellCenters(
mesh=ugrid_mesh,
verbose=verbose-1)
iarray_region = computeRegionsForBiV(
points=cell_centers,
pdata_endLV=pdata_endLV,
pdata_endRV=pdata_endRV,
pdata_epi=pdata_epi,
verbose=verbose-1)
ugrid_mesh.GetCellData().AddArray(iarray_region)
########################################################################