|
32 | 32 |
|
33 | 33 | from catmaid.apps import get_system_user |
34 | 34 | 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, |
36 | 36 | 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) |
38 | 39 | from catmaid.fields import Double3D |
39 | 40 | from catmaid.control.annotationadmin import copy_annotations |
40 | 41 | from catmaid.control.common import urljoin, is_valid_host |
@@ -1755,10 +1756,31 @@ def transform_single_location(self, location): |
1755 | 1756 | def transform_volume(self, volume): |
1756 | 1757 | """ |
1757 | 1758 | 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))) |
1759 | 1767 | """ |
1760 | 1768 | 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 |
1762 | 1784 |
|
1763 | 1785 | return volume |
1764 | 1786 |
|
@@ -1935,18 +1957,18 @@ def import_data(self): |
1935 | 1957 | import_objects_by_type_and_id, existing_classes) |
1936 | 1958 |
|
1937 | 1959 | # 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 |
1939 | 1962 | if self.transform: |
1940 | 1963 | n_transformed = 0 |
1941 | 1964 | logger.info('Applying stored transformation') |
1942 | | - single_location_types = [Treenode, Connector, Location, DeepLink] |
| 1965 | + single_location_types = [Treenode, Connector, Location, DeepLink, Point, RegionOfInterest] |
1943 | 1966 | for location_type in single_location_types: |
1944 | 1967 | location_objects = objects_to_save.get(location_type, []) |
1945 | 1968 | for lo in location_objects: |
1946 | 1969 | self.transform_single_location(lo.object) |
1947 | 1970 | n_transformed += 1 |
1948 | 1971 |
|
1949 | | - # TODO: Volume isn't updated yet |
1950 | 1972 | volume_objects = objects_to_save.get(Volume, []) |
1951 | 1973 | for vo in volume_objects: |
1952 | 1974 | self.transform_volume(vo.object) |
|
0 commit comments