forked from kayarre/vmtktools
/
vmtksurfaceclipper.py
91 lines (68 loc) · 2.38 KB
/
vmtksurfaceclipper.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
#!/usr/bin/env python
import vtk
import sys
import vmtkrenderer
from argparse import ArgumentParser
def read_command_line():
"""Read arguments from commandline"""
parser = ArgumentParser()
parser.add_argument('--d', '--dir_path', type=str, default=".",
help="Path to the folder with all the cases")
parser.add_argument('--m', type=str, default="model.vtp", help="Name of the model file")
parser.add_argument('--c', type=str, default="centerline.vtp",
help="Name of the centerline file")
Surface = None
def ClipCallback(ClipWidget, Clipper, ClipFunction, Surface, ClippedSurface,
Cutter, CutLines)
ClipWidget.GetPlanes(ClipFunction)
Clipper.Update()
Surface.DeepCopy(Clipper.GetOutput())
Surface.Update()
ClippedSurface.DeepCopy(Clipper.GetClippedOutput())
ClippedSurface.Update()
Cutter.Update()
CutLines.DeepCopy(Cutter.GetOutput())
def Execute(Surface, cl):
if Surface == None:
print 'Error: no Surface.'
sys.exit(0)
# Initialize
Clipper = vtk.vtkClipPolyData()
Clipper.SetInput(Surface)
Clipper.GenerateClippedOutputOn()
Clipper.SetInsideOut(0)
ClipFunction = vtk.vtkPlanes()
Clipper.SetClipFunction(ClipFunction)
Cutter = vtk.vtkCutter()
Cutter.SetInput(Surface)
Cutter.SetCutFunction(ClipFunction)
ClippedSurface = vtk.vtkPolyData()
CutLines = vtk.vtkPolyData()
ClipWidget = vtk.vtkBoxWidget()
ClipWidget.GetFaceProperty().SetColor(0.6,0.6,0.2)
ClipWidget.GetFaceProperty().SetOpacity(0.25)
Transform = vtk.vtkTransform()
ClipWidget.GetTransform(Transform)
for i in range(cl.GetNumberOfLines()):
# TODO: Implement thing here.
# Clean surface
cleaner = vtk.vtkCleanPolyData()
cleaner.SetInput(Surface)
cleaner.Update()
Surface = cleaner.GetOutput()
cleaner = vtk.vtkCleanPolyData()
cleaner.SetInput(ClippedSurface)
cleaner.Update()
ClippedSurface = cleaner.GetOutput()
cleaner = vtk.vtkCleanPolyData()
cleaner.SetInput(CutLines)
cleaner.Update()
stripper = vtk.vtkStripper()
stripper.SetInput(cleaner.GetOutput())
stripper.Update()
CutLines = stripper.GetOutput()
if Surface.GetSource():
Surface.GetSource().UnRegisterAllOutputs()
if __name__=='__main__':
surface = read_command_line()
Execute()