From a3de6fc55009852b50f6cc0886cedff1178feef0 Mon Sep 17 00:00:00 2001 From: ivmartel Date: Sun, 26 Jun 2016 02:26:14 +0200 Subject: [PATCH] Added support for per frame drawing. Fixes other draw issues. Sorted out the drawLayer activation. Fixes #230. Fixes drawing for slice/frame change via keyboard shortcodes. --- src/app/application.js | 109 +++++++++++++++++++++++++---------------- src/image/view.js | 2 +- src/tools/draw.js | 39 +++++++++++++-- 3 files changed, 103 insertions(+), 47 deletions(-) diff --git a/src/app/application.js b/src/app/application.js index 787bef557d..713668f7d1 100644 --- a/src/app/application.js +++ b/src/app/application.js @@ -153,15 +153,14 @@ dwv.App = function () this.getImageLayer = function () { return imageLayer; }; /** * Get the draw layer. + * @param {Number} slice Optional slice position (uses the current slice position if not provided). + * @param {Number} frame Optional frame position (uses the current frame position if not provided). * @return {Object} The draw layer. */ - this.getDrawLayer = function (k) { - if ( typeof k === "undefined" ) { - return drawLayers[view.getCurrentPosition().k]; - } - else { - return drawLayers[k]; - } + this.getDrawLayer = function (slice, frame) { + var k = (typeof slice === "undefined") ? view.getCurrentPosition().k : slice; + var f = (typeof frame === "undefined") ? view.getCurrentFrame() : frame; + return drawLayers[k][f]; }; /** * Get the draw stage. @@ -474,28 +473,21 @@ dwv.App = function () var fileIO = new dwv.io.File(); fileIO.setDecoderScripts(decoderScripts); fileIO.onload = function (data) { - - var isFirst = true; if ( image ) { view.append( data.view ); - isFirst = false; } postLoadInit(data); if ( drawStage ) { - // create slice draw layer - var drawLayer = new Kinetic.Layer({ - listening: false, - hitGraphEnabled: false, - visible: isFirst - }); - // add to layers array - drawLayers.push(drawLayer); - // add the layer to the stage - drawStage.add(drawLayer); + appendDrawLayer(image.getNumberOfFrames()); } }; fileIO.onerror = function (error) { handleError(error); }; - fileIO.onloadend = function (/*event*/) { fireEvent({ 'type': 'load-end' }); }; + fileIO.onloadend = function (/*event*/) { + if ( drawStage ) { + activateDrawLayer(); + } + fireEvent({ 'type': 'load-end' }); + }; fileIO.onprogress = onLoadProgress; // main load (asynchronous) fireEvent({ 'type': 'load-start' }); @@ -553,27 +545,21 @@ dwv.App = function () var urlIO = new dwv.io.Url(); urlIO.setDecoderScripts(decoderScripts); urlIO.onload = function (data) { - var isFirst = true; if ( image ) { view.append( data.view ); - isFirst = false; } postLoadInit(data); if ( drawStage ) { - // create slice draw layer - var drawLayer = new Kinetic.Layer({ - listening: false, - hitGraphEnabled: false, - visible: isFirst - }); - // add to layers array - drawLayers.push(drawLayer); - // add the layer to the stage - drawStage.add(drawLayer); + appendDrawLayer(image.getNumberOfFrames()); } }; urlIO.onerror = function (error) { handleError(error); }; - urlIO.onloadend = function (/*event*/) { fireEvent({ 'type': 'load-end' }); }; + urlIO.onloadend = function (/*event*/) { + if ( drawStage ) { + activateDrawLayer(); + } + fireEvent({ 'type': 'load-end' }); + }; urlIO.onprogress = onLoadProgress; // main load (asynchronous) fireEvent({ 'type': 'load-start' }); @@ -599,6 +585,45 @@ dwv.App = function () urlIO.load([url]); } + /** + * Append a new draw layer list to the list. + * @private + */ + function appendDrawLayer(number) { + // add a new dimension + drawLayers.push([]); + // fill it + for (var i=0; i