Skip to content

Commit 324c8c0

Browse files
committed
TEST: Test basic TriangularMesh behavior
1 parent 82ff662 commit 324c8c0

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

nibabel/pointset.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class HasMeshAttrs(ty.Protocol):
5353
triangles: CoordinateArray
5454

5555

56-
@dataclass
56+
@dataclass(init=False)
5757
class Pointset:
5858
"""A collection of points described by coordinates.
5959
@@ -70,7 +70,7 @@ class Pointset:
7070

7171
coordinates: CoordinateArray
7272
affine: np.ndarray
73-
homogeneous: bool = False
73+
homogeneous: bool
7474

7575
# Force use of __rmatmul__ with numpy arrays
7676
__array_priority__ = 99
@@ -149,6 +149,7 @@ def get_coords(self, *, as_homogeneous: bool = False):
149149
return coords
150150

151151

152+
@dataclass(init=False)
152153
class TriangularMesh(Pointset):
153154
triangles: CoordinateArray
154155

nibabel/tests/test_pointset.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import namedtuple
12
from math import prod
23
from pathlib import Path
34
from unittest import skipUnless
@@ -184,8 +185,47 @@ def test_to_mask(self):
184185
assert np.array_equal(mask_img.affine, np.eye(4))
185186

186187

187-
class TestTriangularMeshes(TestPointsets):
188-
...
188+
class TestTriangularMeshes:
189+
def test_init(self):
190+
# Tetrahedron
191+
coords = np.array(
192+
[
193+
[0.0, 0.0, 0.0],
194+
[0.0, 0.0, 1.0],
195+
[0.0, 1.0, 0.0],
196+
[1.0, 0.0, 0.0],
197+
]
198+
)
199+
triangles = np.array(
200+
[
201+
[0, 2, 1],
202+
[0, 3, 2],
203+
[0, 1, 3],
204+
[1, 2, 3],
205+
]
206+
)
207+
208+
mesh = namedtuple('mesh', ('coordinates', 'triangles'))(coords, triangles)
209+
210+
tm1 = ps.TriangularMesh(coords, triangles)
211+
tm2 = ps.TriangularMesh.from_tuple(mesh)
212+
tm3 = ps.TriangularMesh.from_object(mesh)
213+
214+
assert np.allclose(tm1.affine, np.eye(4))
215+
assert np.allclose(tm2.affine, np.eye(4))
216+
assert np.allclose(tm3.affine, np.eye(4))
217+
218+
assert tm1.homogeneous is False
219+
assert tm2.homogeneous is False
220+
assert tm3.homogeneous is False
221+
222+
assert (tm1.n_coords, tm1.dim) == (4, 3)
223+
assert (tm2.n_coords, tm2.dim) == (4, 3)
224+
assert (tm3.n_coords, tm3.dim) == (4, 3)
225+
226+
assert tm1.n_triangles == 4
227+
assert tm2.n_triangles == 4
228+
assert tm3.n_triangles == 4
189229

190230

191231
class H5ArrayProxy:

0 commit comments

Comments
 (0)