Skip to content

Commit 9fc478d

Browse files
committed
[feat] tested direct PLC meshing, fix plotedges error
1 parent fa99afc commit 9fc478d

File tree

7 files changed

+74
-21
lines changed

7 files changed

+74
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
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.3.0
7+
* Version: 0.3.1
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

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.3.0"
140+
__version__ = "0.3.1"
141141
__all__ = [
142142
"advancefront",
143143
"barycentricgrid",

iso2mesh/core.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@
4343
)
4444
from iso2mesh.utils import *
4545
from iso2mesh.io import saveoff, readoff, saveinr, readtetgen, savesurfpoly, readmedit
46-
from iso2mesh.modify import meshcheckrepair, sortmesh, meshresample, removeisolatedsurf
46+
from iso2mesh.modify import (
47+
meshcheckrepair,
48+
sortmesh,
49+
meshresample,
50+
removeisolatedsurf,
51+
removeisolatednode,
52+
)
4753

4854
##====================================================================================
4955
## implementations

iso2mesh/io.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -567,20 +567,21 @@ def savesurfpoly(v, f, holelist, regionlist, p0, p1, fname, forcebox=None):
567567
np.isnan(plc)
568568
): # we use nan to separate outer contours and holes
569569
holeid = np.where(np.isnan(plc))[0]
570+
plc = np.array(plc, dtype=np.int32)
570571
if faceid > 0:
571572
fp.write(
572573
"{} {} {}\n{}".format(
573-
len(holeid) + 1, len(holeid), faceid, holeid[0] - 1
574+
len(holeid) + 1, len(holeid), faceid, holeid[0]
574575
)
575576
)
576577
else:
577578
fp.write(
578579
"{} {}\n{}".format(
579-
len(holeid) + 1, len(holeid), holeid[0] - 1
580+
len(holeid) + 1, len(holeid), holeid[0]
580581
)
581582
)
582583
fp.write(
583-
"\t{}".format("\t".join(map(str, plc[: holeid[0] - 1] - 1)))
584+
"\t{}".format("\t".join(map(str, plc[: holeid[0]] - 1)))
584585
)
585586
fp.write("\t1\n")
586587
for j in range(len(holeid)):
@@ -608,24 +609,35 @@ def savesurfpoly(v, f, holelist, regionlist, p0, p1, fname, forcebox=None):
608609
for j in range(len(holeid)):
609610
if j == len(holeid) - 1:
610611
fp.write(
611-
"{} {:.16f} {:.16f} {:.16f}\n".format(
612-
j,
613-
np.mean(
614-
node[plc[holeid[j] + 1 :] - 1, 1:4], axis=0
612+
"{} {}\n".format(
613+
j + 1,
614+
"".join(
615+
"{:.16f} ".format(x)
616+
for x in np.mean(
617+
node[plc[holeid[j] + 1 :] - 1, 1:4],
618+
axis=0,
619+
)
615620
),
616621
)
617622
)
618623
else:
619624
fp.write(
620-
"{} {:.16f} {:.16f} {:.16f}\n".format(
621-
j,
622-
np.mean(
623-
node[
624-
plc[holeid[j] + 1 : holeid[j + 1] - 1]
625-
- 1,
626-
1:4,
627-
],
628-
axis=0,
625+
"{} {}\n".format(
626+
j + 1,
627+
"".join(
628+
"{:.16f} ".format(x)
629+
for x in np.mean(
630+
node[
631+
plc[
632+
holeid[j]
633+
+ 1 : holeid[j + 1]
634+
- 1
635+
]
636+
- 1,
637+
1:4,
638+
],
639+
axis=0,
640+
)
629641
),
630642
)
631643
)

iso2mesh/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def plotsurf(node, face, *args, **kwargs):
4848
kwargs["cmap"] = plt.get_cmap("jet")
4949

5050
if isinstance(face, list): # polyhedral facets
51-
5251
newsurf = {}
5352
colormap = []
5453

@@ -88,6 +87,7 @@ def plotsurf(node, face, *args, **kwargs):
8887

8988
elif face.shape[1] == 2:
9089
h = plotedges(node, face, *args, **kwargs)
90+
return h
9191
elif face.shape[1] == 4:
9292
tag = face[:, 3]
9393
types = np.unique(tag)

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

test/run_test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,34 @@ def __init__(self, *args, **kwargs):
945945
self.mask = self.mask.astype(float)
946946
self.mask[25:35, 25:35, :] = 2
947947

948+
self.plcno = (
949+
np.array(
950+
[
951+
[0, 0, 0],
952+
[0, 1, 0],
953+
[1, 1, 0],
954+
[1, 0, 0],
955+
[0.5, 0.5, 1],
956+
[0.2, 0.2, 0],
957+
[0.2, 0.8, 0],
958+
[0.8, 0.8, 0],
959+
[0.8, 0.2, 0],
960+
]
961+
)
962+
* 10
963+
)
964+
self.plcfc = [
965+
[1, 2, 5],
966+
[2, 3, 5],
967+
[3, 4, 5],
968+
[4, 1, 5],
969+
[1, 2, 3, 4, np.nan, 9, 8, 7, 6],
970+
[6, 7, 5],
971+
[7, 8, 5],
972+
[8, 9, 5],
973+
[9, 6, 5],
974+
]
975+
948976
def test_binsurface(self):
949977
no, fc = binsurface(self.im)
950978
expected_fc = [
@@ -1054,6 +1082,13 @@ def test_v2m_simplify(self):
10541082
sum(elemvolume(no[:, :3], el[:, :4])) * 0.001, 5.456390624999979, 2
10551083
)
10561084

1085+
def test_s2m_plc(self):
1086+
no, el, fc = s2m(self.plcno, self.plcfc, 1, 3)
1087+
self.assertEqual(sum(elemvolume(no[:, :3], el[:, :4])), 213.33333333333337)
1088+
self.assertAlmostEqual(
1089+
sum(elemvolume(no[:, :3], fc[:, :3])), 412.8904758569056, 4
1090+
)
1091+
10571092

10581093
if __name__ == "__main__":
10591094
unittest.main()

0 commit comments

Comments
 (0)