Skip to content

Commit

Permalink
fix(VolumeController): Add rescaleColorMap option
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Feb 3, 2018
1 parent 985e8c5 commit a8e990a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Sources/Interaction/UI/VolumeController/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ function vtkVolumeController(publicAPI, model) {
const dataArray =
sourceDS.getPointData().getScalars() ||
sourceDS.getPointData().getArrays()[0];
const dataRange = dataArray.getRange();
const dataRange = model.rescaleColorMap
? model.colorDataRange
: dataArray.getRange();
const preset = vtkColorMaps.getPresetByName(
model.el.querySelector('.js-color-preset').value
);
Expand Down Expand Up @@ -196,6 +198,7 @@ function vtkVolumeController(publicAPI, model) {
model.widget.applyOpacity(piecewiseFunction);
model.widget.setContainer(widgetContainer);
model.widget.bindMouseListeners();
model.colorDataRange = model.widget.getOpacityRange();

// Attach listeners
domToggleButton.addEventListener('click', toggleVisibility);
Expand All @@ -206,6 +209,11 @@ function vtkVolumeController(publicAPI, model) {

model.widget.onOpacityChange(() => {
model.widget.applyOpacity(piecewiseFunction);
model.colorDataRange = model.widget.getOpacityRange();
if (model.rescaleColorMap) {
updateColorMapPreset();
}

if (!model.renderWindow.getInteractor().isAnimating()) {
model.renderWindow.render();
}
Expand Down Expand Up @@ -251,6 +259,15 @@ function vtkVolumeController(publicAPI, model) {
}
};

const rescaleColorMap = publicAPI.setRescaleColorMap;
publicAPI.setSescaleColorMap = (value) => {
if (rescaleColorMap(value)) {
updateColorMapPreset();
return true;
}
return false;
};

publicAPI.setSize = model.widget.setSize;
publicAPI.render = model.widget.render;
publicAPI.onAnimation = model.widget.onAnimation;
Expand All @@ -267,6 +284,7 @@ function vtkVolumeController(publicAPI, model) {
const DEFAULT_VALUES = {
size: [600, 300],
expanded: true,
rescaleColorMap: false,
};

// ----------------------------------------------------------------------------
Expand All @@ -276,7 +294,7 @@ export function extend(publicAPI, model, initialValues = {}) {

// Object methods
macro.obj(publicAPI, model);
macro.setGet(publicAPI, model, ['actor', 'renderWindow']);
macro.setGet(publicAPI, model, ['actor', 'renderWindow', 'rescaleColorMap']);
macro.get(publicAPI, model, ['widget']);

// Object specific methods
Expand Down

0 comments on commit a8e990a

Please sign in to comment.