forked from gacevedobolton/myVTKPythonLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clipSurfacesForFullBiVMesh.py
137 lines (116 loc) · 4.63 KB
/
clipSurfacesForFullBiVMesh.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
125
126
127
128
129
130
131
132
133
134
135
136
#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 argparse
import vtk
import myVTKPythonLibrary as myVTK
from mat_vec_tools import *
########################################################################
def clipSurfacesForFullBiVMesh(
pdata_endLV,
pdata_endRV,
pdata_epi,
verbose=0):
myVTK.myPrint(verbose, "*** clipSurfacesForFullBiVMesh ***")
pdata_endLV_implicit_distance = vtk.vtkImplicitPolyDataDistance()
pdata_endLV_implicit_distance.SetInput(pdata_endLV)
pdata_endRV_implicit_distance = vtk.vtkImplicitPolyDataDistance()
pdata_endRV_implicit_distance.SetInput(pdata_endRV)
pdata_epi_implicit_distance = vtk.vtkImplicitPolyDataDistance()
pdata_epi_implicit_distance.SetInput(pdata_epi)
pdata_endLV_clip = vtk.vtkClipPolyData()
if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
pdata_endLV_clip.SetInputData(pdata_endLV)
else:
pdata_endLV_clip.SetInput(pdata_endLV)
pdata_endLV_clip.SetClipFunction(pdata_epi_implicit_distance)
pdata_endLV_clip.InsideOutOn()
pdata_endLV_clip.Update()
clipped_pdata_endLV = pdata_endLV_clip.GetOutput(0)
pdata_endRV_clip = vtk.vtkClipPolyData()
if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
pdata_endRV_clip.SetInputData(pdata_endRV)
else:
pdata_endRV_clip.SetInput(pdata_endRV)
pdata_endRV_clip.SetClipFunction(pdata_epi_implicit_distance)
pdata_endRV_clip.InsideOutOn()
pdata_endRV_clip.Update()
clipped_pdata_endRV = pdata_endRV_clip.GetOutput(0)
pdata_epi_clip = vtk.vtkClipPolyData()
if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
pdata_epi_clip.SetInputData(pdata_epi)
else:
pdata_epi_clip.SetInput(pdata_epi)
pdata_epi_clip.SetClipFunction(pdata_endLV_implicit_distance)
pdata_epi_clip.GenerateClippedOutputOn()
pdata_epi_clip.Update()
clipped_pdata_epi = pdata_epi_clip.GetOutput(0)
clipped_valM = pdata_epi_clip.GetOutput(1)
pdata_epi_clip = vtk.vtkClipPolyData()
if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
pdata_epi_clip.SetInputData(clipped_pdata_epi)
else:
pdata_epi_clip.SetInput(clipped_pdata_epi)
pdata_epi_clip.SetClipFunction(pdata_endRV_implicit_distance)
pdata_epi_clip.GenerateClippedOutputOn()
pdata_epi_clip.Update()
clipped_pdata_epi = pdata_epi_clip.GetOutput(0)
clipped_valP = pdata_epi_clip.GetOutput(1)
return (clipped_pdata_endLV,
clipped_pdata_endRV,
clipped_pdata_epi,
clipped_valM,
clipped_valP)
########################################################################
if (__name__ == "__main__"):
parser = argparse.ArgumentParser()
parser.add_argument('endLV_filename', type=str)
parser.add_argument('endRV_filename', type=str)
parser.add_argument('epi_filename', type=str)
parser.add_argument('-v', '--verbose', type=int, default=1)
args = parser.parse_args()
pdata_endLV = myVTK.readSTL(
filename=args.endLV_filename,
verbose=args.verbose)
pdata_endRV = myVTK.readSTL(
filename=endRV_filename,
verbose=args.verbose)
pdata_epi = myVTK.readSTL(
filename=args.epi_filename,
verbose=args.verbose)
(clipped_pdata_endLV,
clipped_pdata_endRV,
clipped_pdata_epi,
clipped_valM,
clipped_valP) = myVTK.clipSurfacesForFullBiVMesh(
pdata_endLV=pdata_endLV,
pdata_endRV=pdata_endRV,
pdata_epi=pdata_epi,
verbose=args.verbose)
myVTK.writeSTL(
pdata=clipped_pdata_endLV,
filename="endLV.stl",
verbose=args.verbose)
myVTK.writeSTL(
pdata=clipped_pdata_endRV,
filename="endRV.stl",
verbose=args.verbose)
myVTK.writeSTL(
pdata=clipped_pdata_epi,
filename="epi.stl",
verbose=args.verbose)
myVTK.writeSTL(
pdata=clipped_pdata_valM,
filename="valM.stl",
verbose=args.verbose)
myVTK.writeSTL(
pdata=clipped_pdata_valP,
filename="valP.stl",
verbose=args.verbose)