@@ -47,14 +47,11 @@ def __getitem__(self, slicer):
47
47
return h5f [self .dataset_name ][slicer ]
48
48
49
49
50
- class H5Geometry (ps .TriangularMesh ):
50
+ class H5Geometry (ps .TriMeshFamily ):
51
51
"""Simple Geometry file structure that combines a single topology
52
52
with one or more coordinate sets
53
53
"""
54
54
55
- def __init__ (self , meshes ):
56
- self ._meshes = meshes
57
-
58
55
@classmethod
59
56
def from_filename (klass , pathlike ):
60
57
meshes = {}
@@ -65,33 +62,11 @@ def from_filename(klass, pathlike):
65
62
return klass (meshes )
66
63
67
64
def to_filename (self , pathlike ):
68
- topology = None
69
- coordinates = {}
70
- for name , mesh in self ._meshes .items ():
71
- coords , faces = mesh
72
- if topology is None :
73
- topology = faces
74
- elif not np .array_equal (faces , topology ):
75
- raise ValueError ('Inconsistent topology' )
76
- coordinates [name ] = coords
77
-
78
65
with h5 .File (pathlike , 'w' ) as h5f :
79
- h5f .create_dataset ('/topology' , data = topology )
80
- for name , coord in coordinates .items ():
66
+ h5f .create_dataset ('/topology' , data = self . get_triangles () )
67
+ for name , coord in self . _coords .items ():
81
68
h5f .create_dataset (f'/coordinates/{ name } ' , data = coord )
82
69
83
- def get_coords (self , name = None ):
84
- if name is None :
85
- name = next (iter (self ._meshes ))
86
- coords , _ = self ._meshes [name ]
87
- return coords
88
-
89
- def get_triangles (self , name = None ):
90
- if name is None :
91
- name = next (iter (self ._meshes ))
92
- _ , triangles = self ._meshes [name ]
93
- return triangles
94
-
95
70
96
71
class FSGeometryProxy :
97
72
def __init__ (self , pathlike ):
@@ -145,10 +120,7 @@ def triangles(self):
145
120
return ap
146
121
147
122
148
- class FreeSurferHemisphere (ps .TriangularMesh ):
149
- def __init__ (self , meshes ):
150
- self ._meshes = meshes
151
-
123
+ class FreeSurferHemisphere (ps .TriMeshFamily ):
152
124
@classmethod
153
125
def from_filename (klass , pathlike ):
154
126
path = Path (pathlike )
@@ -174,24 +146,6 @@ def from_filename(klass, pathlike):
174
146
hemi ._default = default
175
147
return hemi
176
148
177
- def get_coords (self , name = None ):
178
- if name is None :
179
- name = self ._default
180
- return self ._meshes [name ].coords
181
-
182
- def get_triangles (self , name = None ):
183
- if name is None :
184
- name = self ._default
185
- return self ._meshes [name ].triangles
186
-
187
- @property
188
- def n_coords (self ):
189
- return self ._meshes [self ._default ].vnum
190
-
191
- @property
192
- def n_triangles (self ):
193
- return self ._meshes [self ._default ].fnum
194
-
195
149
196
150
def test_FreeSurferHemisphere ():
197
151
lh = FreeSurferHemisphere .from_filename (FS_DATA / 'fsaverage/surf/lh.white' )
@@ -206,6 +160,6 @@ def test_make_H5Geometry(tmp_path):
206
160
h5geo .to_filename (tmp_path / 'geometry.h5' )
207
161
208
162
rt_h5geo = H5Geometry .from_filename (tmp_path / 'geometry.h5' )
209
- assert set (h5geo ._meshes ) == set (rt_h5geo ._meshes )
163
+ assert set (h5geo ._coords ) == set (rt_h5geo ._coords )
210
164
assert np .array_equal (lh .get_coords ('white' ), rt_h5geo .get_coords ('white' ))
211
165
assert np .array_equal (lh .get_triangles (), rt_h5geo .get_triangles ())
0 commit comments