-
Notifications
You must be signed in to change notification settings - Fork 0
/
mesh_gen.py
120 lines (98 loc) · 3.98 KB
/
mesh_gen.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
#!/usr/bin/env python
from itaps import iBase, iMesh
import utils, argparse, time
import numpy as np
def make_2d(mesh, dims):
print ">>>>>> make_2d"
x,y=dims
print "X-dim=%s, Y-dim=%s, Z-dim=%s" % (x,y,1)
print "--> make_coords"
t0=time.time()
coords=utils.make_coords(x,y,1)
print " %.1f ms" % ((time.time()-t0)*1000)
print "--> createVtx"
t0=time.time()
verts=mesh.createVtx(coords)
print " %.1f ms" % ((time.time()-t0)*1000)
print "--> make_quadrilateral_vertex_array"
t0=time.time()
# vert_arr=utils.make_quadrilateral_vertex_array_orig(verts, x, y)
# vert_arr=utils.make_quadrilateral_vertex_array_extend(verts, x)
vert_arr=utils.make_quadrilateral_vertex_array(verts, x)
print " %.1f ms" % ((time.time()-t0)*1000)
print "--> createEntArr quadrilaterals"
t0=time.time()
quads,status=mesh.createEntArr(iMesh.Topology.quadrilateral,vert_arr)
print " %.1f ms" % ((time.time()-t0)*1000)
print "--> createEntSet(s)"
set=mesh.createEntSet(ordered=False)
set.add(quads)
utils.print_mesh_types(mesh)
print "<<<<<<\n"
def make_3d(mesh, dims, t3d):
print ">>>>>> make_3d"
x,y,z=dims
print "X-dim=%s, Y-dim=%s, Z-dim=%s" % (x,y,z)
print "--> make_coords"
t0=time.time()
coords=utils.make_coords(x,y,z)
print " %.1f ms" % ((time.time()-t0)*1000)
print "--> createVtx"
t0=time.time()
verts=mesh.createVtx(coords)
print " %.1f ms" % ((time.time()-t0)*1000)
print "--> make_hexahedron_vertex_array"
t0=time.time()
# vert_arr=utils.make_hexahedron_vertex_array_orig(verts, x,y,z)
# vert_arr=utils.make_hexahedron_vertex_array_extend(verts, x,y,z)
vert_arr=utils.make_hexahedron_vertex_array(verts, x,y,z)
print " %.1f ms" % ((time.time()-t0)*1000)
print "--> createEntArr hexahedrons"
t0=time.time()
cubes,status=mesh.createEntArr(iMesh.Topology.hexahedron,vert_arr)
print " %.1f ms" % ((time.time()-t0)*1000)
print "--> createEntSet(s)"
if t3d:
set=mesh.createEntSet(ordered=False)
set.add(cubes)
else:
t0=time.time()
slice_size=(x-1)*(y-1)
# Add a set for the 'top' (5th face) of each 'layer' in the mesh
for zi in range(z-1):
set=mesh.createEntSet(ordered=False)
# The 5th face (index 4) is always the top
set.add([x[4] for x in mesh.getEntAdj(cubes[zi*slice_size:(zi+1)*slice_size], iBase.Type.face)])
# Add a final set for the 'bottom' (6th face) of the last 'layer' in the mesh
set=mesh.createEntSet(ordered=False)
# The 6th face (index 5) is always the top
set.add([x[5] for x in mesh.getEntAdj(cubes[(z-1)*slice_size:z*slice_size], iBase.Type.face)])
print " %.1f ms" % ((time.time()-t0)*1000)
utils.print_mesh_types(mesh)
print "<<<<<<\n"
parser = argparse.ArgumentParser(description='Construct a 2D, 2.5D, or 3D mesh of size <cube_dims>')
parser.add_argument('--3d', action='store_true', dest='t3d', help='If a true 3D mesh should be created. Otherwise, creates a 2.5D mesh')
parser.add_argument('cube_dims', type=int, nargs='*', help='Integers defining the dimensions (x,y,z) of the mesh to create. Must specify at least 2 dimensions (x,y)')
args=parser.parse_args()
dims=args.cube_dims
mesh=iMesh.Mesh()
# Set the adjacency table such that all intermediate-topologies are generated
mesh.adjTable = np.array([[7, 4, 4, 1],[1, 7, 5, 5],[1, 5, 7, 5],[1, 5, 5, 7]], dtype='int32')
ents=[]
if 4 > len(dims) >= 2:
if dims[0] is 1 or dims[1] is 1:
if dims[0] is 1 and dims[1] is 1:
# This is a point
print "!!> Support for points coming soon"
else:
# This is a line (trajectory)
print "!!> Support for lines coming soon"
elif len(dims) is 3:
if dims[2] > 1:
make_3d(mesh, dims, args.t3d)
else:
make_2d(mesh, dims[:-1])
else:
make_2d(mesh, dims)
else:
parser.print_help()