Skip to content

Commit 2f6e21a

Browse files
committed
[port] tested surf2vol and remeshsurf
1 parent a57ff63 commit 2f6e21a

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

iso2mesh/core.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ def surf2volz(node, face, xi, yi, zi):
602602
enum = bcutedges.shape[0]
603603

604604
for j in range(enum):
605-
e0 = bcutpos[bcutedges[j, 0], :2]
606-
e1 = bcutpos[bcutedges[j, 1], :2]
605+
e0 = bcutpos[bcutedges[j, 0] - 1, :2]
606+
e1 = bcutpos[bcutedges[j, 1] - 1, :2]
607607
length = np.ceil(np.sum(np.abs(e1 - e0)) / (np.abs(dx) + np.abs(dy))) + 1
608608
dd = (e1 - e0) / length
609609

@@ -648,7 +648,7 @@ def surf2vol(node, face, xi, yi, zi, **kwargs):
648648

649649
opt = kwargs
650650
label = opt.get("label", 0)
651-
elabel = 1
651+
elabel = np.array([1], dtype=np.int32)
652652

653653
if face.shape[1] >= 4:
654654
elabel = np.unique(face[:, -1])
@@ -671,7 +671,9 @@ def surf2vol(node, face, xi, yi, zi, **kwargs):
671671

672672
im = surf2volz(node[:, :3], fc[:, :3], xi, yi, zi)
673673
im |= np.moveaxis(surf2volz(node[:, [2, 0, 1]], fc[:, :3], zi, xi, yi), 0, 2)
674-
im |= np.moveaxis(surf2volz(node[:, [1, 2, 0]], fc[:, :3], yi, zi, xi), 0, 1)
674+
im |= np.moveaxis(
675+
surf2volz(node[:, [1, 2, 0]], fc[:, :3], yi, zi, xi), [0, 1], [-2, -1]
676+
)
675677

676678
if opt.get("fill", 0) or label:
677679
im = binary_fill_holes(im)
@@ -680,15 +682,15 @@ def surf2vol(node, face, xi, yi, zi, **kwargs):
680682

681683
img = np.maximum(im.astype(img.dtype), img)
682684

683-
v2smap = None
684685
if "v2smap" in kwargs:
685686
dlen = np.abs([xi[1] - xi[0], yi[1] - yi[0], zi[1] - zi[0]])
686687
offset = np.min(node, axis=0)
687688
v2smap = np.eye(4)
688689
v2smap[:3, :3] = np.diag(np.abs(dlen))
689690
v2smap[:3, 3] = offset
691+
return img.astype(np.uint8), v2smap
690692

691-
return img, v2smap
693+
return img.astype(np.uint8)
692694

693695

694696
def binsurface(img, nface=3):
@@ -1205,13 +1207,13 @@ def remeshsurf(node, face, opt):
12051207
dx = opt / 4
12061208

12071209
x_range = np.arange(p0[0] - dx, p1[0] + dx, dx)
1208-
y_range = np.arange(p0[1] - dx, p1[1] + dx)
1209-
z_range = np.arange(p0[2] - dx, p1[2] + dx)
1210+
y_range = np.arange(p0[1] - dx, p1[1] + dx, dx)
1211+
z_range = np.arange(p0[2] - dx, p1[2] + dx, dx)
12101212

12111213
img = surf2vol(node, face, x_range, y_range, z_range)
12121214

12131215
# Compute surface edges
1214-
eg = surfedge(face)
1216+
eg = surfedge(face)[0]
12151217

12161218
closesize = 0
12171219
if eg.size > 0 and isinstance(opt, dict):

iso2mesh/modify.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,12 @@ def qmeshcut(elem, node, value, cutat):
208208
else:
209209
dist = eval(cutat[0]) - cutat[1]
210210
asign = np.where(dist <= 0, -1, 1)
211-
elif not isinstance(cutat, (int, float)) and (len(cutat) == 9 or len(cutat) == 4):
212-
if len(cutat) == 9:
213-
a, b, c, d = getplanefrom3pt(np.array(cutat).reshape(3, 3))
211+
elif not isinstance(cutat, (int, float)) and isinstance(cutat, (list, np.ndarray)):
212+
cutat = np.array(cutat)
213+
if cutat.size == 9:
214+
a, b, c, d = getplanefrom3pt(cutat.reshape(3, 3))
214215
else:
215-
a, b, c, d = cutat
216+
a, b, c, d = cutat.tolist()
216217
dist = np.dot(node, np.array([a, b, c])) + d
217218
asign = np.where(dist >= 0, 1, -1)
218219
else:
@@ -261,7 +262,7 @@ def qmeshcut(elem, node, value, cutat):
261262

262263
if value.shape[0] == node.shape[0]:
263264
if isinstance(cutat, (str, list)) or (
264-
not isinstance(cutat, (int, float)) and len(cutat) in [4, 9]
265+
not isinstance(cutat, (int, float)) and np.array(cutat).size in [4, 9]
265266
):
266267
cutvalue = (
267268
value[edges[cutedges, 0] - 1] * cutweight[:, [1]].squeeze()

test/run_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,20 @@ def test_s2m_plc(self):
12171217
sum(elemvolume(no[:, :3], fc[:, :3])), 412.8904758569056, 4
12181218
)
12191219

1220+
def test_remeshsurf(self):
1221+
no, fc, _, _ = v2s(self.dist, 100, 2)
1222+
no1, fc1 = remeshsurf(no, fc, 1)
1223+
self.assertAlmostEqual(
1224+
sum(elemvolume(no[:, :3], fc[:, :3])) * 0.0001, 2.034550093898604, 4
1225+
)
1226+
1227+
# def test_surf2vol(self):
1228+
# no, fc, _, _ = v2s(self.dist < 100, 0.5, 2)
1229+
# vol = surf2vol(
1230+
# no, fc, np.arange(19, 42, 1), np.arange(19, 42, 1), np.arange(19, 42, 1)
1231+
# )
1232+
# self.assertAlmostEqual(np.sum(vol.astype(np.float32)), 2.034550093898604, 4)
1233+
12201234

12211235
@unittest.skipIf(
12221236
(int(mpl_ver[0]), int(mpl_ver[1])) < (3, 6), "Requires Matplotlib 3.6 or higher"

0 commit comments

Comments
 (0)