From d520cc81ef2745566e73898269bc549f859382b4 Mon Sep 17 00:00:00 2001 From: Renan Date: Thu, 7 Apr 2022 08:55:32 +0300 Subject: [PATCH] FIX: check coil mesh connection --- invesalius/net/neuronavigation_api.py | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/invesalius/net/neuronavigation_api.py b/invesalius/net/neuronavigation_api.py index dfc99de..31e49dd 100644 --- a/invesalius/net/neuronavigation_api.py +++ b/invesalius/net/neuronavigation_api.py @@ -72,26 +72,27 @@ class NeuronavigationApi(metaclass=Singleton): ) def update_coil_mesh(self, polydata): - wrapped = dataset_adapter.WrapDataObject(polydata) - - points = np.asarray(wrapped.Points) - polygons_raw = np.asarray(wrapped.Polygons) - - # The polygons are returned as 1d-array of the form - # - # [n_0, id_0(0), id_0(1), ..., id_0(n_0), - # n_1, id_1(0), id_1(1), ..., id_1(n_1), - # ...] - # - # where n_i is the number of vertices in polygon i, and id_i's are indices to the vertex list. - # - # Assert that all polygons have an equal number of vertices, reshape the array, and drop n_i's. - # - assert np.all(polygons_raw[0::self.N_VERTICES_IN_POLYGON + 1] == self.N_VERTICES_IN_POLYGON) - - polygons = polygons_raw.reshape(-1, self.N_VERTICES_IN_POLYGON + 1)[:, 1:] - - self.connection.update_coil_mesh( - points=points, - polygons=polygons, - ) + if self.connection is not None: + wrapped = dataset_adapter.WrapDataObject(polydata) + + points = np.asarray(wrapped.Points) + polygons_raw = np.asarray(wrapped.Polygons) + + # The polygons are returned as 1d-array of the form + # + # [n_0, id_0(0), id_0(1), ..., id_0(n_0), + # n_1, id_1(0), id_1(1), ..., id_1(n_1), + # ...] + # + # where n_i is the number of vertices in polygon i, and id_i's are indices to the vertex list. + # + # Assert that all polygons have an equal number of vertices, reshape the array, and drop n_i's. + # + assert np.all(polygons_raw[0::self.N_VERTICES_IN_POLYGON + 1] == self.N_VERTICES_IN_POLYGON) + + polygons = polygons_raw.reshape(-1, self.N_VERTICES_IN_POLYGON + 1)[:, 1:] + + self.connection.update_coil_mesh( + points=points, + polygons=polygons, + ) -- libgit2 0.21.2