@@ -218,14 +218,11 @@ def __getitem__(self, slicer):
218
218
return h5f [self .dataset_name ][slicer ]
219
219
220
220
221
- class H5Geometry (ps .TriangularMesh ):
221
+ class H5Geometry (ps .TriMeshFamily ):
222
222
"""Simple Geometry file structure that combines a single topology
223
223
with one or more coordinate sets
224
224
"""
225
225
226
- def __init__ (self , meshes ):
227
- self ._meshes = meshes
228
-
229
226
@classmethod
230
227
def from_filename (klass , pathlike ):
231
228
meshes = {}
@@ -236,33 +233,11 @@ def from_filename(klass, pathlike):
236
233
return klass (meshes )
237
234
238
235
def to_filename (self , pathlike ):
239
- topology = None
240
- coordinates = {}
241
- for name , mesh in self ._meshes .items ():
242
- coords , faces = mesh
243
- if topology is None :
244
- topology = faces
245
- elif not np .array_equal (faces , topology ):
246
- raise ValueError ('Inconsistent topology' )
247
- coordinates [name ] = coords
248
-
249
236
with h5 .File (pathlike , 'w' ) as h5f :
250
- h5f .create_dataset ('/topology' , data = topology )
251
- for name , coord in coordinates .items ():
237
+ h5f .create_dataset ('/topology' , data = self . get_triangles () )
238
+ for name , coord in self . _coords .items ():
252
239
h5f .create_dataset (f'/coordinates/{ name } ' , data = coord )
253
240
254
- def get_coords (self , name = None ):
255
- if name is None :
256
- name = next (iter (self ._meshes ))
257
- coords , _ = self ._meshes [name ]
258
- return coords
259
-
260
- def get_triangles (self , name = None ):
261
- if name is None :
262
- name = next (iter (self ._meshes ))
263
- _ , triangles = self ._meshes [name ]
264
- return triangles
265
-
266
241
267
242
class FSGeometryProxy :
268
243
def __init__ (self , pathlike ):
@@ -316,10 +291,7 @@ def triangles(self):
316
291
return ap
317
292
318
293
319
- class FreeSurferHemisphere (ps .TriangularMesh ):
320
- def __init__ (self , meshes ):
321
- self ._meshes = meshes
322
-
294
+ class FreeSurferHemisphere (ps .TriMeshFamily ):
323
295
@classmethod
324
296
def from_filename (klass , pathlike ):
325
297
path = Path (pathlike )
@@ -345,24 +317,6 @@ def from_filename(klass, pathlike):
345
317
hemi ._default = default
346
318
return hemi
347
319
348
- def get_coords (self , name = None ):
349
- if name is None :
350
- name = self ._default
351
- return self ._meshes [name ].coords
352
-
353
- def get_triangles (self , name = None ):
354
- if name is None :
355
- name = self ._default
356
- return self ._meshes [name ].triangles
357
-
358
- @property
359
- def n_coords (self ):
360
- return self ._meshes [self ._default ].vnum
361
-
362
- @property
363
- def n_triangles (self ):
364
- return self ._meshes [self ._default ].fnum
365
-
366
320
367
321
def test_FreeSurferHemisphere ():
368
322
lh = FreeSurferHemisphere .from_filename (FS_DATA / 'fsaverage/surf/lh.white' )
@@ -377,6 +331,6 @@ def test_make_H5Geometry(tmp_path):
377
331
h5geo .to_filename (tmp_path / 'geometry.h5' )
378
332
379
333
rt_h5geo = H5Geometry .from_filename (tmp_path / 'geometry.h5' )
380
- assert set (h5geo ._meshes ) == set (rt_h5geo ._meshes )
334
+ assert set (h5geo ._coords ) == set (rt_h5geo ._coords )
381
335
assert np .array_equal (lh .get_coords ('white' ), rt_h5geo .get_coords ('white' ))
382
336
assert np .array_equal (lh .get_triangles (), rt_h5geo .get_triangles ())
0 commit comments