-
Notifications
You must be signed in to change notification settings - Fork 2
/
PlotAlongCenterlineForOasis.py
139 lines (101 loc) · 4.75 KB
/
PlotAlongCenterlineForOasis.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
137
138
139
import sys
import os
from glob import glob
from vtk.util.numpy_support import vtk_to_numpy as npvtk
import numpy as np
from scipy.fftpack import fftfreq,fft,ifft
import vtk
import argparse
from utilities import *
class PlotAlongCenterline():
def __init__(self,Args):
self.Args=Args
def Main(self):
if self.Args.OutputFolder is None:
self.Args.OutputFolder="TemporalAvg"
os.system("mkdir %s"%self.Args.OutputFolder)
#Compute the centerlines
CL_FileName=self.Args.OutputFolder+"/"+self.Args.InputSurface.replace(".vtp","_cl.vtp").split("/")[-1]
InputFiles=sorted(glob(self.Args.InputFolder+"/*.vtu"))
os.system("vmtkcenterlines -ifile %s -ofile %s -endpoints 1 -resampling 1 -resamplingstep 0.05"%(self.Args.InputSurface,CL_FileName))
#Compute centerline sections
OutputFileName=self.Args.OutputFolder+"/Results_Section"
outfile = open(OutputFileName+".txt",'w')
outfile.write('SectionID,Length,Surface_Area')
AllData={}
for file in InputFiles:
File_=ReadVTUFile(file)
os.system("vmtkcenterlinemeshsections -centerlinesfile %s -ifile %s -ofile %s.vtp"%(CL_FileName,file,OutputFileName))
SurfaceSections=(ReadVTPFile(OutputFileName+".vtp"))
#Get the number of section ids
print(SurfaceSections)
Nstart,Nend=SurfaceSections.GetPointData().GetArray("SectionIds").GetRange()
Nstart=int(Nstart)
Nend=int(Nend)
Dist_=np.zeros(Nend-Nstart)
Dist_sum=0
SurfaceArea_=np.zeros(Nend-Nstart)
for i in range(Nstart,Nend):
#outfile.write('%d'%i)i
#Get the Section of the Slice
section_ = ThresholdInBetween(SurfaceSections,"SectionIds",i,i)
#Extract a surface from the section_
surface_=vtk.vtkDataSetSurfaceFilter()
surface_.SetInputData(section_)
surface_.Update()
#Store the Slice
WriteVTPFile(self.Args.OutputFolder+"/"+"temp.vtp",surface_.GetOutput())
#Triangulate the surface
os.system("vmtksurfacetriangle -ifile %s/temp.vtp -ofile %s/temp.vtp"%(self.Args.OutputFolder, self.Args.OutputFolder))
#Remesh the surface to a constant vensity
os.system("vmtksurfaceremeshing -ifile %s/temp.vtp -ofile %s/temp_remeshed.vtp -elementsizemode edgelength -edgelength 0.01"%(self.Args.OutputFolder,self.Args.OutputFolder))
#Project the velocity on the new mesh
os.system("vmtksurfaceprojection -ifile %s/temp_remeshed.vtp -rfile %s/temp.vtp -ofile %s/temp_proj.vtp"%(self.Args.OutputFolder,self.Args.OutputFolder,self.Args.OutputFolder))
#Read the Remeshed Surface File
sectionremeshed_=ReadVTPFile("%s/temp_proj.vtp"%self.Args.OutputFolder)
#Compute the area
SurfaceArea_[i]+=ComputeArea(sectionremeshed_)
#Get the length from the inlet
Centroid_=GetCentroid(sectionremeshed_)
if i==Nstart: Dist_sum=0
else:
Dist_sum+= np.sqrt( (Centroid_[0]-Centroid_old_[0])**2 + (Centroid_[1]-Centroid_old_[1])**2 + (Centroid_[2]-Centroid_old_[2])**2 )
Dist_[i]+=Dist_sum
Centroid_old_=Centroid_
#Loop over arrays
for j in range (0,sectionremeshed_.GetPointData().GetNumberOfArrays()):
#ArrayName
ArrayName=sectionremeshed_.GetPointData().GetArrayName(j)
#Number of Points
Npts=sectionremeshed_.GetNumberOfPoints()
#Write array names to text
if i == Nstart:
outfile.write(',%s_max,%s_avg'%(ArrayName,ArrayName))
AllData[ArrayName+"_max"]=[]
AllData[ArrayName+"_avg"]=[]
#Save values to matrix
min_value,max_value=sectionremeshed_.GetPointData().GetArray(ArrayName).GetValueRange()
AllData[ArrayName+"_max"].append(max_value)
#Get the Average Value
avg_value=np.average(vtk_to_numpy(sectionremeshed_.GetPointData().GetArray(ArrayName)))
AllData[ArrayName+"_avg"].append(avg_value)
outfile.close()
outfile=open(OutputFileName+".txt",'r+')
header=outfile.read()
Array=header.split(',')[3:]
outfile.write('\n')
#Write values to text file
for i in range(Nstart,Nend):
outfile.write('%d %0.5f %0.5f '%(i,Dist_[i],SurfaceArea_[i]))
for name in Array:
outfile.write('%0.5f '%(AllData.get(name)[i]))
outfile.write('\n')
if __name__=="__main__":
#Description
parser = argparse.ArgumentParser(description="This script will compute quantities along the centerline")
parser.add_argument('-InputFolder', '--InputFolder', type=str, required=True, dest="InputFolder",help="The folder that contains the data in vtu format")
parser.add_argument('-InputSurface', '--InputSurface', type=str, required=True, dest="InputSurface",help="The surface file along which to compute the data.")
#Output Filename
parser.add_argument('-OutputFolder', '--OutputFolder', type=str, required=False, dest="OutputFolder",help="An output folder to store the centerlines and data")
args=parser.parse_args()
PlotAlongCenterline(args).Main()