Skip to content

Commit

Permalink
Always create a default minmax w/l preset.
Browse files Browse the repository at this point in the history
Add fill it at first use. Fixes the presets order on which preset change
tools depend.
  • Loading branch information
ivmartel committed Mar 29, 2017
1 parent 7e1dba3 commit 9a24d9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
2 changes: 0 additions & 2 deletions src/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1269,8 +1269,6 @@ dwv.App = function ()
// get the view from the loaded data
view = data.view;
viewController = new dwv.ViewController(view);
// add the min/max preset (just the first time)
view.addWindowLevelMinMax();

// append the DICOM tags table
if ( tagsGui ) {
Expand Down
27 changes: 12 additions & 15 deletions src/image/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ dwv.image.View = function (image)

/**
* Window presets.
* Minmax will be filled at first use (see view.setWindowLevelPreset).
* @private
* @type Object
*/
var windowPresets = [];
var windowPresets = { "minmax": {"name": "minmax"} };

/**
* Current window preset name.
Expand Down Expand Up @@ -464,6 +465,10 @@ dwv.image.View = function (image)
if ( typeof preset === "undefined" ) {
throw new Error("Unknown window level preset: '" + name + "'");
}
// special min/max
if (name === "minmax" && typeof preset.wl === "undefined") {
preset.wl = this.getWindowLevelMinMax();
}
// update member preset name
currentPresetName = name;
// special 'perslice' case
Expand Down Expand Up @@ -541,16 +546,6 @@ dwv.image.View.prototype.setWindowLevelMinMax = function()
this.setWindowLevel(wl.getCenter(), wl.getWidth());
};

/**
* Add the image min/max window/level to the list of presets.
*/
dwv.image.View.prototype.addWindowLevelMinMax = function ()
{
this.addWindowPresets( { "minmax": {
"wl": this.getWindowLevelMinMax(),
"name": "minmax" } } );
};

/**
* Generate display image data to be given to a canvas.
* @param {Array} array The array to fill in.
Expand Down Expand Up @@ -774,6 +769,12 @@ dwv.image.ViewFactory.prototype.create = function (dicomElements, image)
}
}

// min/max
// Not filled yet since it is stil too costly to calculate min/max
// for each slice... It will be filled at first use (see view.setWindowLevelPreset).
// Order is important, if no wl from DICOM, this will be the default.
windowPresets.minmax = { "name": "minmax" };

// optional modality presets
if ( typeof dwv.tool.defaultpresets !== "undefined" ) {
var modality = image.getMeta().Modality;
Expand All @@ -785,10 +786,6 @@ dwv.image.ViewFactory.prototype.create = function (dicomElements, image)
}
}

// TODO min/max preset
// not yet since it is stil too costly to calculate min/max
// for each slice...

// store
view.setWindowPresets( windowPresets );

Expand Down

0 comments on commit 9a24d9a

Please sign in to comment.