@@ -47,13 +47,10 @@ 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
- def __init__ (self , meshes ):
55
- self ._meshes = meshes
56
-
57
54
@classmethod
58
55
def from_filename (klass , pathlike ):
59
56
meshes = {}
@@ -64,33 +61,11 @@ def from_filename(klass, pathlike):
64
61
return klass (meshes )
65
62
66
63
def to_filename (self , pathlike ):
67
- topology = None
68
- coordinates = {}
69
- for name , mesh in self ._meshes .items ():
70
- coords , faces = mesh
71
- if topology is None :
72
- topology = faces
73
- elif not np .array_equal (faces , topology ):
74
- raise ValueError ("Inconsistent topology" )
75
- coordinates [name ] = coords
76
-
77
64
with h5 .File (pathlike , "w" ) as h5f :
78
- h5f .create_dataset ("/topology" , data = topology )
79
- for name , coord in coordinates .items ():
65
+ h5f .create_dataset ("/topology" , data = self . get_triangles () )
66
+ for name , coord in self . _coords .items ():
80
67
h5f .create_dataset (f"/coordinates/{ name } " , data = coord )
81
68
82
- def get_coords (self , name = None ):
83
- if name is None :
84
- name = next (iter (self ._meshes ))
85
- coords , _ = self ._meshes [name ]
86
- return coords
87
-
88
- def get_triangles (self , name = None ):
89
- if name is None :
90
- name = next (iter (self ._meshes ))
91
- _ , triangles = self ._meshes [name ]
92
- return triangles
93
-
94
69
95
70
class FSGeometryProxy :
96
71
def __init__ (self , pathlike ):
@@ -143,10 +118,7 @@ def triangles(self):
143
118
return ap
144
119
145
120
146
- class FreeSurferHemisphere (ps .TriangularMesh ):
147
- def __init__ (self , meshes ):
148
- self ._meshes = meshes
149
-
121
+ class FreeSurferHemisphere (ps .TriMeshFamily ):
150
122
@classmethod
151
123
def from_filename (klass , pathlike ):
152
124
path = Path (pathlike )
@@ -165,24 +137,6 @@ def from_filename(klass, pathlike):
165
137
hemi ._default = default
166
138
return hemi
167
139
168
- def get_coords (self , name = None ):
169
- if name is None :
170
- name = self ._default
171
- return self ._meshes [name ].coords
172
-
173
- def get_triangles (self , name = None ):
174
- if name is None :
175
- name = self ._default
176
- return self ._meshes [name ].triangles
177
-
178
- @property
179
- def n_coords (self ):
180
- return self ._meshes [self ._default ].vnum
181
-
182
- @property
183
- def n_triangles (self ):
184
- return self ._meshes [self ._default ].fnum
185
-
186
140
187
141
def test_FreeSurferHemisphere ():
188
142
lh = FreeSurferHemisphere .from_filename (FS_DATA / 'fsaverage/surf/lh.white' )
@@ -197,6 +151,6 @@ def test_make_H5Geometry(tmp_path):
197
151
h5geo .to_filename (tmp_path / "geometry.h5" )
198
152
199
153
rt_h5geo = H5Geometry .from_filename (tmp_path / "geometry.h5" )
200
- assert set (h5geo ._meshes ) == set (rt_h5geo ._meshes )
154
+ assert set (h5geo ._coords ) == set (rt_h5geo ._coords )
201
155
assert np .array_equal (lh .get_coords ('white' ), rt_h5geo .get_coords ('white' ))
202
156
assert np .array_equal (lh .get_triangles (), rt_h5geo .get_triangles ())
0 commit comments