Skip to content

Commit a65ccf0

Browse files
committed
[OPT] Refactor scalar field interpolation and edge processing for enhanced clarity and integration consistency
1 parent 4e2833d commit a65ccf0

File tree

1 file changed

+49
-10
lines changed

1 file changed

+49
-10
lines changed

gempy_engine/API/dual_contouring/multi_scalar_dual_contouring.py

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from ...core.data.options import MeshExtractionMaskingOptions
2020
from ...core.data.stack_relation_type import StackRelationType
2121
from ...core.utils import gempy_profiler_decorator
22+
from ...modules.dual_contouring.dual_contouring_interface import find_intersection_on_edge
2223
from ...modules.dual_contouring.fancy_triangulation import get_left_right_array
2324

2425

@@ -57,6 +58,10 @@ def dual_contouring_multi_scalar(data_descriptor: InputDataDescriptor, interpola
5758
masking_option=options.evaluation_options.mesh_extraction_masking_options
5859
)
5960

61+
all_stack_intersection = []
62+
all_valid_edges = []
63+
all_left_right_codes = []
64+
6065
for n_scalar_field in range(data_descriptor.stack_structure.n_stacks):
6166
previous_stack_is_onlap = data_descriptor.stack_relation[n_scalar_field - 1] == 'Onlap'
6267
was_erosion_before = data_descriptor.stack_relation[n_scalar_field - 1] == 'Erosion'
@@ -71,27 +76,61 @@ def dual_contouring_multi_scalar(data_descriptor: InputDataDescriptor, interpola
7176
else:
7277
left_right_codes_per_stack = left_right_codes
7378

74-
# @off
75-
dc_data: DualContouringData = interpolate_on_edges_for_dual_contouring(
76-
data_descriptor=data_descriptor,
77-
interpolation_input=interpolation_input,
78-
options=dual_contouring_options,
79-
n_scalar_field=n_scalar_field,
80-
octree_leaves=octree_leaves,
81-
mask=mask
79+
output: InterpOutput = octree_leaves.outputs_centers[n_scalar_field]
80+
intersection_xyz, valid_edges = find_intersection_on_edge(
81+
_xyz_corners=octree_leaves.grid_centers.corners_grid.values,
82+
scalar_field_on_corners=output.exported_fields.scalar_field[output.grid.corners_grid_slice],
83+
scalar_at_sp=output.scalar_field_at_sp,
84+
masking=mask
85+
)
86+
87+
all_stack_intersection.append(intersection_xyz)
88+
all_valid_edges.append(valid_edges)
89+
all_left_right_codes.append(left_right_codes_per_stack)
90+
91+
from gempy_engine.core.data.engine_grid import EngineGrid
92+
from gempy_engine.core.data.generic_grid import GenericGrid
93+
from gempy_engine.API.interp_single.interp_features import interpolate_all_fields_no_octree
94+
interpolation_input.set_temp_grid(
95+
EngineGrid(
96+
custom_grid=GenericGrid(
97+
values=BackendTensor.t.concatenate(all_stack_intersection, axis=0)
98+
)
8299
)
100+
)
101+
# endregion
102+
103+
# ! (@miguel 21 June) I think by definition in the function `interpolate_all_fields_no_octree`
104+
# ! we just need to interpolate up to the n_scalar_field, but I am not sure about this. I need to test it
105+
output_on_edges: List[InterpOutput] = interpolate_all_fields_no_octree(
106+
interpolation_input=interpolation_input,
107+
options=dual_contouring_options,
108+
data_descriptor=data_descriptor
109+
) # ! This has to be done with buffer weights otherwise is a waste
110+
interpolation_input.set_grid_to_original()
83111

112+
for n_scalar_field in range(data_descriptor.stack_structure.n_stacks):
113+
output: InterpOutput = octree_leaves.outputs_centers[n_scalar_field]
114+
dc_data = DualContouringData(
115+
xyz_on_edge=all_stack_intersection[n_scalar_field],
116+
valid_edges=all_valid_edges[n_scalar_field],
117+
xyz_on_centers=octree_leaves.grid_centers.octree_grid.values if mask is None else octree_leaves.grid_centers.octree_grid.values[mask],
118+
dxdydz=octree_leaves.grid_centers.octree_dxdydz,
119+
exported_fields_on_edges=output_on_edges[n_scalar_field].exported_fields,
120+
n_surfaces_to_export=output.scalar_field_at_sp.shape[0],
121+
tree_depth=options.number_octree_levels,
122+
)
84123
meshes: List[DualContouringMesh] = compute_dual_contouring(
85124
dc_data_per_stack=dc_data,
86-
left_right_codes=left_right_codes_per_stack,
125+
left_right_codes=all_left_right_codes[n_scalar_field],
87126
debug=options.debug
88127
)
89128

90129
# ! If the order of the meshes does not match the order of scalar_field_at_surface points we need to reorder them HERE
91130

92131
if meshes is not None:
93132
all_meshes.extend(meshes)
94-
# @on
133+
# @on
95134

96135
return all_meshes
97136

0 commit comments

Comments
 (0)