From 15ecde79fb1d74ee2f2a2b2e21fbda66767a3fda Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Wed, 15 Feb 2017 15:13:24 +0000 Subject: [PATCH] TriangleMesh/GiftiSurface classes have method to load vertex data. I/O will be kept in these classes, instead of in FSLeyes. --- fsl/data/gifti.py | 13 ++++++++++++- fsl/data/mesh.py | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/fsl/data/gifti.py b/fsl/data/gifti.py index ea14b4e2c..41d38e3ba 100644 --- a/fsl/data/gifti.py +++ b/fsl/data/gifti.py @@ -23,6 +23,8 @@ are available: import os.path as op +import nibabel as nib + import fsl.utils.path as fslpath from . import mesh @@ -50,7 +52,6 @@ class GiftiSurface(mesh.TriangleMesh): :arg infile: A GIFTI surface file """ - import nibabel as nib surfimg = nib.load(infile) vertices, indices = extractGiftiSurface(surfimg) @@ -65,6 +66,16 @@ class GiftiSurface(mesh.TriangleMesh): self.surfImg = surfimg + def loadVertexData(self, dataSource): + """Attempts to load scalar data associated with each vertex of this + ``GiftiSurface`` from the given ``dataSource``. + """ + + # TODO make this more robust + norms = nib.load(dataSource) + return norms.darrays[0].data + + ALLOWED_EXTENSIONS = ['.surf.gii', '.gii'] """List of file extensions that a file containing Gifti surface data is expected to have. diff --git a/fsl/data/mesh.py b/fsl/data/mesh.py index 978fbbdd9..d9afd3cf2 100644 --- a/fsl/data/mesh.py +++ b/fsl/data/mesh.py @@ -55,6 +55,14 @@ class TriangleMesh(object): the vertex indices for :math:`M` triangles ============== ==================================================== + + And the following methods: + + .. autosummary:: + :nosignatures: + + getBounds + loadVertexData """ @@ -117,6 +125,15 @@ class TriangleMesh(object): return (self.__loBounds, self.__hiBounds) + def loadVertexData(self, dataSource): + """Attempts to load scalar data associated with each vertex of this + ``TriangleMesh`` from the given ``dataSource``. + + This method may be overridden by sub-classes. + """ + raise NotImplementedError('Not implemented yet') + + ALLOWED_EXTENSIONS = ['.vtk'] """A list of file extensions which could contain :class:`TriangleMesh` data. """ -- GitLab