diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ae032ca0801613df43503e37426aaf164d1a272e..ba122c57b9006f859c4c9898d407f61b536af20b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -27,6 +27,13 @@ Changed vertex data. +Fixed +^^^^^ + +* Fixed an issue in the :class:`.GiftiMesh` class, where + ``numpy``/``nibabel`` was returning read-only index arrays. + + Removed ^^^^^^^ diff --git a/fsl/data/gifti.py b/fsl/data/gifti.py index 11cb3d93cfc7e383dbcca6db74d1036a60786f5b..43ce2ec5a18b7e2c31a2fbf82bb96dfcb566bdd7 100644 --- a/fsl/data/gifti.py +++ b/fsl/data/gifti.py @@ -211,8 +211,8 @@ def loadGiftiMesh(filename): raise ValueError('{}: GIFTI surface files must contain ' 'at least one pointset array'.format(filename)) - vertices = [ps.data for ps in pointsets] - indices = triangles[0].data + vertices = [np.array(ps.data) for ps in pointsets] + indices = np.array(triangles[0].data) if len(vdata) == 0: vdata = None else: vdata = prepareGiftiVertexData(vdata, filename) diff --git a/tests/test_gifti.py b/tests/test_gifti.py index ba758a5057952452eaf27d2651869a657c621805..ff6a9b1a3e51c96a48cd971fbe46f68d6f0e90b9 100644 --- a/tests/test_gifti.py +++ b/tests/test_gifti.py @@ -299,3 +299,23 @@ def test_GiftiMesh_multiple_vertices(): surf.vertices = expvsets[1] assert np.all(surf.vertices == TEST_VERTS * 5) + + +def test_GiftiMesh_needsFixing(): + from . import test_mesh + + verts = test_mesh.CUBE_VERTICES + idxs = test_mesh.CUBE_TRIANGLES_CW + idxs_fixed = test_mesh.CUBE_TRIANGLES_CCW + + verts = nib.gifti.GiftiDataArray(verts, intent='NIFTI_INTENT_POINTSET') + idxs = nib.gifti.GiftiDataArray(idxs, intent='NIFTI_INTENT_TRIANGLE') + gimg = nib.gifti.GiftiImage(darrays=[verts, idxs]) + + with tempdir(): + fname = op.abspath('test.gii') + gimg.to_filename(fname) + + surf = gifti.GiftiMesh(fname, fixWinding=True) + + assert np.all(np.isclose(surf.indices, idxs_fixed)) diff --git a/tests/test_mesh.py b/tests/test_mesh.py index 97f2c9b2f3eb63b02a2c06fec81c508e53f5e713..8b97bfa1c180cd301af462a2f067aff02c04e4b1 100644 --- a/tests/test_mesh.py +++ b/tests/test_mesh.py @@ -248,9 +248,11 @@ def test_needsFixing(): fnormals = np.array(CUBE_CCW_VERTEX_NORMALS) blo = verts.min(axis=0) bhi = verts.max(axis=0) + mesh = fslmesh.Mesh(tris_cw, vertices=verts, fixWinding=True) assert not fslmesh.needsFixing(verts, tris_ccw, fnormals, blo, bhi) assert fslmesh.needsFixing(verts, tris_cw, -fnormals, blo, bhi) + assert np.all(np.isclose(mesh.indices, tris_ccw)) def test_trimesh_no_trimesh():