Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
0467986e
Commit
0467986e
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
New Mesh.loadVertices method. Mesh.vertices only raises a notification if
the vertex set changes.
parent
211858f3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
fsl/data/freesurfer.py
+26
-0
26 additions, 0 deletions
fsl/data/freesurfer.py
fsl/data/gifti.py
+29
-3
29 additions, 3 deletions
fsl/data/gifti.py
fsl/data/mesh.py
+40
-2
40 additions, 2 deletions
fsl/data/mesh.py
with
95 additions
and
5 deletions
fsl/data/freesurfer.py
+
26
−
0
View file @
0467986e
...
@@ -104,6 +104,32 @@ class FreesurferMesh(fslmesh.Mesh):
...
@@ -104,6 +104,32 @@ class FreesurferMesh(fslmesh.Mesh):
self
.
addVertices
(
verts
,
f
,
select
=
False
)
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
):
def
loadVertexData
(
self
,
infile
,
key
=
None
):
"""
Overrides :meth:`.Mesh.loadVertexData`. If the given ``infile``
"""
Overrides :meth:`.Mesh.loadVertexData`. If the given ``infile``
looks like a Freesurfer file, it is loaded via the
looks like a Freesurfer file, it is loaded via the
...
...
This diff is collapsed.
Click to expand it.
fsl/data/gifti.py
+
29
−
3
View file @
0467986e
...
@@ -104,12 +104,38 @@ class GiftiMesh(fslmesh.Mesh):
...
@@ -104,12 +104,38 @@ class GiftiMesh(fslmesh.Mesh):
self
.
setMeta
(
sfile
,
surfimg
)
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
):
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
Attempts to load data associated with each vertex of this
``GiftiMesh`` from the given ``
dataSourc
e``, which may be
``GiftiMesh`` from the given ``
infil
e``, which may be
a GIFTI file or
a
GIFTI file or a
plain text file which contains vertex data.
a plain text file which contains vertex data.
"""
"""
infile
=
op
.
abspath
(
infile
)
infile
=
op
.
abspath
(
infile
)
...
...
This diff is collapsed.
Click to expand it.
fsl/data/mesh.py
+
40
−
2
View file @
0467986e
...
@@ -91,6 +91,7 @@ class Mesh(notifier.Notifier, meta.Meta):
...
@@ -91,6 +91,7 @@ class Mesh(notifier.Notifier, meta.Meta):
.. autosummary::
.. autosummary::
:nosignatures:
:nosignatures:
loadVertices
addVertices
addVertices
selectedVertices
selectedVertices
vertexSets
vertexSets
...
@@ -253,14 +254,19 @@ class Mesh(notifier.Notifier, meta.Meta):
...
@@ -253,14 +254,19 @@ class Mesh(notifier.Notifier, meta.Meta):
def
vertices
(
self
,
key
):
def
vertices
(
self
,
key
):
"""
Select the current vertex set - a ``KeyError`` is raised
"""
Select the current vertex set - a ``KeyError`` is raised
if no vertex set with the specified ``key`` has been added.
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
# Force a key error if
# the key is invalid
# the key is invalid
self
.
__vertices
[
key
]
self
.
__vertices
[
key
]
self
.
__selected
=
key
self
.
notify
(
topic
=
'
vertices
'
)
if
self
.
__selected
!=
key
:
self
.
__selected
=
key
self
.
notify
(
topic
=
'
vertices
'
)
@property
@property
...
@@ -320,6 +326,36 @@ class Mesh(notifier.Notifier, meta.Meta):
...
@@ -320,6 +326,36 @@ class Mesh(notifier.Notifier, meta.Meta):
return
lo
,
hi
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
):
def
addVertices
(
self
,
vertices
,
key
=
None
,
select
=
True
,
fixWinding
=
False
):
"""
Adds a set of vertices to this ``Mesh``.
"""
Adds a set of vertices to this ``Mesh``.
...
@@ -387,6 +423,8 @@ class Mesh(notifier.Notifier, meta.Meta):
...
@@ -387,6 +423,8 @@ class Mesh(notifier.Notifier, meta.Meta):
:arg key: Key to pass to :meth:`addVertexData`. If not provided,
:arg key: Key to pass to :meth:`addVertexData`. If not provided,
set to ``infile`` (converted to an absolute path)
set to ``infile`` (converted to an absolute path)
:returns: The loaded vertex data.
"""
"""
infile
=
op
.
abspath
(
infile
)
infile
=
op
.
abspath
(
infile
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment