src/VTKViewport/Manipulators/customWindowLevel.js
/**
 * Initialize any additional publicAPI functions we may need.
 */
Initialize any additional publicAPI functions we may need.
Initialize any additional publicAPI functions we may need .
function initialize(publicAPI, model) {
  publicAPI.windowLevelFromMouse = pos => {
    const range = model.volumeActor
      .getMapper()
      .getInputData()
      .getPointData()
      .getScalars()
      .getRange();
    const imageDynamicRange = range[1] - range[0];
    const multiplier =
      Math.round(imageDynamicRange / 1024) * publicAPI.getLevelScale();
    const dx = Math.round((pos[0] - model.wlStartPos[0]) * multiplier);
    const dy = Math.round((pos[1] - model.wlStartPos[1]) * multiplier);
    let windowWidth = model.levels.windowWidth + dx;
    let windowCenter = model.levels.windowCenter - dy;
    windowWidth = Math.max(0.01, windowWidth);
    if (
      model.windowWidth === windowWidth &&
      model.windowCenter === windowCenter
    ) {
      return;
    }
    publicAPI.setWindowLevel(windowWidth, windowCenter);
    model.wlStartPos[0] = Math.round(pos[0]);
    model.wlStartPos[1] = Math.round(pos[1]);
    const onLevelsChanged = publicAPI.getOnLevelsChanged();
    if (onLevelsChanged) {
      onLevelsChanged({ windowCenter, windowWidth });
    }
  };
  publicAPI.getWindowLevel = () => {
    const range = model.volumeActor
      .getProperty()
      .getRGBTransferFunction(0)
      .getMappingRange()
      .slice();
    return toWindowLevel(...range);
  };
  publicAPI.setWindowLevel = (windowWidth, windowCenter) => {
    const lowHigh = toLowHighRange(windowWidth, windowCenter);
    model.levels.windowWidth = windowWidth;
    model.levels.windowCenter = windowCenter;
    model.volumeActor
      .getProperty()
      .getRGBTransferFunction(0)
      .setMappingRange(lowHigh.lower, lowHigh.upper);
  };
}
function initialize ( publicAPI , model ) { publicAPI . windowLevelFromMouse = pos => { const range = model . volumeActor . getMapper ( ) . getInputData ( ) . getPointData ( ) . getScalars ( ) . getRange ( ) ; const imageDynamicRange = range [ 1 ] - range [ 0 ] ; const multiplier = Math . round ( imageDynamicRange / 1024 ) * publicAPI . getLevelScale ( ) ; const dx = Math . round ( ( pos [ 0 ] - model . wlStartPos [ 0 ] ) * multiplier ) ; const dy = Math . round ( ( pos [ 1 ] - model . wlStartPos [ 1 ] ) * multiplier ) ; let windowWidth = model . levels . windowWidth + dx ; let windowCenter = model . levels . windowCenter - dy ; windowWidth = Math . max ( 0.01 , windowWidth ) ; if ( model . windowWidth === windowWidth && model . windowCenter === windowCenter ) { return ; } publicAPI . setWindowLevel ( windowWidth , windowCenter ) ; model . wlStartPos [ 0 ] = Math . round ( pos [ 0 ] ) ; model . wlStartPos [ 1 ] = Math . round ( pos [ 1 ] ) ; const onLevelsChanged = publicAPI . getOnLevelsChanged ( ) ; if ( onLevelsChanged ) { onLevelsChanged ( { windowCenter , windowWidth } ) ; } } ; publicAPI . getWindowLevel = ( ) => { const range = model . volumeActor . getProperty ( ) . getRGBTransferFunction ( 0 ) . getMappingRange ( ) . slice ( ) ; return toWindowLevel ( ... range ) ; } ; publicAPI . setWindowLevel = ( windowWidth , windowCenter ) => { const lowHigh = toLowHighRange ( windowWidth , windowCenter ) ; model . levels . windowWidth = windowWidth ; model . levels . windowCenter = windowCenter ; model . volumeActor . getProperty ( ) . getRGBTransferFunction ( 0 ) . setMappingRange ( lowHigh . lower , lowHigh . upper ) ; } ; }
Initialize any additional publicAPI functions we may need.
Initialize any additional publicAPI functions we may need .
// Directly from vtkInteractorStyleMPRWindowLevel // Directly from vtkInteractorStyleMPRWindowLevel // Directly from vtkInteractorStyleMPRWindowLevel