Skip to content

Commit df10732

Browse files
committed
line polydata for the shape reference mesh
1 parent b00fbc2 commit df10732

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

pypeec/lib_mesher/mesher_shape.py

+20-22
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
__copyright__ = "Thomas Guillod - Dartmouth College"
2222
__license__ = "Mozilla Public License Version 2.0"
2323

24+
import vtk
2425
import warnings
2526
import scilogger
2627
import numpy as np
@@ -29,6 +30,9 @@
2930
import rasterio.features as raf
3031
import rasterio.transform as rat
3132

33+
# prevent VTK to mess up the output
34+
vtk.vtkObject.GlobalWarningDisplayOff()
35+
3236
# prevent problematic linear transform to trigger warnings
3337
warnings.filterwarnings("ignore", module="shapely")
3438
warnings.filterwarnings("ignore", module="rasterio.features")
@@ -60,13 +64,13 @@ def _get_boundary_polygon(bnd, z_min):
6064
xyz = xyz[:-1]
6165

6266
# get the face indices
63-
faces = np.arange(len(xyz) + 1)
64-
faces = np.roll(faces, 1)
67+
lines = np.arange(len(xyz))
68+
lines = np.concatenate(([len(xyz)+1], lines, [0]))
6569

6670
# create the polygon
67-
polygon = pv.PolyData(xyz, faces=faces)
71+
mesh = pv.PolyData(xyz, lines=lines)
6872

69-
return polygon
73+
return mesh
7074

7175

7276
def _get_shape_mesh(z_min, z_max, obj):
@@ -81,18 +85,17 @@ def _get_shape_mesh(z_min, z_max, obj):
8185
bnd = obj.exterior
8286
holes = obj.interiors
8387

88+
# create an empty mesh
89+
mesh = pv.PolyData()
90+
8491
# polygon for the external boundaries
85-
polygon = _get_boundary_polygon(bnd, z_min)
92+
mesh += _get_boundary_polygon(bnd, z_min)
93+
mesh += _get_boundary_polygon(bnd, z_max)
8694

8795
# polygon for the holes
8896
for bnd in holes:
89-
polygon += _get_boundary_polygon(bnd, z_min)
90-
91-
# triangulate the resulting polygon
92-
polygon = polygon.delaunay_2d(edge_source=polygon)
93-
94-
# extrude the polygon into a 3D mesh
95-
mesh = polygon.extrude((0.0, 0.0, z_max - z_min), capping=True)
97+
mesh += _get_boundary_polygon(bnd, z_min)
98+
mesh += _get_boundary_polygon(bnd, z_max)
9699

97100
return mesh
98101

@@ -428,8 +431,8 @@ def _get_merge_shape(stack_pos, shape_obj):
428431
This mesh can be used to assess the quality of the voxelization.
429432
"""
430433

431-
# list for storing the meshes
432-
mesh_list = []
434+
# create an empty mesh
435+
reference = pv.PolyData()
433436

434437
# merge all the shapes
435438
for shape_obj_tmp in shape_obj:
@@ -443,19 +446,13 @@ def _get_merge_shape(stack_pos, shape_obj):
443446

444447
# transform the shapes into meshes
445448
if isinstance(obj, sha.Polygon):
446-
mesh = _get_shape_mesh(z_min, z_max, obj)
447-
mesh_list.append(mesh)
449+
reference += _get_shape_mesh(z_min, z_max, obj)
448450
elif isinstance(obj, sha.MultiPolygon):
449451
for obj_tmp in obj.geoms:
450-
mesh = _get_shape_mesh(z_min, z_max, obj_tmp)
451-
mesh_list.append(mesh)
452+
reference += _get_shape_mesh(z_min, z_max, obj_tmp)
452453
else:
453454
raise ValueError("invalid shape type")
454455

455-
# assemble the meshes
456-
reference = pv.MultiBlock(mesh_list)
457-
reference = reference.combine().extract_surface()
458-
459456
return reference
460457

461458

@@ -514,6 +511,7 @@ def get_mesh(param, layer_stack, geometry_shape):
514511
# cast reference mesh
515512
reference = {
516513
"faces": np.array(reference.faces, dtype=np.int64),
514+
"lines": np.array(reference.lines, dtype=np.int64),
517515
"points": np.array(reference.points, dtype=np.float64),
518516
}
519517

pypeec/lib_mesher/mesher_stl.py

+1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ def get_mesh(param, domain_stl):
334334
# cast reference mesh
335335
reference = {
336336
"faces": np.array(reference.faces, dtype=np.int64),
337+
"lines": np.array(reference.lines, dtype=np.int64),
337338
"points": np.array(reference.points, dtype=np.float64),
338339
}
339340

pypeec/lib_plot/parse_voxel.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,17 @@ def get_point(pts_cloud):
6464
return point
6565

6666

67-
def get_reference(reference, voxel):
67+
def get_reference(reference):
6868
"""
6969
Construct a PyVista object from the reference mesh.
7070
"""
7171

7272
if reference is None:
73-
reference = voxel
73+
reference = pv.PolyData()
7474
else:
7575
points = reference["points"]
76+
lines = reference["lines"]
7677
faces = reference["faces"]
77-
reference = pv.PolyData(points, faces)
78+
reference = pv.PolyData(points, lines=lines, faces=faces)
7879

7980
return reference

pypeec/run/viewer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _get_grid_voxel(data_voxel):
5858
grid = parse_voxel.get_grid(n, d, c)
5959
voxel = parse_voxel.get_voxel(grid, idx)
6060
point = parse_voxel.get_point(pts_cloud)
61-
reference = parse_voxel.get_reference(reference, voxel)
61+
reference = parse_voxel.get_reference(reference)
6262

6363
# add the domains and connected components to the geometry
6464
voxel = parse_viewer.set_data(voxel, idx, domain_def, component_def)

0 commit comments

Comments
 (0)