Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fslpy
Commits
0467986e
Commit
0467986e
authored
Jan 23, 2018
by
Paul McCarthy
🚵
Browse files
New Mesh.loadVertices method. Mesh.vertices only raises a notification if
the vertex set changes.
parent
211858f3
Changes
3
Hide whitespace changes
Inline
Side-by-side
fsl/data/freesurfer.py
View file @
0467986e
...
...
@@ -104,6 +104,32 @@ class FreesurferMesh(fslmesh.Mesh):
self
.
addVertices
(
verts
,
f
,
select
=
False
)
def
loadVertices
(
self
,
infile
,
key
=
None
,
**
kwargs
):
"""Overrides :meth:`.Mesh.loadVertices`. If the given ``infile``
looks like a Freesurfer file, it is loaded via
``nibabel.freesurfer.load_geometry``. Otherwise, it is passed to
:meth:`.Mesh.loadVertices`.
"""
if
not
fslpath
.
hasExt
(
infile
,
GEOMETRY_EXTENSIONS
):
return
fslmesh
.
Mesh
.
loadVertices
(
self
,
infile
,
key
,
**
kwargs
)
infile
=
op
.
abspath
(
infile
)
if
key
is
None
:
key
=
infile
# TODO merge metadata
vertices
,
indices
,
meta
,
comment
=
nibfs
.
read_geometry
(
infile
,
read_metadata
=
True
,
read_stamp
=
True
)
vertices
=
vertices
.
reshape
(
self
.
vertices
.
shape
)
self
.
addVertices
(
vertices
,
key
,
**
kwargs
)
return
vertices
def
loadVertexData
(
self
,
infile
,
key
=
None
):
"""Overrides :meth:`.Mesh.loadVertexData`. If the given ``infile``
looks like a Freesurfer file, it is loaded via the
...
...
fsl/data/gifti.py
View file @
0467986e
...
...
@@ -104,12 +104,38 @@ class GiftiMesh(fslmesh.Mesh):
self
.
setMeta
(
sfile
,
surfimg
)
def
loadVertices
(
self
,
infile
,
key
=
None
,
*
args
,
**
kwargs
):
"""Overrides the :meth:`.Mesh.loadVertices` method.
Attempts to load vertices for this ``GiftiMesh`` from the given
``infile``, which may be a GIFTI file or a plain text file containing
vertices.
"""
if
not
infile
.
endswith
(
'.gii'
):
return
fslmesh
.
Mesh
.
loadVertices
(
self
,
infile
,
key
,
*
args
,
**
kwargs
)
infile
=
op
.
abspath
(
infile
)
if
key
is
None
:
key
=
infile
surfimg
,
vertices
,
_
=
loadGiftiMesh
(
infile
)
vertices
=
vertices
.
reshape
(
self
.
vertices
.
shape
[
0
],
3
)
self
.
addVertices
(
vertices
,
key
,
*
args
,
**
kwargs
)
self
.
setMeta
(
infile
,
surfimg
)
return
vertices
def
loadVertexData
(
self
,
infile
,
key
=
None
):
"""Overrides the :meth:`.
Triangle
Mesh.loadVertexData` method.
"""Overrides the :meth:`.Mesh.loadVertexData` method.
Attempts to load data associated with each vertex of this
``GiftiMesh`` from the given ``
dataSourc
e``, which may be
a
GIFTI file or a
plain text file which contains vertex data.
``GiftiMesh`` from the given ``
infil
e``, which may be
a GIFTI file or
a plain text file which contains vertex data.
"""
infile
=
op
.
abspath
(
infile
)
...
...
fsl/data/mesh.py
View file @
0467986e
...
...
@@ -91,6 +91,7 @@ class Mesh(notifier.Notifier, meta.Meta):
.. autosummary::
:nosignatures:
loadVertices
addVertices
selectedVertices
vertexSets
...
...
@@ -253,14 +254,19 @@ class Mesh(notifier.Notifier, meta.Meta):
def
vertices
(
self
,
key
):
"""Select the current vertex set - a ``KeyError`` is raised
if no vertex set with the specified ``key`` has been added.
When the current vertex set is changed, a notification is emitted
through the :class:`.Notifier` interface, with the topic
``'vertices'``.
"""
# Force a key error if
# the key is invalid
self
.
__vertices
[
key
]
self
.
__selected
=
key
self
.
notify
(
topic
=
'vertices'
)
if
self
.
__selected
!=
key
:
self
.
__selected
=
key
self
.
notify
(
topic
=
'vertices'
)
@
property
...
...
@@ -320,6 +326,36 @@ class Mesh(notifier.Notifier, meta.Meta):
return
lo
,
hi
def
loadVertices
(
self
,
infile
,
key
=
None
,
**
kwargs
):
"""Loads vertex data from the given ``infile``, and adds it as a vertex
set with the given ``key``. This implementation supports loading vertex
data from white-space delimited text files via ``numpy.loadtxt``, but
sub-classes may override this method to support additional file types.
:arg infile: File to load data from.
:arg key: Key to pass to :meth:`addVertices`. If not provided,
set to ``infile`` (converted to an absolute path)
All of the other arguments are passed through to :meth:`addVertices`.
:returns: The loaded vertices.
"""
infile
=
op
.
abspath
(
infile
)
if
key
is
None
:
key
=
infile
vertices
=
np
.
loadtxt
(
infile
)
vertices
=
vertices
.
reshape
(
self
.
vertices
.
shape
)
self
.
addVertices
(
vertices
,
key
,
**
kwargs
)
return
vertices
def
addVertices
(
self
,
vertices
,
key
=
None
,
select
=
True
,
fixWinding
=
False
):
"""Adds a set of vertices to this ``Mesh``.
...
...
@@ -387,6 +423,8 @@ class Mesh(notifier.Notifier, meta.Meta):
:arg key: Key to pass to :meth:`addVertexData`. If not provided,
set to ``infile`` (converted to an absolute path)
:returns: The loaded vertex data.
"""
infile
=
op
.
abspath
(
infile
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment