Skip to content

Commit 5615979

Browse files
committed
ENH: Add stubs from BIAP 9
1 parent 7327927 commit 5615979

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

nibabel/coordimage.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
class CoordinateImage:
2+
"""
3+
Attributes
4+
----------
5+
header : a file-specific header
6+
coordaxis : ``CoordinateAxis``
7+
dataobj : array-like
8+
"""
9+
10+
11+
class CoordinateAxis:
12+
"""
13+
Attributes
14+
----------
15+
parcels : list of ``Parcel`` objects
16+
"""
17+
18+
def load_structures(self, mapping):
19+
"""
20+
Associate parcels to ``Pointset`` structures
21+
"""
22+
raise NotImplementedError
23+
24+
def __getitem__(self, slicer):
25+
"""
26+
Return a sub-sampled CoordinateAxis containing structures
27+
matching the indices provided.
28+
"""
29+
raise NotImplementedError
30+
31+
def get_indices(self, parcel, indices=None):
32+
"""
33+
Return the indices in the full axis that correspond to the
34+
requested parcel. If indices are provided, further subsample
35+
the requested parcel.
36+
"""
37+
raise NotImplementedError
38+
39+
40+
class Parcel:
41+
"""
42+
Attributes
43+
----------
44+
name : str
45+
structure : ``Pointset``
46+
indices : object that selects a subset of coordinates in structure
47+
"""
48+
49+
50+
class GeometryCollection:
51+
"""
52+
Attributes
53+
----------
54+
structures : dict
55+
Mapping from structure names to ``Pointset``
56+
"""
57+
58+
@classmethod
59+
def from_spec(klass, pathlike):
60+
"""Load a collection of geometries from a specification."""
61+
raise NotImplementedError

nibabel/pointset.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
class Pointset:
2+
@property
3+
def n_coords(self):
4+
"""Number of coordinates
5+
6+
Subclasses should override with more efficient implementations.
7+
"""
8+
return len(self.get_coords())
9+
10+
def get_coords(self, name=None):
11+
"""Nx3 array of coordinates in RAS+ space"""
12+
raise NotImplementedError
13+
14+
15+
class TriangularMesh(Pointset):
16+
@property
17+
def n_triangles(self):
18+
"""Number of faces
19+
20+
Subclasses should override with more efficient implementations.
21+
"""
22+
return len(self.get_triangles())
23+
24+
def get_triangles(self, name=None):
25+
"""Mx3 array of indices into coordinate table"""
26+
raise NotImplementedError
27+
28+
def get_mesh(self, name=None):
29+
return self.get_coords(name=name), self.get_triangles(name=name)
30+
31+
def get_names(self):
32+
"""List of surface names that can be passed to
33+
``get_{coords,triangles,mesh}``
34+
"""
35+
raise NotImplementedError
36+
37+
## This method is called for by the BIAP, but it now seems simpler to wait to
38+
## provide it until there are any proposed implementations
39+
# def decimate(self, *, n_coords=None, ratio=None):
40+
# """ Return a TriangularMesh with a smaller number of vertices that
41+
# preserves the geometry of the original """
42+
# # To be overridden when a format provides optimization opportunities
43+
# raise NotImplementedError
44+
45+
46+
class NdGrid(Pointset):
47+
"""
48+
Attributes
49+
----------
50+
shape : 3-tuple
51+
number of coordinates in each dimension of grid
52+
"""
53+
54+
def get_affine(self, name=None):
55+
"""4x4 array"""
56+
raise NotImplementedError

0 commit comments

Comments
 (0)