Skip to content

Commit bfc6e69

Browse files
committed
[brain1020] further improving brain1020 robustness
1 parent 5eae75a commit bfc6e69

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

iso2mesh/brain2mesh.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,6 @@ def intriangulation(
765765
TESTP = testp.copy()
766766

767767
for n in range(1, heavytest + 2): # MATLAB: for n = 1:heavytest + 1
768-
769768
# Randomize
770769
if n > 1:
771770
v = np.random.rand(1, 3)
@@ -879,7 +878,6 @@ def VOXELISEinternal(
879878
nm = meshXYZmin.shape[0]
880879

881880
for loop in range(len(OUTPUT)):
882-
883881
nf = 0
884882
# - 1a - Find which mesh facets could possibly be crossed by the ray:
885883
# possibleCROSSLISTy = find( meshXYZmin(:,2)<=testy(loop) & meshXYZmax(:,2)>=testy(loop) );
@@ -899,7 +897,6 @@ def VOXELISEinternal(
899897
if (
900898
len(possibleCROSSLIST) != 0
901899
): # Only continue the analysis if some nearby facets were actually identified
902-
903900
# - 2 - For each facet, check if the ray really does cross the facet rather than just passing it close-by:
904901

905902
# GENERAL METHOD:
@@ -914,7 +911,6 @@ def VOXELISEinternal(
914911
# 2. If a ray crosses exactly on a vertex, this is also taken into account.
915912

916913
for loopCHECKFACET in possibleCROSSLIST:
917-
918914
# Check if ray crosses the facet. This method is much (>>10 times) faster than using the built-in function 'inpolygon'.
919915
# Taking each edge of the facet in turn, check if the ray is on the same side as the opposing vertex. If so, let testVn=1
920916

@@ -1063,7 +1059,6 @@ def VOXELISEinternal(
10631059
# - 3 - Find the z coordinate of the locations where the ray crosses each facet:
10641060
gridCOzCROSS = np.zeros(nf)
10651061
for i, loopFINDZ in enumerate(facetCROSSLIST):
1066-
10671062
# METHOD:
10681063
# 1. Define the equation describing the plane of the facet. For a
10691064
# more detailed outline of the maths, see:
@@ -1152,7 +1147,6 @@ def VOXELISEinternal(
11521147
if (
11531148
len(gridCOzCROSS) % 2 == 0
11541149
): # Only rays which cross an even number of facets are voxelised
1155-
11561150
for loopASSIGN in range(1, len(gridCOzCROSS) // 2 + 1):
11571151
voxelsINSIDE = (
11581152
testz[loop] > gridCOzCROSS[2 * loopASSIGN - 2]
@@ -1321,7 +1315,6 @@ def brain1020(
13211315
(isinstance(initpoints, dict) and "iz" not in initpoints)
13221316
or (isinstance(initpoints, np.ndarray) and initpoints.shape[0] == 3)
13231317
):
1324-
13251318
if isinstance(initpoints, dict):
13261319
nz = np.array(initpoints["nz"]).flatten()
13271320
lpa = np.array(initpoints["lpa"]).flatten()
@@ -1454,7 +1447,6 @@ def brain1020(
14541447

14551448
# Find cz that bisects cm and sm curves within a tolerance, using UI 10-10 approach
14561449
while np.linalg.norm(initpoints[4, :] - lastcz) > tol and cziter < maxcziter:
1457-
14581450
# Step 1: nz, iz and cz0 to determine saggital reference curve
14591451
nsagg, curveloop, _ = slicesurf(node, face, initpoints[[0, 1, 4], :], full=True)
14601452
nsagg = nsagg[maxloop(curveloop) - 1, :]
@@ -1523,7 +1515,7 @@ def brain1020(
15231515
landmarks["cm"][0, :],
15241516
landmarks["sm"][-1, :],
15251517
perc2 * 2,
1526-
0,
1518+
dosimplify,
15271519
maxloop=1,
15281520
)
15291521

@@ -1535,7 +1527,7 @@ def brain1020(
15351527
landmarks["cm"][-1, :],
15361528
landmarks["sm"][-1, :],
15371529
perc2 * 2,
1538-
0,
1530+
dosimplify,
15391531
maxloop=1,
15401532
)
15411533

@@ -1663,7 +1655,7 @@ def brain1020(
16631655
landmarks["sm"][idxcz - 1 - i, :],
16641656
landmarks["aar"][i - 1, :],
16651657
step,
1666-
0,
1658+
dosimplify,
16671659
maxloop=1,
16681660
)
16691661

@@ -1715,7 +1707,7 @@ def brain1020(
17151707
landmarks["sm"][idxcz - 1 + i, :],
17161708
landmarks["apr"][i - 1, :],
17171709
step,
1718-
0,
1710+
dosimplify,
17191711
maxloop=1,
17201712
)
17211713

@@ -1758,7 +1750,7 @@ def brain1020(
17581750
landmarks["lpa"],
17591751
landmarks["iz"],
17601752
perc2 * 2,
1761-
0,
1753+
dosimplify,
17621754
maxloop=1,
17631755
)
17641756
(
@@ -1773,7 +1765,7 @@ def brain1020(
17731765
landmarks["rpa"],
17741766
landmarks["iz"],
17751767
perc2 * 2,
1776-
0,
1768+
dosimplify,
17771769
maxloop=1,
17781770
)
17791771

iso2mesh/line.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ def maxloop(curveloop: np.ndarray) -> np.ndarray:
383383

384384
newloop = curveloop.copy()
385385

386+
if (len(curveloop) > 0) and (not np.isnan(curveloop[-1])):
387+
curveloop = np.append(curveloop, np.nan)
388+
386389
# Find array positions where nan occurs - equivalent to find(isnan(curveloop))
387390
# loopend contains Python 0-based positions in the curveloop array where NaN appears
388391
loopend = np.where(np.isnan(curveloop))[0]

0 commit comments

Comments
 (0)