Skip to content

Commit 868eb99

Browse files
committed
Admin clone/transform tool: add support for XYZ offsets in transformation
1 parent 2fabe76 commit 868eb99

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

django/applications/catmaid/control/annotationadmin.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ class TransformImportForm(forms.Form):
7676
queryset=Stack.objects.all())
7777
x_factor = forms.FloatField(initial=1.0, required=False, help_text="A factor that is multiplied to each X shift")
7878
y_factor = forms.FloatField(initial=1.0, required=False, help_text="A factor that is multiplied to each Y shift")
79+
z_factor = forms.FloatField(initial=1.0, required=False, help_text="A factor that is multiplied to each Z shift")
80+
x_offset = forms.FloatField(initial=0.0, required=False, help_text="A offset that is added to each X shift")
81+
y_offset = forms.FloatField(initial=0.0, required=False, help_text="A offset that is added to each Y shift")
82+
z_offset = forms.FloatField(initial=0.0, required=False, help_text="A offset that is added to each Z shift")
7983
delimiter = forms.CharField(initial=',', required=False, help_text="The delimiter used in the transform CSV")
8084
transform_type = forms.ChoiceField(choices=TRANSFORM_TYPE_CHOICES, required=True, help_text="The type of tranformaton")
8185
transform_text = forms.CharField(widget=forms.Textarea, label='Transform',
@@ -323,6 +327,10 @@ def done(self, form_list, **kwargs) -> HttpResponse:
323327
reference_stack = transform_data['reference_stack']
324328
x_factor = transform_data['x_factor']
325329
y_factor = transform_data['y_factor']
330+
z_factor = transform_data['z_factor']
331+
x_offset = transform_data['x_offset']
332+
y_offset = transform_data['y_offset']
333+
z_offset = transform_data['z_offset']
326334
delimiter = transform_data['delimiter']
327335
transform_data_type = transform_data['transform_type']
328336
transform_text = transform_data['transform_text'].replace('\r\n', '\n').replace('\r', '\n')
@@ -332,8 +340,9 @@ def done(self, form_list, **kwargs) -> HttpResponse:
332340
if transform_data_type == 'csv-z-slices':
333341
with StringIO(transform_text) as transform_stream:
334342
reader = csv.reader(transform_stream, delimiter=delimiter)
335-
transform = list(map(lambda xy: [x_factor * float(xy[0]),
336-
y_factor * float(xy[1])],
343+
transform = list(map(lambda xy: [x_factor * float(xy[0]) + x_offset,
344+
y_factor * float(xy[1]) + y_offset,
345+
z_offset],
337346
reader))
338347
else:
339348
raise ValidationError(f"Unknown transform data type: {transform_data_type}")

django/applications/catmaid/control/importer.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,10 +1749,11 @@ def transform_single_location(self, location, clamped_locations):
17491749
z_index = int(location.location_z / self.reference_stack.resolution.z)
17501750
if z_index >= len(self.transform) or z_index < 0:
17511751
clamped_locations[z_index] += 1
1752-
z_index = len(self.transform) - 1
1753-
xy_shift = self.transform[z_index]
1754-
location.location_x += xy_shift[0]
1755-
location.location_y += xy_shift[1]
1752+
z_index = 0 if z_index < 0 else len(self.transform) - 1
1753+
xyz_shift = self.transform[z_index]
1754+
location.location_x += xyz_shift[0]
1755+
location.location_y += xyz_shift[1]
1756+
location.location_z += xyz_shift[2]
17561757

17571758
return location
17581759

@@ -1779,10 +1780,11 @@ def transform_volume(self, volume, clamped_locations):
17791780
z_index = int(c[2] / self.reference_stack.resolution.z)
17801781
if z_index >= len(self.transform) or z_index < 0:
17811782
clamped_locations[z_index] += 1
1782-
z_index = len(self.transform) - 1
1783-
xy_shift = self.transform[z_index]
1784-
c[0] += xy_shift[0]
1785-
c[1] += xy_shift[1]
1783+
z_index = 0 if z_index < 0 else len(self.transform) - 1
1784+
xyz_shift = self.transform[z_index]
1785+
c[0] += xyz_shift[0]
1786+
c[1] += xyz_shift[1]
1787+
c[2] += xyz_shift[2]
17861788

17871789
# Convert array to TIN WKT again
17881790
wkt_data = 'TIN Z (' + ','.join(map(lambda t: '((' + ','.join(list(map(lambda c: ' '.join(list(map(str, c))), t))) + '))', triangles)) + ')'

0 commit comments

Comments
 (0)