Skip to content

Commit 3846518

Browse files
committed
Painting tool: draw only into cache for now
Also, improve coarse circle drawing slightly, by reducing the number of Math.sqrt() calls.
1 parent f427b41 commit 3846518

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

django/applications/catmaid/static/js/image-block.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,16 @@
131131
// Second, write to back-end asynchronously
132132
// TODO: This should be done with the help of rate limitng to only send
133133
// changes every 3 seconds or so.
134+
/*
134135
CATMAID.fetch(`${projectId}/writable-stacks/${writableStackId}/write-block`, 'POST', {
136+
// TODO: zip/lzw block, esp. useful for new blocks
135137
data: block.tolist(),
136138
data_bounds: [[x, y, z], [x, y, z]],
137139
})
138140
.then(response => {
139141
return Promise.reject('Not yet implemented');
140142
});
143+
*/
141144
}
142145

143146
evictAll() {

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
prevY = y;
161161
}
162162

163-
const canvasDrawing = true;
163+
const canvasDrawing = false;
164164

165165
if (canvasDrawing) {
166166
if (x === prevX && y === prevY) {
@@ -250,15 +250,32 @@
250250
// No block found in cache and on server
251251
CATMAID.msg('success', 'A new block is created, because no existing block is found');
252252
// TODO: Init new block
253-
// const backgroundValue = 0;
254-
const blockData = nj.zeros(blockSize, dataType);
255-
block = new nj.NdArray(blockData)
256-
.transpose(...this.dataLayer.tileSource.sliceDims);
253+
const backgroundValue = 0;
254+
block = nj.zeros(blockSize, dataType);
255+
block.assign(backgroundValue, false);
256+
// TODO: Needed?
257+
block = block.transpose(...this.dataLayer.tileSource.sliceDims);
257258
}
258259

259260
// Update block data and write to cache if not already there. The block is
260261
// a nj.NdArray instance.
261-
262+
const relVoxelPos = [
263+
Math.floor(voxelPosX - blockCoord[0] * blockSize[0]),
264+
Math.floor(voxelPosY - blockCoord[1] * blockSize[1]),
265+
Math.floor(voxelPosZ - blockCoord[2] * blockSize[2])
266+
];
267+
268+
// Draw a coarse circle
269+
const halfBrushSize = Math.floor(this.brushSize / 2.0);
270+
const sqBrushSize = halfBrushSize * halfBrushSize;
271+
for (let x = -halfBrushSize; x <= halfBrushSize; x++) {
272+
for (let y = -halfBrushSize; y <= halfBrushSize; y++) {
273+
const sqDist = x * x + y * y;
274+
if (sqDist <= sqBrushSize) {
275+
block.set(relVoxelPos[0] + x, relVoxelPos[1] + y, relVoxelPos[2], this.value);
276+
}
277+
}
278+
}
262279

263280
// Write block back to server. This is done asynchronously in regular
264281
// intervald (if changes happen).

0 commit comments

Comments
 (0)