Skip to content

Commit d6fe2fd

Browse files
committed
[TEST/WIP] Adding first test to implement marching cubes
1 parent 258f5ba commit d6fe2fd

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

gempy/core/data/grid.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,11 @@ def _update_values(self):
254254
if self.GridTypes.CENTERED in self.active_grids:
255255
if self.centered_grid is None: raise AttributeError('Centered grid is active but not defined')
256256
values.append(self.centered_grid.values)
257-
257+
258+
# make sure values is not empty
259+
if len(values) == 0:
260+
return self.values
261+
258262
self.values = np.concatenate(values)
259263

260264
return self.values
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import numpy as np
2+
from gempy_engine.core.data.raw_arrays_solution import RawArraysSolution
3+
4+
import gempy as gp
5+
from gempy.core.data.enumerators import ExampleModel
6+
from gempy.core.data.grid_modules import RegularGrid
7+
from gempy.optional_dependencies import require_gempy_viewer
8+
9+
PLOT = True
10+
11+
12+
def test_marching_cubes_implementation():
13+
model = gp.generate_example_model(ExampleModel.COMBINATION, compute_model=False)
14+
15+
# Change the grid to only be the dense grid
16+
dense_grid: RegularGrid = RegularGrid(
17+
extent=model.grid.extent,
18+
resolution=np.array([20, 20, 20])
19+
)
20+
21+
model.grid.dense_grid = dense_grid
22+
gp.set_active_grid(
23+
grid=model.grid,
24+
grid_type=[model.grid.GridTypes.DENSE],
25+
reset=True
26+
)
27+
28+
model.interpolation_options.evaluation_options.mesh_extraction = False # * Not extracting the mesh with dual contouring
29+
gp.compute_model(model)
30+
31+
# Assert
32+
assert model.solutions.block_solution_type == RawArraysSolution.BlockSolutionType.DENSE_GRID
33+
assert model.solutions.dc_meshes is None
34+
arrays = model.solutions.raw_arrays # * arrays is equivalent to gempy v2 solutions
35+
36+
assert arrays.scalar_field_matrix.shape == (3, 8_000) # * 3 surfaces, 8000 points
37+
38+
# TODO: Code to extract the mesh with marching cubes
39+
40+
if PLOT:
41+
gpv = require_gempy_viewer()
42+
gtv: gpv.GemPyToVista = gpv.plot_3d(model, show_data=True, image=True)
43+
import pyvista as pv
44+
pyvista_plotter: pv.Plotter = gtv.p
45+
46+
foo = np.empty(0) # TODO: use the marching cubes algorithm to add mesh to the gempy plot
47+
# Add the mesh to the plot
48+
pyvista_plotter.add_mesh(
49+
foo,
50+
show_edges=True,
51+
color='white',
52+
opacity=0.5,
53+
)

0 commit comments

Comments
 (0)