21
21
__copyright__ = "Thomas Guillod - Dartmouth College"
22
22
__license__ = "Mozilla Public License Version 2.0"
23
23
24
+ import vtk
24
25
import warnings
25
26
import scilogger
26
27
import numpy as np
29
30
import rasterio .features as raf
30
31
import rasterio .transform as rat
31
32
33
+ # prevent VTK to mess up the output
34
+ vtk .vtkObject .GlobalWarningDisplayOff ()
35
+
32
36
# prevent problematic linear transform to trigger warnings
33
37
warnings .filterwarnings ("ignore" , module = "shapely" )
34
38
warnings .filterwarnings ("ignore" , module = "rasterio.features" )
@@ -60,13 +64,13 @@ def _get_boundary_polygon(bnd, z_min):
60
64
xyz = xyz [:- 1 ]
61
65
62
66
# 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 ]) )
65
69
66
70
# create the polygon
67
- polygon = pv .PolyData (xyz , faces = faces )
71
+ mesh = pv .PolyData (xyz , lines = lines )
68
72
69
- return polygon
73
+ return mesh
70
74
71
75
72
76
def _get_shape_mesh (z_min , z_max , obj ):
@@ -81,18 +85,17 @@ def _get_shape_mesh(z_min, z_max, obj):
81
85
bnd = obj .exterior
82
86
holes = obj .interiors
83
87
88
+ # create an empty mesh
89
+ mesh = pv .PolyData ()
90
+
84
91
# 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 )
86
94
87
95
# polygon for the holes
88
96
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 )
96
99
97
100
return mesh
98
101
@@ -428,8 +431,8 @@ def _get_merge_shape(stack_pos, shape_obj):
428
431
This mesh can be used to assess the quality of the voxelization.
429
432
"""
430
433
431
- # list for storing the meshes
432
- mesh_list = []
434
+ # create an empty mesh
435
+ reference = pv . PolyData ()
433
436
434
437
# merge all the shapes
435
438
for shape_obj_tmp in shape_obj :
@@ -443,19 +446,13 @@ def _get_merge_shape(stack_pos, shape_obj):
443
446
444
447
# transform the shapes into meshes
445
448
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 )
448
450
elif isinstance (obj , sha .MultiPolygon ):
449
451
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 )
452
453
else :
453
454
raise ValueError ("invalid shape type" )
454
455
455
- # assemble the meshes
456
- reference = pv .MultiBlock (mesh_list )
457
- reference = reference .combine ().extract_surface ()
458
-
459
456
return reference
460
457
461
458
@@ -514,6 +511,7 @@ def get_mesh(param, layer_stack, geometry_shape):
514
511
# cast reference mesh
515
512
reference = {
516
513
"faces" : np .array (reference .faces , dtype = np .int64 ),
514
+ "lines" : np .array (reference .lines , dtype = np .int64 ),
517
515
"points" : np .array (reference .points , dtype = np .float64 ),
518
516
}
519
517
0 commit comments