Skip to content

Commit b26382e

Browse files
committed
Admin clone/transform tool: add transform Z lookup offset
This allows to start using a transformation table only at a particular Z index.
1 parent 11a3979 commit b26382e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

django/applications/catmaid/control/annotationadmin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class TransformImportForm(forms.Form):
8282
x_offset = forms.FloatField(initial=0.0, required=False, help_text="A offset that is added to each X shift")
8383
y_offset = forms.FloatField(initial=0.0, required=False, help_text="A offset that is added to each Y shift")
8484
z_offset = forms.FloatField(initial=0.0, required=False, help_text="A offset that is added to each Z shift")
85+
z_lookup_offset = forms.IntegerField(initial=0, required=False, help_text="An offset that is added to each Z look-up index. Slices before won't be transformed.")
8586
delimiter = forms.CharField(initial=',', required=False, help_text="The delimiter used in the transform CSV")
8687
transform_type = forms.ChoiceField(choices=TRANSFORM_TYPE_CHOICES, required=True, help_text="The type of tranformaton")
8788
transform_text = forms.CharField(widget=forms.Textarea, label='Transform',
@@ -204,6 +205,7 @@ def async_project_copy_job(import_task_id) -> str:
204205
import_options['transform'] = scd['transform']
205206
import_options['reference_stack_id'] = scd['reference_stack_id']
206207
import_options['transform_in_project_space'] = scd['transform_in_project_space']
208+
import_options['transform_z_lookup_offset'] = scd['transform_z_lookup_offset']
207209

208210
# Import project data into new project
209211
task_logger.info(f'Importing into project {target_project}')
@@ -343,6 +345,7 @@ def done(self, form_list, **kwargs) -> HttpResponse:
343345
x_offset = transform_data['x_offset']
344346
y_offset = transform_data['y_offset']
345347
z_offset = transform_data['z_offset']
348+
z_lookup_offset = transform_data['z_lookup_offset']
346349
delimiter = transform_data['delimiter']
347350
transform_data_type = transform_data['transform_type']
348351
transform_text = transform_data['transform_text'].replace('\r\n', '\n').replace('\r', '\n')
@@ -380,6 +383,7 @@ def done(self, form_list, **kwargs) -> HttpResponse:
380383
'reference_stack_id': reference_stack.id,
381384
'transfer_stats': transfer_stats,
382385
'transform_in_project_space': transform_data['transform_in_project_space'],
386+
'transform_z_lookup_offset': transform_data['z_lookup_offset'],
383387
})
384388

385389
# Make sure the created import task is available

django/applications/catmaid/control/importer.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,7 @@ def __init__(self, source, target, user, options, custom_logger=None):
14681468
reference_stack_id = options.get('reference_stack_id')
14691469
self.reference_stack = Stack.objects.get(id=reference_stack_id) if reference_stack_id is not None else None
14701470
self.transform_in_project_space = options.get('transform_in_project_space', False)
1471+
self.transform_z_lookup_offset = options.get('transform_z_lookup_offset', 0)
14711472
self.precomputed_stats = options.get('precomputed_stats')
14721473

14731474
# Map user IDs to newly created users
@@ -1750,10 +1751,13 @@ def transform_single_location(self, location, clamped_locations):
17501751
"""
17511752
if self.transform and self.reference_stack:
17521753
# Assume csv-z-slice type for now
1753-
z_index = int(location.location_z / self.reference_stack.resolution.z)
1754+
z_index = int(location.location_z / self.reference_stack.resolution.z) \
1755+
+ self.transform_z_lookup_offset
1756+
# Don't transform data outside of transform index
17541757
if z_index >= len(self.transform) or z_index < 0:
17551758
clamped_locations[z_index] += 1
1756-
z_index = 0 if z_index < 0 else len(self.transform) - 1
1759+
return location
1760+
17571761
xyz_shift = self.transform[z_index]
17581762
if self.transform_in_project_space:
17591763
location.location_x += xyz_shift[0] * self.reference_stack.resolution.x
@@ -1786,10 +1790,12 @@ def transform_volume(self, volume, clamped_locations):
17861790
for triangle_coords in triangles:
17871791
for c in triangle_coords:
17881792
# Assume csv-z-slice type for now
1789-
z_index = int(c[2] / self.reference_stack.resolution.z)
1793+
z_index = int(c[2] / self.reference_stack.resolution.z) \
1794+
+ self.transform_z_lookup_offset
17901795
if z_index >= len(self.transform) or z_index < 0:
17911796
clamped_locations[z_index] += 1
1792-
z_index = 0 if z_index < 0 else len(self.transform) - 1
1797+
continue
1798+
17931799
xyz_shift = self.transform[z_index]
17941800
if self.transform_in_project_space:
17951801
c[0] += xyz_shift[0] * self.reference_stack.resolution.x

0 commit comments

Comments
 (0)