Skip to content

Commit ff794b8

Browse files
committed
[OPT] Simplify triangle order flipping logic for normals
1 parent 9fc3ee4 commit ff794b8

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

gempy_engine/modules/dual_contouring/fancy_triangulation.py

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -231,36 +231,25 @@ def check_voxels_exist_next_to_edge(coord_col, edge_vector, _left_right_array_ac
231231
raise ValueError("n must be smaller than 12")
232232

233233
# flip triangle order if normal is negative
234-
if False:
235-
indices = BackendTensor.tfnp.stack([x[normal >= 0], y[normal >= 0], z[normal >= 0]]).T
236-
flipped_indices = BackendTensor.tfnp.stack(
237-
[
238-
x[normal < 0],
239-
y[normal < 0],
240-
z[normal < 0]]).T[:, [0, 2, 1]
241-
]
242-
indices = BackendTensor.tfnp.stack([indices, flipped_indices])
243-
else:
244-
# flip triangle order if normal is negative
245-
# Create masks for positive and negative normals
246-
positive_mask = normal >= 0
247-
negative_mask = normal < 0
248-
249-
# Extract indices for positive normals (keep original order)
250-
x_pos = x[positive_mask]
251-
y_pos = y[positive_mask]
252-
z_pos = z[positive_mask]
253-
254-
# Extract indices for negative normals (flip order: x, z, y instead of x, y, z)
255-
x_neg = x[negative_mask]
256-
y_neg = y[negative_mask]
257-
z_neg = z[negative_mask]
258-
259-
# Combine all indices
260-
all_x = BackendTensor.tfnp.concatenate([x_pos, x_neg], axis=0)
261-
all_y = BackendTensor.tfnp.concatenate([y_pos, z_neg], axis=0) # Note: z_neg for flipped triangles
262-
all_z = BackendTensor.tfnp.concatenate([z_pos, y_neg], axis=0) # Note: y_neg for flipped triangles
263-
264-
# Stack into final indices array
265-
indices = BackendTensor.tfnp.stack([all_x, all_y, all_z], axis=1)
234+
# Create masks for positive and negative normals
235+
positive_mask = normal >= 0
236+
negative_mask = normal < 0
237+
238+
# Extract indices for positive normals (keep original order)
239+
x_pos = x[positive_mask]
240+
y_pos = y[positive_mask]
241+
z_pos = z[positive_mask]
242+
243+
# Extract indices for negative normals (flip order: x, z, y instead of x, y, z)
244+
x_neg = x[negative_mask]
245+
y_neg = y[negative_mask]
246+
z_neg = z[negative_mask]
247+
248+
# Combine all indices
249+
all_x = BackendTensor.tfnp.concatenate([x_pos, x_neg], axis=0)
250+
all_y = BackendTensor.tfnp.concatenate([y_pos, z_neg], axis=0) # Note: z_neg for flipped triangles
251+
all_z = BackendTensor.tfnp.concatenate([z_pos, y_neg], axis=0) # Note: y_neg for flipped triangles
252+
253+
# Stack into final indices array
254+
indices = BackendTensor.tfnp.stack([all_x, all_y, all_z], axis=1)
266255
return indices

0 commit comments

Comments
 (0)