@@ -86,7 +86,7 @@ def _get_idx_voxel(n, idx_shape, stack_idx):
86
86
return idx_voxel
87
87
88
88
89
- def _get_boundary_polygon (bnd , z_min ):
89
+ def _get_boundary_polygon (tag , bnd , z_min ):
90
90
"""
91
91
Convert a Shapely boundary into a line mesh.
92
92
"""
@@ -114,6 +114,7 @@ def _get_boundary_polygon(bnd, z_min):
114
114
115
115
# create the polygon
116
116
mesh = {
117
+ "tag" : tag ,
117
118
"faces" : np .array (faces , dtype = np .int64 ),
118
119
"lines" : np .array (lines , dtype = np .int64 ),
119
120
"points" : np .array (points , dtype = np .float64 ),
@@ -122,7 +123,7 @@ def _get_boundary_polygon(bnd, z_min):
122
123
return mesh
123
124
124
125
125
- def _get_shape_mesh (obj , z_min , z_max ):
126
+ def _get_shape_mesh (tag , obj , z_min , z_max ):
126
127
"""
127
128
Extrude a Shapely polygon into line meshes.
128
129
"""
@@ -138,13 +139,13 @@ def _get_shape_mesh(obj, z_min, z_max):
138
139
geom_def = []
139
140
140
141
# 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 ))
143
144
144
145
# polygon for the holes
145
146
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 ))
148
149
149
150
return geom_def
150
151
@@ -316,8 +317,8 @@ def _get_shape_obj(geometry_shape, stack_tag, simplify, construct):
316
317
Find the bounding box for all the shapes (minimum and maximum coordinates).
317
318
"""
318
319
319
- # init shape dict
320
- shape_obj = {}
320
+ # init shape list
321
+ shape_obj = []
321
322
322
323
# init the coordinate (minimum and maximum coordinates)
323
324
xy_min = np .full (2 , + np .inf , dtype = np .float64 )
@@ -343,7 +344,7 @@ def _get_shape_obj(geometry_shape, stack_tag, simplify, construct):
343
344
xy_max = np .maximum (xy_max , tmp_max )
344
345
345
346
# assign the object
346
- shape_obj [ tag ] = ( obj , idx )
347
+ shape_obj . append ({ " tag" : tag , " idx" : idx , "obj" : obj } )
347
348
348
349
return shape_obj , xy_min , xy_max
349
350
@@ -401,17 +402,22 @@ def _get_merge_shape(stack_pos, shape_obj):
401
402
geom_def = []
402
403
403
404
# 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
+
405
411
# get the coordinates
406
412
z_min = stack_pos [idx + 0 ]
407
413
z_max = stack_pos [idx + 1 ]
408
414
409
415
# transform the shapes into meshes
410
416
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 )
412
418
elif isinstance (obj , sha .MultiPolygon ):
413
419
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 )
415
421
else :
416
422
raise ValueError ("invalid shape type" )
417
423
@@ -428,7 +434,12 @@ def _get_domain_def(n, d, c, domain_def, stack_idx, shape_obj):
428
434
xyz_max = c + (n * d ) / 2
429
435
430
436
# 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
+
432
443
# voxelize and get the indices
433
444
idx_shape = _get_voxelize_shape (n , xyz_min , xyz_max , obj )
434
445
idx_voxel = _get_idx_voxel (n , idx_shape , stack_idx [idx ])
0 commit comments