-
Notifications
You must be signed in to change notification settings - Fork 2
/
ComputeCenterlines.py
84 lines (75 loc) · 2.82 KB
/
ComputeCenterlines.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
import vtk
from vmtk import vtkvmtk, vmtkscripts
import numpy as np
import sys
import os
from glob import glob
class ComputeCenterlines():
def __init__(self,Args):
self.Args=Args
def Main(self):
print ("--- Processing Centerlines")
#Read Cap Names
print ("------ Getting Cap Names")
CapNamesInlet,CapNamesOutlet=self.GetCapNames()
#Get Cap Surfaces
print ("------ Getting Cap Surfaces")
CapSurfacesInlet=[self.ReadVtpFile(CapName) for CapName in CapNamesInlet]
CapSurfacesOutlet=[self.ReadVtpFile(CapName) for CapName in CapNamesOutlet]
#Compute Cap Center
print ("------ Computing Cap Centers")
CapPointsInlet=np.array([self.GetCapCenter(CapSurface) for CapSurface in CapSurfacesInlet])
CapPointsOutlet=np.array([self.GetCapCenter(CapSurface) for CapSurface in CapSurfacesOutlet])
#Compute Centerlines
print ("------ Computing Centerlines\n")
self.ComputeCenterlines(list(CapPointsInlet.flatten()),list(CapPointsOutlet.flatten()))
def ComputeCenterlines(self,CapPointsInlet,CapPointsOutlet):
print (CapPointsOutlet)
exit(1)
centerlines=vmtkscripts.vmtkCenterlines()
centerlines.Surface= self.ReadVtpFile(self.Args.InputMeshFolder+"/walls_combined.vtp")
centerlines.SeedSelectorName='openprofiles'#'pointlist'
centerlines.AppendEndPoints=1
#centerlines.Resampling=0
#centerlines.ResamplingStepLength=0.05
centerlines.SourcePoints=CapPointsInlet
centerlines.TargetPoints=CapPointsOutlet
centerlines.Execute()
centerlines=centerlines.Centerlines
"""SmoothenCenterlines=vmtkscripts.vmtkCenterlineSmoothing()
SmoothenCenterlines.Centerlines=centerlines
SmoothenCenterlines.iterations=100
SmoothenCenterlines.factor=0.1
SmoothenCenterlines.Execute()
centerlines=SmoothenCenterlines.Centerlines"""
#Save the compute centerlines
print ("------ Storing Centerlines in %s/Centerlines.vtp"%self.Args.OutFolder)
self.WriteVtpFile(centerlines,self.Args.OutFolder+"/Centerlines.vtp")
def GetCapCenter(self,CapSurface):
Center=vtk.vtkCenterOfMass()
Center.SetInputData(CapSurface)
Center.SetUseScalarsAsWeights(False)
Center.Update()
return Center.GetCenter()
def ReadVtpFile(self,FileName):
reader=vtk.vtkXMLPolyDataReader()
reader.SetFileName(FileName)
reader.Update()
return reader.GetOutput()
def WriteVtpFile(self,Surface,FileName):
writer=vtk.vtkXMLPolyDataWriter()
writer.SetFileName(FileName)
writer.SetInputData(Surface)
writer.Update()
def GetCapNames(self):
#Go inside mesh-complete/mesh-surfaces/ and get outlets
CapNames=sorted(glob(self.Args.InputMeshFolder+"/mesh-surfaces/*.vtp"))
CapNamesInlet=[]
CapNamesOutlet=[]
for CapName in CapNames:
if CapName.find("wall_")<0 and CapName.find("inflow")<0:
CapNamesOutlet.append(CapName)
print (CapName)
if CapName.find("inflow")>=0:
CapNamesInlet.append(CapName)
return CapNamesInlet,CapNamesOutlet