Skip to content

Commit d9855e6

Browse files
committed
feat: small updates
1 parent db7f234 commit d9855e6

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

python/examples/example_linear_registration.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,6 @@ def update(self):
276276
if current_time - self.last_updated_print > 5:
277277
print(f"Viewer states are successfully syncing at {ctime()}")
278278
self.last_updated_print = current_time
279-
# TODO make ready a status instead of two vars
280-
# TODO overall update the class attributes at the end to cleaner
281279
if self.co_ords_ready and not self.ready:
282280
with self.viewer.txn() as s:
283281
self.setup_registration_layers(s)
@@ -310,13 +308,14 @@ def setup_two_panel_layout(self, s: neuroglancer.ViewerState):
310308
neuroglancer.LayerGroupViewer(layers=group2_names, layout="xy-3d"),
311309
]
312310
)
313-
# Unliked position solves rendering problem but makes navigation awkward
314-
# s.layout.children[1].position.link = "unlinked"
315-
# In theory we could make keep unlinked and then on state change check
316-
# but that could be not worth compared to trying to improve rendering
311+
# Unlinked position solves rendering problem but makes navigation awkward
312+
if not self.two_coord_spaces
313+
s.layout.children[1].position.link = "unlinked"
317314
s.layout.children[1].crossSectionOrientation.link = "unlinked"
318-
# s.layout.children[1].crossSectionScale.link = "unlinked"
319315
s.layout.children[1].projectionOrientation.link = "unlinked"
316+
317+
# Can also unlink scales if desired
318+
# s.layout.children[1].crossSectionScale.link = "unlinked"
320319
# s.layout.children[1].projectionScale.link = "unlinked"
321320

322321
def setup_second_coord_space(self):
@@ -329,12 +328,15 @@ def setup_second_coord_space(self):
329328
info_future.add_done_callback(lambda f: self.save_coord_space_info(f))
330329

331330
def combine_affine_across_dims(self, s: neuroglancer.ViewerState, affine):
331+
"""
332+
The affine matrix only applies to the moving dims
333+
but the annotation layer in the two coord space case
334+
applies to all dims so we need to create a larger matrix
335+
"""
332336
all_dims = s.dimensions.names
333337
moving_dims = self.output_dim_names
334-
# The affine matrix only applies to the moving dims
335-
# so we need to create a larger matrix that applies to all dims
336-
# by adding identity transforms for the real dims
337338
full_matrix = np.zeros((len(all_dims), len(all_dims) + 1))
339+
338340
for i, dim in enumerate(all_dims):
339341
for j, dim2 in enumerate(all_dims):
340342
if dim in moving_dims and dim2 in moving_dims:
@@ -350,8 +352,7 @@ def combine_affine_across_dims(self, s: neuroglancer.ViewerState, affine):
350352

351353
def setup_registration_layers(self, s: neuroglancer.ViewerState):
352354
dimensions = s.dimensions
353-
# It is possible that the dimensions are not ready yet, return if so
354-
if len(dimensions.names) != self.num_dims:
355+
if len(dimensions.names) != self.num_dims # loading:
355356
return
356357

357358
# Make the annotation layer if needed
@@ -448,11 +449,6 @@ def setup_viewer_actions(self):
448449

449450
with viewer.config_state.txn() as s:
450451
s.input_event_bindings.viewer["keyt"] = "toggleRegisteredVisibility"
451-
s.input_event_bindings.viewer["keyp"] = "screenshotStatistics"
452-
453-
def is_fixed_image_space_last(self, dim_names):
454-
first_name = dim_names[0]
455-
return first_name not in self.input_dim_names
456452

457453
def on_state_changed(self):
458454
self.viewer.defer_callback(self.update)
@@ -477,7 +473,8 @@ def split_points_into_pairs(self, annotations, dim_names):
477473
if len(annotations) == 0:
478474
return np.zeros((0, 0)), np.zeros((0, 0))
479475
if self.two_coord_spaces:
480-
real_dims_last = self.is_fixed_image_space_last(dim_names)
476+
first_name = dim_names[0]
477+
real_dims_last = first_name not in self.input_dim_names
481478
num_points = len(annotations)
482479
num_dims = len(annotations[0].point) // 2
483480
fixed_points = np.zeros((num_points, num_dims))
@@ -647,7 +644,7 @@ def _set_status_message(self, key: str, message: str):
647644
s.status_messages[key] = message
648645
self.status_timers[key] = time()
649646

650-
def transform_points_with_affine(self, points: np.ndarray):
647+
def _transform_points_with_affine(self, points: np.ndarray):
651648
if self.affine is not None:
652649
return transform_points(self.affine, points)
653650

0 commit comments

Comments
 (0)