Skip to content

Commit 0b43cd2

Browse files
committed
Painting layer: fix painting in non-zero scale levels
1 parent 1732608 commit 0b43cd2

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

django/applications/catmaid/control/cropping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ def write_block(request:HttpRequest, project_id=None, writable_stack_id=None) ->
10211021
# Assume the dataset exists already
10221022
pass
10231023

1024-
dataset += f"s{scale_level}"
1024+
dataset += f"{'/' if len(dataset) else ''}s{scale_level}"
10251025
n5 = pyn5.open(full_path, dataset, dtype.lower(), False)
10261026
pyn5.write(n5, (np.array(data_bounds[0]), np.array(data_bounds[1]) + 1), data, dtype)
10271027

django/applications/catmaid/control/stack.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,26 @@ def post(self, request:HttpRequest, project_id) -> JsonResponse:
298298
}
299299
scale_attributes = []
300300
for n, scale_level in enumerate(stack.downsample_factors):
301+
dimensions = [
302+
int(metadata['dataset_size'][0] / scale_level.x),
303+
int(metadata['dataset_size'][1] / scale_level.y),
304+
int(metadata['dataset_size'][2] / scale_level.z),
305+
]
306+
resolution = [
307+
metadata['resolution'][0] / scale_level.x,
308+
metadata['resolution'][1] / scale_level.y,
309+
metadata['resolution'][2] / scale_level.z,
310+
]
301311
scale_attributes.append({
302312
"dataType": metadata['dtype'],
303313
"compression": {
304314
"type": encoding,
305315
},
306316
"blockSize": metadata['block_size'],
307-
"dimensions": metadata['dataset_size'],
317+
"dimensions": dimensions,
308318
"pixelResolution": {
309319
"unit": "um",
310-
"dimensions": metadata['resolution'],
320+
"dimensions": resolution,
311321
},
312322
"downsamplingFactors": [
313323
scale_level.x,

django/applications/catmaid/static/js/layers/painting-layer.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,14 @@
207207

208208
// Convert screen coordinates to voxel coordinates. Convert voxel
209209
// coordinates into block coordinates.
210+
let zoom = this.stackViewer.s;
210211
const screenPosition = this.stackViewer.screenPosition();
211-
const voxelPosX = screenPosition.left +
212-
x / this.stackViewer.scale / this.stackViewer.primaryStack.anisotropy(0).x;
213-
const voxelPosY = screenPosition.top +
214-
y / this.stackViewer.scale / this.stackViewer.primaryStack.anisotropy(0).y;
212+
const voxelPosX = (screenPosition.left +
213+
x * Math.pow(2, zoom) / this.stackViewer.primaryStack.anisotropy(0).x) / Math.pow(2, zoom);
214+
const voxelPosY = (screenPosition.top +
215+
y * Math.pow(2, zoom) / this.stackViewer.primaryStack.anisotropy(0).y) / Math.pow(2, zoom);
215216
const voxelPosZ = this.stackViewer.z;
216217

217-
const datasetSize = activeWritableStack.metadata.dataset_size;
218-
if (!datasetSize) {
219-
throw new CATMAID.ValueError('Need writable stacke metadata field: dataset_size');
220-
}
221-
222-
let zoom = this.stackViewer.s;
223218
var mag = 1.0;
224219

225220
//var anisotropy = this.dataLayer.stack.anisotropy(zoom);
@@ -255,9 +250,17 @@
255250
}
256251
}
257252

258-
// TODO: Maybe better get from active writable stack?
259-
const blockSize = this.dataLayer.tileSource.blockSize(this.stackViewer.s);
253+
// Use meta data from data layer, because it actually shows the
254+
// server-side N5 file.
260255
const dataType = this.dataLayer.tileSource.dataType();
256+
const blockSize = this.dataLayer.tileSource.blockSize(this.stackViewer.s);
257+
const blockCoordBounds = this.dataLayer.tileSource.blockCoordBounds(zoom);
258+
// The +1 is needed, because the bounds are inclusice.
259+
const datasetSize = [
260+
(blockCoordBounds.max[0] - blockCoordBounds.min[0] + 1) * blockSize[0],
261+
(blockCoordBounds.max[1] - blockCoordBounds.min[1] + 1) * blockSize[1],
262+
(blockCoordBounds.max[2] - blockCoordBounds.min[2] + 1) * blockSize[2],
263+
];
261264
const blockShape = [
262265
datasetSize[0] / blockSize[0],
263266
datasetSize[1] / blockSize[1],
@@ -300,8 +303,7 @@
300303
method: 'POST',
301304
parallel: true,
302305
data: {
303-
// TODO: Allow other scale levels
304-
scale_level: 0,
306+
scale_level: bS,
305307
//compression: 'raw',
306308
//data: mostRecentBlock.tolist().join(','),
307309
compression: 'msgpack',

0 commit comments

Comments
 (0)