Skip to content

Commit e7a66a5

Browse files
committed
introduced bug for shape mesher
1 parent c206327 commit e7a66a5

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

pypeec/lib_mesher/mesher_shape.py

+24-13
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _get_idx_voxel(n, idx_shape, stack_idx):
8686
return idx_voxel
8787

8888

89-
def _get_boundary_polygon(bnd, z_min):
89+
def _get_boundary_polygon(tag, bnd, z_min):
9090
"""
9191
Convert a Shapely boundary into a line mesh.
9292
"""
@@ -114,6 +114,7 @@ def _get_boundary_polygon(bnd, z_min):
114114

115115
# create the polygon
116116
mesh = {
117+
"tag": tag,
117118
"faces": np.array(faces, dtype=np.int64),
118119
"lines": np.array(lines, dtype=np.int64),
119120
"points": np.array(points, dtype=np.float64),
@@ -122,7 +123,7 @@ def _get_boundary_polygon(bnd, z_min):
122123
return mesh
123124

124125

125-
def _get_shape_mesh(obj, z_min, z_max):
126+
def _get_shape_mesh(tag, obj, z_min, z_max):
126127
"""
127128
Extrude a Shapely polygon into line meshes.
128129
"""
@@ -138,13 +139,13 @@ def _get_shape_mesh(obj, z_min, z_max):
138139
geom_def = []
139140

140141
# polygon for the external boundaries
141-
geom_def.append(_get_boundary_polygon(bnd, z_min))
142-
geom_def.append(_get_boundary_polygon(bnd, z_max))
142+
geom_def.append(_get_boundary_polygon(tag, bnd, z_min))
143+
geom_def.append(_get_boundary_polygon(tag, bnd, z_max))
143144

144145
# polygon for the holes
145146
for bnd in holes:
146-
geom_def.append(_get_boundary_polygon(bnd, z_min))
147-
geom_def.append(_get_boundary_polygon(bnd, z_max))
147+
geom_def.append(_get_boundary_polygon(tag, bnd, z_min))
148+
geom_def.append(_get_boundary_polygon(tag, bnd, z_max))
148149

149150
return geom_def
150151

@@ -316,8 +317,8 @@ def _get_shape_obj(geometry_shape, stack_tag, simplify, construct):
316317
Find the bounding box for all the shapes (minimum and maximum coordinates).
317318
"""
318319

319-
# init shape dict
320-
shape_obj = {}
320+
# init shape list
321+
shape_obj = []
321322

322323
# init the coordinate (minimum and maximum coordinates)
323324
xy_min = np.full(2, +np.inf, dtype=np.float64)
@@ -343,7 +344,7 @@ def _get_shape_obj(geometry_shape, stack_tag, simplify, construct):
343344
xy_max = np.maximum(xy_max, tmp_max)
344345

345346
# assign the object
346-
shape_obj[tag] = (obj, idx)
347+
shape_obj.append({"tag": tag, "idx": idx, "obj": obj})
347348

348349
return shape_obj, xy_min, xy_max
349350

@@ -401,17 +402,22 @@ def _get_merge_shape(stack_pos, shape_obj):
401402
geom_def = []
402403

403404
# merge all the shapes
404-
for obj, idx in shape_obj.values():
405+
for shape_obj_tmp in shape_obj:
406+
# extract the data
407+
tag = shape_obj_tmp["tag"]
408+
obj = shape_obj_tmp["obj"]
409+
idx = shape_obj_tmp["idx"]
410+
405411
# get the coordinates
406412
z_min = stack_pos[idx + 0]
407413
z_max = stack_pos[idx + 1]
408414

409415
# transform the shapes into meshes
410416
if isinstance(obj, sha.Polygon):
411-
geom_def += _get_shape_mesh(obj, z_min, z_max)
417+
geom_def += _get_shape_mesh(tag, obj, z_min, z_max)
412418
elif isinstance(obj, sha.MultiPolygon):
413419
for obj_tmp in obj.geoms:
414-
geom_def += _get_shape_mesh(obj_tmp, z_min, z_max)
420+
geom_def += _get_shape_mesh(tag, obj_tmp, z_min, z_max)
415421
else:
416422
raise ValueError("invalid shape type")
417423

@@ -428,7 +434,12 @@ def _get_domain_def(n, d, c, domain_def, stack_idx, shape_obj):
428434
xyz_max = c + (n * d) / 2
429435

430436
# voxelize the shapes
431-
for tag, (obj, idx) in shape_obj.items():
437+
for shape_obj_tmp in shape_obj:
438+
# extract the data
439+
tag = shape_obj_tmp["tag"]
440+
obj = shape_obj_tmp["obj"]
441+
idx = shape_obj_tmp["idx"]
442+
432443
# voxelize and get the indices
433444
idx_shape = _get_voxelize_shape(n, xyz_min, xyz_max, obj)
434445
idx_voxel = _get_idx_voxel(n, idx_shape, stack_idx[idx])

pypeec/lib_mesher/mesher_stl.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def _get_mesh_stl(domain_stl, check):
8484
Find the bounding box for all the meshes (minimum and maximum coordinates).
8585
"""
8686

87-
# init mesh dict
88-
mesh_stl = {}
87+
# init mesh list
88+
mesh_stl = []
8989

9090
# init the coordinate (minimum and maximum coordinates)
9191
xyz_min = np.full(3, +np.inf, dtype=np.float64)
@@ -112,7 +112,7 @@ def _get_mesh_stl(domain_stl, check):
112112
xyz_max = np.maximum(xyz_max, tmp_max)
113113

114114
# assign the mesh
115-
mesh_stl[tag] = mesh
115+
mesh_stl.append({"tag": tag, "mesh": mesh})
116116

117117

118118
return mesh_stl, xyz_min, xyz_max
@@ -258,8 +258,14 @@ def _get_merge_mesh(mesh_stl):
258258
geom_def = []
259259

260260
# cast the surface mesh to a dict
261-
for mesh in mesh_stl.values():
261+
for mesh_stl_tmp in mesh_stl:
262+
# extract the data
263+
tag = mesh_stl_tmp["tag"]
264+
mesh = mesh_stl_tmp["mesh"]
265+
266+
# add the mesh
262267
geom_def.append({
268+
"tag": tag,
263269
"faces": np.array(mesh.faces, dtype=np.int64),
264270
"lines": np.array(mesh.lines, dtype=np.int64),
265271
"points": np.array(mesh.points, dtype=np.float64),
@@ -274,7 +280,11 @@ def _get_domain_def(pts, connect, domain_def, mesh_stl, thr):
274280
"""
275281

276282
# voxelize the meshes
277-
for tag, mesh in mesh_stl.items():
283+
for mesh_stl_tmp in mesh_stl:
284+
# extract the data
285+
tag = mesh_stl_tmp["tag"]
286+
mesh = mesh_stl_tmp["mesh"]
287+
278288
# voxelize and get the indices
279289
idx_voxel = _get_voxelize_stl(pts, connect, mesh, thr)
280290

0 commit comments

Comments
 (0)