diff --git a/examples/02_maps_and_templates/005_access_surface_maps.py b/examples/02_maps_and_templates/005_access_surface_maps.py index c38770943..16de46fc9 100644 --- a/examples/02_maps_and_templates/005_access_surface_maps.py +++ b/examples/02_maps_and_templates/005_access_surface_maps.py @@ -52,13 +52,12 @@ # first one from the list. Now let us fetch a specific variant and also the # hemisphere fragment mesh = mp.fetch(variant="inflated", fragment="left") - -# The returned structure is a dictionary of three numpy arrays representing the -# vertices, faces, and labels respectively. Each vertex defines a 3D surface +mesh +# The returned structure is a Surface consiting of three numpy arrays representing the +# vertices, faces, and vertex_labels respectively. Each vertex defines a 3D surface # point, while the faces are triplets of indices into the list of vertices, # defining surface triangles. The labels provide the label index associated with # each vertex. -print(mesh.keys()) # %% # Most meshes are shipped with a color map which we can fetch from the map diff --git a/siibra/surface/common.py b/siibra/surface/common.py index 82231c04c..6f55b5dda 100644 --- a/siibra/surface/common.py +++ b/siibra/surface/common.py @@ -4,32 +4,43 @@ from io import BytesIO from functools import wraps + class Surface: - def __init__(self, vertices: List[List[float]]=None, - faces: List[List[int]]=None, - vertices_labels: List[List[Union[float, int]]]=None, - **kwargs) -> None: - """Describes a common interface to surface, where vertices + def __init__( + self, + vertices: List[List[float]] = None, + faces: List[List[int]] = None, + vertex_labels: List[List[Union[float, int]]] = None, + **kwargs, + ) -> None: + """ + Describes a common interface to surface, where vertices faces are defined, and optionally, vertices labels, face labels can be defined. - - Args: - vertices (List[List[float]] or ndarray): verticies triplet - faces: (List[List[int]] or ndarray): faces triplet - vertices_labels: (Labels)""" - - self.vertices = np.array(kwargs.get("verts", []) if vertices is None else vertices) + + Parameters + ---------- + vertices (List[List[float]] or ndarray): verticies triplet + faces: (List[List[int]] or ndarray): faces triplet + vertex_labels: (Labels) + """ + + self.vertices = np.array( + kwargs.get("verts", []) if vertices is None else vertices + ) self.faces = np.array([] if faces is None else faces, dtype=np.uint64) - vertices_labels = kwargs.get("labels", []) if vertices_labels is None else vertices_labels - self.vertices_labels = np.array(vertices_labels) + vertex_labels = ( + kwargs.get("labels", []) if vertex_labels is None else vertex_labels + ) + self.vertex_labels = np.array(vertex_labels) def __contains__(self, spec): self.faces if spec in ("verts", "faces"): return True if spec == "labels": - return len(self.vertices_labels) > 0 + return len(self.vertex_labels) > 0 return False def __getitem__(self, spec: str): @@ -38,10 +49,10 @@ def __getitem__(self, spec: str): if spec == "faces": return self.faces if spec == "labels": - if len(self.vertices_labels) > 0: - return self.vertices_labels + if len(self.vertex_labels) > 0: + return self.vertex_labels raise IndexError(f"spec {spec!r} not found in class surface") - + def export(self, export_dest: Union[str, IO]): mesh = trimesh.Trimesh(self.vertices, self.faces) mesh.export(export_dest) @@ -53,11 +64,14 @@ def to_bytes(self): io.seek(0) return io.read() + def wrap_return_surface(): def outer(fn): @wraps(fn) def inner(*args, **kwargs): return_val = fn(*args, **kwargs) return Surface(**return_val) + return inner + return outer diff --git a/siibra/volumes/volume.py b/siibra/volumes/volume.py index cc2b03a22..00150798a 100644 --- a/siibra/volumes/volume.py +++ b/siibra/volumes/volume.py @@ -346,9 +346,8 @@ def fetch( try: if fmt == "gii-label": tpl = self.space.get_template(variant=kwargs.get('variant')) - mesh = tpl.fetch(**kwargs) - labels = self._providers[fmt].fetch(**fwd_args) - result = dict(**mesh, **labels) + result = tpl.fetch(format='mesh', **kwargs) + result.vertex_labels = self._providers[fmt].fetch(**fwd_args).get('labels') else: result = self._providers[fmt].fetch(**fwd_args) except requests.SiibraHttpRequestError as e: