Skip to content

Commit f0c5ba3

Browse files
committed
Admin: add hacky volume transformation to clone/transform tool
1 parent 8b831db commit f0c5ba3

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

django/applications/catmaid/control/importer.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232

3333
from catmaid.apps import get_system_user
3434
from catmaid.models import (BrokenSlice, Class, Relation, ClassClass, Location, Volume,
35-
ClassInstance, Project, ClassInstanceClassInstance, Stack, StackGroup, DeepLink,
35+
ClassInstance, Project, ClassInstanceClassInstance, Stack, StackGroup, DeepLink, Point,
3636
StackStackGroup, ProjectStack, StackClassInstance, StackGroupClassInstance, StackGroupRelation,
37-
StackMirror, TILE_SOURCE_TYPE_CHOICES, User, Treenode, Connector, Concept, SkeletonSummary)
37+
StackMirror, TILE_SOURCE_TYPE_CHOICES, User, Treenode, Connector, Concept, SkeletonSummary,
38+
RegionOfInterest)
3839
from catmaid.fields import Double3D
3940
from catmaid.control.annotationadmin import copy_annotations
4041
from catmaid.control.common import urljoin, is_valid_host
@@ -1755,10 +1756,31 @@ def transform_single_location(self, location):
17551756
def transform_volume(self, volume):
17561757
"""
17571758
Update the volume locations of the passed in
1758-
volume object according to the stored transform.
1759+
volume object according to the stored transform. This is somewhat hacky,
1760+
because we parse and write the the geometry representation of the volume
1761+
directly. At the time of writing there was no convenient way to do this
1762+
in an alternative fashion.
1763+
1764+
We expect geometry data like this:
1765+
1766+
TIN Z (((18347.2525117247 15120.551976926 15240.0,18347.2525117247 27120.551976926 15240.0,30347.2525117247 15120.551976926 15240.0,18347.2525117247 15120.551976926 15240.0)),((30347.2525117247 15120.551976926 15240.0,18347.2525117247 27120.551976926 15240.0,30347.2525117247 27120.551976926 15240.0,30347.2525117247 15120.551976926 15240.0)))
17591767
"""
17601768
if self.transform and self.reference_stack:
1761-
pass
1769+
triangle_data = volume.geometry.replace('TIN Z ', '').replace('(((', '').replace(')))', '') \
1770+
.replace('))', ']').replace('((', '[').split('],[')
1771+
triangles = list(map(lambda t: list(map(lambda c: list(map(lambda n: float(n), c.split(' '))), t.split(','))), triangle_data))
1772+
1773+
for triangle_coords in triangles:
1774+
for c in triangle_coords:
1775+
# Assume csv-z-slice type for now
1776+
z_index = int(c[2] / self.reference_stack.resolution.z)
1777+
xy_shift = self.transform[z_index]
1778+
c[0] += xy_shift[0]
1779+
c[1] += xy_shift[1]
1780+
1781+
# Convert array to TIN WKT again
1782+
wkt_data = 'TIN Z (' + ','.join(map(lambda t: '((' + ','.join(list(map(lambda c: ' '.join(list(map(str, c))), t))) + '))', triangles)) + ')'
1783+
volume.geometry = wkt_data
17621784

17631785
return volume
17641786

@@ -1935,18 +1957,18 @@ def import_data(self):
19351957
import_objects_by_type_and_id, existing_classes)
19361958

19371959
# Apply an optional transformation to all location information that can
1938-
# currently be imported: treenode, connector, location, deep link, volume
1960+
# currently be imported: treenode, connector, location, deep link,
1961+
# point, ROI and volume
19391962
if self.transform:
19401963
n_transformed = 0
19411964
logger.info('Applying stored transformation')
1942-
single_location_types = [Treenode, Connector, Location, DeepLink]
1965+
single_location_types = [Treenode, Connector, Location, DeepLink, Point, RegionOfInterest]
19431966
for location_type in single_location_types:
19441967
location_objects = objects_to_save.get(location_type, [])
19451968
for lo in location_objects:
19461969
self.transform_single_location(lo.object)
19471970
n_transformed += 1
19481971

1949-
# TODO: Volume isn't updated yet
19501972
volume_objects = objects_to_save.get(Volume, [])
19511973
for vo in volume_objects:
19521974
self.transform_volume(vo.object)

0 commit comments

Comments
 (0)