Skip to content

Commit cf2f359

Browse files
committed
[port] test surf2vol, surf2volz, s2v, bump version to 0.3.8
1 parent 2f6e21a commit cf2f359

File tree

5 files changed

+51
-19
lines changed

5 files changed

+51
-19
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
* **Copyright**: (C) Qianqian Fang (2024-2025) <q.fang at neu.edu>
66
* **License**: GNU Public License V3 or later
7-
* **Version**: 0.3.7
7+
* **Version**: 0.3.8
88
* **URL**: [https://pypi.org/project/iso2mesh/](https://pypi.org/project/iso2mesh/)
99
* **Homepage**: [https://iso2mesh.sf.net](https://iso2mesh.sf.net)
1010
* **Github**: [https://github.com/NeuroJSON/pyiso2mesh](https://github.com/NeuroJSON/pyiso2mesh)
@@ -187,21 +187,21 @@ tracked in https://github.com/NeuroJSON/pyiso2mesh/issues/1
187187
|`v2m.m` | ✅ tested | |`saveasc.m` | ⭕️ tested |
188188
|`v2s.m` | ✅ tested | |`savedxf.m` | ⭕️ tested |
189189
|`s2m.m` | ✅ tested | |`savestl.m` | ⭕️ tested |
190-
|`s2v.m` | ⭕️ tested | |`savebinstl.m` | ⭕️ tested |
190+
|`s2v.m` | tested | |`savebinstl.m` | ⭕️ tested |
191191
|`m2v.m` | ⭕️ tested | |`saveinr.m` | ⭕️ tested |
192192
|`sms.m` | ✅ tested | |`saveoff.m` | ✅ tested |
193193
| > Streamlined mesh generation| | | ⭕️ `savesmf.m` | ⭕️ tested |
194194
|`vol2mesh.m` | ✅ tested | |`savesurfpoly.m` | ✅ tested |
195195
|`vol2surf.m` | ✅ tested | | ⭕️ `savegts.m` | ⭕️ tested |
196196
|`surf2mesh.m` | ✅ tested | | ⭕️ `readgts.m` | ⭕️ tested |
197-
|`surf2vol.m` | ⭕️ tested | | ⭕️ `savemsh.m` | ⭕️ tested |
197+
|`surf2vol.m` | tested | | ⭕️ `savemsh.m` | ⭕️ tested |
198198
|`mesh2vol.m` | ⭕️ tested | | ⭕️ `savevrml.m` | ⭕️ tested |
199199
| > Iso2mesh main function backend| | |`readasc.m` | ⭕️ tested |
200200
|`binsurface.m` | ✅ tested | | ⭕️ `readinr.m` | ⭕️ tested |
201201
|`cgalv2m.m` | ✅ tested | |`readmedit.m` | ⭕️ tested |
202202
|`cgals2m.m` | ⭕️ tested | |`readoff.m` | ✅ tested |
203203
|`vol2restrictedtri.m` | ✅ tested | | ⭕️ `readsmf.m` | ⭕️ tested |
204-
|`surf2volz.m` | ⭕️ tested | |`readtetgen.m` | ✅ tested |
204+
|`surf2volz.m` | tested | |`readtetgen.m` | ✅ tested |
205205
|`mesh2mask.m` | ⭕️ tested | |`deletemeshfile.m` | ✅ tested |
206206
| > Iso2mesh primitive meshing| | |`mcpath.m` | ✅ tested |
207207
|`meshabox.m` | ✅ tested | |`mwpath.m` | ✅ tested |
@@ -273,7 +273,7 @@ tracked in https://github.com/NeuroJSON/pyiso2mesh/issues/1
273273
| ⭕️ `closestnode.m` | ⭕️ tested | | ⭕️ `soa2aos.m` | ⭕️ tested |
274274
| > Mesh resampling and optimization| |
275275
|`meshresample.m` | ✅ tested |
276-
|`remeshsurf.m` | ⭕️ tested |
276+
|`remeshsurf.m` | tested |
277277
|`smoothsurf.m` | ✅ tested |
278278
|`sortmesh.m` | ⭕️ tested |
279279
|`mergemesh.m` | ⭕️ tested |

iso2mesh/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
regpt2surf,
158158
)
159159

160-
__version__ = "0.3.7"
160+
__version__ = "0.3.8"
161161
__all__ = [
162162
"advancefront",
163163
"barycentricgrid",

iso2mesh/core.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,15 @@ def s2m(
200200
return node, elem, face
201201

202202

203-
def s2v(node, face, div=50, *args):
203+
def s2v(node, face, div=50, **kwargs):
204204
"""
205205
Convert a surface mesh to a volumetric binary image.
206206
207207
Parameters:
208208
node : array-like, the vertices of the triangular surface (Nx3 for x, y, z)
209209
face : array-like, the triangle node indices (Mx3, each row is a triangle)
210210
div : int, division number along the shortest edge of the mesh (resolution)
211-
*args : additional arguments for the surf2vol function
211+
kwargs : additional arguments for the surf2vol function
212212
213213
Returns:
214214
img : volumetric binary image
@@ -232,9 +232,9 @@ def s2v(node, face, div=50, *args):
232232
yi = np.arange(p0[1] - dx, p1[1] + dx, dx)
233233
zi = np.arange(p0[2] - dx, p1[2] + dx, dx)
234234

235-
img, v2smap = surf2vol(node, face, xi, yi, zi, *args)
235+
img = surf2vol(node, face, xi, yi, zi, **kwargs)
236236

237-
return img, v2smap
237+
return img
238238

239239

240240
def vol2mesh(img, ix, iy, iz, opt, maxvol, dofix, method="cgalsurf", isovalues=None):
@@ -586,7 +586,10 @@ def surf2volz(node, face, xi, yi, zi):
586586
maxz = np.max(node[:, 2])
587587

588588
# Determine the z index range
589-
iz = np.histogram([minz, maxz], bins=zi)[0]
589+
iz, _ = np.histogram(
590+
[minz, maxz],
591+
bins=np.append(zi - np.diff(zi)[0] / 2, zi[-1] + np.diff(zi)[-1] / 2),
592+
)
590593
hz = np.nonzero(iz)[0]
591594
iz = np.arange(hz[0], min(len(zi), hz[-1] + 1))
592595

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
setup(
77
name="iso2mesh",
88
packages=["iso2mesh"],
9-
version="0.3.7",
9+
version="0.3.8",
1010
license="GPLv3+",
1111
description="One-liner 3D Surface and Tetrahedral Mesh Generation Toolbox",
1212
long_description=readme,

test/run_test.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ def __init__(self, *args, **kwargs):
10701070
self.mask = self.dist < 400
10711071
self.mask = self.mask.astype(float)
10721072
self.mask[25:35, 25:35, :] = 2
1073+
self.no, self.fc, _, _ = v2s(self.dist < 100, 0.5, 2)
10731074

10741075
self.plcno = (
10751076
np.array(
@@ -1221,15 +1222,43 @@ def test_remeshsurf(self):
12211222
no, fc, _, _ = v2s(self.dist, 100, 2)
12221223
no1, fc1 = remeshsurf(no, fc, 1)
12231224
self.assertAlmostEqual(
1224-
sum(elemvolume(no[:, :3], fc[:, :3])) * 0.0001, 2.034550093898604, 4
1225+
sum(elemvolume(no[:, :3], fc[:, :3])) * 0.0001, 2.034550093898604, 3
12251226
)
12261227

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)
1228+
def test_surf2volz(self):
1229+
vol = surf2volz(
1230+
self.no,
1231+
self.fc,
1232+
np.arange(19, 42, 1),
1233+
np.arange(19, 42, 1),
1234+
np.arange(19, 42, 1),
1235+
)
1236+
self.assertAlmostEqual(np.sum(vol.astype(np.float32)) * 0.001, 1.099, 2)
1237+
1238+
def test_surf2vol(self):
1239+
vol = surf2vol(
1240+
self.no,
1241+
self.fc,
1242+
np.arange(19, 42, 1),
1243+
np.arange(19, 42, 1),
1244+
np.arange(19, 42, 1),
1245+
)
1246+
self.assertAlmostEqual(np.sum(vol.astype(np.float32)) * 0.001, 1.704, 2)
1247+
1248+
def test_surf2vol_fill(self):
1249+
vol = surf2vol(
1250+
self.no,
1251+
self.fc,
1252+
np.arange(19, 42, 1),
1253+
np.arange(19, 42, 1),
1254+
np.arange(19, 42, 1),
1255+
fill=1,
1256+
)
1257+
self.assertAlmostEqual(np.sum(vol.astype(np.float32)) * 0.001, 4.903, 2)
1258+
1259+
def test_s2v(self):
1260+
vol = s2v(self.no, self.fc, fill=1)
1261+
self.assertAlmostEqual(np.sum(vol.astype(np.float32)) * 0.0001, 7.8651, 2)
12331262

12341263

12351264
@unittest.skipIf(

0 commit comments

Comments
 (0)