-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_random.py
57 lines (43 loc) · 1.66 KB
/
gen_random.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
import argparse
from paraview import simple
def main(edge_size, field, dest_dir):
fug = simple.FastUniformGrid()
fug.WholeExtent = [0, edge_size - 1, 0, edge_size - 1, 0, edge_size - 1]
sfname = {"elevation": "Elevation", "random": "RandomPointScalars"}
if field == "elevation":
sf = simple.Elevation(Input=fug)
sf.LowPoint = [0, 0, 0]
sf.HighPoint = [edge_size - 1, edge_size - 1, edge_size - 1]
elif field == "random":
sf = simple.RandomAttributes(Input=fug)
sf.DataType = "Float"
sf.ComponentRange = [0.0, 1.0]
sf.GeneratePointScalars = 1
sf.GenerateCellVectors = 0
# rename scalar field to "ImageFile" (and convert it to float)
calc = simple.Calculator(Input=sf)
calc.Function = sfname[field]
calc.ResultArrayType = "Float"
calc.ResultArrayName = "ImageFile"
# only keep "ImageFile" field
pa = simple.PassArrays(Input=calc)
pa.PointDataArrays = ["ImageFile"]
simple.SaveData(f"{dest_dir}/{field}.vti", Input=pa)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Generate a cubical grid with the given edge size "
"with a random or an elevation scalar field"
)
parser.add_argument(
"edge_size", help="Number of vertices per grid edge", type=int, default=8
)
parser.add_argument(
"-f",
"--field",
choices=["elevation", "random"],
help="Generated scalar field",
default="random",
)
parser.add_argument("-d", "--dest_dir", help="Destination directory", default=".")
args = parser.parse_args()
main(args.edge_size, args.field, args.dest_dir)