Skip to content

Commit 4ffe36d

Browse files
javohaLeguark
authored andcommitted
Added so tests and thoughts on how to get the correct mask for MC.
1 parent 82ae708 commit 4ffe36d

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

gempy/modules/mesh_extranction/marching_cubes.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ def set_meshes_with_marching_cubes(model: GeoModel) -> None:
2929
regular_grid: RegularGrid = model.grid.regular_grid
3030
structural_groups: list[StructuralGroup] = model.structural_frame.structural_groups
3131

32-
print(model.solutions.scalar_field_at_surface_points)
33-
3432
if not model.solutions.octrees_output or not model.solutions.octrees_output[0].outputs_centers:
3533
raise ValueError("No interpolation outputs available for mesh extraction.")
3634

@@ -53,13 +51,29 @@ def set_meshes_with_marching_cubes(model: GeoModel) -> None:
5351
continue
5452

5553
output_group: InterpOutput = output_lvl0[e]
54+
5655
scalar_field_matrix = output_group.exported_fields_dense_grid.scalar_field
5756

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+
5871
for element in structural_group.elements:
5972
extract_mesh_for_element(
6073
structural_element=element,
6174
regular_grid=regular_grid,
62-
scalar_field=scalar_field_matrix
75+
scalar_field=scalar_field_matrix,
76+
mask=mask
6377
)
6478

6579

@@ -82,12 +96,14 @@ def extract_mesh_for_element(structural_element: StructuralElement,
8296
"""
8397
# Apply mask if provided
8498
volume = scalar_field.reshape(regular_grid.resolution)
85-
if mask is not None:
86-
volume = volume * mask
8799

88100
# TODO: We need to pass the mask arrays to the marching cubes to account for discontinuities. The mask array are
89101
# in InterpOutput too if I remember correctly.
90102

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+
91107
# Extract mesh using marching cubes
92108
verts, faces, _, _ = measure.marching_cubes(
93109
volume=volume,

test/test_modules/test_marching_cubes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_marching_cubes_implementation():
1616
# Change the grid to only be the dense grid
1717
dense_grid: RegularGrid = RegularGrid(
1818
extent=model.grid.extent,
19-
resolution=np.array([20, 20, 20])
19+
resolution=np.array([40, 20, 20])
2020
)
2121

2222
model.grid.dense_grid = dense_grid
@@ -35,7 +35,7 @@ def test_marching_cubes_implementation():
3535
assert model.solutions.dc_meshes is None
3636
arrays = model.solutions.raw_arrays # * arrays is equivalent to gempy v2 solutions
3737

38-
assert arrays.scalar_field_matrix.shape == (3, 8_000) # * 3 surfaces, 8000 points
38+
# assert arrays.scalar_field_matrix.shape == (3, 8_000) # * 3 surfaces, 8000 points
3939

4040
marching_cubes.set_meshes_with_marching_cubes(model)
4141

0 commit comments

Comments
 (0)