@@ -22,16 +22,16 @@ def set_meshes_with_marching_cubes(model: GeoModel) -> None:
22
22
If the model solutions do not contain dense grid data.
23
23
"""
24
24
# Verify that solutions contain dense grid data
25
- if ( model .solutions is None or
26
- model .solutions . block_solution_type != RawArraysSolution . BlockSolutionType . DENSE_GRID ) :
25
+ solution_not_having_dense : bool = model .solutions . block_solution_type != RawArraysSolution . BlockSolutionType . DENSE_GRID
26
+ if model .solutions is None or solution_not_having_dense :
27
27
raise ValueError ("Model solutions must contain dense grid data for mesh extraction." )
28
-
28
+
29
29
regular_grid : RegularGrid = model .grid .regular_grid
30
30
structural_groups : list [StructuralGroup ] = model .structural_frame .structural_groups
31
31
32
32
if not model .solutions .octrees_output or not model .solutions .octrees_output [0 ].outputs_centers :
33
33
raise ValueError ("No interpolation outputs available for mesh extraction." )
34
-
34
+
35
35
output_lvl0 : list [InterpOutput ] = model .solutions .octrees_output [0 ].outputs_centers
36
36
37
37
# TODO: How to get this properly in gempy
@@ -50,26 +50,12 @@ def set_meshes_with_marching_cubes(model: GeoModel) -> None:
50
50
scalar_values = model .solutions .raw_arrays .scalar_field_at_surface_points
51
51
52
52
# TODO: Here I just get my own masks, cause the gempy masks dont work as expected
53
- masks = []
54
- masks .append (np .ones_like (model .solutions .raw_arrays .scalar_field_matrix [0 ].reshape (model .grid .regular_grid .resolution ),
55
- dtype = bool ))
56
- for idx in lith_group_indices :
57
- mask = model .solutions .raw_arrays .scalar_field_matrix [idx ].reshape (model .grid .regular_grid .resolution ) <= \
58
- scalar_values [idx ][- 1 ]
59
-
60
- masks .append (mask )
53
+ masks = _get_masking_arrays (lith_group_indices , model , scalar_values )
61
54
62
55
# TODO: Attribute of element.scalar_field was None, changed it to scalar field value of that element
63
56
# This should probably be done somewhere else and maybe renamed to scalar_field_value?
64
57
# This is just the most basic solution to be clear what I did
65
- counter = 0
66
- for e , structural_group in enumerate (structural_groups ):
67
- if e >= len (output_lvl0 ):
68
- continue
69
-
70
- for element in structural_group .elements :
71
- element .scalar_field = model .solutions .scalar_field_at_surface_points [counter ]
72
- counter += 1
58
+ _set_scalar_field_to_element (model , output_lvl0 , structural_groups )
73
59
74
60
# Trying to use the exiting gempy masks
75
61
# masks = []
@@ -96,7 +82,7 @@ def set_meshes_with_marching_cubes(model: GeoModel) -> None:
96
82
if structural_group .is_fault :
97
83
mask = np .ones_like (scalar_field , dtype = bool )
98
84
else :
99
- mask = masks [non_fault_counter ] # TODO: I need the entry without faults here
85
+ mask = masks [non_fault_counter ] # TODO: I need the entry without faults here
100
86
non_fault_counter += 1
101
87
102
88
for element in structural_group .elements :
@@ -108,9 +94,34 @@ def set_meshes_with_marching_cubes(model: GeoModel) -> None:
108
94
)
109
95
110
96
111
- def extract_mesh_for_element (structural_element : StructuralElement ,
112
- regular_grid : RegularGrid ,
113
- scalar_field : np .ndarray ,
97
+ # TODO: This should be set somewhere else
98
+ def _set_scalar_field_to_element (model , output_lvl0 , structural_groups ):
99
+ counter = 0
100
+ for e , structural_group in enumerate (structural_groups ):
101
+ if e >= len (output_lvl0 ):
102
+ continue
103
+
104
+ for element in structural_group .elements :
105
+ element .scalar_field = model .solutions .scalar_field_at_surface_points [counter ]
106
+ counter += 1
107
+
108
+
109
+ # TODO: This should be set somewhere else
110
+ def _get_masking_arrays (lith_group_indices , model , scalar_values ):
111
+ masks = []
112
+ masks .append (np .ones_like (model .solutions .raw_arrays .scalar_field_matrix [0 ].reshape (model .grid .regular_grid .resolution ),
113
+ dtype = bool ))
114
+ for idx in lith_group_indices :
115
+ mask = model .solutions .raw_arrays .scalar_field_matrix [idx ].reshape (model .grid .regular_grid .resolution ) <= \
116
+ scalar_values [idx ][- 1 ]
117
+
118
+ masks .append (mask )
119
+ return masks
120
+
121
+
122
+ def extract_mesh_for_element (structural_element : StructuralElement ,
123
+ regular_grid : RegularGrid ,
124
+ scalar_field : np .ndarray ,
114
125
mask : Optional [np .ndarray ] = None ) -> None :
115
126
"""Extract a mesh for a single structural element using marching cubes.
116
127
@@ -132,12 +143,12 @@ def extract_mesh_for_element(structural_element: StructuralElement,
132
143
spacing = (regular_grid .dx , regular_grid .dy , regular_grid .dz ),
133
144
mask = mask
134
145
)
135
-
146
+
136
147
# Adjust vertices to correct coordinates in the model's extent
137
148
verts = (verts + [regular_grid .extent [0 ],
138
149
regular_grid .extent [2 ],
139
150
regular_grid .extent [4 ]])
140
151
141
152
# Store mesh in the structural element
142
153
structural_element .vertices = verts
143
- structural_element .edges = faces
154
+ structural_element .edges = faces
0 commit comments