Skip to content
Snippets Groups Projects
Commit cb88b49a authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Merge branch 'bf/gifti_readonly' into 'master'

Bf/gifti readonly

See merge request fsl/fslpy!98
parents ff26709b f770700c
No related branches found
No related tags found
No related merge requests found
Pipeline #3275 passed
......@@ -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
^^^^^^^
......
......@@ -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)
......
......@@ -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))
......@@ -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():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment