Skip to content

Commit

Permalink
fix(RangeManipulator): allow querying current value with get callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Girault committed Jan 19, 2018
1 parent ccf74ac commit 5988867
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Expand Up @@ -40,25 +40,25 @@ const range = data
.getRange();
const wMin = 1;
const wMax = range[1] - range[0];
const wCurrent = actor.getProperty().getColorWindow();
const wCallback = actor.getProperty().setColorWindow;
const wGet = actor.getProperty().getColorWindow;
const wSet = actor.getProperty().setColorWindow;
const lMin = range[0];
const lMax = range[1];
const lCurrent = actor.getProperty().getColorLevel();
const lCallback = actor.getProperty().setColorLevel;
const lGet = actor.getProperty().getColorLevel;
const lSet = actor.getProperty().setColorLevel;
const bounds = data.getBounds();
const zMin = bounds[4];
const zMax = bounds[5];
const zCurrent = mapper.getZSlice();
const zCallback = mapper.setZSlice;
const zGet = mapper.getZSlice;
const zSet = mapper.setZSlice;

const rangeManipulator = Manipulators.vtkRangeManipulator.newInstance({
button: 1,
pinch: true,
});
rangeManipulator.setVerticalListener(wMin, wMax, wCurrent, 1, wCallback);
rangeManipulator.setHorizontalListener(lMin, lMax, lCurrent, 1, lCallback);
rangeManipulator.setScrollListener(zMin, zMax, zCurrent, 1, zCallback);
rangeManipulator.setVerticalListener(wMin, wMax, 1, wGet, wSet);
rangeManipulator.setHorizontalListener(lMin, lMax, 1, lGet, lSet);
rangeManipulator.setScrollListener(zMin, zMax, 1, zGet, zSet);

const iStyle = vtkInteractorStyleManipulator.newInstance();
iStyle.addManipulator(rangeManipulator);
Expand Down
20 changes: 11 additions & 9 deletions Sources/Interaction/Manipulators/RangeManipulator/index.js
Expand Up @@ -13,33 +13,35 @@ function vtkRangeManipulator(publicAPI, model) {
function processDelta(listener, delta) {
let normDelta = delta;
normDelta *= (listener.max - listener.min) / listener.step + 1;
let value = listener.value + normDelta;
let value = listener.getValue() + normDelta;

const difference = value - listener.min;
const stepsToDifference = Math.round(difference / listener.step);
value = listener.min + listener.step * stepsToDifference;
value = Math.max(value, listener.min);
value = Math.min(value, listener.max);

listener.callback(value);
listener.value = value;
listener.setValue(value);
}

//-------------------------------------------------------------------------
publicAPI.setHorizontalListener = (min, max, value, step, callback) => {
model.horizontalListener = { min, max, value, step, callback };
publicAPI.setHorizontalListener = (min, max, step, getValue, setValue) => {
const getFn = Number.isFinite(getValue) ? () => getValue : getValue;
model.horizontalListener = { min, max, step, getValue: getFn, setValue };
publicAPI.modified();
};

//-------------------------------------------------------------------------
publicAPI.setVerticalListener = (min, max, value, step, callback) => {
model.verticalListener = { min, max, value, step, callback };
publicAPI.setVerticalListener = (min, max, step, getValue, setValue) => {
const getFn = Number.isFinite(getValue) ? () => getValue : getValue;
model.verticalListener = { min, max, step, getValue: getFn, setValue };
publicAPI.modified();
};

//-------------------------------------------------------------------------
publicAPI.setScrollListener = (min, max, value, step, callback) => {
model.scrollListener = { min, max, value, step, callback };
publicAPI.setScrollListener = (min, max, step, getValue, setValue) => {
const getFn = Number.isFinite(getValue) ? () => getValue : getValue;
model.scrollListener = { min, max, step, getValue: getFn, setValue };
publicAPI.modified();
};

Expand Down

0 comments on commit 5988867

Please sign in to comment.