-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProjectToNewMesh_VMTK.py
55 lines (42 loc) · 2.29 KB
/
ProjectToNewMesh_VMTK.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
import os
import argparse
import sys
from glob import glob
from utilities import *
import vtk
import numpy as np
from vtk.util.numpy_support import vtk_to_numpy, numpy_to_vtk
class ProjectToNewMesh_VMTK():
def __init__(self,Args):
self.Args=Args
if self.Args.OutputFolder is None:
self.Args.OutputFolder=self.Args.InputFolder.replace(self.Args.InputFolder.split("/")[-1],self.Args.InputFolder.split("/")[-1]+"_coarse/")
os.system("mkdir %s"%self.Args.OutputFolder)
else:
os.system("mkdir %s/"%self.Args.OutputFolder)
self.Args.OutputFolder=self.Args.OutputFolder+"/"
def Main(self):
#Read all of the file name
InputFiles=sorted(glob(self.Args.InputFolder+"/*.vtu")) #volumetric files
print ("--- Total number of Files: %d"%len(InputFiles))
InputFiles=InputFiles[::self.Args.Skip]
#Read the Coarse Mesh
#MeshVolume=ReadVTUFile(self.Args.InputFileName)
#print ("--- Read the Mesh File: %s"%self.Args.InputFileName)
#Loop over all of the velocity files
counter=0
for InputFile_ in InputFiles:
outputfilename_=self.Args.OutputFolder+InputFile_.split("/")[-1]
os.system("vmtkmeshprojection -rfile %s -ifile %s -ofile %s/velocity_%05d.vtu"%(InputFile_,self.Args.InputFileName,self.Args.OutputFolder,counter))
counter+=1
if __name__=="__main__":
#Arguments
parser= argparse.ArgumentParser(description="This script will project results generated by simvascular onto a coarser mesh.")
parser.add_argument('-InputFolder', '--InputFolder', type=str, required=True, dest="InputFolder", help="The input folder that contains all of the results file, taged ass all_results.vtu.XXXXX.vtu")
parser.add_argument('-InputFileName', '--InputFileName', type=str, required=True, dest="InputFileName", help="The input file corresponds to the mesh onto which the results will be projected.")
parser.add_argument('-Skip', '--Skip', type=int, required=False, default=1, dest="Skip", help="Skip factor to reduce the number of time series data (e.g., skip=2 means only every other file will be used)")
parser.add_argument('-OutputFolder', '--OutputFolder', type=str, required=False, dest="OutputFolder", help="The output folder to store the time-averaged file in.")
#Put all the arguments together
args=parser.parse_args()
#Call your Class
ProjectToNewMesh_VMTK(args).Main()