@@ -29,8 +29,6 @@ def set_meshes_with_marching_cubes(model: GeoModel) -> None:
29
29
regular_grid : RegularGrid = model .grid .regular_grid
30
30
structural_groups : list [StructuralGroup ] = model .structural_frame .structural_groups
31
31
32
- print (model .solutions .scalar_field_at_surface_points )
33
-
34
32
if not model .solutions .octrees_output or not model .solutions .octrees_output [0 ].outputs_centers :
35
33
raise ValueError ("No interpolation outputs available for mesh extraction." )
36
34
@@ -53,13 +51,29 @@ def set_meshes_with_marching_cubes(model: GeoModel) -> None:
53
51
continue
54
52
55
53
output_group : InterpOutput = output_lvl0 [e ]
54
+
56
55
scalar_field_matrix = output_group .exported_fields_dense_grid .scalar_field
57
56
57
+ # TODO: get the correct mask
58
+ # for some reason output_group.mask_components has 8 more entries then necessary
59
+ # output_group.mask_components[8:] seems to be correct for plotting when transposed
60
+ # at least for the 2D slice plot. But it does not work for the marching cubes
61
+ mask = np .invert (output_group .mask_components [8 :].reshape (model .grid .regular_grid .resolution ).T )
62
+
63
+ # plot slice of mask as sanity check
64
+ import matplotlib .pyplot as plt
65
+ plt .imshow (mask [:, 5 , :])
66
+ # set extent to match the model
67
+ plt .xlim (0 , 40 )
68
+ plt .ylim (0 , 20 )
69
+ plt .show ()
70
+
58
71
for element in structural_group .elements :
59
72
extract_mesh_for_element (
60
73
structural_element = element ,
61
74
regular_grid = regular_grid ,
62
- scalar_field = scalar_field_matrix
75
+ scalar_field = scalar_field_matrix ,
76
+ mask = mask
63
77
)
64
78
65
79
@@ -82,12 +96,14 @@ def extract_mesh_for_element(structural_element: StructuralElement,
82
96
"""
83
97
# Apply mask if provided
84
98
volume = scalar_field .reshape (regular_grid .resolution )
85
- if mask is not None :
86
- volume = volume * mask
87
99
88
100
# TODO: We need to pass the mask arrays to the marching cubes to account for discontinuities. The mask array are
89
101
# in InterpOutput too if I remember correctly.
90
102
103
+ # TODO: Do we apply the mask before or add it as an argument to the marching cubes function?
104
+ # if mask is not None:
105
+ # volume = volume * mask
106
+
91
107
# Extract mesh using marching cubes
92
108
verts , faces , _ , _ = measure .marching_cubes (
93
109
volume = volume ,
0 commit comments