Commit 8e5c5977297a8f7ee81f799427455fe2cc7f68fa
Committed by
GitHub
Exists in
master
Merge pull request #442 from rmatsuda/check_coil_mesh_connection
FIX: check coil mesh connection
Showing
1 changed file
with
24 additions
and
23 deletions
Show diff stats
invesalius/net/neuronavigation_api.py
| @@ -72,26 +72,27 @@ class NeuronavigationApi(metaclass=Singleton): | @@ -72,26 +72,27 @@ class NeuronavigationApi(metaclass=Singleton): | ||
| 72 | ) | 72 | ) |
| 73 | 73 | ||
| 74 | def update_coil_mesh(self, polydata): | 74 | def update_coil_mesh(self, polydata): |
| 75 | - wrapped = dataset_adapter.WrapDataObject(polydata) | ||
| 76 | - | ||
| 77 | - points = np.asarray(wrapped.Points) | ||
| 78 | - polygons_raw = np.asarray(wrapped.Polygons) | ||
| 79 | - | ||
| 80 | - # The polygons are returned as 1d-array of the form | ||
| 81 | - # | ||
| 82 | - # [n_0, id_0(0), id_0(1), ..., id_0(n_0), | ||
| 83 | - # n_1, id_1(0), id_1(1), ..., id_1(n_1), | ||
| 84 | - # ...] | ||
| 85 | - # | ||
| 86 | - # where n_i is the number of vertices in polygon i, and id_i's are indices to the vertex list. | ||
| 87 | - # | ||
| 88 | - # Assert that all polygons have an equal number of vertices, reshape the array, and drop n_i's. | ||
| 89 | - # | ||
| 90 | - assert np.all(polygons_raw[0::self.N_VERTICES_IN_POLYGON + 1] == self.N_VERTICES_IN_POLYGON) | ||
| 91 | - | ||
| 92 | - polygons = polygons_raw.reshape(-1, self.N_VERTICES_IN_POLYGON + 1)[:, 1:] | ||
| 93 | - | ||
| 94 | - self.connection.update_coil_mesh( | ||
| 95 | - points=points, | ||
| 96 | - polygons=polygons, | ||
| 97 | - ) | 75 | + if self.connection is not None: |
| 76 | + wrapped = dataset_adapter.WrapDataObject(polydata) | ||
| 77 | + | ||
| 78 | + points = np.asarray(wrapped.Points) | ||
| 79 | + polygons_raw = np.asarray(wrapped.Polygons) | ||
| 80 | + | ||
| 81 | + # The polygons are returned as 1d-array of the form | ||
| 82 | + # | ||
| 83 | + # [n_0, id_0(0), id_0(1), ..., id_0(n_0), | ||
| 84 | + # n_1, id_1(0), id_1(1), ..., id_1(n_1), | ||
| 85 | + # ...] | ||
| 86 | + # | ||
| 87 | + # where n_i is the number of vertices in polygon i, and id_i's are indices to the vertex list. | ||
| 88 | + # | ||
| 89 | + # Assert that all polygons have an equal number of vertices, reshape the array, and drop n_i's. | ||
| 90 | + # | ||
| 91 | + assert np.all(polygons_raw[0::self.N_VERTICES_IN_POLYGON + 1] == self.N_VERTICES_IN_POLYGON) | ||
| 92 | + | ||
| 93 | + polygons = polygons_raw.reshape(-1, self.N_VERTICES_IN_POLYGON + 1)[:, 1:] | ||
| 94 | + | ||
| 95 | + self.connection.update_coil_mesh( | ||
| 96 | + points=points, | ||
| 97 | + polygons=polygons, | ||
| 98 | + ) |