Skip to content

Commit c5c3c81

Browse files
committed
[ci] test v2m_cgalmesh, v2m_simplify and v2s in labeled volumn
1 parent 092edc2 commit c5c3c81

File tree

7 files changed

+53
-12
lines changed

7 files changed

+53
-12
lines changed

README.md

Lines changed: 2 additions & 2 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>, Edward Xu (2024) <xu.ed at northeastern.edu>
66
* License: GNU Public License V3 or later
7-
* Version: 0.2.3
7+
* Version: 0.2.4
88
* URL: [https://pypi.org/project/iso2mesh/](https://pypi.org/project/iso2mesh/)
99
* Github: [https://github.com/NeuroJSON/pyiso2mesh](https://github.com/NeuroJSON/pyiso2mesh)
1010

@@ -85,7 +85,7 @@ the built-in unit-test script inside the downloaded git repository by using this
8585
inside the `pyiso2mesh` root folder
8686

8787
```
88-
python -m unittest test.run_test
88+
python3 -m unittest test.run_test
8989
```
9090

9191

iso2mesh/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
barycentricgrid,
138138
)
139139

140-
__version__ = "0.2.3"
140+
__version__ = "0.2.4"
141141
__all__ = [
142142
"advancefront",
143143
"barycentricgrid",

iso2mesh/core.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@
3333
import re
3434
import platform
3535
import subprocess
36-
from iso2mesh.trait import surfinterior, surfseeds, surfedge, elemvolume, meshreorient
36+
from iso2mesh.trait import (
37+
surfinterior,
38+
surfseeds,
39+
surfedge,
40+
elemvolume,
41+
meshreorient,
42+
finddisconnsurf,
43+
)
3744
from iso2mesh.utils import *
3845
from iso2mesh.io import saveoff, readoff, saveinr, readtetgen, savesurfpoly, readmedit
39-
from iso2mesh.modify import meshcheckrepair, sortmesh
46+
from iso2mesh.modify import meshcheckrepair, sortmesh, meshresample, removeisolatedsurf
4047

4148
##====================================================================================
4249
## implementations
@@ -732,7 +739,7 @@ def binsurface(img, nface=3):
732739
)
733740

734741
# Compress the node indices
735-
maxid = elem.max() + 1
742+
maxid = np.max(elem) + 1
736743
nodemap = np.zeros(maxid, dtype=int)
737744
nodemap[elem.ravel(order="F")] = 1
738745
id = np.where(nodemap)[0]

iso2mesh/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def saveinr(vol, fname):
7777

7878
# Write the header and the volume data to the file
7979
fid.write(header.encode("ascii"))
80-
fid.write(vol.astype(dtype).tobytes())
80+
fid.write(np.transpose(vol, [2, 1, 0]).astype(dtype).tobytes())
8181

8282
# Close the file
8383
fid.close()

iso2mesh/modify.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import subprocess
4141
from iso2mesh.utils import *
4242
from iso2mesh.io import saveoff, readoff
43-
from iso2mesh.trait import meshconn, mesheuler
43+
from iso2mesh.trait import meshconn, mesheuler, finddisconnsurf
4444

4545
##====================================================================================
4646
## implementations
@@ -549,17 +549,17 @@ def removeisolatedsurf(v, f, maxdiameter):
549549
"""
550550
fc = finddisconnsurf(f)
551551
for i in range(len(fc)):
552-
xdia = v[fc[i], 0]
552+
xdia = v[fc[i] - 1, 0]
553553
if np.max(xdia) - np.min(xdia) <= maxdiameter:
554554
fc[i] = []
555555
continue
556556

557-
ydia = v[fc[i], 1]
557+
ydia = v[fc[i] - 1, 1]
558558
if np.max(ydia) - np.min(ydia) <= maxdiameter:
559559
fc[i] = []
560560
continue
561561

562-
zdia = v[fc[i], 2]
562+
zdia = v[fc[i] - 1, 2]
563563
if np.max(zdia) - np.min(zdia) <= maxdiameter:
564564
fc[i] = []
565565
continue

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.2.3",
9+
version="0.2.4",
1010
license='GPLv3+',
1111
description="Image-based 3D Surface and Volumetric Mesh Generator",
1212
long_description=readme,

test/run_test.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,14 @@ def __init__(self, *args, **kwargs):
933933
self.im = np.zeros((3, 3, 3))
934934
self.im[1, 1, 1:3] = 1
935935

936+
xi, yi, zi = np.meshgrid(
937+
np.arange(0, 61), np.arange(0, 58), np.arange(0, 55), indexing="ij"
938+
)
939+
dist = (xi - 30) ** 2 + (yi - 30) ** 2 + (zi - 30) ** 2
940+
self.mask = dist < 400
941+
self.mask = self.mask.astype(float)
942+
self.mask[25:35, 25:35, :] = 2
943+
936944
def test_binsurface(self):
937945
no, fc = binsurface(self.im)
938946
expected_fc = [
@@ -1005,6 +1013,32 @@ def test_cgalv2m(self):
10051013
self.assertEqual(removedupelem(fc[:, :3]).shape[0], 0)
10061014
self.assertAlmostEqual(sum(elemvolume(no[:, :3], el[:, :4])), 0.7455, 3)
10071015

1016+
def test_v2s_label(self):
1017+
no, fc, _, _ = v2s(self.mask, 0.04, 1)
1018+
self.assertAlmostEqual(
1019+
sum(elemvolume(no[:, :3], fc[:, :3])) * 0.001, 6.356848339883229, 3
1020+
)
1021+
1022+
def test_v2m_cgalmesh(self):
1023+
no, el, _ = v2m(
1024+
self.mask.astype(np.uint8),
1025+
[],
1026+
{"radbound": 1, "distbound": 0.5},
1027+
5,
1028+
"cgalmesh",
1029+
)
1030+
self.assertAlmostEqual(
1031+
sum(elemvolume(no[:, :3], el[:, :4])) * 0.0001, 3.4780013268627226, 2
1032+
)
1033+
1034+
def test_v2m_simplify(self):
1035+
no, el, _ = v2m(
1036+
self.mask.astype(np.uint8), 1.5, {"keepratio": 0.5}, 10, "simplify"
1037+
)
1038+
self.assertAlmostEqual(
1039+
sum(elemvolume(no[:, :3], el[:, :4])), 5456.390624999979, 0
1040+
)
1041+
10081042

10091043
if __name__ == "__main__":
10101044
unittest.main()

0 commit comments

Comments
 (0)