Skip to content

Commit 092edc2

Browse files
committed
[test] debug and test qmeshcut, extractloops, bump 0.2.3
1 parent 6f7496d commit 092edc2

File tree

5 files changed

+81
-10
lines changed

5 files changed

+81
-10
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.2.2
7+
* Version: 0.2.3
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.2.2"
140+
__version__ = "0.2.3"
141141
__all__ = [
142142
"advancefront",
143143
"barycentricgrid",

iso2mesh/modify.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ def qmeshcut(elem, node, value, cutat):
277277

278278
emap = np.zeros(edges.shape[0], dtype=int)
279279
emap[cutedges] = np.arange(1, len(cutedges) + 1)
280-
emap = emap.reshape((-1, int(edges.shape[0] / elem.shape[0])))
280+
emap = emap.reshape((elem.shape[0], -1), order="F")
281281

282282
etag = np.sum(emap > 0, axis=1)
283283
if esize == 3:
284284
linecut = np.where(etag == 2)[0]
285-
lineseg = emap[linecut].T
286-
facedata = lineseg[lineseg > 0].reshape((2, len(linecut))).T
285+
lineseg = emap[linecut, :]
286+
facedata = lineseg[lineseg > 0].reshape((2, len(linecut)), order="F").T
287287
elemid = linecut
288288
if value.shape[0] == elem.shape[0] and "cutvalue" not in locals():
289289
cutvalue = value[elemid]
@@ -292,14 +292,15 @@ def qmeshcut(elem, node, value, cutat):
292292
tricut = np.where(etag == 3)[0]
293293
quadcut = np.where(etag == 4)[0]
294294
elemid = np.concatenate([tricut, quadcut])
295+
295296
if value.shape[0] == elem.shape[0] and "cutvalue" not in locals():
296297
cutvalue = value[elemid]
297298

298-
tripatch = emap[tricut].T
299-
tripatch = tripatch[tripatch > 0].reshape((3, len(tricut))).T
299+
tripatch = emap[tricut, :]
300+
tripatch = tripatch[tripatch > 0].reshape((3, len(tricut)), order="F").T
300301

301-
quadpatch = emap[quadcut].T
302-
quadpatch = quadpatch[quadpatch > 0].reshape((4, len(quadcut))).T
302+
quadpatch = emap[quadcut, :]
303+
quadpatch = quadpatch[quadpatch > 0].reshape((4, len(quadcut)), order="F").T
303304

304305
facedata = np.vstack([tripatch[:, [0, 1, 2, 2]], quadpatch[:, [0, 1, 3, 2]]])
305306

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

test/run_test.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,8 @@ def __init__(self, *args, **kwargs):
706706
)
707707
self.el = meshreorient(self.no, self.el[:, :4])[0]
708708
self.no1, self.fc1 = meshcheckrepair(self.no, self.fc, "deep")
709+
self.nbox, self.ebox = meshgrid5([0, 1], [1, 2], [0, 2])
710+
self.fbox = volface(self.ebox)[0]
709711

710712
def test_removeisolatednode(self):
711713
no1 = removeisolatednode(self.no[:, :3], self.fc[:, :3])[0]
@@ -778,6 +780,74 @@ def test_sms(self):
778780
no2, el2, _ = s2m(no1, el, 1, 100)
779781
self.assertTrue(np.sum(elemvolume(no2, el2[:, :4])) > 0.55)
780782

783+
def test_qmeshcut_elem(self):
784+
cutpos, cutvalue, facedata, _, _ = qmeshcut(
785+
self.ebox, self.nbox, self.nbox[:, 0] + self.nbox[:, 1], 2
786+
)
787+
expected_fc = [
788+
[1, 16, 29, 29],
789+
[2, 17, 30, 30],
790+
[3, 42, 55, 55],
791+
[4, 44, 57, 57],
792+
[5, 45, 58, 58],
793+
[19, 46, 71, 71],
794+
[6, 20, 32, 32],
795+
[7, 21, 33, 33],
796+
[35, 60, 72, 72],
797+
[36, 61, 73, 73],
798+
[8, 48, 62, 62],
799+
[24, 49, 75, 75],
800+
[37, 64, 76, 76],
801+
[10, 50, 65, 65],
802+
[12, 51, 67, 67],
803+
[39, 69, 78, 78],
804+
[13, 53, 70, 70],
805+
[14, 27, 40, 40],
806+
[15, 28, 54, 41],
807+
[18, 31, 56, 43],
808+
[22, 34, 59, 47],
809+
[9, 23, 74, 63],
810+
[11, 25, 77, 66],
811+
[26, 38, 68, 52],
812+
]
813+
self.assertEqual(np.sum(cutpos), 234.0)
814+
self.assertEqual(facedata.tolist(), expected_fc)
815+
816+
def test_qmeshcut_face(self):
817+
no2, fc2, _ = removeisolatednode(self.nbox, self.fbox)
818+
cutpos, cutvalue, facedata, _, _ = qmeshcut(fc2[:, :3], no2, no2[:, 0], 0)
819+
expected_fc = [
820+
[1, 22],
821+
[2, 12],
822+
[13, 23],
823+
[14, 24],
824+
[3, 15],
825+
[4, 25],
826+
[5, 16],
827+
[6, 26],
828+
[7, 27],
829+
[8, 17],
830+
[18, 28],
831+
[9, 19],
832+
[10, 29],
833+
[20, 30],
834+
[21, 31],
835+
[11, 32],
836+
]
837+
self.assertEqual(np.sum(cutpos), 80.0)
838+
self.assertEqual(facedata.tolist(), expected_fc)
839+
840+
def test_extractloops(self):
841+
no2, fc2, _ = removeisolatednode(self.nbox, self.fbox)
842+
cutpos, cutvalue, facedata, _, _ = qmeshcut(fc2[:, :3], no2, no2[:, 0], 0)
843+
_, ed2 = removedupnodes(cutpos, facedata)
844+
bcutloop = extractloops(ed2)
845+
846+
expected_fc = [1, 4, 6, 7, 8, 5, 3, 2, 1]
847+
self.assertNotEqual(bcutloop[-1], bcutloop[-1])
848+
bcutloop.pop()
849+
self.assertEqual(bcutloop, expected_fc)
850+
781851

782852
class Test_surfboolean(unittest.TestCase):
783853
def __init__(self, *args, **kwargs):

0 commit comments

Comments
 (0)