Skip to content

Commit 5aa9f20

Browse files
committed
[BUG] Fix apply_faults_vertex_overlap call and refactor fault relations logic
1 parent 10e5482 commit 5aa9f20

File tree

3 files changed

+25
-62
lines changed

3 files changed

+25
-62
lines changed

gempy_engine/API/dual_contouring/multi_scalar_dual_contouring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def dual_contouring_multi_scalar(
134134

135135
# endregion
136136
if (options.debug or len(all_left_right_codes) > 1) and True:
137-
apply_faults_vertex_overlap(all_meshes, data_descriptor, left_right_per_mesh)
137+
apply_faults_vertex_overlap(all_meshes, data_descriptor.stack_structure, left_right_per_mesh)
138138

139139
return all_meshes
140140

gempy_engine/modules/dual_contouring/_vertex_overlap.py

Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
import numpy as np
44

55
from ...core.data.dual_contouring_mesh import DualContouringMesh
6-
6+
from ...core.data.stacks_structure import StacksStructure
77

88

99
def _apply_fault_relations_to_overlaps(
1010
all_meshes: List[DualContouringMesh],
11-
faults_relations: np.ndarray,
1211
voxel_overlaps: dict,
13-
n_stacks: int
12+
stacks_structure: StacksStructure
1413
) -> None:
1514
"""
1615
Apply fault relations to voxel overlaps by updating mesh vertices.
@@ -21,70 +20,48 @@ def _apply_fault_relations_to_overlaps(
2120
voxel_overlaps: Dictionary containing overlap information between stacks
2221
n_stacks: Total number of stacks
2322
"""
23+
faults_relations = stacks_structure.faults_relations
24+
n_stacks = stacks_structure.n_stacks
25+
number_surfaces_per_stack = stacks_structure.number_of_surfaces_per_stack_vector
26+
2427
if faults_relations is None:
2528
return
2629

27-
# Calculate mesh indices offset for each stack
28-
mesh_indices_offset = _calculate_mesh_indices_offset(all_meshes, n_stacks)
29-
3030
# Iterate through fault relations matrix
3131
for origin_stack in range(n_stacks):
3232
for destination_stack in range(n_stacks):
33-
# If there's a fault relation from origin to destination
3433
if faults_relations[origin_stack, destination_stack]:
35-
overlap_key = f"stack_{origin_stack}_vs_stack_{destination_stack}"
34+
for surface_n in range(number_surfaces_per_stack[destination_stack], number_surfaces_per_stack[destination_stack + 1]):
35+
overlap_key = f"stack_{origin_stack}_vs_stack_{surface_n}"
3636

37-
# Check if there are actual overlaps between these stacks
38-
if overlap_key in voxel_overlaps:
39-
_apply_vertex_sharing(
40-
all_meshes,
41-
origin_stack,
42-
destination_stack,
43-
voxel_overlaps[overlap_key],
44-
mesh_indices_offset
45-
)
46-
47-
48-
def _calculate_mesh_indices_offset(all_meshes: List[DualContouringMesh], n_stacks: int) -> List[int]:
49-
"""
50-
Calculate the starting mesh index for each stack.
51-
52-
Args:
53-
all_meshes: List of all dual contouring meshes
54-
n_stacks: Total number of stacks
55-
56-
Returns:
57-
List of starting mesh indices for each stack
58-
"""
59-
# For now, assume each stack has one mesh (this may need adjustment based on actual structure)
60-
# This is a simplified approach - you may need to adjust based on how meshes are organized
61-
mesh_indices_offset = list(range(n_stacks))
62-
return mesh_indices_offset
37+
# Check if there are actual overlaps between these stacks
38+
if overlap_key in voxel_overlaps:
39+
_apply_vertex_sharing(all_meshes, origin_stack, surface_n, voxel_overlaps[overlap_key])
6340

6441

6542
def _apply_vertex_sharing(
6643
all_meshes: List[DualContouringMesh],
67-
origin_stack: int,
68-
destination_stack: int,
69-
overlap_data: dict,
70-
mesh_indices_offset: List[int]
44+
origin_mesh: int,
45+
destination_mesh: int,
46+
overlap_data: dict
7147
) -> None:
7248
"""
7349
Apply vertex sharing between origin and destination meshes based on overlap data.
7450
7551
Args:
7652
all_meshes: List of dual contouring meshes
77-
origin_stack: Stack index that serves as the source of vertices
78-
destination_stack: Stack index that receives vertices from origin
53+
origin_mesh: Stack index that serves as the source of vertices
54+
destination_mesh: Stack index that receives vertices from origin
7955
overlap_data: Dictionary containing indices and overlap information
8056
mesh_indices_offset: Starting mesh index for each stack
8157
"""
82-
origin_mesh_idx = mesh_indices_offset[origin_stack]
83-
destination_mesh_idx = mesh_indices_offset[destination_stack]
58+
# origin_mesh_idx = mesh_indices_offset[origin_stack]
59+
# destination_mesh_idx = mesh_indices_offset[destination_stack]
60+
origin_mesh_idx = origin_mesh
61+
destination_mesh_idx = destination_mesh
8462

8563
# Ensure mesh indices are valid
86-
if (origin_mesh_idx >= len(all_meshes) or
87-
destination_mesh_idx >= len(all_meshes)):
64+
if origin_mesh_idx >= len(all_meshes) or destination_mesh_idx >= len(all_meshes):
8865
return
8966

9067
# Apply the vertex sharing (same logic as original _f function)
@@ -97,20 +74,6 @@ def _apply_vertex_sharing(
9774
destination_mesh.vertices[indices_in_destination] = origin_mesh.vertices[indices_in_origin]
9875

9976

100-
def _f(all_meshes: list[DualContouringMesh], destination: int, origin: int, voxel_overlaps: dict):
101-
"""
102-
Legacy function - kept for backward compatibility.
103-
Consider using _apply_fault_relations_to_overlaps for new implementations.
104-
"""
105-
key = f"stack_{origin}_vs_stack_{destination}"
106-
if key in voxel_overlaps:
107-
all_meshes[destination].vertices[voxel_overlaps[key]["indices_in_stack_j"]] = all_meshes[origin].vertices[voxel_overlaps[key]["indices_in_stack_i"]]
108-
109-
# def _f(all_meshes: list[DualContouringMesh], destination: int, origin: int, voxel_overlaps: dict):
110-
# key = f"stack_{origin}_vs_stack_{destination}"
111-
# all_meshes[destination].vertices[voxel_overlaps[key]["indices_in_stack_j"]] = all_meshes[origin].vertices[voxel_overlaps[key]["indices_in_stack_i"]]
112-
113-
11477
def find_repeated_voxels_across_stacks(all_left_right_codes: List[np.ndarray]) -> dict:
11578
"""
11679
Find repeated voxels using NumPy operations - better for very large arrays.

gempy_engine/modules/dual_contouring/dual_contouring_interface.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from ...core.data.octree_level import OctreeLevel
1414
from ...core.data.options import MeshExtractionMaskingOptions
1515
from ...core.data.stack_relation_type import StackRelationType
16+
from ...core.data.stacks_structure import StacksStructure
1617

1718

1819
# region edges
@@ -199,11 +200,10 @@ def mask_generation(
199200

200201
# endregion
201202
def apply_faults_vertex_overlap(all_meshes: list[DualContouringMesh],
202-
data_descriptor: InputDataDescriptor,
203+
stack_structure: StacksStructure,
203204
left_right_per_mesh: list[np.ndarray]):
204-
faults_relations = data_descriptor.stack_structure.faults_relations
205205
voxel_overlaps = find_repeated_voxels_across_stacks(left_right_per_mesh)
206206

207207
if voxel_overlaps:
208208
print(f"Found voxel overlaps between stacks: {voxel_overlaps}")
209-
_apply_fault_relations_to_overlaps(all_meshes, faults_relations, voxel_overlaps, data_descriptor.stack_structure.n_stacks)
209+
_apply_fault_relations_to_overlaps(all_meshes, voxel_overlaps, stack_structure)

0 commit comments

Comments
 (0)