Skip to content

Commit

Permalink
Allow to change smoothing from app, fixes #1555
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Nov 16, 2023
1 parent a844e37 commit 584d437
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,16 @@ dwv.App = function () {
controller.initialise();
};

/**
* Set the imageSmoothing flag value. Default is false.
*
* @param {boolean} flag True to enable smoothing.
*/
this.setImageSmoothing = function (flag) {
stage.setImageSmoothing(flag);
stage.draw();
};

/**
* Get the layer group configuration from a data index.
* Defaults to div id 'layerGroup' if no association object has been set.
Expand Down
23 changes: 23 additions & 0 deletions src/gui/layerGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ dwv.gui.LayerGroup = function (containerDiv) {
*/
var currentPosition;

/**
* Image smoothing flag.
*
* @type {boolean}
*/
var imageSmoothing = false;

/**
* Get the target orientation.
*
Expand Down Expand Up @@ -274,6 +281,21 @@ dwv.gui.LayerGroup = function (containerDiv) {
}
};

/**
* Set the imageSmoothing flag value.
*
* @param {boolean} flag True to enable smoothing.
*/
this.setImageSmoothing = function (flag) {
imageSmoothing = flag;
// set for existing layers
for (let i = 0; i < layers.length; ++i) {
if (layers[i] instanceof dwv.gui.ViewLayer) {
layers[i].enableImageSmoothing(flag);
}
}
};

/**
* Update crosshair on offset or zoom change.
*/
Expand Down Expand Up @@ -486,6 +508,7 @@ dwv.gui.LayerGroup = function (containerDiv) {
containerDiv.append(div);
// view layer
var layer = new dwv.gui.ViewLayer(div);
layer.enableImageSmoothing(imageSmoothing);
// add layer
layers.push(layer);
// mark it as active
Expand Down
16 changes: 16 additions & 0 deletions src/gui/stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ dwv.gui.Stage = function () {
// binder callbacks
var callbackStore = null;

// image smoothing flag
var imageSmoothing = false;

/**
* Get the layer group at the given index.
*
Expand Down Expand Up @@ -202,6 +205,7 @@ dwv.gui.Stage = function () {
this.addLayerGroup = function (htmlElement) {
activeLayerGroupIndex = layerGroups.length;
var layerGroup = new dwv.gui.LayerGroup(htmlElement);
layerGroup.setImageSmoothing(imageSmoothing);
// add to storage
var isBound = callbackStore && callbackStore.length !== 0;
if (isBound) {
Expand Down Expand Up @@ -339,6 +343,18 @@ dwv.gui.Stage = function () {
callbackStore = null;
};

/**
* Set the imageSmoothing flag value.
*
* @param {boolean} flag True to enable smoothing.
*/
this.setImageSmoothing = function (flag) {
imageSmoothing = flag;
for (let i = 0; i < layerGroups.length; ++i) {
layerGroups[i].setImageSmoothing(flag);
}
};

/**
* Get the binder callback function for a given layer group index.
* The function is created if not yet stored.
Expand Down

0 comments on commit 584d437

Please sign in to comment.